I am trying to create a private room/lobby for a board game(like tic tac toe) where you play against your friends. So far, I have been able to create the match and join them by following the documentation.
However, the match id it generates is a very long string. Even if your friend is beside you, you will need to send that match id with some social medias. I want to convert that “match id” into some simple digits(probably of 5-6 digit) that can by typed manually. How can I implement this feature?
I tried to create a global dictionary variable holding some random numbers that point to that “match id” and some rpc function to retrieve that “match id” from that random number. But global variables are not supported in typescript.
One way to achieve this is to create a server-side RPC function which takes the long match_id as an input and returns some abbreviated match code using a storage collection with 2 columns: match_code, match_id. Client would call this function when match-making: this RPC would generate a new match_code and insert it in the collection associated with the internal match_id, then return the match_code to the client that started the match.
On the match join, a client would call another RPC with reverse logic: take match_code as input and return the long match_id to the client to pass to MatchJoin.
You may be able to do it all in one RPC and some details may differ depending on whether you are planning to have authoritative matches or not.
I am trying to figure out how to give the custom name to my match. Currently, in the server side I have this:
let rpcCreateMatchFiveHandPokerTraining: nkruntime.RpcFunction = function (
context: nkruntime.Context,
logger: nkruntime.Logger,
nk: nkruntime.Nakama,
payload: string
): string {
logger.debug(payload);
var matchId = nk.matchCreate(moduleFiveHandPokerTraining, { payload });
return JSON.stringify({ matchId });
};
// In main.ts
initializer.registerRpc(
rpcIdCreateMatchFiveHandPokerTraining,
rpcCreateMatchFiveHandPokerTraining
);
And in the client side I have:
public async void CreateTrainingMatch(string gametype)
{
Debug.Log("Start Training");
var rpcid = $"create_match_{gametype}_training_js";
try
{
Task<IApiRpc> searchTask;
searchTask = Client.RpcAsync(Session, rpcid, "");
//awaiting for server returning value
IApiRpc searchResult = await searchTask;
var matchIdResponse = searchResult.Payload.FromJson<MatchIdResponse>();
Debug.Log($"Retrieved match id : {matchIdResponse.matchId}");
if (matchIdResponse.matchId.Length > 0)
{
currentMatchId = matchIdResponse.matchId;
JoinMatch(currentMatchId);
}
}
catch (Exception e)
{
Debug.Log($"Creating training failed: {e.Message}");
}
}
I want a simple name with the first 5 characters of the matchId to serve as my research parameter in JoinMatch(string matchName). Can you provide some indications as I am enable to find it in the wiki? Thanks a lot!