Exemple #1
0
        public bool GetVillageDetails(MapCoordinates village)
        {
            Log.Debug("GetVillageDetails");
            browser.GoTo(village.VillageLink);
            Table tableVillageInfo = browser.Table(Find.ById("village_info"));
            if (tableVillageInfo.Exists)
            {
                Log.Debug(village.VillageName);
                if (!browser.Link(Find.ByUrl(new Regex("build.php.z=*"))).Exists)
                {
                    oasis.Add(village);
                    Log.Debug("Oazis : Merchants link not found");
                    return false;
                }
                if (tableVillageInfo.TableRows.Count == 4)
                {
                    oasis.Add(village);
                    Log.Debug("Oazis : 4 TableRows");
                    return false;
                }
                string nameAndCoordinates = tableVillageInfo.TableRows[0].Text;
                int lastIndexOf = nameAndCoordinates.LastIndexOf('(');
                if (lastIndexOf == -1)
                {
                    oasis.Add(village);
                    Log.DebugFormat("Oazis : {0}", nameAndCoordinates);
                    return false;
                }
                village.VillageName = nameAndCoordinates.Substring(0, lastIndexOf - 1);
                string coordinates = nameAndCoordinates.Substring(lastIndexOf).Trim();
                if (coordinates.IndexOf('|') == -1)
                {
                    Log.Warn("Failed to parse coordinates");
                    return false;
                }
                village.Coordinates = coordinates;
                string[] strings = coordinates.Split('|', '(', ')');
                village.CoordinateX = Misc.String2Number(strings[1]);
                village.CoordinateY = Misc.String2Number(strings[2]);
                village.Tribe = tableVillageInfo.TableRows[1].TableCells[0].Text;
                village.AllianceId = 0;
                village.AllianceName = tableVillageInfo.TableRows[2].TableCells[0].Text;
                village.AllianceLink =
                    tableVillageInfo.TableRows[2].TableCells[0].Link(Find.ByUrl(new Regex("allianz.php*"))).Url;
                Regex regAllianceId = new Regex(@"allianz.php.aid=([0-9]{0,8})");
                if (regAllianceId.IsMatch(village.AllianceLink))
                {
                    Match mc = regAllianceId.Matches(village.AllianceLink)[0];
                    village.AllianceId = Misc.String2Number(mc.Groups[1].Value.Trim());
                }
                village.PlayerId = -1;
                village.PlayerName = tableVillageInfo.TableRows[3].TableCells[0].Text;
                village.PlayerNameLink =
                    tableVillageInfo.TableRows[3].TableCells[0].Link(Find.ByUrl(new Regex("spieler.php*"))).Url;
                Regex regPlayerId = new Regex(@"spieler.php.uid=([0-9]{0,6})");
                if (regPlayerId.IsMatch(village.PlayerNameLink))
                {
                    Match mc = regPlayerId.Matches(village.PlayerNameLink)[0];
                    village.PlayerId = Misc.String2Number(mc.Groups[1].Value.Trim());
                }
                village.Population = Misc.String2Number(tableVillageInfo.TableRows[4].TableCells[0].Text);
                village.PlayerStatus = "Available";
                village.PlayerStatusLink = String.Format(CultureInfo.InvariantCulture, "{0}a2b.php?z={1}", Server, village.VillageId);
                Table tableOptions = browser.Table(Find.ById("options"));
                if (tableOptions.Exists)
                {
                    TableCell tableCell = tableOptions.TableBodies[0].TableRows[1].TableCells[0];
                    if (tableCell.Exists)
                    {
                        village.PlayerStatus = tableCell.Title;
                        if (tableCell.Links.Count>0)
                        {
                            Link link = tableCell.Links[0];
                            village.PlayerStatus = link.Text;
                            village.PlayerStatusLink = link.Url;
                            village.PlayerEnabled = true;
                        }
                        else
                        {
                            village.PlayerEnabled = false;
                        }
                    }
                }
                Log.InfoFormat("Village : {0}", village.ToString());
            /*
            <table cellspacing="1" cellpadding="1" class="tableNone" id="options">
            <thead>
            <tr>
            <th>Options</th>
            </tr>
            </thead>
            <tbody>
            <tr>
            <td><a href="karte.php?z=348625">» Centre map.</a></td>
            </tr>
            <tr>
            <td title="Beginners protection till 28.11.09 17:32." class="none">» Send troops. (Player is in beginner's protection.)</td>
            </tr>
            <tr>
            <td><a href="build.php?z=348625&amp;gid=17" class="">» Send merchant(s).</a></td>
            </tr>
            </tbody>
            </table>

            <table cellspacing="1" cellpadding="1" class="tableNone" id="options">
            <thead>
            <tr>
            <th>Options</th>
            </tr>
            </thead>
            <tbody>
            <tr>
            <td><a href="karte.php?z=347834">» Centre map.</a></td>
            </tr>
            <tr>
            <td><a href="a2b.php?z=347834">» Send troops.</a></td>
            </tr>
            <tr>
            <td><a href="build.php?z=347834&amp;gid=17" class="">» Send merchant(s).</a></td>
            </tr>
            </tbody>
            </table>
            */
                return true;
            }
            if (browser.Table(Find.ById("distribution")).Exists)
            {
                abandoned.Add(village);
                Log.DebugFormat("Abandoned : {0}", village.VillageName);
                return false;
            }
            oasis.Add(village);
            Log.DebugFormat("Oazis : {0}", village.VillageName);
            return false;
        }
