示例#1
0
 /// <summary>
 /// Processes all events appeared since last call
 /// </summary>
 public override void ProcessEvents()
 {
     while (peerConnectionAttemptMessages.TryDequeue(out ENetPeerConnectionAttemptMessage connection_attempt_message))
     {
         ENetPeer peer = new ENetPeer(Guid.NewGuid(), connection_attempt_message.Peer, this);
         OnPeerConnectionAttempted?.Invoke(peer);
         if (IsConnectionAllowed(peer))
         {
             peers.Add(peer.GUID.ToString(), peer);
             peerIDToPeerLookup.Add(peer.Peer.ID, peer);
             OnPeerConnected?.Invoke(peer);
         }
         else
         {
             connection_attempt_message.Peer.Disconnect((uint)EDisconnectionReason.Banned);
         }
     }
     while (peerDisconnectionMessages.TryDequeue(out ENetPeerDisconnectionMessage disconnection_message))
     {
         RemovePeer(disconnection_message.Peer);
     }
     while (peerTimeOutMessages.TryDequeue(out ENetPeerTimeOutMessage time_out_message))
     {
         RemovePeer(time_out_message.Peer);
     }
     while (peerReceiveMessages.TryDequeue(out ENetPeerReceiveMessage receive_message))
     {
         if (peerIDToPeerLookup.ContainsKey(receive_message.Peer.ID))
         {
             OnPeerMessageReceived?.Invoke(peerIDToPeerLookup[receive_message.Peer.ID], receive_message.Message);
         }
     }
 }
 /// <summary>
 /// Processes all events
 /// </summary>
 public override void ProcessEvents()
 {
     while (localPeerConnectionAttemptMessages.TryDequeue(out LocalPeerConnectionAttemptMessage local_peer_connection_attempt_message))
     {
         IPeer peer = local_peer_connection_attempt_message.Peer;
         OnPeerConnectionAttempted?.Invoke(peer);
         if (IsConnectionAllowed(peer))
         {
             peers.Add(peer.GUID.ToString(), peer);
             OnPeerConnected?.Invoke(peer);
         }
         else
         {
             local_peer_connection_attempt_message.Peer.Disconnect(EDisconnectionReason.Banned);
         }
     }
     while (localPeerDisconnectionMessages.TryDequeue(out LocalPeerDisconnectionMessage local_peer_disconnection_message))
     {
         IPeer  peer = local_peer_disconnection_message.Peer;
         string key  = peer.GUID.ToString();
         if (peers.ContainsKey(key))
         {
             OnPeerDisconnected?.Invoke(peer);
             peers.Remove(key);
         }
         foreach (KeyValuePair <string, ILocalPeer> peer_peer in peerPeerLookup)
         {
             if (peer.GUID == peer_peer.Value.GUID)
             {
                 peerPeerLookup.Remove(peer_peer.Key);
                 break;
             }
         }
     }
     while (localPeerReceiveMessages.TryDequeue(out LocalPeerReceiveMessage local_peer_receive_message))
     {
         OnPeerMessageReceived?.Invoke(local_peer_receive_message.Peer, Compression.Decompress(local_peer_receive_message.Message, local_peer_receive_message.Index, local_peer_receive_message.Length));
     }
 }