Ejemplo n.º 1
0
 internal override void Init(PacketDefinition def)
 {
     foreach (var segment in Segments)
     {
         segment.Init(def);
     }
 }
Ejemplo n.º 2
0
        internal override void Init(PacketDefinition def)
        {
            if (Segments.Count == 0)
            {
                throw new Exception("List " + Name + " in Defintion for " + def.PacketIds.ToString(", ") + " has no structure defined.");
            }

            if (string.IsNullOrEmpty(Name))
            {
                throw new Exception("List in " + def.PacketIds.ToString(", ") + " has no Name but Name is required.");
            }

            if (LengthSegment == null)
            {
                if (!string.IsNullOrEmpty(LengthSegmentName))
                {
                    if ((LengthSegment = def.GetSegment(LengthSegmentName)) == null)
                    {
                        throw new ArgumentException("Length-Segment \"" + LengthSegmentName + "\" for ListSegment " + this + " does not exist.");
                    }
                }
            }

            foreach (var segment in Segments)
            {
                segment.Init(def);
            }
        }
Ejemplo n.º 3
0
        internal override void Init(PacketDefinition def)
        {
            if (Cases.Count == 0)
            {
                throw new ArgumentNullException(string.Format("No Conditions found in Switch {0} for packet {1}", this, def));
            }

            if (ReferenceSegment == null)
            {
                if (string.IsNullOrEmpty(ReferenceName))
                {
                    throw new ArgumentException(def.PacketIds.ToString(", ") + " defines SwitchSegment without CompareWith-Attribute.");
                }
                if ((ReferenceSegment = def.GetSegment(ReferenceName)) == null)
                {
                    throw new ArgumentException("CompareWith-Segment \"" + ReferenceName + "\" for SwitchSegment " + this + " does not exist.");
                }
            }

            foreach (var condition in Cases)
            {
                try
                {
                    condition.Init(this, def);
                }
                catch (Exception e)
                {
                    throw new Exception(string.Format("Failed to parse Switch {0} - Invalid Case: {1}", this, condition), e);
                }
            }
        }
Ejemplo n.º 4
0
        public static ParsedSegment Parse(PacketIn packet, PacketSender sender, PacketDefinition def)
        {
            var parser = new PacketParser(packet, sender, def);

            parser.Parse();
            return(parser.ParsedPacket);
        }
Ejemplo n.º 5
0
 internal virtual void Init(PacketDefinition def)
 {
     if (string.IsNullOrEmpty(EncodingName))
     {
         Encoding = WCellConstants.DefaultEncoding;
     }
     else
     {
         Encoding = Encoding.GetEncoding(EncodingName);
     }
 }
Ejemplo n.º 6
0
		public PacketParser(PacketIn packet, PacketSender sender, PacketDefinition def)
		{
			if (packet.PacketId == RealmServerOpCode.SMSG_COMPRESSED_MOVES)
			{
				var packet2 = ParseCompressedMove(packet);
				if (packet2 != null)
				{
					packet = packet2;
				}
			}
			Packet = packet;
			Sender = sender;
			Definition = def;
			Timestamp = DateTime.Now;
		}
Ejemplo n.º 7
0
 public PacketParser(PacketIn packet, PacketSender sender, PacketDefinition def)
 {
     if (packet.PacketId == RealmServerOpCode.SMSG_COMPRESSED_MOVES)
     {
         var packet2 = ParseCompressedMove(packet);
         if (packet2 != null)
         {
             packet = packet2;
         }
     }
     Packet     = packet;
     Sender     = sender;
     Definition = def;
     Timestamp  = DateTime.Now;
 }
Ejemplo n.º 8
0
		/// <summary>
		/// Registers a new PacketDefinition. Overrides existing Definitions (if any)
		/// </summary>
		public static void RegisterDefintion(PacketDefinition def)
		{
			foreach (var id in def.PacketIds)
			{
				var arr = PacketDefinitions[(uint)id.Service];
				if (def.Sender == PacketSender.Any || def.Sender == PacketSender.Client)
				{
					arr[id.RawId * 2] = def;
				}
				if (def.Sender == PacketSender.Any || def.Sender == PacketSender.Server)
				{
					arr[id.RawId * 2 + 1] = def;
				}
				s_defCount++;
			}
		}
