Exemplo n.º 1
0
        public async Task <bool> ChangeProxy()
        {
            if (_proxyIssue && CurrentProxy != null)
            {
                ProxyHandler.IncreaseFailCounter(CurrentProxy);
            }

            RemoveProxy();

            //Get new
            //This call will increment the proxy
            CurrentProxy = ProxyHandler.GetRandomProxy();
            _runningStopwatch.Stop();

            if (CurrentProxy == null)
            {
                LogCaller(new LoggerEventArgs("No available proxies left. Will recheck every 5 seconds", LoggerTypes.Warning));
            }

            while (CurrentProxy == null && IsRunning)
            {
                await Task.Delay(5000);

                CurrentProxy = ProxyHandler.GetRandomProxy();
            }

            //Program is stopping
            if (CurrentProxy == null)
            {
                return(false);
            }

            _runningStopwatch.Start();
            UserSettings.ProxyIP       = CurrentProxy.Address;
            UserSettings.ProxyPort     = CurrentProxy.Port;
            UserSettings.ProxyUsername = CurrentProxy.Username;
            UserSettings.ProxyPassword = CurrentProxy.Password;


            LogCaller(new LoggerEventArgs(String.Format("Changing proxy to {0}", CurrentProxy.ToString()), LoggerTypes.Info));

            return(true);
        }
