key0-96/
key0-96/doc/key/
key0-96/doc/key/credits/
key0-96/doc/key/developers/
key0-96/doc/key/developers/resources/
key0-96/setup/caves/
key0-96/setup/help/
key0-96/setup/ruins/
key0-96/src/
key0-96/src/commands/
key0-96/src/events/
key0-96/src/hack/
key0-96/src/sql/
key0-96/src/swing/
key0-96/src/talker/forest/
key0-96/src/talker/objects/
key0-96/src/terminals/
/*
**               j###t  ########## ####   ####
**              j###t   ########## ####   ####
**             j###T               "###L J###"
**          ######P'    ##########  #########
**          ######k,    ##########   T######T
**          ####~###L   ####
**          #### q###L  ##########   .#####
**          ####  \###L ##########   #####"
**
**  $Id: Citizen.java,v 1.6 1997/07/29 08:38:15 subtle Exp $
**
**  Class History
**
**  Date        Name         description
**  ---------|------------|-----------------------------------------------
**  26Jul97     snapper      creation of the command
**  29Jul97     subtle       removed use of ranks
*/

package key.commands;
import key.*;
import key.primitive.*;
import java.io.*;
import java.util.StringTokenizer;

public class Citizen extends Command
{
	public static final AtomicElement[] ELEMENTS =
	{
		AtomicElement.construct( Citizen.class, String.class, "message",
			AtomicElement.PUBLIC_FIELD,
			"the message sent to the player when the citizening worked" ),
		AtomicElement.construct( Citizen.class, String.class, "feedback",
			AtomicElement.PUBLIC_FIELD,
			"the message sent to the superuser" ),
		AtomicElement.construct( Citizen.class, String.class, "splashback",
			AtomicElement.PUBLIC_FIELD,
			"the message sent to the SU channel" ),
		AtomicElement.construct( Citizen.class, Scape.class, "splashTo",
			AtomicElement.PUBLIC_FIELD,
			"the SU channel to send the message to" )
	};

	public static final AtomicStructure STRUCTURE = new AtomicStructure( Command.STRUCTURE, ELEMENTS );
	
	public static final char originatorCode = 'o';
	public static final char targetCode = 't';

	public String message = "--\n%o has made you a citizen!\n--";
	public String feedback = "You grant citizenship to %t.";
	public String splashback =  "%o grants citizenship to %t.";
	public Reference splashTo = Reference.EMPTY;
	
	public Citizen()
	{
		setKey( "citizen" );
		usage = "<player>";
	}
	
	public AtomicStructure getDeclaredStructure()
	{
		return( STRUCTURE );
	}
	

	public void run( Player p, StringTokenizer args, String fullLine, CategoryCommand caller, InteractiveConnection ic, Flags flags ) throws IOException
	{
		String playerName;
		Player targetPlayer;

		if( args.hasMoreTokens() )
		{
			playerName = args.nextToken();
			targetPlayer = (Player) getOnlinePlayer( p, ic, playerName );
			
			if( targetPlayer == null )
				return;
			
				// check to see if they're in the rank
			if( targetPlayer.isCitizen() )
			{
				ic.sendError( targetPlayer.getName() + " is already a citizen." );
				return;
			}
			
			Duration dur = (Duration) targetPlayer.loginStats.getTotalConnectionTime();
			
			int login = (int)(dur.getTime() / Duration.SIH);
			
			if( login < 16 )
			{
				ic.sendFeedback( "They require more than 16 hours login time to be a citizen..." );	
				return;
			}
			
			targetPlayer.setCitizen( true );
			
			p.putCode( originatorCode, p.getName() );
			p.putCode( targetCode, targetPlayer.getName() );
			
			message = Grammar.substitute( message, p.getCodes() );
			feedback = Grammar.substitute( feedback, p.getCodes() );
			splashback = Grammar.substitute( splashback, p.getCodes() );
			
			(new key.effect.PrivilegedAction( p, targetPlayer, feedback, message, splashback, (Scape) splashTo.get() ) ).cause();
			Log.log( "citizen", splashback );
		}
		else
			usage( ic );
	}
}