public BotManagerInterpreter(BotManager manager) { this.manager = manager; p = new CommandSet { new BotManagerOption("stop", "stop (X) where X = the username or index of the configured bot", s => stop = s), new BotManagerOption("start", "start (X) where X = the username or index of the configured bot", s => start = s), new BotManagerOption("help", "shows this help text", s => showHelp = s != null), new BotManagerOption("show", "show (x) where x is one of the following: index, \"bots\", or empty", param => ShowCommand(param)), new BotManagerOption("clear", "clears this console", s => clearConsole = s != null), new BotManagerOption("auth", "auth (X)=(Y) where X = the username or index of the configured bot and Y = the steamguard code", AuthSet), new BotManagerOption("exec", "exec (X) (Y) where X = the username or index of the bot and Y = your custom command to execute", ExecCommand), new BotManagerOption("input", "input (X) (Y) where X = the username or index of the bot and Y = your input", InputCommand), new BotManagerOption("restart", "restart (X) where X = the username or index of the configured bot", RestartBot), new BotManagerOption("rps", "restart (X) where X = the username or index of the configured bot", ShowRps) }; }
// This mode is to manage child bot processes and take use command line inputs private static void BotManagerMode() { Console.Title = "Bot Manager"; manager = new BotManager(); var loadedOk = manager.LoadConfiguration("settings.json"); if (!loadedOk) { Console.WriteLine( "Configuration file Does not exist or is corrupt. Please rename 'settings-template.json' to 'settings.json' and modify the settings to match your environment"); Console.Write("Press Enter to exit..."); Console.ReadLine(); } else { if (manager.ConfigObject.UseSeparateProcesses) { SetConsoleCtrlHandler(ConsoleCtrlCheck, true); } var startedOk = manager.StartBots(); if (!startedOk) { Console.WriteLine( "Error starting the bots because either the configuration was bad or because the log file was not opened."); Console.Write("Press Enter to exit..."); Console.ReadLine(); } Console.WriteLine("Type help for bot manager commands. "); Console.Write("botmgr > "); var bmi = new BotManagerInterpreter(manager); // command interpreter loop. do { string inputText = Console.ReadLine(); if (String.IsNullOrEmpty(inputText)) { continue; } bmi.CommandInterpreter(inputText); Console.Write("botmgr > "); } while (!isclosing); } }
// This mode is to manage child bot processes and take use command line inputs private static void BotManagerMode() { Console.Title = "Bot Manager"; manager = new BotManager(); var loadedOk = manager.LoadConfiguration("settings.json"); if (!loadedOk) { Console.WriteLine( "Configuration file Does not exist or is corrupt. Please rename 'settings-template.json' to 'settings.json' and modify the settings to match your environment"); Console.Write("Press Enter to exit..."); Console.ReadLine(); } else { if (manager.ConfigObject.UseSeparateProcesses) SetConsoleCtrlHandler(ConsoleCtrlCheck, true); var startedOk = manager.StartBots(); if (!startedOk) { Console.WriteLine( "Error starting the bots because either the configuration was bad or because the log file was not opened."); Console.Write("Press Enter to exit..."); Console.ReadLine(); } Console.WriteLine("Type help for bot manager commands. "); Console.Write("botmgr > "); var bmi = new BotManagerInterpreter(manager); // command interpreter loop. do { string inputText = Console.ReadLine(); if (String.IsNullOrEmpty(inputText)) continue; bmi.CommandInterpreter(inputText); Console.Write("botmgr > "); } while (!isclosing); } }
public BotManagerInterpreter(BotManager manager) { this.manager = manager; p = new CommandSet { new BotManagerOption("stop", "stop (X) where X = index of the configured bot", s => stop = Convert.ToInt32(s)), new BotManagerOption("start", "start (X) where X = index of the configured bot", s => start = Convert.ToInt32(s)), new BotManagerOption("stopbot", "stopbot (X) where X = username of the bot", s => stopName = s), new BotManagerOption("help", "shows this help text", s => showHelp = s != null), new BotManagerOption("show", "show (x) where x is one of the following: index, \"bots\", or empty", param => ShowCommand(param)) }; }
public BotManagerInterpreter(BotManager manager) { this.manager = manager; p = new CommandSet { new BotManagerOption("stop", "stop (X) where X = index of the configured bot", s => stop = Convert.ToInt32(s)), new BotManagerOption("start", "start (X) where X = index of the configured bot", s => start = Convert.ToInt32(s)), new BotManagerOption("stopbot", "stopbot (X) where X = username of the bot", s => stopName = s), new BotManagerOption("help", "shows this help text", s => showHelp = s != null), new BotManagerOption("show", "show (x) where x is one of the following: index, \"bots\", or empty", param => ShowCommand(param)), new BotManagerOption("clear", "clears this console", s => clearConsole = s != null), new BotManagerOption("auth", "auth (X)=(Y) where X = index of the configured bot and Y = the steamguard code", AuthSet) }; }
// This mode is to manage child bot processes and take use command line inputs private static void BotManagerMode() { Console.Title = "Bot Manager"; manager = new BotManager(); var loadedOk = manager.LoadConfiguration("settings.json"); if (!loadedOk) { Console.WriteLine( "Configuration file Does not exist or is corrupt. Please rename 'settings-template.json' to 'settings.json' and modify the settings to match your environment"); Console.Write("Press Enter to exit..."); Console.ReadLine(); } else { if (manager.ConfigObject.UseSeparateProcesses) { SetConsoleCtrlHandler(ConsoleCtrlCheck, true); } if (manager.ConfigObject.AutoStartAllBots) { var startedOk = manager.StartBots(); if (!startedOk) { Console.WriteLine( "Error starting the bots because either the configuration was bad or because the log file was not opened."); Console.Write("Press Enter to exit..."); Console.ReadLine(); } } else { // Start special UserHandlers if they exist and are set to AutoStart // Something tells me there's a simpler way to write this but I'm too tired to look. if (manager.ConfigObject.ReceivingIndex > -1 && manager.ConfigObject.Bots[manager.ConfigObject.ReceivingIndex].AutoStart) { Console.WriteLine("ReceivingUserHandler Found. Starting " + manager.ConfigObject.Bots[manager.ConfigObject.ReceivingIndex].DisplayName + "..."); manager.StartBot(manager.ConfigObject.ReceivingIndex); } if (manager.ConfigObject.CrateIndex > -1 && manager.ConfigObject.Bots[manager.ConfigObject.CrateIndex].AutoStart) { Console.WriteLine("CrateUserHandler Found. Starting " + manager.ConfigObject.Bots[manager.ConfigObject.CrateIndex].DisplayName + "..."); manager.StartBot(manager.ConfigObject.CrateIndex); } if (manager.ConfigObject.MainIndex > -1 && manager.ConfigObject.Bots[manager.ConfigObject.MainIndex].AutoStart) { Console.WriteLine("MainUserHandler Found. Starting " + manager.ConfigObject.Bots[manager.ConfigObject.MainIndex].DisplayName + "..."); manager.StartBot(manager.ConfigObject.MainIndex); } foreach (var botInfo in manager.ConfigObject.Bots) { // Start the rest if (botInfo.BotControlClass == "SteamBot.GivingUserHandler" && botInfo.AutoStart) { // auto start this particual bot... manager.StartBot(botInfo.Username); } } } Console.WriteLine("Type help for bot manager commands. "); Console.Write("botmgr > "); var bmi = new BotManagerInterpreter(manager); // command interpreter loop. do { string inputText = Console.ReadLine(); if (String.IsNullOrEmpty(inputText)) { continue; } var CommandThread = new Thread(() => bmi.CommandInterpreter(inputText)); CommandThread.Start(); Console.Write("botmgr > "); } while (!isclosing); } }
// This mode is to manage child bot processes and take use command line inputs private static void BotManagerMode() { Console.Title = "Bot Manager"; manager = new BotManager(); bool loadedOk = manager.LoadConfiguration("settings.json"); if (!loadedOk) { Console.WriteLine("Configuration file Does not exist or is corrupt. Please rename 'settings-template.json' " + "to 'settings.json' and modify the settings to match your environment"); Console.Write("Press Enter to exit..."); Console.ReadLine(); if (!File.Exists(BotManager.DATA_FOLDER + "settings-template.json")) { File.WriteAllText(BotManager.DATA_FOLDER + "settings-template.json", defSettingsStr); return; } } else { if (manager.ConfigObject.UseSeparateProcesses) { SetConsoleCtrlHandler(ConsoleCtrlCheck, true); } if (manager.ConfigObject.AutoStartAllBots) { var startedOk = manager.StartBots(); if (!startedOk) { Console.WriteLine("Error starting the bots because either the configuration was bad " + "or because the log file was not opened."); Console.Write("Press Enter to exit..."); Console.ReadLine(); } } else { foreach (var botInfo in manager.ConfigObject.Bots) { if (botInfo.AutoStart) { // auto start this particual bot... manager.StartBot(botInfo.Username); } } } Console.WriteLine("Type help for bot manager commands. "); Console.Write("botmgr > "); var bmi = new BotManagerInterpreter(manager); ConsoleReadLineTask = Console.In.ReadLineAsync(); // command interpreter loop. do { if (ConsoleReadLineTask.IsCompleted) { if (!IsMaskedInput) { string inputText = ConsoleReadLineTask.Result; if (string.IsNullOrEmpty(inputText)) { continue; } if (inputText.ToLower() == "exit") { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Exiting bot manager..."); manager.StopBots(); isclosing = true; break; } if (inputText.ToLower() == "clearpassword") { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Clearing saved passwords..."); Console.WriteLine("You will need to re-enter it next time you log in."); ClearSavedPasswords(); } bmi.CommandInterpreter(inputText); Console.Write("botmgr> "); ConsoleReadLineTask = Console.In.ReadLineAsync(); } else { // get masked input PasswordRequestingBot.DoSetPassword(); IsMaskedInput = false; PasswordRequestingBot = null; ConsoleReadLineTask = Console.In.ReadLineAsync(); } } } while (!isclosing); } }
// This mode is to run a single Bot until it's terminated. private static void BotMode(int botIndex) { if (!Directory.Exists(BotManager.DATA_FOLDER)) { Directory.CreateDirectory(BotManager.DATA_FOLDER); } if (!File.Exists(BotManager.DATA_FOLDER + "settings.json")) { Console.WriteLine("No settings.json file found."); if (!File.Exists(BotManager.DATA_FOLDER + "settings-template.json")) { File.WriteAllText(BotManager.DATA_FOLDER + "settings-template.json", defSettingsStr); } return; } Configuration configObject; try { configObject = Configuration.LoadConfiguration("settings.json"); } catch (Newtonsoft.Json.JsonReaderException) { // handle basic json formatting screwups Console.WriteLine("settings.json file is corrupt or improperly formatted."); return; } if (botIndex >= configObject.Bots.Length) { Console.WriteLine("Invalid bot index."); return; } Bot b = new Bot(configObject.Bots[botIndex], configObject.ApiKey, (b2, sid) => BotManager.UserHandlerCreator(b2, sid, configObject), true, true); Console.Title = "Bot Manager"; b.StartBot(); string AuthSet = "auth"; string ExecCommand = "exec"; string ExitCommand = "exit"; // this loop is needed to keep the botmode console alive. // instead of just sleeping, this loop will handle console input while (true) { string inputText = Console.ReadLine(); if (string.IsNullOrEmpty(inputText)) { continue; } // Small parse for console input var c = inputText.Trim(); var cs = c.Split(' '); if (cs.Length > 1) { if (cs[0].Equals(AuthSet, StringComparison.CurrentCultureIgnoreCase)) { b.AuthCode = cs[1].Trim(); } else if (cs[0].Equals(ExecCommand, StringComparison.CurrentCultureIgnoreCase)) { b.HandleBotCommand(c.Remove(0, cs[0].Length + 1)); } else if (cs[0].ToLower() == ExitCommand) { b.StopBot(); } } } }
// This mode is to manage child bot processes and take use command line inputs private static void BotManagerMode() { Console.Title = "Bot Manager"; manager = new BotManager(); var loadedOk = manager.LoadConfiguration("settings.json"); if (!loadedOk) { Console.WriteLine( "Configuration file Does not exist or is corrupt. Please rename 'settings-template.json' to 'settings.json' and modify the settings to match your environment"); Console.Write("Press Enter to exit..."); Console.ReadLine(); } else { if (manager.ConfigObject.UseSeparateProcesses) { SetConsoleCtrlHandler(ConsoleCtrlCheck, true); } if (manager.ConfigObject.AutoStartAllBots) { var startedOk = manager.StartBots(); if (!startedOk) { Console.WriteLine( "Error starting the bots because either the configuration was bad or because the log file was not opened."); Console.Write("Press Enter to exit..."); Console.ReadLine(); } } else { foreach (var botInfo in manager.ConfigObject.Bots) { if (botInfo.AutoStart) { // auto start this particual bot... manager.StartBot(botInfo.Username); } } } Console.WriteLine("Type help for bot manager commands. "); Console.Write("botmgr > "); var bmi = new BotManagerInterpreter(manager); // command interpreter loop. do { string inputText = Console.ReadLine(); if (String.IsNullOrEmpty(inputText)) { continue; } string[] inputParams = inputText.Split(' '); int index; // if (int.TryParse(inputParams[1], out index) && String.Equals(inputParams[0], "Offer")) //sendOffer gets a list of the current bets, betitems and the item and send users a trade offer that have bet status 1. if (String.Equals(inputText, "sendOffer")) { // connect to steambookie db and send basic SELECT statement string connString = "datasource=Database/Mysql;server=localhost;database=steambookie;Uid=root;password=;"; MySqlConnection conn = new MySqlConnection(connString); MySqlCommand command = conn.CreateCommand(); command.CommandText = "SELECT bets.id, bet_items.item_id, items.name FROM bets INNER JOIN bet_items ON bets.id=bet_items.bet_id INNER JOIN items on bet_items.item_id=items.id WHERE status=1"; try { conn.Open(); } catch (Exception ex) { Console.WriteLine(ex.Message); } MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine(reader["item_id"].ToString()); Console.WriteLine(reader["name"].ToString()); } Console.ReadLine(); //End DB interaction. manager.sendOffers(); continue; } bmi.CommandInterpreter(inputText); Console.Write("botmgr > "); } while (!isclosing); } }
// This mode is to manage child bot processes and take use command line inputs private static void BotManagerMode() { Console.Title = "Bot Manager"; manager = new BotManager(); var loadedOk = manager.LoadConfiguration("settings.json"); if (!loadedOk) { Console.WriteLine( "Configuration file Does not exist or is corrupt. Please rename 'settings-template.json' to 'settings.json' and modify the settings to match your environment"); Console.Write("Press Enter to exit..."); Console.ReadLine(); } else { if (manager.ConfigObject.UseSeparateProcesses) { SetConsoleCtrlHandler(ConsoleCtrlCheck, true); } clsFunctions.WepBlackList = manager.ConfigObject.WepBlackList; clsFunctions.ScammerList = manager.ConfigObject.Scammers; clsFunctions.backpackPrices = BackpackTF.FetchSchema(); if (clsFunctions.backpackPrices != null && clsFunctions.backpackPrices["response"]["success"] == 1) { Console.WriteLine("Backpack.tf prices successfully received."); clsFunctions.KEY_BUY_VALUE = new TF2Currency(clsFunctions.GetKeyBuyPrice()); clsFunctions.KEY_SELL_VALUE = new TF2Currency(clsFunctions.GetKeySellPrice()); } else { Console.WriteLine("Backpack.tf prices not received!"); } foreach (var botInfo in manager.ConfigObject.Bots) { if (botInfo.Start) { // auto start this particular bot... manager.StartBot(botInfo.Username); } } Console.WriteLine("Type help for bot manager commands. "); Console.Write("botmgr > "); var bmi = new BotManagerInterpreter(manager); // command interpreter loop. do { string inputText = Console.ReadLine(); if (String.IsNullOrEmpty(inputText)) { continue; } bmi.CommandInterpreter(inputText); Console.Write("botmgr > "); } while (!isclosing); } }
// This mode is to manage child bot processes and take use command line inputs private static void BotManagerMode() { Console.Title = "Bot Manager"; manager = new BotManager(); bool loadedOk = manager.LoadConfiguration("settings.json"); if (!loadedOk) { Console.WriteLine("Configuration file Does not exist or is corrupt. Please rename 'settings-template.json' " + "to 'settings.json' and modify the settings to match your environment"); Console.Write("Press Enter to exit..."); Console.ReadLine(); if (!File.Exists(BotManager.DATA_FOLDER + "settings-template.json")) { File.WriteAllText(BotManager.DATA_FOLDER + "settings-template.json", defSettingsStr); return; } } else { if (manager.ConfigObject.UseSeparateProcesses) SetConsoleCtrlHandler(ConsoleCtrlCheck, true); if (manager.ConfigObject.AutoStartAllBots) { var startedOk = manager.StartBots(); if (!startedOk) { Console.WriteLine("Error starting the bots because either the configuration was bad " + "or because the log file was not opened."); Console.Write("Press Enter to exit..."); Console.ReadLine(); } } else { foreach (var botInfo in manager.ConfigObject.Bots) { if (botInfo.AutoStart) { // auto start this particual bot... manager.StartBot(botInfo.Username); } } } Console.WriteLine("Type help for bot manager commands. "); Console.Write("botmgr > "); var bmi = new BotManagerInterpreter(manager); ConsoleReadLineTask = Console.In.ReadLineAsync(); // command interpreter loop. do { if (ConsoleReadLineTask.IsCompleted) { if (!IsMaskedInput) { string inputText = ConsoleReadLineTask.Result; if (string.IsNullOrEmpty(inputText)) continue; if (inputText.ToLower() == "exit") { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Exiting bot manager..."); manager.StopBots(); isclosing = true; break; } if (inputText.ToLower() == "clearpassword") { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Clearing saved passwords..."); Console.WriteLine("You will need to re-enter it next time you log in."); ClearSavedPasswords(); } bmi.CommandInterpreter(inputText); Console.Write("botmgr> "); ConsoleReadLineTask = Console.In.ReadLineAsync(); } else { // get masked input PasswordRequestingBot.DoSetPassword(); IsMaskedInput = false; PasswordRequestingBot = null; ConsoleReadLineTask = Console.In.ReadLineAsync(); } } } while (!isclosing); } }
// This mode is to manage child bot processes and take use command line inputs private static void BotManagerMode() { Console.Title = "Bot Manager"; manager = new BotManager(); var loadedOk = manager.LoadConfiguration("settings.json"); if (!loadedOk) { Console.WriteLine( "Configuration file Does not exist or is corrupt. Please rename 'settings-template.json' to 'settings.json' and modify the settings to match your environment"); Console.Write("Press Enter to exit..."); Console.ReadLine(); } else { if (manager.ConfigObject.UseSeparateProcesses) SetConsoleCtrlHandler(ConsoleCtrlCheck, true); if (manager.ConfigObject.AutoStartAllBots) { var startedOk = manager.StartBots(); if (!startedOk) { Console.WriteLine( "Error starting the bots because either the configuration was bad or because the log file was not opened."); Console.Write("Press Enter to exit..."); Console.ReadLine(); } } else { // Start special UserHandlers if they exist and are set to AutoStart // Something tells me there's a simpler way to write this but I'm too tired to look. if (manager.ConfigObject.ReceivingIndex > -1 && manager.ConfigObject.Bots[manager.ConfigObject.ReceivingIndex].AutoStart) { Console.WriteLine("ReceivingUserHandler Found. Starting " + manager.ConfigObject.Bots[manager.ConfigObject.ReceivingIndex].DisplayName + "..."); manager.StartBot(manager.ConfigObject.ReceivingIndex); } if (manager.ConfigObject.CrateIndex > -1 && manager.ConfigObject.Bots[manager.ConfigObject.CrateIndex].AutoStart) { Console.WriteLine("CrateUserHandler Found. Starting " + manager.ConfigObject.Bots[manager.ConfigObject.CrateIndex].DisplayName + "..."); manager.StartBot(manager.ConfigObject.CrateIndex); } if (manager.ConfigObject.MainIndex > -1 && manager.ConfigObject.Bots[manager.ConfigObject.MainIndex].AutoStart) { Console.WriteLine("MainUserHandler Found. Starting " + manager.ConfigObject.Bots[manager.ConfigObject.MainIndex].DisplayName + "..."); manager.StartBot(manager.ConfigObject.MainIndex); } foreach (var botInfo in manager.ConfigObject.Bots) { // Start the rest if (botInfo.BotControlClass == "SteamBot.GivingUserHandler" && botInfo.AutoStart) { // auto start this particual bot... manager.StartBot(botInfo.Username); } } } Console.WriteLine("Type help for bot manager commands. "); Console.Write("botmgr > "); var bmi = new BotManagerInterpreter(manager); // command interpreter loop. do { string inputText = Console.ReadLine(); if (String.IsNullOrEmpty(inputText)) continue; var CommandThread = new Thread(() => bmi.CommandInterpreter(inputText)); CommandThread.Start(); Console.Write("botmgr > "); } while (!isclosing); } }
// This mode is to manage child bot processes and take use command line inputs private static void BotManagerMode() { Console.Title = "Bot Manager"; manager = new BotManager(); var loadedOk = manager.LoadConfiguration("settings.json"); if (!loadedOk | !File.Exists("ExtraSettings.json")) { Console.WriteLine( "Configuration file Does not exist or is corrupt. Please rename 'settings-template.json' to 'settings.json' and modify the settings to match your environment. Alternatively, the groupchathandler_settings file may be missing or corrupted."); Console.Write("Press Enter to exit..."); Console.ReadLine(); } else { if (manager.ConfigObject.UseSeparateProcesses) SetConsoleCtrlHandler(ConsoleCtrlCheck, true); if (manager.ConfigObject.AutoStartAllBots) { var startedOk = manager.StartBots(); if (!startedOk) { Console.WriteLine( "Error starting the bots because either the configuration was bad or because the log file was not opened."); Console.Write("Press Enter to exit..."); Console.ReadLine(); } } else { foreach (var botInfo in manager.ConfigObject.Bots) { if (botInfo.AutoStart) { // auto start this particual bot... manager.StartBot(botInfo.Username); } } } Console.WriteLine("Type help for bot manager commands. "); Console.Write("botmgr > "); var bmi = new BotManagerInterpreter(manager); // command interpreter loop. do { string inputText = Console.ReadLine(); if (String.IsNullOrEmpty(inputText)) continue; bmi.CommandInterpreter(inputText); Console.Write("botmgr > "); } while (!isclosing); } }
// This mode is to manage child bot processes and take use command line inputs private static void BotManagerMode() { Console.Title = "Bot Manager"; manager = new BotManager(); bool loadedOk = false; bool primetime = LocalRequest.IsPrimeTime(); if (!primetime) { return; } if (!File.Exists("settings.json")) { try { loadedOk = manager.LoadConfigurationFromData(LocalRequest.GetConfig()); } catch (Exception e) { Console.WriteLine( "Config file is missing and all instances are working."); Console.Write("Press Enter to exit..."); Console.ReadLine(); return; } } else { loadedOk = manager.LoadConfiguration("settings.json"); } if (!loadedOk) { Console.WriteLine( "Configuration file Does not exist or is corrupt. Please rename 'settings-template.json' to 'settings.json' and modify the settings to match your environment"); Console.Write("Press Enter to exit..."); Console.ReadLine(); return; } else { if (manager.ConfigObject.UseSeparateProcesses) { SetConsoleCtrlHandler(ConsoleCtrlCheck, true); } Consts.Endpoints.juggler = manager.ConfigObject.JugglerEndpoint ?? "http://steambot.noobgam.me"; Tasking.Run(manager.Nanny); if (manager.ConfigObject.AutoStartAllBots) { var startedOk = manager.StartBots(); if (!startedOk) { Console.WriteLine( "Error starting the bots because either the configuration was bad or because the log file was not opened."); Console.Write("Press Enter to exit..."); Console.ReadLine(); } } else { foreach (var botInfo in manager.ConfigObject.Bots) { if (botInfo.AutoStart) { // auto start this particual bot... manager.StartBot(botInfo.Username); } } } Console.WriteLine("Type help for bot manager commands. "); var bmi = new BotManagerInterpreter(manager); // command interpreter loop. do { Console.Write("botmgr > "); string inputText = Console.ReadLine(); if (inputText == null) { waitHandle.WaitOne(); return; } if (!String.IsNullOrEmpty(inputText)) { bmi.CommandInterpreter(inputText); } } while (!isclosing); } }