Esempio n. 1
0
        private void ButtonLogin_Click(object sender, EventArgs e)
        {
            username = textBoxName.Text;
            password = textBoxPassword.Text;
            server   = textBoxServer.Text;
            var trainTroopType    = comboBoxTroop.SelectedIndex;
            var farmlistTroopType = comboBoxTroop.SelectedIndex;

            if (username == string.Empty)
            {
                Bot.Log("Enter a valid username.", Color.Black);
            }
            else if (password == string.Empty)
            {
                Bot.Log("Enter a valid password.", Color.Black);
            }
            else if (Uri.CheckHostName(server) != UriHostNameType.Dns)
            {
                Bot.Log("Enter a valid server URL.", Color.Black);
            }
            else
            {
                travian          = new Travian(username, password, server, trainTroopType, farmlistTroopType);
                travian.mainForm = this;
                Bot.Log("Loading page...", Color.Black);
                int loginAttempts = 1;

                threadLogin?.Abort();

                threadLogin = new Thread(() =>
                {
                    while (!_login)
                    {
                        travian.GetToken();
                        var token = Info.LoginId;
                        if (token.Length != 10)
                        {
                            Bot.Log("Token error, retrying in 2 seconds... Attempts: " + loginAttempts, Color.Black);
                            Thread.Sleep(2000);
                            loginAttempts++;
                            continue;
                        }
                        else
                        {
                            Bot.Log("Logging in...", Color.Black);
                            _login = travian.Login(token);
                        }
                    }

                    Bot.Log("Logged in!", Color.Black);
                });
                threadLogin.Start();
                SaveUserSettings();
            }
        }
Esempio n. 2
0
        private void ButtonStart_Click(object sender, EventArgs e)
        {
            StartBrowserProxy();

            username           = textBoxName.Text;
            password           = textBoxPassword.Text;
            server             = textBoxServer.Text;
            _trainTroopType    = comboBoxTroop.SelectedIndex;
            _farmlistTroopType = comboBoxFarmlist.SelectedIndex;
            _interval          = Convert.ToInt32(textBoxTrainInterval.Text);
            travian            = new Travian(username, password, server, _trainTroopType, _farmlistTroopType);
            travian.mainForm   = this;

            villageInfo = new VillageInfo();
            travian.CollectData(ref villageInfo);
            var barracksId = villageInfo.Buildings.Barracks.Id;

            if (buttonStart.Text == "Stop")
            {
                Bot.Log("Bot stopped", Color.Black);
                worker.Abort();
                buttonStart.Text = "Start";
                if (timer != null)
                {
                    if (timer.IsAlive)
                    {
                        timer.Abort();
                    }
                }

                textBoxName.Enabled          = true;
                textBoxPassword.Enabled      = true;
                textBoxServer.Enabled        = true;
                comboBoxFarmlist.Enabled     = true;
                comboBoxTroop.Enabled        = true;
                buttonLogin.Enabled          = true;
                checkBoxBuyAnimals.Enabled   = true;
                checkBoxBuyResources.Enabled = true;
                checkBoxExcludeList.Enabled  = true;
                checkBoxNpc.Enabled          = true;
            }
            else
            {
                if (_login)
                {
                    buttonStart.Text             = "Stop";
                    textBoxName.Enabled          = false;
                    textBoxPassword.Enabled      = false;
                    textBoxServer.Enabled        = false;
                    comboBoxFarmlist.Enabled     = false;
                    comboBoxTroop.Enabled        = false;
                    buttonLogin.Enabled          = false;
                    checkBoxBuyAnimals.Enabled   = false;
                    checkBoxBuyResources.Enabled = false;
                    checkBoxExcludeList.Enabled  = false;
                    checkBoxNpc.Enabled          = false;

                    if (checkBoxExcludeList.Checked)
                    {
                        travian.ExcludeLastList = true;
                        Bot.Log("Exclude raid list is active. The last raid list will not send to raid.", Color.Black);
                    }
                    if (checkBoxBuyAnimals.Checked)
                    {
                        travian.BuyAnimalsState = true;
                        Bot.Log("- Animal purchasing is active.", Color.Green);
                    }
                    if (checkBoxBuyResources.Checked)
                    {
                        travian.BuyResourcesState = true;
                        Bot.Log("- Resources purchasing is active.", Color.Green);
                    }
                    if (checkBoxNpc.Checked)
                    {
                        travian.DoNpc = true;
                        Bot.Log("- NPC is active.", Color.Green);
                    }

                    timer = new Thread(() =>
                    {
                        while (true)
                        {
                            Bot.Log("Starting to buy goodies in 5 seconds.", Color.Black);
                            Thread.Sleep(5000);
                            travian.BuyGoodies();
                            travian.TrainTroops(barracksId);
                            Thread.Sleep(355000);
                        }
                    });
                    timer.Start();

                    worker = new Thread(() =>
                    {
                        int raidCount = 0;

                        while (buttonStart.Text == "Stop")
                        {
                            if (raidCount < _interval)
                            {
                                if (travian.StartRaid())
                                {
                                    Bot.Log("Sending raid...", Color.Black);
                                }
                                else
                                {
                                    Bot.Log("Error: Raid couldn't started.", Color.Black);
                                }
                                raidCount++;
                                Thread.Sleep(10000);
                            }
                            else
                            {
                                Bot.Log("Training troops", Color.Black);
                                if (travian.TrainTroops(barracksId))
                                {
                                    Bot.Log("Raid next.", Color.Black);
                                }
                                raidCount = 0;
                            }
                        }
                    });
                    worker.Start();
                }
                else
                {
                    Bot.Log("First login!", Color.DarkRed);
                }
            }
            if (threadLogin != null)
            {
                threadLogin.Abort();
            }
        }