diff --git a/back/src/Model/GameRoom.ts b/back/src/Model/GameRoom.ts
index 79ed9d3c..9afeae55 100644
--- a/back/src/Model/GameRoom.ts
+++ b/back/src/Model/GameRoom.ts
@@ -96,11 +96,6 @@ export class GameRoom {
return this.users;
}
- public getUserByName(name: string): User | undefined {
- let foundUsers = Array.from(this.users.values());
- foundUsers = foundUsers.filter((user: User) => user.name === name);
- return foundUsers[0];
- }
public getUserByUuid(uuid: string): User | undefined {
return this.usersByUuid.get(uuid);
}
@@ -237,10 +232,6 @@ export class GameRoom {
});
}
- public sendToUserWithName(name: string, message: ServerToClientMessage): void {
- this.getUserByName(name)?.socket.write(message);
- }
-
setSilent(user: User, silent: boolean) {
if (user.silent === silent) {
return;
diff --git a/back/src/Model/User.ts b/back/src/Model/User.ts
index 09c0d3d9..13a61c3f 100644
--- a/back/src/Model/User.ts
+++ b/back/src/Model/User.ts
@@ -25,7 +25,7 @@ export class User implements Movable {
public readonly IPAddress: string,
private position: PointInterface,
public silent: boolean,
- public following: string[],
+ public following: number[],
private positionNotifier: PositionNotifier,
public readonly socket: UserSocket,
public readonly tags: string[],
@@ -49,15 +49,15 @@ export class User implements Movable {
this.positionNotifier.updatePosition(this, position, oldPosition);
}
- public addFollower(name: string): void {
- if (this.following.includes(name)) {
+ public addFollower(userId: number): void {
+ if (this.following.includes(userId)) {
return;
}
- this.following.push(name);
+ this.following.push(userId);
}
- public delFollower(name: string): void {
- const idx = this.following.indexOf(name);
+ public delFollower(userId: number): void {
+ const idx = this.following.indexOf(userId);
if (idx === -1) {
return;
}
diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts
index 5818afa9..8c7eecac 100644
--- a/back/src/Services/SocketManager.ts
+++ b/back/src/Services/SocketManager.ts
@@ -846,16 +846,17 @@ export class SocketManager {
handleFollowConfirmationMessage(room: GameRoom, user: User, message: FollowConfirmationMessage) {
const clientMessage = new ServerToClientMessage();
clientMessage.setFollowconfirmationmessage(message);
- room.sendToUserWithName(message.getLeader(), clientMessage);
+ const leader = room.getUserById(message.getLeader());
+ leader?.socket.write(clientMessage);
- room.getUserByName(message.getLeader())?.addFollower(user.name);
+ leader?.addFollower(user.id);
user.addFollower(message.getLeader());
}
handleFollowAbortMessage(room: GameRoom, user: User, message: FollowAbortMessage) {
const clientMessage = new ServerToClientMessage();
clientMessage.setFollowabortmessage(message);
- if (user.name === message.getLeader()) {
+ if (user.id === message.getLeader()) {
// Forward message
room.sendToOthersInGroupIncludingUser(user, clientMessage);
@@ -865,10 +866,11 @@ export class SocketManager {
});
} else {
// Forward message
- room.sendToUserWithName(message.getLeader(), clientMessage);
+ const leader = room.getUserById(message.getLeader());
+ leader?.socket.write(clientMessage);
// Update followers
- room.getUserByName(message.getLeader())?.delFollower(user.name);
+ leader?.delFollower(user.id);
user.following = [];
}
}
diff --git a/front/src/Components/InteractMenu/InteractMenu.svelte b/front/src/Components/InteractMenu/InteractMenu.svelte
index 6f5e62b2..dae7f099 100644
--- a/front/src/Components/InteractMenu/InteractMenu.svelte
+++ b/front/src/Components/InteractMenu/InteractMenu.svelte
@@ -19,7 +19,7 @@ vim: ft=typescript
let followState: string;
let followRole: string;
- let followUsers: string[];
+ let followUsers: number[];
let stateUnsubscriber: Unsubscriber;
let roleUnsubscriber: Unsubscriber;
let nameUnsubscriber: Unsubscriber;
@@ -51,14 +51,18 @@ vim: ft=typescript
}
});
+ function name(userId: number): string | undefined {
+ return gameScene.MapPlayersByKey.get(userId)?.PlayerValue;
+ }
+
function sendFollowRequest() {
- gameScene.connection?.emitFollowRequest(gameManager.getPlayerName());
+ gameScene.connection?.emitFollowRequest();
followStateStore.set(followStates.active);
}
function acceptFollowRequest() {
gameScene.CurrentPlayer.enableFollowing();
- gameScene.connection?.emitFollowConfirmation(followUsers[0], gameManager.getPlayerName());
+ gameScene.connection?.emitFollowConfirmation();
}
function abortEnding() {
@@ -66,11 +70,7 @@ vim: ft=typescript
}
function reset() {
- if (followRole === followRoles.leader && followUsers.length > 0) {
- gameScene.connection?.emitFollowAbort(gameManager.getPlayerName(), "*");
- } else {
- gameScene.connection?.emitFollowAbort(followUsers[0], gameManager.getPlayerName());
- }
+ gameScene.connection?.emitFollowAbort();
followStateStore.set(followStates.off);
followRoleStore.set(followRoles.leader);
followUsersStore.set([]);
@@ -92,7 +92,7 @@ vim: ft=typescript
{#if followRole === followRoles.follower}
{#if followRole === followRoles.follower}
{:else if followRole === followRoles.leader}