Ejemplo n.º 1
0
        public async void HandlePackets()
        {
            while (true)
            {
                while (this.packetQueue.TryDequeue(out PacketQueueEntry queueEntry))
                {
                    switch (queueEntry.PacketId)
                    {
                    case PacketId.PACKET_ID_PLAYER_JOIN:
                        HandlePlayerJoin(queueEntry.Client);
                        break;

                    case PacketId.PACKET_ID_PLAYER_JOINDATA:
                        PlayerJoinDataPacket joinDataPacket = new PlayerJoinDataPacket();
                        joinDataPacket.Read(queueEntry.Data);
                        HandlePlayerJoinData(queueEntry.Client, joinDataPacket);
                        break;

                    case PacketId.PACKET_ID_PLAYER_QUIT:
                    case PacketId.PACKET_ID_PLAYER_TIMEOUT:
                        HandlePlayerQuit(queueEntry.Client);
                        break;
                    }
                }
                await Task.Delay(this.sleepInterval);
            }
        }
        protected override void HandlePacket(PacketQueueEntry queueEntry)
        {
            switch (queueEntry.PacketId)
            {
            case PacketId.PACKET_ID_PLAYER_JOIN:
                HandleClientJoin(queueEntry.Client);
                break;

            case PacketId.PACKET_ID_PLAYER_JOINDATA:
                PlayerJoinDataPacket joinDataPacket = new PlayerJoinDataPacket();
                joinDataPacket.Read(queueEntry.Data);
                HandleClientJoinData(queueEntry.Client, joinDataPacket);
                break;

            case PacketId.PACKET_ID_PLAYER_QUIT:
            case PacketId.PACKET_ID_PLAYER_TIMEOUT:
                HandleClientQuit(queueEntry.Client);
                break;
            }
        }