/// <summary>
 /// Poqwpulate player object with stats from server
 /// </summary>
 public void UpdateStats()
 {
     SendCommand("Person");
     // Find the server response to the 'Person' command.
     XMLResponse response = new XMLResponse();
     do { response = FindResponse("Person"); }
     while (response == null);
     // Populate client-side player statistics via 'Person' response.
     _player.kingdomName = response.message[0].body[0];
     _player.race = response.message[1].body[0];
     _player.level = response.message[1].body[1];
     _player.name = response.message[1].body[2];
     _player.movement = Convert.ToInt32(response.message[2].body[0].Substring(0, response.message[2].body[0].IndexOf(" ")));
     _player.structures = Convert.ToInt32(response.message[2].body[1].Substring(0, response.message[2].body[1].IndexOf(" ")));
     _player.gold = Convert.ToInt32(response.message[2].body[2].Substring(0, response.message[2].body[2].IndexOf(" ")));
     _player.land = Convert.ToInt32(response.message[3].body[0].Substring(0, response.message[3].body[0].IndexOf(" ")));
     _player.peasants = Convert.ToInt32(response.message[3].body[1].Substring(0, response.message[3].body[1].IndexOf(" ")));
     _player.food = Convert.ToInt32(response.message[3].body[2].Substring(0, response.message[3].body[2].IndexOf(" ")));
     _player.city = response.message[5].body[0];
     _player.continent = response.message[5].body[1];
     _player.experience = Convert.ToInt32(response.message[6].body[0]);
     _player.protection = (response.message[6].body[1] == "YES") ? true : false;
     _player.taxes = response.message[6].body[2];
 }
 /// <summary>
 /// Convert raw XML string data from server into XMLResponse objects.
 /// </summary>
 /// <param name="_response">Raw XML string data</param>
 /// <returns></returns>
 public XMLResponse ParseResponse(string _response)
 {
     int bodyId = 0;
     int id = 0;
     XMLResponse response = new XMLResponse();
     XElement XML;
     XML = XElement.Parse(_response);
     response.user = XML.Element("User").Value;
     response.command = XML.Element("Command").Value;
     response.token = XML.Element("Token").Value;
     foreach (XElement msgElem in XML.Elements("Message"))
     {
         response.message.Add(new XMLMessage());
         response.message[id].id = msgElem.Attribute("Id").Value;
         foreach (XElement bodyElem in msgElem.Elements("Body"))
         {
             response.message[id].body.Add(bodyElem.Value);
             bodyId += 1;
         }
         bodyId = 0;
         id += 1;
     }
     return response;
 }
 /// <summary>
 /// Login to the server with string parameter as password (character name selected on object instantiation)
 /// </summary>
 /// <param name="password"></param>
 /// <returns></returns>
 public bool Login()
 {
     SendCommand("Validate", new string[] { _password });
     // Find the server response to the validate command.
     XMLResponse response = new XMLResponse();
     do { response = FindResponse("Validate"); }
     while (response == null);
     // Check if the incoming validate response indicates a successful login or not.
     if (response.message[0].id == "46")
     {
         _loggedIn = true;
         _token = response.token;
         UpdateStats();
         return true;
     }
     return false;
 }
 /// <summary>
 /// Create a new character with the name '_playerName'e
 /// </summary>
 public void Newplayer()
 {
     SendCommand ("Newplayer", new string[] { _password, "", "" } );
     // Find the server response to the newplayer command.
     XMLResponse response = new XMLResponse();
     do { response = FindResponse("Newplayer"); }
     while (response == null);
     // Retrieve initial player stats after creating character.
     UpdateStats();
 }
 /// <summary>
 /// Login to the server with string parameter as password (character name selected on object instantiation)
 /// </summary>
 /// <param name="password"></param>
 /// <returns></returns>qw
 public bool Login(string password)
 {
     XMLResponse response = new XMLResponse();
     SendCommand("Validate", new string[] { password });
     do
     {
         response = FindResponse("Validate");
     }
     while (response == null);
     if (response.message[0].id == "46")
     {
         _loggedIn = true;
         _token = response.token;
         UpdateStats();
         return true;
     }
     UpdateStats();
     return false;
 }