Skip to content
This repository has been archived by the owner on Sep 5, 2022. It is now read-only.

Commit

Permalink
Added support for mirror 41
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek-R-S committed Jun 14, 2021
1 parent f988f2d commit cfbfd90
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,20 @@ public void ClientDisconnect()

public void ServerSend(int clientID, ArraySegment<byte> data, int channel)
{
#if MIRROR_40_0_OR_NEWER
directConnectTransport.ServerSend(clientID, data, channel);
#else
directConnectTransport.ServerSend(clientID, channel, data);
#endif
}

public void ClientSend(ArraySegment<byte> data, int channel)
{
#if MIRROR_40_0_OR_NEWER
directConnectTransport.ClientSend(data, channel);
#else
directConnectTransport.ClientSend(channel, data);
#endif
}

#region Transport Callbacks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public void DirectDisconnected()

_isClient = true;

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new System.ArraySegment<byte>(_clientSendBuffer, 0, pos), 0);
#else
clientToServerTransport.ClientSend(0, new System.ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif
}

if (_clientProxy != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ public override void ClientConnect(string address)
}

_isClient = true;

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new System.ArraySegment<byte>(_clientSendBuffer, 0, pos), 0);
#else
clientToServerTransport.ClientSend(0, new System.ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif

}
else
Expand All @@ -112,14 +115,23 @@ public override void ClientDisconnect()
{
int pos = 0;
_clientSendBuffer.WriteByte(ref pos, (byte)OpCodes.LeaveRoom);
#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new ArraySegment<byte>(_clientSendBuffer, 0, pos), 0);
#else
clientToServerTransport.ClientSend(0, new ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif
}

if (_directConnectModule != null)
_directConnectModule.ClientDisconnect();
}

#if MIRROR_40_0_OR_NEWER
public override void ClientSend(ArraySegment<byte> segment, int channelId)
#else
public override void ClientSend(int channelId, ArraySegment<byte> segment)

#endif
{
if (_directConnected)
{
Expand All @@ -131,8 +143,11 @@ public override void ClientSend(int channelId, ArraySegment<byte> segment)
_clientSendBuffer.WriteByte(ref pos, (byte)OpCodes.SendData);
_clientSendBuffer.WriteBytes(ref pos, segment.Array.Take(segment.Count).ToArray());
_clientSendBuffer.WriteInt(ref pos, 0);

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new ArraySegment<byte>(_clientSendBuffer, 0, pos), channelId);
#else
clientToServerTransport.ClientSend(channelId, new ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif
}
}

Expand Down Expand Up @@ -168,7 +183,11 @@ public override bool ServerDisconnect(int connectionId)
}
#endif

#if MIRROR_40_0_OR_NEWER
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId)
#else
public override void ServerSend(int connectionId, int channelId, ArraySegment<byte> segment)
#endif
{
if (_directConnectModule != null && _connectedDirectClients.TryGetBySecond(connectionId, out int directId))
{
Expand All @@ -180,8 +199,11 @@ public override void ServerSend(int connectionId, int channelId, ArraySegment<by
_clientSendBuffer.WriteByte(ref pos, (byte)OpCodes.SendData);
_clientSendBuffer.WriteBytes(ref pos, segment.Array.Take(segment.Count).ToArray());
_clientSendBuffer.WriteInt(ref pos, _connectedRelayClients.GetBySecond(connectionId));

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new ArraySegment<byte>(_clientSendBuffer, 0, pos), channelId);
#else
clientToServerTransport.ClientSend(channelId, new ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif
}
}

Expand Down Expand Up @@ -240,8 +262,11 @@ public override void ServerStart()
_clientSendBuffer.WriteBool(ref pos, false);
_clientSendBuffer.WriteInt(ref pos, _directConnectModule == null ? 1 : _directConnectModule.SupportsNATPunch() ? _directConnectModule.GetTransportPort() : 1);
}

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new ArraySegment<byte>(_clientSendBuffer, 0, pos), 0);
#else
clientToServerTransport.ClientSend(0, new ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif
}

public override void ServerStop()
Expand All @@ -252,7 +277,11 @@ public override void ServerStop()
int pos = 0;
_clientSendBuffer.WriteByte(ref pos, (byte)OpCodes.LeaveRoom);

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new ArraySegment<byte>(_clientSendBuffer, 0, pos), 0);
#else
clientToServerTransport.ClientSend(0, new ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif

if (_directConnectModule != null)
_directConnectModule.StopServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ IEnumerator JoinOtherRelayAndMatch(Room? roomValue, string ID)

_isClient = true;

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new System.ArraySegment<byte>(_clientSendBuffer, 0, pos), 0);
#else
clientToServerTransport.ClientSend(0, new System.ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif
}

IEnumerator GetServerList(LRMRegions region)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ void SendHeartbeat()
// Send a blank message with just the opcode 200, which is heartbeat
int pos = 0;
_clientSendBuffer.WriteByte(ref pos, 200);

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new ArraySegment<byte>(_clientSendBuffer, 0, pos), 0);
#else
clientToServerTransport.ClientSend(0, new ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif

// If NAT Puncher is initialized, send heartbeat on that as well.

Expand Down Expand Up @@ -339,7 +344,11 @@ public void UpdateRoomName(string newServerName = "My Awesome Server!")
_clientSendBuffer.WriteBool(ref pos, false);
_clientSendBuffer.WriteBool(ref pos, false);

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new ArraySegment<byte>(_clientSendBuffer, 0, pos), 0);
#else
clientToServerTransport.ClientSend(0, new ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif
}
}

Expand All @@ -355,8 +364,11 @@ public void UpdateRoomData(string newServerData = "Extra Data!")
_clientSendBuffer.WriteString(ref pos, newServerData);
_clientSendBuffer.WriteBool(ref pos, false);
_clientSendBuffer.WriteBool(ref pos, false);

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new ArraySegment<byte>(_clientSendBuffer, 0, pos), 0);
#else
clientToServerTransport.ClientSend(0, new ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif
}
}

Expand All @@ -373,7 +385,11 @@ public void UpdateRoomVisibility(bool isPublic = true)
_clientSendBuffer.WriteBool(ref pos, isPublic);
_clientSendBuffer.WriteBool(ref pos, false);

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new ArraySegment<byte>(_clientSendBuffer, 0, pos), 0);
#else
clientToServerTransport.ClientSend(0, new ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif
}
}

Expand All @@ -390,7 +406,11 @@ public void UpdateRoomPlayerCount(int maxPlayers = 16)
_clientSendBuffer.WriteBool(ref pos, true);
_clientSendBuffer.WriteInt(ref pos, maxPlayers);

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new ArraySegment<byte>(_clientSendBuffer, 0, pos), 0);
#else
clientToServerTransport.ClientSend(0, new ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif
}
}

Expand All @@ -410,7 +430,12 @@ void SendAuthKey()
int pos = 0;
_clientSendBuffer.WriteByte(ref pos, (byte)OpCodes.AuthenticationResponse);
_clientSendBuffer.WriteString(ref pos, authenticationKey);

#if MIRROR_40_0_OR_NEWER
clientToServerTransport.ClientSend(new ArraySegment<byte>(_clientSendBuffer, 0, pos), 0);
#else
clientToServerTransport.ClientSend(0, new ArraySegment<byte>(_clientSendBuffer, 0, pos));
#endif
}

public enum OpCodes
Expand Down

0 comments on commit cfbfd90

Please sign in to comment.