示例#1
0
        public ServerPacketHeader(uint size, ServerOpcodes opcode)
        {
            Size   = size + 2;
            Opcode = opcode;

            data = BitConverter.GetBytes(Size).Combine(BitConverter.GetBytes((ushort)opcode));
        }
示例#2
0
        public uint CompressPacket(byte[] data, ServerOpcodes opcode)
        {
            byte[] uncompressedData = BitConverter.GetBytes((ushort)opcode).Combine(data);

            uint bufferSize = ZLib.deflateBound(_compressionStream, (uint)uncompressedData.Length);

            byte[] outPrt = new byte[bufferSize];

            _compressionStream.next_out  = 0;
            _compressionStream.avail_out = bufferSize;
            _compressionStream.out_buf   = outPrt;

            _compressionStream.next_in  = 0;
            _compressionStream.avail_in = (uint)uncompressedData.Length;
            _compressionStream.in_buf   = uncompressedData;

            int z_res = ZLib.deflate(_compressionStream, 2);

            if (z_res != 0)
            {
                Log.outError(LogFilter.Network, "Can't compress packet data (zlib: deflate) Error code: {0} msg: {1}", z_res, _compressionStream.msg);
                return(0);
            }

            uint compressedSize = bufferSize - _compressionStream.avail_out;

            Buffer.BlockCopy(outPrt, 0, data, 0, (int)compressedSize);
            return(compressedSize);
        }
示例#3
0
    public static void Write(byte[] data, ServerOpcodes opcode, IPAddress address, uint port, ConnectionType connectionType)
    {
        if (!CanLog())
        {
            return;
        }

        lock (syncObj)
        {
            using (var writer = new BinaryWriter(File.Open(FullPath, FileMode.Append), Encoding.ASCII))
            {
                writer.Write("SMSG".ToCharArray());
                writer.Write((uint)connectionType);
                writer.Write(Time.GetMSTime());

                writer.Write(20);
                byte[] SocketIPBytes = new byte[16];
                if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    Buffer.BlockCopy(address.GetAddressBytes(), 0, SocketIPBytes, 0, 4);
                }
                else
                {
                    Buffer.BlockCopy(address.GetAddressBytes(), 0, SocketIPBytes, 0, 16);
                }

                writer.Write(data.Length + 4);
                writer.Write(SocketIPBytes);
                writer.Write(port);
                writer.Write((uint)opcode);
                writer.Write(data);
            }
        }
    }
示例#4
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());
        }
示例#5
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));
        }
示例#6
0
        public static bool IsInstanceOnlyOpcode(ServerOpcodes opcode)
        {
            switch (opcode)
            {
            case ServerOpcodes.QuestGiverStatus:  // ClientQuest
            case ServerOpcodes.DuelRequested:     // Client
            case ServerOpcodes.DuelInBounds:      // Client
            case ServerOpcodes.QueryTimeResponse: // Client
            case ServerOpcodes.DuelWinner:        // Client
            case ServerOpcodes.DuelComplete:      // Client
            case ServerOpcodes.DuelOutOfBounds:   // Client
            case ServerOpcodes.AttackStop:        // Client
            case ServerOpcodes.AttackStart:       // Client
            case ServerOpcodes.MountResult:       // Client
                return(true);

            default:
                return(false);
            }
        }
示例#7
0
 public CombatLogServerPacket(ServerOpcodes opcode, ConnectionType connection = ConnectionType.Realm) : base(opcode, connection)
 {
     LogData = new SpellCastLogData();
 }
 public TitleEarned(ServerOpcodes opcode) : base(opcode)
 {
 }
示例#9
0
 protected ServerPacket(ServerOpcodes opcode, ConnectionType type = ConnectionType.Realm)
 {
     connectionType = type;
     _worldPacket   = new WorldPacket(opcode);
 }
示例#10
0
 public WorldPacket(ServerOpcodes opcode = ServerOpcodes.None)
 {
     this.opcode = (uint)opcode;
 }
示例#11
0
 public MoveSetFlag(ServerOpcodes opcode) : base(opcode, ConnectionType.Instance)
 {
 }
示例#12
0
 public MoveUpdateSpeed(ServerOpcodes opcode) : base(opcode, ConnectionType.Instance)
 {
 }
示例#13
0
 public MoveSplineSetSpeed(ServerOpcodes opcode) : base(opcode, ConnectionType.Instance)
 {
 }
示例#14
0
 public MoveStateChange(ServerOpcodes messageId, uint sequenceIndex)
 {
     MessageID     = messageId;
     SequenceIndex = sequenceIndex;
 }
示例#15
0
 public ServerPacket(ServerOpcodes opcode)
 {
     connectionType = ConnectionType.Realm;
     _worldPacket   = new WorldPacket(opcode);
 }