Merge branch 'master' into develop

# Conflicts:
#	front/src/Connexion/RoomConnection.ts
#	front/src/Phaser/Menu/ReportMenu.ts
This commit is contained in:
Gregoire Parant 2021-03-11 02:22:05 +01:00
commit 2fcb8a76b1
8 changed files with 100 additions and 93 deletions

View file

@ -176,7 +176,7 @@ const roomManager: IRoomManagerServer = {
}, },
ban(call: ServerUnaryCall<BanMessage>, callback: sendUnaryData<EmptyMessage>): void { ban(call: ServerUnaryCall<BanMessage>, callback: sendUnaryData<EmptyMessage>): void {
// FIXME Work in progress // 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()); callback(null, new EmptyMessage());
}, },

View file

@ -690,7 +690,7 @@ export class SocketManager {
public sendAdminMessage(roomId: string, recipientUuid: string, message: string): void { public sendAdminMessage(roomId: string, recipientUuid: string, message: string): void {
const room = this.rooms.get(roomId); const room = this.rooms.get(roomId);
if (!room) { 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; return;
} }
@ -704,10 +704,10 @@ export class SocketManager {
sendUserMessage.setMessage(message); sendUserMessage.setMessage(message);
sendUserMessage.setType('ban'); //todo: is the type correct? sendUserMessage.setType('ban'); //todo: is the type correct?
const subToPusherMessage = new SubToPusherMessage(); const serverToClientMessage = new ServerToClientMessage();
subToPusherMessage.setSendusermessage(sendUserMessage); serverToClientMessage.setSendusermessage(sendUserMessage);
recipient.socket.write(subToPusherMessage); recipient.socket.write(serverToClientMessage);
} }
public banUser(roomId: string, recipientUuid: string, message: string): void { public banUser(roomId: string, recipientUuid: string, message: string): void {
@ -726,16 +726,15 @@ export class SocketManager {
// Let's leave the room now. // Let's leave the room now.
room.leave(recipient); room.leave(recipient);
const sendUserMessage = new SendUserMessage(); const banUserMessage = new BanUserMessage();
sendUserMessage.setMessage(message); banUserMessage.setMessage(message);
sendUserMessage.setType('banned'); banUserMessage.setType('banned');
const subToPusherMessage = new SubToPusherMessage(); const serverToClientMessage = new ServerToClientMessage();
subToPusherMessage.setSendusermessage(sendUserMessage); serverToClientMessage.setBanusermessage(banUserMessage);
recipient.socket.write(subToPusherMessage);
// Let's close the connection when the user is banned. // Let's close the connection when the user is banned.
recipient.socket.write(serverToClientMessage);
recipient.socket.end(); recipient.socket.end();
} }

View file

@ -1,5 +1,5 @@
import {Subject} from "rxjs"; import {Subject} from "rxjs";
import {SendUserMessage} from "../Messages/generated/messages_pb"; import {BanUserMessage, SendUserMessage} from "../Messages/generated/messages_pb";
export enum AdminMessageEventTypes { export enum AdminMessageEventTypes {
admin = 'message', admin = 'message',
@ -23,7 +23,7 @@ class AdminMessagesService {
this.messageStream.subscribe((event) => console.log('message', event)) this.messageStream.subscribe((event) => console.log('message', event))
} }
onSendusermessage(message: SendUserMessage) { onSendusermessage(message: SendUserMessage|BanUserMessage) {
this._messageStream.next({ this._messageStream.next({
type: message.getType() as unknown as AdminMessageEventTypes, type: message.getType() as unknown as AdminMessageEventTypes,
text: message.getMessage(), text: message.getMessage(),

View file

@ -27,7 +27,7 @@ import {
SendJitsiJwtMessage, SendJitsiJwtMessage,
CharacterLayerMessage, CharacterLayerMessage,
PingMessage, PingMessage,
SendUserMessage SendUserMessage, BanUserMessage
} from "../Messages/generated/messages_pb" } from "../Messages/generated/messages_pb"
import {UserSimplePeerInterface} from "../WebRtc/SimplePeer"; import {UserSimplePeerInterface} from "../WebRtc/SimplePeer";
@ -177,6 +177,8 @@ export class RoomConnection implements RoomConnection {
this.dispatch(EventMessage.START_JITSI_ROOM, message.getSendjitsijwtmessage()); this.dispatch(EventMessage.START_JITSI_ROOM, message.getSendjitsijwtmessage());
} else if (message.hasSendusermessage()) { } else if (message.hasSendusermessage()) {
adminMessagesService.onSendusermessage(message.getSendusermessage() as SendUserMessage); adminMessagesService.onSendusermessage(message.getSendusermessage() as SendUserMessage);
} else if (message.hasBanusermessage()) {
adminMessagesService.onSendusermessage(message.getSendusermessage() as BanUserMessage);
} else { } else {
throw new Error('Unknown message received'); throw new Error('Unknown message received');
} }

View file

@ -104,8 +104,7 @@ export class ReportMenu extends Phaser.GameObjects.DOMElement {
gamePError.innerText = ''; gamePError.innerText = '';
gamePError.style.display = 'none'; gamePError.style.display = 'none';
const gameTextArea = this.getChildByID('gameReportInput') as HTMLInputElement; const gameTextArea = this.getChildByID('gameReportInput') as HTMLInputElement;
const gameIdUserReported = this.getChildByID('idUserReported') as HTMLInputElement; if(!gameTextArea || !gameTextArea.value){
if(!gameTextArea || !gameTextArea.value ){
gamePError.innerText = 'Report message cannot to be empty.'; gamePError.innerText = 'Report message cannot to be empty.';
gamePError.style.display = 'block'; gamePError.style.display = 'block';
return; return;
@ -116,4 +115,4 @@ export class ReportMenu extends Phaser.GameObjects.DOMElement {
); );
this.close(); this.close();
} }
} }

View file

@ -350,6 +350,7 @@ message AdminMessage {
string message = 1; string message = 1;
string recipientUuid = 2; string recipientUuid = 2;
string roomId = 3; string roomId = 3;
string type = 4;
} }
// A message sent by an administrator to everyone in a specific room // A message sent by an administrator to everyone in a specific room
@ -366,6 +367,8 @@ message AdminGlobalMessage {
message BanMessage { message BanMessage {
string recipientUuid = 1; string recipientUuid = 1;
string roomId = 2; string roomId = 2;
string type = 3;
string message = 4;
} }
message EmptyMessage { message EmptyMessage {

View file

@ -76,10 +76,10 @@ export class IoSocketController {
if(message.event === 'user-message') { if(message.event === 'user-message') {
const messageToEmit = (message.message as { message: string, type: string, userUuid: string }); const messageToEmit = (message.message as { message: string, type: string, userUuid: string });
if(messageToEmit.type === 'banned'){ 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') { 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) { }catch (err) {

View file

@ -22,7 +22,7 @@ import {
AdminPusherToBackMessage, AdminPusherToBackMessage,
ServerToAdminClientMessage, ServerToAdminClientMessage,
SendUserMessage, SendUserMessage,
BanUserMessage, UserJoinedRoomMessage, UserLeftRoomMessage BanUserMessage, UserJoinedRoomMessage, UserLeftRoomMessage, AdminMessage, BanMessage
} from "../Messages/generated/messages_pb"; } from "../Messages/generated/messages_pb";
import {ProtobufUtils} from "../Model/Websocket/ProtobufUtils"; import {ProtobufUtils} from "../Model/Websocket/ProtobufUtils";
import {JITSI_ISS, SECRET_JITSI_KEY} from "../Enum/EnvironmentVariable"; import {JITSI_ISS, SECRET_JITSI_KEY} from "../Enum/EnvironmentVariable";
@ -434,90 +434,94 @@ export class SocketManager implements ZoneEventListener {
public handleQueryJitsiJwtMessage(client: ExSocketInterface, queryJitsiJwtMessage: QueryJitsiJwtMessage) { public handleQueryJitsiJwtMessage(client: ExSocketInterface, queryJitsiJwtMessage: QueryJitsiJwtMessage) {
const room = queryJitsiJwtMessage.getJitsiroom(); try {
const tag = queryJitsiJwtMessage.getTag(); // FIXME: this is not secure. We should load the JSON for the current room and check rights associated to room instead. const room = queryJitsiJwtMessage.getJitsiroom();
const tag = queryJitsiJwtMessage.getTag(); // FIXME: this is not secure. We should load the JSON for the current room and check rights associated to room instead.
if (SECRET_JITSI_KEY === '') { if (SECRET_JITSI_KEY === '') {
throw new Error('You must set the SECRET_JITSI_KEY key to the secret to generate JWT tokens for Jitsi.'); throw new Error('You must set the SECRET_JITSI_KEY key to the secret to generate JWT tokens for Jitsi.');
}
// Let's see if the current client has
const isAdmin = client.tags.includes(tag);
const jwt = Jwt.sign({
"aud": "jitsi",
"iss": JITSI_ISS,
"sub": JITSI_URL,
"room": room,
"moderator": isAdmin
}, SECRET_JITSI_KEY, {
expiresIn: '1d',
algorithm: "HS256",
header:
{
"alg": "HS256",
"typ": "JWT"
}
});
const sendJitsiJwtMessage = new SendJitsiJwtMessage();
sendJitsiJwtMessage.setJitsiroom(room);
sendJitsiJwtMessage.setJwt(jwt);
const serverToClientMessage = new ServerToClientMessage();
serverToClientMessage.setSendjitsijwtmessage(sendJitsiJwtMessage);
client.send(serverToClientMessage.serializeBinary().buffer, true);
} catch (e) {
console.error('An error occured while generating the Jitsi JWT token: ', e);
}
}
public async emitSendUserMessage(userUuid: string, message: string, type: string, roomId: string) {
const client = this.searchClientByUuid(userUuid);
if(client) {
const adminMessage = new SendUserMessage();
adminMessage.setMessage(message);
adminMessage.setType(type);
const pusherToBackMessage = new PusherToBackMessage();
pusherToBackMessage.setSendusermessage(adminMessage);
client.backConnection.write(pusherToBackMessage);
return;
} }
// Let's see if the current client has const backConnection = await apiClientRepository.getClient(roomId);
const isAdmin = client.tags.includes(tag); const backAdminMessage = new AdminMessage();
backAdminMessage.setMessage(message);
const jwt = Jwt.sign({ backAdminMessage.setRoomid(roomId);
"aud": "jitsi", backAdminMessage.setRecipientuuid(userUuid);
"iss": JITSI_ISS, backAdminMessage.setType(type);
"sub": JITSI_URL, backConnection.sendAdminMessage(backAdminMessage, (error) => {
"room": room, if (error !== null) {
"moderator": isAdmin console.error('Error while sending admin message', error);
}, SECRET_JITSI_KEY, { }
expiresIn: '1d',
algorithm: "HS256",
header:
{
"alg": "HS256",
"typ": "JWT"
}
}); });
const sendJitsiJwtMessage = new SendJitsiJwtMessage();
sendJitsiJwtMessage.setJitsiroom(room);
sendJitsiJwtMessage.setJwt(jwt);
const serverToClientMessage = new ServerToClientMessage();
serverToClientMessage.setSendjitsijwtmessage(sendJitsiJwtMessage);
client.send(serverToClientMessage.serializeBinary().buffer, true);
} }
public emitSendUserMessage(userUuid: string, message: string, type: string): void { public async emitBan(userUuid: string, message: string, type: string, roomId: string) {
const client = this.searchClientByUuid(userUuid); const client = this.searchClientByUuid(userUuid);
if(!client){ if(client) {
throw Error('client not found'); const banUserMessage = new BanUserMessage();
banUserMessage.setMessage(message);
banUserMessage.setType(type);
const pusherToBackMessage = new PusherToBackMessage();
pusherToBackMessage.setBanusermessage(banUserMessage);
client.backConnection.write(pusherToBackMessage);
return;
} }
const adminMessage = new SendUserMessage(); const backConnection = await apiClientRepository.getClient(roomId);
adminMessage.setMessage(message); const banMessage = new BanMessage();
adminMessage.setType(type); banMessage.setMessage(message);
const pusherToBackMessage = new PusherToBackMessage(); banMessage.setRoomid(roomId);
pusherToBackMessage.setSendusermessage(adminMessage); banMessage.setRecipientuuid(userUuid);
client.backConnection.write(pusherToBackMessage); banMessage.setType(type);
backConnection.ban(banMessage, (error) => {
/*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) => {
if (error !== null) { if (error !== null) {
console.error('Error while sending admin message', error); console.error('Error while sending admin message', error);
} }
});*/ });
}
public emitBan(userUuid: string, message: string, type: string): void {
const client = this.searchClientByUuid(userUuid);
if(!client){
throw Error('client not found');
}
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) => {
if (error !== null) {
console.error('Error while sending admin message', error);
}
});*/
} }
/** /**