Fix a bug where a player rejoining triggered a join message and desyncs

This commit is contained in:
Andrio Celos 2022-10-05 16:43:45 +11:00
parent ada0c9f150
commit 59dc677077
3 changed files with 12 additions and 4 deletions

View File

@ -123,9 +123,12 @@ function getGameInfo(gameID: string, myPlayerIndex: number | null) {
if (s) {
let payload = JSON.parse(s);
if (payload.event == 'join') {
currentGame.players.push(payload.data.player);
playerListItems[payload.data.playerIndex].innerText = payload.data.player.name;
updatePlayerListItem(payload.data.playerIndex);
if (payload.data.playerIndex == currentGame.players.length) {
currentGame.players.push(payload.data.player);
playerListItems[payload.data.playerIndex].innerText = payload.data.player.name;
updatePlayerListItem(payload.data.playerIndex);
} else
communicationError();
} else if (payload.event == 'playerReady') {
currentGame.players[payload.data.playerIndex].isReady = true;
updatePlayerListItem(payload.data.playerIndex);

View File

@ -69,6 +69,10 @@ function onGameStateChange(game: any, playerData: any) {
}
}
function communicationError() {
document.getElementById('errorModal')!.hidden = false;
}
showSection('preGame');
function isInternetExplorer() {

View File

@ -162,10 +162,11 @@ internal class Program {
SetErrorResponse(e.Response, error.Code == "GameAlreadyStarted" ? (int) HttpStatusCode.Gone : 422, error);
return;
}
game.SendEvent("join", new { playerIndex, player }, false);
}
// If they're already in the game, resend the original join response instead of an error.
SetResponse(e.Response, (int) HttpStatusCode.OK, "application/json", JsonConvert.SerializeObject(new { playerIndex, clientToken }));
game.SendEvent("join", new { playerIndex, player }, false);
timer.Start();
} catch (ArgumentException) {
e.Response.StatusCode = (int) HttpStatusCode.BadRequest;