I have a multiplayer card game which I am in the process of developing.
The game is relatively simple; players have a certain number of cards which they can activate, sell, or use in various other ways.
The game isn't turn based. Instead, it is asynchronous so that players (A, B, C, and D) all make their choices at the same time. Certain actions will affect the game state. For example, removing a card from the game or adding a card to the game. Players should always be in sync with each other so that, for instance, Player A cannot use a card that Player B has just removed, as it is no longer present.
Obviously there are situations in which Player A may remove a card at nearly the same time that Player B tries to interact with the same card. How would the server handle this sort of situation?
My original thought is that each client could hash their game state and send it with their command to the server, for example:
Player A - #MYHASH# - Command = Pick Up Card Z
Player B - #MYHASH# - Command = Remove Card Z
The server would then action the first command and regenerate the hash. Upon trying to execute the second command it would notice the hash sent by Player B differs from the current hash, so the server would reject the request.
In the above example Player A would notice nothing and the game would continue normally, but Player B would have to be informed that their action failed.