Exemplo n.º 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");
                }
        }
Exemplo n.º 2
0
        private static void BotProcConvertMoney(object botnfo)
        {
            var botinfo = (DbRow)botnfo;
            double lHowMuch = dHowMuch;

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

            try
            {
                NerZul.Core.Utils.ManagedCitizen Bot = new ManagedCitizen(
                    (string)botinfo["login"],
                    (string)botinfo["email"],
                    (string)botinfo["password"],
                    Globals.BotConfig);

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

                    int curRemains = 1;
                    for (int i = 1; i <= 20; i++)
                    {
                        try
                        {
                            ConsoleLog.WriteLine("Convert money, try " + i.ToString());

                            string response;
                            string URL;

                            int tmpRemains = GetCurrencyAmount(Bot, iCurrencySpendID, iCurrencyBuyID);

                            if (tmpRemains == -1)
                                continue;

                            curRemains = tmpRemains;

                            if (curRemains < 0.1)
                            {
                                ConsoleLog.WriteLine("Everything converted");
                                break;
                            }

                            // Открываем страницу ставок ММ, получаем первую нормальную ставку и ее параметры
                            ConsoleLog.WriteLine("Loading rates MM page...");
                            URL =
                                "http://www.erepublik.com/en/exchange/listOffers?select_page=select&buy_currency_history_id=buy_currencies=" +
                                iCurrencyBuyID.ToString() +
                                "&sell_currency_history_id=sell_currencies=" +
                                iCurrencySpendID.ToString() +
                                "&account_type=citizen-&action_path=listOffers&page=page=1";
                            //ConsoleLog.WriteLine("URL: " + URL);
                            response = Bot.Bot.CustomRequest(URL);

                            //ConsoleLog.WriteLine(response, "ConvertMoneyLog2.txt");

                            if (!response.Contains("form_amount_accept_"))
                            {
                                ConsoleLog.WriteLine("Error rates MM page");
                                continue;
                            }

                            int iOfferID = 0;
                            double dPosRate = 0;
                            double dPosAmount = 0;
                            int iCorrespondentID = 0;

                            for (int rateNum = 1; rateNum <= 10; rateNum++)
                            {

                                string sOfferId = CommonUtils.GetStringBetween(
                                    response,
                                    "\"form_amount_accept_",
                                    "\"");
                                string sPosRate = CommonUtils.GetStringBetween(
                                    response,
                                    "<span class=\"special\" id=\"exchange_value_amount_" + sOfferId + "\">",
                                    "</span>");
                                string sPosAmount = CommonUtils.GetStringBetween(
                                    response,
                                    "<span class=\"special\"  id=\"initial_amount_" + sOfferId + "\">",
                                    "</span>");
                                string sCorrespondentID = CommonUtils.GetStringBetween(
                                    response,
                                    "<a class=\"nameholder dotted\" href=\"/en/citizen/profile/",
                                    "\">");

                                ConsoleLog.WriteLine("Detected position " + rateNum.ToString() + ": OfferId=" + sOfferId + ", PosRate=" + sPosRate + ", PosAmount=" + sPosAmount + ", CorrespondentID=" + sCorrespondentID);

                                iOfferID = Convert.ToInt32(sOfferId);
                                dPosRate = Convert.ToDouble(sPosRate);
                                dPosAmount = Convert.ToDouble(sPosAmount);
                                iCorrespondentID = Convert.ToInt32(sCorrespondentID);

                                if (dPosAmount < 0.01)
                                {
                                    ConsoleLog.WriteLine("Position amount less then 0.01, getting next position");
                                    response = response.Substring(response.IndexOf("submit_form_accept") + 10);
                                }
                                else
                                    break;
                            }

                            if (dPosRate > fMaxRate)
                            {
                                ConsoleLog.WriteLine("Rate greater then max possible, waiting 10 sec...");
                                System.Threading.Thread.Sleep(10000);
                                continue;
                            }

                            //double dToBuy = Math.Min(Math.Truncate(curRemains / dPosRate), dPosAmount);
                            double dToBuy = Math.Min(curRemains / dPosRate - 0.01, dPosAmount);
                            dToBuy = Math.Truncate(dToBuy * 100) / 100;

                            ConsoleLog.WriteLine("Buy " + dToBuy.ToString() + " currency");
                            if (Bot.Bot.BuyMoney(iOfferID, dToBuy, iCurrencySpendID, iCorrespondentID, iCurrencyBuyID))
                            {
                                ConsoleLog.WriteLine("Buy currency successfull");
                            }
                            else
                            {
                                ConsoleLog.WriteLine("Buy currency fail");
                            }
                        }
                        catch (System.Exception localE)
                        {
                            ConsoleLog.WriteLine("Local convert exception: " + localE.Message);
                        }
                    }

                    Bot.GetInfoFromCommonResponse(true);
                    botinfo = Utils.TryToUpdateDbWithBasicInfo(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");
                    }
            }
            catch (System.Exception e)
            {
                ConsoleLog.WriteLine("Convert exception: " + e.Message);
            }
        }
