I return few values in MatchJoinAttempt. I want to use that in unity client to show to the user.
const online_random_matchJoinAttempt: nkruntime.MatchJoinAttemptFunction<GameState> = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, dispatcher: nkruntime.MatchDispatcher, tick: number, state: GameState, presence: nkruntime.Presence, metadata: {
[key: string]: any
}): { state: GameState, accept: boolean, reason: string } | null
{
logger.debug('matchJoinAttempt --> : ');
for (let key in metadata)
{
logger.debug(`matchJoinAttempt --> Key is: ${key}, Value is: ${metadata[key]}`);
}
if (state.presences[presence.sessionId])
{
logger.debug('matchJoinAttempt --> : Already joined');
return {
state,
accept: false,
reason: "Already joined"
};
}
// Check if match is full.
if (connectedPlayers(state) == state.maxPlayers)
{
logger.debug('matchJoinAttempt --> : Match is full');
return {
state: state,
accept: false,
reason: "Match is full"
};
}
//if the game is already started
if (state.gameStarted)
{
logger.debug('matchJoinAttempt --> : Match is already started');
return {
state: state,
accept: false,
reason: "Match is already started"
};
}
return {
state,
accept: true,
reason: "Join success"
};
};
In unity
private async void ContinueToJoinPrivateRoom(string roomName)
{
try
{
//First get the actual room code using the short code. this fetches the real room id from the server storage
var jsonObject = new { roomCode = roomName, gameMode = "online_private" };
var jsonString = JsonConvert.SerializeObject(jsonObject);
var response = await _socket.RpcAsync("rpc_get_short_room_code", jsonString);
if (!string.IsNullOrEmpty(response.Payload))
{
var matchResponse = JsonUtility.FromJson<MatchIdResponse>(response.Payload);
var match = await _socket.JoinMatchAsync(matchResponse.matchId);
_currentMatchID = match.Id;
}
else
{
_logger.PrintLog("Response payload is empty", LogType.Error);
}
}
catch (ApiResponseException)
{
_logger.PrintLog("Failed to join match");
}
}
In Unity it just throws an error in JoinMatchAsync method
WebSocketException: Match join rejected
Nakama.Socket.SendAsync (Nakama.WebSocketMessageEnvelope envelope) (at <cec673f2491249a5929c0733c26b2fce>:0)
Nakama.Socket.JoinMatchAsync (System.String matchId, System.Collections.Generic.IDictionary`2[TKey,TValue] metadata) (at <cec673f2491249a5929c0733c26b2fce>:0)
Nakama.Controller.NakamaController.ContinueToJoinRandomRoom () (at Assets/Scripts/Nakama/Controller/NakamaController.cs:577)
It just throws Match join rejected error I want to get the reason as well in the client. How to do that?