print help message on joining

pull/34/head
Zlatin Balevsky 2019-11-12 04:18:35 +00:00
parent d91f15ee54
commit d57d2ccb71
1 changed files with 20 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import java.nio.charset.StandardCharsets
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import java.util.logging.Level import java.util.logging.Level
import java.util.stream.Collectors
import com.muwire.core.Constants import com.muwire.core.Constants
import com.muwire.core.EventBus import com.muwire.core.EventBus
@ -50,6 +51,8 @@ class ChatServer {
public void start() { public void start() {
running.set(true) running.set(true)
connections.put(me.destination, LocalChatLink.INSTANCE) connections.put(me.destination, LocalChatLink.INSTANCE)
joinRoom(me, CONSOLE)
processHelp(me.destination)
} }
private void sendPings() { private void sendPings() {
@ -103,6 +106,7 @@ class ChatServer {
connections.put(endpoint.destination, connection) connections.put(endpoint.destination, connection)
joinRoom(client, CONSOLE) joinRoom(client, CONSOLE)
connection.start() connection.start()
processHelp(connection.endpoint.destination)
eventBus.publish(new ChatConnectionEvent(connection : connection, status : ChatConnectionAttemptStatus.SUCCESSFUL, persona : client)) eventBus.publish(new ChatConnectionEvent(connection : connection, status : ChatConnectionAttemptStatus.SUCCESSFUL, persona : client))
} }
@ -188,9 +192,9 @@ class ChatServer {
case ChatAction.JOIN : processJoin(command.payload, e); break case ChatAction.JOIN : processJoin(command.payload, e); break
case ChatAction.LEAVE : processLeave(e); break case ChatAction.LEAVE : processLeave(e); break
case ChatAction.SAY : processSay(e); break case ChatAction.SAY : processSay(e); break
case ChatAction.LIST : processList(e); break case ChatAction.LIST : processList(e.sender.destination); break
case ChatAction.INFO : processInfo(e); break case ChatAction.INFO : processInfo(e.sender.destination); break
case ChatAction.HELP : processHelp(e); break case ChatAction.HELP : processHelp(e.sender.destination); break
} }
} }
@ -226,22 +230,25 @@ class ChatServer {
} }
} }
private void processList(ChatMessageEvent e) { private void processList(Destination d) {
String roomList = "/SAY " + String.join("\n", rooms.keySet()) String roomList = rooms.keySet().stream().filter({it != CONSOLE}).collect(Collectors.joining("\n"))
echo(roomList, e) roomList = "/SAY \nRoom List:\n"+roomList
echo(roomList, d)
} }
private void processInfo(ChatMessageEvent e) { private void processInfo(Destination d) {
String info = "/SAY The address of this server is \n${me.toBase64()}\nCopy/paste this and share it" String info = "/SAY \nThe address of this server is\n========\n${me.toBase64()}\n========\nCopy/paste the above and share it\n"
echo(info, e) String connectedUsers = memberships.keySet().stream().map({it.getHumanReadableName()}).collect(Collectors.joining("\n"))
info = "${info}\nConnected Users:\n$connectedUsers\n======="
echo(info, d)
} }
private void processHelp(ChatMessageEvent e) { private void processHelp(Destination d) {
String help = "/SAY Available commands: /JOIN /LEAVE /SAY /LIST /INFO /HELP" String help = "/SAY Available commands: /JOIN /LEAVE /SAY /LIST /INFO /HELP"
echo(help, e) echo(help, d)
} }
private void echo(String payload, ChatMessageEvent e) { private void echo(String payload, Destination d) {
log.info "echoing $payload" log.info "echoing $payload"
UUID uuid = UUID.randomUUID() UUID uuid = UUID.randomUUID()
long now = System.currentTimeMillis() long now = System.currentTimeMillis()
@ -255,7 +262,7 @@ class ChatServer {
chatTime : now, chatTime : now,
sig : sig sig : sig
) )
connections[e.sender.destination]?.sendChat(echo) connections[d]?.sendChat(echo)
} }
void stop() { void stop() {