/** * Tells if a non private channel is available for a client using the specified protocol. * * @param protocol the name of the protocol used * @since 0.3 */ public boolean hasCompatibleChannels(String protocol) { for (Channel chan : channels) { if (!chan.getConfig().isPasswordProtected() && chan.getConfig().isProtocolAccepted(protocol)) { return true; } } return false; }
/** Remove a channel. */ public void removeChannel(Channel channel) { String name = channel.getConfig().getName().toLowerCase(); // unregister the channel channels.remove(channel); channelMap.remove(name.toLowerCase()); }
/** Remove a channel. */ public void removeChannel(String name) { // get the channel Channel channel = getChannel(name); removeChannel(channel); // close it as soon as the last client leaves channel.getConfig().setPersistent(false); channel.send(new ShutdownMessage()); }
/** * 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; }