Inheritance: AbstractDomainObject
        void UpdateSummoner(Summoner summoner, AllPublicSummonerDataDTO publicSummonerData, AggregatedStats[] aggregatedStats, PlayerLifeTimeStats lifeTimeStatistics, RecentGames recentGames, DbConnection connection)
        {
            int accountId = summoner.AccountId;

            lock (ActiveAccountIds)
            {
                // Avoid concurrent updates of the same account, it's asking for trouble and is redundant anyways
                // We might obtain outdated results in one query but that's a minor issue in comparison to corrupted database results
                if (ActiveAccountIds.Contains(accountId))
                    return;

                ActiveAccountIds.Add(accountId);
            }

            // Use a transaction because we're going to insert a fair amount of data
            using (var transaction = connection.BeginTransaction())
            {
                UpdateSummonerFields(summoner, connection, true);
                UpdateRunes(summoner, publicSummonerData, connection);

                UpdateSummonerRatings(summoner, lifeTimeStatistics, connection);
                // A season value of zero indicates the current season only
                for (int season = 0; season < aggregatedStats.Length; season++)
                    UpdateSummonerRankedStatistics(summoner, season, aggregatedStats[season], connection);
                UpdateSummonerGames(summoner, recentGames, connection);

                transaction.Commit();
            }

            lock (ActiveAccountIds)
                ActiveAccountIds.Remove(accountId);
        }
Exemple #2
0
 void GetRecentGameData(RecentGames recentGameData)
 {
     RecentGameData = recentGameData;
     ProcessReply();
 }
 void UpdateSummonerGames(SummonerDescription summoner, RecentGames recentGameData)
 {
     var recentGames = recentGameData.gameStatistics;
     recentGames.Sort(CompareGames);
     foreach (var game in recentGames)
         UpdateSummonerGame(summoner, game);
     string query =
         "with rating as " +
         "( " +
         "with source as " +
         "(select game_result.game_time, team_player.rating, team_player.rating_change from game_result, team_player where game_result.id = team_player.game_id and game_result.result_map = cast('summoners_rift' as map_type) and game_result.game_mode = cast('normal' as game_mode_type) and team_player.summoner_id = :summoner_id) " +
         "select current_rating.current_rating, top_rating.top_rating from " +
         "(select (rating + rating_change) as current_rating from source order by game_time desc limit 1) " +
         "as current_rating, " +
         "(select max(rating + rating_change) as top_rating from source) " +
         "as top_rating " +
         ") " +
         "update summoner_rating set current_rating = (select current_rating from rating), top_rating = (select top_rating from rating) where summoner_id = :summoner_id and rating_map = cast('summoners_rift' as map_type) and game_mode = cast('normal' as game_mode_type);",
         myquery =
     @"UPDATE summoner_rating
     SET current_rating = (SELECT current_rating FROM rating_current WHERE summoner_id = ?summoner_id),
       top_rating = (SELECT top_rating FROM rating_top WHERE summoner_id = ?summoner_id)
     WHERE summoner_id = ?summoner_id
     AND rating_map = 'summoners_rift' AND game_mode = 'normal';";
     SQLCommand update = Database is MySql.Data.MySqlClient.MySqlConnection ? Command(myquery) : Command(query);
     update.Set("summoner_id", summoner.Id);
     update.Execute();
 }
 void UpdateSummonerGames(Summoner summoner, RecentGames recentGameData, DbConnection connection, bool lookUpFurther = true)
 {
     var recentGames = recentGameData.gameStatistics;
     recentGames.Sort(CompareGames);
     foreach (var game in recentGames)
         UpdateSummonerGame(summoner, game, connection, lookUpFurther);
 }
Exemple #5
0
        public void endRecentGamesResponder(RecentGames rGames)
        {
            int ndx, sNdx, i;
            bool tempExists;
            PlayerGameStats pgStats;
            List<long> fellowSummonerIds = new List<long>();

            if (rGames == null)
                return;

            // Sort recent games by newest game first
            rGames.gameStatistics.Sort(CompareGames);

            for (ndx = 0; ndx < rGames.gameStatistics.Count; ndx++)
            {
                pgStats = rGames.gameStatistics.ElementAt(ndx);

                /* Check if game is current game we are updating */
                if (pgStats.gameId == reportingSummoner.lastGameId)
                {
                    if (db.gameStatsIncomplete(pgStats.gameId))
                    {
                        endSummonerStats.Add(new EndSummonerGameStats(pgStats, rGames.userId));

                        // Set GLOBAL variable for endGame total players
                        endTotalPlayers = 1 + pgStats.fellowPlayers.Count;

                        for (sNdx = 0; sNdx < pgStats.fellowPlayers.Count; sNdx++)
                        {
                            fellowSummonerIds.Add(pgStats.fellowPlayers.ElementAt(sNdx).summonerId);
                        }

                        // Async call to get all names by summoner IDs, continues in responder function
                        pvpnet.RPC.GetSummonerNamesAsync(fellowSummonerIds, new FluorineFx.Net.Responder<List<string>>(endSummonerNamesResponder));
                    }
                    else
                    {
                        // This is a boolean that specifies if other thread updated End game
                        gameUpdatedElsewhere = true;
                        stopWaitHandle.Set();
                    }
                    break;
                }
            }

            for (i = (ndx + 1); i < rGames.gameStatistics.Count; i++)
            {
                pgStats = rGames.gameStatistics.ElementAt(i);
                tempExists = db.gameStatsExists(pgStats.gameId);

                /* Check if it should add an old game */
                if (!tempExists)
                {
                    ConsoleOut("\t\tOld Game Added, id = " + pgStats.gameId);
                    db.addOldGame(pgStats, rGames.userId);
                }
                /* Check if it should skip rest of loop because older games should already be in database */
                else if (tempExists)
                {
                    break;
                }
            }
        }
Exemple #6
0
        public void endFellowRecentGamesResponder(RecentGames rGames)
        {
            int ndx;
            // Sort recent games by newest game first
            if (rGames == null)
                return;

            rGames.gameStatistics.Sort(CompareGames);

            for (ndx = 0; ndx < rGames.gameStatistics.Count; ndx++)
            {
                if (rGames.gameStatistics.ElementAt(ndx).gameId == reportingSummoner.lastGameId)
                {
                    endSummonerStats.Add(new EndSummonerGameStats(rGames.gameStatistics.ElementAt(ndx), rGames.userId));
                    break;
                }
            }

            if (ndx >= rGames.gameStatistics.Count)
            {
                return;
            }

            //ConsoleOut("\tGameUpdate: EndRecentGames");

            if (endLifeStats.Count >= endTotalPlayers && endSummonerStats.Count >= endTotalPlayers)
            {
                stopWaitHandle.Set();
            }
        }