コード例 #1
0
ファイル: NetCore.cs プロジェクト: slango0513/Papagei
        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);
            }
        }
コード例 #2
0
ファイル: NetPeer.cs プロジェクト: slango0513/Papagei
 internal void OnPeerClosed(NetCloseReason reason, byte userKickReason, SocketError error)
 {
     PeerClosed?.Invoke(this, reason, userKickReason, error);
 }