// Todo: move the item-check after a failed trade to a separate method to clean up handler. public ReceivingUserHandler(Bot bot, SteamID sid, Configuration config) : base(bot, sid, config) { Success = false; mySteamID = Bot.SteamUser.SteamID; ReceivingSID = mySteamID; }
public Bot(Configuration.BotInfo config, string apiKey, bool debug = false) { sql = new Sql(); Username = config.Username; Password = config.Password; DisplayName = config.DisplayName; Admins = config.Admins; id = config.Id; this.apiKey = apiKey; TradeListener = new ScrapTrade(this); TradeListenerInternal = new ExchangeTrade(this); TradeListenerAdmin = new AdminTrade(this); List<object[]> result = sql.query("SELECT text, response FROM responses"); foreach (object[] row in result) { responses.Add(((string) row[0]).ToLower(), (string) row[1]); } // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); queueHandler = new QueueHandler(this); SteamClient.Connect(); while (true) { Update(); } }
/// <summary> /// Loads a configuration file to use when creating bots. /// </summary> /// <param name="configFile"><c>false</c> if there was problems loading the config file.</param> public bool LoadConfiguration(string configFile) { if (!File.Exists(configFile)) return false; try { ConfigObject = Configuration.LoadConfiguration(configFile); } catch (JsonReaderException) { // handle basic json formatting screwups ConfigObject = null; } if (ConfigObject == null) return false; useSeparateProcesses = ConfigObject.UseSeparateProcesses; mainLog = new Log(ConfigObject.MainLog, null, Log.LogLevel.Debug); for (int i = 0; i < ConfigObject.Bots.Length; i++) { Configuration.BotInfo info = ConfigObject.Bots[i]; mainLog.Info("Launching Bot " + info.DisplayName + "..."); var v = new RunningBot(useSeparateProcesses, i, ConfigObject); botProcs.Add(v); } return true; }
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false) { Username = config.Username; Password = config.Password; DisplayName = config.DisplayName; ChatResponse = config.ChatResponse; MaximumTradeTime = config.MaximumTradeTime; MaximiumActionGap = config.MaximumActionGap; DisplayNamePrefix = config.DisplayNamePrefix; TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval; Admins = config.Admins; this.apiKey = apiKey; AuthCode = null; log = new Log (config.LogFile, this); CreateHandler = handlerCreator; // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; log.Debug ("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); log.Info ("Connecting..."); SteamClient.Connect(); Thread CallbackThread = new Thread(() => // Callback Handling { while (true) { CallbackMsg msg = SteamClient.WaitForCallback (true); HandleSteamMessage (msg); } }); new Thread(() => // Trade Polling if needed { while (true) { Thread.Sleep (TradePollingInterval); if (CurrentTrade != null) { try { CurrentTrade.Poll (); } catch (Exception e) { log.Error ("Error Polling Trade: " + e); } } } }).Start (); CallbackThread.Start(); log.Success ("Done Loading Bot!"); CallbackThread.Join(); }
public GivingUserHandler(Bot bot, SteamID sid, Configuration config) : base(bot, sid, config) { Success = false; //Just makes referencing the bot's own SID easier. mySteamID = Bot.SteamUser.SteamID; }
/// <summary> /// A method to return an instance of the <c>bot.BotControlClass</c>. /// </summary> /// <param name="bot">The bot.</param> /// <param name="sid">The steamId.</param> /// <param name="config">Config info, cause why the hell not</param> /// <returns>A <see cref="UserHandler"/> instance.</returns> /// <exception cref="ArgumentException">Thrown if the control class type does not exist.</exception> public static UserHandler UserHandlerCreator(Bot bot, SteamID sid, Configuration config) { Type controlClass = Type.GetType(bot.BotControlClass); if (controlClass == null) throw new ArgumentException("Configured control class type was null. You probably named it wrong in your configuration file.", "bot"); return (UserHandler)Activator.CreateInstance( controlClass, new object[] { bot, sid, config }); }
public Bot(Configuration.BotInfo config, string apiKey, bool debug = false) { Username = config.Username; Password = config.Password; DisplayName = config.DisplayName; ChatResponse = config.ChatResponse; Admins = config.Admins; this.apiKey = apiKey; AuthCode = null; TradeListener = new TradeEnterTradeListener(this); // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); SteamClient.Connect(); Thread CallbackThread = new Thread(() => // Callback Handling { while (true) { CallbackMsg msg = SteamClient.WaitForCallback (true); HandleSteamMessage (msg); } }); new Thread(() => // Trade Polling if needed { while (true) { Thread.Sleep (800); if (CurrentTrade != null) { try { CurrentTrade.Poll (); } catch (Exception e) { Console.Write ("Error polling the trade: "); Console.WriteLine (e); } } } }).Start (); CallbackThread.Start(); CallbackThread.Join(); }
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false) { logOnDetails = new SteamUser.LogOnDetails { Username = config.Username, Password = config.Password }; DisplayName = config.DisplayName; ChatResponse = config.ChatResponse; MaximumTradeTime = config.MaximumTradeTime; MaximiumActionGap = config.MaximumActionGap; DisplayNamePrefix = config.DisplayNamePrefix; TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval; Admins = config.Admins; this.apiKey = apiKey; try { LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true); } catch (ArgumentException) { Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'"); LogLevel = Log.LogLevel.Info; } log = new Log (config.LogFile, this.DisplayName, LogLevel); CreateHandler = handlerCreator; BotControlClass = config.BotControlClass; // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; log.Debug ("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); log.Info ("Connecting..."); SteamClient.Connect(); Thread CallbackThread = new Thread(() => // Callback Handling { while (true) { CallbackMsg msg = SteamClient.WaitForCallback (true); HandleSteamMessage (msg); } }); CallbackThread.Start(); log.Success ("Done Loading Bot!"); CallbackThread.Join(); }
public Bot(Configuration config, Configuration.BotInfo botConfig, string apiKey, UserHandlerCreator handlerCreator, bool debug = false, bool process = false) { this.config = config; logOnDetails = new SteamUser.LogOnDetails { Username = botConfig.Username, Password = botConfig.Password }; DisplayName = botConfig.DisplayName; ChatResponse = botConfig.ChatResponse; MaximumTradeTime = botConfig.MaximumTradeTime; MaximiumActionGap = botConfig.MaximumActionGap; DisplayNamePrefix = botConfig.DisplayNamePrefix; TradePollingInterval = botConfig.TradePollingInterval <= 100 ? 800 : botConfig.TradePollingInterval; Admins = config.Admins; this.apiKey = apiKey; this.isprocess = process; try { LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), botConfig.LogLevel, true); } catch (ArgumentException) { Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'"); LogLevel = Log.LogLevel.Info; } this.LogFile = botConfig.LogFile; log = new Log(this.LogFile, this.DisplayName, LogLevel); CreateHandler = handlerCreator; BotControlClass = botConfig.BotControlClass; // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; log.Debug ("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); SteamGameCoordinator = SteamClient.GetHandler<SteamGameCoordinator>(); backgroundWorker = new BackgroundWorker { WorkerSupportsCancellation = true }; backgroundWorker.DoWork += BackgroundWorkerOnDoWork; backgroundWorker.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted; backgroundWorker.RunWorkerAsync(); }
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, Interface gui, bool debug = false) { while (Interface.loginClicked == false) { // Wait for user to login } logOnDetails = new SteamUser.LogOnDetails { Username = Interface.username, Password = Interface.password }; Admins = new ulong[1]; Admins[0] = 123456789; this.apiKey = apiKey; LogLevel = Log.LogLevel.Info; //log = new Log(config.LogFile, this.DisplayName, LogLevel); CreateHandler = handlerCreator; BotControlClass = config.BotControlClass; // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; ////log.Debug("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); gui.UpdateLog("\r\nConnecting, please wait..."); ////log.Info("Connecting..."); SteamClient.Connect(); Thread CallbackThread = new Thread(() => // Callback Handling { while (true) { CallbackMsg msg = SteamClient.WaitForCallback(true); HandleSteamMessage(msg, gui); } }); CallbackThread.Start(); ////log.Success("Done Loading Bot!"); CallbackThread.Join(); }
public UserHandler(Bot bot, SteamID sid, Configuration config) { Bot = bot; OtherSID = sid; if (Settings == null) { BotMode = config.BotMode; NumberOfBots = config.TotalBots; AutoCraftWeps = config.Options.AutoCraftWeapons; ManageCrates = config.Options.ManageCrates; DeleteCrates = config.Options.DeleteCrates; TransferCrates = config.Options.TransferCrates; ExcludedCrates = config.Options.SavedCrates; CrateUHIsRunning = config.HasCrateUHLoaded; MainUHIsRunning = config.HasMainUHLoaded; Settings = config; } }
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false, bool process = false) { userHandlers = new Dictionary<SteamID, UserHandler>(); logOnDetails = new SteamUser.LogOnDetails { Username = config.Username, Password = config.Password }; DisplayName = config.DisplayName; ChatResponse = config.ChatResponse; MaximumTradeTime = config.MaximumTradeTime; MaximumActionGap = config.MaximumActionGap; DisplayNamePrefix = config.DisplayNamePrefix; tradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval; schemaLang = config.SchemaLang != null && config.SchemaLang.Length == 2 ? config.SchemaLang.ToLower() : "en"; Admins = config.Admins; ApiKey = !String.IsNullOrEmpty(config.ApiKey) ? config.ApiKey : apiKey; isProccess = process; try { if( config.LogLevel != null ) { consoleLogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true); Console.WriteLine(@"(Console) LogLevel configuration parameter used in bot {0} is depreciated and may be removed in future versions. Please use ConsoleLogLevel instead.", DisplayName); } else consoleLogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.ConsoleLogLevel, true); } catch (ArgumentException) { Console.WriteLine(@"(Console) ConsoleLogLevel invalid or unspecified for bot {0}. Defaulting to ""Info""", DisplayName); consoleLogLevel = Log.LogLevel.Info; } try { fileLogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.FileLogLevel, true); } catch (ArgumentException) { Console.WriteLine(@"(Console) FileLogLevel invalid or unspecified for bot {0}. Defaulting to ""Info""", DisplayName); fileLogLevel = Log.LogLevel.Info; } logFile = config.LogFile; Log = new Log(logFile, DisplayName, consoleLogLevel, fileLogLevel); createHandler = handlerCreator; BotControlClass = config.BotControlClass; SteamWeb = new SteamWeb(); // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; Log.Debug ("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamClient.AddHandler(new SteamNotifications()); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); SteamGameCoordinator = SteamClient.GetHandler<SteamGameCoordinator>(); SteamNotifications = SteamClient.GetHandler<SteamNotifications>(); botThread = new BackgroundWorker { WorkerSupportsCancellation = true }; botThread.DoWork += BackgroundWorkerOnDoWork; botThread.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted; botThread.RunWorkerAsync(); }
private void SpawnBotThread(Configuration.BotInfo botConfig) { /* // the bot object itself is threaded so we just build it and start it. Bot b = new Bot(botConfig, config.ApiKey, UserHandlerCreator, true); b.OnSteamGuardRequired += BotOnOnSteamGuardRequired; TheBot = b; TheBot.StartBot(); */ }
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false) { Username = config.Username; Password = config.Password; DisplayName = config.DisplayName; ChatResponse = config.ChatResponse; MaximumTradeTime = config.MaximumTradeTime; MaximiumActionGap = config.MaximumActionGap; DisplayNamePrefix = config.DisplayNamePrefix; TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval; Admins = config.Admins; this.apiKey = apiKey; AuthCode = null; try { LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true); } catch (ArgumentException) { Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'"); LogLevel = Log.LogLevel.Info; } log = new Log (config.LogFile, this.DisplayName, LogLevel); CreateHandler = handlerCreator; // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; log.Debug ("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); log.Info ("Connecting..."); SteamClient.Connect(); Thread CallbackThread = new Thread(() => // Callback Handling { while (true) { CallbackMsg msg = SteamClient.WaitForCallback (true); HandleSteamMessage (msg); } }); new Thread(() => // Trade Polling if needed { while (true) { Thread.Sleep (TradePollingInterval); if (CurrentTrade != null) { try { CurrentTrade.Poll (); if (CurrentTrade.OtherUserCancelled) { log.Info("Other user cancelled the trade."); CurrentTrade = null; } } catch (Exception e) { log.Error ("Error Polling Trade: " + e); // ok then we should stop polling... CurrentTrade = null; } } } }).Start (); CallbackThread.Start(); log.Success ("Done Loading Bot!"); CallbackThread.Join(); }
public BotControlForm(Configuration.BotInfo config, string apiKey, bool debug = false) { InitializeComponent(); foreach(EPersonaState state in Enum.GetValues(typeof(EPersonaState))) { this.cbxPersonaState.Items.Add(state); } SetStatus("Setting variables..."); logOnDetails = new SteamUser.LogOnDetails { Username = config.Username, Password = config.Password }; DisplayName = config.DisplayName; ChatResponse = config.ChatResponse; MaximumTradeTime = config.MaximumTradeTime; MaximiumActionGap = config.MaximumActionGap; DisplayNamePrefix = config.DisplayNamePrefix; TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval; Admins = config.Admins; this.apiKey = apiKey; try { LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true); } catch (ArgumentException) { Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'"); LogLevel = Log.LogLevel.Info; } log = new Log(config.LogFile, this.DisplayName, LogLevel); //CreateHandler = handlerCreator; BotControlClass = config.BotControlClass; // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); SetStatus("Connecting to Steam..."); SteamClient.Connect(); masterThread = new Thread(this.pollSteam); masterThread.Start(); }
public CrateUserHandler(Bot bot, SteamID sid, Configuration config) : base(bot, sid, config) { mySteamID = Bot.SteamUser.SteamID; CrateSID = mySteamID; }
public static void Main(string[] args) { Application.EnableVisualStyles(); string path = Path.Combine(Environment.ExpandEnvironmentVariables("%systemroot%"), @"Microsoft.NET\Framework\v4.0.30319\System.Core.dll"); if (!File.Exists(path)) { DialogResult userChoice = MessageBox.Show("It seems that you don't have .NET 4.0 installed. Would you like to be directed to the download page? " + "If you are sure you do have .NET 4.0 installed, click No to simply close this message box. " + "Click Cancel to close Mist.\n\n" + ".NET 4.0 can be found at http://www.microsoft.com/en-ca/download/details.aspx?id=17851", ".NET 4.0 Not Detected", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); if (userChoice == DialogResult.Yes) { System.Diagnostics.Process.Start("http://www.microsoft.com/en-ca/download/details.aspx?id=17851"); Environment.Exit(0); return; } else if (userChoice == DialogResult.No) { } else if (userChoice == DialogResult.Cancel) { Environment.Exit(0); return; } } CleanUp(); string LogDirectory = Path.Combine(Application.StartupPath, "logs"); if (!Directory.Exists(LogDirectory)) { try { Directory.CreateDirectory(LogDirectory); // try making the log directory Console.WriteLine("Creating log directory."); } catch (Exception ex) { Console.WriteLine("Unable to create log directory.\n{0}", ex.ToString()); return; } } Log mainLog; bool created; mutex = new Mutex(false, "Mist-AF12AF2", out created); if (!created) { int pid = 0; try { Random random = new Random(); pid = random.Next(0, 9999); pid += System.Diagnostics.Process.GetProcessesByName("Mist")[0].Id; } catch { Random random = new Random(); pid = random.Next(0, 9999); } mainLog = new Log(@"logs/Mist-" + pid + ".log", "Mist", Log.LogLevel.Debug); } else { mainLog = new Log(@"logs/Mist.log", "Mist", Log.LogLevel.Debug); } Login login = new Login(mainLog); mainLog.Info("Launching Mist..."); Configuration config = new Configuration(); Configuration.BotInfo info = new Configuration.BotInfo(); info.BotControlClass = "SteamBot.SimpleUserHandler"; new Thread(() => { while (!Login.LoginClicked) { } int crashes = 0; while (crashes < 100) { try { new Bot(info, mainLog, login.APIKey, (Bot bot, SteamID sid) => { return (SteamBot.UserHandler)System.Activator.CreateInstance(Type.GetType(bot.BotControlClass), new object[] { bot, sid }); }, login, false); } catch (Exception e) { mainLog.Error("Error With Bot: " + e); crashes++; } } }).Start(); Application.Run(login); }
public static void Main(string[] args) { string LogDirectory = Path.Combine(Application.StartupPath, "logs"); if (!Directory.Exists(LogDirectory)) { try { Directory.CreateDirectory(LogDirectory); // try making the cache directory Console.WriteLine("Creating log directory."); } catch (Exception ex) { Console.WriteLine("Unable to create log directory.\n{0}", ex.ToString()); return; } } Log mainLog; bool created; mutex = new Mutex(false, "Mist-AF12AF2", out created); if (!created) { int pid = 0; try { Random random = new Random(); pid = random.Next(0, 9999); pid += System.Diagnostics.Process.GetProcessesByName("Mist")[0].Id; } catch { Random random = new Random(); pid = random.Next(0, 9999); } mainLog = new Log(@"logs/Mist-" + pid + ".log", "Mist", Log.LogLevel.Debug); } else { mainLog = new Log(@"logs/Mist.log", "Mist", Log.LogLevel.Debug); } Application.EnableVisualStyles(); Login login = new Login(); mainLog.Info("Launching Mist..."); Configuration config = new Configuration(); Configuration.BotInfo info = new Configuration.BotInfo(); info.BotControlClass = "SteamBot.SimpleUserHandler"; login.Show(); login.Activate(); new Thread(() => { while (!Login.LoginClicked) { } int crashes = 0; while (crashes < 100) { try { new Bot(info, mainLog, login.APIKey, (Bot bot, SteamID sid) => { return (SteamBot.UserHandler)System.Activator.CreateInstance(Type.GetType(bot.BotControlClass), new object[] { bot, sid }); }, login, false); } catch (Exception e) { mainLog.Error("Error With Bot: " + e); crashes++; } } }).Start(); Application.Run(login); }
/// <summary> /// Creates a new instance of <see cref="RunningBot"/> class. /// </summary> /// <param name="useProcesses"> /// <c>true</c> indicates that this bot is ran in a thread; /// <c>false</c> indicates it is ran in a separate process. /// </param> /// <param name="index">The index of the bot in the configuration.</param> /// <param name="config">The bots configuration object.</param> public RunningBot(bool useProcesses, int index, Configuration config) { this.config = config; UsingProcesses = useProcesses; BotConfigIndex = index; BotConfig = config.Bots[BotConfigIndex]; this.config = config; }
public static void Main(string[] args) { Application.EnableVisualStyles(); Welcome login = new Welcome(); Interface mainForm = new Interface(); Splash splash = new Splash(); Configuration config = new Configuration(); Configuration.BotInfo info = new Configuration.BotInfo(); info.Admins = new ulong[1]; info.Admins[0] = 0123456789; info.BotControlClass = ""; info.ChatResponse = ""; info.DisplayName = ""; info.DisplayNamePrefix = ""; info.LogFile = ""; info.LogLevel = "Info"; info.MaximumActionGap = 0; info.MaximumTradeTime = 0; info.Password = ""; info.TradePollingInterval = 999; info.Username = ""; splash.Show(); new Thread(() => { int crashes = 0; while (crashes < 1000) { try { new Bot(info, "120F03A1543C9F22AA9BF4C7B6442154", (Bot bot, SteamID sid) => { return (SteamBot.UserHandler)System.Activator.CreateInstance(Type.GetType(bot.BotControlClass), new object[] { bot, sid }); }, mainForm, false); } catch (Exception e) { Console.WriteLine("Error With Bot: " + e); crashes++; } } }).Start(); Thread.Sleep(3000); splash.Close(); splash.Dispose(); Application.Run(login); while (!Welcome.trial || !Welcome.loggedIn) { if (Welcome.loggedIn || Welcome.trial) { mainForm.Text = "SteamGrouper " + Interface.BotVersion; mainForm.ShowDialog(); mainForm.Activate(); break; } else if (Application.OpenForms.Count == 0) { Environment.Exit(0); } } }
public Bot(Configuration.BotInfo config, Log log, string apiKey, UserHandlerCreator handlerCreator, Login _login, bool debug = false) { this.main = _login; logOnDetails = new SteamUser.LogOnDetails { Username = _login.Username, Password = _login.Password }; ChatResponse = ""; TradePollingInterval = 500; Admins = new ulong[1]; Admins[0] = 0; this.apiKey = apiKey; try { LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), "Debug", true); } catch (ArgumentException) { Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'"); LogLevel = Log.LogLevel.Info; } this.log = log; CreateHandler = handlerCreator; BotControlClass = "SteamBot.SimpleUserHandler"; // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; log.Debug ("Initializing Steam account..."); main.Invoke((Action)(() => { main.label_status.Text = "Initializing Steam account..."; })); SteamClient = new SteamClient(); SteamClient.AddHandler(new ClientPlayerNicknameListHandler()); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); SteamGameCoordinator = SteamClient.GetHandler<SteamGameCoordinator>(); SteamNicknames = SteamClient.GetHandler<ClientPlayerNicknameListHandler>(); log.Info ("Connecting..."); main.Invoke((Action)(() => { main.label_status.Text = "Connecting to Steam..."; })); SteamClient.Connect(); Thread CallbackThread = new Thread(() => // Callback Handling { while (true) { CallbackMsg msg = SteamClient.WaitForCallback(true); new Thread(() => HandleSteamMessage(msg)).Start(); } }); CallbackThread.Start(); CallbackThread.Join(); log.Success("Done loading account!"); main.Invoke((Action)(() => { main.label_status.Text = "Done loading account!"; })); }
private void SpawnBotThread(Configuration.BotInfo botConfig) { // the bot object itself is threaded so we just build it and start it. Bot b = new Bot(botConfig, config.ApiKey, UserHandlerCreator, true); TheBot = b; TheBot.StartBot(); }
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false) { logOnDetails = new SteamUser.LogOnDetails { Username = config.Username, Password = config.Password }; DisplayName = config.DisplayName; ChatResponse = config.ChatResponse; MaximumTradeTime = config.MaximumTradeTime; MaximiumActionGap = config.MaximumActionGap; DisplayNamePrefix = config.DisplayNamePrefix; TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval; hatBuyPrice= config.HatBuyPrice; hatSellPrice= config.HatSellPrice; maxRequestTime= config.MaxRequestTime; craftHatSellPrice = config.CraftHatSellPrice; Admins = config.Admins; this.apiKey = apiKey; try { LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true); } catch (ArgumentException) { Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'"); LogLevel = Log.LogLevel.Info; } log = new Log (config.LogFile, this.DisplayName, LogLevel); CreateHandler = handlerCreator; BotControlClass = config.BotControlClass; // Hacking around https ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate; log.Debug ("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler<SteamTrading>(); SteamUser = SteamClient.GetHandler<SteamUser>(); SteamFriends = SteamClient.GetHandler<SteamFriends>(); log.Info ("Connecting..."); SteamClient.Connect(); Thread CallbackThread = new Thread(() => // Callback Handling { while (true) { CallbackMsg msg = SteamClient.WaitForCallback (true); HandleSteamMessage (msg); } }); new Thread(() => { while (true) { Thread.Sleep(1000); if (currentRequest.User != null) { DateTime RequestTimeout = RequestTime.AddSeconds(maxRequestTime); int untilTradeTimeout = (int)Math.Round((RequestTimeout - DateTime.Now).TotalSeconds); if (untilTradeTimeout <= 0 && (MySQL.getItem().User != null)) { SteamFriends.SendChatMessage(currentRequest.User, EChatEntryType.ChatMsg, "Sorry, but your request took too long"); NewRequest(MySQL.RequestStatus.Timedout); log.Warn("Request timedout"); } } } }).Start(); CallbackThread.Start(); log.Success ("Done Loading Bot!"); CallbackThread.Join(); }