Skip to content

Multiplayer

The GOG GALAXY SDK allows you to use its features to implement multiplayer, matchmaking and P2P communication in your game.

Hosting a Multiplayer Lobby

As a user trying to host a lobby

Creating a lobby is pretty straightforward: you need to call the IMatchmaking::CreateLobby() functions, which takes in the following parameters:

Parameter Type Description
lobbyType LobbyType Specifies the type of a lobby: private, public, visible only to friends, or even invisible only to friends
maxMembers integer Maximum number of lobby members
joinable bool Determines whether the lobby is joinable immediately after its creation
lobbyTopologyType LobbyTopologyType Specifies the way users connect to each other

The GOG GALAXY SDK allows you to create lobbies of several topologies:

Lobby Topology Description
LOBBY_TOPOLOGY_TYPE_FCM Every user connects with every other user (and the multiplayer server); no ownership migration
LOBBY_TOPOLOGY_TYPE_STAR Every user connects to the lobby owner (and the multiplayer server); no ownership migration
LOBBY_TOPOLOGY_TYPE_CONNECTIONLESS Every user connects only to the server with lobby owner transition, direct communication between users is not possible, yet lobby/member data is propagated as usual; sending lobby messages works
LOBBY_TOPOLOGY_TYPE_FCM_OWNERSHIP_TRANSITION Every user connects with every other user with lobby owner transition

After the IMatchmaking::CreateLobby() call is made and a lobby creation request has been completed, you will receive two responses: one to ILobbyCreatedListener with the ID of your lobby, and the other one to ILobbyEnteredListener — provided that the lobby was created successfully, in which case the owning user enters it automatically. Then lobby data and user information is automatically requested for every member of the lobby.

Setting Lobby Data

As a user hosting a lobby, after performing the steps in the Hosting a Multiplayer Lobby scenario above

The next thing you might want to do after hosting a lobby is specifying Lobby Data — that is data that can hold lobby properties and can make the lobby distinguishable from others. In order to do that, you need to call IMatchmaking::SetLobbyData() that takes 3 parameters: the ID of the lobby for which you want to set the data for, the key under which the data will be held, and the value of that key. For example:

SetLobbyData(1234, "LobbyName", "TestLobby")

Setting Other Lobby Properties

As a user hosting a lobby, after performing the steps in the Hosting a Multiplayer Lobby scenario

Creating a multiplayer lobby is not the only time you can specify lobby properties: states like “joinable” etc. can also be modified after a lobby has been created. In order to do that, you can use functions like IMatchmaking::SetLobbyJoinable(), IMatchmaking::SetLobbyType() or IMatchmaking::SetMaxNumLobbyMembers(). For a full list of functions please refer to the SDK documentation.

Requesting a List of Lobbies

As a user trying to join an already hosted lobby

First thing you will need to do is call the IMatchmaking()::RequestLobbyList() function. This function can take a Boolean parameter specifying whether to include lobbies which are full. After the call processes you should receive a response to ILobbyListListener::OnLobbyList() listener function.

That response will contain the number of lobbies found and whether there was an error during retrieving them. Inside that listener function you can use the IMatchmaking::GetLobbyByIndex() method to retrieve a lobby ID (please note that this is the only place that this method can be called in). Once you have the ID of a lobby, you will want to call the IMatchmaking::RequestLobbyData() function, passing the ID as a parameter. This allows you to retrieve information about a specified lobby; the call is asynchronous, so you need to wait for a response to an appropriate listener (ILobbyDataListener or ILobbyDataRetrieveListener).

Using Lobby Data

As a user trying to join an already hosted lobby and after performing the steps in the Requesting a List of Lobbies scenario above

Once a response to the IMatchmaking::RequestLobbyData() function is received, you should call IMatchmaking::GetLobbyData(), using the ID of the lobby and the key of the property, which you want to retrieve. For example, in order to retrieve the “LobbyName” property, which was set in the Setting Lobby Data scenario, you would call GetLobbyData(1234, "LobbyName") and receive “TestLobby” as a return value.

Retrieving Information Other Than Lobby Data

As a user trying to join an already hosted lobby and after performing the steps in the Requesting a List of Lobbies scenario

Once a response to the IMatchmaking::RequestLobbyData() function is received, you can call various functions in order to retrieve different information about the lobby, for example: IMatchmaking::GetNumLobbyMembers() or IMatchmaking::GetLobbyOwner(). For a list of all functions that can be called on a lobby before and after joining it, please refer to the SDK documentation.

Joining a Lobby

As a user trying to join an already hosted lobby and after performing the steps in the Requesting a List of Lobbies scenario

After you select the ID of the lobby to which you want to connect to, you can call IMatchmaking::JoinLobby(). This call is asynchronous and after calling it, a response will come to the ILobbyEnteredListener::OnLobbyEntered() listener function, indicating whether you successfully joined the lobby and providing the ID of the lobby you have just joined.

Communicating Inside a Lobby

As a user hosting a lobby, or as a user that has joined a lobby

There is a couple of ways to communicate with other users in a lobby:

  1. Sending lobby messages — you can call the IMatchmaking::SendLobbyMessage() function to send a message to all members in the lobby (including yourself). Each recipient should be registered for notifications about incoming messages with a dedicated listener, and when such notification is received, call IMatchmaking::GetLobbyMessage().
  2. Sending P2P Packets — you can use the INetworking::SendP2PPacket() function to send packets to other lobby members or to the lobby owner (depending on the topology of the lobby).
  3. Setting lobby data — the lobby owner can set various lobby data, using the IMatchmaking::SetLobbyData() function, which the lobby members can then read.

A lobby topology specifies, to whom you should send p2p packets:

  • FCM — packets should be sent to every other lobby member.
  • Star — packets should be sent to the lobby owner and the lobby owner should then redistribute packets to other members.
  • Connectionless — connectionless type does not support packet sending at this moment; it’s ideal for making a chatroom and other features, which can rely only on lobby messages and lobby data.

Leaving a Lobby

As a user hosting a lobby, or as a user that has joined a lobby

If you are a user that has joined a lobby — and are not the lobby owner — you can simply call IMatchmaking::LeaveLobby() to initiate leaving a lobby. You will receive a callback to ILobbyLeftListener once leaving is finished. Other lobby members will receive a callback to their ILobbyMemberStateListener, indicating that someone has left the lobby. If you are the lobby owner, you also use the IMatchmaking::LeaveLobby() method, but what happens to the lobby after you leave, depends on the topology:

  • FCM — disconnection of the owner from the lobby results in closing the lobby.
  • Star — disconnection of the owner from the lobby results in closing the lobby.
  • Connectionless — disconnection of the owner from the lobby results in choosing a new lobby owner.
  • FCM Ownership Transition — disconnection of the owner from the lobby results in choosing a new lobby owner.

GameServer

The implementation of GameServers (dedicated servers) in the GOG GALAXY SDK is not much different from the implementation of a user-hosted game. The only differences between GameServers and user-hosted multiplayer games are as follows:

Back to top