Exemplo n.º 3
0
        private static void BotProcCollectmoneyToCountry(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)
            {
                ConsoleLog.WriteLine("Logged in - " + botinfo["login"]);
                botinfo = Utils.TryToUpdateDbWithBasicInfo(botinfo, Bot);

                int curRemains = 1;
                for (int i = 1; i <= 20; i++)
                {
                    try
                    {
                        ConsoleLog.WriteLine("Collect money to country, try " + i.ToString());

                        int tmpRemains = GetCurrencyAmount(Bot, iCurrencySpendID, 0);

                        if (tmpRemains == -1)
                            continue;

                        curRemains = tmpRemains;

                        if (curRemains < 0.1)
                        {
                            ConsoleLog.WriteLine("Everything collected");
                            break;
                        }

                        if (Bot.Bot.DonateMoneyToCountry(sDestinationCountry, curRemains - 0.01, iCurrencySpendID))
                        {
                            ConsoleLog.WriteLine("Collect money to country successfull");
                        }
                        else
                        {
                            ConsoleLog.WriteLine("Collect money to country fail");
                        }

                    }
                    catch (System.Exception e1)
                    {
                        ConsoleLog.WriteLine("Collect money to country - error" + e1.ToString());
                    }

                    Bot.GetInfoFromCommonResponse(true);
                    botinfo = Utils.TryToUpdateDbWithBasicInfo(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");
                }
        }
Exemplo n.º 4
0
        private static void BotProcBuyFromOffer(object botnfo)
        {
            var botinfo = (DbRow)botnfo;

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

            try
            {
                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)
                {
                    botinfo = Utils.TryToUpdateDbWithBasicInfo(botinfo, Bot);
                    ConsoleLog.WriteLine("Logged in - " + botinfo["login"]);

                    if (iCorrespondentID == Convert.ToInt32((uint)botinfo["citizen_id"]))
                    {
                        ConsoleLog.WriteLine("Cannot buy from the same account, exiting");
                        return;
                    }

                    for (int i = 1; i <= 10; i++)
                    {
                        try
                        {
                            double lHowMuch = dHowMuch;

                            ConsoleLog.WriteLine("BuyFromOffer money, try " + i.ToString());

                            if (lHowMuch == 0)
                            {
                                int tmpRemains = GetCurrencyAmount(Bot, iCurrencySpendID, iCurrencyBuyID);

                                if (tmpRemains == -1)
                                    continue;

                                lHowMuch = tmpRemains * 0.001 - 0.01;
                            }
                            if (lHowMuch < 0.02)
                            {
                                ConsoleLog.WriteLine("Nothing to drain");
                                break;
                            }

                            lHowMuch = Math.Truncate(lHowMuch * 100) / 100;

                            ConsoleLog.WriteLine("Buy " + lHowMuch.ToString() + " currency");

                            if (Bot.Bot.BuyMoney(iOffer, lHowMuch, iCurrencySpendID, iCorrespondentID, iCurrencyBuyID))
                            {
                                //ConsoleLog.WriteLine(botinfo["login"] + ": Gold drained. Waiting for 1 minute.");
                                ConsoleLog.WriteLine(botinfo["login"] + ": Gold drained.");
                            }
                            else
                            {
            //                                ConsoleLog.WriteLine(botinfo["login"] + ": Gold drain failed. Waiting for 1 minute.");
                                ConsoleLog.WriteLine(botinfo["login"] + ": Gold drain failed.");
                            }

                            // Если сливаем нац. валюту -- обновляем инфу
                            if (iCurrencySpendID == (int)botinfo["country"])
                                Bot.GetInfoFromCommonResponse(true);

                            //System.Threading.Thread.Sleep(60000);

                            if (dHowMuch != 0)
                                break;
                        }
                        catch (System.Exception localE)
                        {
                            ConsoleLog.WriteLine("Local convert exception: " + localE.Message);
                        }
                    }

                    // 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");
                    }
            }
            catch (System.Exception e)
            {
                ConsoleLog.WriteLine("BuyFromOffer exception: " + e.Message);
            }
        }
