Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
namespace PBServer.src.data.xml.parsers
{
using PBServer;
using PBServer.src.data.model;
using PBServer.src.data.xml.holders;
using System;
using System.IO;
using System.Xml;
public class GameServerInfoParser
{
private GameServerInfoHolder _holder;
private static GameServerInfoParser _instance;
public GameServerInfoParser()
{
if (this._holder == null)
{
this._holder = GameServerInfoHolder.getInstance();
}
string path = "data//gameservers.xml";
if (File.Exists(path))
{
this.parse(path);
}
else
{
CLogger.getInstance().info("[GameServerInfoParser]: No Have File: " + path);
}
if (this._holder != null)
{
this._holder.log();
}
}
public static GameServerInfoParser getInstance()
{
if (_instance == null)
{
_instance = new GameServerInfoParser();
}
return _instance;
}
private void parse(string path)
{
XmlDocument document = new XmlDocument();
FileStream inStream = new FileStream(path, FileMode.Open);
if (inStream.Length == 0L)
{
CLogger.getInstance().info("[GameServerInfoParser]: File is Empty: " + path);
}
else
{
try
{
document.Load(inStream);
for (XmlNode node = document.FirstChild; node != null; node = node.NextSibling)
{
if ("list".Equals(node.Name))
{
for (XmlNode node2 = node.FirstChild; node2 != null; node2 = node2.NextSibling)
{
if ("gameserver".Equals(node2.Name))
{
XmlNamedNodeMap attributes = node2.Attributes;
this._holder.addGameServerInfo(new GameServerInfo(attributes.GetNamedItem("name").Value, int.Parse(attributes.GetNamedItem("id").Value), attributes.GetNamedItem("password").Value, int.Parse(attributes.GetNamedItem("type").Value), int.Parse(attributes.GetNamedItem("max_players").Value), attributes.GetNamedItem("ip").Value, int.Parse(attributes.GetNamedItem("port").Value)));
}
}
}
}
}
catch (XmlException exception)
{
CLogger.getInstance().info("[GameServerInfoParser]: Error in file: " + path);
CLogger.getInstance().info("[GameServerInfoParser]: " + exception.Message);
}
inStream.Close();
}
}
}
}
Minha debug ta dando erro Alguen sabe como posso criar essas xml que pede no codico , porfavor que suber criar , eu acradeço!
XmlNamedNodeMap attributes = node2.Attributes;
this._holder.addGameServerInfo(new GameServerInfo(attributes.GetNamedItem("name").Value, int.Parse(attributes.GetNamedItem("id").Value), attributes.GetNamedItem("password").Value, int.Parse(attributes.GetNamedItem("type").Value), int.Parse(attributes.GetNamedItem("max_players").Value), attributes.GetNamedItem("ip").Value, int.Parse(attributes.GetNamedItem("port").Value)));Carregando comentários...