From 944cb299019452df6413656a0a4256d37019a3b3 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 18 Sep 2020 18:15:15 +0100 Subject: [PATCH] show error messages if the command is not in the appropriate room --- TODO.md | 1 - .../com/muwire/core/chat/ChatServer.groovy | 22 ++++++++++++++----- .../com/muwire/gui/ChatRoomController.groovy | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index 364bc142..a4cfbf45 100644 --- a/TODO.md +++ b/TODO.md @@ -22,7 +22,6 @@ This helps with scalability * Use tracker pings - either embedded logic or external mwtrackerd to add more sources to downloads ### Chat -* echo "unknown/innappropriate command" in the console * break up lines on CR/LF, send multiple messages * enforce # in room names or ignore it * auto-create/join channel on server start diff --git a/core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy b/core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy index 68f82064..7e80dc39 100644 --- a/core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy +++ b/core/src/main/groovy/com/muwire/core/chat/ChatServer.groovy @@ -201,9 +201,19 @@ class ChatServer { return } - if ((command.action.console && e.room != CONSOLE) || - (!command.action.console && e.room == CONSOLE) || - !command.action.user) + if (command.action.console && e.room != CONSOLE) { + echo("/SAY ERROR: You can only execute that command in the chat console, not in a chat room.", + e.sender.destination, e.room) + return + } + + if (!command.action.console && e.room == CONSOLE) { + echo("/SAY ERROR: You need to be in a chat room. Type /LIST for list of rooms or /JOIN to join or create a room.", + e.sender.destination) + return + } + + if (!command.action.user) return if (command.action.local && e.sender != me) @@ -300,17 +310,17 @@ class ChatServer { echo(help, d) } - private void echo(String payload, Destination d) { + private void echo(String payload, Destination d, String room = CONSOLE) { log.info "echoing $payload" UUID uuid = UUID.randomUUID() long now = System.currentTimeMillis() - byte [] sig = ChatConnection.sign(uuid, now, CONSOLE, payload, me, me, spk) + byte [] sig = ChatConnection.sign(uuid, now, room, payload, me, me, spk) ChatMessageEvent echo = new ChatMessageEvent( uuid : uuid, payload : payload, sender : me, host : me, - room : CONSOLE, + room : room, chatTime : now, sig : sig ) diff --git a/gui/griffon-app/controllers/com/muwire/gui/ChatRoomController.groovy b/gui/griffon-app/controllers/com/muwire/gui/ChatRoomController.groovy index 1bf4f932..e222341d 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/ChatRoomController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/ChatRoomController.groovy @@ -65,7 +65,7 @@ class ChatRoomController { trimLines() } - if (command.action == ChatAction.JOIN) { + if (command.action == ChatAction.JOIN && model.console) { String newRoom = command.payload String groupId = model.host.getHumanReadableName()+"-"+newRoom if (!mvcGroup.parentGroup.childrenGroups.containsKey(groupId)) {