diff --git a/back/src/RoomManager.ts b/back/src/RoomManager.ts index 9aaf1edb..7bde839c 100644 --- a/back/src/RoomManager.ts +++ b/back/src/RoomManager.ts @@ -212,7 +212,7 @@ const roomManager: IRoomManagerServer = { callback(null, new EmptyMessage()); }, sendAdminMessageToRoom(call: ServerUnaryCall, callback: sendUnaryData): void { - socketManager.sendAdminRoomMessage(call.request.getRoomid(), call.request.getMessage()); + socketManager.sendAdminRoomMessage(call.request.getRoomid(), call.request.getMessage(), call.request.getType()); callback(null, new EmptyMessage()); }, sendWorldFullWarningToRoom( diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index 5e45c975..8b05863b 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -731,7 +731,7 @@ export class SocketManager { recipient.socket.end(); } - sendAdminRoomMessage(roomId: string, message: string) { + sendAdminRoomMessage(roomId: string, message: string, type: string) { const room = this.rooms.get(roomId); if (!room) { //todo: this should cause the http call to return a 500 @@ -746,7 +746,7 @@ export class SocketManager { room.getUsers().forEach((recipient) => { const sendUserMessage = new SendUserMessage(); sendUserMessage.setMessage(message); - sendUserMessage.setType("message"); + sendUserMessage.setType(type); const clientMessage = new ServerToClientMessage(); clientMessage.setSendusermessage(sendUserMessage); diff --git a/front/src/Administration/GlobalMessageManager.ts b/front/src/Administration/GlobalMessageManager.ts deleted file mode 100644 index aae695fa..00000000 --- a/front/src/Administration/GlobalMessageManager.ts +++ /dev/null @@ -1,92 +0,0 @@ -import {HtmlUtils} from "./../WebRtc/HtmlUtils"; -import {PUSHER_URL, UPLOADER_URL} from "../Enum/EnvironmentVariable"; -import type {RoomConnection} from "../Connexion/RoomConnection"; -import type {PlayGlobalMessageInterface} from "../Connexion/ConnexionModels"; -import {soundPlayingStore} from "../Stores/SoundPlayingStore"; -import {soundManager} from "../Phaser/Game/SoundManager"; -import {AdminMessageEventTypes} from "../Connexion/AdminMessagesService"; - -export class GlobalMessageManager { - - constructor(private Connection: RoomConnection) { - this.initialise(); - } - - initialise(){ - //receive signal to show message - this.Connection.receivePlayGlobalMessage((message: PlayGlobalMessageInterface) => { - this.playMessage(message); - }); - - //receive signal to close message - this.Connection.receiveStopGlobalMessage((messageId: string) => { - this.stopMessage(messageId); - }); - - //receive signal to close message - this.Connection.receiveTeleportMessage((map: string) => { - console.log('map to teleport user', map); - //TODO teleport user on map - }); - } - - private playMessage(message : PlayGlobalMessageInterface){ - const previousMessage = document.getElementById(this.getHtmlMessageId(message.id)); - if(previousMessage){ - previousMessage.remove(); - } - - if(AdminMessageEventTypes.audio === message.type){ - this.playAudioMessage(message.id, message.message); - } - - if(AdminMessageEventTypes.admin === message.type){ - this.playTextMessage(message.id, message.message); - } - } - - private playAudioMessage(messageId : string, urlMessage: string) { - soundPlayingStore.playSound(UPLOADER_URL + urlMessage); - } - - private playTextMessage(messageId : string, htmlMessage: string){ - //add button to clear message - const buttonText = document.createElement('p'); - buttonText.id = 'button-clear-message'; - buttonText.innerText = 'Clear'; - - const buttonMainConsole = document.createElement('div'); - buttonMainConsole.classList.add('clear'); - buttonMainConsole.appendChild(buttonText); - buttonMainConsole.addEventListener('click', () => { - messageContainer.style.top = '-80%'; - setTimeout(() => { - messageContainer.remove(); - buttonMainConsole.remove(); - }); - }); - - //create content message - const messageCotent = document.createElement('div'); - messageCotent.innerHTML = htmlMessage; - messageCotent.className = "content-message"; - - //add message container - const messageContainer = document.createElement('div'); - messageContainer.id = this.getHtmlMessageId(messageId); - messageContainer.className = "message-container"; - messageContainer.appendChild(messageCotent); - messageContainer.appendChild(buttonMainConsole); - - const mainSectionDiv = HtmlUtils.getElementByIdOrFail('main-container'); - mainSectionDiv.appendChild(messageContainer); - } - - private stopMessage(messageId: string){ - HtmlUtils.removeElementByIdOrFail(this.getHtmlMessageId(messageId)); - } - - private getHtmlMessageId(messageId: string) : string{ - return `message-${messageId}`; - } -} diff --git a/front/src/Administration/TypeMessage.ts b/front/src/Administration/TypeMessage.ts deleted file mode 100644 index d735ba58..00000000 --- a/front/src/Administration/TypeMessage.ts +++ /dev/null @@ -1,95 +0,0 @@ -import type {TypeMessageInterface} from "./UserMessageManager"; -import {HtmlUtils} from "../WebRtc/HtmlUtils"; - -let modalTimeOut : NodeJS.Timeout; - -export class TypeMessageExt implements TypeMessageInterface{ - private nbSecond = 0; - private maxNbSecond = 10; - private titleMessage = 'IMPORTANT !'; - - showMessage(message: string, canDeleteMessage: boolean = true): void { - //delete previous modal - try{ - if(modalTimeOut){ - clearTimeout(modalTimeOut); - } - const modal = HtmlUtils.getElementByIdOrFail('report-message-user'); - modal.remove(); - }catch (err){ - console.error(err); - } - - //create new modal - const div : HTMLDivElement = document.createElement('div'); - div.classList.add('modal-report-user'); - div.id = 'report-message-user'; - div.style.backgroundColor = '#000000e0'; - - const img : HTMLImageElement = document.createElement('img'); - img.src = 'resources/logos/report.svg'; - div.appendChild(img); - - const title : HTMLParagraphElement = document.createElement('p'); - title.id = 'title-report-user'; - title.innerText = `${this.titleMessage} (${this.maxNbSecond})`; - div.appendChild(title); - - const p : HTMLParagraphElement = document.createElement('p'); - p.id = 'body-report-user' - p.innerText = message; - div.appendChild(p); - - const mainSectionDiv = HtmlUtils.getElementByIdOrFail('main-container'); - mainSectionDiv.appendChild(div); - - const reportMessageAudio = HtmlUtils.getElementByIdOrFail('report-message'); - // FIXME: this will fail on iOS - // We should move the sound playing into the GameScene and listen to the event of a report using a store - try { - reportMessageAudio.play(); - } catch (e) { - console.error(e); - } - - this.nbSecond = this.maxNbSecond; - setTimeout((c) => { - this.forMessage(title, canDeleteMessage); - }, 1000); - } - - forMessage(title: HTMLParagraphElement, canDeleteMessage: boolean = true){ - this.nbSecond -= 1; - title.innerText = `${this.titleMessage} (${this.nbSecond})`; - if(this.nbSecond > 0){ - modalTimeOut = setTimeout(() => { - this.forMessage(title, canDeleteMessage); - }, 1000); - }else { - title.innerText = this.titleMessage; - - if (!canDeleteMessage) { - return; - } - const imgCancel: HTMLImageElement = document.createElement('img'); - imgCancel.id = 'cancel-report-user'; - imgCancel.src = 'resources/logos/close.svg'; - - const div = HtmlUtils.getElementByIdOrFail('report-message-user'); - div.appendChild(imgCancel); - imgCancel.addEventListener('click', () => { - div.remove(); - }); - } - } -} - -export class Message extends TypeMessageExt {} - -export class Ban extends TypeMessageExt {} - -export class Banned extends TypeMessageExt { - showMessage(message: string){ - super.showMessage(message, false); - } -} diff --git a/front/src/Administration/UserMessageManager.ts b/front/src/Administration/UserMessageManager.ts index ec02ac3b..42c31083 100644 --- a/front/src/Administration/UserMessageManager.ts +++ b/front/src/Administration/UserMessageManager.ts @@ -1,43 +1,34 @@ -import * as TypeMessages from "./TypeMessage"; -import {Banned} from "./TypeMessage"; -import {adminMessagesService} from "../Connexion/AdminMessagesService"; - -export interface TypeMessageInterface { - showMessage(message: string): void; -} +import { AdminMessageEventTypes, adminMessagesService } from "../Connexion/AdminMessagesService"; +import { textMessageContentStore, textMessageVisibleStore } from "../Stores/TypeMessageStore/TextMessageStore"; +import { soundPlayingStore } from "../Stores/SoundPlayingStore"; +import { UPLOADER_URL } from "../Enum/EnvironmentVariable"; +import { banMessageContentStore, banMessageVisibleStore } from "../Stores/TypeMessageStore/BanMessageStore"; class UserMessageManager { - - typeMessages: Map = new Map(); receiveBannedMessageListener!: Function; constructor() { - const valueTypeMessageTab = Object.values(TypeMessages); - Object.keys(TypeMessages).forEach((value: string, index: number) => { - const typeMessageInstance: TypeMessageInterface = (new valueTypeMessageTab[index]() as TypeMessageInterface); - this.typeMessages.set(value.toLowerCase(), typeMessageInstance); - }); - adminMessagesService.messageStream.subscribe((event) => { - const typeMessage = this.showMessage(event.type, event.text); - if(typeMessage instanceof Banned) { + textMessageVisibleStore.set(false); + banMessageVisibleStore.set(false); + if (event.type === AdminMessageEventTypes.admin) { + textMessageContentStore.set(event.text); + textMessageVisibleStore.set(true); + } else if (event.type === AdminMessageEventTypes.audio) { + soundPlayingStore.playSound(UPLOADER_URL + event.text); + } else if (event.type === AdminMessageEventTypes.ban) { + banMessageContentStore.set(event.text); + banMessageVisibleStore.set(true); + } else if (event.type === AdminMessageEventTypes.banned) { + banMessageContentStore.set(event.text); + banMessageVisibleStore.set(true); this.receiveBannedMessageListener(); } - }) + }); } - showMessage(type: string, message: string) { - const classTypeMessage = this.typeMessages.get(type.toLowerCase()); - if (!classTypeMessage) { - console.error('Message unknown'); - return; - } - classTypeMessage.showMessage(message); - return classTypeMessage; - } - - setReceiveBanListener(callback: Function){ + setReceiveBanListener(callback: Function) { this.receiveBannedMessageListener = callback; } } -export const userMessageManager = new UserMessageManager() \ No newline at end of file +export const userMessageManager = new UserMessageManager(); diff --git a/front/src/Components/App.svelte b/front/src/Components/App.svelte index 0f808074..095b9399 100644 --- a/front/src/Components/App.svelte +++ b/front/src/Components/App.svelte @@ -27,6 +27,10 @@ import {gameOverlayVisibilityStore} from "../Stores/GameOverlayStoreVisibility"; import {consoleGlobalMessageManagerVisibleStore} from "../Stores/ConsoleGlobalMessageManagerStore"; import ConsoleGlobalMessageManager from "./ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte"; + import AdminMessage from "./TypeMessage/BanMessage.svelte"; + import TextMessage from "./TypeMessage/TextMessage.svelte"; + import {banMessageVisibleStore} from "../Stores/TypeMessageStore/BanMessageStore"; + import {textMessageVisibleStore} from "../Stores/TypeMessageStore/TextMessageStore"; export let game: Game; @@ -58,6 +62,16 @@ {/if} + {#if $banMessageVisibleStore} +
+ +
+ {/if} + {#if $textMessageVisibleStore} +
+ +
+ {/if} {#if $soundPlayingStore}
diff --git a/front/src/Components/ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte b/front/src/Components/ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte index 69d1dcee..c1811650 100644 --- a/front/src/Components/ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte +++ b/front/src/Components/ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte @@ -10,7 +10,7 @@ let inputSendTextActive = true; let uploadMusicActive = false; let handleSendText: { sendTextMessage(broadcast: boolean): void }; - let handleSendAudio: { sendAudioMessage(): Promise }; + let handleSendAudio: { sendAudioMessage(broadcast: boolean): Promise }; let broadcastToWorld = false; function closeConsoleGlobalMessage() { @@ -38,7 +38,7 @@ handleSendText.sendTextMessage(broadcastToWorld); } if (uploadMusicActive) { - handleSendAudio.sendAudioMessage(); + handleSendAudio.sendAudioMessage(broadcastToWorld); } } diff --git a/front/src/Components/ConsoleGlobalMessageManager/InputTextGlobalMessage.svelte b/front/src/Components/ConsoleGlobalMessageManager/InputTextGlobalMessage.svelte index 424d4f7f..62dc6011 100644 --- a/front/src/Components/ConsoleGlobalMessageManager/InputTextGlobalMessage.svelte +++ b/front/src/Components/ConsoleGlobalMessageManager/InputTextGlobalMessage.svelte @@ -3,9 +3,9 @@ import { onMount } from "svelte"; import type { Game } from "../../Phaser/Game/Game"; import type { GameManager } from "../../Phaser/Game/GameManager"; - import type { UserGlobalMessageInterface } from "../../Connexion/ConnexionModels"; import { AdminMessageEventTypes } from "../../Connexion/AdminMessagesService"; import type { Quill } from "quill"; + import type { PlayGlobalMessageInterface } from "../../Connexion/ConnexionModels"; //toolbar const toolbarOptions = [ @@ -46,15 +46,19 @@ return; } const text = quill.getText(0, quill.getLength()); + const content = quill.getContents(0, quill.getLength()); - const textGlobalMessage: UserGlobalMessageInterface = { + console.log('Text : ', text); + console.log('Content : ', content); + + const textGlobalMessage: PlayGlobalMessageInterface = { type: MESSAGE_TYPE, content: text, broadcastToWorld: broadcastToWorld }; quill.deleteText(0, quill.getLength()); - gameScene.connection?.sendUserGlobalMessage(textGlobalMessage); + gameScene.connection?.emitGlobalMessage(textGlobalMessage); disableConsole(); } } diff --git a/front/src/Components/ConsoleGlobalMessageManager/UploadAudioGlobalMessage.svelte b/front/src/Components/ConsoleGlobalMessageManager/UploadAudioGlobalMessage.svelte index cae6bc7c..91f462c8 100644 --- a/front/src/Components/ConsoleGlobalMessageManager/UploadAudioGlobalMessage.svelte +++ b/front/src/Components/ConsoleGlobalMessageManager/UploadAudioGlobalMessage.svelte @@ -4,8 +4,8 @@ import type { GameManager } from "../../Phaser/Game/GameManager"; import { consoleGlobalMessageManagerFocusStore, consoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore"; import { AdminMessageEventTypes } from "../../Connexion/AdminMessagesService"; - import type { PlayGlobalMessageInterface } from "../../Connexion/ConnexionModels"; import uploadFile from "../images/music-file.svg"; + import type {PlayGlobalMessageInterface} from "../../Connexion/ConnexionModels"; interface EventTargetFiles extends EventTarget { files: Array; @@ -23,7 +23,7 @@ const AUDIO_TYPE = AdminMessageEventTypes.audio; export const handleSending = { - async sendAudioMessage() { + async sendAudioMessage(broadcast: boolean) { if (gameScene == undefined) { return; } @@ -38,13 +38,13 @@ fd.append('file', selectedFile); const res = await gameScene.connection?.uploadAudio(fd); - const GlobalMessage: PlayGlobalMessageInterface = { - id: (res as { id: string }).id, - message: (res as { path: string }).path, - type: AUDIO_TYPE + const audioGlobalMessage: PlayGlobalMessageInterface = { + content: (res as { path: string }).path, + type: AUDIO_TYPE, + broadcastToWorld: broadcast } inputAudio.value = ''; - gameScene.connection?.emitGlobalMessage(GlobalMessage); + gameScene.connection?.emitGlobalMessage(audioGlobalMessage); disableConsole(); } } diff --git a/front/src/Components/TypeMessage/BanMessage.svelte b/front/src/Components/TypeMessage/BanMessage.svelte new file mode 100644 index 00000000..ea9c4869 --- /dev/null +++ b/front/src/Components/TypeMessage/BanMessage.svelte @@ -0,0 +1,89 @@ + + +
+

*** Important message ***

+
+ {text} +
+ +
+ + + \ No newline at end of file diff --git a/front/src/Components/TypeMessage/TextMessage.svelte b/front/src/Components/TypeMessage/TextMessage.svelte new file mode 100644 index 00000000..1f2f9a48 --- /dev/null +++ b/front/src/Components/TypeMessage/TextMessage.svelte @@ -0,0 +1,57 @@ + + + + +
+
+

{text}

+
+ +
+ + \ No newline at end of file diff --git a/front/src/Connexion/ConnexionModels.ts b/front/src/Connexion/ConnexionModels.ts index c87f93e5..dbb9ad81 100644 --- a/front/src/Connexion/ConnexionModels.ts +++ b/front/src/Connexion/ConnexionModels.ts @@ -108,12 +108,6 @@ export interface RoomJoinedMessageInterface { } export interface PlayGlobalMessageInterface { - id: string; - type: string; - message: string; -} - -export interface UserGlobalMessageInterface { type: string; content: string; broadcastToWorld: boolean; diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index 6c84d7f9..8cae9f80 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -7,7 +7,6 @@ import { GroupUpdateMessage, ItemEventMessage, PlayGlobalMessage, - UserGlobalMessage, PositionMessage, RoomJoinedMessage, ServerToClientMessage, @@ -45,7 +44,6 @@ import { MessageUserJoined, OnConnectInterface, PlayGlobalMessageInterface, - UserGlobalMessageInterface, PositionInterface, RoomJoinedMessageInterface, ViewportInterface, @@ -560,7 +558,7 @@ export class RoomConnection implements RoomConnection { }); } - public receivePlayGlobalMessage(callback: (message: PlayGlobalMessageInterface) => void) { + /* public receivePlayGlobalMessage(callback: (message: PlayGlobalMessageInterface) => void) { return this.onMessage(EventMessage.PLAY_GLOBAL_MESSAGE, (message: PlayGlobalMessage) => { callback({ id: message.getId(), @@ -568,7 +566,7 @@ export class RoomConnection implements RoomConnection { message: message.getMessage(), }); }); - } + }*/ public receiveStopGlobalMessage(callback: (messageId: string) => void) { return this.onMessage(EventMessage.STOP_GLOBAL_MESSAGE, (message: StopGlobalMessage) => { @@ -582,11 +580,11 @@ export class RoomConnection implements RoomConnection { }); } - public emitGlobalMessage(message: PlayGlobalMessageInterface) { + public emitGlobalMessage(message: PlayGlobalMessageInterface): void { const playGlobalMessage = new PlayGlobalMessage(); - playGlobalMessage.setId(message.id); playGlobalMessage.setType(message.type); - playGlobalMessage.setMessage(message.message); + playGlobalMessage.setContent(message.content); + playGlobalMessage.setBroadcasttoworld(message.broadcastToWorld); const clientToServerMessage = new ClientToServerMessage(); clientToServerMessage.setPlayglobalmessage(playGlobalMessage); @@ -645,16 +643,4 @@ export class RoomConnection implements RoomConnection { public getAllTags(): string[] { return this.tags; } - - public sendUserGlobalMessage(message: UserGlobalMessageInterface): void { - const userGlobalMessage = new UserGlobalMessage(); - userGlobalMessage.setType(message.type); - userGlobalMessage.setContent(message.content); - userGlobalMessage.setBroadcasttoworld(message.broadcastToWorld); - - const clientToServerMessage = new ClientToServerMessage(); - clientToServerMessage.setUserglobalmessage(userGlobalMessage); - - this.socket.send(clientToServerMessage.serializeBinary().buffer); - } } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index dfecc0c8..91ed7152 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -1,5 +1,4 @@ import type { Subscription } from "rxjs"; -import { GlobalMessageManager } from "../../Administration/GlobalMessageManager"; import { userMessageManager } from "../../Administration/UserMessageManager"; import { iframeListener } from "../../Api/IframeListener"; import { connectionManager } from "../../Connexion/ConnectionManager"; @@ -160,7 +159,6 @@ export class GameScene extends DirtyScene { private playersPositionInterpolator = new PlayersPositionInterpolator(); public connection: RoomConnection | undefined; private simplePeer!: SimplePeer; - private GlobalMessageManager!: GlobalMessageManager; private connectionAnswerPromise: Promise; private connectionAnswerPromiseResolve!: ( value: RoomJoinedMessageInterface | PromiseLike @@ -694,7 +692,6 @@ export class GameScene extends DirtyScene { peerStore.connectToSimplePeer(this.simplePeer); screenSharingPeerStore.connectToSimplePeer(this.simplePeer); videoFocusStore.connectToSimplePeer(this.simplePeer); - this.GlobalMessageManager = new GlobalMessageManager(this.connection); userMessageManager.setReceiveBanListener(this.bannedUser.bind(this)); const self = this; diff --git a/front/src/Stores/TypeMessageStore/BanMessageStore.ts b/front/src/Stores/TypeMessageStore/BanMessageStore.ts new file mode 100644 index 00000000..b8c042b4 --- /dev/null +++ b/front/src/Stores/TypeMessageStore/BanMessageStore.ts @@ -0,0 +1,5 @@ +import { writable } from "svelte/store"; + +export const banMessageVisibleStore = writable(false); + +export const banMessageContentStore = writable(""); diff --git a/front/src/Stores/TypeMessageStore/TextMessageStore.ts b/front/src/Stores/TypeMessageStore/TextMessageStore.ts new file mode 100644 index 00000000..e3969016 --- /dev/null +++ b/front/src/Stores/TypeMessageStore/TextMessageStore.ts @@ -0,0 +1,5 @@ +import { writable } from "svelte/store"; + +export const textMessageVisibleStore = writable(false); + +export const textMessageContentStore = writable(""); diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto index 90dc587a..a62815e0 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -94,7 +94,6 @@ message ClientToServerMessage { ReportPlayerMessage reportPlayerMessage = 11; QueryJitsiJwtMessage queryJitsiJwtMessage = 12; EmotePromptMessage emotePromptMessage = 13; - UserGlobalMessage userGlobalMessage = 14; } } @@ -109,12 +108,6 @@ message ItemEventMessage { } message PlayGlobalMessage { - string id = 1; - string type = 2; - string message = 3; -} - -message UserGlobalMessage { string type = 1; string content = 2; bool broadcastToWorld = 3; @@ -267,7 +260,6 @@ message ServerToClientMessage { RefreshRoomMessage refreshRoomMessage = 17; WorldConnexionMessage worldConnexionMessage = 18; EmoteEventMessage emoteEventMessage = 19; - UserGlobalMessage userGlobalMessage = 20; } } @@ -342,7 +334,6 @@ message PusherToBackMessage { SendUserMessage sendUserMessage = 12; BanUserMessage banUserMessage = 13; EmotePromptMessage emotePromptMessage = 14; - UserGlobalMessage userGlobalMessage = 15; } } @@ -415,6 +406,7 @@ message AdminMessage { message AdminRoomMessage { string message = 1; string roomId = 2; + string type = 3; } // A message sent by an administrator to absolutely everybody diff --git a/pusher/src/Controller/IoSocketController.ts b/pusher/src/Controller/IoSocketController.ts index 303d1bb7..bd9b5821 100644 --- a/pusher/src/Controller/IoSocketController.ts +++ b/pusher/src/Controller/IoSocketController.ts @@ -17,7 +17,6 @@ import { ServerToClientMessage, CompanionMessage, EmotePromptMessage, - UserGlobalMessage, } from "../Messages/generated/messages_pb"; import { UserMovesMessage } from "../Messages/generated/messages_pb"; import { TemplatedApp } from "uWebSockets.js"; @@ -382,8 +381,6 @@ export class IoSocketController { client, message.getEmotepromptmessage() as EmotePromptMessage ); - } else if (message.hasUserglobalmessage()) { - socketManager.handleUserGlobalMessage(client, message.getUserglobalmessage() as UserGlobalMessage); } /* Ok is false if backpressure was built up, wait for drain */ diff --git a/pusher/src/Services/SocketManager.ts b/pusher/src/Services/SocketManager.ts index b4575f85..e1e7bc2e 100644 --- a/pusher/src/Services/SocketManager.ts +++ b/pusher/src/Services/SocketManager.ts @@ -23,7 +23,6 @@ import { SetPlayerDetailsMessage, SilentMessage, SubMessage, - UserGlobalMessage, UserJoinedRoomMessage, UserLeftMessage, UserLeftRoomMessage, @@ -387,17 +386,6 @@ export class SocketManager implements ZoneEventListener { } } - emitPlayGlobalMessage(client: ExSocketInterface, playglobalmessage: PlayGlobalMessage) { - if (!client.tags.includes("admin")) { - //In case of xss injection, we just kill the connection. - throw "Client is not an admin!"; - } - const pusherToBackMessage = new PusherToBackMessage(); - pusherToBackMessage.setPlayglobalmessage(playglobalmessage); - - client.backConnection.write(pusherToBackMessage); - } - public getWorlds(): Map { return this.rooms; } @@ -607,9 +595,9 @@ export class SocketManager implements ZoneEventListener { client.backConnection.write(pusherToBackMessage); } - public async handleUserGlobalMessage( + public async emitPlayGlobalMessage( client: ExSocketInterface, - userGlobalMessageEvent: UserGlobalMessage + playGlobalMessageEvent: PlayGlobalMessage ): Promise { if (!client.tags.includes("admin")) { throw "Client is not an admin!"; @@ -618,14 +606,15 @@ export class SocketManager implements ZoneEventListener { const clientRoomUrl = client.roomId; let tabUrlRooms: string[]; - if (userGlobalMessageEvent.getBroadcasttoworld()) { + if (playGlobalMessageEvent.getBroadcasttoworld()) { tabUrlRooms = await adminApi.getUrlRoomsFromSameWorld(clientRoomUrl); } else { tabUrlRooms = [clientRoomUrl]; } let roomMessage = new AdminRoomMessage(); - roomMessage.setMessage(userGlobalMessageEvent.getContent()); + roomMessage.setMessage(playGlobalMessageEvent.getContent()); + roomMessage.setType(playGlobalMessageEvent.getType()); for (let roomUrl of tabUrlRooms) { let apiRoom = await apiClientRepository.getClient(roomUrl);