예제 #1
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;
  }
예제 #2
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;
  }