Lobby Manager

This tool simply exposes features present in LobbyData and the Matchmaking API to the inspector.

This is not required to use these features; it is simply a helper tool allowing users who are more comfortable working with editor inspectors and game objects rather than classic C# objects and scripting to make use of the related feature.

A tool for creating and managing a specific lobby. This component is meant to be attached to a game object in your matchmaking scene / ui. Your game may have multiple Lobby Managers, where each manages a single specific lobby.

Events

You can add events via the Add New Event Type button, like Unity's Event Trigger component. The names listed are slightly different from the names as they appear in code to help clarify the use of each when IntelliSense is not available, as it is in code.

Authentication Session Results

Only occurs on the owner of the lobby when an authentication request is received, and BeginSession responds with the results of the authentication attempt.

void Handler(AuthenticationSession Session, byte[] Inventory)
{
    // Session contains details about the auth session started
    // If any, this will be the serialised inventory passed in with the ticket
}

Lobby Chat Message Received

Occurs for all lobby members when a chat message is received from the lobby.

void Handler(LobbyChatMsg Message)
{
    // Message contains the user, time, string and byte[] if any sent
}

Lobby Creation Failed

Occurs when a Create request fails.

void Handler(EResult Result)
{
    // Result is the error code for the failure
}

Lobby Creation Success

Occurs when a Create request is successful.

void Handler(LobbyData Lobby)
{
    // Lobby is the lobby that was created
}

Lobby Invite Received

Occurs when a lobby invite was received.

void Handler(LobbyInvite Invite)
{
    // Invite contains the user its from and the lobby and game it is for
}

Lobby Join Failure

Occurs when a request to join a lobby fails.

void Handler(EChatRoomEnterResponse Response)
{
}

Lobby Join Success

Occurs when a request to join a lobby is successful.

void Handler(LobbyData Lobby)
{
    // Lobby is the lobby that was joined
}

Metadata Updated

Occurs when data on the lobby or a member is updated.

void Handler(LobbyDataUpdateEventData Data)
{
    // Data.lobby will always have a value and be the lobby that was updated
    // Data.member can be null, if it is null, then the data was lobby metadata
    // If it is not null, then the data was member metadata.
    // Steam doesn't tell us what field, just on what object.
}

Other User Left

Occurs when a user leaves a lobby that you are in.

void Handler(UserLobbyLeaveData Data)
{
    // Data.user is who left
    // Data.state can indicate how or why
}

Other User Joined

Occurs when a user joins the lobby that you are in.

void Handler(UserData User)
{
    // User is who joined
}

Quick Match Failed

Occurs when quick match fails to find a lobby to match to.

void Handler()
{
    // No parameters are passed
}

Search Result Ready

Occurs when a search completes and results are ready.

void Handler(LobbyData[] Results)
{
    // Results is the array of lobbies found as LobbyData structs
}

Session Connection Updated

Occurs when connection information has been updated in the lobby

void Handler(LobbyGameServer GameServer)
{
    // GameServer.id is the CSteamID of the Listen (P2P) or Dedicated server, if any
    // GameServer.IpAddress is the 0.0.0.0 IP address as a string, if any
    // GameServer.ipAddress is the IP address as a uint32, if any
    // GameServer.port is the port, if any
}

You Are Asked to Leave

Occurs when you have been "kicked" from the lobby, and you should then leave the lobby.

void Handler()
{
    // No parameters are passed
}

Fields and Attributes

Search Arguments

public SearchArguments searchArguments;

Used with any form of search performed through the Lobby Manager, including the Search and QuickMatch methods. This is used to define the "search arguments", e.g. the rules to be tested when searching for lobbies.

The SearchArguments data type is an internal class:

[Serializable]
public class SearchArguments
{
    /// <summary>
    /// If less than or equal to 0, then we won't use the open slot filter
    /// </summary>
    public int slots = -1;
    public ELobbyDistanceFilter distance = ELobbyDistanceFilter.k_ELobbyDistanceFilterDefault;
    public List<NearFilter> nearValues = new List<NearFilter>();
    public List<NumericFilter> numericFilters = new List<NumericFilter>();
    public List<StringFilter> stringFilters = new List<StringFilter>();
}

