Revert "Update LightReflectiveMirrorTransport.cs"

This reverts commit 3e82fcc75a.
This commit is contained in:
Derek S 2021-04-07 13:38:06 -05:00
parent 3e82fcc75a
commit cc84f21812

View file

@ -21,10 +21,6 @@ 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.");
@ -63,6 +59,7 @@ namespace LightReflectiveMirror
_connectedToRelay = false; _connectedToRelay = false;
_isAuthenticated = false; _isAuthenticated = false;
diconnectedFromRelay?.Invoke(); diconnectedFromRelay?.Invoke();
serverStatus = "Disconnected from relay.";
} }
public void ConnectToRelay() public void ConnectToRelay()
@ -103,7 +100,9 @@ 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);
} }
@ -152,9 +151,11 @@ 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:
@ -188,7 +189,7 @@ namespace LightReflectiveMirror
} }
break; break;
case OpCodes.RoomCreated: case OpCodes.RoomCreated:
serverId = data.ReadInt(ref pos); serverId = data.ReadString(ref pos);
break; break;
case OpCodes.ServerJoined: case OpCodes.ServerJoined:
int clientId = data.ReadInt(ref pos); int clientId = data.ReadInt(ref pos);
@ -261,7 +262,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(IPAddress.Parse(serverIP), NATPunchtroughPort); _relayPuncherIP = new IPEndPoint(serverAddr, 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);
@ -331,7 +332,7 @@ namespace LightReflectiveMirror
} }
} }
Room GetServerForID(int serverID) Room GetServerForID(string serverID)
{ {
for(int i = 0; i < relayServerList.Count; i++) for(int i = 0; i < relayServerList.Count; i++)
{ {
@ -339,6 +340,7 @@ 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!");
} }
@ -377,7 +379,7 @@ namespace LightReflectiveMirror
{ {
public string serverName; public string serverName;
public int maxPlayers; public int maxPlayers;
public int serverId; public string serverId;
public string serverData; public string serverData;
public int hostId; public int hostId;
public List<int> clients; public List<int> clients;