Jump to content
  • entries
    943
  • comments
    5,899
  • views
    923,763

Lobbies


Josh

1,684 views

 Share

Previously, I talked about the new peer-to-peer networking system that handles Nat punch-through and allows a sort of "floating" server that stays alive as long as at least one player is in the game.

The lobby system allows you to broadcast to other players that you have a game available to join. The name might be somewhat misleading, as it does not require players to hang out in a chatroom before starting the game. My implementation functions more like a standard game server list.

To create a new lobby and tell other players your game is available to join, call the following:

Lobby* lobby = Lobby::Create(const int maxplayers = 32, const int type = Lobby::Public)

Or in Leadwerks 5:

auto lobby = CreateLobby(const int maxplayers = 32, const int type = LOBBY_PUBLIC)

You can set attributes of your lobby that other users can read and display:

lobby->SetKey("map","SuperArenaOfDeath")

Other users can retrieve a list of lobbies as follows:

int count = Lobby::Count();
for (int n=0; n<count; n++)
{
	auto lobby = Lobby::Get(n);
}

Or in Leadwerks 5:

int count = CountLobbies();
for (int n=0; n<count; n++)
{
	auto lobby = GetLobby(n);
}

You can retrieve attributes of a lobby:

std::string value = lobby->GetKey("map");

When you find the lobby you want, joining and leaving is easy:

lobby->Join();
lobby->Leave();

When you have joined a lobby you can retrieve the lobby owner Steam ID, and the Steam IDs of all lobby members. This is what you use as the message destinations in the peer-to-peer messagng system:

int64 steamid = lobby->GetOwner();
for (int n=0; n<lobby->CountMembers(); n++)
{
	steamid = lobby->GetMember();
}

Once you have joined a lobby and retrieved the steam IDs of the members you can start sending messages to the lobby owner or to other players in the game. Just like the P2P networking system, if the original creator of the lobby leaves, the ownership of that lobby is automatically passed off onto another player, and the lobby stays alive as long as one person is still participating. Once everyone leaves the lobby, it shuts down automatically.

  • Like 3
 Share

3 Comments


Recommended Comments

Looks very straightforward.

So does this command Lobby::Count(); or CountLobbies()  fetch a count of all existing lobbies? Can you also pass in a name or id of your game, so that you only get lobbies that belong to your game?

 

Link to comment
56 minutes ago, AggrorJorn said:

Looks very straightforward.

So does this command Lobby::Count(); or CountLobbies()  fetch a count of all existing lobbies? Can you also pass in a name or id of your game, so that you only get lobbies that belong to your game?

 

If you have a Steam ID for your game then all lobbies are yours.

You can also supply optional attributes as either a map of strings or a single string. This can be used to lobbies with specific values, including a lobby with your game's name, if a shared Steam ID is used.

int count = CountLobbies( {"game","TurboTron"} );

 

  • Like 1
Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...