public ServerPacketHeader(uint size, ServerOpcodes opcode) { Size = size + 2; Opcode = opcode; data = BitConverter.GetBytes(Size).Combine(BitConverter.GetBytes((ushort)opcode)); }
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); }
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); } } }
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()); }
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)); }
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); } }
public CombatLogServerPacket(ServerOpcodes opcode, ConnectionType connection = ConnectionType.Realm) : base(opcode, connection) { LogData = new SpellCastLogData(); }
public TitleEarned(ServerOpcodes opcode) : base(opcode) { }
protected ServerPacket(ServerOpcodes opcode, ConnectionType type = ConnectionType.Realm) { connectionType = type; _worldPacket = new WorldPacket(opcode); }
public WorldPacket(ServerOpcodes opcode = ServerOpcodes.None) { this.opcode = (uint)opcode; }
public MoveSetFlag(ServerOpcodes opcode) : base(opcode, ConnectionType.Instance) { }
public MoveUpdateSpeed(ServerOpcodes opcode) : base(opcode, ConnectionType.Instance) { }
public MoveSplineSetSpeed(ServerOpcodes opcode) : base(opcode, ConnectionType.Instance) { }
public MoveStateChange(ServerOpcodes messageId, uint sequenceIndex) { MessageID = messageId; SequenceIndex = sequenceIndex; }
public ServerPacket(ServerOpcodes opcode) { connectionType = ConnectionType.Realm; _worldPacket = new WorldPacket(opcode); }