예제 #1
0
파일: Login.cs 프로젝트: PeterDM65/POGOLib
        /// <summary>
        /// Login with a stored <see cref="AccessToken" />.
        /// </summary>
        /// <param name="loginProvider">The OAuth provider you use to authenticate.</param>
        /// <param name="accessToken">The <see cref="AccessToken"/> you want to re-use.</param>
        /// <param name="coordinate">The initial coordinate you will spawn at after logging into PokémonGo.</param>
        /// <param name="deviceWrapper">The <see cref="DeviceWrapper"/> used by the <see cref="Session"/>, keep null if you want a randomly generated <see cref="DeviceWrapper"/>.</param>
        /// <param name = "playerLocale"></param>
        /// <returns></returns>
        public static Session GetSession(ILoginProvider loginProvider, AccessToken accessToken, GeoCoordinate coordinate, DeviceWrapper deviceWrapper = null, GetPlayerMessage.Types.PlayerLocale playerLocale = null)
        {
            DeviceWrapper device = deviceWrapper ?? DeviceInfoUtil.GetRandomDevice();

            GetPlayerMessage.Types.PlayerLocale locale = playerLocale ?? new GetPlayerMessage.Types.PlayerLocale {
                Country = "US", Language = "en", Timezone = "America/New_York"
            };
            string language = locale.Language + "-" + locale.Country;

            if (accessToken.IsExpired)
            {
                accessToken = loginProvider.GetAccessToken(device.UserAgent, language).Result;
                //throw new ArgumentException($"{nameof(accessToken)} is expired.");
            }

            var session = new Session(loginProvider, accessToken, coordinate, device, locale);

            session.Logger.Debug("Authenticated from cache.");
            if (loginProvider is PtcLoginProvider)
            {
                session.Logger.Debug("Authenticated through PTC.");
            }
            else
            {
                session.Logger.Debug("Authenticated through Google.");
            }
            return(session);
        }
예제 #2
0
        /// <summary>
        /// Login with a stored <see cref="AccessToken" />.
        /// </summary>
        /// <param name="loginProvider">The OAuth provider you use to authenticate.</param>
        /// <param name="accessToken">The <see cref="AccessToken"/> you want to re-use.</param>
        /// <param name="coordinate">The initial coordinate you will spawn at after logging into UniteGo.</param>
        /// <param name="deviceWrapper">The <see cref="DeviceWrapper"/> used by the <see cref="Session"/>, keep null if you want a randomly generated <see cref="DeviceWrapper"/>.</param>
        /// <param name = "playerLocale"></param>
        /// <returns></returns>
        public static async Task <Session> GetSession(ILoginProvider loginProvider, AccessToken accessToken, GeoCoordinate coordinate, DeviceWrapper deviceWrapper = null, CreateOrUpdatePlayerMessage.Types.ClientPlayerLocale playerLocale = null)
        {
            DeviceWrapper device = deviceWrapper ?? DeviceInfoUtil.GetRandomDevice();

            CreateOrUpdatePlayerMessage.Types.ClientPlayerLocale locale = playerLocale ?? new CreateOrUpdatePlayerMessage.Types.ClientPlayerLocale {
                Country = "US", Language = "en", Timezone = "America/New_York"
            };
            string language = locale.Language + "-" + locale.Country;

            if (accessToken == null || string.IsNullOrEmpty(accessToken.Token) || accessToken.IsExpired)
            {
                accessToken = await loginProvider.GetAccessToken(device.UserAgent, language);

                if (accessToken == null || string.IsNullOrEmpty(accessToken.Token) || accessToken.IsExpired)
                {
                    throw new SessionStateException($"{nameof(accessToken)} is expired.");
                }
            }

            var session = new Session(loginProvider, accessToken, coordinate, device, locale);

            session.Logger.Debug("Authenticated from cache.");
            session.Logger.Debug("Authenticated through Google.");
            return(session);
        }
예제 #3
0
        public void RandomizeDevice()
        {
            var device = DeviceInfoUtil.GetRandomDevice();

            DeviceInfo.DeviceId             = device.DeviceInfo.DeviceId;
            DeviceInfo.DeviceBrand          = device.DeviceInfo.DeviceBrand;
            DeviceInfo.DeviceModel          = device.DeviceInfo.DeviceModel;
            DeviceInfo.DeviceModelBoot      = device.DeviceInfo.DeviceModelBoot;
            DeviceInfo.HardwareManufacturer = device.DeviceInfo.HardwareManufacturer;
            DeviceInfo.HardwareModel        = device.DeviceInfo.HardwareModel;
            DeviceInfo.FirmwareBrand        = device.DeviceInfo.FirmwareBrand;
            DeviceInfo.FirmwareType         = device.DeviceInfo.FirmwareType;
        }
