question

Brent Batas (Lisk) avatar image
Brent Batas (Lisk) asked

How can you check if a match is finished, given a MatchId?

I'm researching how to implement reconnecting to a game in progress (e.g. your computer crashed and you want to get back into your match).

Currently, my live title does this via legacy matchmaking by

1. Store current game ID in player data as a "currentgame" field. When a game finishes, this field is cleared by a dedicated lobby server.

2. When the client logs on, it checks if it has a non-null "currentgame." If so, it will fetch server data (indirectly) from a call to PlayFabClientAPI.GetCurrentGames() and connect to the server (i.e. 'reconnect to game in progress').

In game servers 2.0, matchmaking no longer flows through my dedicated lobby server, but instead is communicated between clients and PlayFab.


If I store the matchId in the currentgame field, I can reconnect to a match in progress by calling GetMatch() and connecting to the server in the serverDetails.

However, I don't know how to handle the case where the match already finished by the time my client tries to reconnect to it.

The direct solution that comes to mind is if there was an API call to tell if a matchId was finished (the server that handled this matchId already shut down).

Does such an API call exist?

Alternatively, a naive solution is that the client will always try to connect to the "current game" server, then it will just consider a timeout (failing to connect to the server) as a sign that the match finished. This feels messy to me and potentially buggy given that a timeout could happen for other reasons.

Custom Game ServersMatchmaking
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Hi Brent, I don’t think such an API call exist. However, after a discussion with our team, we may have a workaround for you. When the game has come to an end, the server instance will call ShutdownMultiplayerServer API to shut down the server. After that players will not be able to connect to the server. The player should keep a copy of ServerId for himself. Therefore, when the player tries to reconnect to a game in progress, first call ListMultiplayerServers API to get the list of all the servers, then compare the ServerId the player have with the all the serverId. If the ServerId the player having is in the list of all servers, then the game is in progress, player reconnect to the game. Otherwise the player need to rematch a game. You could give it a try, any issues let us know:)

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Brent Batas (Lisk) avatar image Brent Batas (Lisk) commented ·

Thanks for the answer - I think this workaround will work! I think I originally implemented it on the lobby server so I could reduce the # of API calls on the client, but it shouldn't be a problem since it only needs to call ListMultiplayerServers occasionally.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Brent Batas (Lisk) commented ·

Yeah, glad it helped, any issues let us know:)

0 Likes 0 ·
Brent Batas (Lisk) avatar image Brent Batas (Lisk) commented ·

@Citrus Yan

I'm looking to implement this; however, I get an error when calling ListMultiplayerServers API:

Only entities of the following types may call this API: title

How else can I have the player call ListMultiplayerServers API as you are suggesting?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Brent Batas (Lisk) commented ·

Hi Brent, as the error suggests, in order to call ListMultiplayerServers API, you must provide your title’s EntiyToken as X-EntityToken in the headers. You’ll need to call GetEntityToken with X-SecretKey in order to get your title’s EntityToken, which means you’ll be exposing your secret key in the client if you want to call ListMultiplayerServers API. This is highly un-recommended and needs to be avoided.

In my considered opinion, it’s probably better for you to leave the whole checking procedure to the CloudScript. The basic idea is to let the player submit the serverId(it can be received from the server, I noticed that you can't get it from GetMatchId API) or any other properties that can be used to check server status, in the CloudScript handler call ListMultiplayerServer API and use the info returned to check whether the match is finished. At last return the result to the client to do the next move.

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.