Update LightReflectiveMirrorTransport.cs

This commit is contained in:
cxxpxr 2021-04-07 14:35:47 -04:00 committed by GitHub
parent d3006273b6
commit 3e82fcc75a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,10 @@ namespace LightReflectiveMirror
public bool IsAuthenticated() => _isAuthenticated;
private void Awake()
{
#if !NET_4_6
throw new Exception("LRM | Please switch to .NET 4.x for LRM to function properly!");
#endif
if (clientToServerTransport is LightReflectiveMirrorTransport)
throw new Exception("Haha real funny... Use a different transport.");
@ -59,7 +63,6 @@ namespace LightReflectiveMirror
_connectedToRelay = false;
_isAuthenticated = false;
diconnectedFromRelay?.Invoke();
serverStatus = "Disconnected from relay.";
}
public void ConnectToRelay()
@ -100,9 +103,7 @@ namespace LightReflectiveMirror
SetTransportPort(port);
this.serverIP = serverIP;
serverStatus = "Connecting to relay...";
_clientSendBuffer = new byte[clientToServerTransport.GetMaxPacketSize()];
clientToServerTransport.ClientConnect(serverIP);
}
@ -151,11 +152,9 @@ namespace LightReflectiveMirror
switch (opcode)
{
case OpCodes.Authenticated:
serverStatus = "Authenticated! Good to go!";
_isAuthenticated = true;
break;
case OpCodes.AuthenticationRequest:
serverStatus = "Sent authentication to relay...";
SendAuthKey();
break;
case OpCodes.GetData:
@ -189,7 +188,7 @@ namespace LightReflectiveMirror
}
break;
case OpCodes.RoomCreated:
serverId = data.ReadString(ref pos);
serverId = data.ReadInt(ref pos);
break;
case OpCodes.ServerJoined:
int clientId = data.ReadInt(ref pos);
@ -262,7 +261,7 @@ namespace LightReflectiveMirror
if (!IPAddress.TryParse(serverIP, out serverAddr))
serverAddr = Dns.GetHostEntry(serverIP).AddressList[0];
_relayPuncherIP = new IPEndPoint(serverAddr, NATPunchtroughPort);
_relayPuncherIP = new IPEndPoint(IPAddress.Parse(serverIP), NATPunchtroughPort);
// Send 3 to lower chance of it being dropped or corrupted when received on server.
_NATPuncher.Send(initalData, sendPos, _relayPuncherIP);
@ -332,7 +331,7 @@ namespace LightReflectiveMirror
}
}
Room GetServerForID(string serverID)
Room GetServerForID(int serverID)
{
for(int i = 0; i < relayServerList.Count; i++)
{
@ -340,7 +339,6 @@ namespace LightReflectiveMirror
return relayServerList[i];
}
OnClientDisconnected?.Invoke();
throw new Exception("LRM | An attempt was made to connect to a server which does not exist!");
}
@ -379,7 +377,7 @@ namespace LightReflectiveMirror
{
public string serverName;
public int maxPlayers;
public string serverId;
public int serverId;
public string serverData;
public int hostId;
public List<int> clients;