boardgameio / boardgame.io

State Management and Multiplayer Networking for Turn-Based Games
https://boardgame.io
MIT License
9.93k stars 707 forks source link

flow callback on client. #366

Closed pociej closed 4 years ago

pociej commented 5 years ago

In docs you say its intentional that flow callbacks like onPhaseBegin are called only on master. Let me share my opinion that it seems to be wrong conception. Lets say i want to display some tips on client because i have some tutorial mode in my game, or i want to simulate something based on moves in current phase. You can find more and more cases, and all of them shouldnt affect game state. With current implementation i could of course update G on phaseBegin to let client know that something has to be done but that sounds like huge reduncdancy. Tell me if im wrong but from what i see everything should be available for client.

nicolodavis commented 5 years ago

Let me first explain a little more about how the client / server separation works: All moves are run on both the server and client. They are run on the client in order to avoid network latency, but they are still run on the server in order to calculate the next game state authoritatively (to avoid cheating). The server then broadcasts the next game state to everyone (including the player that just made the move).

For flow callbacks like onPhaseBegin, it was deemed unnecessary to also run them on the client since they typically involve some game related setup that may:

  1. Use randomness, at which point running it on the client would produce a different result.
  2. Rely on secret state, which is only visible on the server.
nicolodavis commented 5 years ago

I'm not sure I fully understand your use cases. All the functions in boardgame.io should be pure (i.e. should have no side effects), so the only way to use the result of a move or something like onPhaseBegin is to put it inside the game state.

If you want to just simulate or run a tutorial mode, have you considered using a separate client that is in singleplayer mode for this?