Ejemplo n.º 9
0
 /// <summary>
 /// Registers a new PacketDefinition. Overrides existing Definitions (if any)
 /// </summary>
 public static void RegisterDefintion(PacketDefinition def)
 {
     foreach (var id in def.PacketIds)
     {
         var arr = PacketDefinitions[(uint)id.Service];
         if (def.Sender == PacketSender.Any || def.Sender == PacketSender.Client)
         {
             arr[id.RawId * 2] = def;
         }
         if (def.Sender == PacketSender.Any || def.Sender == PacketSender.Server)
         {
             arr[id.RawId * 2 + 1] = def;
         }
         s_defCount++;
     }
 }
Ejemplo n.º 10
0
        public virtual void Init(SwitchPacketSegmentStructure swtch, PacketDefinition def)
        {
            m_switch = swtch;

            if (StringValue != null)
            {
                var values = StringValue.Split(',');
                if (values.Length > 0)
                {
                    m_value     = ParseValue(values[0]);
                    m_valueList = new List <object>();
                    foreach (var val in values)
                    {
                        m_valueList.Add(ParseValue(val));
                    }
                }
            }

            if (m_value == null)
            {
                throw new Exception("No value given in Switch " + m_switch + " Case for " + def + "");
            }

            if (SegmentList.Count > 1 || SegmentList.Count == 0)
            {
                Structure = new ComplexPacketSegmentStructure(SegmentList);
            }
            else
            {
                Structure = SegmentList[0];
            }

            foreach (var segment in SegmentList)
            {
                segment.Init(def);
            }
        }
Ejemplo n.º 11
0
        public void TestConditions()
        {
            PacketSegmentStructure spellAttributes, chatType, someNumber;
            SwitchPacketSegmentStructure swtch;
            SwitchCase cond, cond2, cond3, cond4;
            var def = new PacketDefinition(RealmServerOpCode.CMSG_SET_FACTION_INACTIVE, PacketSender.Client,
                spellAttributes = new PacketSegmentStructure(SimpleType.UInt, "SpellAttributes", typeof(SpellAttributes)),
                chatType = new PacketSegmentStructure(SimpleType.UInt, "ChatType", typeof(ChatMsgType)),
                someNumber = new PacketSegmentStructure(SimpleType.Int, "SomeNumber"),

                swtch = new SwitchPacketSegmentStructure("some switch", chatType,
                    cond = new SwitchCase(ComparisonType.Equal, ChatMsgType.Say,
                        new PacketSegmentStructure(SimpleType.CString, "Message")
                    )
                ),
                new SwitchPacketSegmentStructure("Mathmatical comparisons", someNumber,
                    cond2 = new SwitchCase(ComparisonType.GreaterOrEqual, 300,
                        new PacketSegmentStructure(SimpleType.CString, "Message")
                    )),
                new SwitchPacketSegmentStructure("Flag Switch", spellAttributes,
                    cond3 = new SwitchCase(ComparisonType.And, "Passive | Ranged",
                        new PacketSegmentStructure(SimpleType.CString, "Something Else")
                    ),
                    cond4 = new SwitchCase(ComparisonType.AndNot, "OnNextMelee",
                        new PacketSegmentStructure(SimpleType.CString, "Meleestuff")
                    )
                )
            );

            // basic structure
            Assert.AreEqual(6, ((ComplexPacketSegmentStructure)def.Structure).Segments.Count);

            Assert.AreEqual(1, swtch.Cases.Count);
            Assert.AreEqual(cond, swtch.Cases[0]);

            def.Init();

            // conditions
            Assert.IsFalse(cond.Matches((ChatMsgType)123));
            Assert.AreEqual(cond.Value, ChatMsgType.Say);
            Assert.IsTrue(cond.Matches(ChatMsgType.Say));

            Assert.IsFalse(cond2.Matches(123));
            Assert.IsTrue(cond2.Matches(300));
            Assert.IsTrue(cond2.Matches(3000));

            Assert.IsTrue(cond3.Matches(SpellAttributes.Passive | SpellAttributes.Ranged | SpellAttributes.CannotBeCastInCombat));
            Assert.IsFalse(cond3.Matches(SpellAttributes.StartCooldownAfterEffectFade));

            Assert.IsTrue(cond4.Matches(SpellAttributes.Passive));
            Assert.IsFalse(cond4.Matches(SpellAttributes.Passive | SpellAttributes.OnNextMelee));
            Assert.IsFalse(cond4.Matches(SpellAttributes.OnNextMelee));
        }
