public static LoadConfiguration ( string filename ) : |
||
filename | string | |
Результат |
public static void Main(string[] args) { if (!File.Exists("settings.json")) { Console.WriteLine("No settings.json file found."); return; } Configuration configObject; try { configObject = Configuration.LoadConfiguration("settings.json"); } catch (Newtonsoft.Json.JsonReaderException) { // handle basic json formatting screwups Console.WriteLine("settings.json file is currupt or improperly formatted."); return; } if (configObject.Bots.Length > 0) { //Bot b = new Bot(configObject.Bots[botIndex], configObject.ApiKey, BotManager.UserHandlerCreator, true); BotControlForm frm = new BotControlForm(configObject.Bots[0], configObject.ApiKey, true); frm.ShowDialog(); Application.Exit(); //frm.StartBot(); //Console.Title = configObject.Bots[botIndex].DisplayName; //b.StartBot(); // never returns from this. } }
// This mode is to run a single Bot until it's terminated. private static void BotMode(int botIndex) { if (!File.Exists("settings.json")) { Console.WriteLine("No settings.json file found."); return; } Configuration configObject; try { configObject = Configuration.LoadConfiguration("settings.json"); } catch (Newtonsoft.Json.JsonReaderException) { // handle basic json formatting screwups Console.WriteLine("settings.json file is currupt or improperly formatted."); return; } if (configObject.Bots.Length > botIndex) { Bot b = new Bot(configObject.Bots[botIndex], configObject.ApiKey, BotManager.UserHandlerCreator, true); Console.Title = configObject.Bots[botIndex].DisplayName; b.StartBot(); // never returns from this. } while (true) { // we need this in here so we can keep // the console alive so we can read the // steamguard code if need be. } }
// This mode is to run a single Bot until it's terminated. private static void BotMode(int botIndex) { if (!File.Exists("settings.json")) { Console.WriteLine("No settings.json file found."); return; } Configuration configObject; try { configObject = Configuration.LoadConfiguration("settings.json"); } catch (Newtonsoft.Json.JsonReaderException) { // handle basic json formatting screwups Console.WriteLine("settings.json file is currupt or improperly formatted."); return; } if (configObject.Bots.Length > botIndex) { Bot b = new Bot(configObject.Bots[botIndex], configObject.ApiKey, BotManager.UserHandlerCreator, true, true); Console.Title = configObject.Bots[botIndex].DisplayName; b.StartBot(); // never returns from this. } // this loop is needed to keep the botmode console alive. // the sleep keeps the cpu usage low. while (true) { System.Threading.Thread.Sleep(1000); } }
/// <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); }
/// <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); }
/// <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); }
public static void Main(string[] args) { if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "/settings.json")) { Configuration config = Configuration.LoadConfiguration(AppDomain.CurrentDomain.BaseDirectory + "/settings.json"); Log mainLog = new Log(config.MainLog, null); foreach (Configuration.BotInfo info in config.Bots) { mainLog.Info("Launching Bot " + info.DisplayName + "..."); new Thread(() => { int crashes = 0; while (crashes < 1000) { try { new Bot(info, config.ApiKey, (Bot bot, SteamID sid) => { return((SteamBot.UserHandler)System.Activator.CreateInstance(Type.GetType(info.BotControlClass), new object[] { bot, sid })); }); } catch (Exception e) { mainLog.Error("Error With Bot: " + e); crashes++; } } }).Start(); Thread.Sleep(5000); } MySQL.start(); } else { Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory); Console.WriteLine("Configuration File Does not exist. Please rename 'settings-template.json' to 'settings.json' and modify the settings to match your environment"); } }
/// <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); } return(ParseConfiguration()); }
// This mode is to run a single Bot until it's terminated. private static void BotMode(int botIndex) { if (!File.Exists("settings.json")) { Console.WriteLine("No settings.json file found."); 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, BotManager.UserHandlerCreator, true, true); Console.Title = "Bot Manager"; b.StartBot(); string AuthSet = "auth"; string ExecCommand = "exec"; string InputCommand = "input"; // 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].Equals(InputCommand, StringComparison.CurrentCultureIgnoreCase)) { b.HandleInput(c.Remove(0, cs[0].Length + 1)); } } } }