/** Remove a channel. */ public void removeChannel(Channel channel) { String name = channel.getConfig().getName().toLowerCase(); // unregister the channel channels.remove(channel); channelMap.remove(name.toLowerCase()); }
/** * 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; }
/** * 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; }
/** * 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; }
/** Returns the number of existing channels. */ public int getChannelCount() { return channels.size(); }
/** Get a channel by number in the list. */ public Channel getChannel(int num) { return ((num >= 0 && num < channels.size()) ? channels.get(num) : null); }
/** Clear the channel list. */ public void clear() { channels.clear(); channelMap.clear(); }