public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false, bool process = false) { logOnDetails = new SteamUser.LogOnDetails { Username = config.Username, Password = config.Password }; DisplayName = config.DisplayName; MaximumTradeTime = config.MaximumTradeTime; MaximiumActionGap = config.MaximumActionGap; DisplayNamePrefix = config.DisplayNamePrefix; TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval; Admins = config.Admins; BackpackUrl = config.Backpack; sNumberTradeFile = config.TradeNumberSaveFile; this.apiKey = apiKey; this.isprocess = process; 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; dReserved = new Dictionary <ulong, SteamID>(); dDonated = new Dictionary <ulong, SteamID>(); log.Debug("Initializing Steam Bot..."); SteamClient = new SteamClient(); SteamTrade = SteamClient.GetHandler <SteamTrading>(); SteamUser = SteamClient.GetHandler <SteamUser>(); SteamFriends = SteamClient.GetHandler <SteamFriends>(); SteamGameCoordinator = SteamClient.GetHandler <SteamGameCoordinator>(); craftHandler = new CraftingHandler(this); informHandler = new InformHandler(this, BotControlClass.Substring(9)); AdvertiseHandler = new AdvertiseHandler(this, BotControlClass.Substring(9), clsFunctions.BotGroup); backgroundWorker = new BackgroundWorker { WorkerSupportsCancellation = true }; if (!Directory.Exists(FriendsFolder)) { Directory.CreateDirectory(FriendsFolder); } this.FriendActivity = FriendActivity.LoadFriendActivity(FriendsFolder + logOnDetails.Username + ".json"); backgroundWorker.DoWork += BackgroundWorkerOnDoWork; backgroundWorker.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted; backgroundWorker.RunWorkerAsync(); }
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(); }
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, bool process = 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; SchemaLang = config.SchemaLang != null && config.SchemaLang.Length == 2 ? config.SchemaLang.ToLower() : "en"; Admins = config.Admins; this.ApiKey = !String.IsNullOrEmpty(config.ApiKey) ? config.ApiKey : apiKey; this.isprocess = process; 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; 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>(); backgroundWorker = new BackgroundWorker { WorkerSupportsCancellation = true }; backgroundWorker.DoWork += BackgroundWorkerOnDoWork; backgroundWorker.RunWorkerCompleted += BackgroundWorkerOnRunWorkerCompleted; backgroundWorker.RunWorkerAsync(); }
/// <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) { configFile = (AppDomain.CurrentDomain.BaseDirectory + configFile); try { FileStream file = File.OpenRead(configFile); } catch (Exception e) { return(false); } try { ConfigObject = Configuration.LoadConfiguration(configFile); } catch (JsonReaderException) { // handle basic json formatting screwups ConfigObject = null; } if (ConfigObject == null) { return(false); } DB = new Database(ConfigObject.DatabaseHost, ConfigObject.DatabaseUserName, ConfigObject.DatabasePassword); InitialiseDatabase(); useSeparateProcesses = ConfigObject.UseSeparateProcesses; mainLog = new Log(ConfigObject.MainLog, null, Log.LogLevel.Debug, Log.LogLevel.Debug); for (int i = 0; i < ConfigObject.Bots.Length; i++) { Configuration.BotInfo info = ConfigObject.Bots[i]; if (ConfigObject.AutoStartAllBots || info.AutoStart) { mainLog.Info("Launching Bot " + info.DisplayName + "..."); } var v = new RunningBot(useSeparateProcesses, i, ConfigObject, DB); botProcs.Add(v); } return(true); }
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, 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(); }
/// <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 (!Directory.Exists(DATA_FOLDER)) { Directory.CreateDirectory(DATA_FOLDER); } if (!File.Exists(DATA_FOLDER + configFile)) { return(false); } try { ConfigObject = Configuration.LoadConfiguration(DATA_FOLDER + 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, Log.LogLevel.Debug); for (int i = 0; i < ConfigObject.Bots.Length; i++) { Configuration.BotInfo info = ConfigObject.Bots[i]; if (ConfigObject.AutoStartAllBots || info.AutoStart) { mainLog.Info("Launching Bot " + info.DisplayName + "..."); } var v = new RunningBot(useSeparateProcesses, i, ConfigObject); botProcs.Add(v); } return(true); }
/// <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); foreach (ulong admin in ConfigObject.Admins) { clsFunctions.AdminIDs.Add(admin.ToString()); } clsFunctions.schema = SteamTrade.Schema.FetchSchema(ConfigObject.ApiKey); } 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]; if (info.Start) { mainLog.Info("Launching Bot " + info.DisplayName + "..."); } var v = new RunningBot(useSeparateProcesses, i, ConfigObject); botProcs.Add(v); } return(true); }
public bool ParseConfiguration() { useSeparateProcesses = ConfigObject.UseSeparateProcesses; mainLog = new Log(ConfigObject.MainLog, null, Log.LogLevel.Debug, Log.LogLevel.Debug); mongoLog = new NewMarketLogger(); for (int i = 0; i < ConfigObject.Bots.Length; i++) { Configuration.BotInfo info = ConfigObject.Bots[i]; if (ConfigObject.AutoStartAllBots || info.AutoStart) { mainLog.Info("Launching Bot " + info.DisplayName + "..."); } var v = new RunningBot(useSeparateProcesses, i, ConfigObject); botProcs.Add(v); } return(true); }
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); }
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 = 50; Admins = new ulong[1]; Admins[0] = 123456789; 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(); SteamTrade = SteamClient.GetHandler <SteamTrading>(); SteamUser = SteamClient.GetHandler <SteamUser>(); SteamFriends = SteamClient.GetHandler <SteamFriends>(); 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); HandleSteamMessage(msg); } }); CallbackThread.Start(); CallbackThread.Join(); log.Success("Done loading account!"); main.Invoke((Action)(() => { main.label_status.Text = "Done loading account!"; })); }
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, string apiKey, UserHandlerCreator handlerCreator, bool debug = false, bool process = false) { userHandlers = new Dictionary <SteamID, UserHandler>(); logOnDetails = new SteamUser.LogOnDetails { Username = config.Username, Password = _sec_RetrievePassword(config.Username) }; 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 : "en_US"; 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(); Orders = OrderManager.Load(Log); // 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>(); CallbackMgr = new CallbackManager(SteamClient); EventMgr = new EventManager(this, CallbackMgr); botSteamThread = new BackgroundWorker { WorkerSupportsCancellation = true }; botSteamThread.DoWork += _backgroundWorkerOnDoWork; botSteamThread.RunWorkerCompleted += _backgroundWorkerOnRunWorkerCompleted; botSteamThread.RunWorkerAsync(); heartBeatThread = new Thread(HeartbeatLoop); heartBeatThread.Name = "bp.tf Heartbeat Thread: " + config.Username; heartBeatThread.Start(); crafterThread = new Thread(CrafterLoop); crafterThread.Name = "Crafting Loop Thread: " + config.Username; crafterThread.Start(); }
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; // 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 != null && 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 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; CreateLog(); 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(); }
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 static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { MessageBox.Show( @"A fatal error has occured! Error message has been written to error.log"); File.AppendAllText("error.log", eventArgs.ExceptionObject.ToString() + "\r\n"); }; 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(); if (args.Length > 0 && args[0] == "-login") { login.ForceLogin = true; mainLog.Info("-login parameter detected, logging in automatically with saved credentials."); } Application.Run(login); }
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(); }