public RealmPacketOut(RealmServerOpCode packetOpCode) : base(new PacketId(packetOpCode)) { base.WriteByte(0xFB); //0 base.WriteInt16(0); //packetLen//1-2 base.WriteInt32(0); //4-5-6-7 base.WriteInt16((ushort)packetOpCode); }
/// <summary> /// Constructs a RealmPacketIn object given the buffer to read, the offset to read from, and the number of bytes to read. /// Do not use this, unless you have a BufferManager that ensures the BufferWrapper's content to be pinned. /// For self-managed RealmPackets, use <c>DisposableRealmPacketIn</c>. /// </summary> /// <param name="segment">buffer container to read from</param> /// <param name="offset">offset to read from relative to the segment offset</param> /// <param name="length">number of bytes to read</param> /// <param name="opcode">the opcode of this packet</param> public RealmPacketIn(BufferSegment segment, int offset, int length, RealmServerOpCode opcode, int headerSize) : base(segment, offset, length) { _packetID = opcode; Position = headerSize; _headerSize = headerSize; _oversizedPacket = (_headerSize == LARGE_PACKET_HEADER_SIZE); }
/// <summary> /// Constructs a RealmPacketIn object given the buffer to read, the offset to read from, and the number of bytes to read. /// Do not use this, unless you have a BufferManager that ensures the BufferWrapper's content to be pinned. /// For self-managed RealmPackets, use <c>DisposableRealmPacketIn</c>. /// </summary> /// <param name="segment">buffer container to read from</param> /// <param name="offset">offset to read from relative to the segment offset</param> /// <param name="length">number of bytes to read</param> /// <param name="opcode">the opcode of this packet</param> public RealmPacketIn(BufferSegment segment, int offset, int length, RealmServerOpCode opcode, int headerSize) : base(segment, offset, length) { this._packetID = (PacketId)opcode; this.Position = headerSize; this._headerSize = headerSize; this._oversizedPacket = this._headerSize == 7; }
/// <summary> /// Constructs a RealmPacketIn object given the buffer to read, the offset to read from, and the number of bytes to read. /// Do not use this, unless you have a BufferManager that ensures the BufferWrapper's content to be pinned. /// For self-managed RealmPackets, use <c>DisposableRealmPacketIn</c>. /// </summary> /// <param name="segment">buffer container to read from</param> /// <param name="offset">offset to read from relative to the segment offset</param> /// <param name="length">number of bytes to read</param> /// <param name="opcode">the opcode of this packet</param> public RealmPacketIn(BufferSegment segment, int offset, int length, RealmServerOpCode opcode, int headerSize) : base(segment, offset, length) { _packetID = opcode; Position = headerSize; _headerSize = headerSize; _oversizedPacket = _headerSize == 7; }
public RealmPacketOut(RealmServerOpCode packetOpCode) : base(new PacketId(packetOpCode)) { this.WriteByte(251); this.WriteInt16(0); this.WriteByte(RealmPacketOut._xorKeyNum++); this.WriteInt32(7077887); this.WriteInt16((ushort)packetOpCode); }
/// <summary> /// Dequeues and returns the last CMSG-Packet that had the given opcode. /// </summary> public ParsedSegment DequeueCMSG(RealmServerOpCode opCode) { var info = DequeueCMSGInfo(opCode); if (info != null) { return info.Parser.ParsedPacket; } return null; }
public RealmPacketOut(RealmServerOpCode packetOpCode) : base(new PacketId(packetOpCode)) { base.WriteByte(0xFB); base.WriteInt16(0); //packetLen base.WriteByte(_xorKeyNum++); //xorKeyNum base.WriteInt32(-1); base.WriteInt16((ushort)packetOpCode); }
public static DisposableRealmPacketIn CreateFromOutPacket(byte[] outPacket, int offset, int totalLength) { int num = offset; RealmServerOpCode realmServerOpCode = (RealmServerOpCode)((int)outPacket[num + 2] | (int)outPacket[num + 3] << 8); BufferSegment segment = BufferManager.GetSegment(totalLength + 2); return(DisposableRealmPacketIn.Create((PacketId)realmServerOpCode, outPacket, offset + 4, totalLength - 4, segment)); }
/// <summary> /// Dequeues and returns the last CMSG-Packet that had the given opcode. /// </summary> public ParsedSegment DequeueCMSG(RealmServerOpCode opCode) { var info = DequeueCMSGInfo(opCode); if (info != null) { return(info.Parser.ParsedPacket); } return(null); }
public RealmReceiveInfo DequeueCMSGInfo(RealmServerOpCode opCode) { Setup.WriteLine("Fetching packet " + opCode); Assert.IsNotNull(RealmPacketMgr.Instance[opCode], "You did not add a PacketHandler for: {0} - " + "To do so, simply call one of the Add*Handler(...) methods of this class during initialization.", opCode); LockfreeQueue<RealmReceiveInfo> queue; CMSGPackets.TryGetValue(opCode, out queue); if (queue != null) { var info = queue.TryDequeue(); if (info == null) { var def = PacketAnalyzer.GetDefinition(opCode, PacketSender.Client); Assert.IsNotNull(def, "You did not define the packet-structure for OpCode {0}!", opCode); } return info; } throw new InvalidOperationException("Packets are not cached!"); }
public RealmReceiveInfo DequeueCMSGInfo(RealmServerOpCode opCode) { Setup.WriteLine("Fetching packet " + opCode); Assert.IsNotNull(RealmPacketMgr.Instance[opCode], "You did not add a PacketHandler for: {0} - " + "To do so, simply call one of the Add*Handler(...) methods of this class during initialization.", opCode); LockfreeQueue <RealmReceiveInfo> queue; CMSGPackets.TryGetValue(opCode, out queue); if (queue != null) { var info = queue.TryDequeue(); if (info == null) { var def = PacketAnalyzer.GetDefinition(opCode, PacketSender.Client); Assert.IsNotNull(def, "You did not define the packet-structure for OpCode {0}!", opCode); } return(info); } throw new InvalidOperationException("Packets are not cached!"); }
public static DisposableRealmPacketIn ParseCompressedMove(PacketIn packet) { // special treatment for the compressed move packet var uncompressedLength = packet.ReadInt32(); var segment = BufferManager.GetSegment(uncompressedLength); var arr = segment.Buffer.Array; try { Compression.DecompressZLib(packet.ReadBytes(packet.RemainingLength), arr); ushort length = arr[0]; RealmServerOpCode opCode = (RealmServerOpCode)(arr[1] | arr[2] << 8); return(new DisposableRealmPacketIn(segment, 1, length, length - 3, opCode)); } catch (Exception e) { LogUtil.ErrorException(e, "Unable to parse packet: " + packet); } return(null); }
public override void Process(CmdTrigger <RealmServerCmdArgs> trigger) { RealmServerOpCode packetOpCode = trigger.Text.NextEnum <RealmServerOpCode>(RealmServerOpCode.Unknown); if (packetOpCode == RealmServerOpCode.Unknown) { trigger.Reply("Invalid OpCode."); } else { using (RealmPacketOut packet = new RealmPacketOut(packetOpCode)) { while (trigger.Text.HasNext) { int num = trigger.Text.NextInt(); packet.Write(num); } ((Character)trigger.Args.Target).Client.Send(packet, false); } } }
public PacketHandlerAttribute(RealmServerOpCode identifier) { this.Id = (PacketId)identifier; this.IsGamePacket = true; this.RequiresLogin = true; }
public WorldPacket(RealmServerOpCode opCode) : base(opCode.Parse(), (ushort)opCode) { }
public PacketId(RealmServerOpCode id) { Service = ServiceType.Realm; RawId = (uint)id; }
public PacketType(RealmServerOpCode opCode) : this(PacketHandleType.World, (ushort)opCode) { }
public ClientPacketHandlerAttribute(RealmServerOpCode identifier) : base(identifier) { }
public DisposableRealmPacketIn(BufferSegment segment, int offset, int length, int contentLength, RealmServerOpCode packetId) : base(segment, offset, length, packetId, (length - contentLength)) { }
public PacketId(RealmServerOpCode id) { Service = ServiceType.Realm; RawId = (uint) id; }
public PacketHandlerAttribute(RealmServerOpCode identifier) { Id = identifier; IsGamePacket = true; RequiresLogin = true; }
public static PacketHeaderType Parse(this RealmServerOpCode opCode) { return(opCode.ToString().StartsWith("CMSG") ? PacketHeaderType.WorldCmsg : PacketHeaderType.WorldSmsg); }
/// <summary> /// Sends the requested party member stats data to the client /// </summary> /// <param name="client">realm client</param> /// <param name="member">The character whose stats is going to be retrieved</param> /// <param name="flags">The stats to be retrieved from the <paramref name="member"/></param> private static void SendPartyMemberStatsInternal(IPacketReceiver client, GroupMember member, GroupUpdateFlags flags, RealmServerOpCode opcode) { using (var packet = new RealmPacketOut(opcode)) { if (opcode == RealmServerOpCode.SMSG_PARTY_MEMBER_STATS_FULL) { packet.Write((byte)0); //arena something } member.WriteIdPacked(packet); if (!member.IsOnline) { packet.WriteUShort((ushort)CharacterStatus.OFFLINE); client.Send(packet, addEnd: false); return; } packet.Write((uint)flags); var chr = member.Character; if (flags.HasFlag(GroupUpdateFlags.Status)) { packet.Write((ushort)chr.Status); } if (flags.HasFlag(GroupUpdateFlags.Health)) { packet.Write(chr.Health); } if (flags.HasFlag(GroupUpdateFlags.MaxHealth)) { packet.Write(chr.MaxHealth); } if (flags.HasFlag(GroupUpdateFlags.PowerType)) { packet.Write((byte)chr.PowerType); } if (flags.HasFlag(GroupUpdateFlags.Power)) { packet.Write((ushort)chr.Power); } if (flags.HasFlag(GroupUpdateFlags.MaxPower)) { packet.Write((ushort)chr.MaxPower); } if (flags.HasFlag(GroupUpdateFlags.Level)) { packet.Write((ushort)chr.Level); } if (flags.HasFlag(GroupUpdateFlags.ZoneId)) { packet.Write((ushort)(chr.Zone != null ? chr.Zone.Id : ZoneId.None)); } if (flags.HasFlag(GroupUpdateFlags.Position)) { packet.Write((ushort)chr.Position.X); packet.Write((ushort)chr.Position.Y); } if (flags.HasFlag(GroupUpdateFlags.Auras)) { ulong auraMask = chr.AuraUpdateMask; packet.Write(auraMask); Aura currAura; for (byte i = 0; i < AuraHandler.MaxAuras; ++i) { if ((auraMask & ((ulong)1 << i)) != 0) { currAura = chr.Auras.GetAt(i); packet.Write(currAura.Spell.Id); packet.Write((byte)currAura.Flags); } } } NPC targetPet = chr.ActivePet; if (targetPet == null) //no pet { packet.Write((byte)0); //name packet.Write(0UL); //auras client.Send(packet, addEnd: false); return; } if (flags.HasFlag(GroupUpdateFlags.PetGuid)) { packet.Write(targetPet.EntityId); } if (flags.HasFlag(GroupUpdateFlags.PetName)) { packet.WriteCString(targetPet.Name); } if (flags.HasFlag(GroupUpdateFlags.PetDisplayId)) { packet.Write((ushort)targetPet.DisplayId); } if (flags.HasFlag(GroupUpdateFlags.PetHealth)) { packet.Write(targetPet.Health); } if (flags.HasFlag(GroupUpdateFlags.PetMaxHealth)) { packet.Write(targetPet.MaxHealth); } if (flags.HasFlag(GroupUpdateFlags.PetPowerType)) { packet.Write((byte)targetPet.PowerType); } if (flags.HasFlag(GroupUpdateFlags.PetPower)) { packet.Write((ushort)targetPet.Power); } if (flags.HasFlag(GroupUpdateFlags.PetMaxPower)) { packet.Write((ushort)targetPet.MaxPower); } if (flags.HasFlag(GroupUpdateFlags.PetAuras)) { ulong auraMask = targetPet.AuraUpdateMask; packet.Write(auraMask); Aura currAura; for (byte i = 0; i < AuraHandler.MaxAuras; ++i) { if ((auraMask & ((ulong)1 << i)) != 0) { currAura = targetPet.Auras.GetAt(i); //chr.Auras.GetAt(i); packet.Write(currAura.Spell.Id); packet.Write((byte)currAura.Flags); } } } client.Send(packet, addEnd: false); } }
public DisposableRealmPacketIn(BufferSegment segment, int offset, int length, int contentLength, RealmServerOpCode packetId) : base(segment, offset, length, packetId, length - contentLength) { }
public RealmPacketDefinition(RealmServerOpCode opCode, params PacketSegmentStructure[] segments) { OpCode = opCode; Structure = segments.ToList(); }
/// <summary> /// Sends the requested party member stats data to the client /// </summary> /// <param name="client">realm client</param> /// <param name="member">The character whose stats is going to be retrieved</param> /// <param name="flags">The stats to be retrieved from the <paramref name="member"/></param> private static void SendPartyMemberStatsInternal(IPacketReceiver client, GroupMember member, GroupUpdateFlags flags, RealmServerOpCode opcode) { using (var packet = new RealmPacketOut(opcode)) { if (opcode == RealmServerOpCode.SMSG_PARTY_MEMBER_STATS_FULL) { packet.Write((byte)0); //arena something } member.WriteIdPacked(packet); if (!member.IsOnline) { packet.WriteUShort((ushort)CharacterStatus.OFFLINE); client.Send(packet); return; } packet.Write((uint)flags); var chr = member.Character; if (flags.HasFlag(GroupUpdateFlags.Status)) { packet.Write((ushort)chr.Status); } if (flags.HasFlag(GroupUpdateFlags.Health)) { packet.Write(chr.Health); } if (flags.HasFlag(GroupUpdateFlags.MaxHealth)) { packet.Write(chr.MaxHealth); } if (flags.HasFlag(GroupUpdateFlags.PowerType)) { packet.Write((byte)chr.PowerType); } if (flags.HasFlag(GroupUpdateFlags.Power)) { packet.Write((ushort)chr.Power); } if (flags.HasFlag(GroupUpdateFlags.MaxPower)) { packet.Write((ushort)chr.MaxPower); } if (flags.HasFlag(GroupUpdateFlags.Level)) { packet.Write((ushort)chr.Level); } if (flags.HasFlag(GroupUpdateFlags.ZoneId)) { packet.Write((ushort)(chr.Zone != null ? chr.Zone.Id : ZoneId.None)); } if (flags.HasFlag(GroupUpdateFlags.Position)) { packet.Write((ushort)chr.Position.X); packet.Write((ushort)chr.Position.Y); } if (flags.HasFlag(GroupUpdateFlags.Auras)) { ulong auraMask = chr.AuraUpdateMask; packet.Write(auraMask); Aura currAura; for (byte i = 0; i < AuraHandler.MaxAuras; ++i) { if ((auraMask & ((ulong)1 << i)) != 0) { currAura = chr.Auras.GetAt(i); packet.Write(currAura.Spell.Id); packet.Write((byte)currAura.Flags); } } } NPC targetPet = chr.ActivePet; if (targetPet == null) //no pet { packet.Write((byte)0); //name packet.Write(0UL); //auras client.Send(packet); return; } if (flags.HasFlag(GroupUpdateFlags.PetGuid)) { packet.Write(targetPet.EntityId); } if (flags.HasFlag(GroupUpdateFlags.PetName)) { packet.WriteCString(targetPet.Name); } if (flags.HasFlag(GroupUpdateFlags.PetDisplayId)) { packet.Write((ushort)targetPet.DisplayId); } if (flags.HasFlag(GroupUpdateFlags.PetHealth)) { packet.Write(targetPet.Health); } if (flags.HasFlag(GroupUpdateFlags.PetMaxHealth)) { packet.Write(targetPet.MaxHealth); } if (flags.HasFlag(GroupUpdateFlags.PetPowerType)) { packet.Write((byte)targetPet.PowerType); } if (flags.HasFlag(GroupUpdateFlags.PetPower)) { packet.Write((ushort)targetPet.Power); } if (flags.HasFlag(GroupUpdateFlags.PetMaxPower)) { packet.Write((ushort)targetPet.MaxPower); } if (flags.HasFlag(GroupUpdateFlags.PetAuras)) { ulong auraMask = targetPet.AuraUpdateMask; packet.Write(auraMask); Aura currAura; for (byte i = 0; i < AuraHandler.MaxAuras; ++i) { if ((auraMask & ((ulong)1 << i)) != 0) { currAura = targetPet.Auras.GetAt(i);//chr.Auras.GetAt(i); packet.Write(currAura.Spell.Id); packet.Write((byte)currAura.Flags); } } } client.Send(packet); } }
/// <summary> /// Sends the requested party member stats data to the client /// </summary> /// <param name="client">realm client</param> /// <param name="member">The character whose stats is going to be retrieved</param> /// <param name="flags">The stats to be retrieved from the <paramref name="member" /></param> private static void SendPartyMemberStatsInternal(IPacketReceiver client, GroupMember member, GroupUpdateFlags flags, RealmServerOpCode opcode) { using (RealmPacketOut packet = new RealmPacketOut(opcode)) { if (opcode == RealmServerOpCode.SMSG_PARTY_MEMBER_STATS_FULL) { packet.Write((byte)0); } member.WriteIdPacked(packet); if (!member.IsOnline) { packet.WriteUShort((ushort)0); client.Send(packet, false); } else { packet.Write((uint)flags); Character character = member.Character; if (flags.HasFlag(GroupUpdateFlags.Status)) { packet.Write((ushort)character.Status); } if (flags.HasFlag(GroupUpdateFlags.Health)) { packet.Write(character.Health); } if (flags.HasFlag(GroupUpdateFlags.MaxHealth)) { packet.Write(character.MaxHealth); } if (flags.HasFlag(GroupUpdateFlags.PowerType)) { packet.Write((byte)character.PowerType); } if (flags.HasFlag(GroupUpdateFlags.Power)) { packet.Write((ushort)character.Power); } if (flags.HasFlag(GroupUpdateFlags.MaxPower)) { packet.Write((ushort)character.MaxPower); } if (flags.HasFlag(GroupUpdateFlags.Level)) { packet.Write((ushort)character.Level); } if (flags.HasFlag(GroupUpdateFlags.ZoneId)) { packet.Write(character.Zone != null ? (ushort)character.Zone.Id : (ushort)0); } if (flags.HasFlag(GroupUpdateFlags.Position)) { packet.Write((ushort)character.Position.X); packet.Write((ushort)character.Position.Y); } if (flags.HasFlag(GroupUpdateFlags.Auras)) { ulong auraUpdateMask = character.AuraUpdateMask; packet.Write(auraUpdateMask); for (byte index = 0; index < (byte)56; ++index) { if (((long)auraUpdateMask & 1L << index) != 0L) { Aura at = character.Auras.GetAt(index); packet.Write(at.Spell.Id); packet.Write((byte)at.Flags); } } } NPC activePet = character.ActivePet; if (activePet == null) { packet.Write((byte)0); packet.Write(0UL); client.Send(packet, false); } else { if (flags.HasFlag(GroupUpdateFlags.PetGuid)) { packet.Write(activePet.EntityId); } if (flags.HasFlag(GroupUpdateFlags.PetName)) { packet.WriteCString(activePet.Name); } if (flags.HasFlag(GroupUpdateFlags.PetDisplayId)) { packet.Write((ushort)activePet.DisplayId); } if (flags.HasFlag(GroupUpdateFlags.PetHealth)) { packet.Write(activePet.Health); } if (flags.HasFlag(GroupUpdateFlags.PetMaxHealth)) { packet.Write(activePet.MaxHealth); } if (flags.HasFlag(GroupUpdateFlags.PetPowerType)) { packet.Write((byte)activePet.PowerType); } if (flags.HasFlag(GroupUpdateFlags.PetPower)) { packet.Write((ushort)activePet.Power); } if (flags.HasFlag(GroupUpdateFlags.PetMaxPower)) { packet.Write((ushort)activePet.MaxPower); } if (flags.HasFlag(GroupUpdateFlags.PetAuras)) { ulong auraUpdateMask = activePet.AuraUpdateMask; packet.Write(auraUpdateMask); for (byte index = 0; index < (byte)56; ++index) { if (((long)auraUpdateMask & 1L << index) != 0L) { Aura at = activePet.Auras.GetAt(index); packet.Write(at.Spell.Id); packet.Write((byte)at.Flags); } } } client.Send(packet, false); } } } }
public RealmPacketDefinition(RealmServerOpCode opCode, ComplexPacketSegmentStructure segments) { OpCode = opCode; Structure = segments.Segments.ToList(); }