/// <summary>
 /// Provides a safe way to invoke the <see cref="HatchedEggsReceived" /> event.
 /// </summary>
 /// <param name="value"></param>
 public void RaiseHatchedEggsReceived(GetHatchedEggsResponse value) => HatchedEggsReceived?.Invoke(this, value);
Exemple #2
0
        /// <summary>
        ///     Handles the default heartbeat responses.
        /// </summary>
        /// <param name="requestEnvelope"></param>
        /// <param name="returns">The payload of the <see cref="ResponseEnvelope" />.</param>
        private void HandleDefaultResponses(RequestEnvelope requestEnvelope, IList <ByteString> returns)
        {
            var responseIndexes = new Dictionary <int, RequestType>();

            for (var i = 0; i < requestEnvelope.Requests.Count; i++)
            {
                var request = requestEnvelope.Requests[i];
                if (_defaultRequests.Contains(request.RequestType))
                {
                    responseIndexes.Add(i, request.RequestType);
                }
            }

            foreach (var responseIndex in responseIndexes)
            {
                var bytes = returns[responseIndex.Key];

                switch (responseIndex.Value)
                {
                case RequestType.GetHatchedEggs:     // Get_Hatched_Eggs
                    var hatchedEggs = GetHatchedEggsResponse.Parser.ParseFrom(bytes);
                    if (hatchedEggs.Success && hatchedEggs.PokemonId.Count > 0)
                    {
                        HatchedEggsReceived?.Invoke(this, hatchedEggs);
                    }
                    break;

                case RequestType.GetInventory:     // Get_Inventory
                    var inventory = GetInventoryResponse.Parser.ParseFrom(bytes);
                    if (inventory.Success)
                    {
                        if (inventory.InventoryDelta.NewTimestampMs >=
                            _session.Player.Inventory.LastInventoryTimestampMs)
                        {
                            _session.Player.Inventory.LastInventoryTimestampMs =
                                inventory.InventoryDelta.NewTimestampMs;
                            if (inventory.InventoryDelta != null &&
                                inventory.InventoryDelta.InventoryItems.Count > 0)
                            {
                                _session.Player.Inventory.UpdateInventoryItems(inventory.InventoryDelta);
                            }
                        }
                    }
                    break;

                case RequestType.CheckAwardedBadges:     // Check_Awarded_Badges
                    var awardedBadges = CheckAwardedBadgesResponse.Parser.ParseFrom(bytes);
                    if (awardedBadges.Success && awardedBadges.AwardedBadges.Count > 0)
                    {
                        CheckAwardedBadgesReceived?.Invoke(this, awardedBadges);
                    }
                    break;

                case RequestType.DownloadSettings:     // Download_Settings
                    var downloadSettings = DownloadSettingsResponse.Parser.ParseFrom(bytes);
                    if (string.IsNullOrEmpty(downloadSettings.Error))
                    {
                        if (downloadSettings.Settings == null)
                        {
                            continue;
                        }
                        if (_session.GlobalSettings == null || _session.GlobalSettingsHash != downloadSettings.Hash)
                        {
                            _session.GlobalSettingsHash = downloadSettings.Hash;
                            _session.GlobalSettings     = downloadSettings.Settings;
                        }
                        else
                        {
                            _session.GlobalSettings = downloadSettings.Settings;
                        }
                    }
                    else
                    {
                        Logger.Debug($"DownloadSettingsResponse.Error: '{downloadSettings.Error}'");
                    }
                    break;

                // TODO: Let the developer know about this somehow.
                case RequestType.CheckChallenge:
                    var checkChallenge = CheckChallengeResponse.Parser.ParseFrom(bytes);
                    if (checkChallenge.ShowChallenge)
                    {
                        Logger.Warn($"Received Captcha on {_session.AccessToken.Username}");
                        Logger.Warn(JsonConvert.SerializeObject(checkChallenge, Formatting.Indented));
                        CheckChallengeReceived?.Invoke(this, checkChallenge);
                    }
                    break;
                }
            }
        }
Exemple #3
0
 internal void OnHatchedEggsReceived(GetHatchedEggsResponse getHatchedEggsResponse)
 {
     HatchedEggsReceived?.Invoke(this, new GetHatchedEggsResponse(getHatchedEggsResponse));
 }