// $Id: core.c,v 1.1.1.1 2004/09/10 17:44:49 MagicalTux Exp $ // original : core.c 2003/02/26 18:03:12 Rev 1.7 #include #include #ifndef _WIN32 #include #endif #include #include #ifdef DUMPSTACK #include #endif #include "../common/mmo.h" #include "core.h" #include "socket.h" #include "timer.h" #include "version.h" #include "showmsg.h" #ifdef MEMWATCH #include "memwatch.h" #endif static void (*term_func)(void)=NULL; /*====================================== * CORE : Set function *-------------------------------------- */ void set_termfunc(void (*termfunc)(void)) { term_func = termfunc; } // Added by Gabuzomeu // // This is an implementation of signal() using sigaction() for portability. // (sigaction() is POSIX; signal() is not.) Taken from Stevens' _Advanced // Programming in the UNIX Environment_. // #ifndef SIGPIPE #define SIGPIPE SIGINT #endif #ifndef POSIX #define compat_signal(signo, func) signal(signo, func) #else sigfunc *compat_signal(int signo, sigfunc *func) { struct sigaction sact, oact; sact.sa_handler = func; sigemptyset(&sact.sa_mask); sact.sa_flags = 0; #ifdef SA_INTERRUPT sact.sa_flags |= SA_INTERRUPT; /* SunOS */ #endif if (sigaction(signo, &sact, &oact) < 0) return (SIG_ERR); return (oact.sa_handler); } #endif /*====================================== * CORE : Signal Sub Function *-------------------------------------- */ static void sig_proc(int sn) { int i; switch(sn){ case SIGINT: case SIGTERM: if(term_func) term_func(); for(i=0;i0) { snprintf(tmp_output,sizeof(tmp_output),"SVN Revision: '"CL_WHITE"%d"CL_RESET"'.\n",revision); ShowInfo(tmp_output); } } /*====================================== * CORE : MAINROUTINE *-------------------------------------- */ int runflag = 1; int main(int argc,char **argv) { int next; Net_Init(); do_socket(); compat_signal(SIGPIPE,SIG_IGN); compat_signal(SIGTERM,sig_proc); compat_signal(SIGINT,sig_proc); #ifndef DUMPSTACK // Signal to create coredumps by system when necessary (crash) compat_signal(SIGSEGV, SIG_DFL); compat_signal(SIGFPE, SIG_DFL); compat_signal(SIGILL, SIG_DFL); #ifndef _WIN32 compat_signal(SIGBUS, SIG_DFL); compat_signal(SIGTRAP, SIG_DFL); #endif #else compat_signal(SIGSEGV, sig_dump); compat_signal(SIGFPE, sig_dump); compat_signal(SIGILL, sig_dump); #ifndef _WIN32 compat_signal(SIGBUS, sig_dump); compat_signal(SIGTRAP, SIG_DFL); #endif #endif display_title(); tick_ = time(0); do_init(argc,argv); while(runflag){ next=do_timer(gettick_nocache()); do_sendrecv(next); do_parsepacket(); } return 0; }