Ejemplo n.º 12
0
        public void TestSavingAndLoading()
        {
            var def = new PacketDefinition(RealmServerOpCode.CMSG_SET_CHANNEL_WATCH, PacketSender.Client, new List<PacketSegmentStructure>());
            PacketAnalyzer.RegisterDefintion(def);

            var def2 = PacketAnalyzer.GetDefinition(RealmServerOpCode.CMSG_SET_CHANNEL_WATCH, PacketSender.Client);
            Assert.AreEqual(def, def2);

            def = new PacketDefinition(RealmServerOpCode.CMSG_SET_CHANNEL_WATCH, PacketSender.Any, new List<PacketSegmentStructure>());
            PacketAnalyzer.RegisterDefintion(def);

            def2 = PacketAnalyzer.GetDefinition(RealmServerOpCode.CMSG_SET_CHANNEL_WATCH, PacketSender.Server);
            Assert.AreEqual(def, def2);
        }
Ejemplo n.º 13
0
        public void TestParsedSegment()
        {
            PacketDefinition def = new PacketDefinition(RealmServerOpCode.CMSG_PLAYER_AI_CHEAT, PacketSender.Client,
                new PacketSegmentStructure(SimpleType.UInt, "SpellAttributes", typeof(SpellAttributes)),
                new ListPacketSegmentStructure(SimpleType.Byte, "Members",
                    new PacketSegmentStructure(SimpleType.Guid, "MemberId"),
                    new PacketSegmentStructure(SimpleType.CString, "Name")
                ),

                new SwitchPacketSegmentStructure("Attribute Switch", "SpellAttributes",
                    new SwitchCase(ComparisonType.And, SpellAttributes.CannotBeCastInCombat,
                        new PacketSegmentStructure(SimpleType.CString, "NoCombatString")
                    ),
                    new SwitchCase(ComparisonType.And, SpellAttributes.CannotBeCastInCombat | SpellAttributes.CastableWhileMounted,
                        new PacketSegmentStructure(SimpleType.CString, "NoCombatNoDismountString")
                    )
                ),

                new SwitchPacketSegmentStructure("List Switch", "Members",
                    new SwitchCase(ComparisonType.Equal, (byte)0,
                        new PacketSegmentStructure(SimpleType.Byte, "Status", "CharacterStatus"),
                        new SwitchPacketSegmentStructure("Nested Switch", "Status",
                            new SwitchCase(ComparisonType.AndNot, CharacterStatus.OFFLINE,
                                new PacketSegmentStructure(SimpleType.UInt, "NumX")
                            )
                        )
                    ),
                    new SwitchCase(ComparisonType.GreaterThan, (byte)0,
                        new PacketSegmentStructure(SimpleType.CString, "Info")
                    )
                ),

                new StaticListPacketSegmentStructure(1, "StaticList1",
                    new PacketSegmentStructure(SimpleType.Int, "Number1")
                ),

                new StaticListPacketSegmentStructure(2, "StaticList2",
                    new PacketSegmentStructure(SimpleType.Int, "Number2")
                ),

                new PacketSegmentStructure(SimpleType.Byte, "ListLength"),

                new ListPacketSegmentStructure("SomeList3", "ListLength",
                    new PacketSegmentStructure(SimpleType.Int, "SomeListEle")
                )
            );

            def.Init();

            using (var packet = new RealmPacketOut(RealmServerOpCode.CMSG_PLAYER_AI_CHEAT))
            {
                packet.WriteUInt((uint)(SpellAttributes.CastableWhileMounted | SpellAttributes.CannotBeCastInCombat));
                packet.WriteByte(2);

                packet.Write(EntityId.Zero);
                packet.WriteCString("Member1Name");

                packet.Write(new EntityId(10));
                packet.WriteCString("Member2Name");

                packet.WriteCString("NoCombat");
                packet.WriteCString("NoCombatNoDismount");

                packet.WriteCString("lotsofinfo");

                // StaticList1
                packet.WriteInt(10);

                // StaticList2
                packet.WriteInt(20);
                packet.WriteInt(30);

                // SomeList3's length
                packet.WriteByte(2);
                // SomeList3
                packet.WriteInt(5);
                packet.WriteInt(7);

                var parsedPacket = PacketParser.Parse(packet, PacketSender.Client, def);

                Assert.AreEqual("NoCombat", parsedPacket["NoCombatString"].StringValue);
                Assert.AreEqual("NoCombatNoDismount", parsedPacket["NoCombatNoDismountString"].StringValue);

                var members = parsedPacket["Members"];
                Assert.AreEqual(EntityId.Zero, members[0]["MemberId"].EntityIdValue);
                Assert.AreEqual("Member1Name", members[0]["Name"].StringValue);
                Assert.AreEqual("Member2Name", members[1]["Name"].StringValue);
                Assert.AreEqual("lotsofinfo", parsedPacket["Info"].StringValue);
                CheckRemainder(parsedPacket);
            }

            using (var packet = new RealmPacketOut(RealmServerOpCode.CMSG_PLAYER_AI_CHEAT))
            {
                packet.WriteUInt((uint)SpellAttributes.None);
                packet.WriteByte(0);

                packet.Write((byte)CharacterStatus.ONLINE);
                packet.Write((uint)1234);

                packet.WriteInt(10);

                packet.WriteInt(20);
                packet.WriteInt(30);

                // SomeList3's length
                packet.WriteByte(2);
                // SomeList3
                packet.WriteInt(5);
                packet.WriteInt(7);

                var parsedPacket = PacketParser.Parse(packet, PacketSender.Client, def);

                Assert.IsNull(parsedPacket.GetByName("Info"));

                Assert.AreEqual(CharacterStatus.ONLINE, parsedPacket["Status"].Value);
                Assert.AreEqual((uint)1234, parsedPacket["NumX"].Value);

                CheckRemainder(parsedPacket);
            }
        }
