LOG.C
LIB3/GLOBAL/LOG.C · 13.6 KB
From the archive nm4dos.zip
Download the archive « Back to the archive contents
#define TEMP_MAIL_LIST "/w/" + this_player()->query_name() + "/TEMP_MAIL_LIST"
#define TEMP_ERRORS "/log/TEMPORARY_ERRORS"
#include "log.h";
inherit "/std/smart_log";
int bug_num, bugs;
string error, file;
string temp_body;
void logging_commands()
{
add_action( "log_bug", "bug" );
add_action( "log_typo", "typo" );
add_action( "log_idea", "idea" );
add_action( "log_soul", "soul" );
add_action( "test", "test" );
if( this_player()->query_creator() )
add_action( "errors", "errors" );
}
int log_typo( string str )
{
if( !str || "" == str )
{
notify_fail( "Usage : typo <text>\n" );
return 0;
}
smart_log( "TYPO", this_player()->query_name() + "\n" + str + "\n",
file_name( environment() ) );
write( "Ok.\n" );
return 1;
}
void bug_command( string str )
{
int i;
string trash;
mixed *junk, *coms;
if( !str || str == "" )
return;
coms = ({ });
junk = actions_defined( 0, 0, 12 );
for( i = 0; i < sizeof( junk ); i += 2 )
if( junk[ i ] == str )
coms += ({ junk[ i ], junk[ i + 1 ][ 0 ], junk[ i + 1 ][ 1 ] });
if( !sizeof( coms ) )
{
write( "Command " + str + " not found.\n" );
return;
}
if( sizeof( coms ) > 3 )
{
write( "More than one commands with the name " + str +
" found. Please be more specific.\n" );
return;
}
file = function_exists( (string)coms[ 2 ], ( object ) coms[ 1 ] );
sscanf( file, "%s#%s", file, trash );
error = "COMMAND " + str;
this_player()->do_edit( 0, "end_of_edit" );
}
void bug_spell( string str )
{
int i;
mapping junk;
junk = this_player()->query_spells();
if( undefinedp( junk[ str ] ) )
{
write( "Spell " + str + " not found.\n" );
return;
}
file = junk[ str ][ 0 ];
error = "SPELL " + str;
this_player()->do_edit( 0, "end_of_edit" );
}
void bug_object( string str )
{
string trash;
object *obj;
if( !str || str == "" )
return;
obj = find_match( str, this_object() );
if( sizeof( obj ) == 0 )
obj = find_match( str, environment( this_object() ) );
if( !sizeof( obj ) )
{
write( "Object " + str + " not found.\n" );
return;
}
if( sizeof( obj ) > 1 )
{
write( "More than one objects can be identified with the name " + str + "\n" );
return;
}
file = file_name( obj[ 0 ] );
sscanf( file, "%s#%s", file, trash );
error = "OBJECT BUG";
this_player()->do_edit( 0, "end_of_edit" );
}
int log_bug( string str )
{
string arg;
if( !str || str == "" )
str = "room";
sscanf( str, "%s %s", str, arg );
notify_fail( "Usage : bug [command/spell/object/room] [name]\n" );
if( str != "command" && str != "spell" && str != "object" && str != "room" )
return 0;
switch( str )
{
case "command":
bug_command( arg );
break;
case "spell":
bug_spell( arg );
break;
case "object":
bug_object( arg );
break;
case "room":
file = file_name( environment() );
error = "ROOM BUG";
this_player()->do_edit( 0, "end_of_edit" );
break;
}
return 1;
}
void end_of_edit( string body )
{
if( body && body != "" )
smart_log( error, this_player()->query_name() + "\n" + body + "\n",
file );
}
int log_idea( string str )
{
if( !str || "" == str )
{
notify_fail( "Usage : idea <text>\n" );
return 0;
}
smart_log( "IDEA", this_player()->query_name() + "\n" + str + "\n",
file_name( environment() ) );
write( "Ok.\n" );
return 1;
}
int log_soul( string str )
{
if( !str || str == "" )
{
notify_fail( "Usage : soul <text>\n" );
return 0;
}
if( str == "on" || str == "off" )
{
write( "\"soul\" is the command to report suggestions/errors" +
" with soul commands.\n" +
"If you wish to turn your soul off or on, use the " +
"\"nosoul\" command.\n" );
return 1;
}
str = sprintf( "%s: %s\n", this_player()->query_cap_name(), str );
str = sprintf( "%-=79s", str );
log_file( "soulcommands", str );
write( "Ok, your suggestion has been logged! Thank you.\n" );
return 1;
}
void print_bug( int i )
{
int rtime;
string fmt, trash, bug;
string title, filename;
string ftime, fname;
string time, name;
if( bugs == 0 || i > bugs )
return;
fmt = "%s.START " + i + "\n%s.END " + i;
sscanf( error, fmt, trash, bug );
sscanf( bug, "%s\n%s\n%s\n%s\n%s\n%s\n%s", title, filename, ftime, fname,
time, name, bug );
write( title + "\n" );
write( filename + "\n" );
if( ftime != "" )
{
write( "Forwarded from : " + capitalize( fname ) + "\n" );
sscanf( ftime, "%d", rtime );
write( "at : " + ctime( rtime ) + "\n" );
}
write( "Made by : " + capitalize( name ) + "\n" );
sscanf( time, "%d", rtime );
write( "at : " + ctime( rtime ) + "\n" );
write( bug );
}
void request()
{
if( bugs > 0 )
write( "[1-" + bugs + "](" + bug_num + ")" );
else
write( "[No bugs]" );
write( "Choose from EUFDNPGQX H for help. " );
input_to( "commands" );
}
int errors( string str )
{
string bug, temp;
if( !str )
str = this_player()->query_current_path();
if( str[ strlen( str ) - 1..strlen( str ) ] != "/" )
str += "/";
str += ERROR_LOG;
error = read_file( str );
file = str;
if( !error )
write( "No error found in this dir.\n" );
else
{
rm( TEMP_MAIL_LIST );
temp = read_file( str, file_length( str ), 1 );
sscanf( temp, ".END %d", bugs );
bug_num = 1;
print_bug( bug_num );
request();
}
return 1;
}
delete_bug( int n )
{
int i;
string fmt, bug, trash;
fmt = "%s.START " + n + "\n%s.END " + n + "\n%s";
sscanf( error, fmt, error, bug, trash );
error += trash;
for( i = n + 1; i < bugs + 1; i++ )
{
fmt = "%s.START " + i + "\n%s.END " + i + "\n%s";
sscanf( error, fmt, error, bug, trash );
error += ".START " + (i - 1) + "\n" + bug + ".END " + (i - 1) + "\n" + trash;
}
bugs -= 1;
}
end_of_mail( string body )
{
string name, bug, rtime;
if( body && body != "" )
{
sscanf( temp_body, "%s %s %s", name, rtime, bug );
if( sscanf( body, "%s$report$%s", body, temp_body ) == 2 )
body += bug + temp_body;
write_file( TEMP_MAIL_LIST, name + " " + rtime + " " + body + "END" );
}
print_bug( bug_num );
request();
}
int commands( string str )
{
int i;
string bug, ed_file, trash, fmt;
string title, filename;
string ftime, fname;
string rtime, name;
if( str[ 0..0 ] == "g" )
sscanf( str, "%s %d", str, i );
if( str[ 0..0 ] == "e" || str[ 0..0 ] == "f" || str[ 0..0 ] == "d" )
sscanf( str, "%s %s", str, ed_file );
str = lower_case( str );
switch( str )
{
case "e":
if( !ed_file )
{
fmt = "%s.START " + bug_num + "\n%s.END " + bug_num;
sscanf( error, fmt, trash, bug );
sscanf( bug, "%s\n%s\n", trash, ed_file );
ed_file += ".c";
}
write( "Editing " + ed_file + "\n" );
ed( ed_file, "request" );
return 1;
case "u":
str = "f";
ed_file = "unknown";
case "f":
write( "Sorry but the forward option is down to the pub at the moment " +
"having a pint and some peanuts. It will be back very shortly.\n" );
print_bug( bug_num );
request();
return 1;
if( !ed_file )
write( "You must either give the name of a creator, or a directory.\n" );
else
{
string cre;
cre = this_player()->expand_nickname( ed_file );
if( "/secure/login"->test_creator( cre ) || cre == "unknown" )
{
fmt = "%s.START " + bug_num + "\n%s.END " + bug_num;
sscanf( error, fmt, trash, bug );
sscanf( bug, "%s\n%s\n%s\n%s\n%s\n%s\n%s", title, filename, ftime,
fname, rtime, name, bug );
if( ftime == "\n" )
{
write( "No previous forwarding!\n" );
trash = read_file( TEMP_ERRORS );
if( sscanf( trash, "%s" + name + " " + rtime + "%s\n%s", trash, filename, fmt ) == 3 )
{
write( filename + "\n" );
trash += fmt + name + " " + time() + filename + "\n";
}
"/global/error"->new_mail_list( trash );
}
else
{
write( "Previous forwarding!\n" );
trash = read_file( TEMP_ERRORS );
if( sscanf( trash, "%s" + fname + " " + ftime + "%s\n%s", trash, filename, fmt ) == 3 )
trash += fmt + name + " " + time() + filename + "\n";
"/global/error"->new_mail_list( trash );
}
bug = title + "\n" + filename + "\n" + time() + "\n" +
this_player()->query_name() + "\n" + rtime + "\n" + name +
"\n" + bug;
if( cre == "unknown" )
trash = "/log/" + ERROR_LOG;
else
trash = "/w/" + cre + "/" + ERROR_LOG;
i = file_length( trash );
if( i > 0 )
{
fmt = read_file( trash, i, 1 );
if( sscanf( fmt, ".END %d", i ) == 1 )
i += 1;
else
i = 1;
}
else
i = 1;
bug = ".START " + i + "\n" + bug + ".END " + i + "\n";
"/secure/master"->forward_error( trash, bug );
delete_bug( bug_num );
write( "Forwarded (hopefully :).\n" );
}
else
{
if( file_size( ed_file ) == -2 )
{
fmt = "%s.START " + bug_num + "\n%s.END " + bug_num;
sscanf( error, fmt, trash, bug );
sscanf( bug, "%s\n%s\n%s\n%s\n%s\n%s\n%s", title, filename, ftime,
fname, rtime, name, bug );
bug = title + "\n" + filename + "\n" + time() + "\n" +
this_player()->query_name() + "\n" + rtime + "\n" + name +
"\n" + bug;
trash = ed_file + "/" + ERROR_LOG;
i = file_length( trash );
if( i > 0 )
{
fmt = read_file( trash, i, 1 );
if( sscanf( fmt, ".END %d", i ) == 1 )
i += 1;
else
i = 1;
}
else
i = 1;
bug = ".START " + i + "\n" + bug + ".END " + i + "\n";
"/secure/master"->forward_error( trash, bug );
delete_bug( bug_num );
write( "Forwarded (hopefully :).\n" );
}
else
{
write( "No.\n" );
}
}
}
print_bug( bug_num );
request();
return 1;
case "d":
if( ed_file == "f" || ed_file == "" || !ed_file )
{
fmt = "%s.START " + bug_num + "\n%s.END " + bug_num + "\n%s";
sscanf( error, fmt, trash, bug, trash );
sscanf( bug, "%s\n%s\n%s\n%s\n%s\n%s\n%s", title, filename, ftime,
fname, rtime, name, bug );
bug = "The following bug has now been fixed.\n" + bug +
"\n" + "Thank you for reporting it.\n\n" +
"This was an automatic mail.\n";
write_file( TEMP_MAIL_LIST, name + " " + rtime + " " + bug + "END" );
}
if( ed_file == "n" )
{
fmt = "%s.START " + bug_num + "\n%s.END " + bug_num + "\n%s";
sscanf( error, fmt, trash, bug, trash );
sscanf( bug, "%s\n%s\n%s\n%s\n%s\n%s\n%s", title, filename, ftime,
fname, rtime, name, bug );
bug = "The following report by you is not a bug.\n" + bug +
"\n" + "Thank you for reporting it anyway though.\n" +
"This was an automatic mail.\n";
write_file( TEMP_MAIL_LIST, name + " " + rtime + " " + bug + "END" );
}
if( ed_file == "r" )
{
fmt = "%s.START " + bug_num + "\n%s.END " + bug_num + "\n%s";
sscanf( error, fmt, trash, bug, trash );
sscanf( bug, "%s\n%s\n%s\n%s\n%s\n%s\n%s", title, filename, ftime,
fname, rtime, name, bug );
temp_body = name + " " + rtime + " " + bug;
this_player()->do_edit( 0, "end_of_mail" );
}
delete_bug( bug_num );
if( ed_file != "r" )
{
print_bug( bug_num );
request();
}
return 1;
case "":
case "+":
case "n":
if( bug_num < bugs )
{
bug_num += 1;
print_bug( bug_num );
}
else
write( "No more errors\n" );
request();
return 1;
case "-":
case "p":
if( bug_num > 1 )
{
bug_num -= 1;
print_bug( bug_num );
}
else
write( "This is the first error.\n" );
request();
return 1;
case "g":
if( i > 0 && i < bugs + 1 )
{
bug_num = i;
print_bug( bug_num );
}
else
write( "Error number doesn't exists.\n" );
request();
return 1;
case "q":
rm( TEMP_MAIL_LIST );
return 1;
case "x":
if( rm( file ) )
{
write_file( file, error );
error = read_file( TEMP_MAIL_LIST );
if( error )
{
trash = read_file( TEMP_ERRORS );
while( sscanf( error, "%s %s %sEND%s", name, rtime, bug, error ) == 4 )
{
if( sscanf( trash, "%s" + name + " " + rtime + "%s\n%s", trash, fname, title ) == 3 )
{
trash += title;
"/obj/handlers/mailer"->do_mail_message( name,
this_player()->query_name(), "Bug report", "", bug, 0, 0 );
log_file( "REPLIES", this_player()->query_name() + " replied " +
"to " + name + "\n" );
}
}
"/global/error"->new_mail_list( trash );
rm( TEMP_MAIL_LIST );
}
write( "Done.\n" );
}
else
write( "Error!\n" );
return 1;
case "h":
case "?":
write( "E - Edit the file to correct the error.\n" );
write( "E f - Edit file with name f.\n" );
write( "U - Forward and delete error to unknow list.\n" );
write( "F n - Forward and delete error to creator or directory n.\n" );
write( "D - Delete bug and mark as fixed.\n" );
write( "D F - same as above.\n" );
write( "D N - Delete bug and mark as not an error.\n" );
write( "D R - Delete bug and reply to sender yourself.\n" );
write( " The word $report$ will be replaced by the original\n" );
write( " bug report.\n" );
write( "N/+ - Next error.\n" );
write( "P/- - Previous error.\n" );
write( "G - Goto to error.\n" );
write( "Q - Quit.\n" );
write( "X - Save and quit.\n" );
write( "H/? - This help file.\n" );
request();
return 1;
default:
request();
return 1;
}
}