Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace LoL_AutoAdder
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- _allBots = new List<Bot>();
- FormClosed += Form1_Close;
- cbRegion.SelectedIndex = 0;
- cbFrom.SelectedIndex = 0;
- cbTo.SelectedIndex = 5;
- lvBots.MouseDoubleClick += lv1_doubleClick;
- //_rnd = new Random(DateTime.Now.Millisecond);
- }
- private void lv1_doubleClick(object sender, MouseEventArgs e)
- {
- if (e.Button != MouseButtons.Left)
- return;
- foreach (ListViewItem item in lvBots.SelectedItems)
- {
- InfoPage newPage = new InfoPage { Info = _newDict[item.Text].WebScraper.Logger };
- newPage.Prepare(_newDict[item.Text]);
- newPage.Show();
- }
- }
- private string GetKey(Bot lSender)
- {
- try
- {
- return _newDict.First(item => item.Value == lSender).Key;
- }
- catch (InvalidOperationException)
- {
- return GetKey(lSender);
- }
- }
- private async void bot_disposed(object sender, EventArgs e)
- {
- if (_shouldStop || IsDisposed)
- return;
- Bot oldBot = (Bot)sender;
- _allBots.Remove(oldBot);
- string lKey = GetKey(oldBot);
- _newDict.Remove(lKey);
- lvBots.Invoke(new MethodInvoker(
- async () =>
- {
- ListViewItem[] lItems = lvBots.Items.Find(lKey, false);
- if (lItems.Length == 0)
- return;
- lItems[0].Remove();
- lblAccepted.Text = @"total friends accepted: " + _allBots.Sum(item => item.WebScraper.Logger.CountFriends);
- lblSend.Text = @"total friendrequests sent: " + _allBots.Sum(item => item.WebScraper.Logger.FriendrequestsSend);
- const int maxReconnectionCount = 3;
- bool reconnect = oldBot.ReconnectionCount < maxReconnectionCount;
- using (var lcontext = new lol_usersEntities())
- {
- euwbots lItem = null;
- var oldItem = lcontext.euwbots
- .FirstOrDefault(p => p.SummonerName == oldBot.UserName && p.Banned != true);
- if (oldItem != null)
- {
- if (!oldBot.LoggedIn && !reconnect)
- {
- oldItem.Banned = true;
- FileLogger.AddMessage($@"Banned.
- Bot: Username={ oldItem?.SummonerName}");
- }
- else if (reconnect)
- {
- lItem = oldItem;
- FileLogger.AddMessage($@"Reconnect.
- Bot: Username={ oldItem?.SummonerName}");
- }
- else
- {
- //Logged in, but don't want to reconnect.
- }
- }
- if (lItem == null)
- {
- var lowerUserName = oldBot.UserName.ToLower();
- //var random = new Random();
- //var number = random.Next(20);
- lItem = (from item in lcontext.euwbots
- where oldBot.WebScraper.LowerRegion == item.Region
- && lowerUserName != item.SummonerName
- && oldBot.Min <= item.Lvl.Value && oldBot.Max >= item.Lvl.Value
- && !item.Active.Value
- && !item.Fullfriendlist.Value
- select item).OrderBy(x => Guid.NewGuid())
- //.Skip(number).Take(1)
- .FirstOrDefault();
- //if (lItem == null)
- // return;
- }
- if (lItem != null)
- {
- if (reconnect)
- {
- const int timeout = 15000;//ms
- await Task.Delay(timeout);
- }
- Bot newBot = new Bot(oldBot.From, oldBot.To, (int)numDelayMin.Value * 1000,
- (int)numDelayMax.Value * 1000, oldBot.Min, oldBot.Max, oldBot.Spamtext, BotVersion,
- rbLolsumm.Checked, (int)numWait.Value * 1000, dtpOnline.Value)
- {
- AcceptFriends = true,
- ReconnectionCount = reconnect && !oldBot.LoggedIn ? oldBot.ReconnectionCount + 1 : 1
- };
- if (reconnect)
- {
- newBot.WebScraper.Logger.FriendrequestsSend = oldBot.FriendrequestsSend;
- newBot.WebScraper.Logger.CountFriends = oldBot.CountFriends;
- }
- lock (this)
- {
- await Task.Delay(5000);
- newBot.Start(lItem.SummonerName, lItem.Password, lItem.Region);
- Bot_Created(newBot);
- lItem.Active = true;
- }
- }
- else
- {
- FileLogger.AddMessage($@"Can't find appropriate bot.");
- }
- lcontext.SaveChanges();
- }
- }));
- }
- private readonly Dictionary<string, Bot> _newDict = new Dictionary<string, Bot>();
- private readonly List<Bot> _allBots;
- //private Random _rnd;
- private bool _shouldStop;
- private void Form1_Close(object sender, FormClosedEventArgs e)
- {
- _shouldStop = true;
- FileLogger.AddMessage($"Form1_Close: {_allBots.Count}");
- for (int x = _allBots.Count - 1; x >= 0; x--)
- {
- _allBots[x].Dispose();
- }
- }
- private const string BotVersion = "6.3.16_02_05_12_04";
- private async void btnAdd_Click(object sender, EventArgs e)
- {
- if (nbSite.Value > nbSiteEnd.Value && nbSiteEnd.Value > 0)
- {
- MessageBox.Show(@"Min Level may not be higher than Max Level!");
- return;
- }
- if (rbDatabase.Checked)
- {
- using (lol_usersEntities context = new lol_usersEntities())
- {
- string lRegion = cbRegion.Text;
- int lAmount = (int)numAmount.Value;
- int lvlMin = (int)nbSite.Value;
- int lvlMax = (int)nbSiteEnd.Value;
- //var random = new Random();
- //var number = random.Next(20);
- var items = from item in context.euwbots
- where item.Lvl.Value >= lvlMin && item.Lvl.Value <= lvlMax && !item.Active.Value && item.Region == lRegion && !item.Fullfriendlist.Value
- select item;
- int lFrom = 0;
- int lTo = 0;
- if (cbFrom.SelectedIndex != 0)
- lFrom = (int)numFrom.Value;
- if (cbTo.SelectedIndex != 0)
- lTo = (int)numTo.Value;
- var lLeagueFrom = new Bot.LeagueRank((Bot.LeagueRank.Rank)(cbFrom.SelectedIndex * 5), lFrom);
- var lLeagueTo = new Bot.LeagueRank((Bot.LeagueRank.Rank)(cbTo.SelectedIndex * 5), lTo);
- var allItems = items.Take(lAmount).ToArray();
- foreach (var asd in allItems)
- {
- string lName = asd.AccountName;
- string lPassword = asd.Password;
- Bot newBot = new Bot(lLeagueFrom, lLeagueTo, (int)numDelayMin.Value * 1000,
- (int)numDelayMax.Value * 1000, lvlMin, lvlMax, rtbMessage.Text, BotVersion, rbLolsumm.Checked,
- (int)numWait.Value * 1000 * 60, dtpOnline.Value)
- { AcceptFriends = true };
- newBot.Start(lName, lPassword, lRegion);
- Bot_Created(newBot);
- asd.Active = true;
- context.SaveChanges();
- await Task.Delay(5000);
- }
- }
- }
- //else
- //{
- // Bot newBot = new Bot((int)this.nbSite.Value, (int)this.nbSiteEnd.Value, this.rtbMessage.Text, BOT_VERSION, rbLolsumm.Checked);
- // newBot.AcceptFriends = true;
- // newBot.Start(this.tbUsername.Text, this.tbPassword.Text, this.cbRegion.Text);
- // Bot_Created(newBot);
- //}
- }
- private void Bot_Created(Bot newBot)
- {
- int pZaehler = _allBots.Count + 1;
- string pDeclare = "Bot " + pZaehler;
- while (_newDict.ContainsKey(pDeclare))
- {
- pZaehler--;
- pDeclare = "Bot " + pZaehler;
- }
- var newItem = new ListViewItem(pDeclare)
- {
- Name = pDeclare,
- UseItemStyleForSubItems = false
- };
- newItem.SubItems.Add(new ListViewItem.ListViewSubItem(newItem, newBot.Region.ToString()));
- newItem.SubItems.Add(new ListViewItem.ListViewSubItem(newItem, "offline", Color.Red, Color.Transparent, Font));
- _newDict.Add(pDeclare, newBot);
- lvBots.Items.Add(newItem);
- newBot.WebScraper.Logger.PropertyChanged += FriendCountChanged;
- newBot.Botdisposed += bot_disposed;
- newBot.LoginSucceed += Login_Changed;
- _allBots.Add(newBot);
- Actualise();
- }
- private void Login_Changed(object sender, EventArgs e)
- {
- try
- {
- lvBots.Invoke(new MethodInvoker(() =>
- {
- Bot lBot = (Bot)sender;
- if (_newDict.All(item => item.Value != lBot))
- return;
- ListViewItem lItem = lvBots.Items[lvBots.Items.IndexOfKey(_newDict.First(item => item.Value == lBot).Key)];
- lItem.SubItems[2].Text = @"online";
- lItem.SubItems[2].ForeColor = Color.Green;
- }));
- }
- catch
- {
- // ignored
- }
- }
- private void FriendCountChanged(object sender, PropertyChangedEventArgs e)
- {
- if (e.PropertyName == "FriendrequestsSend")
- {
- //await Task.Delay(5);
- lblSend.Invoke(new MethodInvoker(() => lblSend.Text = @"total friendrequests sent: " + _allBots.Sum(item => item.WebScraper.Logger.FriendrequestsSend)));
- }
- else if (e.PropertyName == "LoggedIn")
- {
- lblOnline.Invoke(new MethodInvoker(Actualise));
- }
- else
- lblAccepted.Text = @"total friends accepted: " + _allBots.Sum(item => item.WebScraper.Logger.CountFriends);
- }
- private void Actualise()
- {
- int lCount = _allBots.Where(item => item.WebScraper != null).Count(item => item.WebScraper.Logger.LoggedIn);
- lblOnline.Text = @"total bots online: " + lCount + @"/" + _allBots.Count;
- }
- private void btnMessageLoad_Click(object sender, EventArgs e)
- {
- string pFileName;
- using (OpenFileDialog newDia = new OpenFileDialog())
- {
- newDia.Filter = @"(*.txt)|*.txt";
- if (newDia.ShowDialog() != DialogResult.OK)
- return;
- pFileName = newDia.FileName;
- }
- rtbMessage.Text = System.IO.File.ReadAllText(pFileName);
- }
- private void btnRemove_Click(object sender, EventArgs e)
- {
- var allItems = lvBots.SelectedItems;
- FileLogger.AddMessage($"btnRemove_Click: {allItems.Count}");
- foreach (ListViewItem item in allItems)
- {
- _newDict[item.Text].Dispose();
- lvBots.Items.Remove(item);
- }
- }
- private bool _running;
- private void button1_Click(object sender, EventArgs e)
- {
- if (_running)
- return;
- string lFileName;
- using (OpenFileDialog newDialog = new OpenFileDialog())
- {
- if (newDialog.ShowDialog() != DialogResult.OK)
- return;
- lFileName = newDialog.FileName;
- }
- _running = true;
- button1.Enabled = false;
- string allBots = System.IO.File.ReadAllText(lFileName, Encoding.Default).Trim();
- //IEnumerable<Tuple<string, string, string, Bot>> allBot = Bot.CreateFromString(allBots, BotVersion, checkBox1.Checked);
- var allBot = Bot.CreateFromString(allBots, BotVersion, checkBox1.Checked).ToArray();
- Check(allBot, 0, allBot.Length);
- }
- private void Check(Tuple<string, string, string, Bot>[] allItems, int pNext, int pEnd)
- {
- if (pNext == pEnd)
- {
- _running = false;
- button1.Enabled = true;
- return;
- }
- Tuple<string, string, string, Bot> actual = allItems[pNext];
- actual.Item4.Start(actual.Item1, actual.Item2, actual.Item3);
- Bot_Created(actual.Item4);
- Action lActor = () =>
- {
- System.Threading.Thread.Sleep(35000);
- if (IsDisposed)
- return;
- Invoke(new MethodInvoker(() => Check(allItems, ++pNext, pEnd)));
- };
- lActor.BeginInvoke(lActor.EndInvoke, null);
- }
- //private void AddOption_ContextMenu()
- //{
- // RegistryKey _key = Registry.ClassesRoot.OpenSubKey("Folder\\Shell", true);
- // RegistryKey newkey = _key.CreateSubKey("LoLAutoadder");
- // RegistryKey subNewkey = newkey.CreateSubKey("Command");
- // subNewkey.SetValue("", "C:\\LoL_AutoAdder.exe");
- // subNewkey.Close();
- // newkey.Close();
- // _key.Close();
- //}
- //private void RemoveOption_ContextMenu()
- //{
- // RegistryKey _key = Registry.ClassesRoot.OpenSubKey("Folder\\Shell\\", true);
- // _key.DeleteSubKeyTree("Your Application");
- // _key.Close();
- //}
- private void button2_Click(object sender, EventArgs e)
- {
- string lFileName;
- using (OpenFileDialog newDia = new OpenFileDialog())
- {
- newDia.Filter = @"(*.txt)|*.txt";
- if (newDia.ShowDialog() != DialogResult.OK)
- return;
- lFileName = newDia.FileName;
- }
- string allBotts = System.IO.File.ReadAllText(lFileName, Encoding.Default).Trim();
- Tuple<string, string, string, Bot>[] allBot = Bot.CreateFromString(allBotts, BotVersion, checkBox1.Checked).ToArray();
- List<Bot> lBanned = new List<Bot>();
- for (int lIndex = _allBots.Count - 1; lIndex >= 0; lIndex--)
- {
- if (!_allBots[lIndex].LoggedIn)
- lBanned.Add(_allBots[lIndex]);
- }
- FileLogger.AddMessage($"button2_Click: {_allBots.Count}");
- for (int i = 0; i < allBot.Length; i++)
- {
- if (i >= lBanned.Count)
- continue;
- allBot[i].Item4.WebScraper = lBanned[i].WebScraper;
- lBanned[i].Dispose();
- Bot_Created(allBot[i].Item4);
- }
- }
- private void btnClear_Click(object sender, EventArgs e)
- {
- MessageBox.Show(@"THIS TAKES A MOMENT");
- using (lol_usersEntities context = new lol_usersEntities())
- {
- foreach (var item in context.euw.Where(item => item.Scraped))
- {
- item.Scraped = false;
- }
- context.SaveChanges();
- }
- }
- private void btnActive_Click(object sender, EventArgs e)
- {
- MessageBox.Show(@"THIS TAKES A MOMENT");
- using (lol_usersEntities context = new lol_usersEntities())
- {
- foreach (var item in context.euwbots.Where(item => item.Active.Value))
- {
- item.Active = false;
- }
- context.SaveChanges();
- }
- }
- private void cbFrom_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (cbFrom.SelectedIndex == 0)
- numFrom.Enabled = false;
- else if (!numFrom.Enabled)
- numFrom.Enabled = true;
- }
- private void cbTo_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (cbTo.SelectedIndex == 0)
- numTo.Enabled = false;
- else if (!numTo.Enabled)
- numTo.Enabled = true;
- }
- private void banTimer_Tick(object sender, EventArgs e)
- {
- BanWithoutFriends();
- }
- private void BanWithoutFriends()
- {
- const int maxFriendRequestCount = 100;
- var query = _allBots
- .Where(
- p =>
- p.WebScraper.Logger.CountFriends == 0 &&
- p.WebScraper.Logger.FriendrequestsSend >= maxFriendRequestCount)
- .ToArray();
- using (lol_usersEntities context = new lol_usersEntities())
- {
- foreach (var bot in query)
- {
- FileLogger.AddMessage($@"BanWithoutFriends.
- Bot: Username={bot.UserName}");
- var dbBot = context.euwbots.FirstOrDefault(p => p.SummonerName == bot.UserName);
- if (dbBot != null) dbBot.Banned = true;
- bot.Dispose();
- }
- context.SaveChanges();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement