Beispiel #1
0
        /// <summary>
        /// Query and cache player data
        /// </summary>
        /// <param name="player">Player to load</param>
        /// <param name="control">Control to update</param>
        void LoadPlayer(PlayerParticipant player, PlayerControl control)
        {
            PlayerCache existing;
            var         ply = new PlayerCache();

            try
            {
                lock (PlayersCache)
                {
                    //Clear the cache every 50000 players to prevent crashing afk lobbies.
                    if (PlayersCache.Count > 50000)
                    {
                        PlayersCache.Clear();
                    }

                    //Does the player already exist in the cache?
                    if ((existing = PlayersCache.Find(p => p.Player != null && p.Player.Id == player.SummonerId)) == null)
                    {
                        PlayersCache.Add(ply);
                    }
                }

                //If another thread is loading the player data, lets wait for it to finish and use its data.
                if (existing != null)
                {
                    existing.LoadWait.WaitOne();
                    LoadPlayerUIFinish(existing, control);
                    return;
                }


                using (SimpleLogTimer.Start("Player query"))
                {
                    //var entry = Recorder.GetPlayer(player.SummonerId);
                    //ply.Player = entry ?? ply.Player;
                }

                using (SimpleLogTimer.Start("Stats query"))
                {
                    var cmd      = new PlayerCommands(Connection);
                    var summoner = cmd.GetPlayerByName(player.Name);
                    if (summoner != null)
                    {
                        ply.Summoner        = summoner;
                        ply.CurrentChampion = Convert.ToInt32(player.QueueRating);
                        ply.RankedStats     = cmd.GetAggregatedStatList(summoner.AccountId, "CLASSIC", "CURRENT");
                        ply.LeagueInfo      = cmd.GetLeagueInfo(summoner.SummonerId);

                        /*
                         * if ((Settings.LoadWhatData & LoadDataEnum.Stats) != 0)
                         *                          ply.Stats = cmd.RetrievePlayerStatsByAccountId(summoner.AccountId);
                         * if ((Settings.LoadWhatData & LoadDataEnum.TopChamps) != 0)
                         *  ply.RecentChamps = cmd.RetrieveTopPlayedChampions(summoner.AccountId, "CLASSIC");
                         * if ((Settings.LoadWhatData & LoadDataEnum.RecentGames) != 0)
                         *  ply.Games = cmd.GetRecentGames(summoner.AccountId);
                         * */
                    }
                    else
                    {
                        StaticLogger.Debug(string.Format("Player {0} not found", player.Name));
                        ply.LoadWait.Set();
                        return;
                    }
                }

                using (SimpleLogTimer.Start("Seen query"))
                {
                    if (SelfSummoner != null && SelfSummoner.SummonerId != ply.Summoner.SummonerId && ply.Games != null)
                    {
                        ply.SeenCount = ply.Games.GameStatistics.Count(pgs => pgs.FellowPlayers.Any(fp => fp.SummonerId == SelfSummoner.SummonerId));
                    }
                }

                ply.LoadWait.Set();
                LoadPlayerUIFinish(ply, control);
            }
            catch (Exception ex)
            {
                ply.LoadWait.Set();                 //
                StaticLogger.Warning(ex);
            }
        }