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); });