Fixed wrong IP getting sent to unity client
This commit is contained in:
parent
e464ebc26f
commit
bdee2d039b
3 changed files with 11 additions and 6 deletions
|
|
@ -30,6 +30,7 @@ namespace LightReflectiveMirror.LoadBalancing
|
||||||
string receivedAuthKey = req.Headers["Auth"];
|
string receivedAuthKey = req.Headers["Auth"];
|
||||||
string endpointPort = req.Headers["EndpointPort"];
|
string endpointPort = req.Headers["EndpointPort"];
|
||||||
string gamePort = req.Headers["GamePort"];
|
string gamePort = req.Headers["GamePort"];
|
||||||
|
string publicIP = req.Headers["PIP"];
|
||||||
|
|
||||||
string address = context.Request.RemoteEndPoint.Address.ToString();
|
string address = context.Request.RemoteEndPoint.Address.ToString();
|
||||||
|
|
||||||
|
|
@ -46,7 +47,7 @@ namespace LightReflectiveMirror.LoadBalancing
|
||||||
{
|
{
|
||||||
var _gamePort = Convert.ToUInt16(gamePort);
|
var _gamePort = Convert.ToUInt16(gamePort);
|
||||||
var _endpointPort = Convert.ToUInt16(endpointPort);
|
var _endpointPort = Convert.ToUInt16(endpointPort);
|
||||||
await Program.instance.AddServer(address, _gamePort, _endpointPort);
|
await Program.instance.AddServer(address, _gamePort, _endpointPort, publicIP);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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))
|
if (availableRelayServers.ContainsKey(relayAddr))
|
||||||
{
|
{
|
||||||
|
|
@ -121,7 +121,7 @@ namespace LightReflectiveMirror.LoadBalancing
|
||||||
|
|
||||||
for (int i = 0; i < keys.Count; i++)
|
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())
|
using (WebClient wc = new WebClient())
|
||||||
{
|
{
|
||||||
|
|
@ -206,12 +206,14 @@ namespace LightReflectiveMirror.LoadBalancing
|
||||||
}
|
}
|
||||||
|
|
||||||
// container for relay address info
|
// container for relay address info
|
||||||
[Serializable]
|
[JsonObject(MemberSerialization.OptOut)]
|
||||||
public struct RelayAddress
|
public struct RelayAddress
|
||||||
{
|
{
|
||||||
public ushort Port;
|
public ushort Port;
|
||||||
public ushort EndpointPort;
|
public ushort EndpointPort;
|
||||||
public string Address;
|
public string Address;
|
||||||
|
[JsonIgnore]
|
||||||
|
public string EndpointAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ namespace LightReflectiveMirror
|
||||||
WriteTitle();
|
WriteTitle();
|
||||||
instance = this;
|
instance = this;
|
||||||
_startupTime = DateTime.Now;
|
_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))
|
if (!File.Exists(CONFIG_PATH))
|
||||||
{
|
{
|
||||||
|
|
@ -204,6 +205,7 @@ namespace LightReflectiveMirror
|
||||||
authReq.Headers.Add("Auth", conf.LoadBalancerAuthKey);
|
authReq.Headers.Add("Auth", conf.LoadBalancerAuthKey);
|
||||||
authReq.Headers.Add("EndpointPort", endpointPort);
|
authReq.Headers.Add("EndpointPort", endpointPort);
|
||||||
authReq.Headers.Add("GamePort", gamePort);
|
authReq.Headers.Add("GamePort", gamePort);
|
||||||
|
authReq.Headers.Add("PIP", publicIP); // Public IP
|
||||||
|
|
||||||
var res = await authReq.GetResponseAsync();
|
var res = await authReq.GetResponseAsync();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue