Skip to content

Is there a proper way to end a game using a custom endpoint? #959

Answered by delucis
kumarajith asked this question in Q&A
Discussion options

You must be logged in to vote

@kumarajith Do you mean call setState directly on the database? The drawback with that is that it won’t update clients — database state isn’t reactive by itself, it only gets broadcast to clients when changed by moves/events/etc. in the game.

One pattern that might work would be something like this:

import { INVALID_MOVE } from 'boardgame.io/core';

const timeoutDuration = 60_000; // or whatever makes sense for the game

const game = {
  turn: {
    onMove: (G, ctx) => {
      // When a player moves, store the time of the move.
      // You could also reset this when the turn starts or wherever it makes sense.
      G.timeAtLastMove = Date.now();
    },
  },
  moves: {
    // Move that ch…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kumarajith
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants