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.
This commit is contained in:
David Négrier 2022-04-28 15:44:36 +02:00 committed by GitHub
parent d6450831c6
commit 5e156ade74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -520,7 +520,16 @@ export class GameRoom {
this.admins.delete(admin);
}
public incrementVersion(): number {
public async incrementVersion(): Promise<number> {
// 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;
}

View File

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