Exemple #1
0
        /// <summary>
        ///     Starts a Google session for the given user
        /// </summary>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <returns>true if login worked</returns>
        public static async Task <bool> DoGoogleLogin(string email, string password)
        {
            _clientSettings = new Settings
            {
                GoogleUsername = email,
                GooglePassword = password,
                AuthType       = AuthType.Google
            };

            _client = new Client(_clientSettings, null, DeviceInfos.Current);
            var apiFailureStrategy = new ApiFailureStrategy(_client);

            _client.ApiFailure = apiFailureStrategy;
            // Register to AccessTokenChanged
            apiFailureStrategy.OnAccessTokenUpdated += (s, e) => SaveAccessToken();
            // Get Google token
            await _client.Login.DoLogin();

            // Update current token even if it's null and clear the token for the other identity provide
            SaveAccessToken();
            // Update other data if login worked
            if (_client.AccessToken == null)
            {
                return(false);
            }
            SettingsService.Instance.LastLoginService = AuthType.Google;
            SettingsService.Instance.UserCredentials  =
                new PasswordCredential(nameof(SettingsService.Instance.UserCredentials), email, password);
            // Return true if login worked, meaning that we have a token
            return(true);
        }
Exemple #2
0
        public void Reset(ISettings settings, ILogicSettings logicSettings)
        {
            ApiFailureStrategy _apiStrategy = new ApiFailureStrategy(this);

            Client = new Client(Settings, _apiStrategy);
            // ferox wants us to set this manually
            Inventory  = new Inventory(Client, logicSettings);
            Navigation = new Navigation(Client);
        }
Exemple #3
0
 public Session(ISettings settings, ILogicSettings logicSettings)
 {
     Settings           = settings;
     LogicSettings      = logicSettings;
     ApiFailureStrategy = new ApiFailureStrategy(this);
     EventDispatcher    = new EventDispatcher();
     Translation        = Common.Translation.Load(logicSettings);
     Reset(settings, LogicSettings);
 }
Exemple #4
0
        public void UpdateSessionConfiguration(IClientSettings settings, ILogicSettings logicSettings)
        {
            ApiFailureStrategy apiFailureStrategy = new ApiFailureStrategy(this);

            Client = new Client(ClientSettings, apiFailureStrategy);

            Inventory  = new Inventory(Client, logicSettings);
            Navigation = new Navigation(Client, logicSettings);
        }
Exemple #5
0
 public Session(ISettings settings, ILogicSettings logicSettings)
 {
     Settings           = settings;
     LogicSettings      = logicSettings;
     ApiFailureStrategy = new ApiFailureStrategy(this);
     EventDispatcher    = new EventDispatcher();
     Translation        = Common.Translation.Load(logicSettings);
     Reset(settings, LogicSettings);
     Runtime = new RuntimeSettings();
     State   = BotState.Idle;
     Stats   = new Statistics();
 }
Exemple #6
0
 public Context(PokeRoadieSettings settings)
 {
     Settings           = settings;
     Directories        = new Directories();
     Utility            = new Utility(this);
     Session            = new Session(this);
     ApiFailureStrategy = new ApiFailureStrategy(this);
     Client             = new PokeRoadieClient(this);
     Inventory          = new PokeRoadieInventory(this);
     Statistics         = new Statistics(this);
     Navigation         = new Navigation(this);
     Logic = new PokeRoadieLogic(this);
 }
Exemple #7
0
 public Session(ISettings settings, ILogicSettings logicSettings)
 {
     Settings           = settings;
     LogicSettings      = logicSettings;
     ApiFailureStrategy = new ApiFailureStrategy(this);
     EventDispatcher    = new EventDispatcher();
     Translation        = Common.Translation.Load(logicSettings);
     Reset(settings, LogicSettings);
     Runtime     = new RuntimeSettings();
     State       = BotState.Idle;
     Stats       = new Statistics();
     EggWalker   = new EggWalker(this);
     ActionQueue = new ObservableCollection <ManualAction>();
 }
Exemple #8
0
        /// <summary>
        ///     Sets things up if we didn't come from the login page
        /// </summary>
        /// <returns></returns>
        public static async Task InitializeClient()
        {
            DataCache.Init();

            var credentials = SettingsService.Instance.UserCredentials;

            credentials.RetrievePassword();
            _clientSettings = new Settings
            {
                AuthType       = SettingsService.Instance.LastLoginService,
                PtcUsername    = SettingsService.Instance.LastLoginService == AuthType.Ptc ? credentials.UserName : null,
                PtcPassword    = SettingsService.Instance.LastLoginService == AuthType.Ptc ? credentials.Password : null,
                GoogleUsername = SettingsService.Instance.LastLoginService == AuthType.Google ? credentials.UserName : null,
                GooglePassword = SettingsService.Instance.LastLoginService == AuthType.Google ? credentials.Password : null,
            };

            _client = new Client(_clientSettings, null, DeviceInfos.Current)
            {
                AccessToken = LoadAccessToken()
            };
            var apiFailureStrategy = new ApiFailureStrategy(_client);

            _client.ApiFailure = apiFailureStrategy;
            // Register to AccessTokenChanged
            apiFailureStrategy.OnAccessTokenUpdated       += (s, e) => SaveAccessToken();
            apiFailureStrategy.OnFailureToggleUpdateTimer += ToggleUpdateTimer;
            try
            {
                await _client.Login.DoLogin();
            }
            catch (Exception e)
            {
                if (e is PokemonGo.RocketAPI.Exceptions.AccessTokenExpiredException)
                {
                    Debug.WriteLine("AccessTokenExpired Exception caught");
                    _client.AccessToken.Expire();
                    await _client.Login.DoLogin();
                }
                else
                {
                    await new MessageDialog(e.Message).ShowAsyncQueue();
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Creates and initializes API client
        /// </summary>
        private static void CreateClient()
        {
            //Unregister old handlers
            if (_client != null)
            {
                _client.CheckChallengeReceived -= _client_CheckChallengeReceived;
            }

            _client = new Client(_clientSettings, null, DeviceInfos.Current);

            //Register EventHandlers
            _client.CheckChallengeReceived += _client_CheckChallengeReceived;

            var apiFailureStrategy = new ApiFailureStrategy(_client);

            _client.ApiFailure = apiFailureStrategy;
            // Register to AccessTokenChanged
            apiFailureStrategy.OnAccessTokenUpdated       += (s, e) => SaveAccessToken();
            apiFailureStrategy.OnFailureToggleUpdateTimer += ToggleUpdateTimer;
        }
 public PokeRoadieClient(PokeRoadieSettings settings, ApiFailureStrategy apiFailureStrategy)
     : base(settings, apiFailureStrategy)
 {
 }