boardgame.io
boardgame.io copied to clipboard
Add server side calculations
It would allow this kind of scenario in multiplayer:
- Player 1 attacks Player 2
- Start Player 1 Attack animation (if
optimisticUpdate
) - Start Player 2 Hurt animation (if
optimisticUpdate
) - Calculate damages on the server
- 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!
onMove is already calculated on the server side. Does this solve your use-case?
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
?
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.
Ah yes, when optimisticUpdate
is disabled stripping away everything in the flow
could be a solution!
Thank you for your help!