Ejemplo n.º 1
0
        public void PollEvents()
        {
            while (controller.TryReceiveEvent(out NetEvent evnt))
            {
                var peer = evnt.Peer;

                // No events should fire if the user closed the peer
                if (peer.ClosedByUser == false)
                {
                    switch (evnt.EventType)
                    {
                    case NetEventType.PeerConnected:
                        peer.SetCore(this);
                        peer.OnPeerConnected();
                        PeerConnected?.Invoke(peer, peer.Token);
                        break;

                    case NetEventType.PeerClosed:
                        peer.OnPeerClosed(evnt.CloseReason, evnt.UserKickReason, evnt.SocketError);
                        PeerClosed?.Invoke(peer, evnt.CloseReason, evnt.UserKickReason, evnt.SocketError);
                        break;

                    case NetEventType.Payload:
                        peer.OnPayloadReceived(evnt.EncodedData, evnt.EncodedLength);
                        PeerPayload?.Invoke(peer, evnt.EncodedData, evnt.EncodedLength);
                        break;

                    case NetEventType.Notification:
                        peer.OnNotificationReceived(evnt.EncodedData, evnt.EncodedLength);
                        PeerNotification?.Invoke(peer, evnt.EncodedData, evnt.EncodedLength);
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }

                controller.RecycleEvent(evnt);
            }
        }
Ejemplo n.º 2
0
 internal void OnPeerClosed(NetCloseReason reason, byte userKickReason, SocketError error)
 {
     PeerClosed?.Invoke(this, reason, userKickReason, error);
 }