/// <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)); } }
private void HandleConnectAccept( NetPeer peer, byte[] buffer, int length) { NetDebug.Assert(peer.IsClient == false, "Ignoring accept from client"); if (peer.IsConnected || peer.IsClient) { return; } peer.OnReceiveOther(Time); peer.Connected(); eventOut.Enqueue( CreateEvent(NetEventType.PeerConnected, peer)); }
private void HandleKick( NetPeer peer, byte[] buffer, int length) { if (peer.IsClosed) { return; } byte rawReason; byte userReason; bool success = NetEncoding.ReadProtocol( buffer, length, out rawReason, out userReason); // Validate if (success == false) { NetDebug.LogError("Error reading kick"); return; } NetCloseReason closeReason = (NetCloseReason)rawReason; // Skip the packet if it's a bad reason (this will cause error output) if (NetUtil.ValidateKickReason(closeReason) == NetCloseReason.INVALID) { return; } peer.OnReceiveOther(this.Time); this.ClosePeerSilent(peer); this.eventOut.Enqueue( this.CreateClosedEvent(peer, closeReason, userReason)); }