/************************************************************************
* iDIRT Exit Handler 1.02.00 *
* 1995 by Illusion *
************************************************************************/
/************************************************************************
* The following functions handle all exit() calls from the MUD and *
* handle them itself making sure that the MUD shuts down nicely and *
* with as little problems as possible. *
* - Adjusted the code here and there to allow it to work with Dyrtcode *
* based muds like this mudcode - Marty *
************************************************************************/
#define EXIT_C
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include "kernel.h"
#include "mobile.h"
#include "sendsys.h"
#include "timing.h"
#include "time.h"
#include "exit.h"
#include "mudmacros.h"
#include "pflags.h"
#include "log.h"
#include "uaf.h"
#include "parse.h"
#include "main.h"
#include "bprintf.h"
#include "mud.h"
#include "commands.h"
#include "rooms.h"
#ifdef INTERMUD
#include "InterMud/intermud.h"
#endif
#define COREDUMP
/* __exit(): Handles the shutdown of the MUD. */
void __exit (int status)
{ mudlog ("SYSTEM: __exit(%d) called", status);
send_msg (DEST_ALL, MODE_BRACKET, LVL_MIN, LVL_MAX, NOBODY, NOBODY,
"&+wInternal error has occured");
autosave ();
debug ();
numcrashes++;
#ifdef INTERMUD
imShutdown(1);
#endif
sysreboot(True,True);
_exit (1);
}
/* sig_exit(): Handles the shutdown of the MUD due to signal error. */
void sig_exit (char *sig, int signal)
{
if (signal == SIGUSR1)
{ send_msg (DEST_ALL, 0, LVL_MIN, LVL_MAX, NOBODY, NOBODY,
"\001f" SIGNAL1 "\003");
} else if (signal == SIGUSR2)
{ send_msg (DEST_ALL, 0, LVL_MIN, LVL_MAX, NOBODY, NOBODY,
"\001f" SIGNAL2 "\003");
} else
{ send_msg (DEST_ALL, MODE_BRACKET, LVL_WIZARD, LVL_MAX, NOBODY, NOBODY,
"&+wSignal Error: &+w%s", sig);
send_msg (DEST_ALL, MODE_BRACKET, LVL_GUEST, (LVL_WIZARD - 1), NOBODY, NOBODY,
"&+wInternal error has occured");
}
autosave ();
debug ();
#ifdef INTERMUD
imShutdown(1);
#endif
#ifdef COREDUMP
if (fork())
{ kill(getpid(), SIGTRAP);
}
else
{ numcrashes++;
sysreboot(True,True);
}
#else
numcrashes++;
sysreboot(True,True);
#endif
_exit (2);
}
/* autosave(): Saves all players. */
void autosave (void)
{ int plx;
PERSONA d;
for (plx = 0; plx < max_players; ++plx)
{ if (is_in_game (plx))
{ if (players[plx].aliased || players[plx].polymorphed >= 0)
{ unalias (plx);
unpolymorph (plx);
setup_globals (plx);
sendf (plx, "&+w[&+wUnaliasing You&+w]&*\n");
}
sendf (plx, "&+w[&+wSaving Character&+w]&*\n");
player2pers (&d, &global_clock, plx);
bflush ();
putuaf (&d);
}
}
}
/* debug(): Write last commands entered to system logs */
void debug (void)
{ int plx;
int i;
char *t;
char nt[100];
for (plx = 0; plx < max_players; ++plx)
if (is_in_game (plx))
{ t = ctime (&plast_cmd (plx));
t[19] = '\0';
for (i = 0; i < 8; ++i)
nt[i] = t[i + 11];
nt[8] = '\0';
mudlog ("DEBUG: Last Command (%s) %s@%s: %s",
nt, pname (plx), showname(ploc(plx)), players[plx].prev_com);
}
}