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 intera
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 HARDuint category =1;// Room name that you may assign to the roomstring roomName ="For hardcore players only";// Any information that you may want to assign to the roomstring roomMetadata ="No beginners allowed";// Capture the server response of room.Registerroom.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 joinedroom.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 HARDuint category =1;// This controls how many rooms to retrieveuint howManyItemsToRetrieve =10;// This capture the server response to receive the list of roomsroom.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 roomsroom.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 playersroom.OnMemberBroadcast+= (byte[] message) =>{ // Deserialize the message using Diarkis.Lib.SyncDataDiarkis.Lib.SyncData syncdata =newDiarkis.Lib.SyncData();syncData.Deserialize(message); // These are the properties from the deserialized messageDictionary<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 playerstring remotePlayerUID =syncdata.UID;}// Properties to be serialized and sentDictionary<string, object> properties =newDictionary<string,object>();properties.Add("x", playerPositionX);properties.Add("y", playerPositionY);properties.Add("velocity", playerVelocity);// Serialize the property data to be sent as a messageDiarkis.Lib.SyncData syncdata =newDiarkis.Lib.SyncData();syncdata.UID= playerUID; // Player IDsyncdata.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 messagebool reliable =false;// This is how to send a message to all members in the lobbyroom.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 playersroom.OnMemberMessage+= (byte[] message) =>{ // Deserialize the message using Diarkis.Lib.SyncDataDiarkis.Lib.SyncData syncdata =newDiarkis.Lib.SyncData();syncData.Deserialize(message); // These are the properties from the deserialized messageDictionary<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 playerstring remotePlayerUID =syncdata.UID;}// Properties to be serialized and sentDictionary<string, object> properties =newDictionary<string,object>();properties.Add("x", playerPositionX);properties.Add("y", playerPositionY);properties.Add("velocity", playerVelocity);// Serialize the property data to be sent as a messageDiarkis.Lib.SyncData syncdata =newDiarkis.Lib.SyncData();syncdata.UID= playerUID; // Player IDsyncdata.Properties= properties;syncdata.Serialize();byte[] message =syncdata.Serialized;// Player ID list to send the message toList<string> playerIDs =newList<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 messagebool reliable =false;// This is how to send a message to all members in the lobbyroom.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 sessionint maxMembers =10;// If true, the room will not be discard when it is emptybool allowEmpty =false;// By setting this flag to false, the room will be emptybool join =false;// This means that the empty room will be available for 5 minutesint ttl =300;// Broadcast message buffering interval in milliseconds to lessen server stressint 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.