예제 #4
0
        /// <summary>
        /// Login through OAuth with Google.
        /// </summary>
        /// <param name="loginProvider">The OAuth provider you use to authenticate.</param>
        /// <param name="initialLatitude">The initial latitude you will spawn at after logging into UniteGo.</param>
        /// <param name="initialLongitude">The initial longitude you will spawn at after logging into UniteGo.</param>
        /// <param name="deviceWrapper">The <see cref="DeviceWrapper"/> used by the <see cref="Session"/>, keep null if you want a randomly generated <see cref="DeviceWrapper"/>.</param>
        /// <param name = "playerLocale"></param>
        /// <returns></returns>
        public static async Task <Session> GetSession(ILoginProvider loginProvider, double initialLatitude, double initialLongitude, DeviceWrapper deviceWrapper = null, CreateOrUpdatePlayerMessage.Types.ClientPlayerLocale playerLocale = null)
        {
            DeviceWrapper device = deviceWrapper ?? DeviceInfoUtil.GetRandomDevice();

            CreateOrUpdatePlayerMessage.Types.ClientPlayerLocale locale = playerLocale ?? new CreateOrUpdatePlayerMessage.Types.ClientPlayerLocale {
                Country = "US", Language = "en", Timezone = "America/New_York"
            };
            string language = locale.Language + "-" + locale.Country;
            var    session  = new Session(loginProvider, await loginProvider.GetAccessToken(device.UserAgent, language), new GeoCoordinate(initialLatitude, initialLongitude), device, locale);

            session.Logger.Debug("Authenticated through Google.");
            return(session);
        }
예제 #5
0
        public void LoadDeviceSettings()
        {
            var device = DeviceInfoUtil.GetRandomDevice();

            DeviceId              = device.DeviceInfo.DeviceId;
            AndroidBoardName      = device.DeviceInfo.AndroidBoardName;
            AndroidBootloader     = device.DeviceInfo.AndroidBootloader;
            DeviceBrand           = device.DeviceInfo.DeviceBrand;
            DeviceModel           = device.DeviceInfo.DeviceModel;
            DeviceModelIdentifier = device.DeviceInfo.DeviceModelIdentifier;
            DeviceModelBoot       = device.DeviceInfo.DeviceModelBoot;
            HardwareManufacturer  = device.DeviceInfo.HardwareManufacturer;
            HardwareModel         = device.DeviceInfo.HardwareModel;
            FirmwareBrand         = device.DeviceInfo.FirmwareBrand;
            FirmwareTags          = device.DeviceInfo.FirmwareTags;
            FirmwareType          = device.DeviceInfo.FirmwareType;
            FirmwareFingerprint   = device.DeviceInfo.FirmwareFingerprint;
        }
예제 #6
0
파일: Login.cs 프로젝트: PeterDM65/POGOLib
        /// <summary>
        /// Login through OAuth with PTC / Google.
        /// </summary>
        /// <param name="loginProvider">The OAuth provider you use to authenticate.</param>
        /// <param name="coordinate">The initial coordinate you will spawn at after logging into PokémonGo.</param>
        /// <param name="deviceWrapper">The <see cref="DeviceWrapper"/> used by the <see cref="Session"/>, keep null if you want a randomly generated <see cref="DeviceWrapper"/>.</param>
        /// <param name = "playerLocale"></param>
        /// <returns></returns>
        public static async Task <Session> GetSession(ILoginProvider loginProvider, GeoCoordinate coordinate, DeviceWrapper deviceWrapper = null, GetPlayerMessage.Types.PlayerLocale playerLocale = null)
        {
            DeviceWrapper device = deviceWrapper ?? DeviceInfoUtil.GetRandomDevice();

            GetPlayerMessage.Types.PlayerLocale locale = playerLocale ?? new GetPlayerMessage.Types.PlayerLocale {
                Country = "US", Language = "en", Timezone = "America/New_York"
            };
            string language = locale.Language + "-" + locale.Country;
            var    session  = new Session(loginProvider, await loginProvider.GetAccessToken(device.UserAgent, language), coordinate, device, locale);

            if (loginProvider is PtcLoginProvider)
            {
                session.Logger.Debug("Authenticated through PTC.");
            }
            else
            {
                session.Logger.Debug("Authenticated through Google.");
            }
            return(session);
        }
