ajanata / PretendYoureXyzzy

A web clone of the card game Cards Against Humanity.
https://pretendyoure.xyz/zy
BSD 2-Clause "Simplified" License
1.23k stars 397 forks source link

Wrong card can be removed from hand #55

Closed uecasm closed 10 years ago

uecasm commented 10 years ago

Two separate cases:

  1. If a player has selected a card but not quite clicked Confirm Selection (or possibly when they have clicked it but just slightly too late and the server has already recorded them as not submitting a card) then the game state update can come in and the card will be removed from their hand even though they didn't actually play it.
  2. If a player selects a card, confirms it, and very quickly selects a different card (when the connection is lagging and the client has not yet received the game state update) then the wrong card will be removed from their hand, leaving the server and client disagreeing what their hand is.

I suggest having the "played card completed" handler be the thing responsible for removing the card from the hand, and have it include the specific card id to be removed. I think this will fix the above two, but not this one:

  1. Haven't actually tested/observed this myself so I'm not sure if it's "real", but given the above I strongly suspect that if someone has confirmed one or more cards from a multi-card pick but time out before selecting the final card, they will not get their chosen cards back again. This is actually almost a feature because it should leave them with the correct number of cards in the end (because they drew extras for the multi-pick anyway) but it might annoy some people who "lose" good cards. Also the final card play will still be subject to the other two issues above.

This might also mean that on a pick 3 or higher, if they pick only one and then time out they'll be left with one too many cards. Again, haven't specifically tested this, so maybe it's already dealt with somehow.

(The first and second issues I have directly observed, and also inferred from other players reporting to me that they've lost a card or received "you don't have that card" errors.)

uecasm commented 10 years ago

After a quick look at the code, it does look like the last case is probably mostly imaginary, as the server does try to return cards if the player didn't play enough. But again the race conditions from the first two cases could be a problem. And also this might end up leaving the player with too many cards instead.