From b97f85e9445805dd412da2138e06ea5435d47ce0 Mon Sep 17 00:00:00 2001 From: trippyone <137233897+trippyone@users.noreply.github.com> Date: Tue, 25 Jun 2024 21:36:38 -0400 Subject: [PATCH] Added stronger punching to increase odds of successful connection --- Fika.Core/Networking/FikaPingingClient.cs | 21 ++++++++++++--------- Fika.Core/Networking/FikaServer.cs | 20 +++++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Fika.Core/Networking/FikaPingingClient.cs b/Fika.Core/Networking/FikaPingingClient.cs index 7d245153..2e3206eb 100644 --- a/Fika.Core/Networking/FikaPingingClient.cs +++ b/Fika.Core/Networking/FikaPingingClient.cs @@ -191,20 +191,23 @@ public void OnNatIntroductionSuccess(IPEndPoint targetEndPoint, NatAddressType t public void OnNatIntroductionResponse(IPEndPoint natLocalEndPoint, IPEndPoint natRemoteEndPoint, string token) { + _logger.LogInfo($"OnNatIntroductionResponse: {remoteEndPoint}"); + localEndPoint = natLocalEndPoint; remoteEndPoint = natRemoteEndPoint; - NetDataWriter data = new(); - data.Put("fika.hello"); - - for (int i = 0; i < 10; i++) + Task.Run(async () => { - NetClient.SendUnconnectedMessage(data, localEndPoint); - NetClient.SendUnconnectedMessage(data, remoteEndPoint); - Task.Delay(100); - } + NetDataWriter data = new(); + data.Put("fika.hello"); - _logger.LogInfo($"OnNatIntroductionResponse: {remoteEndPoint}"); + for (int i = 0; i < 20; i++) + { + NetClient.SendUnconnectedMessage(data, localEndPoint); + NetClient.SendUnconnectedMessage(data, remoteEndPoint); + await Task.Delay(100); + } + }); } } } diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index c7010c8d..af3283b2 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -873,18 +873,20 @@ public void OnNatIntroductionSuccess(IPEndPoint targetEndPoint, NatAddressType t public void OnNatIntroductionResponse(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, string token) { - NetDataWriter data = new(); - data.Put("fika.hello"); + logger.LogInfo($"OnNatIntroductionResponse: {remoteEndPoint}"); - for (int i = 0; i < 10; i++) + Task.Run(async () => { - _netServer.SendUnconnectedMessage(data, localEndPoint); - _netServer.SendUnconnectedMessage(data, remoteEndPoint); - - Task.Delay(100); - } + NetDataWriter data = new(); + data.Put("fika.hello"); - logger.LogInfo($"OnNatIntroductionResponse: {remoteEndPoint}"); + for (int i = 0; i < 20; i++) + { + _netServer.SendUnconnectedMessage(data, localEndPoint); + _netServer.SendUnconnectedMessage(data, remoteEndPoint); + await Task.Delay(100); + } + }); } private class InventoryOperationHandler