From bdee2d039b43150ef75a4bc1c64b922577d52d0f Mon Sep 17 00:00:00 2001 From: Derek S <44935661+Derek-R-S@users.noreply.github.com> Date: Tue, 6 Apr 2021 12:54:42 -0500 Subject: [PATCH] Fixed wrong IP getting sent to unity client --- .../LRM_LoadBalancer/Endpoint.cs | 3 ++- .../LRM_LoadBalancer/Program.cs | 10 ++++++---- .../LRM/Program/Program.cs | 4 +++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint.cs b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint.cs index 0b3f369..b30ea59 100644 --- a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint.cs +++ b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint.cs @@ -30,6 +30,7 @@ namespace LightReflectiveMirror.LoadBalancing string receivedAuthKey = req.Headers["Auth"]; string endpointPort = req.Headers["EndpointPort"]; string gamePort = req.Headers["GamePort"]; + string publicIP = req.Headers["PIP"]; string address = context.Request.RemoteEndPoint.Address.ToString(); @@ -46,7 +47,7 @@ namespace LightReflectiveMirror.LoadBalancing { var _gamePort = Convert.ToUInt16(gamePort); var _endpointPort = Convert.ToUInt16(endpointPort); - await Program.instance.AddServer(address, _gamePort, _endpointPort); + await Program.instance.AddServer(address, _gamePort, _endpointPort, publicIP); } catch { diff --git a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program.cs b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program.cs index a0c8047..c814b8b 100644 --- a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program.cs +++ b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program.cs @@ -58,9 +58,9 @@ namespace LightReflectiveMirror.LoadBalancing } - public async Task AddServer(string serverIP, ushort port, ushort endpointPort) + public async Task AddServer(string serverIP, ushort port, ushort endpointPort, string publicIP) { - var relayAddr = new RelayAddress { Port = port, EndpointPort = endpointPort, Address = serverIP }; + var relayAddr = new RelayAddress { Port = port, EndpointPort = endpointPort, Address = publicIP, EndpointAddress = serverIP }; if (availableRelayServers.ContainsKey(relayAddr)) { @@ -121,7 +121,7 @@ namespace LightReflectiveMirror.LoadBalancing for (int i = 0; i < keys.Count; i++) { - string url = $"http://{keys[i].Address}:{keys[i].EndpointPort}{API_PATH}"; + string url = $"http://{keys[i].EndpointAddress}:{keys[i].EndpointPort}{API_PATH}"; using (WebClient wc = new WebClient()) { @@ -206,12 +206,14 @@ namespace LightReflectiveMirror.LoadBalancing } // container for relay address info - [Serializable] + [JsonObject(MemberSerialization.OptOut)] public struct RelayAddress { public ushort Port; public ushort EndpointPort; public string Address; + [JsonIgnore] + public string EndpointAddress; } [Serializable] diff --git a/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Program/Program.cs b/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Program/Program.cs index f175636..988f5f4 100644 --- a/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Program/Program.cs +++ b/ServerProject-DONT-IMPORT-INTO-UNITY/LRM/Program/Program.cs @@ -23,7 +23,8 @@ namespace LightReflectiveMirror WriteTitle(); instance = this; _startupTime = DateTime.Now; - publicIP = new WebClient().DownloadString("http://icanhazip.com").Replace("\\r\\n", "").Replace("\\n", "").Trim(); + using (WebClient wc = new WebClient()) + publicIP = wc.DownloadString("http://icanhazip.com").Replace("\\r", "").Replace("\\n", "").Trim(); if (!File.Exists(CONFIG_PATH)) { @@ -204,6 +205,7 @@ namespace LightReflectiveMirror authReq.Headers.Add("Auth", conf.LoadBalancerAuthKey); authReq.Headers.Add("EndpointPort", endpointPort); authReq.Headers.Add("GamePort", gamePort); + authReq.Headers.Add("PIP", publicIP); // Public IP var res = await authReq.GetResponseAsync();