cr fixes #1 wip

This commit is contained in:
Hanusiak Piotr 2022-03-09 16:51:11 +01:00
parent 3c74b2b554
commit 3a5aa3c3c5
4 changed files with 25 additions and 13 deletions

View File

@ -46,7 +46,7 @@ export class GameRoom {
// Users, sorted by ID
private readonly users = new Map<number, User>();
private readonly usersByUuid = new Map<string, User>();
private readonly groups = new Set<Group>();
private readonly groups: Map<number, Group> = new Map<number, Group>();
private readonly admins = new Set<Admin>();
private itemsState = new Map<number, unknown>();
@ -250,7 +250,7 @@ export class GameRoom {
this.disconnectCallback,
this.positionNotifier
);
this.groups.add(group);
this.groups.set(group.getId(), group);
}
}
} else {
@ -334,7 +334,7 @@ export class GameRoom {
this.disconnectCallback,
this.positionNotifier
);
this.groups.add(newGroup);
this.groups.set(newGroup.getId(), newGroup);
} else {
this.leaveGroup(user);
}
@ -381,10 +381,10 @@ export class GameRoom {
group.leave(user);
if (group.isEmpty()) {
group.destroy();
if (!this.groups.has(group)) {
if (!this.groups.has(group.getId())) {
throw new Error(`Could not find group ${group.getId()} referenced by user ${user.id} in World.`);
}
this.groups.delete(group);
this.groups.delete(group.getId());
//todo: is the group garbage collected?
} else {
group.updatePosition();
@ -664,4 +664,8 @@ export class GameRoom {
const variablesManager = await this.getVariableManager();
return variablesManager.getVariablesForTags(tags);
}
public getGroupById(id: number): Group | undefined {
return this.groups.get(id);
}
}

View File

@ -41,6 +41,7 @@ import {
GroupUsersUpdateMessage,
LockGroupMessage,
LockGroupPromptMessage,
RoomMessage,
} from "../Messages/generated/messages_pb";
import { User, UserSocket } from "../Model/User";
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
@ -287,7 +288,7 @@ export class SocketManager {
(emoteEventMessage: EmoteEventMessage, listener: ZoneSocket) =>
this.onEmote(emoteEventMessage, listener),
(lockGroupMessage: LockGroupMessage, listener: ZoneSocket) =>
this.onLockGroup(lockGroupMessage, listener),
this.onLockGroup(lockGroupMessage, listener, roomPromise),
(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ZoneSocket) =>
this.onPlayerDetailsUpdated(playerDetailsUpdatedMessage, listener)
)
@ -391,10 +392,19 @@ export class SocketManager {
emitZoneMessage(subMessage, client);
}
private onLockGroup(lockGroupMessage: LockGroupMessage, client: ZoneSocket) {
const subMessage = new SubToPusherMessage();
subMessage.setLockgroupmessage(lockGroupMessage);
emitZoneMessage(subMessage, client);
private async onLockGroup(
lockGroupMessage: LockGroupMessage,
client: ZoneSocket,
roomPromise: PromiseLike<GameRoom> | undefined
) {
if (!roomPromise) {
return;
}
const group = (await roomPromise).getGroupById(lockGroupMessage.getGroupid());
if (!group) {
return;
}
this.emitCreateUpdateGroupEvent(client, null, group);
}
private onPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, client: ZoneSocket) {

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
HostUrl=about:internet

View File

@ -2010,6 +2010,7 @@ ${escapedMessage}
}
private doShareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface) {
console.log(groupPositionMessage);
//delete previous group
this.doDeleteGroup(groupPositionMessage.groupId);