ikram


SUBMITTED BY: dbzdivik

DATE: Nov. 27, 2015, 5:28 a.m.

UPDATED: Nov. 27, 2015, 6:45 a.m.

FORMAT: Text only

SIZE: 15.5 kB

HITS: 5016

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using System.Diagnostics;
  12. namespace Ikariam
  13. {
  14. public partial class Form1 : Form
  15. {
  16. int waitFrame = 150000;//it means 2 min 30 sec for wait next pirate attack.
  17. int count = 0, earned;
  18. bool pirateStarted = false;
  19. bool captchaEntered = false;
  20. bool sessionError = false;
  21. public static CookieContainer cookies;//this is important about HTTP REQUESTS
  22. HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
  23. string gold, wood, wine, marble,glass, sulfur, ship, shipMax, actionPoints, citizens, population, cityId, actionRequest;
  24. string locale_response;//HTML code after pirate attack done.
  25. public Form1()
  26. {
  27. InitializeComponent();
  28. cookies = new CookieContainer();
  29. pirateLoop();
  30. // This loop starts when application starts. Go to definition to look this method.
  31. }
  32. public static HttpWebRequest GetNewRequest(string targetUrl, CookieContainer SessionCookieContainer)
  33. {
  34. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(targetUrl);
  35. request.CookieContainer = SessionCookieContainer;
  36. request.AllowAutoRedirect = false;
  37. return request;
  38. }
  39. public async static Task<HttpWebResponse> MakeRequest(HttpWebRequest request, CookieContainer SessionCookieContainer, Dictionary<string, string> parameters = null)
  40. {
  41. HttpWebResponse response;
  42. request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5Accept: */*";
  43. request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
  44. request.CookieContainer = SessionCookieContainer;
  45. request.AllowAutoRedirect = false;
  46. if (parameters != null)
  47. {
  48. request.Method = "POST";
  49. request.ContentType = "application/x-www-form-urlencoded";
  50. string s = "";
  51. foreach (KeyValuePair<string, string> pair in parameters)
  52. {
  53. if (s.Length == 0)
  54. {
  55. s = s + string.Format("{0}={1}", pair.Key, pair.Value);
  56. }
  57. else
  58. {
  59. s = s + string.Format("&{0}={1}", pair.Key, pair.Value);
  60. }
  61. }
  62. byte[] bytes = Encoding.UTF8.GetBytes(s);
  63. using (Stream stream = await request.GetRequestStreamAsync())
  64. {
  65. stream.Write(bytes, 0, bytes.Length);
  66. }
  67. }
  68. request.Method = "GET";
  69. response = await request.GetResponseAsync() as HttpWebResponse;
  70. SessionCookieContainer.Add(response.Cookies);
  71. while (response.StatusCode == HttpStatusCode.Found)
  72. {
  73. response.Close();
  74. request = GetNewRequest(response.Headers["Location"], SessionCookieContainer);
  75. response = await request.GetResponseAsync() as HttpWebResponse;
  76. SessionCookieContainer.Add(response.Cookies);
  77. }
  78. return response;
  79. }
  80. void fetchData(string html)
  81. {
  82. doc.LoadHtml(html);
  83. gold = doc.DocumentNode.Descendants("a").Where(s => s.GetAttributeValue("id", "") == "js_GlobalMenu_gold").First().InnerText;
  84. wood = doc.DocumentNode.Descendants("span").Where(s => s.GetAttributeValue("id", "") == "js_GlobalMenu_wood").First().InnerText;
  85. wine = doc.DocumentNode.Descendants("span").Where(s => s.GetAttributeValue("id", "") == "js_GlobalMenu_wine").First().InnerText;
  86. marble = doc.DocumentNode.Descendants("span").Where(s => s.GetAttributeValue("id", "") == "js_GlobalMenu_marble").First().InnerText;
  87. glass = doc.DocumentNode.Descendants("span").Where(s => s.GetAttributeValue("id", "") == "js_GlobalMenu_crystal").First().InnerText;
  88. sulfur = doc.DocumentNode.Descendants("span").Where(s => s.GetAttributeValue("id", "") == "js_GlobalMenu_sulfur").First().InnerText;
  89. ship = doc.DocumentNode.Descendants("span").Where(s => s.GetAttributeValue("id", "") == "js_GlobalMenu_freeTransporters").First().InnerText;
  90. shipMax = doc.DocumentNode.Descendants("span").Where(s => s.GetAttributeValue("id", "") == "js_GlobalMenu_maxTransporters").First().InnerText;
  91. actionPoints = doc.DocumentNode.Descendants("li").Where(s => s.GetAttributeValue("id", "") == "js_GlobalMenu_maxActionPoints").First().InnerText;
  92. citizens = doc.DocumentNode.Descendants("span").Where(s => s.GetAttributeValue("id", "") == "js_GlobalMenu_citizens").First().InnerText;
  93. population = doc.DocumentNode.Descendants("span").Where(s => s.GetAttributeValue("id", "") == "js_GlobalMenu_population").First().InnerText;
  94. cityId = Regex.Match(html, @"cityId=\s*(.+?)\s*""").Groups[1].Value;
  95. actionRequest = doc.DocumentNode.Descendants("input").Where(s => s.GetAttributeValue("id", "") == "js_ChangeCityActionRequest").First().Attributes["value"].Value;
  96. label8.Text = gold;
  97. label7.Text = ship + " / " + shipMax;
  98. label1.Text = wood;
  99. label2.Text = wine;
  100. label3.Text = marble;
  101. label5.Text = glass;
  102. label4.Text = sulfur;
  103. label6.Text = citizens + " / " + population;
  104. }//Fetch Datas from HTML page with HtmlAgilityPack.
  105. async Task<string> login(string server, string id, string pw)
  106. {
  107. if (!server.Contains("http://"))
  108. {
  109. server = "http://" + server;
  110. }
  111. HttpWebRequest newRequest = GetNewRequest(server + "/index.php?action=loginAvatar&function=login", cookies);
  112. Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
  113. dictionary2.Add("name", id);
  114. dictionary2.Add("password", pw);
  115. dictionary2.Add("uni_url", server);
  116. dictionary2.Add("startPageShown", "1");
  117. dictionary2.Add("detectedDevice", "1");
  118. Dictionary<string, string> parameters = dictionary2;
  119. HttpWebResponse gecici = await MakeRequest(newRequest, cookies, parameters);
  120. using (StreamReader reader = new StreamReader(gecici.GetResponseStream()))
  121. {
  122. if (!reader.EndOfStream)
  123. {
  124. return reader.ReadToEnd();
  125. }
  126. }
  127. return "";
  128. }//Returns html codes from successfully or fail login.
  129. async Task<string> pirate_Attack(string server)
  130. {
  131. HttpWebRequest newRequest = GetNewRequest(server + "/index.php?action=PiracyScreen&function=capture&buildingLevel=1&view=pirateFortress&cityId="+cityId+"&position=17&backgroundView=city&currentCityId="+cityId+"&templateView=pirateFortress&currentTab=tabBootyQuest&actionRequest="+actionRequest+"&ajax=1", cookies);
  132. Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
  133. Dictionary<string, string> parameters = dictionary2;
  134. HttpWebResponse gecici = await MakeRequest(newRequest, cookies, parameters);
  135. using (StreamReader reader = new StreamReader(gecici.GetResponseStream()))
  136. {
  137. if (!reader.EndOfStream)
  138. {
  139. return reader.ReadToEnd();
  140. }
  141. }
  142. return "";
  143. }//Starts to pirate bot
  144. async Task<string> pirate_Attack_captcha(string captcha, string server)
  145. {
  146. HttpWebRequest newRequest = GetNewRequest(server + "/index.php?action=PiracyScreen&function=capture&buildingLevel=1&captcha=" + captcha + "&view=pirateFortress&cityId=" + cityId + "&position=17&backgroundView=city&currentCityId=" + cityId + "&templateView=pirateFortress&currentTab=tabBootyQuest&actionRequest=" + actionRequest + "&ajax=1", cookies);
  147. Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
  148. Dictionary<string, string> parameters = dictionary2;
  149. HttpWebResponse gecici = await MakeRequest(newRequest, cookies, parameters);
  150. using (StreamReader reader = new StreamReader(gecici.GetResponseStream()))
  151. {
  152. if (!reader.EndOfStream)
  153. {
  154. return reader.ReadToEnd();
  155. }
  156. }
  157. return "";
  158. }//If Captcha needed, this method is for pirate bot
  159. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  160. {
  161. Process.Start("http://www.elitepvpers.com/forum/members/3828962-naworia.html");
  162. }
  163. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  164. {
  165. Process.Start("http://adf.ly/Xb4Nq");//Just view this ad to support me about finance.
  166. }
  167. private void Form1_Load(object sender, EventArgs e)
  168. {
  169. }
  170. private void button2_Click(object sender, EventArgs e)
  171. {
  172. pirateStarted = true ;
  173. button2.Text = "Loading";
  174. button2.Enabled = false;
  175. textBox1.Enabled = false;
  176. textBox2.Enabled = false;
  177. textBox3.Enabled = false;
  178. }
  179. async void pirateLoop()
  180. {
  181. while (true)
  182. {
  183. try
  184. {
  185. if (pirateStarted && !captchaEntered)
  186. {
  187. fetchData(await login(textBox1.Text, textBox2.Text, textBox3.Text));
  188. button2.Text = "Started";
  189. locale_response = await pirate_Attack(textBox1.Text);
  190. if (locale_response.Contains("captchaNeeded=1"))
  191. {
  192. button4.Enabled = true;
  193. textBox4.Enabled = true;
  194. listBox1.Items.Add("Captcha Needed");
  195. actionRequest = Regex.Match(locale_response, @"actionRequest"":""\s*(.+?)\s*""").Groups[1].Value;
  196. pirateStarted = false;
  197. string id = Regex.Match(locale_response, @"&rand=\s*(.+?)\s*\\").Groups[1].Value;
  198. string url = textBox1.Text + "/index.php?action=Options&function=createCaptcha&rand=" + id;
  199. HttpWebRequest newRequest = GetNewRequest(url, cookies);
  200. HttpWebResponse gecici = await MakeRequest(newRequest, cookies);
  201. pictureBox9.Image = Image.FromStream(gecici.GetResponseStream());
  202. MessageBox.Show("Enter captcha");
  203. }
  204. else if (locale_response.Contains("error"))
  205. {
  206. listBox1.Items.Add("Error about session");
  207. waitFrame = 3000;
  208. sessionError = true;
  209. }
  210. else
  211. {
  212. waitFrame = 155000;
  213. }
  214. if (pirateStarted)
  215. {
  216. captchaEntered = false;
  217. if (!sessionError)
  218. {
  219. progressing();
  220. }
  221. await Task.Delay(waitFrame);
  222. if (!sessionError)
  223. {
  224. count++;
  225. earned += 40;
  226. listBox1.Items.Add("Earned 40 Gold");
  227. }
  228. linkLabel3.Text = "Completed : " + count;
  229. linkLabel4.Text = "Earned : " + earned;
  230. sessionError = false;
  231. }
  232. }
  233. }
  234. catch(Exception Ex)
  235. {
  236. MessageBox.Show(Ex.Message + "\nCheck your credentials.");
  237. button2.Text = "Start";
  238. button2.Enabled = true;
  239. textBox1.Enabled = true;
  240. textBox2.Enabled = true;
  241. textBox3.Enabled = true;
  242. pirateStarted = false;
  243. }
  244. await Task.Delay(2000);
  245. }
  246. }//most important to check about this application
  247. private async void button3_Click(object sender, EventArgs e)
  248. {
  249. fetchData(await login(textBox1.Text, textBox2.Text, textBox3.Text));
  250. }
  251. private async void button4_Click(object sender, EventArgs e)
  252. {
  253. try
  254. {
  255. locale_response = await pirate_Attack_captcha(textBox4.Text, textBox1.Text);
  256. if (locale_response.Contains("captchaNeeded=1"))
  257. {
  258. actionRequest = Regex.Match(locale_response, @"actionRequest"":""\s*(.+?)\s*""").Groups[1].Value;
  259. MessageBox.Show("You entered captcha wrong. Please enter true digits in captcha image");
  260. }
  261. else if(locale_response.Contains("captchaNeeded=0"))
  262. {
  263. actionRequest = Regex.Match(locale_response, @"actionRequest"":""\s*(.+?)\s*""").Groups[1].Value;
  264. listBox1.Items.Add("Captcha entered");
  265. waitFrame = 155000;
  266. button4.Enabled = false;
  267. textBox4.Enabled = false;
  268. textBox4.Text = "";
  269. pirateStarted = true;
  270. pictureBox9.Image = Ikariam.Properties.Resources.captc;
  271. }
  272. }
  273. catch(Exception Ex)
  274. { MessageBox.Show(Ex.Message); }
  275. }
  276. private void button5_Click(object sender, EventArgs e)
  277. {
  278. MessageBox.Show(actionRequest);
  279. }
  280. async void progressing()
  281. {
  282. progressBar1.Value = 0;
  283. for (int i = 0; i < 155; i++)
  284. {
  285. await Task.Delay(1000);
  286. progressBar1.Value++;
  287. this.Text = "Ikariam Pirate Bot v1 - " + Math.Round(((double)progressBar1.Value / (double)progressBar1.Maximum) * 100.00, 1) + "%" ;
  288. }
  289. this.Text = "Ikariam Pirate Bot v1";
  290. }//about timing with progressBar1
  291. }
  292. }

comments powered by Disqus