Package games.stendhal.server.core.engine.dbcommand

Source Code of games.stendhal.server.core.engine.dbcommand.StoreMessageCommand

/***************************************************************************
*                    (C) Copyright 2007-2010 - Stendhal                   *
***************************************************************************
***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/
package games.stendhal.server.core.engine.dbcommand;

import games.stendhal.server.core.engine.db.PostmanDAO;

import java.sql.SQLException;

import marauroa.server.db.DBTransaction;
import marauroa.server.db.command.AbstractDBCommand;
import marauroa.server.game.db.CharacterDAO;
import marauroa.server.game.db.DAORegister;

/**
* Store postman messages for a player, if a character for them exists
* Can find out from this function if the character existed
*
* @author kymara
*/
public class StoreMessageCommand extends AbstractDBCommand {

  private final String source;
  private final String target;
  private final String message;
  private final String messagetype;
  private String accountName;

  /**
   * creates a new StoreMessageCommand
   *
   * @param source who left the message
   * @param target the player name the message is for
   * @param message what the message is
   * @param messagetype N for NPCs, S for support, P for player
   */
  public StoreMessageCommand(String source, String target, String message, String messagetype) {
    this.source = source;
    this.target = target;
    this.message = message;
    this.messagetype = messagetype;
  }

  @Override
  public void execute(DBTransaction transaction) throws SQLException {
    CharacterDAO characterdao = DAORegister.get().get(CharacterDAO.class);
    accountName = characterdao.getAccountName(transaction, target);
    if (accountName != null) {
      PostmanDAO postmandao = DAORegister.get().get(PostmanDAO.class);
      postmandao.storeMessage(transaction, source, target, message, messagetype);
    }
  }

  /**
   * checks if account name could be found - which tells if the character whom the message was for, existed
   *
   * @return true if an account was found for that character name
   */
  public boolean targetCharacterExists() {
    return accountName != null;
  }

  /**
   * To access the character name we queried
   *
   * @return target the character who we checked for
   */
  public String getTarget() {
    return target;
  }

  /**
   * To access the source message sender
   *
   * @return source who sent the message
   */
  public String getSource() {
    return source;
  }

  /**
   * To access the message
   *
   * @return message
   */
  public String getMessage() {
    return message;
  }

  /**
   * returns a string suitable for debug output of this DBCommand.
   *
   * @return debug string
   */
  @Override
  public String toString() {
    return "StoreMessageCommand [source=" + source + ", target=" + target
        + ", message=" + message + ", messagetype=" + messagetype
        + ", accountName=" + accountName + "]";
  }
}
TOP

Related Classes of games.stendhal.server.core.engine.dbcommand.StoreMessageCommand

TOP
Copyright © 2018 www.massapi.com. 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.