The match is still running.
My test is user1 create the match, then user2 call match.search (using nk.matchlist to find that old one) but the array is , you can see in the log (The line below - Try to find existing matches...
)
{"level":"debug","ts":"2022-11-26T16:16:47.086+0700","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_Rpc message","uid":"1a89360c-e7cd-4ae5-b495-1a5c7da4506e","sid":"0d464210-6d6b-11ed-b040-006100a0eb06","envelope":"cid:\"1\" rpc:{id:\"match.create\" payload:\"{\\\"data\\\":{\\\"matchId\\\":\\\"8c55e455-e49b-4ec1-aeb7-610f83a91228.nakama\\\"}}\"}"}
{"level":"debug","ts":"2022-11-26T16:16:47.087+0700","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchJoin message","uid":"1a89360c-e7cd-4ae5-b495-1a5c7da4506e","sid":"0d464210-6d6b-11ed-b040-006100a0eb06","cid":"2","message":{"MatchJoin":{"Id":{"MatchId":"8c55e455-e49b-4ec1-aeb7-610f83a91228.nakama"}}}}
{"level":"debug","ts":"2022-11-26T16:16:47.088+0700","caller":"server/runtime_javascript_logger.go:104","msg":"\"1a89360c-e7cd-4ae5-b495-1a5c7da4506e\" attempted to join match, metadata: map[]","mid":"8c55e455-e49b-4ec1-aeb7-610f83a91228"}
{"level":"debug","ts":"2022-11-26T16:16:47.089+0700","caller":"server/runtime_javascript_logger.go:104","msg":"tlmn.handler - match join - instatiate TLMNDI","mid":"8c55e455-e49b-4ec1-aeb7-610f83a91228"}
{"level":"debug","ts":"2022-11-26T16:16:47.089+0700","caller":"server/tracker.go:907","msg":"Processing presence event","joins":1,"leaves":0}
{"level":"debug","ts":"2022-11-26T16:16:47.089+0700","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_Match message","uid":"1a89360c-e7cd-4ae5-b495-1a5c7da4506e","sid":"0d464210-6d6b-11ed-b040-006100a0eb06","envelope":"cid:\"2\" match:{match_id:\"8c55e455-e49b-4ec1-aeb7-610f83a91228.nakama\" authoritative:true label:{value:\"{\\\"id\\\":\\\"8c55e455-e49b-4ec1-aeb7-610f83a91228.nakama\\\",\\\"status\\\":\\\"initial\\\",\\\"players\\\":[],\\\"leaderUserId\\\":null,\\\"gameplay\\\":\\\"tlmn\\\",\\\"competitive\\\":\\\"normal\\\",\\\"mode\\\":\\\"normal\\\",\\\"betGold\\\":10000}\"} self:{user_id:\"1a89360c-e7cd-4ae5-b495-1a5c7da4506e\" session_id:\"0d464210-6d6b-11ed-b040-006100a0eb06\" username:\"NR79LO\"}}"}
{"level":"debug","ts":"2022-11-26T16:16:47.089+0700","caller":"server/runtime_javascript_logger.go:104","msg":"\"1a89360c-e7cd-4ae5-b495-1a5c7da4506e\" request to join match","mid":"8c55e455-e49b-4ec1-aeb7-610f83a91228"}
{"level":"debug","ts":"2022-11-26T16:16:47.092+0700","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_Rpc message","uid":"f1d26365-fd35-48ae-b6c7-25082ebfe2ca","sid":"0d4cd0e4-6d6b-11ed-b040-006100a0eb06","cid":"1","message":{"Rpc":{"id":"match.create","payload":"{\"gameplay\":\"tlmn\",\"payload\":{\"maxPlayers\":2,\"gameplay\":\"tlmn\"},\"useExisting\":true}"}}}
{"level":"debug","ts":"2022-11-26T16:16:47.097+0700","caller":"server/runtime_javascript_logger.go:104","msg":"tlmn - handler - send state message: map[command:55 context:MatchPlayerJoin data:{\"competitive\":\"normal\",\"mode\":\"normal\",\"betGold\":10000,\"id\":\"8c55e455-e49b-4ec1-aeb7-610f83a91228.nakama\",\"status\":\"initial\",\"players\":[\"1a89360c-e7cd-4ae5-b495-1a5c7da4506e\"],\"leaderUserId\":\"1a89360c-e7cd-4ae5-b495-1a5c7da4506e\",\"gameplay\":\"tlmn\"} sender:SYS], receivers: <nil>","mid":"8c55e455-e49b-4ec1-aeb7-610f83a91228"}
{"level":"debug","ts":"2022-11-26T16:16:47.099+0700","caller":"server/runtime_javascript_logger.go:104","msg":"@@@@@@@@@@@@@@ Try to find existing matches []","rpc_id":"match.create"}
Here is my recap implementation
export function createMatch(
context: nkruntime.Context,
logger: nkruntime.Logger,
nk: nkruntime.Nakama,
dto: CreateMatchInputDto
): CreateMatchResultDto {
if (dto.useExisting) {
const existings = nk.matchList(10, true, null, 2, 4);
logger.debug("@@@@@@@@@@@@@@ Try to find existing matches %v", existings); // Here result is empty
if (existings?.[0]) {
return { matchId: existings[0].matchId}
}
}
// Fallback to create new one
const matchId = nk.matchCreate(TLMN_MODULE_NAME, props);
return {
matchId: matchId,
};
}
Here is my jest test pseudocode
const user1;
const user2;
const response1 = await user1.socket.rpc(
rpcCreateMatchId, // match.create
JSON.stringify({useExisting: false})
);
const data1 = JSON.parse(
String(response1.payload)
) as AppResponseDto<CreateMatchResultDto>;
expect(data1.data.matchId).toBeDefined();
await user1.socket.joinMatch(data1.data.matchId);
const response2 = await user2.socket.rpc(
rpcCreateMatchId, // match.create
JSON.stringify({ useExisting: true })
);
const data2 = JSON.parse(
String(response2.payload)
) as AppResponseDto<CreateMatchResultDto>;
expect(data2.data.matchId).toBe(data1.data.matchId); // Failed because another match is created
await user2.socket.joinMatch(data2.data.matchId);