public async Task <IList <Lobby> > SearchLobbies(Action <ILobbySearchBuilder> builder = null)
        {
            LobbySearchBuilder queryBuilder;

            if (_nameFilter.Item2 != "")
            {
                queryBuilder = new LobbySearchBuilder(SteamMatchmaking.LobbyList.WithKeyValue(_nameFilter.Item1, _nameFilter.Item2));
            }
            else
            {
                queryBuilder = new LobbySearchBuilder(SteamMatchmaking.LobbyList);
            }

            builder?.Invoke(queryBuilder);
            var result = await queryBuilder.RunAsync();

            if (result == null)
            {
                return(new Lobby[0]);
            }

            var lobbies = new SteamLobby[result.Length];

            for (var i = 0; i < lobbies.Length; i++)
            {
                lobbies[i] = new SteamLobby(result[i], this);
            }

            return(lobbies);
        }
Пример #2
0
        public async Task <Lobby> CreateLobby(LobbyCreateParams createParams)
        {
            var result = await SteamMatchmaking.CreateLobbyAsync((int)createParams.Capacity);

            var steamLobby = result ?? throw new Exception("Failed to create the lobby");

            if (createParams.Type == LobbyType.Public)
            {
                steamLobby.SetPublic();
            }
            if (createParams.Metadata != null)
            {
                foreach (var kvp in createParams.Metadata)
                {
                    if (kvp.Key == null || kvp.Value == null)
                    {
                        continue;
                    }
                    steamLobby.SetData(kvp.Key, kvp.Value.ToString());
                }
            }
            var lobby = new SteamLobby(steamLobby, this, true);

            _connectedLobbies.Add(steamLobby.Id, lobby);
            return(lobby);
        }
        public async Task <Lobby> CreateLobby(LobbyCreateParams createParams)
        {
            ELobbyType type;

            switch (createParams.Type)
            {
            case LobbyType.Private: type = ELobbyType.k_ELobbyTypePrivate; break;

            default:
            case LobbyType.Public: type = ELobbyType.k_ELobbyTypePublic; break;
            }
            var size       = createParams.Capacity;
            var lobbyEnter = SteamUtility.WaitFor <LobbyEnter_t>();
            var result     = await SteamMatchmaking.CreateLobby(type, (int)size).ToTask <LobbyCreated_t>();

            SteamUtility.ThrowIfError(result.m_eResult);
            await lobbyEnter;
            var   lobbyId = new CSteamID(lobbyEnter.Result.m_ulSteamIDLobby);
            var   lobby   = new SteamLobby(lobbyId, this);

            if (createParams.Metadata != null)
            {
                foreach (var kvp in createParams.Metadata)
                {
                    if (kvp.Key == null || kvp.Value == null)
                    {
                        continue;
                    }
                    SteamMatchmaking.SetLobbyData(lobbyId, kvp.Key, kvp.Value.ToString());
                }
            }
            _connectedLobbies.Add(lobbyId, lobby);
            return(lobby);
        }
Пример #4
0
 internal void LeaveLobby(SteamLobby lobby)
 {
     Assert.IsNotNull(lobby);
     if (!_connectedLobbies.ContainsKey(lobby.Id))
     {
         throw new InvalidOperationException("[Steam] Not connected to lobby.");
     }
     _connectedLobbies.Remove(lobby.Id);
     lobby._lobby.Leave();
     lobby.Dispose();
 }
        internal async Task JoinLobby(SteamLobby lobby)
        {
            Assert.IsNotNull(lobby);
            var id = new CSteamID(lobby.Id);

            if (_connectedLobbies.ContainsKey(id))
            {
                throw new InvalidOperationException("[Steam] Already connected to lobby.");
            }
            await SteamMatchmaking.JoinLobby(id).ToTask <LobbyEnter_t>();

            _connectedLobbies.Add(id, lobby);
            lobby.Members.Refresh();
        }
Пример #6
0
        internal async Task JoinLobby(SteamLobby lobby)
        {
            Assert.IsNotNull(lobby);
            if (_connectedLobbies.ContainsKey(lobby.Id))
            {
                throw new InvalidOperationException("[Steam] Already connected to lobby.");
            }
            var result = await SteamMatchmaking.JoinLobbyAsync(lobby.Id);

            var steamLobby = result ?? throw new Exception($"Failed to connect to lobby: {lobby.Id}");

            lobby._lobby = steamLobby;
            _connectedLobbies.Add(lobby.Id, lobby);
            lobby.Members.Refresh();
        }
Пример #7
0
        public async Task <IList <Lobby> > SearchLobbies(Action <ILobbySearchBuilder> builder = null)
        {
            var queryBuilder = new LobbySearchBuilder(SteamMatchmaking.LobbyList);

            builder?.Invoke(queryBuilder);
            var result = await queryBuilder.RunAsync();

            if (result == null)
            {
                return(new Lobby[0]);
            }
            var lobbies = new Lobby[result.Length];

            for (var i = 0; i < lobbies.Length; i++)
            {
                lobbies[i] = new SteamLobby(result[i], this);
            }
            return(lobbies);
        }
        public async Task <IList <Lobby> > SearchLobbies(Action <ILobbySearchBuilder> builder = null)
        {
            var queryBuilder = new LobbySearchBuilder();

            builder?.Invoke(queryBuilder);
            var list = await SteamMatchmaking.RequestLobbyList().ToTask <LobbyMatchList_t>();

            var results = new Lobby[list.m_nLobbiesMatching];

            for (var i = 0; i < list.m_nLobbiesMatching; i++)
            {
                var lobbyId = SteamMatchmaking.GetLobbyByIndex(i);
                if (!lobbyId.IsValid())
                {
                    continue;
                }
                results[i] = new SteamLobby(lobbyId, this);
            }
            return(results);
        }