Send request to group members only

This commit is contained in:
PizZaKatZe 2021-12-12 02:17:39 +01:00
parent 1fca99c0d1
commit d6ef60a3d8
2 changed files with 25 additions and 6 deletions

View File

@ -106,6 +106,16 @@ export class Group implements Movable {
return this.users.size <= 1;
}
includes(user: User): boolean {
let found = false;
this.users.forEach((currentUser: User) => {
if (currentUser.name === user.name) {
found = true;
}
});
return found;
}
join(user: User): void {
// Broadcast on the right event
this.connectCallback(user, this);

View File

@ -836,13 +836,22 @@ export class SocketManager {
}
handleFollowMeRequestMessage(room: GameRoom, user: User, requestMessage: FollowMeRequestMessage) {
console.log("Handling follow me request message");
console.log(user.name);
// Find group including the requesting user
let foundGroups = room.getGroups().filter((grp) => grp.includes(user));
if (!foundGroups[0]) {
return;
}
let group = foundGroups[0];
// Send invitations to other group members
requestMessage.setPlayername(user.name);
room.getUsers().forEach((recipient) => {
const clientMessage = new ServerToClientMessage();
clientMessage.setFollowmerequestmessage(requestMessage);
recipient.socket.write(clientMessage);
const clientMessage = new ServerToClientMessage();
clientMessage.setFollowmerequestmessage(requestMessage);
group.getUsers().forEach((currentUser: User) => {
if (user.name !== currentUser.name) {
console.log("Inviting " + currentUser.name + " to follow " + user.name);
currentUser.socket.write(clientMessage);
}
});
}
}