Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var cmd      = new PlayerCommands(Connection);
            var summoner = cmd.GetPlayerByName(SelfSummoner.Username);

            if (summoner != null)
            {
                cmd.RetrievePlayerStatsByAccountId(summoner.AccountId);
                cmd.RetrieveTopPlayedChampions(summoner.AccountId, "CLASSIC");
                cmd.GetRecentGames(summoner.AccountId);
            }


            //var cmd = new PlayerCommands(Connection);
            //var obj = cmd.InvokeServiceUnknown(
            //    "gameService",
            //    "quitGame"
            //);

            //if (Champions == null)
            //    return;

            //var sorted = Champions.OrderBy(c => ChampNames.Get(c.ChampionId)).ToList();

            //var cmd = new PlayerCommands(Connection);
            //for (int i = 0; i < sorted.Count; i++)
            //{
            //    if (sorted[i].FreeToPlay || sorted[i].Owned)
            //    {
            //        var id = sorted[i].ChampionId;
            //        //ThreadPool.QueueUserWorkItem(delegate
            //        //{
            //        var obj = cmd.InvokeServiceUnknown(
            //            "gameService",
            //            "selectChampion",
            //            id
            //        );
            //        //});
            //    }
            //}
        }
Example #2
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 1000 players to prevent crashing afk lobbies.
                    if (PlayersCache.Count > 1000)
                    {
                        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.Stats        = cmd.RetrievePlayerStatsByAccountId(summoner.AccountId);
                        ply.RecentChamps = cmd.RetrieveTopPlayedChampions(summoner.AccountId, "CLASSIC");
                        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);
            }
        }