Пример #1
0
 private void Remove()
 {
     if (Packets.Contains(SelectedPacket))
     {
         Packets.Remove(SelectedPacket);
     }
     if (FilteredPackets.Contains(SelectedPacket))
     {
         FilteredPackets.Remove(SelectedPacket);
     }
 }
Пример #2
0
        public void Listen()
        {
            Validate();
            NetIncomingMessage message = NetPeer.ReadMessage();

            if (message == null)
            {
                return;
            }
            switch (message.MessageType)
            {
            case NetIncomingMessageType.Data:
                int packetHeader = message.ReadInt32();
                if (Packets.Contains(packetHeader))
                {
                    Packets[packetHeader]?.Invoke(this, new PacketRecievedEventArgs(message.SenderConnection, message));
                }

                break;

            case NetIncomingMessageType.StatusChanged:
                switch (message.SenderConnection.Status)
                {
                case NetConnectionStatus.Connected:
                    OnConnected(new ConnectionEventArgs(message.SenderConnection, message));
                    break;

                case NetConnectionStatus.Disconnected:
                    OnDisconnected(new ConnectionEventArgs(message.SenderConnection, message));
                    break;
                }
                break;

            default:
                if (incomingMessageHandlers.ContainsKey(message.MessageType))
                {
                    incomingMessageHandlers[message.MessageType](this, new IncomingMessageEventArgs(message));
                }
                break;
            }

            NetPeer.Recycle(message);
        }