Closed kaizencc closed 3 years ago
Turns out that this issue is a lot bigger than I previously thought. The issue is an old one - refreshing the page disconnects the user from the socket and that calls removePlayerBySocketId
, which deletes all the information pertaining to that player (including all statistics).
Storing scores and current display in session storage remains possible and the likely solution there. I believe time can be stored there as well (for now, since this will likely result in some syncing issues). But time is not super essential to the game so that is okay for now.
Steps to fix the pervasive issue:
joined-user
: add a toBeDeleted
boolean to each player.disconnected
: same call to removeBySocketId
. But the timeout
function does not need logic for deleting rooms, just for sending message to the room.mongoDb
: change removeBySocketId
to simply find and mark toBeDeleted
for the player.mongoDb
: create a garbageCollector
function that sifts through a room and deletes all marked players.mongoDb
: modify getPlayersInRoom
to return players that are not marked.mongoDb
: create a updateSocketId
function.app.js
: Check to see if username exists in room should be fine because on refresh, even though the username is there, it should not be returned by getPlayersInRoom
.joined-user
: check if username exists in the room already (for real this time, this may require another mongo
function). If it doesn't, proceed as normal. If it does, instead of creating a new user
, simply update the socketId
and toBeDeleted
values of the player and take over that one.garbageCollector
every time startGame
is called.
Currently refreshing the page will mess up the state of the game for the user. Need to use
sessionStorage
and other avenues to ensure that necessary information is saved.timesync
.