/* $Id: driver.c,v 1.4 1998/02/22 13:43:51 esimonse Exp $ */ /* $Log: driver.c,v $ * Revision 1.4 1998/02/22 13:43:51 esimonse * Added support for editing * * Revision 1.3 1998/01/29 16:11:58 esimonse * Added Id and Log. * */ #include <status.h> private object load( string path ) { object ob; ob = find_object( path ); return( ob ) ? ob : compile_object( path ); } void message(string str) { send_message(ctime(time())[4 .. 18] + " ** " + str); } static initialize() { message( "DGD " + status()[ST_VERSION] + " running " + LIB_NAME + " " + LIB_VERSION + ".\n"); message( "Initializing...\n" ); message( "Preloading...\n" ); compile_object( STARTING_ROOM ); message( "Setting up events\n" ); EVENT_D->add_event( "clean_up" ); EVENT_D->add_event( "player_login" ); EVENT_D->add_event( "player_logout" ); EVENT_D->add_event( "heart_beat" ); EVENT_D->add_event( "new_player" ); message( "Setting up daemons\n" ); call_other( FTP_D, "initialize" ); call_other( CHANNEL_D, "???" ); call_other( TIME_D, "???" ); call_other( IMUD_D, "???" ); call_other( OBJECT_D, "???" ); call_other( RACE_D, "???" ); call_other( SKILL_D, "???" ); call_other( MONEY_D, "???" ); call_other( BANISH_D, "???" ); call_other( SITEBAN_D, "???" ); call_other( GUILD_D, "???" ); call_other( LANGUAGE_D, "???" ); call_other( PARSE_D, "???" ); message( "Setting up call outs\n" ); call_out( "swapswap", 1800 ); call_out( "clean_up", 60 ); call_out( "heart_beat", 2 ); message( "Opening port...\n" ); open_port( "telnet", LOGIN_PORT ); message( "Done.\n" ); } static void heart_beat( void ) { EVENT_D->event( "heart_beat" ); call_out( "heart_beat", 2 ); } static void clean_up( void ) { EVENT_D->event( "clean_up" ); call_out( "clean_up", 60 ); } static void swapswap() { swapout(); call_out( "swapswap", 1800 ); } object clone_object( string path ) { object ob; if( ob = find_object( path ) ) return ::clone_object( ob ); else return ::clone_object( compile_object( path ) ); } static restored() { message( "DGD " + status()[ST_VERSION] + " running Gurba.\n" ); message( "State restored.\n" ); } /* * NAME: normalize_path() * DESCRIPTION: reduce a path to its minimal absolute form */ string normalize_path(string file, string dir) { string *path; int i, j, sz; if (strlen(file) == 0) { file = dir; } switch (file[0]) { case '~': /* ~path */ if(strlen(file) == 1 || file[1] == '/') { file = "/wiz/" + this_user()->query_name() + file[1 ..]; } else { file = "/wiz/" + file[1 ..]; } /* fall through */ case '/': /* absolute path */ path = explode(file, "/"); if( (path[0] == "data" || path[0] == "kernel") && SECURE_D->query_admin( this_user()->query_name() ) == 0 ) return(""); if (sscanf(file, "%*s//") == 0 && sscanf(file, "%*s/.") == 0) { return file; /* no changes */ } break; default: /* relative path */ if (sscanf(file, "%*s//") == 0 && sscanf(file, "%*s/.") == 0 && sscanf(dir, "%*s/..") == 0) { /* * simple relative path */ if( dir[strlen(dir)-1] == '/' ) path = explode( dir + file, "/" ); else path = explode( dir + "/" + file, "/" ); if( (path[0] == "data" || path[0] == "kernel") && SECURE_D->query_admin( this_user()->query_name() ) == 0 ) return(""); if( dir[strlen(dir)-1] == '/' ) return dir + file; else return dir + "/" + file; } /* fall through */ case '.': /* * complex relative path */ path = explode(dir + "/" + file, "/"); break; } for (i = 0, j = -1, sz = sizeof(path); i < sz; i++) { switch (path[i]) { case "..": if (j >= 0) { --j; } /* fall through */ case "": case ".": continue; } path[++j] = path[i]; } if( (path[0] == "data" || path[0] == "kernel") && SECURE_D->query_admin( this_user()->query_name() ) == 0 ) { return ""; } return "/" + implode(path[.. j], "/"); } string path_read( string path ) { string file; file = normalize_path( path, this_user()->query_player()->query_env("cwd") ); return( file ); } string path_write( string path ) { string file; file = normalize_path( path, this_user()->query_player()->query_env("cwd") ); return( file ); } object call_object( string name ) { object ob; if( ob = find_object(name) ) return ob; ob = compile_object(name); return ob; } object inherit_program( string file, string program ) { object ob; if( ob = find_object( program ) ) return ob; else return compile_object( program ); } string path_include( string file, string path ) { if( path[0] != '/' ) { return file + "/../" + path; } else { return path; } } void recompile( object obj ) { message( "recompile( obj );\n" ); } object connection( string ip, int port ) { object user; message( "New connection from " + ip + "\n" ); user = clone_object( "/std/user" ); user->login(); return( user ); } void interrupt() { object *usrs; int i; for( i=0; i < sizeof( usrs ); i++ ) { usrs[i]->query_player()->do_quit(); } message( "Shutting down." ); shutdown(); } void compile_error( string file, int line, string err ) { object usr; object plr; /* Error during compiling */ err = file + ", " + line + ": " + err + "\n"; send_message( err ); write_file("/logs/errors/compile", err); usr = this_user(); if( usr != 0 ) { if( usr->query_player() != 0 ) { if( SECURE_D->query_wiz( usr->query_player()->query_name() ) == 1 ) { usr->query_player()->write( err ); } else { usr->query_player()->write( "You have encountered a rift in reality. Please report it to the admins.\n" ); } } } } void runtime_error( string error, int cought, int ticks ) { mixed **trace; string progname, objname, function, str; int i, sz, line, len; object player; if( cought ) { return; } trace = call_trace(); if( (sz=sizeof(trace) - 1) != 0 ) { for( i=0; i<sz; i++ ) { progname = trace[i][1]; function = trace[i][2]; objname = trace[i][0]; line = trace[i][3]; if( line == 0 ) { str = " "; } else { str = " " + line; str = str[strlen( str ) - 4 ..]; } str += " " + function + " "; len = strlen( function ); if( len < 17 ) { str += " "[len ..]; } str += progname; if( progname != objname ) { len = strlen(progname); if( len < strlen(objname) && progname == objname[.. len - 1]) { str += " (" + objname[len ..] + ")"; } else { str += " (" + objname + ")"; } } send_message( str + "\n" ); if( this_user() != 0 ) { player = this_user()->query_player(); if( player != 0 ) { if( i == 0 ) { player->write( error + "\nObject: " + objname + ", program: " + progname + ", line " + line + "\n" ); } else { player->write( "\nObject: " + objname + ", program: " + progname + ", line " + line + "\n" ); } } } } } } int compile_rlimits( string objname ) { message( "compile_rlimits( " + objname + " );\n" ); } int runtime_rlimits( object obj, int stack, int ticks ) { message( "runtime_rlimits( );\n" ); } void remove_program( string objname, int timestamp, int index ) { message( "remove_program( " + objname + ",... );\n" ); }