Пример #1
0
        public void SetSettings(Manager manager)
        {
            Settings      = manager.UserSettings;
            ClientManager = manager;

            int osId = OsVersions[Settings.FirmwareType.Length].Length;
            var firmwareUserAgentPart = OsUserAgentParts[osId];
            var firmwareType          = OsVersions[osId];

            Proxy = new ProxyEx
            {
                Address  = Settings.ProxyIP,
                Port     = Settings.ProxyPort,
                Username = Settings.ProxyUsername,
                Password = Settings.ProxyPassword
            };

            ClientDeviceWrapper = new DeviceWrapper
            {
                UserAgent  = $"pokemongo/1 {firmwareUserAgentPart}",
                DeviceInfo = new DeviceInfo
                {
                    DeviceId              = Settings.DeviceId,
                    DeviceBrand           = Settings.DeviceBrand,
                    DeviceModelBoot       = Settings.DeviceModelBoot,
                    HardwareModel         = Settings.HardwareModel,
                    HardwareManufacturer  = Settings.HardwareManufacturer,
                    FirmwareBrand         = Settings.FirmwareBrand,
                    FirmwareType          = Settings.FirmwareType,
                    AndroidBoardName      = Settings.AndroidBoardName,
                    AndroidBootloader     = Settings.AndroidBootloader,
                    DeviceModel           = Settings.DeviceModel,
                    DeviceModelIdentifier = Settings.DeviceModelIdentifier,
                    FirmwareFingerprint   = Settings.FirmwareFingerprint,
                    FirmwareTags          = Settings.FirmwareTags
                },
                Proxy = Proxy.AsWebProxy()
            };

            PlayerLocale = new GetPlayerMessage.Types.PlayerLocale
            {
                Country  = Settings.Country,
                Language = Settings.Language,
                Timezone = Settings.TimeZone
            };
        }
Пример #2
0
        public void SetSettings(Manager manager)
        {
            ClientManager = manager;

            Proxy = new ProxyEx
            {
                Address  = ClientManager.UserSettings.ProxyIP,
                Port     = ClientManager.UserSettings.ProxyPort,
                Username = ClientManager.UserSettings.ProxyUsername,
                Password = ClientManager.UserSettings.ProxyPassword
            };

            Dictionary <string, string> Header = new Dictionary <string, string>()
            {
                { "11.1.0", "CFNetwork/889.3 Darwin/17.2.0" },
                { "11.2.0", "CFNetwork/893.10 Darwin/17.3.0" },
                { "11.2.5", "CFNetwork/893.14.2 Darwin/17.4.0" }
            };

            ClientDeviceWrapper = new DeviceWrapper
            {
                UserAgent  = $"pokemongo/1 {Header[ClientManager.UserSettings.FirmwareType]}",
                DeviceInfo = new DeviceInfo
                {
                    DeviceId             = ClientManager.UserSettings.DeviceId,
                    DeviceBrand          = ClientManager.UserSettings.DeviceBrand,
                    DeviceModel          = ClientManager.UserSettings.DeviceModel,
                    DeviceModelBoot      = ClientManager.UserSettings.DeviceModelBoot,
                    HardwareManufacturer = ClientManager.UserSettings.HardwareManufacturer,
                    HardwareModel        = ClientManager.UserSettings.HardwareModel,
                    FirmwareBrand        = ClientManager.UserSettings.FirmwareBrand,
                    FirmwareType         = ClientManager.UserSettings.FirmwareType
                },
                Proxy = Proxy.AsWebProxy()
            };

            PlayerLocale = new GetPlayerMessage.Types.PlayerLocale
            {
                Country  = ClientManager.UserSettings.Country,
                Language = ClientManager.UserSettings.Language,
                Timezone = ClientManager.UserSettings.TimeZone
            };
        }
