From 9374324b4198605a9ee57f31de010ae18af49256 Mon Sep 17 00:00:00 2001 From: xazax-hun Date: Sun, 18 Mar 2012 00:06:38 +0000 Subject: * Properly handling, when closing the consoles via X button on windows. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15706 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/core.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/common/core.c') diff --git a/src/common/core.c b/src/common/core.c index 89a002ebe..243fac24c 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -18,6 +18,8 @@ #include #ifndef _WIN32 #include +#else +#include // Console close event handling #endif @@ -68,6 +70,35 @@ sigfunc *compat_signal(int signo, sigfunc *func) } #endif +/*====================================== + * CORE : Console events for Windows + *--------------------------------------*/ +#ifdef _WIN32 +static BOOL WINAPI console_handler(DWORD c_event) +{ + switch(c_event) + { + case CTRL_CLOSE_EVENT: + case CTRL_LOGOFF_EVENT: + case CTRL_SHUTDOWN_EVENT: + if( shutdown_callback != NULL ) + shutdown_callback(); + else + runflag = CORE_ST_STOP;// auto-shutdown + break; + default: + break; + } + return TRUE; +} + +static void cevents_init() +{ + if (SetConsoleCtrlHandler(console_handler,TRUE)==FALSE) + ShowWarning ("Unable to install the console handler!\n"); +} +#endif + /*====================================== * CORE : Signal Sub Function *--------------------------------------*/ @@ -251,6 +282,10 @@ int main (int argc, char **argv) db_init(); signals_init(); +#ifdef _WIN32 + cevents_init(); +#endif + timer_init(); socket_init(); plugins_init(); -- cgit v1.2.3-60-g2f50