Jump to content

Ultra Software Company Blog

  • entries
    188
  • comments
    1,259
  • views
    700,790

Contributors to this blog

Introducing the Lobby System in Leadwerks 4.6


Josh

4,338 views

 Share

The new Lobby system in Leadwerks 4.6 allows you to create a public listing of your multiplayer game for others to join. This uses the Steamworks library. You can tap into the Steamworks lib by piggybacking on the default "SpaceWar" example game, which uses the Steam app ID 480. This is set up by default when you create a new Leadwerks project.

Now you might think of a lobby as a place where people hang out and chat before the game starts. You can treat it like this, but it's best to keep the lobby up as the game is running. This will allow other people to find the game to join, if it isn't full or if someone leaves the game. So a lobby is better described as a publicly advertised game others can join.

Creating a new lobby to advertise our game is easy. We just call a command to create it, and then we will set two string values. The game title is set so that we can later retrieve only lobbies that are running this particular game. (This should be done if you are using the SpaceWar app ID instead of your own Steam ID.) We also add a short description that can display information about the game.

Lobby* mylobby = Lobby::Create();
mylobby->SetKey("game", "MyGameTitle");
mylobby->SetKey("description", "Here is my lobby!");

It's also easy to retrieve a list of lobbies:

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

We can use GetKey() to look for lobbies that are running the same game we are:

if (lobby->GetKey("game") == "MyGameTitle")

We can retrieve the owner of the lobby with this command that will return a Steam ID:

uint64 steamid = lobby->GetOwner();

Once you have that Steam ID, that is all you need to start sending messages through the new P2P networking system. More on that later.

And we can also retrieve a list of all members in the lobby:

int count = lobby->CountMembers();
for (int k = 0; k < count; ++k)
{
	uint64 steamid = lobby->GetMember(k);
}

After a lobby is created, it will have one member, which will be the same Steam ID as the owner.

Joining a lobby is simple enough:

if (lobby->Join()) System::Print("Joined lobby!");

And leaving is just as easy:

lobby->Leave()

Now here's the magical part: When the owner of the lobby leaves, the lobby is not destroyed. Instead, the system will automatically choose another player to become the owner of that lobby, so the multiplayer game can keep going! The lobby will not be destroyed until everyone leaves the game.

  • Like 2
  • Upvote 1
 Share

5 Comments


Recommended Comments

Definitely familiar with this stuff, having worked with Steam (and literally working with it right now).  Very flexible.  Curious if you'll end up implementing some functions for transferring various data types beyond the void pointer Steam uses for packet send/receive.

Link to comment

It will use a Message object just like the current networking commands use:
https://www.leadwerks.com/learn?page=API-Reference_Object_Message

The message has an integer ID and a memory stream you can read from like a file.

I just got the voice recording stuff worked out. The VOIP stuff will be handled automatically since it is pretty complex. All you have to do is call SetVoiceRecording(window->KeyDown(Key::V)) and the rest is automatic.

  • Upvote 1
Link to comment

I've got voice chat over the network working now. It's great and it just takes one line of code to enable:

Voice::SetRecording(window->KeyDown(Key::V));

 

  • Like 1
Link to comment
8 hours ago, reepblue said:

Since the Turbo repo is now distant from the Leadwerks one, will this roll into Turbo or will it be less Steam reliant?

Yes, this will be added. It's a bit easier in the new engine because for example you do not have to remember to delete a Message object, and I prefer the constants like MESSAGE_RELIABLE over the LE4 style.

  • 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...