예제 #1
0
        private void UpdateRanksForPlayers(GameCoordinatorClient gameCoordinatorClient)
        {
            using var scope = myScopeFactory.CreateScope();
            var userRepository = scope.ServiceProvider.GetRequiredService <SteamUserRepository>();

            var steamUsers = userRepository.SteamUsers.AsEnumerable().ToList();

            myLogger.LogInformation($"Checking for rank changes of {steamUsers.Count} players");

            foreach (var user in steamUsers)
            {
                var steamId = user.SteamID;

                try
                {
                    var rank = gameCoordinatorClient.GetRank(steamId);
                    myLogger.LogTrace($"Got rank {rank} for steam id: {steamId}");
                    user.Rank = rank;
                    userRepository.SaveChanges();
                }
                catch (GameCoordinatorException)
                {
                    myLogger.LogWarning($"Couldn't get rank for steam id {steamId}");
                    continue;
                }

                Thread.Sleep(3000);
            }
        }
예제 #2
0
        public void ProcessNewMatches(object state)
        {
            var gameCoordinatorClient = new GameCoordinatorClient(myLoggerFactory);

            using var scope = myScopeFactory.CreateScope();
            var shareCodeRepository = scope.ServiceProvider.GetRequiredService <ShareCodeRepository>();
            var matchRepository     = scope.ServiceProvider.GetRequiredService <MatchRepository>();

            PruneShareCodeRepository(shareCodeRepository, matchRepository);

            try
            {
                if (!shareCodeRepository.HasRetryableCodes())
                {
                    myLogger.LogInformation("No retryable share codes available right now");
                    return;
                }

                gameCoordinatorClient.ConnectAndLogin();

                ProcessNewMatches(gameCoordinatorClient, shareCodeRepository, matchRepository);
                Thread.Sleep(5000);
            }
            catch (GameCoordinatorException e)
            {
                myLogger.LogWarning($"Exception while trying to process new matches: {e.Message}");
            }
            finally
            {
                matchRepository.Dispose();
                shareCodeRepository.Dispose();
                scope.Dispose();
                gameCoordinatorClient.Dispose();
            }
        }
예제 #3
0
        public void CheckForRankChanges(object state)
        {
            var gameCoordinatorClient = new GameCoordinatorClient(myLoggerFactory);

            try
            {
                gameCoordinatorClient.ConnectAndLogin();
                UpdateRanksForPlayers(gameCoordinatorClient);
            }
            catch (GameCoordinatorException e)
            {
                myLogger.LogWarning($"Exception while trying to update ranks: {e.Message}");
            }
            finally
            {
                gameCoordinatorClient.Dispose();
            }
        }
예제 #4
0
        private void ProcessNewMatches(GameCoordinatorClient gameCoordinatorClient, ShareCodeRepository shareCodeRepository, MatchRepository matchRepository)
        {
            var newSharingCodes = shareCodeRepository.GetRetryableBatch(5);

            if (!newSharingCodes.Any())
            {
                return;
            }

            myLogger.LogDebug($"Retrieved {newSharingCodes.Count} new sharing codes: {string.Join(", ", newSharingCodes.Select(x => x.Code))}");
            var newMatches     = new List <Match>();
            var demoDownloader = new DemoDownloader(myLoggerFactory.CreateLogger <DemoDownloader>());
            var demoBackuper   = new DemoBackuper(myLoggerFactory.CreateLogger <DemoBackuper>());

            foreach (var sharingCode in newSharingCodes)
            {
                var demo = CreateNewDemoForShareCode(sharingCode);

                try
                {
                    var match = gameCoordinatorClient.GetMatchInfo(demo);
                    myLogger.LogTrace($"Got match details for sharing code {sharingCode.Code}");

                    match.Demo.FilePath = demoDownloader.DownloadAndDecompressDemo(match.Demo.DownloadURL);
                    myLogger.LogTrace($"Downloaded and decompressed demo file for sharing code {sharingCode.Code}");

                    using var demoReader = new DemoReader(match, 0, 0);
                    match = demoReader.Parse();

                    myLogger.LogTrace($"Finished analyzing demo file for sharing code {sharingCode.Code}");
                    newMatches.Add(match);
                }
                catch (GameCoordinatorException)
                {
                    myLogger.LogWarning($"Couldn't get download url for sharing code {sharingCode.Code}. See previous logs/exceptions for explanation. Continuing.");
                    continue;
                }
                catch (DemoDownloaderException exception)
                {
                    myLogger.LogWarning($"Demo downloading or decompressing failed: {exception.Message} for sharing code {sharingCode.Code}.");
                    continue;
                }
                catch (DemoReaderException e)
                {
                    myLogger.LogWarning($"Analyzing demo for share code {sharingCode.Code} failed: {e.Message}");
                    demo.State = DemoState.ParseFailure;
                    continue;
                }
                finally
                {
                    TryBackupDemo(demo, demoBackuper);
                }
            }

            myLogger.LogDebug($"Downloaded and analyzed {newMatches.Count} new matches (from {newSharingCodes.Count} new sharing codes).");
            myLogger.LogTrace($"Saving {newMatches.Count} new matches to repository.");

            var successfullySavedMatches = matchRepository.AddMatchesAndSave(newMatches);

            shareCodeRepository.RemoveCodes(successfullySavedMatches.Select(x => x.Demo.ShareCode));
        }