Lobbies
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.
- 3
3 Comments
Recommended Comments