コード例 #1
0
        /// <summary>
        /// Loads all mapped handlers from the file.
        /// </summary>
        /// <param name="File"></param>
        public TibiaGamePacketParserFactory(Stream File, TibiaGameData data)
        {
            GameData = data;
            try
            {
                System.Xml.XmlDocument XMLData = new System.Xml.XmlDocument();
                XMLData.Load(File);

                System.Xml.XmlNodeList Versions = XMLData.GetElementsByTagName("TibiaVersion");
                foreach (System.Xml.XmlNode versionNode in Versions)
                {
                    int version = int.Parse(versionNode.Attributes["id"].InnerText);
                    if (version != GameData.Version)
                    {
                        continue;
                    }

                    foreach (System.Xml.XmlNode packetNode in versionNode.ChildNodes)
                    {
                        if (packetNode.LocalName == "Packet")
                        {
                            PacketParser ph = new PacketParser();
                            string       n  = packetNode.Attributes["type"].InnerText;
                            if (!int.TryParse(packetNode.Attributes["type"].InnerText.Substring(2),
                                              System.Globalization.NumberStyles.HexNumber,
                                              System.Globalization.CultureInfo.InvariantCulture,
                                              out ph.type))
                            {
                                continue;
                            }

                            ph.name   = packetNode.Attributes["parser"].InnerText;
                            ph.parser = GetPacketParser(ph.name);
                            AllHandlers.Add(ph);
                        }
                    }
                }
            }
            catch (System.Xml.XmlException xmlException)
            {
                Log.Error("XML error when parsing internal version table: " + xmlException.Message);
            }
            catch (System.ArgumentException argException)
            {
                Log.Error("Conversion error when parsing internal version table: " + argException.Message);
            }
        }