public static Task <GameServer[]> LoadLobbies(string gameVariant = null, string indicator = null)
        {
            lock (LOCK)
            {
                SteamApiHelper.CancelApiCall <LobbyMatchList_t>();

                SteamMatchmaking.AddRequestLobbyListDistanceFilter(ELobbyDistanceFilter.k_ELobbyDistanceFilterWorldwide);

                if (indicator != null)
                {
                    SteamMatchmaking.AddRequestLobbyListStringFilter(LobbyDataKeys.THUNDERHAWK_INDICATOR, indicator, ELobbyComparison.k_ELobbyComparisonEqual);
                }

                if (gameVariant != null)
                {
                    SteamMatchmaking.AddRequestLobbyListStringFilter(LobbyDataKeys.GAME_VARIANT, gameVariant, ELobbyComparison.k_ELobbyComparisonEqual);
                }

                return(SteamApiHelper.HandleApiCall <GameServer[], LobbyMatchList_t>(SteamMatchmaking.RequestLobbyList(), CancellationToken.None,
                                                                                     (tcs, result, bIOFailure) =>
                {
                    if (bIOFailure)
                    {
                        return;
                    }

                    Console.WriteLine("Лобби найдено " + result.m_nLobbiesMatching);

                    tcs.SetResult(HandleGameLobbies(result));
                }));
            }
        }
Exemple #2
0
        internal static async Task <bool> SetLeaderboardValue(string leaderboardName, int value, int[] pDataValue,
                                                              int timeout = 10000,
                                                              Func <bool, bool> resultHandler = null,
                                                              Func <bool> repeatHandler       = null)
        {
            if (pDataValue?.Length > 64)
            {
                return(false);
            }

            var resultLeaderboard = await GetLeaderboard(leaderboardName);

            return(await TaskHelper.RepeatTaskForeverIfFailed(() => SteamApiHelper.HandleApiCall <bool, LeaderboardScoreUploaded_t>(SteamUserStats.UploadLeaderboardScore(resultLeaderboard.m_hSteamLeaderboard, ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodForceUpdate, value, pDataValue, pDataValue == null ? 0 : pDataValue.Length), CancellationToken.None,
                                                                                                                                    (tcs, result, bIOFailure) =>
            {
                if (result.m_bSuccess == 0 || bIOFailure)
                {
                    tcs.SetException(new Exception("Ошибка запроса OnUploadLeaderboardScore"));
                    return;
                }

                if (result.m_bScoreChanged == 1)
                {
                    tcs.SetResult(true);
                    return;
                }

                tcs.SetException(new Exception("Ошибка запроса OnUploadLeaderboardScore"));
            }), timeout, CancellationToken.None, resultHandler : resultHandler, repeatHandler : repeatHandler));
        }
Exemple #3
0
        internal static async Task <Tuple <LeaderboardEntry_t, int[]> > GetLeaderboardEntryWithDetails(string leaderboardName,
                                                                                                       int timeout = 10000,
                                                                                                       Func <Tuple <LeaderboardEntry_t, int[]>, bool> resultHandler = null,
                                                                                                       Func <bool> repeatHandler = null)
        {
            var resultLeaderboard = await GetLeaderboard(leaderboardName);

            return(await TaskHelper.RepeatTaskForeverIfFailed(() => SteamApiHelper.HandleApiCall <Tuple <LeaderboardEntry_t, int[]>, LeaderboardScoresDownloaded_t>(SteamUserStats.DownloadLeaderboardEntriesForUsers(resultLeaderboard.m_hSteamLeaderboard, new CSteamID[] { SteamUser.GetSteamID() }, 1), CancellationToken.None,
                                                                                                                                                                    (tcs, result, bIOFailure) =>
            {
                if (result.m_hSteamLeaderboard.m_SteamLeaderboard == 0 || bIOFailure)
                {
                    tcs.SetException(new Exception("Ошибка GetLeaderboardEntryWithDetails"));
                    return;
                }

                int[] pData = null;

                if (result.m_cEntryCount > 0)
                {
                    pData = new int[64];
                }

                var entry = new LeaderboardEntry_t();

                for (int index = 0; index < result.m_cEntryCount; index++)
                {
                    SteamUserStats.GetDownloadedLeaderboardEntry(result.m_hSteamLeaderboardEntries, index, out entry, pData, 64);
                }

                tcs.SetResult(Tuple.Create(entry, pData));
            }), timeout, CancellationToken.None, resultHandler : resultHandler, repeatHandler : repeatHandler));
        }
