/// <summary>
/// Handles an incoming connection request from a remote peer.
/// </summary>
private void HandleConnectRequest(
IPEndPoint source,
byte[] buffer,
int length)
{
bool success =
NetEncoding.ReadConnectRequest(
buffer,
out string version,
out string token);
// Validate
if (success == false)
{
NetDebug.LogError("Error reading connect request");
return;
}
if (ShouldCreatePeer(source, version))
{
long curTime = Time;
// Create and add the new peer as a client
NetPeer peer = new NetPeer(source, token, true, curTime);
peers.Add(source, peer);
peer.OnReceiveOther(curTime);
// Accept the connection over the network
sender.SendAccept(peer);
// Queue the event out to the main thread to receive the connection
eventOut.Enqueue(
CreateEvent(NetEventType.PeerConnected, peer));
}
}