The fields of the class are as follows.

  • slots If less than or equal to 0, this will be ignored; otherwise, this will indicate the number of available slots resulting lobbies must have. For example, if you wanted to find a lobby for you and 3 friends, then you would provide a value of 4 in this field to return only lobbies that had 4 open slots.

  • distance An enumerator that indicates the maximum allowed distance between the searching user and the members of the resulting lobbies. For more details on the values, see Valve's documentation on ELobbyDistanceFilter, in summary

    • Close Only in the same Valve region as this user

    • Default In the same or nearby Valve region as this user

    • Far Up to half a world away

    • World Wide No filtering at all

  • nearValues Key value pairs that the system should search for "nearby" values for. See Valve's documentation on this feature for more details. In summary, this doesn't "filter out" lobbies but rather affects the sorting; the closer a lobby's metadata is to matching this value, the higher it will be sorted in the resulting list. This is useful for say "Player Rank" whose min and max player rank are as near the player's actual rank as possible. To do this, you could set near values of minRank = myRank and maxRank = myRank. This would not exclude any lobbies in and of itself, but would sort lobbies such that top results were nearest "my rank" This assumes minRank is the rank of the lowest-ranked player in that lobby, and maxRank is the rank of the highest-ranked player in that lobby.

  • numericFilters Instructs the search to perform a numeric filtering operation on these fields, and can filter by the following methods

    • Equal to or Less than

    • Less than

    • Equal

    • Greater than

    • Equal to or Greater than

    • Not Equal

  • stringFilter Instructs the search to perform a string filtering operation on these fields, and can be filtered by the same methods as numeric filters. Valve doesn't explain what the result of each is, so test to confirm the desired results.


Create Arguments

public CreateArguments createArguments;

Used by the Lobby Manager any time a lobby is created with it, this would apply to Create as well as QuickMatch when no lobby is found and create on fail is set to true.

The CreateArguments data type is an internal class:

[Serializable]
public class CreateArguments
{
    public UseHintOptions usageHint;
    public string name;
    public int slots;
    public ELobbyType type;
    public List<MetadataTempalate> metadata = new List<MetadataTempalate>();
}

The fields of the class are as follows.

  • usageHint This simply indicates what the intended use is for the lobbies created by this instance of the lobby manager. If set to a value other than "None", it will cause the Lobby Manager, on the creation of a new lobby, to set that lobby as either Group or Session, depending on the value you set here.

  • name This will be set as metadata on the lobby when created, e.g. MyLobby["name"] = value;

  • slots This is the maximum number of slots this lobby will have ... this includes the owner of the lobby.

  • type The type of lobby, you can learn more about the available types above.

  • metadata Metadata fields to be set on the lobby once created. This is a simple string key and string value pairing. Metadata is what is used when "filtering" or "searching" for lobbies.


Lobby

public LobbyData Lobby { get; set; }

The lobby the manager is currently managing. This will automatically be updated when you use the lobby manager to create, join or leave a lobby. If you create, join or leave a lobby from outside the manager, then you should update this field accordingly.


Has Lobby

public bool HasLobby => get;

True if the manager is managing a lobby, false otherwise.


Is Player Owner

public bool IsPlayerOwner => get;

True if the local user is the owner of the managed lobby, false otherwise.


All Players Ready

public bool AllPlayersReady => get;

True if all members of the lobby have marked themselves as ready, otherwise false.


Is Player Ready

public bool IsPlayerReady { get; set; }

Returns true if the player has marked themselves as ready in this lobby. This can be set to mark the player as ready or not in this lobby.


Full

public bool Full => get;

Returns true if the lobby is currently full, false otherwise.


Is Type Set

public bool IsTypeSet => get;

Returns true if the lobby type has been recorded on the lobby metadata, false otherwise.


Type

public ELobbyType Type { get; set; }

Returns the type of lobby this lobby is set to; this is a feature of Heathen's Lobby tools. Valve does not actually expose this, so this will only work for lobbies created by Heathen's tools, such as the lobby manager or the API.Matchmaking class. This can only be set by the owner of the lobby.


