示例#1
0
  public void registerChannel(Channel channel) {
    if (channel instanceof ChatChannel) {
      ChatChannel _channel = (ChatChannel) channel;
      channels.put(_channel, _channel.isEnabled());
    }

    if (channel instanceof DebugChannel) {
      debug = (DebugChannel) channel;
    }
  }
示例#2
0
  private void joinAllAvailableChannels(ChatPlayer cp) {
    for (Map.Entry channel : getMap().entrySet()) {
      if (cp.canConnect((Channel) channel.getKey(), "")) {
        ChatChannel c = (ChatChannel) channel.getKey();
        c.connectWithoutBroadcast(cp.getPlayer().getName());
      }
    }

    getDefaultChannel().assignFocus(cp.getPlayer().getName(), true);
  }
示例#3
0
  public String resolveShortName(final String shortName) {
    String name = "";

    for (final ChatChannel ch : this.getChatChannels()) {
      if (ch.getShortName().equalsIgnoreCase(shortName)) {
        name = shortName;
        break;
      }
    }

    return name;
  }
示例#4
0
  // should be used for system messages...
  public boolean send(final String channelName, final String message) {
    final ChatChannel chan = channels.get(channelName);

    if (chan != null) {
      chan.write(message); // add message to ChatChannel message queue
      // mud.debug("(" + channelName + ") " + message + "\n");

      return true;
    } else {
      return false;
    }
  }
示例#5
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;
  }
示例#6
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;
  }
示例#7
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;
  }
示例#8
0
  public Result remove(final Player player, final String channelName) {
    Result result = Result.NIL;

    final ChatChannel channel = channels.get(channelName);

    if (channel != null) {
      if (channel.isListener(player)) {
        if (channel.removeListener(player)) {
          result = Result.LEAVE;
        }
      } else result = Result.CURR_NOLISTEN;
    } 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;
  }
示例#9
0
  // ChatChannel stuff
  public void removeChannel(ChatChannel channel) {
    unregisterChannel(channel);

    for (Map.Entry<String, Boolean> listener : channel.listeners.entrySet()) {
      if (listener.getValue()) {
        if (!def.hasListener(listener.getKey())) {
          def.addListener(listener.getKey(), true);
        } else {
          def.assignFocus(listener.getKey(), true);
        }
      }
    }

    List<String> l = new LinkedList<String>();

    for (Map.Entry<Channel, Boolean> entry : channels.entrySet()) {
      if (entry.getKey().getName().equals(channel.getName())) continue;

      l.add(entry.getKey().getName());
    }

    ISMain.getChannelConfig().set("channels", l);
    ISMain.getChannelConfig().set(channel.getName(), null);
  }
示例#10
0
  private void writeDefaults() {
    channels.clear();

    ChatChannel pub = new ChatChannel("Public");
    pub.setDefault(true);
    pub.setGhostFormat("&8[&aPublic&8] $group&8: &7$message");
    registerChannel(pub);
    this.def = pub;

    ChatChannel _helpop = new ChatChannel("HelpOp");
    _helpop.setHelpOp(true);
    _helpop.setGhostFormat("&4[&cHELPOP&4] &7$name&f:&d $message");
    registerChannel(_helpop);
    this.helpop = _helpop;
  }
示例#11
0
 private void disconnectFromAllChannels(ChatPlayer cp) {
   for (Map.Entry entry : getMap().entrySet()) {
     ChatChannel c = (ChatChannel) entry.getKey();
     c.silentDisconnect(cp.getPlayer().getName());
   }
 }