/*
** j###t ########## #### ####
** j###t ########## #### ####
** j###T "###L J###"
** ######P' ########## #########
** ######k, ########## T######T
** ####~###L ####
** #### q###L ########## .#####
** #### \###L ########## #####"
**
** Class History
**
** Date Name Description
** ---------|------------|-----------------------------------------------
** 14Jul97 merlin created this command
**
*/
package key.commands;
import key.*;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.Enumeration;
import java.lang.String;
/**
* This command is to display all the sites in the site container
* that have any form of ban on them, either Newbie, or Complete
*/
public class SitesBanned extends Command
{
public static final TableParagraph.Column[] columns =
{
new TableParagraph.Column( "site", 35 ),
new TableParagraph.Column( "ban type", 8 ),
new TableParagraph.Column( "ban date", 28 ),
};
private StringBuffer siteInfo = null;
public SitesBanned()
{
setKey( "sitesbanned" );
usage = "";
}
public void run( Player p, StringTokenizer args, String fullLine, CategoryCommand caller, InteractiveConnection ic, Flags flags ) throws IOException
{
TableParagraph.Generator table = new TableParagraph.Generator( columns );
// get all the network and site information there is in key
for( Enumeration e = Key.getInternet().elements(); e.hasMoreElements(); )
{
try
{
traverseSites( e.nextElement(), table );
}
catch( InvalidContainerObject i )
{
ic.sendFeedback( i.getMessage() );
}
}
if( table.count() == 0 )
{
ic.sendFeedback( "No sites have bans in place at the current time" );
return;
}
ic.send( table.getParagraph() );
}
private final void traverseSites( Object n, TableParagraph.Generator tpg ) throws InvalidContainerObject
{
if( n instanceof Site )
{
// We have got the site object already - Check
// if it has any ban on it of any type
Site site = (Site) n;
if( !site.newbiesAllowed() || !site.connectionsAllowed() )
{
addBannedSite( site, tpg );
return;
}
}
else if( n instanceof Network )
{
// in this case, its a collection in itself of networks.
// feed each network back into this member function.
// until the Site is found.
Network net = (Network) n;
for( Enumeration e = net.elements(); e.hasMoreElements(); )
{
// parse the network
traverseSites( e.nextElement(), tpg );
}
}
else if( n == null )
{
// there are no sites in the sites container. This is
// an improbable situation, as if you are running this
// command, at least one site is registered. But it's
// better to check that the site exists before doing anything
return;
}
else
{
// in this case, we have an object in the container that is not
// a network or a site. This is a problem. Stop the command
// running straight away.
throw( new InvalidContainerObject( "Invalid Object found in Sites - Class " + n.getClass().getName() ) );
}
}
private final void addBannedSite( Site s, TableParagraph.Generator table )
{
String rowContents[] = new String[ columns.length ];
rowContents[ 0 ] = s.toString();
rowContents[ 1 ] = ( !s.newbiesAllowed()?"newbies":"complete" );
//rowContents[ 2 ] = s.getProperty( "bannedAt" ).toString();
rowContents[ 2 ] = s.bannedAt.toString();
table.appendRow( rowContents );
}
}