NetworkDiscovery via transport.ServerAddress()

This commit is contained in:
vis2k 2021-05-27 19:35:51 +08:00
parent 0198551cc9
commit 30ce805ae7
2 changed files with 15 additions and 9 deletions

View File

@ -59,7 +59,7 @@ protected override ServerResponse ProcessRequest(ServerRequest request, IPEndPoi
return new ServerResponse
{
serverId = ServerId,
uri = transport.ServerUri()
address = transport.ServerAddress()
};
}
catch (NotImplementedException)
@ -98,13 +98,19 @@ protected override void ProcessResponse(ServerResponse response, IPEndPoint endp
// although we got a supposedly valid url, we may not be able to resolve
// the provided host
// TODO Y THO???????
// However we know the real ip address of the server because we just
// received a packet from it, so use that as host.
UriBuilder realUri = new UriBuilder(response.uri)
// UriBuilder realUri = new UriBuilder(response.uri)
// {
// Host = response.EndPoint.Address.ToString()
// };
// response.uri = realUri.Uri;
if (Utils.ParseHostAndPort(response.address, out string _, out ushort port))
{
Host = response.EndPoint.Address.ToString()
};
response.uri = realUri.Uri;
response.address = $"{response.EndPoint.Address}:{port}";
}
OnServerFound.Invoke(response);
}

View File

@ -1,5 +1,4 @@
using System;
using System.Net;
using System.Net;
namespace Mirror.Discovery
{
@ -10,7 +9,8 @@ public struct ServerResponse : NetworkMessage
// client fills this up after we receive it
public IPEndPoint EndPoint { get; set; }
public Uri uri;
// Transport.ServerAddress(). can be "IP:Port".
public string address;
// Prevent duplicate server appearance when a connection can be made via LAN on multiple NICs
public long serverId;