Пример #3
0
        public void SetSettings(Manager manager)
        {
            ClientManager = manager;

            int osId = OsVersions[ClientManager.UserSettings.DeviceInfo.FirmwareType.Length].Length;
            var firmwareUserAgentPart = OsUserAgentParts[osId];
            var firmwareType          = OsVersions[osId];

            Proxy = new ProxyEx
            {
                Address  = ClientManager.UserSettings.ProxyIP,
                Port     = ClientManager.UserSettings.ProxyPort,
                Username = ClientManager.UserSettings.ProxyUsername,
                Password = ClientManager.UserSettings.ProxyPassword
            };

            ClientDeviceWrapper = new DeviceWrapper
            {
                UserAgent  = $"pokemongo/1 {firmwareUserAgentPart}",
                DeviceInfo = new DeviceInfo
                {
                    DeviceId             = ClientManager.UserSettings.DeviceInfo.DeviceId,
                    DeviceBrand          = ClientManager.UserSettings.DeviceInfo.DeviceBrand,
                    DeviceModel          = ClientManager.UserSettings.DeviceInfo.DeviceModel,
                    DeviceModelBoot      = ClientManager.UserSettings.DeviceInfo.DeviceModelBoot,
                    HardwareManufacturer = ClientManager.UserSettings.DeviceInfo.HardwareManufacturer,
                    HardwareModel        = ClientManager.UserSettings.DeviceInfo.HardwareModel,
                    FirmwareBrand        = ClientManager.UserSettings.DeviceInfo.FirmwareBrand,
                    FirmwareType         = ClientManager.UserSettings.DeviceInfo.FirmwareType
                },
                Proxy = Proxy.AsWebProxy()
            };

            PlayerLocale = new GetPlayerMessage.Types.PlayerLocale
            {
                Country  = ClientManager.UserSettings.PlayerLocale.Country,
                Language = ClientManager.UserSettings.PlayerLocale.Language,
                Timezone = ClientManager.UserSettings.PlayerLocale.Timezone
            };
        }
Пример #4
0
        public async Task <MethodResult <bool> > DoLogin(Manager manager)
        {
            SetSettings(manager);
            // TODO: see how do this only once better.
            if (!(Configuration.Hasher is PokeHashHasher))
            {
                // By default Configuration.Hasher is LegacyHasher type  (see Configuration.cs in the pogolib source code)
                // -> So this comparation only will run once.
                if (Settings.UseOnlyOneKey)
                {
                    Configuration.Hasher       = new PokeHashHasher(Settings.AuthAPIKey);
                    Configuration.HasherUrl    = Settings.HashHost;
                    Configuration.HashEndpoint = Settings.HashEndpoint;
                }
                else
                {
                    Configuration.Hasher = new PokeHashHasher(Settings.HashKeys.ToArray());
                }

                // TODO: make this configurable. To avoid bans (may be with a checkbox in hash keys tab).
                //Configuration.IgnoreHashVersion = true;
                VersionStr = Configuration.Hasher.PokemonVersion;
                //Revise sleeping line 118
                //((PokeHashHasher)Configuration.Hasher).PokehashSleeping += OnPokehashSleeping;
            }
            // *****

            ILoginProvider loginProvider;

            switch (Settings.AuthType)
            {
            case AuthType.Google:
                loginProvider = new GoogleLoginProvider(Settings.Username, Settings.Password);
                break;

            case AuthType.Ptc:
                loginProvider = new PtcLoginProvider(Settings.Username, Settings.Password, Proxy.AsWebProxy());
                break;

            default:
                throw new ArgumentException("Login provider must be either \"google\" or \"ptc\".");
            }

            ClientSession = await GetSession(loginProvider, Settings.DefaultLatitude, Settings.DefaultLongitude, true);

            // Send initial requests and start HeartbeatDispatcher.
            // This makes sure that the initial heartbeat request finishes and the "session.Map.Cells" contains stuff.
            string msgStr = null;

            if (!await ClientSession.StartupAsync())
            {
                msgStr   = "Session couldn't start up.";
                LoggedIn = false;
            }
            else
            {
                LoggedIn = true;
                msgStr   = "Successfully logged into server.";

                ClientSession.AccessTokenUpdated         += SessionOnAccessTokenUpdated;
                ClientSession.CaptchaReceived            += SessionOnCaptchaReceived;
                ClientSession.InventoryUpdate            += SessionInventoryUpdate;
                ClientSession.MapUpdate                  += MapUpdate;
                ClientSession.CheckAwardedBadgesReceived += OnCheckAwardedBadgesReceived;
                ClientSession.HatchedEggsReceived        += OnHatchedEggsReceived;

                SaveAccessToken(ClientSession.AccessToken);
            }

            return(new MethodResult <bool>()
            {
                Success = LoggedIn,
                Message = msgStr
            });
        }
