put disconnect reason message in enum

This commit is contained in:
ingmargoudt 2017-04-04 21:59:26 +02:00
parent ff6d1541c3
commit c461d67d34
2 changed files with 19 additions and 31 deletions

View file

@ -85,30 +85,9 @@ public class ChatSession {
clients.remove(userId);
logger.debug(userName + '(' + reason.toString() + ')' + " removed from chatId " + chatId);
}
String message;
switch (reason) {
case Disconnected:
message = " has left XMage";
break;
case LostConnection:
message = " has lost connection";
break;
case SessionExpired:
message = " session expired";
break;
case AdminDisconnect:
message = " was disconnected by the Admin";
break;
case ConnectingOtherInstance:
message = " reconnected and replaced still active old session";
break;
case CleaningUp:
message = null;
break;
default:
message = " left (" + reason.toString() + ')';
}
if (message != null) {
String message = reason.getMessage();
if (!message.isEmpty()) {
broadcast(null, userName + message, MessageColor.BLUE, true, MessageType.STATUS, null);
}
}

View file

@ -6,11 +6,20 @@ package mage.server;
*/
public enum DisconnectReason {
LostConnection,
Disconnected,
CleaningUp,
ConnectingOtherInstance,
AdminDisconnect,
SessionExpired,
Undefined
LostConnection(" has lost connection"),
Disconnected(" has left XMage"),
CleaningUp(" [cleaning up]"),
ConnectingOtherInstance(" reconnected and replaced still active old session"),
AdminDisconnect(" was disconnected by the Admin"),
SessionExpired(" session expired"),
Undefined("");
String message;
DisconnectReason(String message){
this.message = message;
}
public String getMessage(){
return message;
}
}