Exemplo n.º 1
0
  /**
   * NOTE: this used to have an exception, because I'd like to properly report an invalid/
   * non-existent channel... unless a failed add means that there is no such channel?
   *
   * <p>NOTE2: elsewhere the messages claim that a failed add is a restricted channel, while
   *
   * <p>NOTE3: an unsuccessful add, without a thrown exception, implies a restriction failure.
   *
   * @param player
   * @param channelName
   * @param password
   * @return
   * @throws NoSuchChannelException
   */
  public Result add(final Player player, final String channelName, final String password) {
    Result result = Result.NIL;

    boolean valid = false;

    final ChatChannel channel = channels.get(channelName);

    if (channel != null) {
      if (!channel.isListener(player)) {
        // do we pass the restriction?
        if (player.getAccess() >= channel.getRestrict()) {
          if (channel.isProtected()) {
            if (channel.checkPassword(password) || MudUtils.checkAccess(player, Constants.ADMIN)) {
              valid = true;
            } else result = Result.WRONG_PASS; // message about incorrect password
          } else valid = true;
        } else result = Result.RESTRICTED; // message about channel restriction

        if (valid) {
          if (channel.addListener(player)) {
            result = Result.JOIN;
          }
        }
      } else result = Result.CURR_LISTEN; // message about already listening to that channel
    } else {
      // test to see whether a mapping to null exists...
      if (channels.containsKey(channelName)) {
        channels.remove(channelName); // explicit remove a mapping to a null value
      }

      result = Result.NO_CHANNEL;
    }

    return result;
  }
Exemplo n.º 2
0
  public boolean send(final String channelName, final Player player, final String message) {
    boolean success = false;

    final ChatChannel channel = channels.get(channelName);

    if (channel != null) {
      if (player.getAccess() >= channel.getRestrict()) {
        channel.write(player, message); // add message to ChatChannel message queue
        // mud.debug("(" + channelName + ") <" + player.getName() + "> " + message + "\n");

        success = true;
      }
    }

    return success;
  }