You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In closing issue #20, this other bug popped up! If the current player disconnects before their turn is over, in certain scenarios this causes the next player to try to fork their own Gist at the end of the next turn, resulting in a 422 error response from GitHub.
Scenario for current player disconnection bug:
Player 0 connects, creates Gist, and Player 1 connects. (Server initializes previousPlayerIndex and currentPlayerIndex to 0.)
First turn ends, Player 0 edits their Gist, and the second starts and passes control to Player 1. (Server's previousPlayerIndex is now 0, and currentPlayerIndex is now 1.)
Player 1 disconnects on their turn, before their turn is over. (This begins the problematic part, if I continue to do client-side API calls!)
Server removes Player 1 from playerList, restarts turn timer, and changes turn to pass control back to Player 0. (So previousPlayerId is now undefined because previousPlayerIndex is 1, but playerList now only contains information at index 0!)
Server emits updateStateChange to clients, which receive that undefined value and thus set their previousPlayerId variable to undefined too!
At the end of Player 0's turn, their client tries to fork the Gist because the condition for forking is currentPlayerId !== previousPlayerId, comparing the currentPlayer to undefined, which causes an 422 error reponse from GitHub, because Player 0 can't fork their own Gist!
This problem doesn't occur at all if Player 0 disconnects on their turn, because the server can always access index 0 of playerList array, and the rest works out nicely -- one big happy accident!
Other scenarios to explore:
What if there are more than two players in the game?
What other edge cases are there?
Possible solutions:
One definitive fix would be to check just before the end of every turn if the current player is the owner of the Gist or not. That would always work! (But for some reason I feel stubborn about this, hopeful that there's another way to accomplish this without adding one more condition to my code.)
Issue Server should fork/edit Gists on behalf of disconnected users #21 ("Server should fork/edit Gists on behalf of disconnected users") would resolve this issue as well! (I'm leaving this as a separate issue in case there's a way to fix this while still handling all API calls on the clients.)
The text was updated successfully, but these errors were encountered:
Throwing this out, because I'm replacing issue #20 and #24 with issue #26 ("Game state should track Gist owner for forking/editing logic") -- a much better solution!
LearningNerd
changed the title
If current player disconnects, next turn can trigger unwanted Gist fork
CANCELLED: If current player disconnects, next turn can trigger unwanted Gist fork
Jun 29, 2017
In closing issue #20, this other bug popped up! If the current player disconnects before their turn is over, in certain scenarios this causes the next player to try to fork their own Gist at the end of the next turn, resulting in a 422 error response from GitHub.
Scenario for current player disconnection bug:
Player 0 connects, creates Gist, and Player 1 connects. (Server initializes
previousPlayerIndex
andcurrentPlayerIndex
to 0.)First turn ends, Player 0 edits their Gist, and the second starts and passes control to Player 1. (Server's
previousPlayerIndex
is now 0, andcurrentPlayerIndex
is now 1.)Player 1 disconnects on their turn, before their turn is over. (This begins the problematic part, if I continue to do client-side API calls!)
Server removes Player 1 from
playerList
, restarts turn timer, and changes turn to pass control back to Player 0. (SopreviousPlayerId
is now undefined becausepreviousPlayerIndex
is 1, butplayerList
now only contains information at index 0!)Server emits
updateStateChange
to clients, which receive that undefined value and thus set theirpreviousPlayerId
variable to undefined too!At the end of Player 0's turn, their client tries to fork the Gist because the condition for forking is
currentPlayerId !== previousPlayerId
, comparing the currentPlayer toundefined
, which causes an 422 error reponse from GitHub, because Player 0 can't fork their own Gist!This problem doesn't occur at all if Player 0 disconnects on their turn, because the server can always access index 0 of
playerList
array, and the rest works out nicely -- one big happy accident!Other scenarios to explore:
Possible solutions:
One definitive fix would be to check just before the end of every turn if the current player is the owner of the Gist or not. That would always work! (But for some reason I feel stubborn about this, hopeful that there's another way to accomplish this without adding one more condition to my code.)
Issue Server should fork/edit Gists on behalf of disconnected users #21 ("Server should fork/edit Gists on behalf of disconnected users") would resolve this issue as well! (I'm leaving this as a separate issue in case there's a way to fix this while still handling all API calls on the clients.)
The text was updated successfully, but these errors were encountered: