Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.33 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. lock (this)
  148. {
  149. await Task.Delay(5000);
  150. newBot.Start(lItem.SummonerName, lItem.Password, lItem.Region);
  151. Bot_Created(newBot);
  152. lItem.Active = true;
  153. }
  154.  
  155. }
  156. else
  157. {
  158. FileLogger.AddMessage($@"Can't find appropriate bot.");
  159. }
  160.  
  161. lcontext.SaveChanges();
  162. }
  163. }));
  164. }
  165.  
  166. private readonly Dictionary<string, Bot> _newDict = new Dictionary<string, Bot>();
  167. private readonly List<Bot> _allBots;
  168. //private Random _rnd;
  169.  
  170. private bool _shouldStop;
  171.  
  172. private void Form1_Close(object sender, FormClosedEventArgs e)
  173. {
  174. _shouldStop = true;
  175.  
  176. FileLogger.AddMessage($"Form1_Close: {_allBots.Count}");
  177. for (int x = _allBots.Count - 1; x >= 0; x--)
  178. {
  179. _allBots[x].Dispose();
  180. }
  181. }
  182.  
  183. private const string BotVersion = "6.3.16_02_05_12_04";
  184.  
  185. private async void btnAdd_Click(object sender, EventArgs e)
  186. {
  187. if (nbSite.Value > nbSiteEnd.Value && nbSiteEnd.Value > 0)
  188. {
  189. MessageBox.Show(@"Min Level may not be higher than Max Level!");
  190. return;
  191. }
  192. if (rbDatabase.Checked)
  193. {
  194. using (lol_usersEntities context = new lol_usersEntities())
  195. {
  196. string lRegion = cbRegion.Text;
  197. int lAmount = (int)numAmount.Value;
  198. int lvlMin = (int)nbSite.Value;
  199. int lvlMax = (int)nbSiteEnd.Value;
  200.  
  201. //var random = new Random();
  202. //var number = random.Next(20);
  203. var items = from item in context.euwbots
  204. where item.Lvl.Value >= lvlMin && item.Lvl.Value <= lvlMax && !item.Active.Value && item.Region == lRegion && !item.Fullfriendlist.Value
  205. select item;
  206.  
  207. int lFrom = 0;
  208. int lTo = 0;
  209. if (cbFrom.SelectedIndex != 0)
  210. lFrom = (int)numFrom.Value;
  211. if (cbTo.SelectedIndex != 0)
  212. lTo = (int)numTo.Value;
  213. var lLeagueFrom = new Bot.LeagueRank((Bot.LeagueRank.Rank)(cbFrom.SelectedIndex * 5), lFrom);
  214. var lLeagueTo = new Bot.LeagueRank((Bot.LeagueRank.Rank)(cbTo.SelectedIndex * 5), lTo);
  215. var allItems = items.Take(lAmount).ToArray();
  216.  
  217. foreach (var asd in allItems)
  218. {
  219. string lName = asd.AccountName;
  220. string lPassword = asd.Password;
  221. Bot newBot = new Bot(lLeagueFrom, lLeagueTo, (int)numDelayMin.Value * 1000,
  222. (int)numDelayMax.Value * 1000, lvlMin, lvlMax, rtbMessage.Text, BotVersion, rbLolsumm.Checked,
  223. (int)numWait.Value * 1000 * 60, dtpOnline.Value)
  224. { AcceptFriends = true };
  225. newBot.Start(lName, lPassword, lRegion);
  226. Bot_Created(newBot);
  227. asd.Active = true;
  228. context.SaveChanges();
  229. await Task.Delay(5000);
  230. }
  231. }
  232. }
  233.  
  234. //else
  235. //{
  236. // Bot newBot = new Bot((int)this.nbSite.Value, (int)this.nbSiteEnd.Value, this.rtbMessage.Text, BOT_VERSION, rbLolsumm.Checked);
  237. // newBot.AcceptFriends = true;
  238. // newBot.Start(this.tbUsername.Text, this.tbPassword.Text, this.cbRegion.Text);
  239. // Bot_Created(newBot);
  240. //}
  241. }
  242.  
  243. private void Bot_Created(Bot newBot)
  244. {
  245. int pZaehler = _allBots.Count + 1;
  246. string pDeclare = "Bot " + pZaehler;
  247. while (_newDict.ContainsKey(pDeclare))
  248. {
  249. pZaehler--;
  250. pDeclare = "Bot " + pZaehler;
  251. }
  252. var newItem = new ListViewItem(pDeclare)
  253. {
  254. Name = pDeclare,
  255. UseItemStyleForSubItems = false
  256. };
  257. newItem.SubItems.Add(new ListViewItem.ListViewSubItem(newItem, newBot.Region.ToString()));
  258. newItem.SubItems.Add(new ListViewItem.ListViewSubItem(newItem, "offline", Color.Red, Color.Transparent, Font));
  259. _newDict.Add(pDeclare, newBot);
  260. lvBots.Items.Add(newItem);
  261. newBot.WebScraper.Logger.PropertyChanged += FriendCountChanged;
  262. newBot.Botdisposed += bot_disposed;
  263. newBot.LoginSucceed += Login_Changed;
  264. _allBots.Add(newBot);
  265. Actualise();
  266. }
  267.  
  268. private void Login_Changed(object sender, EventArgs e)
  269. {
  270. try
  271. {
  272. lvBots.Invoke(new MethodInvoker(() =>
  273. {
  274. Bot lBot = (Bot)sender;
  275. if (_newDict.All(item => item.Value != lBot))
  276. return;
  277. ListViewItem lItem = lvBots.Items[lvBots.Items.IndexOfKey(_newDict.First(item => item.Value == lBot).Key)];
  278. lItem.SubItems[2].Text = @"online";
  279. lItem.SubItems[2].ForeColor = Color.Green;
  280. }));
  281. }
  282. catch
  283. {
  284. // ignored
  285. }
  286. }
  287.  
  288. private void FriendCountChanged(object sender, PropertyChangedEventArgs e)
  289. {
  290. if (e.PropertyName == "FriendrequestsSend")
  291. {
  292. //await Task.Delay(5);
  293. lblSend.Invoke(new MethodInvoker(() => lblSend.Text = @"total friendrequests sent: " + _allBots.Sum(item => item.WebScraper.Logger.FriendrequestsSend)));
  294. }
  295. else if (e.PropertyName == "LoggedIn")
  296. {
  297. lblOnline.Invoke(new MethodInvoker(Actualise));
  298. }
  299. else
  300. lblAccepted.Text = @"total friends accepted: " + _allBots.Sum(item => item.WebScraper.Logger.CountFriends);
  301. }
  302. private void Actualise()
  303. {
  304. int lCount = _allBots.Where(item => item.WebScraper != null).Count(item => item.WebScraper.Logger.LoggedIn);
  305. lblOnline.Text = @"total bots online: " + lCount + @"/" + _allBots.Count;
  306. }
  307. private void btnMessageLoad_Click(object sender, EventArgs e)
  308. {
  309. string pFileName;
  310. using (OpenFileDialog newDia = new OpenFileDialog())
  311. {
  312. newDia.Filter = @"(*.txt)|*.txt";
  313. if (newDia.ShowDialog() != DialogResult.OK)
  314. return;
  315. pFileName = newDia.FileName;
  316. }
  317. rtbMessage.Text = System.IO.File.ReadAllText(pFileName);
  318. }
  319.  
  320. private void btnRemove_Click(object sender, EventArgs e)
  321. {
  322. var allItems = lvBots.SelectedItems;
  323. FileLogger.AddMessage($"btnRemove_Click: {allItems.Count}");
  324. foreach (ListViewItem item in allItems)
  325. {
  326. _newDict[item.Text].Dispose();
  327. lvBots.Items.Remove(item);
  328. }
  329. }
  330.  
  331. private bool _running;
  332.  
  333. private void button1_Click(object sender, EventArgs e)
  334. {
  335. if (_running)
  336. return;
  337. string lFileName;
  338. using (OpenFileDialog newDialog = new OpenFileDialog())
  339. {
  340. if (newDialog.ShowDialog() != DialogResult.OK)
  341. return;
  342. lFileName = newDialog.FileName;
  343. }
  344. _running = true;
  345. button1.Enabled = false;
  346. string allBots = System.IO.File.ReadAllText(lFileName, Encoding.Default).Trim();
  347. //IEnumerable<Tuple<string, string, string, Bot>> allBot = Bot.CreateFromString(allBots, BotVersion, checkBox1.Checked);
  348. var allBot = Bot.CreateFromString(allBots, BotVersion, checkBox1.Checked).ToArray();
  349. Check(allBot, 0, allBot.Length);
  350. }
  351.  
  352. private void Check(Tuple<string, string, string, Bot>[] allItems, int pNext, int pEnd)
  353. {
  354. if (pNext == pEnd)
  355. {
  356. _running = false;
  357. button1.Enabled = true;
  358. return;
  359. }
  360. Tuple<string, string, string, Bot> actual = allItems[pNext];
  361. actual.Item4.Start(actual.Item1, actual.Item2, actual.Item3);
  362. Bot_Created(actual.Item4);
  363. Action lActor = () =>
  364. {
  365. System.Threading.Thread.Sleep(35000);
  366. if (IsDisposed)
  367. return;
  368. Invoke(new MethodInvoker(() => Check(allItems, ++pNext, pEnd)));
  369. };
  370. lActor.BeginInvoke(lActor.EndInvoke, null);
  371. }
  372.  
  373. //private void AddOption_ContextMenu()
  374. //{
  375. // RegistryKey _key = Registry.ClassesRoot.OpenSubKey("Folder\\Shell", true);
  376. // RegistryKey newkey = _key.CreateSubKey("LoLAutoadder");
  377. // RegistryKey subNewkey = newkey.CreateSubKey("Command");
  378. // subNewkey.SetValue("", "C:\\LoL_AutoAdder.exe");
  379. // subNewkey.Close();
  380. // newkey.Close();
  381. // _key.Close();
  382. //}
  383. //private void RemoveOption_ContextMenu()
  384. //{
  385. // RegistryKey _key = Registry.ClassesRoot.OpenSubKey("Folder\\Shell\\", true);
  386. // _key.DeleteSubKeyTree("Your Application");
  387. // _key.Close();
  388. //}
  389.  
  390. private void button2_Click(object sender, EventArgs e)
  391. {
  392. string lFileName;
  393. using (OpenFileDialog newDia = new OpenFileDialog())
  394. {
  395. newDia.Filter = @"(*.txt)|*.txt";
  396. if (newDia.ShowDialog() != DialogResult.OK)
  397. return;
  398. lFileName = newDia.FileName;
  399. }
  400. string allBotts = System.IO.File.ReadAllText(lFileName, Encoding.Default).Trim();
  401. Tuple<string, string, string, Bot>[] allBot = Bot.CreateFromString(allBotts, BotVersion, checkBox1.Checked).ToArray();
  402. List<Bot> lBanned = new List<Bot>();
  403. for (int lIndex = _allBots.Count - 1; lIndex >= 0; lIndex--)
  404. {
  405. if (!_allBots[lIndex].LoggedIn)
  406. lBanned.Add(_allBots[lIndex]);
  407. }
  408.  
  409. FileLogger.AddMessage($"button2_Click: {_allBots.Count}");
  410. for (int i = 0; i < allBot.Length; i++)
  411. {
  412. if (i >= lBanned.Count)
  413. continue;
  414. allBot[i].Item4.WebScraper = lBanned[i].WebScraper;
  415. lBanned[i].Dispose();
  416. Bot_Created(allBot[i].Item4);
  417. }
  418. }
  419.  
  420. private void btnClear_Click(object sender, EventArgs e)
  421. {
  422.  
  423.  
  424. MessageBox.Show(@"THIS TAKES A MOMENT");
  425. using (lol_usersEntities context = new lol_usersEntities())
  426. {
  427. foreach (var item in context.euw.Where(item => item.Scraped))
  428. {
  429. item.Scraped = false;
  430. }
  431. context.SaveChanges();
  432. }
  433. }
  434.  
  435. private void btnActive_Click(object sender, EventArgs e)
  436. {
  437. MessageBox.Show(@"THIS TAKES A MOMENT");
  438. using (lol_usersEntities context = new lol_usersEntities())
  439. {
  440. foreach (var item in context.euwbots.Where(item => item.Active.Value))
  441. {
  442. item.Active = false;
  443. }
  444. context.SaveChanges();
  445. }
  446. }
  447.  
  448. private void cbFrom_SelectedIndexChanged(object sender, EventArgs e)
  449. {
  450. if (cbFrom.SelectedIndex == 0)
  451. numFrom.Enabled = false;
  452. else if (!numFrom.Enabled)
  453. numFrom.Enabled = true;
  454. }
  455.  
  456. private void cbTo_SelectedIndexChanged(object sender, EventArgs e)
  457. {
  458. if (cbTo.SelectedIndex == 0)
  459. numTo.Enabled = false;
  460. else if (!numTo.Enabled)
  461. numTo.Enabled = true;
  462. }
  463.  
  464. private void banTimer_Tick(object sender, EventArgs e)
  465. {
  466. BanWithoutFriends();
  467. }
  468.  
  469. private void BanWithoutFriends()
  470. {
  471. const int maxFriendRequestCount = 100;
  472.  
  473. var query = _allBots
  474. .Where(
  475. p =>
  476. p.WebScraper.Logger.CountFriends == 0 &&
  477. p.WebScraper.Logger.FriendrequestsSend >= maxFriendRequestCount)
  478. .ToArray();
  479.  
  480. using (lol_usersEntities context = new lol_usersEntities())
  481. {
  482. foreach (var bot in query)
  483. {
  484. FileLogger.AddMessage($@"BanWithoutFriends.
  485. Bot: Username={bot.UserName}");
  486.  
  487. var dbBot = context.euwbots.FirstOrDefault(p => p.SummonerName == bot.UserName);
  488. if (dbBot != null) dbBot.Banned = true;
  489. bot.Dispose();
  490. }
  491.  
  492. context.SaveChanges();
  493. }
  494. }
  495. }
  496. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement