/
LIB3/
LIB3/D/ADMIN/
LIB3/D/ADMIN/OBJ/
LIB3/D/ADMIN/ROOM/W/
LIB3/D/HOME/
LIB3/D/HOME/CITY/ARENA/
LIB3/D/HOME/CITY/ITEMS/
LIB3/D/HOME/CITY/POSTOFFI/
LIB3/DOC/
LIB3/GLOBAL/SPECIAL/
LIB3/GLOBAL/VIRTUAL/
LIB3/NET/
LIB3/NET/CONFIG/
LIB3/NET/DAEMON/CHARS/
LIB3/NET/GOPHER/
LIB3/NET/INHERIT/
LIB3/NET/OBJ/
LIB3/NET/SAVE/
LIB3/NET/VIRTUAL/
LIB3/OBJ/B_DAY/
LIB3/OBJ/HANDLERS/TERM_TYP/
LIB3/PLAYERS/B/
LIB3/PLAYERS/N/
LIB3/ROOM/
LIB3/SAVE/
LIB3/SAVE/BOARDS/
LIB3/SAVE/ENVIRON/
LIB3/SAVE/POST/
LIB3/STD/COMMANDS/SHADOWS/
LIB3/STD/CREATOR/
LIB3/STD/DOM/
LIB3/STD/EFFECTS/
LIB3/STD/EFFECTS/HEALING/
LIB3/STD/EFFECTS/OTHER/
LIB3/STD/EFFECTS/POISONS/
LIB3/STD/ENVIRON/
LIB3/STD/GUILDS/
LIB3/STD/LIQUIDS/
LIB3/STD/ROOM/
LIB3/STD/TRIGGER/SHADOW/
LIB3/W/
LIB3/W/BANNOR/
LIB3/W/NEWSTYLE/
#define MAIL_LIST "/log/TEMPORARY_ERRORS"
#define YEAR 31449600
#define WEEK 604800
#define DAY 86400
#define HOUR 3600
#define MINUTE 60
#include "log.h";

int     check_time;
static mapping list;

create()
{
    seteuid( "Root" );
    restore_object( file_name( this_object() ) );
    if( !list )
	list = ([ ]);
    check_time();
}

check_time()
{
    if( time() > check_time )
    {
	/* Next check is in 7 days */
	check_time += WEEK;
	check_error_log();
	mail_forgoten_reports();
	save_me();
    }
}

check_error_log()
{
    int     i, j, rtime;
    string  reports, report;
    string  name, filename;
    string  person;
    string  temp;

    reports = read_file( MAIL_LIST );
    if( reports )
    {
	j = file_length( MAIL_LIST );
	list = ([ ]);
	for( i = 0; i < j; i++ )
	{
	    sscanf( reports, "%s %d %s\n%s", name, rtime, filename, reports );
	    if( filename[ 0..1 ] == "d/" )
	    {
		temp = "/secure/master"->get_dom_name( filename );
		temp = "/d/" + temp + "/master";
		person = temp->query_lord();
	    }
	    else
		person = "debug";
	    if( rtime + (2 * WEEK) < time() )
	    {
		if( undefinedp( list[ person ] ) )
		    list[ person ] = ({ filename, rtime });
		else
		    list[ person ] += ({ filename, rtime });
	    }
	}
    }
}

mail_forgoten_reports()
{
    int     i, j;
    string  file;
    string *lord;
    string  body;

    lord = keys( list );
    for( i = 0; i < sizeof( lord ); i++ )
    {
	body = "The following files have not been checked :\n\n";
	for( j = 0; j < sizeof( list[ lord[ i ] ] ); j += 2 )
	    body += "  " + list[ lord[ i ] ][ j ] + " for\n    " +
		secs_to_time( time() - list[ lord[ i ] ][ j + 1 ] ) + "\n\n";
	body += "This was brought to you by :\n" +
	    "\tGhost's automatic error notification service.";
	"/obj/handlers/mailer"->do_mail_message( lord[ i ], "Driver",
						 "Forgoten error reports", "", body, 0, 0 );
    }
}

secs_to_time( int s )
{
    int     i;
    string  t;

    t = "";
    i = s / YEAR;
    s -= i * YEAR;
    if( i > 0 )
	if( i == 1 )
	    t += i + " year, ";
	else
	    t += i + " years, ";

    i = s / WEEK;
    s -= i * WEEK;
    if( i > 0 )
	if( i == 1 )
	    t += i + " week, ";
	else
	    t += i + " weeks, ";

    i = s / DAY;
    s -= i * DAY;
    if( i > 0 )
    {
	if( i == 1 )
	    t += i + " day, ";
	else
	    t += i + " days, ";
    }

    i = s / HOUR;
    s -= i * HOUR;
    if( i == 1 )
	t += i + " hour, ";
    else
	t += i + " hours, ";

    i = s / MINUTE;
    s -= i * MINUTE;
    if( i == 1 )
	t += i + " minute, ";
    else
	t += i + " minutes, ";

    t += "and ";
    if( s == 1 )
	t += i + " second.";
    else
	t += i + " seconds.";
    return t;
}

save_me()
{
    save_object( file_name( this_object() ) );
}