Пример #1
0
        private async Task DispatchIncomingPacket()
        {
            using (var bufferScope = _bufferPool.CreateScope())
            {
                var packet = _uncompressedPacketObjectPool.Get();
                try
                {
                    if (_useCompression)
                    {
                        var compressedPacket = await CompressedPacket.DeserializeAsync(_remoteStream, null);

                        packet = PacketCompress.Decompress(compressedPacket, bufferScope, 0, packet);
                    }
                    else
                    {
                        packet = await UncompressedPacket.DeserializeAsync(_remoteStream, bufferScope, packet);
                    }

                    await DispatchIncomingPacket(packet);
                }
                finally
                {
                    _uncompressedPacketObjectPool.Return(packet);
                }
            }
        }
Пример #2
0
 private async Task SendOutcomingPacket(object packetOrCommand)
 {
     if (packetOrCommand == null)
     {
         _tcpClient.Client.Shutdown(SocketShutdown.Send);
         _outcomingPacketDispatcher.Complete();
     }
     else if (packetOrCommand == _useCompressionPacket)
     {
         _useCompression = true;
     }
     else if (packetOrCommand is UncompressedPacket packet)
     {
         using (var bufferScope = _bufferPool.CreateScope())
         {
             if (_useCompression)
             {
                 var newPacket = PacketCompress.Compress(packet, bufferScope, _compressThreshold);
                 await newPacket.SerializeAsync(_remoteStream);
             }
             else
             {
                 await packet.SerializeAsync(_remoteStream);
             }
         }
     }
 }
Пример #3
0
        public void ChannelList(Session s, PacketRead r)
        {
            PacketWrite p = new PacketWrite();

            p.HexArray("00 00 00 06 00 00 00 01 00 00 00 14 46 00 72 00 65 00 65 00 20 00 43 00 6C 00 61 00 73 00 73 00 01 2C 00 00 03 00 00 00 00 02 00 00 00 1C 42 00 65 00 67 00 69 00 6E 00 6E 00 65 00 72 00 20 00 43 00 6C 00 61 00 73 00 73 00 01 2C 00 00 04 00 00 00 00 03 00 00 00 18 4D 00 69 00 64 00 64 00 6C 00 65 00 20 00 43 00 6C 00 61 00 73 00 73 00 01 2C 00 00 05 00 00 00 00 04 00 00 00 1C 53 00 75 00 70 00 65 00 72 00 69 00 6F 00 72 00 20 00 43 00 6C 00 61 00 73 00 73 00 01 2C 00 00 06 00 00 00 00 05 00 00 00 18 4D 00 61 00 73 00 74 00 65 00 72 00 20 00 43 00 6C 00 61 00 73 00 73 00 01 2C 00 00 07 00 00 00 00 06 00 00 00 0E 44 00 75 00 6E 00 67 00 65 00 6F 00 6E 00 01 2C 01 24 00 00");
            s.SendPacket(PacketCompress.EnterChannelCompress(p.Get_Packet()), 47);
        }
Пример #4
0
 private async Task SendOutcomingPacket(UncompressedPacket packet)
 {
     if (_useCompression)
     {
         var newPacket = PacketCompress.Compress(ref packet);
         await newPacket.SerializeAsync(_remoteStream);
     }
     else
     {
         await packet.SerializeAsync(_remoteStream);
     }
 }
Пример #5
0
        public void UsersList(Session s, PacketRead r)
        {
            PacketWrite pw = new PacketWrite();

            pw.Int(GameServer.UsersList.Count);
            for (int i = 0; i < GameServer.UsersList.Count; i++)
            {
                pw.Int(GameServer.UsersList[i].PInfo.m_dwUserUID);//id
                pw.UnicodeStr(GameServer.UsersList[i].PInfo.m_strLogin);
                pw.Byte((byte)11);
                pw.HexArray("00 13 00 00 00 00 00");
            }
            s.SendPacket(PacketCompress.HalfCompress(pw.Get_Packet()), 51);
        }
Пример #6
0
        private async Task DispatchIncomingPacket()
        {
            UncompressedPacket packet;

            if (_useCompression)
            {
                var compressedPacket = await CompressedPacket.DeserializeAsync(_remoteStream);

                packet = PacketCompress.Decompress(ref compressedPacket);
            }
            else
            {
                packet = await UncompressedPacket.DeserializeAsync(_remoteStream);
            }
            await DispatchIncomingPacket(packet);
        }
