Esempio n. 1
0
  /** Remove a channel. */
  public void removeChannel(Channel channel) {
    String name = channel.getConfig().getName().toLowerCase();

    // unregister the channel
    channels.remove(channel);
    channelMap.remove(name.toLowerCase());
  }
Esempio n. 2
0
 /**
  * Create a channel initialized with the specified configuration.
  *
  * @param config the channel configuration
  * @param start initial state
  */
 public Channel createChannel(ChannelConfig config, boolean start) {
   Channel channel = new Channel(config);
   channel.setName("channel: " + config.getName());
   if (start) {
     channel.start();
   }
   channels.add(channel);
   channelMap.put(config.getName().toLowerCase(), channel);
   return channel;
 }
Esempio n. 3
0
  /**
   * Looks for a channel with room left.
   *
   * @return <tt>null</tt> if there is no room left in all available channels
   * @deprecated
   */
  public Channel getOpenedChannel() {
    Channel channel = null;
    Iterator<Channel> it = channels.iterator();
    while (it.hasNext() && channel == null) {
      Channel channel2 = it.next();
      if (!channel2.isFull()) {
        channel = channel2;
      }
    }

    return channel;
  }
Esempio n. 4
0
  /**
   * Return the most suitable home channel for a player newly connected, that's the first accessible
   * channel with players to play with.
   *
   * <p>The channel selected matches the following criteria:
   *
   * <ul>
   *   <li>it must be accessible for the specified access level
   *   <li>it must not be password protected
   *   <li>it must have room left
   *   <li>it should not be empty
   * </ul>
   *
   * @since 0.2
   * @param level the access level of the player added in the channel
   * @param protocol the name of the protocol used
   */
  public Channel getHomeChannel(int level, String protocol) {
    Channel channel = null;
    Channel emptyChannel = null;

    Iterator<Channel> it = channels.iterator();
    while (it.hasNext() && channel == null) {
      Channel chan = it.next();

      if (chan.getConfig().getAccessLevel() <= level
          && !chan.getConfig().isPasswordProtected()
          && !chan.isFull()
          && chan.getConfig().isProtocolAccepted(protocol)) {
        if (chan.isEmpty()) {
          emptyChannel = (emptyChannel != null) ? emptyChannel : chan;
        } else {
          channel = chan;
        }
      }
    }

    return channel != null ? channel : emptyChannel;
  }
Esempio n. 5
0
 /** Returns the number of existing channels. */
 public int getChannelCount() {
   return channels.size();
 }
Esempio n. 6
0
 /** Get a channel by number in the list. */
 public Channel getChannel(int num) {
   return ((num >= 0 && num < channels.size()) ? channels.get(num) : null);
 }
Esempio n. 7
0
 /** Clear the channel list. */
 public void clear() {
   channels.clear();
   channelMap.clear();
 }