Package marauroa.common.net.message

Examples of marauroa.common.net.message.MessageC2SLogout


   *             if timeout happens while waiting for the message.
   * @throws BannedAddressException
   */
  public synchronized boolean logout() throws InvalidVersionException, TimeoutException,
          BannedAddressException {
    Message msgL = new MessageC2SLogout(null);

    netMan.addMessage(msgL);
    int received = 0;

    while (received != 1) {
View Full Code Here


   * @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);
    }
View Full Code Here

TOP

Related Classes of marauroa.common.net.message.MessageC2SLogout

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.