Skip to content

feat: Track players connection status (#834)#839

Merged
delucis merged 4 commits into
boardgameio:masterfrom
pastpatryk:pastDexter/track-players-connection-status
Oct 29, 2020
Merged

feat: Track players connection status (#834)#839
delucis merged 4 commits into
boardgameio:masterfrom
pastpatryk:pastDexter/track-players-connection-status

Conversation

@pastpatryk
Copy link
Copy Markdown
Contributor

Closes #834

  • Server now keeps track of all players connection status and stores this information in matchData alongside id and name
  • Every time player connects or disconnects from the SocketIO server, onConnectionChange method is called on Master to update players metadata in DB and broadcast that info to all the players in the match as matchData message

Checklist

  • Use a separate branch in your local repo (not master).
  • Test coverage is 100% (or you have a story for why it's ok).

@pastpatryk pastpatryk force-pushed the pastDexter/track-players-connection-status branch from 9a1e0c9 to 0f805c5 Compare October 28, 2020 10:34
@pastpatryk pastpatryk force-pushed the pastDexter/track-players-connection-status branch from 0f805c5 to 0b60275 Compare October 28, 2020 10:36
Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pastDexter! Added a small refactor to remove some duplicate code, but this looks great 👍

@delucis delucis merged commit 257a735 into boardgameio:master Oct 29, 2020
@evandroabukamel
Copy link
Copy Markdown
Contributor

Hey guys, I have a about this: are we able to read that status from inside a move? @delucis , do you know that?

@delucis
Copy link
Copy Markdown
Member

delucis commented Nov 24, 2020

@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?

@evandroabukamel
Copy link
Copy Markdown
Contributor

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.

@delucis
Copy link
Copy Markdown
Member

delucis commented Nov 25, 2020

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.

@evandroabukamel
Copy link
Copy Markdown
Contributor

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. 😄

@evandroabukamel
Copy link
Copy Markdown
Contributor

Hi, @delucis . I almost forgot about that. Please, could you clarify that? I don't see how I can achieve it:

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.

Thanks.

@delucis
Copy link
Copy Markdown
Member

delucis commented Dec 8, 2020

@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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep track of players' connection status

3 participants