Some changes to logging and NPE handling.

This commit is contained in:
LevelX2 2014-08-17 20:38:57 +02:00
parent 3e789ccb1f
commit ddb9c786b4
7 changed files with 44 additions and 17 deletions

View file

@ -72,10 +72,14 @@ public class ChatSession {
public void kill(UUID userId, DisconnectReason reason) {
try {
if (userId != null && clients.containsKey(userId)) {
if (reason == null) {
logger.fatal("User kill without disconnect reason userId: " + userId) ;
reason = DisconnectReason.Undefined;
}
if (reason != null && userId != null && clients.containsKey(userId)) {
String userName = clients.get(userId);
clients.remove(userId);
logger.debug(userName + (reason == null?"null":"(" + reason.toString() +")") + " removed from chatId " + chatId) ;
logger.debug(userName + "(" + reason.toString() +")" + " removed from chatId " + chatId) ;
String message;
switch (reason) {
case Disconnected:
@ -85,7 +89,7 @@ public class ChatSession {
message = " has lost connection";
break;
default:
message = reason == null ? " left (unknown reason) ": " left (" + reason.toString() +")";
message = " left (" + reason.toString() +")";
}
if (message != null) {
broadcast(null, new StringBuilder(userName).append(message).toString(), MessageColor.BLUE, true, MessageType.STATUS);