Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace LoL_AutoAdder
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. _allBots = new List<Bot>();
  19. FormClosed += Form1_Close;
  20. cbRegion.SelectedIndex = 0;
  21. cbFrom.SelectedIndex = 0;
  22. cbTo.SelectedIndex = 5;
  23. lvBots.MouseDoubleClick += lv1_doubleClick;
  24. //_rnd = new Random(DateTime.Now.Millisecond);
  25. }
  26.  
  27. private void lv1_doubleClick(object sender, MouseEventArgs e)
  28. {
  29. if (e.Button != MouseButtons.Left)
  30. return;
  31. foreach (ListViewItem item in lvBots.SelectedItems)
  32. {
  33. InfoPage newPage = new InfoPage { Info = _newDict[item.Text].WebScraper.Logger };
  34. newPage.Prepare(_newDict[item.Text]);
  35. newPage.Show();
  36. }
  37. }
  38.  
  39. private string GetKey(Bot lSender)
  40. {
  41. try
  42. {
  43. return _newDict.First(item => item.Value == lSender).Key;
  44. }
  45. catch (InvalidOperationException)
  46. {
  47. return GetKey(lSender);
  48. }
  49. }
  50.  
  51. private async void bot_disposed(object sender, EventArgs e)
  52. {
  53. if (_shouldStop || IsDisposed)
  54. return;
  55.  
  56. Bot oldBot = (Bot)sender;
  57.  
  58. _allBots.Remove(oldBot);
  59.  
  60. string lKey = GetKey(oldBot);
  61.  
  62. _newDict.Remove(lKey);
  63.  
  64. lvBots.Invoke(new MethodInvoker(
  65. async () =>
  66. {
  67. ListViewItem[] lItems = lvBots.Items.Find(lKey, false);
  68. if (lItems.Length == 0)
  69. return;
  70. lItems[0].Remove();
  71. lblAccepted.Text = @"total friends accepted: " + _allBots.Sum(item => item.WebScraper.Logger.CountFriends);
  72. lblSend.Text = @"total friendrequests sent: " + _allBots.Sum(item => item.WebScraper.Logger.FriendrequestsSend);
  73.  
  74. const int maxReconnectionCount = 3;
  75. bool reconnect = oldBot.ReconnectionCount < maxReconnectionCount;
  76.  
  77. using (var lcontext = new lol_usersEntities())
  78. {
  79. euwbots lItem = null;
  80.  
  81. var oldItem = lcontext.euwbots
  82. .FirstOrDefault(p => p.SummonerName == oldBot.UserName && p.Banned != true);
  83.  
  84. if (oldItem != null)
  85. {
  86. if (!oldBot.LoggedIn && !reconnect)
  87. {
  88. oldItem.Banned = true;
  89. FileLogger.AddMessage($@"Banned.
  90. Bot: Username={ oldItem?.SummonerName}");
  91. }
  92. else if (reconnect)
  93. {
  94. lItem = oldItem;
  95.  
  96. FileLogger.AddMessage($@"Reconnect.
  97. Bot: Username={ oldItem?.SummonerName}");
  98. }
  99. else
  100. {
  101. //Logged in, but don't want to reconnect.
  102. }
  103. }
  104.  
  105. if (lItem == null)
  106. {
  107. var lowerUserName = oldBot.UserName.ToLower();
  108.  
  109. //var random = new Random();
  110. //var number = random.Next(20);
  111.  
  112. lItem = (from item in lcontext.euwbots
  113. where oldBot.WebScraper.LowerRegion == item.Region
  114. && lowerUserName != item.SummonerName
  115. && oldBot.Min <= item.Lvl.Value && oldBot.Max >= item.Lvl.Value
  116. && !item.Active.Value
  117. && !item.Fullfriendlist.Value
  118. select item).OrderBy(x => Guid.NewGuid())
  119. //.Skip(number).Take(1)
  120. .FirstOrDefault();
  121.  
  122. //if (lItem == null)
  123. // return;
  124. }
  125.  
  126. if (lItem != null)
  127. {
  128. if (reconnect)
  129. {
  130. const int timeout = 15000;//ms
  131. await Task.Delay(timeout);
  132. }
  133.  
  134. Bot newBot = new Bot(oldBot.From, oldBot.To, (int)numDelayMin.Value * 1000,
  135. (int)numDelayMax.Value * 1000, oldBot.Min, oldBot.Max, oldBot.Spamtext, BotVersion,
  136. rbLolsumm.Checked, (int)numWait.Value * 1000, dtpOnline.Value)
  137. {
  138. AcceptFriends = true,
  139. ReconnectionCount = reconnect && !oldBot.LoggedIn ? oldBot.ReconnectionCount + 1 : 1
  140. };
  141.  
  142. if (reconnect)
  143. {
  144. newBot.WebScraper.Logger.FriendrequestsSend = oldBot.FriendrequestsSend;
  145. newBot.WebScraper.Logger.CountFriends = oldBot.CountFriends;
  146. }
  147. Action lAct = new Action(() =>
  148. {
  149. lock (this)
  150. System.Threading.Thread.Sleep(5000);
  151. this.Invoke(new MethodInvoker(() =>
  152. {
  153. newBot.Start(lItem.SummonerName, lItem.Password, lItem.Region);
  154. Bot_Created(newBot);
  155. lItem.Active = true;
  156. }));
  157. });
  158. lAct.BeginInvoke(lAct.EndInvoke, null);
  159.  
  160. }
  161. else
  162. {
  163. FileLogger.AddMessage($@"Can't find appropriate bot.");
  164. }
  165.  
  166. lcontext.SaveChanges();
  167. }
  168. }));
  169. }
  170.  
  171. private readonly Dictionary<string, Bot> _newDict = new Dictionary<string, Bot>();
  172. private readonly List<Bot> _allBots;
  173. //private Random _rnd;
  174.  
  175. private bool _shouldStop;
  176.  
  177. private void Form1_Close(object sender, FormClosedEventArgs e)
  178. {
  179. _shouldStop = true;
  180.  
  181. FileLogger.AddMessage($"Form1_Close: {_allBots.Count}");
  182. for (int x = _allBots.Count - 1; x >= 0; x--)
  183. {
  184. _allBots[x].Dispose();
  185. }
  186. }
  187.  
  188. private const string BotVersion = "6.3.16_02_05_12_04";
  189.  
  190. private async void btnAdd_Click(object sender, EventArgs e)
  191. {
  192. if (nbSite.Value > nbSiteEnd.Value && nbSiteEnd.Value > 0)
  193. {
  194. MessageBox.Show(@"Min Level may not be higher than Max Level!");
  195. return;
  196. }
  197. if (rbDatabase.Checked)
  198. {
  199. using (lol_usersEntities context = new lol_usersEntities())
  200. {
  201. string lRegion = cbRegion.Text;
  202. int lAmount = (int)numAmount.Value;
  203. int lvlMin = (int)nbSite.Value;
  204. int lvlMax = (int)nbSiteEnd.Value;
  205.  
  206. //var random = new Random();
  207. //var number = random.Next(20);
  208. var items = from item in context.euwbots
  209. where item.Lvl.Value >= lvlMin && item.Lvl.Value <= lvlMax && !item.Active.Value && item.Region == lRegion && !item.Fullfriendlist.Value
  210. select item;
  211.  
  212. int lFrom = 0;
  213. int lTo = 0;
  214. if (cbFrom.SelectedIndex != 0)
  215. lFrom = (int)numFrom.Value;
  216. if (cbTo.SelectedIndex != 0)
  217. lTo = (int)numTo.Value;
  218. var lLeagueFrom = new Bot.LeagueRank((Bot.LeagueRank.Rank)(cbFrom.SelectedIndex * 5), lFrom);
  219. var lLeagueTo = new Bot.LeagueRank((Bot.LeagueRank.Rank)(cbTo.SelectedIndex * 5), lTo);
  220. var allItems = items.Take(lAmount).ToArray();
  221.  
  222. foreach (var asd in allItems)
  223. {
  224. string lName = asd.AccountName;
  225. string lPassword = asd.Password;
  226. Bot newBot = new Bot(lLeagueFrom, lLeagueTo, (int)numDelayMin.Value * 1000,
  227. (int)numDelayMax.Value * 1000, lvlMin, lvlMax, rtbMessage.Text, BotVersion, rbLolsumm.Checked,
  228. (int)numWait.Value * 1000 * 60, dtpOnline.Value)
  229. { AcceptFriends = true };
  230. newBot.Start(lName, lPassword, lRegion);
  231. Bot_Created(newBot);
  232. asd.Active = true;
  233. context.SaveChanges();
  234. await Task.Delay(5000);
  235. }
  236. }
  237. }
  238.  
  239. //else
  240. //{
  241. // Bot newBot = new Bot((int)this.nbSite.Value, (int)this.nbSiteEnd.Value, this.rtbMessage.Text, BOT_VERSION, rbLolsumm.Checked);
  242. // newBot.AcceptFriends = true;
  243. // newBot.Start(this.tbUsername.Text, this.tbPassword.Text, this.cbRegion.Text);
  244. // Bot_Created(newBot);
  245. //}
  246. }
  247.  
  248. private void Bot_Created(Bot newBot)
  249. {
  250. int pZaehler = _allBots.Count + 1;
  251. string pDeclare = "Bot " + pZaehler;
  252. while (_newDict.ContainsKey(pDeclare))
  253. {
  254. pZaehler--;
  255. pDeclare = "Bot " + pZaehler;
  256. }
  257. var newItem = new ListViewItem(pDeclare)
  258. {
  259. Name = pDeclare,
  260. UseItemStyleForSubItems = false
  261. };
  262. newItem.SubItems.Add(new ListViewItem.ListViewSubItem(newItem, newBot.Region.ToString()));
  263. newItem.SubItems.Add(new ListViewItem.ListViewSubItem(newItem, "offline", Color.Red, Color.Transparent, Font));
  264. _newDict.Add(pDeclare, newBot);
  265. lvBots.Items.Add(newItem);
  266. newBot.WebScraper.Logger.PropertyChanged += FriendCountChanged;
  267. newBot.Botdisposed += bot_disposed;
  268. newBot.LoginSucceed += Login_Changed;
  269. _allBots.Add(newBot);
  270. Actualise();
  271. }
  272.  
  273. private void Login_Changed(object sender, EventArgs e)
  274. {
  275. try
  276. {
  277. lvBots.Invoke(new MethodInvoker(() =>
  278. {
  279. Bot lBot = (Bot)sender;
  280. if (_newDict.All(item => item.Value != lBot))
  281. return;
  282. ListViewItem lItem = lvBots.Items[lvBots.Items.IndexOfKey(_newDict.First(item => item.Value == lBot).Key)];
  283. lItem.SubItems[2].Text = @"online";
  284. lItem.SubItems[2].ForeColor = Color.Green;
  285. }));
  286. }
  287. catch
  288. {
  289. // ignored
  290. }
  291. }
  292.  
  293. private void FriendCountChanged(object sender, PropertyChangedEventArgs e)
  294. {
  295. if (e.PropertyName == "FriendrequestsSend")
  296. {
  297. //await Task.Delay(5);
  298. lblSend.Invoke(new MethodInvoker(() => lblSend.Text = @"total friendrequests sent: " + _allBots.Sum(item => item.WebScraper.Logger.FriendrequestsSend)));
  299. }
  300. else if (e.PropertyName == "LoggedIn")
  301. {
  302. lblOnline.Invoke(new MethodInvoker(Actualise));
  303. }
  304. else
  305. lblAccepted.Text = @"total friends accepted: " + _allBots.Sum(item => item.WebScraper.Logger.CountFriends);
  306. }
  307. private void Actualise()
  308. {
  309. int lCount = _allBots.Where(item => item.WebScraper != null).Count(item => item.WebScraper.Logger.LoggedIn);
  310. lblOnline.Text = @"total bots online: " + lCount + @"/" + _allBots.Count;
  311. }
  312. private void btnMessageLoad_Click(object sender, EventArgs e)
  313. {
  314. string pFileName;
  315. using (OpenFileDialog newDia = new OpenFileDialog())
  316. {
  317. newDia.Filter = @"(*.txt)|*.txt";
  318. if (newDia.ShowDialog() != DialogResult.OK)
  319. return;
  320. pFileName = newDia.FileName;
  321. }
  322. rtbMessage.Text = System.IO.File.ReadAllText(pFileName);
  323. }
  324.  
  325. private void btnRemove_Click(object sender, EventArgs e)
  326. {
  327. var allItems = lvBots.SelectedItems;
  328. FileLogger.AddMessage($"btnRemove_Click: {allItems.Count}");
  329. foreach (ListViewItem item in allItems)
  330. {
  331. _newDict[item.Text].Dispose();
  332. lvBots.Items.Remove(item);
  333. }
  334. }
  335.  
  336. private bool _running;
  337.  
  338. private void button1_Click(object sender, EventArgs e)
  339. {
  340. if (_running)
  341. return;
  342. string lFileName;
  343. using (OpenFileDialog newDialog = new OpenFileDialog())
  344. {
  345. if (newDialog.ShowDialog() != DialogResult.OK)
  346. return;
  347. lFileName = newDialog.FileName;
  348. }
  349. _running = true;
  350. button1.Enabled = false;
  351. string allBots = System.IO.File.ReadAllText(lFileName, Encoding.Default).Trim();
  352. //IEnumerable<Tuple<string, string, string, Bot>> allBot = Bot.CreateFromString(allBots, BotVersion, checkBox1.Checked);
  353. var allBot = Bot.CreateFromString(allBots, BotVersion, checkBox1.Checked).ToArray();
  354. Check(allBot, 0, allBot.Length);
  355. }
  356.  
  357. private void Check(Tuple<string, string, string, Bot>[] allItems, int pNext, int pEnd)
  358. {
  359. if (pNext == pEnd)
  360. {
  361. _running = false;
  362. button1.Enabled = true;
  363. return;
  364. }
  365. Tuple<string, string, string, Bot> actual = allItems[pNext];
  366. actual.Item4.Start(actual.Item1, actual.Item2, actual.Item3);
  367. Bot_Created(actual.Item4);
  368. Action lActor = () =>
  369. {
  370. System.Threading.Thread.Sleep(35000);
  371. if (IsDisposed)
  372. return;
  373. Invoke(new MethodInvoker(() => Check(allItems, ++pNext, pEnd)));
  374. };
  375. lActor.BeginInvoke(lActor.EndInvoke, null);
  376. }
  377.  
  378. //private void AddOption_ContextMenu()
  379. //{
  380. // RegistryKey _key = Registry.ClassesRoot.OpenSubKey("Folder\\Shell", true);
  381. // RegistryKey newkey = _key.CreateSubKey("LoLAutoadder");
  382. // RegistryKey subNewkey = newkey.CreateSubKey("Command");
  383. // subNewkey.SetValue("", "C:\\LoL_AutoAdder.exe");
  384. // subNewkey.Close();
  385. // newkey.Close();
  386. // _key.Close();
  387. //}
  388. //private void RemoveOption_ContextMenu()
  389. //{
  390. // RegistryKey _key = Registry.ClassesRoot.OpenSubKey("Folder\\Shell\\", true);
  391. // _key.DeleteSubKeyTree("Your Application");
  392. // _key.Close();
  393. //}
  394.  
  395. private void button2_Click(object sender, EventArgs e)
  396. {
  397. string lFileName;
  398. using (OpenFileDialog newDia = new OpenFileDialog())
  399. {
  400. newDia.Filter = @"(*.txt)|*.txt";
  401. if (newDia.ShowDialog() != DialogResult.OK)
  402. return;
  403. lFileName = newDia.FileName;
  404. }
  405. string allBotts = System.IO.File.ReadAllText(lFileName, Encoding.Default).Trim();
  406. Tuple<string, string, string, Bot>[] allBot = Bot.CreateFromString(allBotts, BotVersion, checkBox1.Checked).ToArray();
  407. List<Bot> lBanned = new List<Bot>();
  408. for (int lIndex = _allBots.Count - 1; lIndex >= 0; lIndex--)
  409. {
  410. if (!_allBots[lIndex].LoggedIn)
  411. lBanned.Add(_allBots[lIndex]);
  412. }
  413.  
  414. FileLogger.AddMessage($"button2_Click: {_allBots.Count}");
  415. for (int i = 0; i < allBot.Length; i++)
  416. {
  417. if (i >= lBanned.Count)
  418. continue;
  419. allBot[i].Item4.WebScraper = lBanned[i].WebScraper;
  420. lBanned[i].Dispose();
  421. Bot_Created(allBot[i].Item4);
  422. }
  423. }
  424.  
  425. private void btnClear_Click(object sender, EventArgs e)
  426. {
  427.  
  428.  
  429. MessageBox.Show(@"THIS TAKES A MOMENT");
  430. using (lol_usersEntities context = new lol_usersEntities())
  431. {
  432. foreach (var item in context.euw.Where(item => item.Scraped))
  433. {
  434. item.Scraped = false;
  435. }
  436. context.SaveChanges();
  437. }
  438. }
  439.  
  440. private void btnActive_Click(object sender, EventArgs e)
  441. {
  442. MessageBox.Show(@"THIS TAKES A MOMENT");
  443. using (lol_usersEntities context = new lol_usersEntities())
  444. {
  445. foreach (var item in context.euwbots.Where(item => item.Active.Value))
  446. {
  447. item.Active = false;
  448. }
  449. context.SaveChanges();
  450. }
  451. }
  452.  
  453. private void cbFrom_SelectedIndexChanged(object sender, EventArgs e)
  454. {
  455. if (cbFrom.SelectedIndex == 0)
  456. numFrom.Enabled = false;
  457. else if (!numFrom.Enabled)
  458. numFrom.Enabled = true;
  459. }
  460.  
  461. private void cbTo_SelectedIndexChanged(object sender, EventArgs e)
  462. {
  463. if (cbTo.SelectedIndex == 0)
  464. numTo.Enabled = false;
  465. else if (!numTo.Enabled)
  466. numTo.Enabled = true;
  467. }
  468.  
  469. private void banTimer_Tick(object sender, EventArgs e)
  470. {
  471. BanWithoutFriends();
  472. }
  473.  
  474. private void BanWithoutFriends()
  475. {
  476. const int maxFriendRequestCount = 100;
  477.  
  478. var query = _allBots
  479. .Where(
  480. p =>
  481. p.WebScraper.Logger.CountFriends == 0 &&
  482. p.WebScraper.Logger.FriendrequestsSend >= maxFriendRequestCount)
  483. .ToArray();
  484.  
  485. using (lol_usersEntities context = new lol_usersEntities())
  486. {
  487. foreach (var bot in query)
  488. {
  489. FileLogger.AddMessage($@"BanWithoutFriends.
  490. Bot: Username={bot.UserName}");
  491.  
  492. var dbBot = context.euwbots.FirstOrDefault(p => p.SummonerName == bot.UserName);
  493. if (dbBot != null) dbBot.Banned = true;
  494. bot.Dispose();
  495. }
  496.  
  497. context.SaveChanges();
  498. }
  499. }
  500. }
  501. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement