lijim / monks-and-mages

Monks and Mages is a TCG-game built on React and socket.io
https://www.monksandmages.com
MIT License
17 stars 0 forks source link

Fix: Prevent effect resolution ending games prematurely #440

Closed lijim closed 1 year ago

lijim commented 1 year ago

Problem In real testing on the actual domain, (not on local) we were able to reproduce twice cards with multiple effects (such as martial trainer, deep sea diver) causing a chain of effects where the latests effects didn't match properly, triggering a state where the game was rendered unplayable.

The reason was that our resolveEffect handler on the sockets connection was setting board to null. This meant whenever the game server was trying to emit the board for the room, it would exit early and not do anything.

How did we fix it? To prevent this we added a series of guardrails:

  1. Increased the timeout to 1250ms, from 1000ms for resolving effects automatically. While in ideal world, the automatic effect resolution should be guided by the server side, we have yet to implement it there. Resolution of effects that automatically resolve (e.g. "add 1 generic mana this turn") right now take place on the client side
  2. If the effect was for any reason returning a null result instead of the board, we don't set the board state to null anymore. Instead, we skip setting the new board state for the room.
  3. Added more await statements around emitting to clients. This will hopefully result in fewer bugs seen based on race conditions where parts of the game app are updated and other parts aren't updated yet (due to asynchronous code).