Example #1
0
        static void BotProc(object botnfo)
        {
            var botinfo = (DbRow)botnfo;

            Globals.processedBotCounter++;
            ConsoleLog.WriteLine(
                "Processing bot " +
                Globals.processedBotCounter.ToString() + "/" +
                Globals.totalBotCounter.ToString() + ": " +
                (string)botinfo["login"]);

            //инициализируем класс
            NerZul.Core.Utils.ManagedCitizen Bot = new NerZul.Core.Utils.ManagedCitizen(
                (string)botinfo["login"],
                (string)botinfo["email"],
                (string)botinfo["password"],
                Globals.BotConfig);

            ManagedCitizen.LoginResult loginResult;
            loginResult = Bot.Login();

            if (loginResult == ManagedCitizen.LoginResult.Success)
            {
                ConsoleLog.WriteLine("Logged in - " + botinfo["login"]);
                botinfo = Utils.TryToUpdateDbWithBasicInfo(botinfo, Bot);

                // Смотрим состояние инвентаря
                if (Bot.GetStorageInfo(true))
                {
                    botinfo = Utils.TryToUpdateDbWithStorageInfo(botinfo, Bot);
                }

                if ((iLeftFood == 0) ||
                    (Bot.storageInfo.foodQty >= iLeftFood))
                {
                    for (int i = 1; i <= 3; i++)
                    {
                        if (cyclicFight)
                            ConsoleLog.WriteLine("Cyclic fight, try " + i.ToString());

                        int iter = 0;
                        int retryCount = 0;
                        float wellness = (float)botinfo["wellness"];
                        float oldWellness = 0;

                        do
                        {
                            System.Threading.Thread.Sleep(1500);
                            iter++;

                            if (iter > 10) break;

                            if (wellness > iLeftHP)
                            {
                                if (cyclicFight)
                                    ConsoleLog.WriteLine("Cyclic fight, iteration " + iter.ToString() + ". Fight!");

                                Bot.Bot.FightInBattle(iBattle, ((bBuyWeapon) ? 1 : 0), (int)botinfo["country"], iLeftHP, iCountry, doNotChange, iShotLimit);
                            }

                            Bot.GetInfoFromCommonResponse(true);
                            botinfo = Utils.TryToUpdateDbWithBasicInfo(botinfo, Bot);

                            if (cyclicFight)
                            {
                                ConsoleLog.WriteLine("Cyclic fight, iteration " + iter.ToString() + ". Feed!");
                                Bot.Feed(!Globals.BotConfig.useTOR, (int)botinfo["country"], Globals.defaultFoodQ, 97, !bBuyFood, true);
                            }

                            Bot.GetInfoFromCommonResponse(true);
                            botinfo = Utils.TryToUpdateDbWithBasicInfo(botinfo, Bot);

                            wellness = (float)botinfo["wellness"];

                            ConsoleLog.WriteLine("Fight finished. Wellness left: " + wellness.ToString());

                            if (oldWellness == wellness)
                            {
                                retryCount++;
                            }
                            else
                            {
                                oldWellness = wellness;
                                retryCount = 0;
                            }

                            if ((!cyclicFight) ||
                                (retryCount >= 3) ||
                                ((iExpLimit != 0) && ((int)botinfo["experience"]) >= iExpLimit))
                                break;
                        }
                        while (wellness > iLeftHP);

                        if ((!cyclicFight) ||
                           ((iExpLimit != 0) && ((int)botinfo["experience"]) >= iExpLimit))
                            break;
                    }
                }

                // Смотрим состояние инвентаря
                if (Bot.GetStorageInfo(true))
                {
                    botinfo = Utils.TryToUpdateDbWithStorageInfo(botinfo, Bot);
                }
            }
            else
                if ((loginResult == ManagedCitizen.LoginResult.Banned) ||
                    (loginResult == ManagedCitizen.LoginResult.Banned2))
                {
                    botinfo["banned"] = (loginResult == ManagedCitizen.LoginResult.Banned) ? 1 : 2;
                    Utils.UpdateDbWithCustomBotInfo(botinfo, "banned");
                    //botinfo = Utils.TryToUpdateDbWithBasicInfo(botinfo, Bot);
                }
                //else
                //    if (Bot.Bot.GetLastResponse().Contains("infringement"))
                //    {
                //        botinfo["banned"] = 1;
                //        Utils.UpdateDbWithCustomBotInfo(botinfo, "banned");
                //        //botinfo = Utils.TryToUpdateDbWithBasicInfo(botinfo, Bot);
                //        ConsoleLog.WriteLine(botinfo["login"].ToString() + ": Banned");
                //    }
                else
                {
                    //ConsoleLog.WriteLine(Bot.Bot.GetLastResponse(), "LoginLog.txt");
                    ConsoleLog.WriteLine(botinfo["login"].ToString() + ": Possibly dead, see LoginLog.txt");
                }
        }
