public class MatchBet
{
public int matchBet;
public int playerLevel;
}
private async void FindPairImpairPvPMatch()
{
MatchBet playerBetToServer = new MatchBet();
playerBetToServer.matchBet = playerRekiumsBet;
playerBetToServer.playerLevel = playerLevel;
string jsonFromClient = JsonUtility.ToJson(playerBetToServer);
Debug.Log(jsonFromClient);
var payload = jsonFromClient;
var rpcid = "find_match_pairimpair";
var serverResponse = await client.RpcAsync(session, rpcid, payload);
var serverResponsePayload = serverResponse.Payload;
MatchIDsFound serverResponseMatchId = JsonUtility.FromJson<MatchIDsFound>(serverResponsePayload);
matchIDs = serverResponseMatchId.matchIds;
//Temp Debug to see the match id
matchIdTemp.text = serverResponseMatchId.matchIds[0];
matchID=serverResponseMatchId.matchIds[0];
matchVsBot = false;
PairImpairPvPJoinMatch();
}
On the server :
//MatchLabel is in the module representing the game.
interface MatchLabel {
matchBet: number,
playerLevel:number
}
//This function is in its own module match_rpc.ts
let rpcFindMatchPairImpair: nkruntime.RpcFunction = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, payload: string): string {
if (!ctx.userId) {
throw Error('No user ID in context');
}
if (!payload) {
throw Error('Expects payload.');
}
let matches: nkruntime.Match[];
try {
logger.debug(ctx.userId , "Has submited the following label :", payload);
matches = nk.matchList(10, true, payload, null, 1, null);
} catch (error) {
logger.error('Error listing matches: %v', error);
throw error;
}
let matchIds: string[] = [];
if (matches.length > 0) {
// There are one or more ongoing matches the user could join.
matchIds = matches.map(m => m.matchId);
logger.error('Another user could join a match, we need to send him back a matchid');
} else {
// No available matches found, create a new one.
try {
matchIds.push(nk.matchCreate(moduleNamePairImpairPvP));
logger.error('We have created a Pair Impair PvP match following a user request');
} catch (error) {
logger.error('Error creating match: %v', error);
throw error;
}
}
let res: RpcFindMatchResponse = { matchIds };
return JSON.stringify(res);
}
The label field of matchList will apply an exact match which doesn’t quite work for json encoded labels, what you want to do is use the query param and use the query syntax - see Server authoritative multiplayer - Heroic Labs Documentation.