예제 #7
0
        /// <summary>
        /// Stores data like assets and item templates. Defaults to an in-memory cache, but can be implemented as writing to disk by the platform
        /// </summary>
        // public IDataCache DataCache { get; set; } = new MemoryDataCache();
        // public Templates Templates { get; private set; }

        internal Session(ILoginProvider loginProvider, AccessToken accessToken, GeoCoordinate geoCoordinate, DeviceInfo deviceInfo = null)
        {
            if (!ValidLoginProviders.Contains(loginProvider.ProviderId))
            {
                throw new ArgumentException($"LoginProvider ID must be one of the following: {string.Join(", ", ValidLoginProviders)}");
            }

            HttpClient = new HttpClient(new HttpClientHandler
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            });
            HttpClient.DefaultRequestHeaders.UserAgent.TryParseAdd("Niantic App");
            HttpClient.DefaultRequestHeaders.ExpectContinue = false;

            DeviceInfo    = deviceInfo ?? DeviceInfoUtil.GetRandomDevice(this);
            AccessToken   = accessToken;
            LoginProvider = loginProvider;
            Player        = new Player(geoCoordinate);
            Map           = new Map(this);
            RpcClient     = new RpcClient(this);
            _heartbeat    = new HeartbeatDispatcher(this);
        }
예제 #8
0
        public void RandomizeDeviceId()
        {
            var device = DeviceInfoUtil.GetRandomDevice();

            DeviceInfo.DeviceId = device.DeviceInfo.DeviceId;
        }
예제 #9
0
        public MethodResult ImportConfig(string data)
        {
            try
            {
                List <Manager> managers = Serializer.FromJson <List <Manager> >(data) ?? new List <Manager> {
                    new Manager {
                        UserSettings = Serializer.FromJson <Settings>(data)
                    }
                };
                foreach (Manager manager in managers)
                {
                    Settings settings = manager.UserSettings;
                    settings.AccountName   = UserSettings.AccountName;
                    settings.Password      = UserSettings.Password;
                    settings.Username      = UserSettings.Username;
                    settings.AuthType      = UserSettings.AuthType;
                    settings.ProxyIP       = UserSettings.ProxyIP;
                    settings.ProxyPassword = UserSettings.ProxyPassword;
                    settings.ProxyPort     = UserSettings.ProxyPort;
                    settings.ProxyUsername = UserSettings.ProxyUsername;
                    settings.GroupName     = UserSettings.GroupName;

                    //Randomize device id
                    var device = DeviceInfoUtil.GetRandomDevice();
                    settings.DeviceId             = device.DeviceInfo.DeviceId;
                    settings.DeviceBrand          = device.DeviceInfo.DeviceBrand;
                    settings.DeviceModel          = device.DeviceInfo.DeviceModel;
                    settings.DeviceModelBoot      = device.DeviceInfo.DeviceModelBoot;
                    settings.HardwareManufacturer = device.DeviceInfo.HardwareManufacturer;
                    settings.HardwareModel        = device.DeviceInfo.HardwareModel;
                    settings.FirmwareBrand        = device.DeviceInfo.FirmwareBrand;
                    settings.FirmwareType         = device.DeviceInfo.FirmwareType;

                    UserSettings = settings;

                    if (String.IsNullOrEmpty(UserSettings.DeviceBrand))
                    {
                        UserSettings.RandomizeDevice();
                    }
                }

                /*
                 * Settings settings = Serializer.FromJson<Settings>(data);
                 * settings.AccountName = UserSettings.AccountName;
                 * settings.Password = UserSettings.Password;
                 * settings.Username = UserSettings.Username;
                 * settings.AuthType = UserSettings.AuthType;
                 * settings.ProxyIP = UserSettings.ProxyIP;
                 * settings.ProxyPassword = UserSettings.ProxyPassword;
                 * settings.ProxyPort = UserSettings.ProxyPort;
                 * settings.ProxyUsername = UserSettings.ProxyUsername;
                 * settings.GroupName = UserSettings.GroupName;
                 *
                 * //Randomize device id
                 * var device = DeviceInfoUtil.GetRandomDevice();
                 * settings.DeviceId = device.DeviceInfo.DeviceId;
                 * settings.DeviceBrand = device.DeviceInfo.DeviceBrand;
                 * settings.DeviceModel = device.DeviceInfo.DeviceModel;
                 * settings.DeviceModelBoot = device.DeviceInfo.DeviceModelBoot;
                 * settings.HardwareManufacturer = device.DeviceInfo.HardwareManufacturer;
                 * settings.HardwareModel = device.DeviceInfo.HardwareModel;
                 * settings.FirmwareBrand = device.DeviceInfo.FirmwareBrand;
                 * settings.FirmwareType = device.DeviceInfo.FirmwareType;
                 */

                LogCaller(new LoggerEventArgs("Successfully imported config file", LoggerTypes.Info));

                return(new MethodResult
                {
                    Message = "Success",
                    Success = true
                });
            }
            catch (Exception ex)
            {
                string message = String.Format("Failed to import config. Ex: {0}", ex.Message);

                LogCaller(new LoggerEventArgs(message, LoggerTypes.Exception, ex));

                return(new MethodResult
                {
                    Message = message
                });
            }
        }
