boardgame.io icon indicating copy to clipboard operation
boardgame.io copied to clipboard

Add server side calculations

Open charlestati opened this issue 6 years ago • 4 comments

It would allow this kind of scenario in multiplayer:

  1. Player 1 attacks Player 2
  2. Start Player 1 Attack animation (if optimisticUpdate)
  3. Start Player 2 Hurt animation (if optimisticUpdate)
  4. Calculate damages on the server
  5. Update the health state on both clients

From what I've seen, the server strips the _random API from ctx so it stays server side. Maybe it could also strip any flow.secret.* so we could use flow.secret.onMove for moves calculated server side?

If you have any hints for where to start I could dig into it!

charlestati avatar Apr 04 '18 03:04 charlestati

onMove is already calculated on the server side. Does this solve your use-case?

nicolodavis avatar Apr 04 '18 03:04 nicolodavis

Yes, but I believe it is still visible client-side? It would be an issue if, for some reason, the calculation must be kept secret.

Also, it works for simple moves but for games with hundreds of different moves (such as role-playing games) each player would download lots of unnecessary data.

Maybe my use case is not suitable for the current architecture of the framework? And I should separate server and client logic rather than use a common Game?

charlestati avatar Apr 04 '18 03:04 charlestati

The framework currently does not allow any secret logic, just secret data. Maybe we should just add an option to strip away everything in the flow object on the client side (at the expense of optimistic updates). That way you can just use onMove to do secret computations and they aren't visible on the client side.

nicolodavis avatar Apr 08 '18 04:04 nicolodavis

Ah yes, when optimisticUpdate is disabled stripping away everything in the flow could be a solution!

Thank you for your help!

charlestati avatar Apr 08 '18 04:04 charlestati