Example #1
0
        public void ConnectAndLogin()
        {
            try
            {
                Connect().Wait();

                var loginResult = Login().Result;
                UnregisterCallback(CallbackType.LoggedOn);
                if (loginResult != EResult.OK)
                {
                    throw new GameCoordinatorException($"Couldn't login to the steam client. Result code: {loginResult}");
                }

                myLogger.LogTrace("Successfully connected and logged in to steam account.");
                myCsgoClient = ConnectToCSGOGameCoodinator().Result;
            }
            catch (AggregateException e)
            {
                var innerExceptions = e.InnerExceptions;

                if (innerExceptions.Any(x => x is GameCoordinatorException))
                {
                    throw innerExceptions.Single(x => x is GameCoordinatorException);
                }

                if (innerExceptions.Any(x => x is TimeoutException))
                {
                    var timeoutMessage = innerExceptions.Single(x => x is TimeoutException).Message;
                    myLogger.LogError(timeoutMessage);
                    throw new GameCoordinatorException(timeoutMessage);
                }

                throw;
            }
        }
Example #2
0
        private Task <CsgoClient> ConnectToCSGOGameCoodinator()
        {
            var taskCompletionSource = TaskHelper.CreateTaskCompletionSourceWithTimeout <CsgoClient>(myWaitTimeInMilliseconds, $"Game coordinator didn't welcome us after {myWaitTimeInMilliseconds} milliseconds.");

            var csgo = new CsgoClient(mySteamClient, myCallbackManager, myLoggerFactory.CreateLogger <CsgoClient>());

            myLogger.LogTrace("Telling Steam we're playing CS:GO to connect to game coordinator.");
            csgo.Launch((callback) =>
            {
                taskCompletionSource.SetResult(csgo);
            });

            return(taskCompletionSource.Task);
        }
Example #3
0
        private Task <uint> GetRank(uint accountId, CsgoClient csgoClient)
        {
            var taskCompletionSource = TaskHelper.CreateTaskCompletionSourceWithTimeout <uint>(
                myWaitTimeInMilliseconds,
                $"Game coordinator didn't provide profile within {myWaitTimeInMilliseconds} milliseconds.");

            myLogger.LogTrace("Asking game coordinator for rank");

            if (csgoClient == null)
            {
                myLogger.LogError("CsGoClient is unexpectedly null");
                taskCompletionSource.SetException(new GameCoordinatorException("CsGoClient is unexpectedly null"));
                return(taskCompletionSource.Task);
            }

            csgoClient.PlayerProfileRequest(accountId, callback =>
            {
                if (callback.account_profiles == null || !callback.account_profiles.Any())
                {
                    taskCompletionSource.SetException(new GameCoordinatorException($"Empty response while trying to get rank for account id {accountId}"));
                }

                var profile = callback.account_profiles.First();
                if (profile.ranking != null)
                {
                    var rankId = profile.ranking.rank_id;
                    taskCompletionSource.SetResult(rankId);
                }
                else
                {
                    myLogger.LogError("Couldn't get rank for account id {accountId}", accountId);
                    taskCompletionSource.SetException(new GameCoordinatorException($"Couldn't get rank for account id {accountId}"));
                }
            });

            return(taskCompletionSource.Task);
        }
Example #4
0
        private Task <CDataGCCStrike15_v2_MatchInfo> RequestGame(GameRequest request, CsgoClient csgoClient)
        {
            var taskCompletionSource = TaskHelper.CreateTaskCompletionSourceWithTimeout <CDataGCCStrike15_v2_MatchInfo>(myWaitTimeInMilliseconds);

            myLogger.LogTrace("Asking game coordinator for match details.");
            if (csgoClient == null)
            {
                myLogger.LogError("CsGoClient is unexpectedly null");
                taskCompletionSource.SetException(new GameCoordinatorException("CsGoClient is unexpectedly null"));
                return(taskCompletionSource.Task);
            }
            csgoClient.RequestGame(request, matchList =>
            {
                if (matchList == null || matchList.matches == null)
                {
                    myLogger.LogError("Unexpected empty result from game coodinator (matchList or matchList.matches is null)");
                    taskCompletionSource.SetException(new GameCoordinatorException("Unexpected empty result from game coodinator (matchList.matches is null)"));
                    return;
                }

                if (!matchList.matches.Any())
                {
                    myLogger.LogWarning("Game coordinator doesn't have match details (probably expired).");
                    taskCompletionSource.SetException(new GameCoordinatorException("Game coordinator doesn't have match details (probably expired)."));
                    return;
                }

                var matchInfo = matchList.matches.First();
                taskCompletionSource.SetResult(matchInfo);
            });

            return(taskCompletionSource.Task);
        }