Exemplo n.º 2
0
        private async void RunningThread()
        {
            int failedWaitTime = 5000;
            int currentFails   = 0;

            //Reset account state
            AccountState = Enums.AccountState.Good;

            while (IsRunning)
            {
                if (CheckTime())
                {
                    continue;
                }

                WaitPaused();

                if ((_proxyIssue || CurrentProxy == null) && UserSettings.AutoRotateProxies)
                {
                    if (_proxyIssue && CurrentProxy != null)
                    {
                        ProxyHandler.IncreaseFailCounter(CurrentProxy);
                    }

                    //Decrease usage
                    if (CurrentProxy != null)
                    {
                        ProxyHandler.ProxyUsed(CurrentProxy, false);
                    }

                    //Get new
                    //This call will increment the proxy
                    CurrentProxy = ProxyHandler.GetRandomProxy();

                    if (CurrentProxy == null)
                    {
                        LogCaller(new LoggerEventArgs("No available proxies left. Will recheck every 5 seconds", LoggerTypes.Warning));
                    }

                    while (CurrentProxy == null && IsRunning)
                    {
                        await Task.Delay(5000);

                        CurrentProxy = ProxyHandler.GetRandomProxy();
                    }

                    //Program is stopping
                    if (CurrentProxy == null)
                    {
                        continue;
                    }

                    UserSettings.ProxyIP       = CurrentProxy.Address;
                    UserSettings.ProxyPort     = CurrentProxy.Port;
                    UserSettings.ProxyUsername = CurrentProxy.Username;
                    UserSettings.ProxyPassword = CurrentProxy.Password;


                    LogCaller(new LoggerEventArgs(String.Format("Changing proxy to {0}", CurrentProxy.ToString()), LoggerTypes.Info));

                    //Have to restart to set proxy
                    Restart();

                    _proxyIssue = false;

                    continue;
                }


                StartingUp = true;

                if (currentFails >= UserSettings.MaxFailBeforeReset)
                {
                    currentFails = 0;
                    _client.Logout();
                }

                if (_failedInventoryReponses >= _failedInventoryUntilBan)
                {
                    AccountState = AccountState.PermAccountBan;

                    LogCaller(new LoggerEventArgs("Potential account ban", LoggerTypes.Warning));

                    Stop();

                    continue;
                }

                ++currentFails;

                MethodResult result = new MethodResult();

                try
                {
                    #region Startup

                    if (!_client.LoggedIn)
                    {
                        //Login
                        result = await Login();

                        if (!result.Success)
                        {
                            //A failed login should require longer wait
                            await Task.Delay(failedWaitTime * 3);

                            continue;
                        }
                    }

                    LogCaller(new LoggerEventArgs("Sending echo test ...", LoggerTypes.Debug));

                    result = await SendEcho();

                    if (!result.Success)
                    {
                        //LogCaller(new LoggerEventArgs("Echo failed. Logging out before retry.", LoggerTypes.Debug));

                        _client.Logout();

                        await Task.Delay(failedWaitTime);

                        continue;
                    }

                    await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));

                    //Get pokemon settings
                    if (PokeSettings == null)
                    {
                        LogCaller(new LoggerEventArgs("Grabbing pokemon settings ...", LoggerTypes.Debug));

                        result = await GetItemTemplates();
                    }


                    await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));

                    //Get profile data
                    LogCaller(new LoggerEventArgs("Grabbing player data ...", LoggerTypes.Debug));
                    result = await RepeatAction(GetProfile, 2);

                    await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));

                    //Update inventory
                    LogCaller(new LoggerEventArgs("Updating inventory items ...", LoggerTypes.Debug));

                    result = await RepeatAction <List <InventoryItem> >(UpdateInventory, 1);

                    await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));

                    if (!result.Success)
                    {
                        if (result.Message == "Failed to get inventory.")
                        {
                            ++_failedInventoryReponses;
                        }

                        await Task.Delay(failedWaitTime);

                        continue;
                    }

                    _failedInventoryReponses = 0;

                    if (WaitPaused())
                    {
                        continue;
                    }

                    //End startup phase
                    StartingUp = false;

                    //Prevent changing back to running state
                    if (State != BotState.Stopping)
                    {
                        State = BotState.Running;
                    }
                    else
                    {
                        continue;
                    }

                    //Update location
                    if (_firstRun)
                    {
                        LogCaller(new LoggerEventArgs("Setting default location ...", LoggerTypes.Debug));

                        result = await RepeatAction(() => UpdateLocation(new GeoCoordinate(UserSettings.DefaultLatitude, UserSettings.DefaultLongitude)), 2);

                        if (!result.Success)
                        {
                            await Task.Delay(failedWaitTime);

                            continue;
                        }
                    }

                    await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));

                    #endregion

                    #region PokeStopTask

                    //Get pokestops
                    LogCaller(new LoggerEventArgs("Grabbing pokestops...", LoggerTypes.Debug));

                    MethodResult <List <FortData> > pokestops = await RepeatAction <List <FortData> >(GetPokeStops, 2);

                    if (!pokestops.Success)
                    {
                        await Task.Delay(failedWaitTime);

                        continue;
                    }

                    int pokeStopNumber = 1;
                    int totalStops     = pokestops.Data.Count;

                    if (totalStops == 0)
                    {
                        _proxyIssue           = false;
                        _potentialPokeStopBan = false;

                        LogCaller(new LoggerEventArgs(String.Format("{0}. Failure {1}/{2}", pokestops.Message, currentFails, UserSettings.MaxFailBeforeReset), LoggerTypes.Warning));

                        await Task.Delay(failedWaitTime);

                        continue;
                    }

                    GeoCoordinate defaultLocation = new GeoCoordinate(UserSettings.DefaultLatitude, UserSettings.DefaultLongitude);

                    List <FortData> pokestopsToFarm = pokestops.Data;

                    int currentFailedStops = 0;

                    while (pokestopsToFarm.Any())
                    {
                        if (!IsRunning || currentFailedStops >= UserSettings.MaxFailBeforeReset)
                        {
                            break;
                        }

                        if (CheckTime())
                        {
                            continue;
                        }

                        WaitPaused();

                        pokestopsToFarm = pokestopsToFarm.OrderBy(x => CalculateDistanceInMeters(_client.CurrentLatitude, _client.CurrentLongitude, x.Latitude, x.Longitude)).ToList();

                        FortData pokestop = pokestopsToFarm[0];
                        pokestopsToFarm.RemoveAt(0);

                        GeoCoordinate currentLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                        GeoCoordinate fortLocation    = new GeoCoordinate(pokestop.Latitude, pokestop.Longitude);

                        double distance = CalculateDistanceInMeters(currentLocation, fortLocation);

                        LogCaller(new LoggerEventArgs(String.Format("Going to stop {0} of {1}. Distance {2:0.00}m", pokeStopNumber, totalStops, distance), LoggerTypes.Info));

                        //Go to stops
                        MethodResult walkResult = await RepeatAction(() => GoToLocation(new GeoCoordinate(pokestop.Latitude, pokestop.Longitude)), 1);

                        if (!walkResult.Success)
                        {
                            LogCaller(new LoggerEventArgs("Too many failed walking attempts. Restarting to fix ...", LoggerTypes.Warning));

                            break;
                        }

                        await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));

                        //Search
                        double filledInventorySpace = FilledInventorySpace();

                        if (filledInventorySpace < UserSettings.SearchFortBelowPercent)
                        {
                            MethodResult searchResult = await SearchPokestop(pokestop);

                            //OutOfRange will show up as a success
                            if (searchResult.Success)
                            {
                                currentFailedStops = 0;
                            }
                            else
                            {
                                ++currentFailedStops;
                            }
                        }
                        else
                        {
                            LogCaller(new LoggerEventArgs(String.Format("Skipping fort. Currently at {0:0.00}% filled", filledInventorySpace), LoggerTypes.Info));
                        }

                        //Stop bot instantly
                        if (!IsRunning)
                        {
                            continue;
                        }

                        int remainingBalls = RemainingPokeballs();

                        if (remainingBalls > 0)
                        {
                            //Catch nearby pokemon
                            MethodResult nearbyPokemonResponse = await RepeatAction(CatchNeabyPokemon, 1);

                            await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));

                            //Get nearby lured pokemon
                            MethodResult luredPokemonResponse = await RepeatAction(() => CatchLuredPokemon(pokestop), 1);

                            await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));
                        }

                        //Check sniping
                        if (Stats.Level >= UserSettings.SnipeAfterLevel)
                        {
                            if (remainingBalls >= UserSettings.MinBallsToSnipe)
                            {
                                if (UserSettings.SnipePokemon && IsRunning && pokeStopNumber >= UserSettings.SnipeAfterPokestops && pokeStopNumber % UserSettings.SnipeAfterPokestops == 0)
                                {
                                    await SnipeAllPokemon();
                                }
                            }
                            else
                            {
                                LogCaller(new LoggerEventArgs(String.Format("Not enough pokeballs to snipe. Need {0} have {1}", UserSettings.MinBallsToSnipe, remainingBalls), LoggerTypes.Info));
                            }

                            await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));
                        }

                        //Clean inventory, evolve, transfer, etc on first and every 10 stops
                        if (IsRunning && ((pokeStopNumber > 4 && pokeStopNumber % 10 == 0) || pokeStopNumber == 1))
                        {
                            MethodResult echoResult = await SendEcho();

                            //Echo failed, restart
                            if (!echoResult.Success)
                            {
                                break;
                            }

                            await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));

                            bool secondInventoryUpdate = false;

                            await UpdateInventory();

                            await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));

                            if (UserSettings.RecycleItems)
                            {
                                secondInventoryUpdate = true;

                                await RecycleFilteredItems();

                                await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));
                            }

                            if (UserSettings.EvolvePokemon)
                            {
                                MethodResult evolveResult = await EvolveFilteredPokemon();

                                if (evolveResult.Success)
                                {
                                    await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));

                                    await UpdateInventory();

                                    await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));
                                }
                            }

                            if (UserSettings.TransferPokemon)
                            {
                                MethodResult transferResult = await TransferFilteredPokemon();

                                if (transferResult.Success)
                                {
                                    secondInventoryUpdate = true;

                                    await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));
                                }
                            }

                            if (UserSettings.IncubateEggs)
                            {
                                MethodResult incubateResult = await IncubateEggs();

                                if (incubateResult.Success)
                                {
                                    secondInventoryUpdate = true;

                                    await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));
                                }
                            }

                            if (secondInventoryUpdate)
                            {
                                await UpdateInventory();
                            }
                        }

                        ++pokeStopNumber;

                        await Task.Delay(CalculateDelay(UserSettings.GeneralDelay, UserSettings.GeneralDelayRandom));

                        if (UserSettings.MaxLevel > 0 && Level >= UserSettings.MaxLevel)
                        {
                            LogCaller(new LoggerEventArgs(String.Format("Max level of {0} reached.", UserSettings.MaxLevel), LoggerTypes.Info));

                            Stop();
                        }

                        if (_potentialPokeStopBan)
                        {
                            //Break out of pokestop loop to test for ip ban
                            break;
                        }
                    }

                    #endregion
                }
                catch (Exception ex)
                {
                    LogCaller(new LoggerEventArgs("Unknown exception occured. Restarting ...", LoggerTypes.Exception, ex));
                }

                currentFails = 0;
                _firstRun    = false;
            }

            State = BotState.Stopped;
            _client.Logout();
            LogCaller(new LoggerEventArgs(String.Format("Bot fully stopped at {0}", DateTime.Now), LoggerTypes.Info));

            if (_autoRestart)
            {
                _wasAutoRestarted = true;
                Start();
            }
        }
Exemplo n.º 3
0
 public void Stop()
 {
     CurrentProxy.Dispose();
     Listener = null;
     "Stopped subscription to Rabbit Queue '{0}'".ToInfo <IBus>();
 }
Exemplo n.º 4
0
 public void Dispose()
 {
     CurrentProxy.Dispose();
     Listener     = null;
     ProxyFactory = null;
 }