Example #2
0
        static void BotProc(object botnfo)
        {
            var botinfo = (DbRow)botnfo;
            Random rnd = new System.Random();

            Globals.processedBotCounter++;
            ConsoleLog.WriteLine(
                "Processing bot " +
                Globals.processedBotCounter.ToString() + "/" +
                Globals.totalBotCounter.ToString() + ": " +
                (string)botinfo["login"]);

            //инициализируем класс
            NerZul.Core.Utils.ManagedCitizen Bot = new NerZul.Core.Utils.ManagedCitizen(
                (string)botinfo["login"],
                (string)botinfo["email"],
                (string)botinfo["password"],
                Globals.BotConfig);
            //Пытаемся залогиниться через проксики

            ManagedCitizen.LoginResult loginResult = Bot.Login();
            if (loginResult == ManagedCitizen.LoginResult.Success)
            {
                try
                {
                    Bot.Bot.m_Client.Timeouts = 0;

                    ConsoleLog.WriteLine("Logged in - " + botinfo["login"]);
                    botinfo = Utils.TryToUpdateDbWithBasicInfo(botinfo, Bot);

                    #region Активируем, если в базе нет отметки что активен. Посещаем диснейленд в первый раз
                    try
                    {
                        if (((int)botinfo["activated"]) == 0)
                        {
                            if (!Globals.BotConfig.useTOR) System.Threading.Thread.Sleep(rnd.Next(2000, 5000));
                            Bot.Bot.Activate();
                            botinfo["activated"] = 1;
                            Utils.UpdateDbWithCustomBotInfo(botinfo, "activated");
                            botinfo = Utils.TryToUpdateDbWithBasicInfo(botinfo, Bot);

                            ConsoleLog.WriteLine("Visit 'Land' for the first time");
                            Bot.Bot.VisitLand((uint)botinfo["citizen_id"]);

                        }
                    }
                    catch (System.Exception e)
                    {
                        ConsoleLog.WriteLine("Error activation: " + e.Message);
                    }

                    if (Bot.Bot.m_Client.Timeouts >= Globals.timeoutsLimit)
                        throw new Exception("Timeout limit reached.");
                    #endregion

                    // Смотрим состояние инвентаря
                    if (Bot.GetStorageInfo(true))
                    {
                        botinfo = Utils.TryToUpdateDbWithStorageInfo(botinfo, Bot);
                    }

                    #region Light mode. Light так light. НИЧЕГО не делаем, только собираем инфу и выходим
                    if (mode == "light")
                    {
                        if (!Globals.BotConfig.useTOR) System.Threading.Thread.Sleep(rnd.Next(1000, 2000));
                        Daily.BotLight(botinfo, Bot, rnd);
                        return;
                    }
                    #endregion

                    #region Покупаем и едим еду 1
                    if (doFeed == 1)
                        Bot.Feed(!Globals.BotConfig.useTOR, (int)botinfo["country"], Globals.defaultFoodQ, 99, true, true);

                    if (Bot.Bot.m_Client.Timeouts >= Globals.timeoutsLimit)
                        throw new Exception("Timeout limit reached.");
                    #endregion

                    #region Работаем, тренькаемся, читаем алерты, читаем статьи, смотрим TreasureMap
                    //, учимся, отдыхаем
                    List<int> lst = new List<int>();
                    lst.Add(1);
                    lst.Add(2);
                    lst.Add(3);
                    lst.Add(4);
                    lst = CommonUtils.MixList(lst);
                    for (List<int>.Enumerator e = lst.GetEnumerator(); e.MoveNext(); )
                    {
                        if (!Globals.BotConfig.useTOR) System.Threading.Thread.Sleep(rnd.Next(1000, 2000));
                        switch (e.Current)
                        {
                            case 1: // Работа
                                for (int i = 1; i <= 3; i++)
                                {
                                    try
                                    {
                                        Daily.BotWork(botinfo, Bot, rnd);
                                        break;
                                    }
                                    catch (System.Exception e1)
                                    {
                                        ConsoleLog.WriteLine("Bot work error: " + e1.Message);
                                    }
                                }
                                break;
                            case 2: // Тренька
                                for (int i = 1; i <= 3; i++)
                                {
                                    try
                                    {
                                        Daily.BotTrain(botinfo, Bot, rnd);
                                        break;
                                    }
                                    catch (System.Exception e1)
                                    {
                                        ConsoleLog.WriteLine("Bot train error: " + e1.Message);
                                    }
                                }
                                break;
                            case 3: // Аллерты
                                try
                                {
                                    Bot.Bot.LookAlerts();
                                }
                                catch (System.Exception e1)
                                {
                                    ConsoleLog.WriteLine("Bot look alerts error: " + e1.Message);
                                }
                                break;
                            case 4: // Статьи
                                try
                                {
                                    Bot.Bot.ReadRandomTopArticle();
                                    //if (!Globals.BotConfig.useTOR) System.Threading.Thread.Sleep(rnd.Next(15000, 20000));
                                    Bot.Bot.ReadRandomTopArticle();
                                }
                                catch (System.Exception e1)
                                {
                                    ConsoleLog.WriteLine("Bot read article error: " + e1.Message);
                                }
                                break;
                        }

                        if (Bot.Bot.m_Client.Timeouts >= Globals.timeoutsLimit)
                            throw new Exception("Timeout limit reached.");
                    }
                    #endregion

                    #region Получаем дневной reward
                    if (!Globals.BotConfig.useTOR) System.Threading.Thread.Sleep(rnd.Next(1000, 2000));
                    for (int i = 1; i <= 3; i++)
                    {
                        try
                        {
                            Bot.Bot.DailyReward();
                            break;
                        }
                        catch (System.Exception e)
                        {
                            ConsoleLog.WriteLine("Bot get daily reward error: " + e.Message);
                        }

                        if (Bot.Bot.m_Client.Timeouts >= Globals.timeoutsLimit)
                            throw new Exception("Timeout limit reached.");
                    }
                    #endregion

                    #region Покупаем и едим еду 2
                    if (doFeed == 2)
                        Bot.Feed(!Globals.BotConfig.useTOR, (int)botinfo["country"], Globals.defaultFoodQ, 99, true, true);

                    if (Bot.Bot.m_Client.Timeouts >= Globals.timeoutsLimit)
                        throw new Exception("Timeout limit reached.");
                    #endregion

                    // Смотрим состояние инвентаря
                    if (Bot.GetStorageInfo(true))
                    {
                        botinfo = Utils.TryToUpdateDbWithStorageInfo(botinfo, Bot);
                    }

                    #region Грузим аватару, если не загружена
                    try
                    {
                        //АВАТАРКА
                        if (/*((int)botinfo["experience"] >= 61) && */(!Bot.Info.HasAvatar))
                        //if (false)
                        {
                            ConsoleLog.WriteLine(botinfo["login"] + ": Upload avatar");
                            if (!Globals.BotConfig.useTOR) System.Threading.Thread.Sleep(rnd.Next(1000, 2000));
                            string Path = System.IO.Path.Combine(Globals.DataDir, "avatars");
                            Path = System.IO.Path.Combine(Path, Globals.Avatars.GetRandomString());
                            Bot.Bot.UploadAvatar(System.IO.File.ReadAllBytes(Path), Path);
                            botinfo = Utils.TryToUpdateDbWithBasicInfo(botinfo, Bot);
                        }
                    }
                    catch (System.Exception e)
                    {
                        ConsoleLog.WriteLine("Error uploading avatar: " + e.Message);
                    }
                    #endregion
                }
                finally
                {
                    // Апдейтим статус бота в базе
                    botinfo = Utils.TryToUpdateDbWithCurrentInfo(botinfo, Bot);
                }

                // Logout
                Bot.Bot.Logout();
            }
            else
                if ((loginResult == ManagedCitizen.LoginResult.Banned) ||
                    (loginResult == ManagedCitizen.LoginResult.Banned2))
                {
                    botinfo["banned"] = (loginResult == ManagedCitizen.LoginResult.Banned)?1:2;
                    Utils.UpdateDbWithCustomBotInfo(botinfo, "banned");
                }
                else
                {
                    //ConsoleLog.WriteLine(Bot.Bot.GetLastResponse(), "LoginLog.txt");
                    ConsoleLog.WriteLine(botinfo["login"].ToString() + ": Possibly dead, see LoginLog.txt");
                }
            ConsoleLog.WriteLine(botinfo["login"].ToString() + ": daily proc finished");
        }