1. Help Center
  2. Getting Started
  3. Online Multiplayer Features

How To Create Individual Lobbies

A lobby is where other players gather together and interact with each other. Also start game sessions and enjoy multiplayer game sessions. An individual lobby is where selected players join and interact with each other.

Diarkis Modules We Need

To create an individual bobbies, we use Diarkis Room and Diarkis P2P.

What An Individual Lobby Can Do

An individual lobby is a Diarkis Room's room, so the players joined the lobby may communicate with each other immediately.

Here are some of many things an individual lobby can do:

  • Synchronize with remote players (send and receive messages)
  • Update and Synchronize Lobby Properties
    • Use Diarkis Room's Properties
  • Change and synchronize lobby properties
    • Use Diarkis Room's room properties
  • Send and Receive Lobby Notifications
    • All players in the lobby may send and receive messages via Diarkis Room
  • Create a game session
    • Create a new room
    • Use Diarkis Room's MessageTo
    • Use Diarkis P2P

How To Create An Individual Lobby

Creating an individual lobby is very similar to create a Diarkis Room's room.

Please read here to learn more about how to create a room.

How To Make Individual Lobbies Visible To Other Players

A room can have a category assigned and other players can find rooms by a category.

How To Assign A Category To A Room

NOTE: The example below uses C# Client SDK.

// For example, category = 1 means difficulty HARD
uint category = 1;

// Room name that you may assign to the room
string roomName = "For hardcore players only";

// Any information that you may want to assign to the room
string roomMetadata = "No noob allowed lol";

// Capture the server response of room.Register
room.OnRegister += (bool success, byte[] message) =>
{
// This event is the response of room.Register
}

// This is how to assign the category to a room that the client has already joined
room.Register(category, roomName, roomMetadata)

How To Retrieve A List of Available Rooms By A Category

NOTE: The example below uses C# Client SDK.

// For example, category = 1 means difficulty HARD
uint category = 1;

// This controls how many rooms to retrieve
uint howManyItemsToRetrieve = 10;

// This capture the server response to receive the list of rooms
room.OnFindRoomsByType += (bool success, List<RoomListItem> rooms) =>
{
// Loop the list to work your magic!
for (int i = 0; i < rooms.Cont; i++)
{
string roomID = rooms[i].GetID();
string roomName = rooms[i].GetName();
string roomMetadata = rooms[i].GetMetadata();
}
}

// This is how to request for the list of rooms
room.FindRoomsByType(category, howManyItemsToRetrieve);

Update And Synchronize Lobby Properties

An individual lobby may manipulate lobby property data and synchronize freely by Diarkis Room's room properties feature.

To learn more about how to manipulate properties please read here.

To learn more about how to synchronize lobby property when a new player joins, please read here.

To learn more about how to retrieve lobby property, please read here.

Synchronize With Remote Players

By using Diarkis Room's BroadcastTo and/or MessageTo players in the lobby may freely send and receive synchronizing messages.

Sending And Receiving Messages To/From All Members of The Lobby

NOTE: The example below uses C# Client SDK.

// This is the listener callback to capture and handle messages sent by room.BroadcastTo from remote players
room.OnMemberBroadcast += (byte[] message) =>
{
// Deserialize the message using Diarkis.Lib.SyncData
Diarkis.Lib.SyncData syncdata = new Diarkis.Lib.SyncData();
syncData.Deserialize(message);

// These are the properties from the deserialized message
Dictionary<string, object> properties = syncData.Properties;
long remotePlayerPositionX = properties.Get("x");
long remotePlayerPositionY = properties.Get("y");
long remotePlayerVelocity = properties.Get("velocity");

// This is the player ID of the remote player
string remotePlayerUID = syncdata.UID;

}

// Properties to be serialized and sent
Dictionary<string, object> properties = new Dictionary<string, object>();
properties.Add("x", playerPositionX);
properties.Add("y", playerPositionY);
properties.Add("velocity", playerVelocity);

// Serialize the property data to be sent as a message
Diarkis.Lib.SyncData syncdata = new Diarkis.Lib.SyncData();
syncdata.UID = playerUID; // Player ID
syncdata.Properties = properties;
syncdata.Serialize();
byte[] message = syncdata.Serialized;

// If UDP client is used setting this flag to true will make the message delivered as an RUDP message
bool reliable = false;

// This is how to send a message to all members in the lobby
room.BroadcastTo(room.GetRoomID(), message, reliable);

Sending And Receiving Messages To/From Selected Members of The Lobby

NOTE: The example below uses C# Client SDK.

// This is the listener callback to capture and handle messages sent by room.MessageTo from remote players
room.OnMemberMessage += (byte[] message) =>
{
// Deserialize the message using Diarkis.Lib.SyncData
Diarkis.Lib.SyncData syncdata = new Diarkis.Lib.SyncData();
syncData.Deserialize(message);

// These are the properties from the deserialized message
Dictionary<string, object> properties = syncData.Properties;
long remotePlayerPositionX = properties.Get("x");
long remotePlayerPositionY = properties.Get("y");
long remotePlayerVelocity = properties.Get("velocity");

// This is the player ID of the remote player
string remotePlayerUID = syncdata.UID;

}

// Properties to be serialized and sent
Dictionary<string, object> properties = new Dictionary<string, object>();
properties.Add("x", playerPositionX);
properties.Add("y", playerPositionY);
properties.Add("velocity", playerVelocity);

// Serialize the property data to be sent as a message
Diarkis.Lib.SyncData syncdata = new Diarkis.Lib.SyncData();
syncdata.UID = playerUID; // Player ID
syncdata.Properties = properties;
syncdata.Serialize();
byte[] message = syncdata.Serialized;

// Player ID list to send the message to
List<string> playerIDs = new List<string>();
playerIDs.Add(playerAID);
playerIDs.Add(playerBID);
playerIDs.Add(playerCID);

// If UDP client is used setting this flag to true will make the message delivered as an RUDP message
bool reliable = false;

// This is how to send a message to all members in the lobby
room.MessageTo(playerIDs, room.GetRoomID(), message, reliable);

Creating A Game Session

There are several ways to create a game session from an individual lobby.

Create A New Room As A Game Session

You may create a new room as a game session.

Diarkis Room does not allow you to join multiple rooms at a time and since an individual lobby is a room, you must leave the lobby to join the game session room.

For this reason, when you create a new room as a game session, you must create the room as an empty room.

NOTE: When players were to join the game session, they must leave the lobby.

// Maximum number of members for the game session
int maxMembers = 10;

// If true, the room will not be discard when it is empty
bool allowEmpty = false;

// By setting this flag to false, the room will be empty
bool join = false;

// This means that the empty room will be available for 5 minutes
int ttl = 300;

// Broadcast message buffering interval in milliseconds to lessen server stress
int interval = 200;

room.Create(maxMembers, allowEmpty, join, ttl, interval);

Using MessageTo of Diarkis Room To Create A Game Session

Instead of using another room as a game session, you may use MessageTo method of Diarkis Room to synchronize with selected member players in the lobby to act as a game session.

This will make the game session simple as there will be no extra room involved.

Using Diarkis P2P As A Game Session

Players in the lobby may freely share their client address since they are already the lobby (room).

Players may pick and chose other players to start a game session with Diarkis P2P.

This method does not require the players to leave the lobby and all players remain in the lobby while they are in a game session.