- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
public void onMessage(final NetConnection connection, final NetMessage message) {
final ClientConnection client = (ClientConnection) connection;
if (message.isCommand(Protocol.CMD_LOGIN)) {
if (this.auth(client,
message.getParameter(Protocol.PARAM_NAME, String.class))) {
final NetMutableMessage msgLogin = new NetMutableMessage(
Protocol.CMD_LOGIN);
msgLogin.addParameter(Protocol.PARAM_FROM, client.getNick());
this.writeMessage(client, null, msgLogin);
} else {
this.removeConnection(client);
}
}
if (message.isCommand(Protocol.CMD_LOGOUT)) {
final NetMutableMessage msgLogout = new NetMutableMessage(
Protocol.CMD_LOGOUT);
msgLogout.addParameter(Protocol.PARAM_FROM, client.getNick());
this.writeMessage(client, null, msgLogout);
this.removeConnection(client);
}
if (message.isCommand(Protocol.CMD_STATUS)) {
final NetMutableMessage msgStatus = new NetMutableMessage(
Protocol.CMD_STATUS);
msgStatus.addParameter(Protocol.PARAM_TYPE,
message.getParameter(Protocol.PARAM_TYPE));
msgStatus.addParameter(Protocol.PARAM_FROM, client.getNick());
this.writeMessage(client, null, message);
this.removeConnection(client);
}
if (message.isCommand(Protocol.CMD_USERS)) {
final NetMutableMessage msgUsers = new NetMutableMessage(
Protocol.CMD_USERS);
msgUsers.addParameter("list", this.getUsers(connection));
this.writeMessage(client, msgUsers, null);
}
if (message.isCommand(Protocol.CMD_SAY)) {
final NetMutableMessage msgSay = new NetMutableMessage(Protocol.CMD_SAY);
msgSay.addParameter(Protocol.PARAM_FROM, client.getNick());
msgSay.addParameter(Protocol.PARAM_MESSAGE,
message.getParameter(Protocol.PARAM_MESSAGE));
if (null == message.getParameter(Protocol.PARAM_TO)) {
this.writeMessage(client, msgSay, msgSay);
} else {
this.writeMessage(
message.getParameter(Protocol.PARAM_TO, String.class), msgSay, null);
}
}
if (message.isCommand(Protocol.CMD_MOVE)) {
final NetMutableMessage msgMove = new NetMutableMessage(Protocol.CMD_MOVE);
msgMove.addParameter(Protocol.PARAM_FROM, client.getNick());
msgMove.addParameter(Protocol.PARAM_CODE,
message.getParameter(Protocol.PARAM_CODE));
this.writeMessage(message.getParameter(Protocol.PARAM_TO, String.class),
msgMove, null);
}
if (message.isCommand(Protocol.CMD_OFFER)) {
final NetMutableMessage msgOffer = new NetMutableMessage(
Protocol.CMD_OFFER);
msgOffer.addParameter(Protocol.PARAM_FROM, client.getNick());
this.writeMessage(message.getParameter(Protocol.PARAM_TO, String.class),
msgOffer, null);
}
if (message.isCommand(Protocol.CMD_ACCEPT)) {
final NetMutableMessage msgAccept = new NetMutableMessage(
Protocol.CMD_ACCEPT);
msgAccept.addParameter(Protocol.PARAM_FROM, client.getNick());
this.writeMessage(message.getParameter(Protocol.PARAM_TO, String.class),
msgAccept, null);
}
if (message.isCommand(Protocol.CMD_DECLINE)) {
final NetMutableMessage msgDecline = new NetMutableMessage(
Protocol.CMD_DECLINE);
msgDecline.addParameter(Protocol.PARAM_FROM, client.getNick());
this.writeMessage(message.getParameter(Protocol.PARAM_TO, String.class),
msgDecline, null);
}
if (message.isCommand(Protocol.CMD_END)) {
final NetMutableMessage msgEnd = new NetMutableMessage(Protocol.CMD_END);
msgEnd.addParameter("player1",
message.getParameter(Protocol.PARAM_TO, String.class));
msgEnd.addParameter("player2", client.getNick());
this.writeMessage(message.getParameter(Protocol.PARAM_TO, String.class),
null, msgEnd);
}
}