Exemplo n.º 5
0
        public static void WorkerDonateMoney(string[] args)
        {
            //#if PUBLIC_BUILD
            if (!Globals.IsValid())
                return;
            //#endif

            if (args.Length != 6)
            {
                ConsoleLog.WriteLine("Usage: donatemoney group login(email) password currency amount");
                return;
            }

            group = args[1];
            login = args[2];
            password = args[3];
            int.TryParse(args[4], out iCurrencySpendID);
            double.TryParse(args[5], out dHowMuch);

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

                ManagedCitizen.LoginResult loginResult = Bot.Login();
                if (loginResult == ManagedCitizen.LoginResult.Success)
                {
                    ConsoleLog.WriteLine("Logged in - " + login);

                    DbRows bots = null;
                    lock (Globals.DBLocker)
                    {
                        Globals.Database.Reset();
                        if (group.ToLower() != "all")
                            Globals.Database.Where("group", group);
                        Globals.Database.Where("banned", 0);
                        if (!String.IsNullOrEmpty(Globals.addWhere))
                            Globals.Database.Where(Globals.addWhere);
                        bots = Globals.Database.Select("bots");
                        Globals.Database.Reset();
                    }
                    if (!Globals.webCitadel.SendLogInfo(args, bots.Count))
                        return;

                    int totalBotCounter = bots.Count;
                    int processedBotCounter = 0;
                    bots = DbRows.MixList(bots);
                    DbRow botinfo;
                    Random rnd = new System.Random();

                    foreach (var botnfo in bots)
                    {
                        botinfo = (DbRow)botnfo;

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

                        try
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                ConsoleLog.WriteLine("Donate money to " + botinfo["login"] + ", try " + (i + 1).ToString());
                                if (Bot.Bot.DonateMoney(Convert.ToInt32((uint)botinfo["citizen_id"]), dHowMuch, iCurrencySpendID))
                                    break;
                            }
                            Bot.GetInfoFromCommonResponse(true);
                        }
                        catch (System.Exception e1)
                        {
                            ConsoleLog.WriteLine("Donate - error" + e1.ToString());
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                ConsoleLog.WriteLine("Worker error: " + e.Message);
            }

            ConsoleLog.WriteLine("Donate done!");
        }
Exemplo n.º 6
0
 public static DbRow TryToUpdateDbWithBasicInfo(DbRow botinfo, ManagedCitizen bot)
 {
     if(!bot.GetInfoFromCommonResponse()) return botinfo;
     return UpdateDbWithBasicInfo((uint)botinfo["id"],bot.Info);
 }