Ejemplo n.º 1
0
    private void Awake()
    {
        if (instance != null)
        {
            Debug.LogWarning("More than one directory.");
            return;
        }

        instance = this;
    }
    private void Start()
    {
        _ui                     = UserInterface.instance;
        _directory              = PlayerDirectory.instance;
        _camera                 = GetComponentInChildren <Camera>().transform;
        _originalCameraPos      = new Vector3(0f, 0.7f, 0f);
        _hasRequiredInteractive = false;
        _inCombinationMode      = false;
        _isInspecting           = false;
        _firstInteractable      = true;

        SafeLockControl.Solved += CombinationSolved;
        ClockControl.Solved    += CombinationSolved;
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Consume players and list matches per player.
        /// </summary>
        private async Task <IEnumerable <MatchSummary> > ConsumePlayerAsync(PlayerEntry player)
        {
            // <TEST> download limiting
            long count = Interlocked.Read(ref testSynchronizer.Count);

            if (count >= testSynchronizer.Limit)
            {
                return(Enumerable.Empty <MatchSummary>());
            }
            // </TEST>

            // Get player id
            long playerId = long.Parse(player.Player.PlayerOrTeamId);

            // Get player data
            PlayerData playerData = PlayerDirectory.GetPlayerData(player.Player);

            // Retry a number of times to handle server-side rate limit errors
            int retriesLeft = 3;

            // Get player match list, looping through pages until reaching a match we've seen for this player, or a match from an old patch
            // TODO: use the new match history api
            int startId = 0;
            int endId   = MaxMatchesPerQuery - 1;

            List <MatchSummary> matches = new List <MatchSummary>();
            bool oldMatches             = false;

            while (!oldMatches)
            {
                try
                {
                    var newmatches = await api.GetMatchHistoryAsync(player.Region, playerId,
                                                                    rankedQueues : queryQueues,
                                                                    beginIndex : startId,
                                                                    endIndex : endId);

                    // Prepare for next query
                    startId += MaxMatchesPerQuery;
                    endId   += MaxMatchesPerQuery;

                    // Filter out matches that aren't on the current patch
                    newmatches = newmatches.Where(m => StaticDataStore.Version.IsSamePatch(new RiotVersion(m.MatchVersion))).ToList();

                    // Check if we've seen any of these matches yet (if so, that's our marker to stop querying)
                    int foundMatchId = newmatches.FindIndex(m => m.MatchId == playerData.LatestMatchId);
                    if (foundMatchId != -1)
                    {
                        newmatches = newmatches.GetRange(0, foundMatchId).ToList();
                        oldMatches = true;
                    }

                    matches.AddRange(newmatches);

                    // If we filtered any matches out, we're past matches on the current patch
                    if (newmatches.Count < MaxMatchesPerQuery)
                    {
                        oldMatches = true;
                    }
                }
                catch (RiotSharpException ex)
                {
                    if (ex.IsRetryable() && retriesLeft > 0)
                    {
                        // NOTE: This server-side rate handler is a bit rough, but I don't want to change RiotSharp too much unless I get more time.
                        //       Ideally, the original error code would be attached to the RiotSharp exception so the handler could decide how to deal
                        //       with it based on the status code. Unfortunately, it's not at this time - I'll clean it up in RiotSharp if I have time.
                        //
                        //       The error seems to be server-side, as there's no retry-after headers of any sort attached to the response. It should
                        //       be safe to just retry after waiting a bit. I'm also retrying 500-series errors, since they seem to be recoverable.
                        --retriesLeft;

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("Server error getting matches for player {0} ({1} retries left)", player.Player.PlayerOrTeamName, retriesLeft);
                        Console.ResetColor();

                        // Wait half a second
                        Thread.Sleep(500);
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Error getting matches for player {0}: {1}", player.Player.PlayerOrTeamName, ex.Message);
                        Console.ResetColor();
                        oldMatches = true;
                    }
                }
            }

            // Store last seen match for this player
            if (matches.Count > 0)
            {
                playerData.LatestMatchId = matches[0].MatchId;
                PlayerDirectory.SetPlayerData(player.Player, playerData);
            }

            return(matches);
        }