public BotFactory() { Instance = this; logger = new StreamWriter(logPath); logger.WriteLine("Starting BotFactory"); if (!File.Exists(botsInfosPath)) botInfos = new List<BotInfo>(); else using (StreamReader sr = new StreamReader(botsInfosPath)) { try { XmlSerializer serializer = new XmlSerializer(typeof(List<BotInfo>)); botInfos = (List<BotInfo>)serializer.Deserialize(sr); } catch(InvalidOperationException) { botInfos = new List<BotInfo>(); } } factoryGame = new AutomatedGame(Settings.Default.Hostname, Settings.Default.Port, Settings.Default.Username, Settings.Default.Password, Settings.Default.RealmID, 0); factoryGame.Start(); }
public static void UnitTestInitialize(TestContext context) { var hostname = Settings.Default.Hostname; var port = Settings.Default.Port; var username = Settings.Default.Username; var password = Settings.Default.Password; var realmId = Settings.Default.RealmID; var character = Settings.Default.Character; game = new AutomatedGame(hostname, port, username, password, realmId, character); game.Start(); int tries = 0; while (!game.LoggedIn) { Thread.Sleep(1000); tries++; if (tries > 15) throw new TimeoutException("Could not login after 15 tries"); } Thread.Sleep(5000); game.ScheduleAction(() => game.DoSayChat("Connected")); }
public BotFactory() { Instance = this; logger = TextWriter.Synchronized(new StreamWriter(logPath)); logger.WriteLine("Starting BotFactory"); if (!File.Exists(botsInfosPath)) botInfos = new List<BotInfo>(); else using (StreamReader sr = new StreamReader(botsInfosPath)) { try { XmlSerializer serializer = new XmlSerializer(typeof(List<BotInfo>)); botInfos = (List<BotInfo>)serializer.Deserialize(sr); } catch(InvalidOperationException) { botInfos = new List<BotInfo>(); } } foreach (BotBehaviorSettings behavior in Settings.Default.Behaviors) botBehaviors[behavior.Name] = behavior; if (botBehaviors.Count == 0) { Log("Behaviors not found in the configuration file, exiting"); Environment.Exit(0); } if (!botBehaviors.ContainsKey(defaultBehaviorName)) { Log("'" + defaultBehaviorName + "' behavior not found in the configuration file, exiting"); Environment.Exit(0); } if (botBehaviors.Sum(behavior => behavior.Value.Probability) != 100) { Log("Behaviors total Probability != 100 (" + botBehaviors.Sum(behavior => behavior.Value.Probability) + "), exiting"); Environment.Exit(0); } foreach (BotInfo botInfo in botInfos) { if (string.IsNullOrEmpty(botInfo.BehaviorName)) { Log(botInfo.Username + " has missing behavior, setting to default one"); botInfo.BehaviorName = defaultBehaviorName; continue; } if (!botBehaviors.ContainsKey(botInfo.BehaviorName)) { Log(botInfo.Username + " has inexistent behavior '" + botInfo.BehaviorName + "', setting to default one"); botInfo.BehaviorName = defaultBehaviorName; continue; } } DetourCLI.Detour.Initialize(Settings.Default.MMAPsFolderPath); VMapCLI.VMap.Initialize(Settings.Default.VMAPsFolderPath); MapCLI.Map.Initialize(Settings.Default.MAPsFolderPath); DBCStoresCLI.DBCStores.Initialize(Settings.Default.DBCsFolderPath); DBCStoresCLI.DBCStores.LoadDBCs(); factoryGame = new AutomatedGame(Settings.Default.Hostname, Settings.Default.Port, Settings.Default.Username, Settings.Default.Password, Settings.Default.RealmID, 0); factoryGame.Start(); }