Emergancy Copyover NOTE: You must have any Copyover function installed that has a copyover_recover() part to it. If not, this code will not work just by plugging it in. You will need to do work yourself. What this does: Hate those crashes your MUD has when something just doesn't go the way you want it to? Well, with this snippet, installed properly of course, you will eliminate most crashes that can be avoided. This ECOPYOVER will detect a crash, and copyover before the MUD can crash, therefore saving the MUD and just leaving everyone a bit shaken up due to an ECOPYOVER. You can also toggle the ECOPYOVER on and off with CSET ECOPYOVER. There is one way that this code will allow a crash, and that is if you have a crash, right after it copyovers. It doesn't have time to detect the crash and then your MUD crashes. What you will need to change: act_wiz.c comm.c db.c mud.h ../system/sysdata.dat *Always remember to backup the files you will change incase of an error with installation, or an error with the code. cp .bak What you will need to add: Nothing. ------------------------------------------------------------------------------------------------- act_wiz.c Find, void do_cset( CHAR_DATA *ch, char *argument ) Somewhere in there where it lists all of the CSET option, add this, ch_printf(ch, " Emergancy Copyover: %s\n\r", sysdata.ECOPYOVER ? "On" : "Off" ); Find, if (!str_cmp(arg, "saveflag")) Above that add, if ( !str_cmp( arg, "ecopyover" ) ) { sysdata.ECOPYOVER = !sysdata.ECOPYOVER; if ( sysdata.ECOPYOVER ) send_to_char( "Emergancy Copyover enabled.\n\r", ch ); else send_to_char( "Emergancy Copyver disabled.\n\r", ch ); return; } ------------------------------------------------------------------------------------------------- comm.c Find, int maxdesc; Below that add, bool emergancy_copy; static void SegVio(); Find, num_descriptors = 0; Below that add, emergancy_copy = TRUE; Find, void SegVio(int sig) (Delete your current SegVio function, and add this one), static void SegVio() { CHAR_DATA *ch; char buf[MAX_STRING_LENGTH]; char bufB[MAX_STRING_LENGTH]; char *strtime; strtime = ctime( ¤t_time ); strtime[strlen(strtime)-1] = '\0'; log_string( "--- SEGMENTATION VIOLATION ---" ); sprintf( buf, "%slastcmd.log", LOG_DIR ); if ( file_size(buf) < 5000000 ) { sprintf( bufB, "%s :: %s", strtime, lastplayercmd ); append_to_file( buf, bufB ); } if ( !sysdata.ECOPYOVER ) { log_string( "Emergancy copyover not enabled. Shutting down." ); } else if ( emergancy_copy == TRUE ) { emergancy_copyover( ); log_string( "Emergancy copyover not ready. Shutting down." ); } else { log_string( "Emergancy copyover not ready. Shutting down." ); } exit(0); } Find, /* signal( SIGSEGV, SegVio ); */ Delete the /* and */ Below your SegVio() function, add this, void emergancy_copyover( void ) { FILE *fp; DESCRIPTOR_DATA *d; char buf[100], buf2[100], buf3[100], buf4[100], buf5[100]; log_string( "--- Engaging Emergancy Copyover! ---" ); fp = fopen (COPYOVER_FILE, "w"); if (!fp) { log_string ( "Could not write to copyover file!" ); perror ("emergancy_copyover:fopen"); return; } sprintf (buf, "\n\r [ALERT]: EMERGENCY COPYOVER - Keep calm, we might pull through!\n\r" ); /* For each playing descriptor, save its state */ for (d = first_descriptor; d ; d = d->next) { CHAR_DATA * och = CH (d); d_next = d->next; /* We delete from the list , so need to save this */ if (!och || !d->character || d->connected > CON_PLAYING) /* drop those logging on */ { write_to_descriptor (d->descriptor, "\n\rSorry, we are rebooting. Come back in a few minutes.\n\r", 0); /* close_socket (d, FALSE); */ } else { fprintf (fp, "%d %s %s\n", d->descriptor, och->name, d->host); save_char_obj (och); write_to_descriptor (d->descriptor, buf, 0); } } fprintf (fp, "-1\n"); fclose (fp); fclose (fpReserve); fclose (fpLOG); sprintf (buf, "%d", port); sprintf (buf2, "%d", control); sprintf (buf3, "%d", control2); execl (EXE_FILE, "swreality", buf, "copyover", buf2, buf3, buf4, buf5, (char *) NULL); perror ("emergancy_copyover: failed to copyover in 'execl'"); if ( ( fpReserve = fopen( NULL_FILE, "r" ) ) == NULL ) { perror( NULL_FILE ); exit( 1 ); } if ( ( fpLOG = fopen( NULL_FILE, "r" ) ) == NULL ) { perror( NULL_FILE ); exit( 1 ); } } void emergancy_arm( ) { if ( !emergancy_copy ) { bug( "Notice: Emergancy hotboot system is ready." ); emergancy_copy = TRUE; } return; } Somewhere at the bottom of comm.c, add this function, (its used for the log file created by the emergancy copyover) int file_size( char * buf ) { FILE *fp; int size=0; if ( ( fp = fopen( buf, "rb" ) ) == NULL ) { bug( "file_size: could not open file to retrive size."); return -1; } /* Seek to end of file */ if ( fseek( fp, 0, SEEK_END ) != 0 ) { bug( "file_size: failed seek-to-end operation."); fclose( fp ); return -1; } /* Returns the number of characters from the beginning */ size = ftell( fp ); fclose( fp ); return size; } ------------------------------------------------------------------------------------------------- db.c Find, fprintf( fp, "Savefreq %d\n", sys.save_frequency ); Below it add, fprintf( fp, "ECopyover %d\n", sys.ECOPYOVER ); Find, case 'E': Below it add, KEY( "ECopyover", sys->ECOPYOVER, fread_number( fp ) ); ------------------------------------------------------------------------------------------------- mud.h Find, sh_int save_frequency; /* How old to autosave someone */ Below it add, bool ECOPYOVER; Find the section that has all of the comm.c declarations, just run a search for comm.c Once you've found it, below it add this, void emergancy_copyover args( ( void ) ); int file_size args( ( char * buf ) ); Find, #define CLAN_DIR "../clans/" /* Clan data dir */ Below it add, #define LOG_DIR "../log/" /* Log dir */ ------------------------------------------------------------------------------------------------- make clean make Before you copyover/reboot(hopefully copyover:-/), go to the ../system/ directory and edit the sysdata.dat file, At the very bottom, add this, Note: 0 = Off 1 = On ECopyover 0 Then you can reboot/copyover(but do a MUD save before you edit the sysdata.dat file or it won't be there when you save and copyover) You can now CSET ECOPYOVER on your MUD, Enjoy:) Any problems please contact me at the provided email address, -,,,.,,,,- _'Diablo'_ Star Wars Development '''''' [*]------------------------------------------------[*] ||| If you have any problems please contact me at: ||| ||| crazy_mike_316@hotmail.com ||| [*]------------------------------------------------[*]