#include "boot.clh"

object WIZARD
    parents PROGRAMMER;

    verb	"@wiz*ard" = wiz_cmd;
    verb	"@dewiz*ard" = dewiz_cmd;
    verb	"@force" : "to" = force_cmd;
    verb	"@force" = force_cmd;
    verb	"@mem" = mem_cmd;
    verb	"@cachestats @cache_stats @cs" = cachestats_cmd;
    verb	"@vis*itors" = visitors_cmd;
    verb	"@boot" = boot_cmd;
    verb	"@shout" = shout_cmd;
    verb	"@shutdown" = shutdown_cmd;

    method init
	if (this == WIZARD)
	    name = "Wizard";
	    password = "83pil1MP02An.";
	    desc = "A short, aged guy with a pointy hat.";
	    this.add_owner(WIZARD);
	endif
	pass() to PLAYER;
    endmethod /* init */

    method cachestats_cmd
	echo(cache_stats());
    endmethod

    method wiz_cmd
	var	who;

	if (caller != this)
	    return 1;
	elseif(!args[2])
	    echo("Usage:  @wizard <player>");
	    return 0;
	endif
	who = SYS_OBJ.find_player(args[2]);
	if (!who)
	    echo("I couldn't find that player.");
	elseif (who in SYS_OBJ.wizards)
	    echo(who.name + " is already a wizard.");
	elseif (!(who in SYS_OBJ.players))
	    echo("That's not a player.");
	else    
	    SYS_OBJ.add_wizard(who);
	endif
    endmethod /* wiz_cmd */

    method dewiz_cmd
	var	who;

	if (caller != this)
	    return 1;
	elseif(!args[2])
	    echo("Usage:  @dewizard <player>");
	    return 0;
	endif
	who = SYS_OBJ.find_player(args[2]);
	if (!who)
	    echo("I couldn't find that player.");
	elseif (!(who in SYS_OBJ.wizards))
	    echo("That's not a wizard.");
	elseif (who == player)
	    echo("You can't dewiz yourself; ask another wizard.");
	else
	    SYS_OBJ.rm_wizard(who);
	endif
    endmethod /* dewiz_cmd */

    method force_cmd
	var	who;

	if (caller != this)
	    return 1;
	elseif (!args[2] || !args[3] || !args[4])
	    echo("Usage:  @force <player> to <cmd>");
	    return 0;
	endif
	who = this.match_env(args[2]);
	if (!who)
	    echo("Force whom?");
	else
	    player = who;
	    player.parse(args[4]);
	endif
    endmethod

    method mem_cmd		/* verb */
	if (caller != this)
	    return 1;
	endif
	echo(checkmem());
    endmethod /* mem_cmd */

    method visitors_cmd		/* verb */
	var	item, id;
	ignore	E_SERVERDN;

	if (caller != this)
	    return 1;
	endif
	echo("Remote objects:");
	for item in (SYS_OBJ.visitors())
	    id = item[1].id;
	    if (id == E_SERVERDN)
		echo("(Ghost of " + tostr(item[1]) + ") is in "
			+ item[2].id);
	    else
		echo(item[1].id + " is in " + item[2].id);
	    endif
	endfor
	echo("---");
    endmethod /* visitors_cmd */

    method boot_cmd /* verb */
	var	who;

	if (caller != this)
	    return 1;
	elseif (!args[2])
	    echo("Usage:  @boot <player>");
	    return 0;
	endif
	who = SYS_OBJ.find_connected_player(args[2]);
	if (!who)
	    echo("That player is not connected.");
	else
	    if (who.quit_cmd())
		echo("You can't boot that player.");
	    else
		echo("Player booted.");
	    endif
	endif
    endmethod /* boot_cmd */

    method shout_cmd 		/* verb */
	var	dude, msg;

	if (caller != this)
	    return 1;
	endif
	msg = name + " shouts, \"" + args[2] + "\"";
	for dude in (SYS_OBJ.connected_players)
	    dude.tell(msg);
	endfor
    endmethod /* shout_cmd */

    method shutdown_cmd
	if (caller != this)
	    return 1;
	endif
	writelog("SHUTDOWN by " + this.id);
	shutdown();
    endmethod

endobject /* WIZARD */