public static Task <GameServer[]> LoadLobbies()
        {
            lock (LOCK)
            {
                SteamApiHelper.CancelApiCall <LobbyMatchList_t>();

                SteamMatchmaking.AddRequestLobbyListDistanceFilter(ELobbyDistanceFilter.k_ELobbyDistanceFilterWorldwide);
                SteamMatchmaking.AddRequestLobbyListStringFilter(LobbyDataKeys.STEAM_SPY_INDICATOR, SteamConstants.INDICATOR, ELobbyComparison.k_ELobbyComparisonEqual);
                SteamMatchmaking.AddRequestLobbyListStringFilter(LobbyDataKeys.GAME_VARIANT, SteamConstants.GameVariant, ELobbyComparison.k_ELobbyComparisonEqual);

                /* SteamMatchmaking.AddRequestLobbyListStringFilter(LobbyDataKeys.LOBBY_TYPE, SteamConstants.LOBBY_TYPE_DEFAULT, ELobbyComparison.k_ELobbyComparisonEqual);
                 * SteamMatchmaking.AddRequestLobbyListStringFilter(LobbyDataKeys.GAME_VERSION, GameConstants.VERSION, ELobbyComparison.k_ELobbyComparisonEqual);
                 * SteamMatchmaking.AddRequestLobbyListStringFilter(LobbyDataKeys.IS_IN_GAME, false.ToString(), ELobbyComparison.k_ELobbyComparisonEqual);
                 * SteamMatchmaking.AddRequestLobbyListStringFilter(LobbyDataKeys.IS_AUTOMATCH, false.ToString(), ELobbyComparison.k_ELobbyComparisonEqual);
                 * SteamMatchmaking.AddRequestLobbyListStringFilter(LobbyDataKeys.IS_DUEL, false.ToString(), 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));
                }));
            }
        }
示例#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));
        }
示例#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));
        }
示例#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));
        }
示例#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)
        {
            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);

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