Skip to content

Commit 171950f

Browse files
committed
Change to IP address get function
1 parent 4ea9f67 commit 171950f

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

Assets/scripts/PlayerControl.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@ public void updateLocation(Vector3 changeposition, GameObject thegameobject, bo
255255
[Command(requiresAuthority = false)]
256256
public void GetLocalIPv4()
257257
{
258-
serverIPaddress = Dns.GetHostEntry(Dns.GetHostName())
259-
.AddressList.First(
260-
f => f.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
261-
.ToString();
258+
string externalIpString = new WebClient().DownloadString("http://icanhazip.com").Replace("\\r\\n", "").Replace("\\n", "").Trim();
259+
var externalIp = IPAddress.Parse(serverIPaddress);
260+
serverIPaddress = externalIp.ToString();
261+
262262
port = NetworkManager.singleton.GetComponent<kcp2k.KcpTransport>().Port;
263263
Debug.Log($"Port = {port}, ipaddress = {serverIPaddress}");
264264
}

Assets/scripts/UIManager.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ public void transferMap(bool hostOrNot)
348348
manager.networkAddress = splitAddress[0];
349349

350350
if (splitAddress.Length > 1 && !String.IsNullOrEmpty(splitAddress[1])) //if there's a port
351-
352351
{
353352
NetworkManager.singleton.GetComponent<kcp2k.KcpTransport>().Port = ushort.Parse(splitAddress[1]);
354353
}

0 commit comments

Comments
 (0)