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(); }
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); } }