From d0da5d392f64c63fefde352a2a0b569317ca59cc Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 24 Jan 2014 23:03:48 +0100 Subject: Added per-connection comm logging in debug mode. It is meant for debugging only, so it is compiled only into debug mode. It is activated by starting the server with "/logcomm" parameter. --- src/main.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 340149e0b..68bf6683f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,15 @@ bool g_SERVER_TERMINATED = false; // Set to true when the server terminates, so +#ifdef _DEBUG +/** If set to true, the protocols will log each player's communication to a separate logfile */ +bool g_ShouldLogComm; +#endif + + + + + /// If defined, a thorough leak finder will be used (debug MSVC only); leaks will be output to the Output window #define ENABLE_LEAK_FINDER @@ -216,12 +225,26 @@ int main( int argc, char **argv ) #ifndef _DEBUG std::signal(SIGSEGV, NonCtrlHandler); std::signal(SIGTERM, NonCtrlHandler); - std::signal(SIGINT, NonCtrlHandler); + std::signal(SIGINT, NonCtrlHandler); #endif // DEBUG: test the dumpfile creation: // *((int *)0) = 0; + // Check if comm logging is to be enabled: + #ifdef _DEBUG + for (int i = 0; i < argc; i++) + { + if ( + (_stricmp(argv[i], "/commlog") == 0) || + (_stricmp(argv[i], "/logcomm") == 0) + ) + { + g_ShouldLogComm = true; + } + } + #endif // _DEBUG + #if !defined(ANDROID_NDK) try #endif -- cgit v1.2.3 From ebcaaad63aaf854e01f63104a820dfcbd76cc80e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 24 Jan 2014 23:05:26 +0100 Subject: Fixed *nix compilation for previous commit. --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 68bf6683f..902e9e43b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -236,8 +236,8 @@ int main( int argc, char **argv ) for (int i = 0; i < argc; i++) { if ( - (_stricmp(argv[i], "/commlog") == 0) || - (_stricmp(argv[i], "/logcomm") == 0) + (NoCaseCompare(argv[i], "/commlog") == 0) || + (NoCaseCompare(argv[i], "/logcomm") == 0) ) { g_ShouldLogComm = true; -- cgit v1.2.3 From ff066453b805748d6e665b3ad219a62c777e4453 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 25 Jan 2014 15:28:16 +0100 Subject: Comm logging is available in both Debug and Release modes. --- src/main.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 902e9e43b..06b344c25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,10 +19,8 @@ bool g_SERVER_TERMINATED = false; // Set to true when the server terminates, so -#ifdef _DEBUG /** If set to true, the protocols will log each player's communication to a separate logfile */ bool g_ShouldLogComm; -#endif @@ -232,7 +230,6 @@ int main( int argc, char **argv ) // *((int *)0) = 0; // Check if comm logging is to be enabled: - #ifdef _DEBUG for (int i = 0; i < argc; i++) { if ( @@ -243,7 +240,6 @@ int main( int argc, char **argv ) g_ShouldLogComm = true; } } - #endif // _DEBUG #if !defined(ANDROID_NDK) try -- cgit v1.2.3 From ea9de4bbb70192626b00a810482671cf14bd7f8c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 26 Jan 2014 16:15:05 +0000 Subject: Added SIGABRT to catchers list --- src/main.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 06b344c25..0f6895d03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,9 +68,10 @@ void NonCtrlHandler(int a_Signal) LOGERROR("Details | SIGABRT: Server self-terminated due to an internal fault"); break; } + case SIGINT: case SIGTERM: { - std::signal(SIGTERM, SIG_IGN); // Server is shutting down, wait for it... + std::signal(a_Signal, SIG_IGN); // Server is shutting down, wait for it... break; } default: break; @@ -224,6 +225,10 @@ int main( int argc, char **argv ) std::signal(SIGSEGV, NonCtrlHandler); std::signal(SIGTERM, NonCtrlHandler); std::signal(SIGINT, NonCtrlHandler); + std::signal(SIGABRT, NonCtrlHandler); + #ifdef SIGABRT_COMPAT + std::signal(SIGABRT_COMPAT, NonCtrlHandler); + #endif // SIGABRT_COMPAT #endif // DEBUG: test the dumpfile creation: -- cgit v1.2.3 From 30c431b479673b2c94b9d642fc7de73679cf3e6f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 26 Jan 2014 17:54:18 +0100 Subject: Fixed client packet parsing. When the packet wouldn't fit the current buffer, the server would mis-parse the next packet. This was the cause for #541. Also modified comm logging, now each direction can be turned on separately. --- src/main.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 0f6895d03..9acc7db3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,8 +19,11 @@ bool g_SERVER_TERMINATED = false; // Set to true when the server terminates, so -/** If set to true, the protocols will log each player's communication to a separate logfile */ -bool g_ShouldLogComm; +/** If set to true, the protocols will log each player's incoming (C->S) communication to a per-connection logfile */ +bool g_ShouldLogCommIn; + +/** If set to true, the protocols will log each player's outgoing (S->C) communication to a per-connection logfile */ +bool g_ShouldLogCommOut; @@ -242,7 +245,24 @@ int main( int argc, char **argv ) (NoCaseCompare(argv[i], "/logcomm") == 0) ) { - g_ShouldLogComm = true; + g_ShouldLogCommIn = true; + g_ShouldLogCommOut = true; + } + if ( + (NoCaseCompare(argv[i], "/commlogin") == 0) || + (NoCaseCompare(argv[i], "/comminlog") == 0) || + (NoCaseCompare(argv[i], "/logcommin") == 0) + ) + { + g_ShouldLogCommIn = true; + } + if ( + (NoCaseCompare(argv[i], "/commlogout") == 0) || + (NoCaseCompare(argv[i], "/commoutlog") == 0) || + (NoCaseCompare(argv[i], "/logcommout") == 0) + ) + { + g_ShouldLogCommOut = true; } } -- cgit v1.2.3 From fc9e5278304adf811becf90e62311c1318e9658d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 27 Jan 2014 18:57:14 +0000 Subject: SIGABRT exits with failure. --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 9acc7db3a..c8cd2d4fe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,6 +69,7 @@ void NonCtrlHandler(int a_Signal) std::signal(a_Signal, SIG_DFL); LOGERROR(" D: | MCServer has encountered an error and needs to close"); LOGERROR("Details | SIGABRT: Server self-terminated due to an internal fault"); + exit(EXIT_FAILURE); break; } case SIGINT: -- cgit v1.2.3 From 50bebd2dbdb26a48ce1637bf515770d1bfc50d99 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 20 Feb 2014 20:11:17 +0100 Subject: Disabled the leak finder. --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index c8cd2d4fe..4d2801926 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,7 +30,9 @@ bool g_ShouldLogCommOut; /// If defined, a thorough leak finder will be used (debug MSVC only); leaks will be output to the Output window -#define ENABLE_LEAK_FINDER +// _X 2014_02_20: Disabled for canon repo, it makes the debug version too slow in MSVC2013 +// and we haven't had a memory leak for over a year anyway. +// #define ENABLE_LEAK_FINDER -- cgit v1.2.3 From a23b5d13bde0742e6208bcc75807a97c1c12f7e1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 27 Feb 2014 15:17:42 +0100 Subject: Added a "nooutbuf" cmdline param. This forces that the stdout stream uses no buffer, even when not a TTY. Used for running MCServer under ZeroBraneStudio. --- src/main.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 4d2801926..2ae8a413b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -243,31 +243,36 @@ int main( int argc, char **argv ) // Check if comm logging is to be enabled: for (int i = 0; i < argc; i++) { + AString Arg(argv[i]); if ( - (NoCaseCompare(argv[i], "/commlog") == 0) || - (NoCaseCompare(argv[i], "/logcomm") == 0) + (NoCaseCompare(Arg, "/commlog") == 0) || + (NoCaseCompare(Arg, "/logcomm") == 0) ) { g_ShouldLogCommIn = true; g_ShouldLogCommOut = true; } - if ( - (NoCaseCompare(argv[i], "/commlogin") == 0) || - (NoCaseCompare(argv[i], "/comminlog") == 0) || - (NoCaseCompare(argv[i], "/logcommin") == 0) + else if ( + (NoCaseCompare(Arg, "/commlogin") == 0) || + (NoCaseCompare(Arg, "/comminlog") == 0) || + (NoCaseCompare(Arg, "/logcommin") == 0) ) { g_ShouldLogCommIn = true; } - if ( - (NoCaseCompare(argv[i], "/commlogout") == 0) || - (NoCaseCompare(argv[i], "/commoutlog") == 0) || - (NoCaseCompare(argv[i], "/logcommout") == 0) + else if ( + (NoCaseCompare(Arg, "/commlogout") == 0) || + (NoCaseCompare(Arg, "/commoutlog") == 0) || + (NoCaseCompare(Arg, "/logcommout") == 0) ) { g_ShouldLogCommOut = true; } - } + else if (NoCaseCompare(Arg, "nooutbuf") == 0) + { + setvbuf(stdout, NULL, _IONBF, 0); + } + } // for i - argv[] #if !defined(ANDROID_NDK) try -- cgit v1.2.3 From b829c9b14e95f37a3a5ba70fc42cb8cfe9066522 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 07:12:00 -0700 Subject: Fixed a few unneeded breaks --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 2ae8a413b..68eea7f4d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,7 +72,6 @@ void NonCtrlHandler(int a_Signal) LOGERROR(" D: | MCServer has encountered an error and needs to close"); LOGERROR("Details | SIGABRT: Server self-terminated due to an internal fault"); exit(EXIT_FAILURE); - break; } case SIGINT: case SIGTERM: -- cgit v1.2.3