Max Members

public int MaxMembers { get; set; }

Indicates the maximum number of members that can be in the lobby. This can be set by the owner of the lobby to change the maximum slots.


Has Server

public bool HasServer => get;

Returns true if the lobby has had its game server set, false otherwise.


Game Server

public LobbyGameServer GameServer => get;

Returns data about the game server set in the lobby, if any.


Functions

Authenticate

public void Authenticate(Action<AuthenticationTicket, bool> callback)
// Or
public bool Authenticate(LobbyAuthenticationData data)

Sends a chat message to the lobby with authentication data that can be used by the owner of the lobby to validate this user and, optionally, serialised inventory. Two overloads are available; you can either create your own LobbyAuthenticationData object and pass that in, or you can provide a callback to be invoked on completion, and the system will create a default LobbyAuthenticationData for you and send that, invoking the callback once that process has been completed.

Callback example

void Callback(AuthenticationTicket ticket, bool ioError)
{
    // ioError true if an error occurred on send
    // ticket the ticket that was sent, if no error
}

Create

public void Create()
// or
public void Create(string name, ELobbyType type, int slots, params MetadataTemplate[] metadata)
// or
public void Create(ELobbyType type, int slots, params MetadataTemplate[] metadata)
// or
public void Create(Action<EResult, LobbyData, bool> callback)

Creates a new lobby and sets the value to the Lobby field. If no parameters are passed in the system will use the Create Arguments. If name, type, slots and metadata parameters are passed in the system will overwrite the create arguments before creating the lobby. If only a callback is passed in, then it will use the Create Arguments and will invoke the provided callback when completed.

void Callback(EResult resultCode, LobbyData lobby, bool ioError)
{
    // resultCode is the status of the request, generally should be "OK"
    // lobby is the lobby that was created
    // ioError if true, then there was a failure requesting the lobby creation
}

Get Lobby Data

public string GetLobbyData(string key)

Get metadata from the lobby itself.


Get Lobby Member

public LobbyMemberData GetLobbyMember(UserData member)

Create a Lobby Member Data object for the indicated user.


Get Member Data

public string GetMemberData(UserData member, string key)

Gets the metadata of a given user; the user must be a member of this lobby.


Invite

public void Invite(UserData user)
// or
public void Invite(uint FriendId)

Invites the indicated user to the lobby.


Is Member Ready

public bool IsMemberReady(UserData member)

Checks if the indicated member is flagged as "ready"


Join

public void Join(LobbyData lobby)
// or
public void Join(ulong lobby)
// or
public void Join(string lobbyIdAsString)

Joins the indicated lobby, which will leave the current lobby, if any.


Kick Member

public void KickMember(UserData member)

Add the member's ID to the Kick Member list. You must then handle the Asked to Leave event and leave the lobby if you want this to work. It is less a "kick" and more of an ask to leave nicely.


Leave

public void Leave()

Leave the lobby.


Quick Match

public void QuickMatch(bool createOnFail = true)

Using the Search Arguments, it will search for a matching lobby. If one is found, it will join it; if not, and if the createOnFail parameter is true, it will create a lobby according to the Create Arguments.


public void Search(int maxResults)

Uses the Search Arguments to find up to 50 lobbies, but not more than maxResults.


Send Chat Message

public bool SendChatMessage(string message)
// or
public bool SendChatMessage(byte[] data)
// or 
public bool SendChatMessage(object jsonObject)

Send a Steam Lobby Chat message to the lobby. You can send a string, a byte[] of binary data, or you can provide a JSON Serializable object, and we will serialise that and send it as an object.


Set Joinable

public bool SetJoinable(bool makeJoinable)

Set the lobby as joinable or not; this can only be called by the lobby owner.


Set Lobby Data

public bool SetLobbyData(string key, string value)

Set metadata on the lobby; only the lobby owner can do this.


Set Member Data

public void SetMemberData(string key, string value)

Set metadata on the local user, you can only set data on yourself self not other members.


Set Type

public bool SetType(ELobbyType type)

Change the type of lobby for the lobby being managed. This can only be done by the lobby owner.

Last updated