Files
sbox-public/engine/Sandbox.Engine/Platform/Steam/SteamMatchmaking.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

51 lines
1.4 KiB
C#

using Steamworks.Data;
namespace Steamworks;
/// <summary>
/// Functions for clients to access matchmaking services, favorites, and to operate on game lobbies
/// </summary>
internal class SteamMatchmaking : SteamClientClass<SteamMatchmaking>
{
internal static ISteamMatchmaking Internal => Interface as ISteamMatchmaking;
internal override void InitializeInterface( bool server )
{
SetInterface( server, new ISteamMatchmaking( server ) );
}
/// <summary>
/// Maximum number of characters a lobby metadata key can be
/// </summary>
internal static int MaxLobbyKeyLength => 255;
internal static LobbyQuery LobbyList => new LobbyQuery();
/// <summary>
/// Creates a new invisible lobby. Call lobby.SetPublic to take it online.
/// </summary>
internal static async Task<Lobby?> CreateLobbyAsync( int maxMembers = 100 )
{
Assert.NotNull( Internal );
var lobby = await Internal.CreateLobby( LobbyType.Invisible, maxMembers );
if ( !lobby.HasValue || lobby.Value.Result != Result.OK ) return null;
return new Lobby { Id = lobby.Value.SteamIDLobby };
}
/// <summary>
/// Attempts to directly join the specified lobby
/// </summary>
internal static async Task<Lobby?> JoinLobbyAsync( SteamId lobbyId )
{
Assert.NotNull( Internal );
var lobby = await Internal.JoinLobby( lobbyId );
if ( !lobby.HasValue ) return null;
return new Lobby { Id = lobby.Value.SteamIDLobby };
}
}