Exemple #2
0
 /// <summary>
 /// Saves the <see cref="MapCoordinates"/> to db.
 /// </summary>
 /// <param name="mapCoordinate">The map coordinate.</param>
 public void SaveVillageToDb(MapCoordinates mapCoordinate)
 {
     using (sqlConnection = new SqlConnection(connectionString))
     {
         sqlConnection.Open();
         using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
         {
             sqlCommand.CommandType = CommandType.StoredProcedure;
             sqlCommand.CommandText = "UpdateMap";
             sqlCommand.Parameters.Add(new SqlParameter("@VillageId", SqlDbType.Int)).Value =
                 mapCoordinate.VillageId;
             sqlCommand.Parameters.Add(new SqlParameter("@VillageName", SqlDbType.NVarChar)).Value =
                 mapCoordinate.VillageName;
             sqlCommand.Parameters.Add(new SqlParameter("@VillageLink", SqlDbType.NVarChar)).Value =
                 mapCoordinate.VillageLink;
             sqlCommand.Parameters.Add(new SqlParameter("@UserId", SqlDbType.Int)).Value = mapCoordinate.PlayerId;
             sqlCommand.Parameters.Add(new SqlParameter("@UserName", SqlDbType.NVarChar)).Value =
                 mapCoordinate.PlayerName;
             sqlCommand.Parameters.Add(new SqlParameter("@UserLink", SqlDbType.NVarChar)).Value =
                 mapCoordinate.PlayerNameLink;
             sqlCommand.Parameters.Add(new SqlParameter("@AllianceId", SqlDbType.Int)).Value =
                 mapCoordinate.AllianceId;
             sqlCommand.Parameters.Add(new SqlParameter("@AllianceName", SqlDbType.NVarChar)).Value =
                 mapCoordinate.AllianceName;
             sqlCommand.Parameters.Add(new SqlParameter("@AllianceLink", SqlDbType.NVarChar)).Value =
                 mapCoordinate.AllianceLink;
             sqlCommand.Parameters.Add(new SqlParameter("@Population", SqlDbType.Int)).Value =
                 mapCoordinate.Population;
             sqlCommand.Parameters.Add(new SqlParameter("@CoordinateX", SqlDbType.Int)).Value =
                 mapCoordinate.CoordinateX;
             sqlCommand.Parameters.Add(new SqlParameter("@CoordinateY", SqlDbType.Int)).Value =
                 mapCoordinate.CoordinateY;
             sqlCommand.Parameters.Add(new SqlParameter("@TribeName", SqlDbType.NVarChar)).Value =
                 mapCoordinate.Tribe;
             sqlCommand.Parameters.Add(new SqlParameter("@PlayerStatus", SqlDbType.NVarChar)).Value =
                 mapCoordinate.PlayerStatus;
             sqlCommand.Parameters.Add(new SqlParameter("@PlayerStatusLink", SqlDbType.NVarChar)).Value =
                 mapCoordinate.PlayerStatusLink;
             sqlCommand.ExecuteNonQuery();
         }
     }
 }
Exemple #3
0
 private void AddVillagesFromMap()
 {
     Log.Debug("AddVillagesFromMap");
     foreach (Area area in browser.Areas)
     {
         string title = area.Title;
         if (title.Length > 0)
         {
             string destination = area.Url;
             if (destination.IndexOf("&c=") > -1)
             {
                 MapCoordinates mapCoordinates = new MapCoordinates(title, destination);
                 if (!villages.Contains(mapCoordinates))
                 {
                     villages.Add(mapCoordinates);
                     Log.DebugFormat("Added {0}", mapCoordinates.VillageName);
                 }
             }
         }
     }
 }
Exemple #4
0
 /// <summary>
 /// Gets the farm list.
 /// </summary>
 /// <returns></returns>
 public IList<MapCoordinates> GetFarmList()
 {
     WebGuiSettings webGuiSettings = GetSettings();
     if (webGuiSettings == null)
     {
         return null;
     }
     List<MapCoordinates> farmList = new List<MapCoordinates>();
     try
     {
         using (sqlConnection = new SqlConnection(connectionString))
         {
             sqlConnection.Open();
             SqlCommand sqlCommand = sqlConnection.CreateCommand();
             sqlCommand.CommandType = CommandType.StoredProcedure;
             sqlCommand.CommandText = "SelectMap";
             sqlCommand.Parameters.Add(new SqlParameter("@CoordinateX", SqlDbType.Int)).Value =
                 webGuiSettings.CoordinatesX;
             sqlCommand.Parameters.Add(new SqlParameter("@CoordinateY", SqlDbType.Int)).Value =
                 webGuiSettings.CoordinatesY;
             sqlCommand.Parameters.Add(new SqlParameter("@DistanceX", SqlDbType.Int)).Value =
                 webGuiSettings.DistanceX;
             sqlCommand.Parameters.Add(new SqlParameter("@DistanceY", SqlDbType.Int)).Value =
                 webGuiSettings.DistanceY;
             SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
             if (sqlDataReader != null)
             {
                 while (sqlDataReader.Read())
                 {
                     MapCoordinates mapCoordinates = new MapCoordinates
                                                     {
                                                         VillageId =
                                                             Int32.Parse(sqlDataReader["VillageId"].ToString()),
                                                         VillageLink = sqlDataReader["VillageLink"].ToString(),
                                                         VillageName = sqlDataReader["VillageName"].ToString()
                                                     };
                     farmList.Add(mapCoordinates);
                 }
                 sqlDataReader.Close();
             }
         }
     }
     catch (SqlException exception)
     {
         Log.Error(exception.Message);
         Log.Error(exception);
         return null;
     }
     finally
     {
         sqlConnection.Close();
     }
     return farmList;
 }