From 5e156ade74c7d04b416d850b7136bce8fc3ae5b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 28 Apr 2022 15:44:36 +0200 Subject: [PATCH] Refreshing map URL (#2144) * Refreshing map URL When a "refresh" message is sent from the admin to the pusher, the map details endpoint is now called again. If the Map URL is changed, the variable manager is refreshed. --- back/src/Model/GameRoom.ts | 11 ++++++++++- back/src/Services/SocketManager.ts | 10 +++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/back/src/Model/GameRoom.ts b/back/src/Model/GameRoom.ts index efe7f86a..e2603ca8 100644 --- a/back/src/Model/GameRoom.ts +++ b/back/src/Model/GameRoom.ts @@ -520,7 +520,16 @@ export class GameRoom { this.admins.delete(admin); } - public incrementVersion(): number { + public async incrementVersion(): Promise { + // Let's check if the mapUrl has changed + const mapDetails = await GameRoom.getMapDetails(this.roomUrl); + if (this.mapUrl !== mapDetails.mapUrl) { + this.mapUrl = mapDetails.mapUrl; + this.mapPromise = undefined; + // Reset the variable manager + this.variableManagerPromise = undefined; + } + this.versionNumber++; return this.versionNumber; } diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index 8d71f4d8..5af1096f 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -852,14 +852,14 @@ export class SocketManager { return; } - const versionNumber = room.incrementVersion(); + const versionNumber = await room.incrementVersion(); room.getUsers().forEach((recipient) => { - const worldFullMessage = new RefreshRoomMessage(); - worldFullMessage.setRoomid(roomId); - worldFullMessage.setVersionnumber(versionNumber); + const refreshRoomMessage = new RefreshRoomMessage(); + refreshRoomMessage.setRoomid(roomId); + refreshRoomMessage.setVersionnumber(versionNumber); const clientMessage = new ServerToClientMessage(); - clientMessage.setRefreshroommessage(worldFullMessage); + clientMessage.setRefreshroommessage(refreshRoomMessage); recipient.socket.write(clientMessage); });