From 46cb9333e69550d6158a5172f512a5e4f7cd4c54 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Thu, 11 Mar 2021 01:25:36 +0100 Subject: [PATCH 1/2] HotFix message in back --- back/src/RoomManager.ts | 2 +- back/src/Services/SocketManager.ts | 21 +++---- front/src/Connexion/RoomConnection.ts | 2 + messages/protos/messages.proto | 3 + pusher/src/Controller/IoSocketController.ts | 4 +- pusher/src/Services/SocketManager.ts | 70 ++++++++++----------- 6 files changed, 53 insertions(+), 49 deletions(-) diff --git a/back/src/RoomManager.ts b/back/src/RoomManager.ts index b6a82850..bc3e5313 100644 --- a/back/src/RoomManager.ts +++ b/back/src/RoomManager.ts @@ -204,7 +204,7 @@ const roomManager: IRoomManagerServer = { }, ban(call: ServerUnaryCall, callback: sendUnaryData): void { // FIXME Work in progress - socketManager.banUser(call.request.getRoomid(), call.request.getRecipientuuid(), 'foo bar TODO change this'); + socketManager.banUser(call.request.getRoomid(), call.request.getRecipientuuid(), call.request.getMessage()); callback(null, new EmptyMessage()); }, diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index 3d6906ea..302900ac 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -795,7 +795,7 @@ export class SocketManager { public sendAdminMessage(roomId: string, recipientUuid: string, message: string): void { const room = this.rooms.get(roomId); if (!room) { - console.error("In sendAdminMessage, could not find room with id '" + roomId + "'. Maybe the room was closed a few milliseconds ago and there was a race condition?"); + console.error("In sendAdminMessage, could not find room with id '" + roomId + "'. Maybe the room was closed a few milliseconds ago and there was a race condition?"); return; } @@ -809,10 +809,10 @@ export class SocketManager { sendUserMessage.setMessage(message); sendUserMessage.setType('ban'); - const subToPusherMessage = new SubToPusherMessage(); - subToPusherMessage.setSendusermessage(sendUserMessage); + const serverToClientMessage = new ServerToClientMessage(); + serverToClientMessage.setSendusermessage(sendUserMessage); - recipient.socket.write(subToPusherMessage); + recipient.socket.write(serverToClientMessage); } public banUser(roomId: string, recipientUuid: string, message: string): void { @@ -831,16 +831,15 @@ export class SocketManager { // Let's leave the room now. room.leave(recipient); - const sendUserMessage = new SendUserMessage(); - sendUserMessage.setMessage(message); - sendUserMessage.setType('banned'); + const banUserMessage = new BanUserMessage(); + banUserMessage.setMessage(message); + banUserMessage.setType('banned'); - const subToPusherMessage = new SubToPusherMessage(); - subToPusherMessage.setSendusermessage(sendUserMessage); - - recipient.socket.write(subToPusherMessage); + const serverToClientMessage = new ServerToClientMessage(); + serverToClientMessage.setBanusermessage(banUserMessage); // Let's close the connection when the user is banned. + recipient.socket.write(serverToClientMessage); recipient.socket.end(); } } diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index cebd7606..b5fb91ba 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -186,6 +186,8 @@ export class RoomConnection implements RoomConnection { this.dispatch(EventMessage.START_JITSI_ROOM, message.getSendjitsijwtmessage()); } else if (message.hasSendusermessage()) { this.dispatch(EventMessage.USER_MESSAGE, message.getSendusermessage()); + } else if (message.hasBanusermessage()) { + this.dispatch(EventMessage.USER_MESSAGE, message.getBanusermessage()); } else { throw new Error('Unknown message received'); } diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto index 54b425f9..c34bbfb0 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -349,6 +349,7 @@ message AdminMessage { string message = 1; string recipientUuid = 2; string roomId = 3; + string type = 4; } // A message sent by an administrator to absolutely everybody @@ -359,6 +360,8 @@ message AdminGlobalMessage { message BanMessage { string recipientUuid = 1; string roomId = 2; + string type = 3; + string message = 4; } message EmptyMessage { diff --git a/pusher/src/Controller/IoSocketController.ts b/pusher/src/Controller/IoSocketController.ts index a43f43ba..da6bb10e 100644 --- a/pusher/src/Controller/IoSocketController.ts +++ b/pusher/src/Controller/IoSocketController.ts @@ -92,10 +92,10 @@ export class IoSocketController { if(message.event === 'user-message') { const messageToEmit = (message.message as { message: string, type: string, userUuid: string }); if(messageToEmit.type === 'banned'){ - socketManager.emitBan(messageToEmit.userUuid, messageToEmit.message, messageToEmit.type); + socketManager.emitBan(messageToEmit.userUuid, messageToEmit.message, messageToEmit.type, ws.roomId as string); } if(messageToEmit.type === 'ban') { - socketManager.emitSendUserMessage(messageToEmit.userUuid, messageToEmit.message, messageToEmit.type); + socketManager.emitSendUserMessage(messageToEmit.userUuid, messageToEmit.message, messageToEmit.type, ws.roomId as string); } } }catch (err) { diff --git a/pusher/src/Services/SocketManager.ts b/pusher/src/Services/SocketManager.ts index 3286dbcb..748d2d54 100644 --- a/pusher/src/Services/SocketManager.ts +++ b/pusher/src/Services/SocketManager.ts @@ -23,7 +23,7 @@ import { AdminPusherToBackMessage, ServerToAdminClientMessage, SendUserMessage, - BanUserMessage, UserJoinedRoomMessage, UserLeftRoomMessage + BanUserMessage, UserJoinedRoomMessage, UserLeftRoomMessage, AdminMessage, BanMessage } from "../Messages/generated/messages_pb"; import {PointInterface} from "../Model/Websocket/PointInterface"; import {ProtobufUtils} from "../Model/Websocket/ProtobufUtils"; @@ -549,54 +549,54 @@ export class SocketManager implements ZoneEventListener { } } - public emitSendUserMessage(userUuid: string, message: string, type: string): void { + public async emitSendUserMessage(userUuid: string, message: string, type: string, roomId: string) { const client = this.searchClientByUuid(userUuid); - if(!client){ - throw Error('client not found'); + if(client) { + const adminMessage = new SendUserMessage(); + adminMessage.setMessage(message); + adminMessage.setType(type); + const pusherToBackMessage = new PusherToBackMessage(); + pusherToBackMessage.setSendusermessage(adminMessage); + client.backConnection.write(pusherToBackMessage); + return; } - const adminMessage = new SendUserMessage(); - adminMessage.setMessage(message); - adminMessage.setType(type); - const pusherToBackMessage = new PusherToBackMessage(); - pusherToBackMessage.setSendusermessage(adminMessage); - client.backConnection.write(pusherToBackMessage); - - /*const backConnection = await apiClientRepository.getClient(client.roomId); - const adminMessage = new AdminMessage(); - adminMessage.setMessage(message); - adminMessage.setRoomid(client.roomId); - adminMessage.setRecipientuuid(client.userUuid); - backConnection.sendAdminMessage(adminMessage, (error) => { + const backConnection = await apiClientRepository.getClient(roomId); + const backAdminMessage = new AdminMessage(); + backAdminMessage.setMessage(message); + backAdminMessage.setRoomid(roomId); + backAdminMessage.setRecipientuuid(userUuid); + backAdminMessage.setType(type); + backConnection.sendAdminMessage(backAdminMessage, (error) => { if (error !== null) { console.error('Error while sending admin message', error); } - });*/ + }); } - public emitBan(userUuid: string, message: string, type: string): void { + public async emitBan(userUuid: string, message: string, type: string, roomId: string) { const client = this.searchClientByUuid(userUuid); - if(!client){ - throw Error('client not found'); + if(client) { + const banUserMessage = new BanUserMessage(); + banUserMessage.setMessage(message); + banUserMessage.setType(type); + const pusherToBackMessage = new PusherToBackMessage(); + pusherToBackMessage.setBanusermessage(banUserMessage); + client.backConnection.write(pusherToBackMessage); + return; } - const banUserMessage = new BanUserMessage(); - banUserMessage.setMessage(message); - banUserMessage.setType(type); - const pusherToBackMessage = new PusherToBackMessage(); - pusherToBackMessage.setBanusermessage(banUserMessage); - client.backConnection.write(pusherToBackMessage); - - /*const backConnection = await apiClientRepository.getClient(client.roomId); - const adminMessage = new AdminMessage(); - adminMessage.setMessage(message); - adminMessage.setRoomid(client.roomId); - adminMessage.setRecipientuuid(client.userUuid); - backConnection.sendAdminMessage(adminMessage, (error) => { + const backConnection = await apiClientRepository.getClient(roomId); + const banMessage = new BanMessage(); + banMessage.setMessage(message); + banMessage.setRoomid(roomId); + banMessage.setRecipientuuid(userUuid); + banMessage.setType(type); + backConnection.ban(banMessage, (error) => { if (error !== null) { console.error('Error while sending admin message', error); } - });*/ + }); } /** From 2cf99df2da81122156fa9b6d7b608ebf7365d6a5 Mon Sep 17 00:00:00 2001 From: Gregoire Parant Date: Thu, 11 Mar 2021 02:03:06 +0100 Subject: [PATCH 2/2] Hot Fix report --- front/src/Phaser/Menu/ReportMenu.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/front/src/Phaser/Menu/ReportMenu.ts b/front/src/Phaser/Menu/ReportMenu.ts index bee86c35..0795debe 100644 --- a/front/src/Phaser/Menu/ReportMenu.ts +++ b/front/src/Phaser/Menu/ReportMenu.ts @@ -104,14 +104,13 @@ export class ReportMenu extends Phaser.GameObjects.DOMElement { gamePError.innerText = ''; gamePError.style.display = 'none'; const gameTextArea = this.getChildByID('gameReportInput') as HTMLInputElement; - const gameIdUserReported = this.getChildByID('idUserReported') as HTMLInputElement; - if(!gameTextArea || !gameTextArea.value || !gameIdUserReported || !gameIdUserReported.value){ + if(!gameTextArea || !gameTextArea.value){ gamePError.innerText = 'Report message cannot to be empty.'; gamePError.style.display = 'block'; return; } gameManager.getCurrentGameScene(this.scene).connection.emitReportPlayerMessage( - parseInt(gameIdUserReported.value), + this.userId, gameTextArea.value ); this.close();