示例#1
0
        /// <summary>
        /// Read accounts from the accounts.txt file
        /// </summary>
        /// <returns>Accounts saved in the file</returns>
        public static List <Account> ReadAccounts()
        {
            var accounts = new List <Account>();

            try
            {
                // Open the text file using a stream reader.
                var folder = IoHelperCore.TbsPath();
                System.IO.Directory.CreateDirectory(folder);

                using (StreamReader sr = new StreamReader(IoHelperCore.AccountsPath))
                {
                    accounts = JsonConvert.DeserializeObject <List <Account> >(sr.ReadToEnd());
                }
                if (accounts == null)
                {
                    accounts = new List <Account>();
                }
            }
            catch (IOException e)
            {
                Console.WriteLine("Can't read accounts.txt, Exception thrown: " + e.Message);
            }
            return(accounts);
        }
示例#2
0
        /// <summary>
        /// Removes the cache folders that were created by Selenium driver, since they take a lot of space (70MB+)
        /// </summary>
        /// <param name="acc">Account</param>
        public static void RemoveCache(Account acc)
        {
            var userFolder = IoHelperCore.GetCacheFolder(acc.AccInfo.Nickname, acc.AccInfo.ServerUrl, "");

            var removeFolders = Directory
                                .GetDirectories(CachePath + "\\")
                                .Where(x => x.Replace(CachePath + "\\", "").StartsWith(userFolder))
                                .ToArray();

            for (int i = 0; i < removeFolders.Count(); i++)
            {
                Directory.Delete(removeFolders[i], true);
            }
        }
示例#3
0
 /// <summary>
 /// Cache folder selenium will use for this account
 /// </summary>
 /// <param name="username">Username</param>
 /// <param name="server">Server url</param>
 /// <param name="proxy">Proxy ip</param>
 /// <returns></returns>
 internal static string GetCacheFolder(string username, string server, string proxy)
 {
     return($"{username}_{IoHelperCore.UrlRemoveHttp(server)}_{proxy}");
 }
        /// <summary>
        /// Initializes a new village model and creates the task to update the village
        /// </summary>
        /// <param name="acc">Account</param>
        /// <param name="newVill">new village</param>
        public static void NewVillageFound(Account acc, VillageChecked newVill)
        {
            var vill = new Village()
            {
                Active      = newVill.Active,
                Coordinates = newVill.Coordinates,
                Id          = newVill.Id,
                Name        = newVill.Name,
                UnderAttack = newVill.UnderAttack
            };

            vill.Init(acc);
            acc.Villages.Add(vill);

            //on new village set the tasks
            if (string.IsNullOrEmpty(acc.NewVillages.BuildingTasksLocationNewVillage))
            {
                DefaultConfigurations.FarmVillagePlan(acc, vill);
            }
            else
            {
                IoHelperCore.AddBuildTasksFromFile(acc, vill, acc.NewVillages.BuildingTasksLocationNewVillage);
            }

            DefaultConfigurations.SetDefaultTransitConfiguration(acc, vill);
            vill.Build.AutoBuildResourceBonusBuildings = true;
            vill.Troops.TroopToTrain = (Classificator.TroopsEnum)((int)(acc.AccInfo.Tribe ?? Classificator.TribeEnum.Any) * 10); //change to acc wide setting

            // Copy default settings to the new village. TODO: use automapper for this.
            var defaultSettings = acc.NewVillages.DefaultSettings;

            vill.Settings = new Models.Settings.VillSettings()
            {
                Type               = defaultSettings.Type,
                BarracksTrain      = defaultSettings.BarracksTrain,
                StableTrain        = defaultSettings.StableTrain,
                WorkshopTrain      = defaultSettings.WorkshopTrain,
                GreatBarracksTrain = defaultSettings.GreatBarracksTrain,
                GreatStableTrain   = defaultSettings.GreatStableTrain,
                SendRes            = defaultSettings.SendRes,
                GetRes             = defaultSettings.GetRes,
            };

            // Update the village
            UpdateDorfs(acc, vill);

            // Change village name
            var newVillageFromList = acc.NewVillages.Locations
                                     .FirstOrDefault(x =>
                                                     x.SettlersSent &&
                                                     x.coordinates.x == vill.Coordinates.x &&
                                                     x.coordinates.y == vill.Coordinates.y
                                                     );

            if (newVillageFromList != null)
            {
                if (string.IsNullOrEmpty(newVillageFromList.Name))
                {
                    newVillageFromList.Name = NewVillageHelper.GenerateName(acc);
                }
                acc.NewVillages.Locations.Remove(newVillageFromList);
                TaskExecutor.AddTaskIfNotExists(acc,
                                                new ChangeVillageName()
                {
                    ExecuteAt  = DateTime.Now,
                    ChangeList = new List <(int, string)> {
                        (vill.Id, newVillageFromList.Name)
                    }
                });