示例#1
0
  /**
   * Handles a "logout"-message.
   *
   * @param connection The <code>Connection</code> the message was received on.
   * @param logoutElement The element (root element in a DOM-parsed XML tree) that holds all the
   *     information.
   * @return The reply.
   */
  protected Element logout(Connection connection, Element logoutElement) {
    ServerPlayer player = getFreeColServer().getPlayer(connection);
    logger.info(
        "Logout by: " + connection + ((player != null) ? " (" + player.getName() + ") " : ""));
    if (player == null) {
      return null;
    }
    // TODO
    // Remove the player's units/colonies from the map and send map updates
    // to the
    // players that can see such units or colonies.
    // SHOULDN'T THIS WAIT UNTIL THE CURRENT PLAYER HAS FINISHED HIS TURN?
    /*
     * player.setDead(true); Element setDeadElement =
     * Message.createNewRootElement("setDead");
     * setDeadElement.setAttribute("player", player.getId());
     * freeColServer.getServer().sendToAll(setDeadElement, connection);
     */
    /*
     * TODO: Setting the player dead directly should be a server option, but
     * for now - allow the player to reconnect:
     */
    Element reply = null;
    player.setConnected(false);
    if (getFreeColServer().getGame().getCurrentPlayer() == player
        && !getFreeColServer().isSinglePlayer()) {
      reply = getFreeColServer().getInGameController().endTurn(player);
    }
    try {
      getFreeColServer().updateMetaServer();
    } catch (NoRouteToServerException e) {
    }

    return reply;
  }