From e52c35fec9a22e2066abab8e542ae8e85ff0a891 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 17 Mar 2013 23:44:45 +0100 Subject: [PATCH] Show player joins message in chat window only, if player isn't already connected. Suppres posting of empty strings in the chat window. --- .../main/java/mage/server/ChatSession.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Mage.Server/src/main/java/mage/server/ChatSession.java b/Mage.Server/src/main/java/mage/server/ChatSession.java index 7c48e4cee5..b8f6f67a5e 100644 --- a/Mage.Server/src/main/java/mage/server/ChatSession.java +++ b/Mage.Server/src/main/java/mage/server/ChatSession.java @@ -56,7 +56,7 @@ public class ChatSession { public void join(UUID userId) { User user = UserManager.getInstance().getUser(userId); - if (user != null) { + if (user != null && !clients.containsKey(userId)) { String userName = user.getName(); clients.put(userId, userName); broadcast(userName, " has joined", MessageColor.BLACK); @@ -74,17 +74,19 @@ public class ChatSession { } public void broadcast(String userName, String message, MessageColor color) { - Calendar cal = new GregorianCalendar(); - final String msg = message; - final String time = timeFormatter.format(cal.getTime()); - final String username = userName; - logger.debug("Broadcasting '" + msg + "' for " + chatId); - for (UUID userId: clients.keySet()) { - User user = UserManager.getInstance().getUser(userId); - if (user != null) - user.fireCallback(new ClientCallback("chatMessage", chatId, new ChatMessage(username, msg, time, color))); - else - kill(userId); + if (!message.isEmpty()) { + Calendar cal = new GregorianCalendar(); + final String msg = message; + final String time = timeFormatter.format(cal.getTime()); + final String username = userName; + logger.debug("Broadcasting '" + msg + "' for " + chatId); + for (UUID userId: clients.keySet()) { + User user = UserManager.getInstance().getUser(userId); + if (user != null) + user.fireCallback(new ClientCallback("chatMessage", chatId, new ChatMessage(username, msg, time, color))); + else + kill(userId); + } } }