示例#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;
  }
示例#2
0
  public Result modifyRestriction(final String channelName, final int newRestrict) {
    Result result = Result.NIL;

    final ChatChannel channel = channels.get(channelName);

    if (channel != null) {
      if (newRestrict != channel.getRestrict()) {
        channel.setRestrict(newRestrict);
        result = Result.MODIFY_OK;
      } else result = Result.MODIFY_NOK;

      // if( player.getAccess() >= channel.getRestrict() ) {}
    } else result = Result.NO_CHANNEL;

    return result;
  }
示例#3
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;
  }