Merge pull request #210 from thecodingmachine/develop
Merging mitigationofwolrsync error in master
This commit is contained in:
commit
c422f3ccef
@ -183,9 +183,13 @@ export class IoSocketController {
|
||||
|
||||
// The answer shall contain the list of all users of the room with their positions:
|
||||
const listOfUsers = Array.from(world.getUsers(), ([key, user]) => {
|
||||
const player = this.searchClientByIdOrFail(user.id);
|
||||
const player: ExSocketInterface|undefined = this.sockets.get(user.id);
|
||||
if (player === undefined) {
|
||||
console.warn('Something went wrong. The World contains a user "'+user.id+"' but this user does not exist in the sockets list!");
|
||||
return null;
|
||||
}
|
||||
return new MessageUserPosition(user.id, player.name, player.character, player.position);
|
||||
});
|
||||
}).filter((item: MessageUserPosition|null) => item !== null);
|
||||
answerFn(listOfUsers);
|
||||
} catch (e) {
|
||||
console.error('An error occurred on "join_room" event');
|
||||
@ -297,6 +301,9 @@ export class IoSocketController {
|
||||
const world : World|undefined = this.Worlds.get(Client.roomId);
|
||||
if(world){
|
||||
world.leave(Client);
|
||||
if (world.isEmpty()) {
|
||||
this.Worlds.delete(Client.roomId);
|
||||
}
|
||||
}
|
||||
//user leave previous room
|
||||
Client.leave(Client.roomId);
|
||||
|
@ -72,6 +72,10 @@ export class World {
|
||||
this.users.delete(user.userId);
|
||||
}
|
||||
|
||||
public isEmpty(): boolean {
|
||||
return this.users.size === 0;
|
||||
}
|
||||
|
||||
public updatePosition(socket : Identificable, userPosition: PointInterface): void {
|
||||
const user = this.users.get(socket.userId);
|
||||
if(typeof user === 'undefined') {
|
||||
|
Loading…
Reference in New Issue
Block a user