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