Esempio n. 1
0
        public virtual object Clone()
        {
            var p = new DsoChatPacket();

            p.Messages.AddRange(Messages);
            return(p);
        }
Esempio n. 2
0
        public static DsoChatPacket Parse(string rawXmlData, byte[] rawData)
        {
            PacketLogger.LogPacket(rawXmlData);

            string xmlBody = SkipHeader(rawXmlData);

            if (string.IsNullOrEmpty(xmlBody))
            {
                // Failed to match against XML
                // Try AMF
                DsoChatPacket amfPacket;
                if ((amfPacket = TryParseAmf(rawXmlData, rawData)) == null)
                {
                    return(null);
                }

                return(amfPacket);
            }
            if (BodyDetection.IsMatch(xmlBody) == false)
            {
                return(null);
            }

            PacketLogger.LogChatPacket(xmlBody);

            // Remove namespaces..
            xmlBody = Regex.Replace(xmlBody, " xmlns=(\"|')[^\"']*(\"|')", "");

            // Get all messages
            MatchCollection matches = RegexMessages.Matches(xmlBody);

            if (matches == null || matches.Count == 0)
            {
                return(null);
            }

            // Build our xml struct
            // <body><messages>...</messages></body>
            string validXml = "<body><messages>";

            foreach (Match match in matches)
            {
                validXml += match.Value;
            }
            validXml += "</messages></body>";

            // Deserialize
            try {
                XmlSerializer serializer = new XmlSerializer(typeof(DsoChatPacket));
                using (StringReader stringStream = new StringReader(validXml)) {
                    DsoChatPacket doc = (DsoChatPacket)serializer.Deserialize(stringStream);
                    return(doc);
                }
            } catch {
                // Incomplete packet maybe..

                return(null);
            }
        }
Esempio n. 3
0
		private void AddPacket(DsoChatPacket packet) {
			foreach (DsoChatPacketMessage msg in packet.Messages) {
				switch (msg.Type) {
					case EDsoMsgTypes.ChatGlobal:
						chatGlobal.AddMessage(msg);
						HighlightTab(tabPageChatGlobal);
						break;
					case EDsoMsgTypes.ChatHelp:
						chatHelp.AddMessage(msg);
						HighlightTab(tabPageChatHelp);
						break;
					case EDsoMsgTypes.Trade:
						// Build trade instance
						// @EDIT: Trade now is a simple chat
						/*
						DsoTrade trade = DsoTrade.Create(msg, (msg.MessageDetails != null ? msg.MessageDetails.Player : "<unknown?>"));
						if (trade != null) {
							// Add to statistics
							ItemStats.CountAverage(trade.OfferedItem, trade.DemandedItem, trade.Ratio);
							// Add to trade list
							listTrades.AddTrade(trade);
							// highlight tab
							HighlightTab(tabPageTrades);
							// Refresh count
							lblStatusTrades.Text = string.Format("Trades: {0}", listTrades.GetItemCount());
						}
						*/
						break;
				}

				// Delete trades
				if ((msg.Type & EDsoMsgTypes.Clear) == EDsoMsgTypes.Clear) {
					if ((msg.Type & EDsoMsgTypes.Trade) == EDsoMsgTypes.Trade) {
						DsoTrade trade = DsoTrade.Create(msg, (msg.MessageDetails != null ? msg.MessageDetails.Player : "<unknown?>"));
						if (trade != null && listTrades.RemoveTrade(trade) == false) {
							//SetStatus("Failed to remove trade from player \"" + trade.Player + "\".");
						} else {
							// Refresh count
							lblStatusTrades.Text = string.Format("Trades: {0}", listTrades.GetItemCount());
						}
					}
				}

				// Count captured packets
				mCapturedPackets++;
				lblStatusPackets.Text = string.Format("Packets: {0}", mCapturedPackets);
			}
		}
Esempio n. 4
0
		public void AddMessages(DsoChatPacket packet) {
			AddMessages(packet.Messages);
		}
Esempio n. 5
0
		public virtual object Clone() {
			var p = new DsoChatPacket();
			p.Messages.AddRange(Messages);
			return p;
		}