Added cross-relay connectivity
This commit is contained in:
parent
1e144d97f8
commit
9bcba0e004
3 changed files with 70 additions and 12 deletions
|
|
@ -68,20 +68,29 @@ namespace LightReflectiveMirror
|
|||
if (_isClient || _isServer)
|
||||
throw new Exception("Cannot connect while hosting/already connected!");
|
||||
|
||||
int pos = 0;
|
||||
_directConnected = false;
|
||||
_clientSendBuffer.WriteByte(ref pos, (byte)OpCodes.JoinServer);
|
||||
_clientSendBuffer.WriteInt(ref pos, _cachedHostID);
|
||||
_clientSendBuffer.WriteBool(ref pos, _directConnectModule != null);
|
||||
var room = GetServerForID(_cachedHostID);
|
||||
|
||||
if (GetLocalIp() == null)
|
||||
_clientSendBuffer.WriteString(ref pos, "0.0.0.0");
|
||||
if (!useLoadBalancer || room.relayInfo.Address == serverIP)
|
||||
{
|
||||
int pos = 0;
|
||||
_directConnected = false;
|
||||
_clientSendBuffer.WriteByte(ref pos, (byte)OpCodes.JoinServer);
|
||||
_clientSendBuffer.WriteInt(ref pos, _cachedHostID);
|
||||
_clientSendBuffer.WriteBool(ref pos, _directConnectModule != null);
|
||||
|
||||
if (GetLocalIp() == null)
|
||||
_clientSendBuffer.WriteString(ref pos, "0.0.0.0");
|
||||
else
|
||||
_clientSendBuffer.WriteString(ref pos, GetLocalIp());
|
||||
|
||||
_isClient = true;
|
||||
|
||||
clientToServerTransport.ClientSend(0, new System.ArraySegment<byte>(_clientSendBuffer, 0, pos));
|
||||
}
|
||||
else
|
||||
_clientSendBuffer.WriteString(ref pos, GetLocalIp());
|
||||
|
||||
_isClient = true;
|
||||
|
||||
clientToServerTransport.ClientSend(0, new System.ArraySegment<byte>(_clientSendBuffer, 0, pos));
|
||||
{
|
||||
StartCoroutine(JoinOtherRelayAndMatch(room));
|
||||
}
|
||||
}
|
||||
|
||||
public override void ClientDisconnect()
|
||||
|
|
|
|||
|
|
@ -58,6 +58,36 @@ namespace LightReflectiveMirror
|
|||
}
|
||||
}
|
||||
|
||||
IEnumerator JoinOtherRelayAndMatch(Room room)
|
||||
{
|
||||
// Wait for disconnection
|
||||
DisconnectFromRelay();
|
||||
|
||||
while (IsAuthenticated())
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
endpointServerPort = room.relayInfo.EndpointPort;
|
||||
Connect(room.relayInfo.Address, room.relayInfo.Port);
|
||||
|
||||
while (!IsAuthenticated())
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
int pos = 0;
|
||||
_directConnected = false;
|
||||
_clientSendBuffer.WriteByte(ref pos, (byte)OpCodes.JoinServer);
|
||||
_clientSendBuffer.WriteInt(ref pos, room.serverId);
|
||||
_clientSendBuffer.WriteBool(ref pos, _directConnectModule != null);
|
||||
|
||||
if (GetLocalIp() == null)
|
||||
_clientSendBuffer.WriteString(ref pos, "0.0.0.0");
|
||||
else
|
||||
_clientSendBuffer.WriteString(ref pos, GetLocalIp());
|
||||
|
||||
_isClient = true;
|
||||
|
||||
clientToServerTransport.ClientSend(0, new System.ArraySegment<byte>(_clientSendBuffer, 0, pos));
|
||||
}
|
||||
|
||||
IEnumerator GetServerList()
|
||||
{
|
||||
if (!useLoadBalancer)
|
||||
|
|
|
|||
|
|
@ -103,6 +103,14 @@ namespace LightReflectiveMirror
|
|||
clientToServerTransport.ClientConnect(serverIP);
|
||||
}
|
||||
|
||||
private void DisconnectFromRelay()
|
||||
{
|
||||
if (IsAuthenticated())
|
||||
{
|
||||
clientToServerTransport.ClientDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void SendHeartbeat()
|
||||
{
|
||||
if (_connectedToRelay)
|
||||
|
|
@ -318,6 +326,17 @@ namespace LightReflectiveMirror
|
|||
}
|
||||
}
|
||||
|
||||
Room GetServerForID(int serverID)
|
||||
{
|
||||
for(int i = 0; i < relayServerList.Count; i++)
|
||||
{
|
||||
if(relayServerList[i].serverId == serverId)
|
||||
return relayServerList[i];
|
||||
}
|
||||
|
||||
throw new Exception("LRM | An attempt was made to connect to a server which does not exist!");
|
||||
}
|
||||
|
||||
void SendAuthKey()
|
||||
{
|
||||
int pos = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue