* @param message
* the logout message
*/
@Override
public void process(Message message) {
MessageC2SLogout msg = (MessageC2SLogout) message;
try {
int clientid = msg.getClientID();
PlayerEntry entry = playerContainer.get(clientid);
/*
* Verify event so that we can trust that it comes from our player
* and that it has completed the login stage.
*/
if (!isValidEvent(msg, entry, ClientState.LOGIN_COMPLETE, ClientState.GAME_BEGIN)) {
return;
}
RPObject object = entry.object;
boolean shouldLogout = true;
/*
* We request to logout of game to RP Manager If may be successful or
* fail and we keep on game.
*/
if (entry.state == ClientState.GAME_BEGIN) {
playerContainer.getLock().requestWriteLock();
if (rpMan.onExit(object)) {
/* NOTE: Set the Object so that it is stored in Database */
entry.storeRPObject(object);
} else {
/*
* If RPManager returned false, that means that logout is
* not allowed right now, so player request is rejected.
* This can be useful to disallow logout on some situations.
*/
shouldLogout = false;
}
playerContainer.getLock().releaseLock();
}
if (shouldLogout) {
stats.add("Players logout", 1);
logger.info("Logging out correctly channel: "+entry.channel);
playerContainer.remove(clientid);
/* Send Logout ACK message */
MessageS2CLogoutACK msgLogout = new MessageS2CLogoutACK(msg.getSocketChannel());
msgLogout.setClientID(clientid);
msgLogout.setProtocolVersion(msg.getProtocolVersion());
netMan.sendMessage(msgLogout);
entry.state = ClientState.LOGOUT_ACCEPTED;
} else {
MessageS2CLogoutNACK msgLogout = new MessageS2CLogoutNACK(msg.getSocketChannel());
msgLogout.setClientID(clientid);
msgLogout.setProtocolVersion(msg.getProtocolVersion());
netMan.sendMessage(msgLogout);
}
} catch (Exception e) {
logger.error("error while processing LogoutEvent", e);
}