Example #1
0
        public bool HandlePacket(Peer peer, byte[] data, Channel channelId)
        {
            var header    = new PacketHeader(data);
            var convertor = GetConvertor(header.Cmd, channelId);

            switch (header.Cmd)
            {
            case PacketCmd.PKT_C2S_STATS_CONFIRM:
            case PacketCmd.PKT_C2S_MOVE_CONFIRM:
            case PacketCmd.PKT_C2S_VIEW_REQ:
                break;
            }

            if (convertor != null)
            {
                //TODO: improve dictionary reverse search
                ulong   playerId = _peers.First(x => x.Value.Address.Equals(peer.Address)).Key;
                dynamic req      = convertor(data);
                // TODO: fix all to use ulong
                _netReq.OnMessage((int)playerId, req);
                return(true);
            }

            PrintPacket(data, "Error: ");
            return(false);
        }