Example #1
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));
        }
Example #2
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));
        }
        void SaveTest()
        {
            var msgSegment       = new PacketSegmentStructure(SimpleType.CString, "Message");
            var targetMsgSegment = new PacketSegmentStructure[] {
                new PacketSegmentStructure(SimpleType.CString, "Target"),
                new PacketSegmentStructure(SimpleType.CString, "Message")
            }.ToList();

            SwitchPacketSegmentStructure msgTypeSwitch;


            var defs = new RealmPacketDefinition();

            Definitions = new XmlPacketDefinition[] {
                new RealmPacketDefinition(RealmServerOpCode.CMSG_CAST_SPELL,
                                          //new ComplexPacketSegmentStructure(
                                          //new PacketSegmentStructure[] {
                                          new PacketSegmentStructure(SimpleType.UInt, "Spell Id", typeof(SpellId))
                                          //})
                                          ),
                defs
            };
            defs.OpCodes   = new[] { RealmServerOpCode.CMSG_MESSAGECHAT };
            defs.Structure = new[] {
                new PacketSegmentStructure(SimpleType.UInt, "Type", typeof(ChatMsgType)),
                new PacketSegmentStructure(SimpleType.UInt, "Language", typeof(ChatLanguage)),
                msgTypeSwitch = new SwitchPacketSegmentStructure("TargetAndMessage", "Type",
                                                                 new SwitchCase(ComparisonType.Equal, ChatMsgType.Say, msgSegment),
                                                                 new SwitchCase(ComparisonType.Equal, ChatMsgType.Yell, msgSegment),
                                                                 new SwitchCase(ComparisonType.Equal, ChatMsgType.Emote, msgSegment),
                                                                 new SwitchCase(ComparisonType.Equal, ChatMsgType.Party, msgSegment),
                                                                 new SwitchCase(ComparisonType.Equal, ChatMsgType.Raid, msgSegment),
                                                                 new SwitchCase(ComparisonType.Equal, ChatMsgType.RaidLeader, msgSegment),
                                                                 new SwitchCase(ComparisonType.Equal, ChatMsgType.RaidWarn, msgSegment),
                                                                 new SwitchCase(ComparisonType.Equal, ChatMsgType.Whisper, targetMsgSegment),
                                                                 new SwitchCase(ComparisonType.Equal, ChatMsgType.Channel, targetMsgSegment)
                                                                 )
            }.ToList();
            //defs.Structure.Init();
            Save();
        }
Example #4
0
 public PacketSegmentStructure GetSegment(PacketSegmentStructure segment, string name)
 {
     foreach (var subSegment in segment)
     {
         if (subSegment == null)
         {
             // from here on segments arent initialized yet -> stop search
             return null;
         }
         if (subSegment.Name == name)
         {
             return subSegment;
         }
         var found = GetSegment(subSegment, name);
         if (found != null)
         {
             return found;
         }
     }
     return null;
 }
Example #5
0
		public ParsedSegment(PacketSegmentStructure structure, object value)
		{
			m_subSegments = new Dictionary<string, ParsedSegment>(StringComparer.InvariantCultureIgnoreCase);

			m_structure = structure;

			if (value is List<ParsedSegment>)
			{
				var list = (List<ParsedSegment>)value;
				Value = list.Count;

				if (IsList)
				{
					throw new Exception("Used List-CTor for Segment that is not a list.");
				}
				m_list = list;
			}
			else
			{
				Value = value;

				if (IsList)
				{
					m_list = new List<ParsedSegment>();
				}
			}
		}
Example #6
0
 static void WarnLength(SimpleType type, PacketSegmentStructure segment, PacketParser parser)
 {
     log.Warn(
         "Packet {0} has invalid definition and tries to read {1} with insufficient remaining length at {2}",
         parser.Packet.PacketId, type, segment);
 }
Example #7
0
 public PacketDefinition(PacketId packetId, PacketSender sender, PacketSegmentStructure structure)
 {
     PacketIds = new[] { packetId };
     Sender = sender;
     Structure = structure ?? new ComplexPacketSegmentStructure();
 }
Example #8
0
 public PacketDefinition(PacketId[] packetIds, PacketSender sender, PacketSegmentStructure structure)
 {
     PacketIds = packetIds;
     Sender = sender;
     Structure = structure ?? new ComplexPacketSegmentStructure();
 }