예제 #10
0
        public MethodResult ImportConfig(string data)
        {
            try
            {
                Settings settings = Serializer.FromJson <Settings>(data);
                settings.AccountName   = UserSettings.AccountName;
                settings.Password      = UserSettings.Password;
                settings.Username      = UserSettings.Username;
                settings.AuthType      = UserSettings.AuthType;
                settings.ProxyIP       = UserSettings.ProxyIP;
                settings.ProxyPassword = UserSettings.ProxyPassword;
                settings.ProxyPort     = UserSettings.ProxyPort;
                settings.ProxyUsername = UserSettings.ProxyUsername;
                settings.GroupName     = UserSettings.GroupName;

                //new values added

                settings.Latitude  = settings.Latitude;
                settings.Longitude = settings.Longitude;
                settings.Altitude  = settings.Altitude;
                settings.Country   = settings.Country;
                settings.Language  = settings.Language;
                settings.TimeZone  = settings.TimeZone;
                settings.POSIX     = settings.POSIX;
                //Randomize device id
                var device = DeviceInfoUtil.GetRandomDevice();
                settings.DeviceId             = device.DeviceInfo.DeviceId;
                settings.DeviceBrand          = settings.DeviceBrand;
                settings.DeviceModel          = settings.DeviceModel;
                settings.DeviceModelBoot      = settings.DeviceModelBoot;
                settings.HardwareManufacturer = settings.HardwareManufacturer;
                settings.HardwareModel        = settings.HardwareModel;
                settings.FirmwareBrand        = settings.FirmwareBrand;
                settings.FirmwareType         = settings.FirmwareType;

                foreach (var element in settings.EvolveSettings)
                {
                    var pokemonSetting = settings.EvolveSettings.FirstOrDefault(x => x.Id == element.Id);
                    if (pokemonSetting != null)
                    {
                        pokemonSetting.Evolve = element.Evolve;
                        pokemonSetting.MinCP  = element.MinCP;
                    }
                }
                foreach (var element in settings.TransferSettings)
                {
                    var pokemonSetting = settings.TransferSettings.FirstOrDefault(x => x.Id == element.Id);
                    if (pokemonSetting != null)
                    {
                        pokemonSetting.Transfer  = element.Transfer;
                        pokemonSetting.MinCP     = element.MinCP;
                        pokemonSetting.IVPercent = element.IVPercent;
                        pokemonSetting.KeepMax   = element.KeepMax;
                        pokemonSetting.Type      = element.Type;
                    }
                }

                UserSettings = settings;

                if (String.IsNullOrEmpty(UserSettings.DeviceBrand))
                {
                    UserSettings.RandomizeDevice();
                }

                LogCaller(new LoggerEventArgs("Successfully imported config file", LoggerTypes.Info));

                return(new MethodResult
                {
                    Message = "Success",
                    Success = true
                });
            }
            catch (Exception ex)
            {
                string message = String.Format("Failed to import config. Ex: {0}", ex.Message);

                LogCaller(new LoggerEventArgs(message, LoggerTypes.Exception, ex));

                return(new MethodResult
                {
                    Message = message
                });
            }
        }