Exemple #4
0
        internal static async Task <List <Tuple <LeaderboardEntry_t, int[]> > > GetLeaderboardEntriesForUsers(string leaderboardName, CSteamID[] steamIds,
                                                                                                              int timeout = 10000,
                                                                                                              Func <List <Tuple <LeaderboardEntry_t, int[]> >, bool> resultHandler = null,
                                                                                                              Func <bool> repeatHandler = null)
        {
            var resultLeaderboard = await GetLeaderboard(leaderboardName);

            return(await TaskHelper.RepeatTaskForeverIfFailed(() => SteamApiHelper.HandleApiCall <List <Tuple <LeaderboardEntry_t, int[]> >, LeaderboardScoresDownloaded_t>(SteamUserStats.DownloadLeaderboardEntriesForUsers(resultLeaderboard.m_hSteamLeaderboard, steamIds, steamIds.Length), CancellationToken.None,
                                                                                                                                                                            (tcs, result, bIOFailure) =>
            {
                if (result.m_hSteamLeaderboard.m_SteamLeaderboard == 0 || bIOFailure)
                {
                    tcs.SetException(new Exception("Ошибка GetLeaderboardEntriesForUsers"));
                    return;
                }

                var entriesList = new List <Tuple <LeaderboardEntry_t, int[]> >();
                LeaderboardEntry_t entry;

                for (int index = 0; index < result.m_cEntryCount; index++)
                {
                    int[] pData = new int[64];

                    if (SteamUserStats.GetDownloadedLeaderboardEntry(result.m_hSteamLeaderboardEntries, index, out entry, pData, 64))
                    {
                        entriesList.Add(Tuple.Create(entry, pData));
                    }
                }

                tcs.SetResult(entriesList);
            }), timeout, CancellationToken.None, resultHandler : resultHandler, repeatHandler : repeatHandler));
        }
Exemple #5
0
        internal static async Task <LeaderboardFindResult_t> GetLeaderboard(string leaderboardName,
                                                                            int timeout = 10000,
                                                                            Func <LeaderboardFindResult_t, bool> resultHandler = null,
                                                                            Func <bool> repeatHandler = null)
        {
            return(await TaskHelper.RepeatTaskForeverIfFailed(() => SteamApiHelper.HandleApiCall <LeaderboardFindResult_t>(SteamUserStats.FindOrCreateLeaderboard(leaderboardName, ELeaderboardSortMethod.k_ELeaderboardSortMethodDescending, ELeaderboardDisplayType.k_ELeaderboardDisplayTypeNumeric), CancellationToken.None,
                                                                                                                           (tcs, result, bIOFailure) =>
            {
                if (result.m_bLeaderboardFound == 0 || bIOFailure)
                {
                    tcs.SetException(new Exception("Ошибка запроса GetLeaderboard"));
                    return;
                }

                tcs.SetResult(result);
            }), timeout, CancellationToken.None, resultHandler : resultHandler, repeatHandler : repeatHandler));
        }
        public static Task <CSteamID> CreatePublicLobby(GameServer server, CancellationToken token, string indicator)
        {
            lock (LOCK)
            {
                LeaveFromCurrentLobby();

                Console.WriteLine("Создание лобби Steam");

                return(SteamApiHelper.HandleApiCall <CSteamID, LobbyCreated_t>(SteamMatchmaking.CreateLobby(ELobbyType.k_ELobbyTypePublic, 3), token,
                                                                               (tcs, result, bIOFailure) =>
                {
                    if (bIOFailure || result.m_eResult != EResult.k_EResultOK)
                    {
                        Console.WriteLine("Ошибка во время создания лобби");
                        tcs.TrySetException(new Exception(result.m_eResult.ToErrorStringMessage()));
                        return;
                    }

                    var id = new CSteamID(result.m_ulSteamIDLobby);

                    if (token.IsCancellationRequested)
                    {
                        Console.WriteLine("Создание лобби было отменено");
                        SteamMatchmaking.LeaveLobby(id);
                        tcs.TrySetCanceled();
                        return;
                    }

                    _currentLobby = id;
                    _currentServer = server;

                    UpdateCurrentLobby(server, indicator);

                    Console.WriteLine("Лобби успешно создано. ID: " + id.m_SteamID);
                    tcs.TrySetResult(id);
                }));
            }
        }