示例#1
0
        public void SendPacket(ServerPacket packet)
        {
            if (!IsOpen())
            {
                return;
            }

            packet.LogPacket(_worldSession);
            packet.WritePacketData();

            var           data   = packet.GetData();
            ServerOpcodes opcode = packet.GetOpcode();

            PacketLog.Write(data, (uint)opcode, GetRemoteIpAddress(), GetRemotePort(), _connectType, false);

            ByteBuffer buffer = new ByteBuffer();

            int packetSize = data.Length;

            if (packetSize > 0x400 && _worldCrypt.IsInitialized)
            {
                buffer.WriteInt32(packetSize + 2);
                buffer.WriteUInt32(ZLib.adler32(ZLib.adler32(0x9827D8F1, BitConverter.GetBytes((ushort)opcode), 2), data, (uint)packetSize));

                byte[] compressedData;
                uint   compressedSize = CompressPacket(data, opcode, out compressedData);
                buffer.WriteUInt32(ZLib.adler32(0x9827D8F1, compressedData, compressedSize));
                buffer.WriteBytes(compressedData, compressedSize);

                packetSize = (ushort)(compressedSize + 12);
                opcode     = ServerOpcodes.CompressedPacket;

                data = buffer.GetData();
            }

            buffer = new ByteBuffer();
            buffer.WriteUInt16((ushort)opcode);
            buffer.WriteBytes(data);
            packetSize += 2 /*opcode*/;

            data = buffer.GetData();

            PacketHeader header = new PacketHeader();

            header.Size = packetSize;
            _worldCrypt.Encrypt(ref data, ref header.Tag);

            ByteBuffer byteBuffer = new ByteBuffer();

            header.Write(byteBuffer);
            byteBuffer.WriteBytes(data);

            AsyncWrite(byteBuffer.GetData());
        }
示例#2
0
        public void SendPacket(ServerPacket packet)
        {
            if (!IsOpen())
            {
                return;
            }

            packet.LogPacket(_worldSession);

            packet.WritePacketData();

            var           data       = packet.GetData();
            uint          packetSize = (uint)data.Length;
            ServerOpcodes opcode     = packet.GetOpcode();

            PacketLog.Write(data, opcode, GetRemoteIpAddress(), GetRemotePort(), _connectType);

            if (packetSize > 0x400 && worldCrypt.IsInitialized)
            {
                ByteBuffer buffer = new ByteBuffer();
                buffer.WriteUInt32(packetSize + 2);
                buffer.WriteUInt32(ZLib.adler32(ZLib.adler32(0x9827D8F1, BitConverter.GetBytes((ushort)opcode), 2), data, packetSize));

                uint compressedSize = CompressPacket(data, opcode);
                buffer.WriteUInt32(ZLib.adler32(0x9827D8F1, data, compressedSize));
                buffer.WriteBytes(data, compressedSize);

                packetSize = (ushort)(compressedSize + 12);
                opcode     = ServerOpcodes.CompressedPacket;

                data = buffer.GetData();
            }

            ServerPacketHeader header = new ServerPacketHeader(packetSize, opcode);

            if (worldCrypt.IsInitialized)
            {
                worldCrypt.Encrypt(header.data, 4);
            }

            AsyncWrite(header.data.Combine(data));
        }