feat: Track players connection status (#834)#839
Conversation
9a1e0c9 to
0f805c5
Compare
0f805c5 to
0b60275
Compare
delucis
left a comment
There was a problem hiding this comment.
Thanks @pastDexter! Added a small refactor to remove some duplicate code, but this looks great 👍
|
Hey guys, I have a about this: are we able to read that status from inside a move? @delucis , do you know that? |
|
@evandroabukamel No, this is only stored in match metadata, which is used by the lobby and can be requested from the lobby server by the client. What’s your use case for using it in a move? |
|
Hi, @delucis . In my game there's a case when currentPlayer may disconnect from the game during their turn and not return back, so their data will remain on the game state. I need to pick a random player who is still connected and begin a new turn with him/her as currentPlayer. |
|
How are you planning on triggering the move? The only secure way I can think of is to have a move, which you call from the server on behalf of the disconnected current player. On the server you have access to the full metadata, so you could get the current player’s credentials, pick a next player and dispatch the move with the selected playerID. You would also have to see how reliable the connection status is (and how to monitor it) — players can probably briefly disconnect then reconnect if they have poor internet (on mobile for example), so you might see disconnections even if a player is still trying to play. |
|
Well, I didn't think about that before. Now it came to me the idea to have a skipTurn move, similar to "Skip voting" from Among Us. Inside that move, if half of players vote to skip within an interval time, the game should pick a random player, but I must assure this player is connected. Maybe, I could choose between those who voted, it's a funny feature. 😄 |
|
Hi, @delucis . I almost forgot about that. Please, could you clarify that? I don't see how I can achieve it:
Thanks. |
|
@evandroabukamel Ah, I assumed you already had some plan to run some custom server-side code for the timeout/next player picking. I meant that on the server you could use the database to fetch the metadata, but you would still need to customise the API or master interface to trigger this somehow (e.g. using a timer, which boardgame.io doesn’t currently have implemented) and I don’t have any immediate ideas about how to best do that. Here’s an example from the #709 changelog of adding a custom endpoint to the lobby API adapted to demonstrate sharing access to the database: import { Server, FlatFile } from 'boardgame.io/server';
const db = FlatFile({/* ... */});
const server = Server({ db, /* ... */ });
server.router.get('/custom-endpoint', async (ctx, next) => {
const { metadata } = await db.fetch('matchID', { metadata: true });
// use metadata
ctx.body = 'Custom Response'
});
server.run(8000); |
Closes #834
matchDataalongsideidandnameonConnectionChangemethod is called onMasterto update players metadata inDBand broadcast that info to all the players in the match asmatchDatamessageChecklist
master).