private void buttonGetInfoAliance_Click(object sender, EventArgs e) { string alianceId = textBoxAlianceId.Text.Length > 1 ? textBoxAlianceId.Text : "1"; string[] allyIds = alianceId.IndexOf(',') > -1 ? alianceId.Split(',') : new[] {alianceId}; ServerInfo serverInfo = new ServerInfo(); alianceData = new AlianceData(); LoginPageData loginPageData = new LoginPageData(serverInfo); bool logedIn = Misc.Login(serverInfo, loginPageData); if (logedIn) { textBoxStatus.Text += "Loged in...\r\n"; foreach (string allyId in allyIds) { string pageSource = Http.SendData(serverInfo.AlianceUrl + allyId, null, serverInfo.CookieContainer, serverInfo.CookieCollection); ParseMembersStats(serverInfo, pageSource, alianceData); FillData(alianceData); } } else { textBoxStatus.Text += "Not loged in...\r\n"; } }
public Send(ServerInfo serverInfo, TroopSenderParamaters parameters) { this.serverInfo = serverInfo; this.parameters = parameters; thread = new Thread(SendTroops); thread.Name = parameters.Id; thread.Start(); }
public void ParseReports() { ServerInfo serverInfo = new ServerInfo(); ReportReader reportReader = new ReportReader(serverInfo); string pageSource = Misc.ReadContent(@"..\..\..\Samples\TestFiles\berichte.php"); reportReader.Parse(pageSource); MatchCollection reportCollection = reportReader.ReportCollection; Assert.AreEqual(4, reportCollection.Count); }
public SendResourcesExecutor(ServerInfo serverInfo) { DirectoryInfo di = new DirectoryInfo(Misc.GetConfigValue("sendResourcesDirectory")); FileInfo[] files = di.GetFiles("*.xml"); foreach (FileInfo file in files) { //Console.WriteLine("Found '{0}' in '{1}'", file, di.FullName); fileNames.Add(file.FullName); } this.serverInfo = serverInfo; }
public void ParseAlianceId(ServerInfo serverInfo) { //<a href="allianz.php?aid=2092"> serverInfo.AlianceId = -1; Regex regAlianceID = new Regex(@"<a href=""allianz.php.aid=([0-9]{0,6})"">"); if (regAlianceID.IsMatch(pageSource)) { Match Mc = regAlianceID.Matches(pageSource)[0]; serverInfo.AlianceId = Int32.Parse(Mc.Groups[1].Value.Trim()); } }
public void SendTroopsExecutorProcess() { ServerInfo serverInfo = new ServerInfo(); serverInfo.Villages.Add(new Village(0, "01")); serverInfo.Villages.Add(new Village(1, "01")); serverInfo.Villages.Add(new Village(3, "01")); serverInfo.Villages.Add(new Village(83117, "01")); SendResourcesExecutor sendResourcesExecutor = new SendResourcesExecutor(serverInfo); sendResourcesExecutor.Parse(); sendResourcesExecutor.Process(); }
public SendTroopsExecutor(ServerInfo serverInfo) { //DirectoryInfo di = new DirectoryInfo(Directory.GetCurrentDirectory() + "\\sendtroops"); DirectoryInfo di = new DirectoryInfo(Misc.GetConfigValue("sendTroopsDirectory")); FileInfo[] attackFiles = di.GetFiles("*.xml"); foreach (FileInfo attackFile in attackFiles) { //Console.WriteLine("Found '{0}' in '{1}'", attackFile, di.FullName); fileNames.Add(attackFile.FullName); } this.serverInfo = serverInfo; }
public void SendTroopsExecutorParser() { ServerInfo serverInfo = new ServerInfo(); SendResourcesExecutor sendResourcesExecutor = new SendResourcesExecutor(serverInfo); sendResourcesExecutor.Parse(); Assert.IsNotNull(sendResourcesExecutor.ActionList); Assert.IsNotNull(sendResourcesExecutor.ActionContainer); Assert.IsNotNull(sendResourcesExecutor.ActionContainer.ActionsContainer.Count); Assert.AreEqual(1, sendResourcesExecutor.ActionContainer.ActionsContainer.Count); Assert.AreEqual(3, sendResourcesExecutor.ActionList.SendResourcesList.Count); Assert.AreEqual(-1, sendResourcesExecutor.ActionList.GetSendResourcesAction("1").GetResourceSendParameters("1").DestinationVillageY); }
public void SendTroopsExecutorParser() { ServerInfo serverInfo = new ServerInfo(); SendTroopsExecutor sendTroopsExecutor = new SendTroopsExecutor(serverInfo); sendTroopsExecutor.Parse(); Assert.IsNotNull(sendTroopsExecutor.ActionList); Assert.IsNotNull(sendTroopsExecutor.ActionContainer); Assert.IsNotNull(sendTroopsExecutor.ActionContainer.ActionsContainer.Count); Assert.AreEqual(1, sendTroopsExecutor.ActionContainer.ActionsContainer.Count); Assert.AreEqual(4, sendTroopsExecutor.ActionList.ActionsList.Count); Assert.AreEqual("asd", sendTroopsExecutor.ActionList.ActionsList["1"].GetActionParameters("1").PlayerName); }
public static bool IsLogedIn(ServerInfo serverInfo, string postData) { string pageSource = Http.SendData(serverInfo.Dorf1Url, postData, serverInfo.CookieContainer, serverInfo.CookieCollection); HtmlParser htmlParser = new HtmlParser(pageSource); //Console.WriteLine(pageSource); htmlParser.ParseUserId(serverInfo); bool uidFound = serverInfo.UserId < 0 ? false : true; if (uidFound) { pageSource = Http.SendData(serverInfo.SpielerUrl + serverInfo.UserId, null, serverInfo.CookieContainer, serverInfo.CookieCollection); htmlParser = new HtmlParser(pageSource); htmlParser.ParseAlianceId(serverInfo); } return uidFound; }
private void buttonGetInfoUid_Click(object sender, EventArgs e) { string username = textBoxUid.Text.Length > 1 ? textBoxUid.Text : "kmet"; ServerInfo serverInfo = new ServerInfo(); LoginPageData loginPageData = new LoginPageData(serverInfo); bool logedIn = Misc.Login(serverInfo, loginPageData); if (logedIn) { textBoxStatus.Text += "Loged in...\r\n"; alianceData = new AlianceData(); GetStats(serverInfo, 1, username, alianceData); FillData(alianceData); } else { textBoxStatus.Text += "Not loged in...\r\n"; } }
public ReportReader(ServerInfo serverInfo) { this.serverInfo = serverInfo; }
public void ParseUserId(ServerInfo serverInfo) { //<a href="spieler.php?uid=9500">Profil</a> serverInfo.UserId = -1; Regex regPlayerID = new Regex(@"<a href=""spieler.php.uid=([0-9]{0,6})"">"); if (regPlayerID.IsMatch(pageSource)) { Match Mc = regPlayerID.Matches(pageSource)[0]; serverInfo.UserId = Int32.Parse(Mc.Groups[1].Value.Trim()); } }
public void ParseVillages(ServerInfo serverInfo) { //<a href="?newdid=83117">01</a> //<a href="?newdid=73913">01</a> 3.5 //<a href=\"\?newdid=([0-9]{0,7})\"\s?(accesskey=\"\w\")?>([\w\W\d\D\s\S]{0,50})<\/a> MatchCollection villagesCollection = Regex.Matches(pageSource, @"<a href="".newdid=([0-9]{0,7})""\s?(accesskey=""\w"")?>([\w\W\d\D\s\S]{0,50})<.a>"); int villageCount = villagesCollection.Count; //Console.WriteLine("villageCount=" + villageCount); for (int i = 0; i < villageCount; i++) { //Console.WriteLine(villagesCollection[i].Groups[0].Value); //Console.WriteLine(villagesCollection[i].Groups[1].Value); //Console.WriteLine(villagesCollection[i].Groups[3].Value); //102706" class="active_vl int villageId = Int32.Parse(Misc.GetOnlyNumbers(villagesCollection[i].Groups[1].Value)); string villageName = villagesCollection[i].Groups[3].Value.Trim(); Village village = new Village(villageId, villageName); serverInfo.Villages.Add(village); } if (villageCount < 2) { const string regVillageName = @"<div class=""dname""><h1>(.*)</h1></div>"; villagesCollection = Regex.Matches(pageSource, regVillageName); Village village = new Village(0, villagesCollection[0].Groups[1].Value.Trim()); serverInfo.Villages.Add(village); } }
public static bool Login(ServerInfo serverInfo, LoginPageData loginPageData) { string postData = String.Format("login={0}&{1}={2}&{3}={4}&{5}={6}&{5}={6}&s1.x=83&s1.y=7&s1=login", loginPageData.HiddenLoginValue, "name", serverInfo.Username, "password", serverInfo.Password, loginPageData.HiddenName, loginPageData.HiddenValue); Console.WriteLine(postData); return IsLogedIn(serverInfo, postData); }
public LoginPageData(ServerInfo serverInfo) { string pageSource = Http.SendData(serverInfo.LoginUrl, null, serverInfo.CookieContainer, serverInfo.CookieCollection); GetLoginPageData(pageSource); }
public static void UpdateVillages(ServerInfo serverInfo) { serverInfo.Villages.Clear(); string pageSource = Http.SendData(serverInfo.Dorf1Url, null, serverInfo.CookieContainer, serverInfo.CookieCollection); HtmlParser htmlParser = new HtmlParser(pageSource); htmlParser.ParseVillages(serverInfo); Console.WriteLine("User: {1}[{0}]", serverInfo.UserId, serverInfo.Username); Console.WriteLine("AlianceId: {0}", serverInfo.AlianceId); Console.WriteLine("Villages:"); Console.WriteLine("Id Name"); foreach (Village village in serverInfo.Villages) { Console.WriteLine("{1,-10}{0}", village.VillageName, village.VillageId); } }
private void ParseMembersStats(ServerInfo serverInfo, string pageSource, AlianceData data) { int delay = Int32.Parse(comboBoxDelay.Text); //<td align="right">1.</td><td class="s7"><a href="spieler.php?uid=9446">NoBody.</a></td> //<td align=""right"">([0-9{0,2}]).</td><td class=""(.*)""><a href=""spieler.php.uid=([0-9]{0,6})"">(.*)</a></td> //<td class="ra">1.</td><td class="pla"><a href="spieler.php?uid=2485">klukec</a></td><td class="hab">689</td> const string patternAlianceMembers = @"<td class=""ra"">([0-9]{0,3}).</td><td class=""pla""><a href=""spieler.php.uid=([0-9]{0,6})"">(.*)</a></td>"; MatchCollection alianceMembersCollection = Regex.Matches(pageSource, patternAlianceMembers); int alianceMembers = alianceMembersCollection.Count; textBoxStatus.Text += "Found " + alianceMembers + " aliance members...\r\n"; progressBarStatus.Maximum = alianceMembers; progressBarStatus.Value = progressBarStatus.Minimum; for (int i = 0; i < alianceMembers; i++) { int number = Int32.Parse(alianceMembersCollection[i].Groups[1].Value.Trim()); string username = alianceMembersCollection[i].Groups[3].Value.Trim(); GetStats(serverInfo, number, username, data); Thread.Sleep(delay); //this checking is automatically done as stated in the Ref Documentation //but it does not work , BUGssssss //so we have to do it shhhhh .... if (progressBarStatus.Value == progressBarStatus.Maximum) { progressBarStatus.Value = progressBarStatus.Minimum; } progressBarStatus.PerformStep(); } }
public void ParseUnitsInVillage(ServerInfo serverInfo, int villageId) { /* <tr> <td><a href="build.php?gid=16"><img class="unit u15" src="img/x.gif" alt="Paladinov" title="Paladinov" /></a></td> <td class="u_count"><b>747</b></td> <td class="u_name">Paladinov</td> </tr> */ const string patternUnits = @"<td class=""u_count""><b>(\d+)</b></td>(.|[\r\n])*?<td class=""u_name"">((\w*)(\s*)(\w*))</td>"; //const string patternUnits = @"<b>(\d+)</b></td><td>((\w*)(\s*)(\w*))</td>"; MatchCollection unitsCollection = Regex.Matches(pageSource, patternUnits); //Console.WriteLine("unitsCollection.Count=" + unitsCollection.Count); Village village = serverInfo.GetVillage(villageId); village.RemoveVillageUnits(); for (int i = 0; i < unitsCollection.Count; i++) { //Console.WriteLine("0" + unitsCollection[i].Groups[0].Value.Trim()); //Console.WriteLine("1" + unitsCollection[i].Groups[1].Value.Trim()); //Console.WriteLine("2" + unitsCollection[i].Groups[2].Value.Trim()); //Console.WriteLine("3" + unitsCollection[i].Groups[3].Value.Trim()); //Console.WriteLine("4" + unitsCollection[i].Groups[4].Value.Trim()); string unitName = unitsCollection[i].Groups[4].Value.Trim(); int unitCount = Int32.Parse(unitsCollection[i].Groups[1].Value.Trim()); Unit unit = new Unit(unitCount, unitName); village.AddVillageUnit(unit); } }
public void Process() { try { ShowBanner(); //Misc.CreateDB(); ServerInfo serverInfo = new ServerInfo(); LoginPageData loginPageData = new LoginPageData(serverInfo); bool logedIn = Misc.Login(serverInfo, loginPageData); if (logedIn) { Misc.UpdateVillages(serverInfo); int repeatCount = 0; do { logedIn = Misc.IsLogedIn(serverInfo, null); if (logedIn) { //DateTime now = new DateTime(DateTime.Now.Ticks); //Console.WriteLine(now.ToLocalTime()); if (repeatCount % 600 == 0) { #region update village names and ids Misc.UpdateVillages(serverInfo); #endregion } if (repeatCount % 1 == 0) { #region attacks SendTroopsExecutor sendTroopsExecutor = new SendTroopsExecutor(serverInfo); sendTroopsExecutor.Parse(); sendTroopsExecutor.Process(); #endregion #region read reports ReportReader reportReader = new ReportReader(serverInfo); string pageSource = Http.SendData(serverInfo.ReportsUrl, null, serverInfo.CookieContainer, serverInfo.CookieCollection); reportReader.Parse(pageSource); reportReader.Process(); #endregion } if (repeatCount % 15 == 0) { //Console.WriteLine("resources"); SendResourcesExecutor sendResourcesExecutor = new SendResourcesExecutor(serverInfo); sendResourcesExecutor.Parse(); sendResourcesExecutor.Process(); } repeatCount++; if (repeatCount > 100) { repeatCount = 0; } } else { Misc.Login(serverInfo, loginPageData); } Thread.Sleep(60000); } while (repeatCount < 1000); } else { Console.WriteLine("Not loged in ..."); } } catch (Exception ex) { Console.WriteLine(ex); } }
private void GetStats(ServerInfo serverInfo, int number, string username, AlianceData data) { PlayerData playerData = new PlayerData {Number = number}; //rank=&name=jasa&submit.x=7&submit.y=8&submit=submit string postData = String.Format("&rank=1&name={0}&submit.x=7&submit.y=8&submit=submit", username); textBoxStatus.Text += postData + "\r\n"; string pageSource = Http.SendData(serverInfo.StatistikAttack, postData, serverInfo.CookieContainer, serverInfo.CookieCollection); HtmlParser htmlParser = new HtmlParser(pageSource); htmlParser.ParseAttackRang(playerData, username); postData = String.Format("&rank=1&name={0}&submit.x=7&submit.y=8&submit=submit", username); textBoxStatus.Text += postData + "\r\n"; pageSource = Http.SendData(serverInfo.StatistikDefense, postData, serverInfo.CookieContainer, serverInfo.CookieCollection); htmlParser = new HtmlParser(pageSource); htmlParser.ParseDefenseRang(playerData, username); postData = String.Format("?rank=1&name={0}&submit.x=7&submit.y=8&submit=submit", username); pageSource = Http.SendData(serverInfo.StatistikRang, postData, serverInfo.CookieContainer, serverInfo.CookieCollection); htmlParser = new HtmlParser(pageSource); htmlParser.ParseRang(playerData, username); data.AddPlayerData(playerData); textBoxStatus.Text += playerData + "\r\n"; }
public void Process() { try { ShowBanner(); ServerInfo serverInfo = new ServerInfo(); LoginPageData loginPageData = new LoginPageData(serverInfo); Thread[] thread = new Thread[actionList.TroopSenderList.Count]; bool logedIn = Misc.Login(serverInfo, loginPageData); if (logedIn) { int actionCount = 0; int executedActions = 0; Misc.UpdateVillages(serverInfo); foreach (Action action in actionList.TroopSenderList) { string id = action.Id; TroopSenderParamaters parameters = action.GetTroopSenderParameters(id); actionCount = actionList.TroopSenderList.Count; Console.WriteLine("Action with id '{1,2}' will be executed at {0}", parameters.Time, parameters.Id); } int repeatCount = 0; do { if (repeatCount % 60 == 0) { logedIn = Misc.IsLogedIn(serverInfo, null); } if (logedIn) { DateTime now = new DateTime(DateTime.Now.Ticks); string timeNow = now.ToString("yyyy-MM-dd HH:mm:ss"); foreach (Action action in actionList.TroopSenderList) { string id = action.Id; TroopSenderParamaters parameters = action.GetTroopSenderParameters(id); if (parameters.Time == timeNow) { //Send.SendTroops(serverInfo, parameters); Send send = new Send(serverInfo, parameters); executedActions++; Console.WriteLine("{0} Executing action with id '{1}'. {2} more action(s) pending for execution.", timeNow, parameters.Id, (actionCount - executedActions)); } } repeatCount++; if (repeatCount > 100) { repeatCount = 0; } if (actionCount == executedActions) { repeatCount = 9999999; Console.WriteLine("{0} All Actions executed...", timeNow); } } else { Misc.Login(serverInfo, loginPageData); } Thread.Sleep(1000); } while (repeatCount < 1000); } else { Console.WriteLine("Not loged in ..."); } } catch (Exception ex) { Console.WriteLine(ex); } }