/// <summary> /// Add a bot to the runner. /// </summary> /// <param name="type"></param> /// <param name="username"></param> /// <param name="password"></param> public void AddBot(Type type, string username, string password) { List <VTankBot> bots = BotRunner.GetRunningBots(); // Remove old bot if it exists. for (int i = 0; i < bots.Count; ++i) { VTankBot bot = bots[i]; if (bot.AuthInfo.Username == username) { Print("Removed duplicate bot {0}.", username); BotRunner.Kill(bot); break; } } AuthInfo auth = new AuthInfo(username, password); BotRunner.Register(type, auth, null); BotRunner.Start(false); Print("Added new bot, {0}.", username); if (OnBotChange != null) { OnBotChange(null); } }
/// <summary> /// Read the list of bots from the configuration file. /// </summary> private void ReadBotsFromConfigFile() { using (StreamReader file = new StreamReader(new FileStream(configFile, FileMode.Open))) { string line = null; while ((line = file.ReadLine()) != null) { if (String.IsNullOrEmpty(line)) { break; } if (line.StartsWith("#")) { continue; } try { string[] data = line.Split(new char[] { '=' }, 2, StringSplitOptions.None); Type type = Type.GetType("VTankBotRunner." + data[0].Trim()); if (type == null) { type = Type.GetType(data[0].Trim()); if (type == null) { throw new Exception("Bot type does not exist."); } } AuthInfo auth = AuthInfo.FromString(data[1].Trim()); runner.Register(type, auth, null); InsertTextIntoConsole(String.Format("Adding bot: {0}", auth.Username)); } catch (Exception e) { Console.Error.WriteLine( "Warning: Found corrupted bot in file: {0}", e); } } } }