You can participate in the desired lobby when entering the lobby by providing search conditions. It set the search condition with metadata (StovePCMatchmakingMetadata).
Lobby Metadata
using Stove.PCSDK.NET.Matchmaking;
// Define the key value of metadata
public struct LOBBY_META_KEY
{
public const string DEFFICULTY_TYPE_KEY = "DefficultyType";
public const string GAMEMODE_TYPE_KEY = "GameModeType";
public const string ROOM_TYPE_KEY = "RoomType";
public const string STAGE_TYPE_KEY = "StageType";
}
// game difficulty
public struct Difficulty
{
public string value; //meta value
public string name; //Name to be displayed in UI
public bool isDefault; // Whether to select the default (if there are multiple, use the first one.)
public string resourcePath; //resource path to display UI
}
// game mode
public struct mode
{
public string value; //meta value
public string name; //Name to be displayed in UI
public
bool isDefault; // Whether to select the default (if there are multiple, use the first one.)
public string resourcePath; //resource path to display UI
public bool isBattleMode; // UI changes depending on whether or not there is a battle mode.
public string[] roomValues; // Room information used in the mod meta value
}
// set the room
public struct room
{
public string value; //meta value
public int maxUser; //Maximum number of people
public string name; //Name to be displayed in UI
public string resourcePath; //resource path to display UI
}
//game stage
public struct stage
{
public string value; //meta value
public string name; //Name to be displayed in UI
public bool isDefault; // Whether to select the default (if there are multiple, use the first one.)
public string resourcePath; //resource path to display UI
}
Defficulty.value = "Beginner";
Mode.value = "Arcade";
Room.value = "Arcade2";
List<StovePCMatchmakingMetadata> metaList = new List<StovePCMatchmakingMetadata>()
{
// set first meta data
// key = "DefficultyType", value = "Beginner"
new StovePCMatchmakingMetadata(LOBBY_META_KEY.DEFFICULTY_TYPE_KEY, Defficulty.value),
// set the second metadata
// key = "GameModType", value = "Arcade"
new StovePCMatchmakingMetadata(LOBBY_META_KEY.GAMEMODE_TYPE_KEY, Mode.value),
// set the third metadata
// key = "RoomType", value = "Arcade2"
new StovePCMatchmakingMetadata(LOBBY_META_KEY.ROOM_TYPE_KEY, Room.value),
};
Plain Text
복사
Lobby Entry API
Enter the matchmaking lobby with the SDK.JoinRandomLobby method. You automatically enter one of the lobbies that match your search criteria.
using Stove.PCSDK.NET.Matchmaking;
List<StovePCMatchmakingMetadata> metaList = new List<StovePCMatchmakingMetadata>()
{
// set first meta data
// key = "DefficultyType", value = "Beginner"
new StovePCMatchmakingMetadata(LOBBY_META_KEY.DEFFICULTY_TYPE_KEY, Defficulty.value),
// set the second metadata
// key = "GameModType", value = "Arcade"
new StovePCMatchmakingMetadata(LOBBY_META_KEY.GAMEMODE_TYPE_KEY, Mode.value),
// set the third metadata
// key = "RoomType", value = "Arcade2"
new StovePCMatchmakingMetadata(LOBBY_META_KEY.ROOM_TYPE_KEY, Room.value),
}
// When creating a lobby, the maximum number of users that can enter the lobby
int maxUser = 4;
SDK.JoinRandomLobby(metaList.ToArray(), maxUser);
Plain Text
복사
If you find multiple lobbies, you will enter one of the lobbies at random. It is created based on the search criteria if it locates no lobby. When creating a lobby, the User becomes the moderator. You can check the user rating through the StovePCMatchmakingAffiliation in the OnUserJoin callback.
Lobby Callback
If an error occurs while the SDK.JoinRandomLobby method is running, you can check the contents in error.result (error code) StovePCMatchmakingResult.
To receive multiple callbacks to the lobby, you must register a delegate in advance.
•
When you enter the lobby, OnJoinLobby => (OnUserJoin * number of users including yourself) is called consecutively.
•
Whenever another user enters the lobby, the OnUserJoin callback is called. ** You can check user rating through StovePCMatchmakingAffiliation in the OnUserJoin callback.
•
Whenever another user leaves the lobby, the OnUserLeave callback is called.
•
When leaving the lobby, the OnLeaveLobby callback is called. ** In addition to API calls, it also calls when it forces you to leave due to lobby kick/ban, lobby deletion, etc.
•
When the moderator leaves, it transfers the moderator to the entry order and calls the OnUserUpdate callback. ** In the OnUserUpdate callback, you can check the User's information who it has transferred.
using Stove.PCSDK.NET.Matchmaking;
// lobby related delegate
// Register lobby entry delegate
SDK.EventJoinLobby += GameObj.OnJoinLobby;
// Register the user entry delegate in the lobby
SDK.EventUserJoin += GameObj.OnUserJoin;
// Register the user information update delegate in the lobby
SDK.EventUserUpdate += GameObj.OnUserUpdate;
// Register the user exit delegate in the lobby
SDK.EventUserLeave += GameObj.OnUserLeave;
// Register lobby exit delegate
SDK.EventLeaveLobby += GameObj.OnLeaveLobby;
// Enter the matchmaking lobby
private void OnJoinLobby(StovePCMatchmakingError error, StovePCMatchmakingJoinLobby joinLobby)
{
// Process the next game logic, such as moving the scene
if (error.result == StovePCMatchmakingResult.NO_ERROR)
{
}
// error handling
else
{
StringBuilder sb = new StringBuilder();
// error code
sb.AppendFormat(" - fail code : {0}", error.result);
// If there is a specific error
sb.AppendFormat(" - fail message : {0}", error.message);
Debug.Log(sb.ToString());
}
}
//User enters the lobby (including myself)
private void OnUserJoin(StovePCMatchmakingError error, StovePCMatchmakingUserJoin userJoin)
{
StringBuilder sb = new StringBuilder();
// Unique Lobby ID
sb.AppendFormat("lobby = {0}", userJoin.lobby);
// user ID
sb.AppendFormat("userID = {0}", userJoin.UID);
// user nickname
sb.AppendFormat("userNickname = {0}", nickname);
// User rating in the lobby ( 0 = Normal, 4 = Moderator )
sb.AppendFormat("affiliation = {0}", userJoin.affiliation);
// User metadata, storage space of the user in the lobby
foreach(var data in userJoin.userDataArray)
{
sb.AppendFormat("meta {0} = {1}", data.key, data.value);
}
Debug.Log(sb.ToString());
//Process game logic
}
// Update user information (including me) in the lobby
private void OnUserUpdate(StovePCMatchmakingError error, StovePCMatchmakingUpdateLobbyUser userUpdate)
{
StringBuilder sb = new StringBuilder();
// Unique Lobby ID
sb.AppendFormat("lobby = {0}", userUpdate.lobby);
// user ID
sb.AppendFormat("userID = {0}", userUpdate.UID);
// user nickname
sb.AppendFormat("userNickname = {0}", userUpdate.nickname);
// User rating in the lobby ( 0 = Normal, 4 = Moderator )
sb.AppendFormat("affiliation = {0}", userUpdate.affiliation);
// User metadata, storage space of the user in the lobby
foreach(var data in userUpdate.userDataArray)
{
sb.Appe
ndFormat("meta {0} = {1}", data.key, data.value);
}
Debug.Log(sb.ToString());
//Process game logic
}
// Exit another user from the lobby
private void OnUserLeave(StovePCMatchmakingError error, StovePCMatchmakingUserLeave userLeave)
{
StringBuilder sb = new StringBuilder();
// Unique Lobby ID
sb.AppendFormat("lobby = {0}", userLeave.lobby);
// user ID
sb.AppendFormat("userID = {0}", userLeave.userID);
// user nickname
sb.AppendFormat("userNickname = {0}", userLeave.nickname);
// Reason code for user leaving (You can check the contents in `StovePCMatchmakingResult`)
sb.AppendFormat("leaveCode = {0}", error.result);
Debug.Log(sb.ToString());
//reason for leaving the lobby of other users
switch(error.result)
{
// Leave the lobby by calling the API
case StovePCMatchmakingResult.NO_ERROR:
break;
// the manager kicks
case StovePCMatchmakingResult.USER_KICKED:
break;
// moderator van
case StovePCMatchmakingResult.USER_BANNED:
break;
// Moderator deletes lobby
case StovePCMatchmakingResult.USER_ROOM_DESTROYED:
break;
// Remove lobby from server
case StovePCMatchmakingResult.USER_ROOM_SHUTDOWN:
break;
// Remove lobby due to operational issue
case StovePCMatchmakingResult.ROOM_DELETED_AS_OPERATIONAL:
break;
}
//Process game logic
}
Plain Text
복사
The lobby ID is unique to the lobby. You can use it when calling other lobby-related APIs.
In the lobby, you must call the RunCallback method periodically because other users can enter, update information, or receive messages.