Пример #5
0
        public async Task <MethodResult <bool> > DoLogin(Manager manager)
        {
            SetSettings(manager);
            // TODO: see how do this only once better.
            if (!(Configuration.Hasher is PokeHashHasher))
            {
                // By default Configuration.Hasher is LegacyHasher type  (see Configuration.cs in the pogolib source code)
                // -> So this comparation only will run once.
                if (ClientManager.UserSettings.UseOnlyOneKey)
                {
                    Configuration.Hasher       = new PokeHashHasher(ClientManager.UserSettings.AuthAPIKey);
                    Configuration.HasherUrl    = ClientManager.UserSettings.HashHost;
                    Configuration.HashEndpoint = ClientManager.UserSettings.HashEndpoint;
                }
                else
                {
                    Configuration.Hasher = new PokeHashHasher(ClientManager.UserSettings.HashKeys.ToArray());
                }

                // TODO: make this configurable. To avoid bans (may be with a checkbox in hash keys tab).
                //Configuration.IgnoreHashVersion = true;
                VersionStr = Configuration.Hasher.PokemonVersion;
                AppVersion = Configuration.Hasher.AppVersion;
                // TODO: Revise sleeping
                // Used on Windows phone background app
                //((PokeHashHasher)Configuration.Hasher).PokehashSleeping += OnPokehashSleeping;
            }
            // *****

            ILoginProvider loginProvider;

            switch (ClientManager.UserSettings.AuthType)
            {
            case AuthType.Google:
                loginProvider = new GoogleLoginProvider(ClientManager.UserSettings.Username, ClientManager.UserSettings.Password);
                break;

            case AuthType.Ptc:
                loginProvider = new PtcLoginProvider(ClientManager.UserSettings.Username, ClientManager.UserSettings.Password, Proxy.AsWebProxy());
                break;

            default:
                throw new ArgumentException("Login provider must be either \"google\" or \"ptc\".");
            }

            ClientSession = await GetSession(loginProvider, ClientManager.UserSettings.Location.Latitude, ClientManager.UserSettings.Location.Longitude, true);

            // Send initial requests and start HeartbeatDispatcher.
            // This makes sure that the initial heartbeat request finishes and the "session.Map.Cells" contains stuff.
            var msgStr = "Session couldn't start up.";

            LoggedIn = false;
            try
            {
                ClientSession.AssetDigestUpdated         += OnAssetDisgestReceived;
                ClientSession.ItemTemplatesUpdated       += OnItemTemplatesReceived;
                ClientSession.UrlsUpdated                += OnDownloadUrlsReceived;
                ClientSession.RemoteConfigVersionUpdated += OnLocalConfigVersionReceived;
                ClientSession.AccessTokenUpdated         += SessionAccessTokenUpdated;
                ClientSession.CaptchaReceived            += SessionOnCaptchaReceived;
                ClientSession.InventoryUpdate            += SessionInventoryUpdate;
                ClientSession.MapUpdate += SessionMapUpdate;
                ClientSession.CheckAwardedBadgesReceived += OnCheckAwardedBadgesReceived;
                ClientSession.HatchedEggsReceived        += OnHatchedEggsReceived;
                ClientSession.Logger.RegisterLogOutput(LoggerFucntion);

                if (await ClientSession.StartupAsync(ClientManager.UserSettings.DownloadResources))
                {
                    LoggedIn = true;
                    msgStr   = "Successfully logged into server.";

                    ClientManager.LogCaller(new LoggerEventArgs("Succefully added all events to the client.", LoggerTypes.Debug));

                    if (ClientSession.Player.Warn)
                    {
                        ClientManager.AccountState = AccountState.Flagged;
                        ClientManager.LogCaller(new LoggerEventArgs("The account is flagged.", LoggerTypes.Warning));

                        if (ClientManager.UserSettings.StopAtMinAccountState == AccountState.Flagged)
                        {
                            //Remove proxy
                            ClientManager.RemoveProxy();
                            ClientManager.Stop();

                            msgStr = "The account is flagged.";
                        }
                    }


                    //Closes bot on captcha received need utils for solve
                    if (ClientManager.AccountState == AccountState.CaptchaReceived)
                    {
                        ClientManager.LogCaller(new LoggerEventArgs("Captcha ceceived.", LoggerTypes.Warning));

                        //Remove proxy
                        ClientManager.RemoveProxy();

                        ClientManager.Stop();

                        msgStr = "Captcha ceceived.";
                    }

                    SaveAccessToken(ClientSession.AccessToken);
                }
                else
                {
                    if (ClientSession.Player.Banned)
                    {
                        ClientManager.AccountState = AccountState.PermanentBan;
                        ClientManager.LogCaller(new LoggerEventArgs("The account is banned.", LoggerTypes.FatalError));

                        //Remove proxy
                        ClientManager.RemoveProxy();

                        ClientManager.Stop();

                        msgStr = "The account is banned.";
                    }
                    if (ClientSession.State == SessionState.TemporalBanned)
                    {
                        ClientManager.AccountState = AccountState.TemporalBan;
                        ClientManager.LogCaller(new LoggerEventArgs("The account is temporal banned.", LoggerTypes.FatalError));

                        //Remove proxy
                        ClientManager.RemoveProxy();

                        ClientManager.Stop();

                        msgStr = "The account is temporal banned.";
                    }
                }
            }
            catch (PtcOfflineException)
            {
                ClientManager.Stop();

                ClientManager.LogCaller(new LoggerEventArgs("Ptc server offline. Please try again later.", LoggerTypes.Warning));

                msgStr = "Ptc server offline.";
            }
            catch (AccountNotVerifiedException)
            {
                ClientManager.Stop();
                ClientManager.RemoveProxy();

                ClientManager.LogCaller(new LoggerEventArgs("Account not verified. Stopping ...", LoggerTypes.Warning));

                ClientManager.AccountState = Enums.AccountState.NotVerified;

                msgStr = "Account not verified.";
            }
            catch (WebException ex)
            {
                ClientManager.Stop();

                if (ex.Status == WebExceptionStatus.Timeout)
                {
                    if (String.IsNullOrEmpty(ClientManager.Proxy))
                    {
                        ClientManager.LogCaller(new LoggerEventArgs("Login request has timed out.", LoggerTypes.Warning));
                    }
                    else
                    {
                        ClientManager._proxyIssue = true;
                        ClientManager.LogCaller(new LoggerEventArgs("Login request has timed out. Possible bad proxy.", LoggerTypes.ProxyIssue));
                    }

                    msgStr = "Request has timed out.";
                }

                if (!String.IsNullOrEmpty(ClientManager.Proxy))
                {
                    if (ex.Status == WebExceptionStatus.ConnectionClosed)
                    {
                        ClientManager._proxyIssue = true;
                        ClientManager.LogCaller(new LoggerEventArgs("Potential http proxy detected. Only https proxies will work.", LoggerTypes.ProxyIssue));

                        msgStr = "Http proxy detected";
                    }
                    else if (ex.Status == WebExceptionStatus.ConnectFailure || ex.Status == WebExceptionStatus.ProtocolError || ex.Status == WebExceptionStatus.ReceiveFailure ||
                             ex.Status == WebExceptionStatus.ServerProtocolViolation)
                    {
                        ClientManager._proxyIssue = true;
                        ClientManager.LogCaller(new LoggerEventArgs("Proxy is offline", LoggerTypes.ProxyIssue));

                        msgStr = "Proxy is offline";
                    }
                }

                ClientManager._proxyIssue |= !String.IsNullOrEmpty(ClientManager.Proxy);

                ClientManager.LogCaller(new LoggerEventArgs("Failed to login due to request error", LoggerTypes.Exception, ex.InnerException));

                msgStr = "Failed to login due to request error";
            }
            catch (TaskCanceledException)
            {
                ClientManager.Stop();

                if (String.IsNullOrEmpty(ClientManager.Proxy))
                {
                    ClientManager.LogCaller(new LoggerEventArgs("Login request has timed out", LoggerTypes.Warning));
                }
                else
                {
                    ClientManager._proxyIssue = true;
                    ClientManager.LogCaller(new LoggerEventArgs("Login request has timed out. Possible bad proxy", LoggerTypes.ProxyIssue));
                }

                msgStr = "Login request has timed out";
            }
            catch (InvalidCredentialsException ex)
            {
                //Puts stopping log before other log.
                ClientManager.Stop();
                ClientManager.RemoveProxy();

                ClientManager.LogCaller(new LoggerEventArgs("Invalid credentials or account lockout. Stopping bot...", LoggerTypes.Warning, ex));

                msgStr = "Username or password incorrect";
            }
            catch (IPBannedException)
            {
                if (ClientManager.UserSettings.StopOnIPBan)
                {
                    ClientManager.Stop();
                }

                string message = String.Empty;

                if (!String.IsNullOrEmpty(ClientManager.Proxy))
                {
                    if (ClientManager.CurrentProxy != null)
                    {
                        ClientManager.ProxyHandler.MarkProxy(ClientManager.CurrentProxy, true);
                    }

                    message = "Proxy IP is banned.";
                }
                else
                {
                    message = "IP address is banned.";
                }

                ClientManager._proxyIssue = true;

                ClientManager.LogCaller(new LoggerEventArgs(message, LoggerTypes.ProxyIssue));

                msgStr = message;
            }
            catch (GoogleLoginException ex)
            {
                ClientManager.Stop();
                ClientManager.RemoveProxy();

                ClientManager.LogCaller(new LoggerEventArgs(ex.Message, LoggerTypes.Warning));

                msgStr = "Failed to login";
            }
            catch (PokeHashException phe)
            {
                ClientManager.AccountState = AccountState.HashIssues;

                msgStr = "Hash issues";
                ClientManager.LogCaller(new LoggerEventArgs(phe.Message, LoggerTypes.FatalError, phe));
            }
            catch (Exception ex)
            {
                ClientManager.Stop();
                //RemoveProxy();

                ClientManager.LogCaller(new LoggerEventArgs("Failed to login", LoggerTypes.Exception, ex));

                msgStr = "Failed to login";
            }

            return(new MethodResult <bool>()
            {
                Success = LoggedIn,
                Message = msgStr
            });
        }