Ejemplo n.º 14
0
        public void TestEmptyStructure()
        {
            var def = new PacketDefinition(RealmServerOpCode.CMSG_SET_CHANNEL_WATCH, PacketSender.Client, new List<PacketSegmentStructure>());
            def.Init();

            using (var packet = new RealmPacketOut(RealmServerOpCode.CMSG_PLAYER_AI_CHEAT))
            {
                packet.WriteUInt((uint)SpellAttributes.CannotRemove);
                packet.WriteByte(0);

                using (var packetIn = DisposableRealmPacketIn.CreateFromOutPacket(packet))
                {
                    var parsedPacket = PacketParser.Parse(packetIn, PacketSender.Client, def);
                    Assert.AreEqual(0, parsedPacket.SubSegments.Count);
                }
            }
        }
Ejemplo n.º 15
0
 static PacketDefinition GetDefinition(PacketDefinition[] arr, uint rawId, PacketSender sender)
 {
     #if DEBUG
     if (rawId * 2 >= arr.Length)
     {
         //Debugger.Break();
         log.Error("Invalid Packet definition: " + rawId);
         return arr[0];
     }
     #endif
     if (sender == PacketSender.Any || sender == PacketSender.Client)
     {
         return arr[rawId * 2];
     }
     return arr[rawId * 2 + 1];
 }
Ejemplo n.º 16
0
		public virtual void Init(SwitchPacketSegmentStructure swtch, PacketDefinition def)
		{
			m_switch = swtch;

			if (StringValue != null)
			{
				var values = StringValue.Split(',');
				if (values.Length > 0)
				{
					m_value = ParseValue(values[0]);
					m_valueList = new List<object>();
					foreach (var val in values)
					{
						m_valueList.Add(ParseValue(val));
					}
				}
			}

			if (m_value == null)
			{
				throw new Exception("No value given in Switch " + m_switch + " Case for " + def + "");
			}

			if (SegmentList.Count > 1 || SegmentList.Count == 0)
			{
				Structure = new ComplexPacketSegmentStructure(SegmentList);
			}
			else
			{
				Structure = SegmentList[0];
			}

			foreach (var segment in SegmentList)
			{
				segment.Init(def);
			}
		}
Ejemplo n.º 17
0
		public static ParsedSegment Parse(PacketIn packet, PacketSender sender, PacketDefinition def)
		{
			var parser = new PacketParser(packet, sender, def);
			parser.Parse();
			return parser.ParsedPacket;
		}
Ejemplo n.º 18
0
		public static ParsedSegment Parse(RealmPacketOut realmPacketOut, PacketSender sender, PacketDefinition def)
		{
			using (var packetIn = DisposableRealmPacketIn.CreateFromOutPacket(realmPacketOut))
			{
				//if (packetIn.PacketID == RealmServerOpCode.SMSG_COMPRESSED_MOVE)
				//{
				//    using (var movePacket = ParseCompressedMove(packetIn))
				//    {
				//        return Parse(movePacket, sender, def);
				//    }
				//}
				return Parse(packetIn, sender, def);
			}
		}
Ejemplo n.º 19
0
 public static ParsedSegment Parse(RealmPacketOut realmPacketOut, PacketSender sender, PacketDefinition def)
 {
     using (var packetIn = DisposableRealmPacketIn.CreateFromOutPacket(realmPacketOut))
     {
         //if (packetIn.PacketID == RealmServerOpCode.SMSG_COMPRESSED_MOVE)
         //{
         //    using (var movePacket = ParseCompressedMove(packetIn))
         //    {
         //        return Parse(movePacket, sender, def);
         //    }
         //}
         return(Parse(packetIn, sender, def));
     }
 }