Пример #7
0
 private async Task SendOutcomingPacket(UncompressedPacket packet)
 {
     // Close
     if (packet == null)
     {
         _tcpClient.Client.Shutdown(SocketShutdown.Send);
         _outcomingPacketDispatcher.Complete();
     }
     else if (_useCompression)
     {
         var newPacket = PacketCompress.Compress(ref packet);
         await newPacket.SerializeAsync(_remoteStream);
     }
     else
     {
         await packet.SerializeAsync(_remoteStream);
     }
 }
Пример #8
0
        public void ListRooms(Session p, PacketRead r)
        {
            try
            {
                byte RoomType = r.Byte();
                byte RoomMode = r.Byte();

                int RoomsCount = 0;
                foreach (ushort i in GameServer.List_Rooms.Keys)
                {
                    if (p.PInfo.m_dwChannelUID == 6)
                    {
                        if (RoomMode != GameServer.List_Rooms[i].m_iGameMode)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (GameServer.List_Rooms[i].m_cGameCategory != 0)
                        {
                            continue;
                        }
                    }
                    if (RoomType == 1)
                    {
                        if (GameServer.List_Rooms[i].m_bPlaying == true || GameServer.List_Rooms[i].m_abTotalSlotsOpen() == 0)
                        {
                            continue;
                        }
                    }
                    RoomsCount += 1;
                }

                PacketWrite pw = new PacketWrite();
                pw.Int(RoomsCount);

                foreach (ushort RoomPosition in GameServer.List_Rooms.Keys)
                {
                    if (p.PInfo.m_dwChannelUID == 6)
                    {
                        if (RoomMode != GameServer.List_Rooms[RoomPosition].m_iGameMode)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (GameServer.List_Rooms[RoomPosition].m_cGameCategory != 0)
                        {
                            continue;
                        }
                    }

                    if (RoomType == 1)
                    {
                        if (GameServer.List_Rooms[RoomPosition].m_bPlaying == true || GameServer.List_Rooms[RoomPosition].m_abTotalSlotsOpen() == 0)
                        {
                            continue;
                        }
                    }

                    pw.UShort(GameServer.List_Rooms[RoomPosition].m_usRoomID);
                    pw.UnicodeStr(GameServer.List_Rooms[RoomPosition].m_strRoomName);

                    if (GameServer.List_Rooms[RoomPosition].m_strRoomPasswd.Length > 0)
                    {
                        pw.Bool(false);
                    }
                    else
                    {
                        pw.Bool(true);
                    }

                    pw.Byte(0);
                    pw.UnicodeStr(GameServer.List_Rooms[RoomPosition].m_strRoomPasswd);
                    pw.Short((short)(GameServer.List_Rooms[RoomPosition].m_abTotalSlotsOpen() + 1));
                    pw.Short(GameServer.List_Rooms[RoomPosition].m_usUsers());
                    pw.Bool(GameServer.List_Rooms[RoomPosition].m_bPlaying);
                    pw.HexArray("6F 0C CC FA 0B 08 00 00 00 20 63 00 00 F5 00 00 00 03 00 00 00 00");
                    pw.Short(0);
                    pw.Short(GameServer.List_Rooms[RoomPosition].m_usUsers());
                    for (int x = 0; x < GameServer.List_Rooms[RoomPosition].m_usMaxUsers; x++)
                    {
                        if (GameServer.List_Rooms[RoomPosition].m_dwSlots[x].Active)
                        {
                            pw.UnicodeStr(GameServer.List_Rooms[RoomPosition].m_dwSlots[x].usr.PInfo.m_strNickName);
                            pw.Byte(11);
                        }
                    }
                    pw.HexArray("00 00 00 00 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 04 42 00 52 00 00 00 00 00 07 00 00 00 00 FF FF FF FF");
                }
                p.SendPacket(PacketCompress.HalfCompress(pw.Get_Packet()), 49);
            }
            catch
            {
                PacketWrite pw = new PacketWrite();
                pw.Int(0);
                p.SendPacket(PacketCompress.HalfCompress(pw.Get_Packet()), 49);
            }
        }