Skip to content

Commit

Permalink
Added server crash dump uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
ccw808 committed Oct 30, 2015
1 parent c229e30 commit 19815b3
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 46 deletions.
26 changes: 16 additions & 10 deletions MTA10_Server/core/CCrashHandler.cpp
Expand Up @@ -24,9 +24,9 @@
extern "C" bool g_bNoCurses;
#include <client/linux/handler/exception_handler.h>
bool DumpCallback( const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded );
static SString ms_strDumpPath;
static SString ms_strDumpPathFilename;
#endif
static SString ms_strDumpPath;

#ifdef WIN32
#include <ctime>
Expand All @@ -43,15 +43,16 @@ typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hF

void CCrashHandler::Init ( const SString& strInServerPath )
{
SString strServerPath = strInServerPath;
if ( strServerPath == "" )
strServerPath = GetSystemCurrentDirectory();
ms_strDumpPath = PathJoin( strServerPath, SERVER_DUMP_PATH );

// Set a global filter
#ifdef WIN32
SetCrashHandlerFilter ( HandleExceptionGlobal );
#else
// Prepare initial dumpfile name
SString strServerPath = strInServerPath;
if ( strServerPath == "" )
strServerPath = GetSystemCurrentDirectory();
ms_strDumpPath = PathJoin( strServerPath, SERVER_DUMP_PATH );
time_t pTime = time( NULL );
struct tm* tm = localtime( &pTime );
SString strFilename( "server_%s_%04d%02d%02d_%02d%02d.dmp",
Expand Down Expand Up @@ -151,6 +152,7 @@ bool DumpCallback( const google_breakpad::MinidumpDescriptor& descriptor, void*
rename( ms_strDumpPathFilename, strFinalDumpPathFilename );

SaveBacktraceSummary();
FileSave( PathJoin( ms_strDumpPath, "server_pending_upload_filename" ), strFinalDumpPathFilename );

// Return false to indicate exception has not been handled (and allow core dump?)
return false;
Expand Down Expand Up @@ -212,15 +214,15 @@ void CCrashHandler::DumpMiniDump ( _EXCEPTION_POINTERS* pException, CExceptionIn
GetLocalTime ( &SystemTime );

// Create the dump directory
CreateDirectory ( SERVER_DUMP_PATH, 0 );
CreateDirectory ( SERVER_DUMP_PATH "/private", 0 );
CreateDirectory ( ms_strDumpPath, 0 );
CreateDirectory ( PathJoin( ms_strDumpPath, "private" ), 0 );

SString strModuleName = pExceptionInformation->GetModuleBaseName ();
strModuleName = strModuleName.ReplaceI ( ".dll", "" ).Replace ( ".exe", "" ).Replace ( "_", "" ).Replace ( ".", "" ).Replace ( "-", "" );
if ( strModuleName.length () == 0 )
strModuleName = "unknown";

SString strFilename ( SERVER_DUMP_PATH "/private/server_%s_%s_%08x_%x_%04d%02d%02d_%02d%02d.dmp",
SString strFilename ( "server_%s_%s_%08x_%x_%04d%02d%02d_%02d%02d.dmp",
MTA_DM_BUILDTAG_LONG,
strModuleName.c_str (),
pExceptionInformation->GetAddressModuleOffset (),
Expand All @@ -232,8 +234,10 @@ void CCrashHandler::DumpMiniDump ( _EXCEPTION_POINTERS* pException, CExceptionIn
SystemTime.wMinute
);

SString strFinalDumpPathFilename = PathJoin( ms_strDumpPath, "private", strFilename );

// Create the file
HANDLE hFile = CreateFile ( strFilename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
HANDLE hFile = CreateFile ( strFinalDumpPathFilename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
if ( hFile != INVALID_HANDLE_VALUE )
{
// Create an exception information struct
Expand All @@ -247,10 +251,12 @@ void CCrashHandler::DumpMiniDump ( _EXCEPTION_POINTERS* pException, CExceptionIn

// Close the dumpfile
CloseHandle ( hFile );

FileSave( PathJoin( ms_strDumpPath, "server_pending_upload_filename" ), strFinalDumpPathFilename );
}

// Write a log with the generic exception information
FILE* pFile = fopen ( SERVER_DUMP_PATH "/server_pending_upload.log", "a+" );
FILE* pFile = fopen ( PathJoin( ms_strDumpPath, "server_pending_upload.log" ), "a+" );
if ( pFile )
{
// Header
Expand Down
29 changes: 19 additions & 10 deletions MTA10_Server/mods/deathmatch/editor.conf
Expand Up @@ -5,11 +5,12 @@
<servername>Map Editor Server</servername>

<!-- ONLY USE THIS PARAMETER IF YOU ARE SURE OF WHAT YOU ARE DOING - it is generally only
needed for professional servers and should be left blank otherwise.
This parameter specifies the IP to use for servers that have multiple IP addresses. If left
blank, it will default to server's standard local IP address. -->
<!-- SERVERIP SHOULD BE LEFT BLANK UNLESS YOU ARE SURE OF WHAT YOU ARE DOING -->
<serverip></serverip>
needed for professional servers and should be left at the default value otherwise.
This parameter specifies the IP to use for servers that have multiple IP addresses. If set
to auto, it will automatically detect and use the server's standard local IP address.
Values: auto or x.x.x.x ; default value: auto -->
<!-- SERVERIP SHOULD BE LEFT SET TO auto UNLESS YOU ARE SURE OF WHAT YOU ARE DOING -->
<serverip>auto</serverip>
<!-- WARNING: SETTING serverip AND THEN ASKING FOR SUPPORT CAN CAUSE DEATH OR INJURY -->

<!-- This parameter specifies the UDP port on which the server will be accepting incoming player
Expand All @@ -20,11 +21,6 @@
value: 32. It is a required parameter. -->
<maxplayers>1</maxplayers>

<!-- This parameter specifies whether the builtin http server is enabled.
The builtin http server is used for webadmin and (if httpdownloadurl is empty) resource downloads.
Values: 0 - disabled , 1 - enabled ; default value: 1. Optional parameter. -->
<httpserver>1</httpserver>

<!-- This parameter specifies the TCP port on which the server will be accepting incoming http
connections. It can be set to the same value as <serverport>. It is a required parameter
if <httpserver> is set to 1. -->
Expand All @@ -50,6 +46,15 @@
Available range: 1 to 100. default value: 20 -->
<httpdosthreshold>20</httpdosthreshold>

<!-- This parameter lists the IP addresses that are to be excluded from http dos threshold limits.
e.g. 88.11.22.33,101.2.3.4 -->
<http_dos_exclude></http_dos_exclude>

<!-- By default, the server will block the use of locally customized gta3.img player skins.
This setting can be used to allow such mods. Not recommended for competitive servers.
Values: none or peds ; default value: none -->
<allow_gta3_img_mods>none</allow_gta3_img_mods>

<!-- By default, the server will block the use of customized GTA:SA data files. -->
<!-- To allow specific client files, add one or more of the following: -->
<!-- <client_file name="data/carmods.dat" verify="0"/> -->
Expand Down Expand Up @@ -223,6 +228,10 @@
Values: 0 - Never, 1 - On server start only after basic backup, 2 - On server start always. Default - 1 -->
<compact_internal_databases>0</compact_internal_databases>

<!-- This parameter specifies whether server crash dump files should be sent to MTA HQ.
Values: 0 - Off, 1 - On. Default - 1 -->
<crash_dump_upload>0</crash_dump_upload>

<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
parameter(s). Optional parameter. -->
<!-- <module src="sample_win32.dll"/> -->
Expand Down
44 changes: 26 additions & 18 deletions MTA10_Server/mods/deathmatch/local.conf
Expand Up @@ -5,11 +5,12 @@
<servername>Default MTA Server</servername>

<!-- ONLY USE THIS PARAMETER IF YOU ARE SURE OF WHAT YOU ARE DOING - it is generally only
needed for professional servers and should be left blank otherwise.
This parameter specifies the IP to use for servers that have multiple IP addresses. If left
blank, it will default to server's standard local IP address. -->
<!-- SERVERIP SHOULD BE LEFT BLANK UNLESS YOU ARE SURE OF WHAT YOU ARE DOING -->
<serverip></serverip>
needed for professional servers and should be left at the default value otherwise.
This parameter specifies the IP to use for servers that have multiple IP addresses. If set
to auto, it will automatically detect and use the server's standard local IP address.
Values: auto or x.x.x.x ; default value: auto -->
<!-- SERVERIP SHOULD BE LEFT SET TO auto UNLESS YOU ARE SURE OF WHAT YOU ARE DOING -->
<serverip>auto</serverip>
<!-- WARNING: SETTING serverip AND THEN ASKING FOR SUPPORT CAN CAUSE DEATH OR INJURY -->

<!-- This parameter specifies the UDP port on which the server will be accepting incoming player
Expand All @@ -20,11 +21,6 @@
value: 32. It is a required parameter. -->
<maxplayers>32</maxplayers>

<!-- This parameter specifies whether the builtin http server is enabled.
The builtin http server is used for webadmin and (if httpdownloadurl is empty) resource downloads.
Values: 0 - disabled , 1 - enabled ; default value: 1. Optional parameter. -->
<httpserver>1</httpserver>

<!-- This parameter specifies the TCP port on which the server will be accepting incoming http
connections. It can be set to the same value as <serverport>. It is a required parameter
if <httpserver> is set to 1. -->
Expand All @@ -35,12 +31,6 @@
are switched to the internal http server. -->
<httpdownloadurl></httpdownloadurl>

<!-- This parameter specifies whether the client files for hosting on an external web server should be
automatically copied into mods/deathmatch/resource-cache/http-client-files/
Only relevant if <httpdownloadurl> is set.
Values: 0 - disabled , 1 - enabled ; default value: 1. Optional parameter. -->
<httpautoclientfiles>1</httpautoclientfiles>

<!-- This parameter limits the number of http connections each client can make. Depending on the type
of http server that is used, a lower figure may reduce download timeouts.
Available range: 1 to 8. -->
Expand All @@ -50,6 +40,15 @@
Available range: 1 to 100. default value: 20 -->
<httpdosthreshold>20</httpdosthreshold>

<!-- This parameter lists the IP addresses that are to be excluded from http dos threshold limits.
e.g. 88.11.22.33,101.2.3.4 -->
<http_dos_exclude></http_dos_exclude>

<!-- By default, the server will block the use of locally customized gta3.img player skins.
This setting can be used to allow such mods. Not recommended for competitive servers.
Values: none or peds ; default value: none -->
<allow_gta3_img_mods>none</allow_gta3_img_mods>

<!-- By default, the server will block the use of customized GTA:SA data files. -->
<!-- To allow specific client files, add one or more of the following: -->
<!-- <client_file name="data/carmods.dat" verify="0"/> -->
Expand Down Expand Up @@ -123,8 +122,8 @@
<keysync_analog_sync_interval>100</keysync_analog_sync_interval>

<!-- This parameter can improve the reliability of shots when using certain weapons. However, it uses more bandwidth.
Values: 0 - disabled , 1 - enabled ; default value: 0. -->
<bullet_sync>0</bullet_sync>
Values: 0 - disabled , 1 - enabled ; default value: 1. -->
<bullet_sync>1</bullet_sync>

<!-- This parameter sets the amount of extrapolation that clients will apply to remote vehicles. This can reduce
some of the latency induced location disparency by predicting where the remote vehicles will probably be.
Expand Down Expand Up @@ -223,6 +222,10 @@
Values: 0 - Never, 1 - On server start only after basic backup, 2 - On server start always. Default - 1 -->
<compact_internal_databases>1</compact_internal_databases>

<!-- This parameter specifies whether server crash dump files should be sent to MTA HQ.
Values: 0 - Off, 1 - On. Default - 1 -->
<crash_dump_upload>0</crash_dump_upload>

<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
parameter(s). Optional parameter. -->
<!-- <module src="sample_win32.dll"/> -->
Expand All @@ -238,10 +241,15 @@
<resource src="mapcycler" startup="1" protected="0"/>
<resource src="mapmanager" startup="1" protected="0"/>
<resource src="parachute" startup="1" protected="0"/>
<resource src="performancebrowser" startup="1" protected="0"/>
<resource src="reload" startup="1" protected="0"/>
<resource src="resourcebrowser" startup="1" protected="1" default="true"/>
<resource src="resourcemanager" startup="1" protected="1"/>
<resource src="scoreboard" startup="1" protected="0"/>
<resource src="spawnmanager" startup="1" protected="0"/>
<resource src="voice" startup="1" protected="0" />
<resource src="votemanager" startup="1" protected="0"/>
<resource src="webadmin" startup="1" protected="0"/>

<!-- play is the default freeroam gamemode. Remove the following line to prevent it from starting. -->
<resource src="play" startup="1" protected="0"/>
Expand Down
1 change: 1 addition & 0 deletions MTA10_Server/mods/deathmatch/logic/CMainConfig.cpp
Expand Up @@ -1451,6 +1451,7 @@ const std::vector < SIntSetting >& CMainConfig::GetIntSettingList ( void )
{ true, true, 0, 1, 2, "minclientversion_auto_update", &m_iMinClientVersionAutoUpdate, NULL },
{ true, true, 0, 0, 100, "server_logic_fps_limit", &m_iServerLogicFpsLimit, NULL },
{ true, true, 0, 1, 1, "bad_net_bullet_fix", &m_bBadNetBulletFixEnabled, NULL },
{ true, true, 0, 1, 1, "crash_dump_upload", &m_bCrashDumpUploadEnabled, NULL },
};

static std::vector < SIntSetting > settingsList;
Expand Down
2 changes: 2 additions & 0 deletions MTA10_Server/mods/deathmatch/logic/CMainConfig.h
Expand Up @@ -125,6 +125,7 @@ class CMainConfig: public CXMLConfig
const SString& GetLoadstringLogFilename ( void ) const { return m_strLoadstringLogFilename; }
bool GetLoadstringLogEnabled ( void ) const { return !m_strLoadstringLogFilename.empty(); }
bool GetBadNetBulletFixEnabled ( void ) const { return m_bBadNetBulletFixEnabled != 0; }
bool GetCrashDumpUploadEnabled ( void ) const { return m_bCrashDumpUploadEnabled != 0; }

SString GetSetting ( const SString& configSetting );
bool GetSetting ( const SString& configSetting, SString& strValue );
Expand Down Expand Up @@ -215,6 +216,7 @@ class CMainConfig: public CXMLConfig
int m_iMinClientVersionAutoUpdate;
int m_iServerLogicFpsLimit;
int m_bBadNetBulletFixEnabled;
int m_bCrashDumpUploadEnabled;
};

#endif
4 changes: 4 additions & 0 deletions MTA10_Server/mods/deathmatch/mtaserver.conf
Expand Up @@ -222,6 +222,10 @@
Values: 0 - Never, 1 - On server start only after basic backup, 2 - On server start always. Default - 1 -->
<compact_internal_databases>1</compact_internal_databases>

<!-- This parameter specifies whether server crash dump files should be sent to MTA HQ.
Values: 0 - Off, 1 - On. Default - 1 -->
<crash_dump_upload>1</crash_dump_upload>

<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
parameter(s). Optional parameter. -->
<!-- <module src="sample_win32.dll"/> -->
Expand Down
37 changes: 29 additions & 8 deletions MTA10_Server/mods/deathmatch/utils/CHqComms.h
Expand Up @@ -29,7 +29,8 @@ class CHqComms : public CRefCountable
{
m_iPollInterval = TICKS_FROM_MINUTES( 60 );
m_strURL = HQCOMMS_URL;
m_strCrashInfoFilename = g_pServerInterface->GetAbsolutePath( PathJoin( SERVER_DUMP_PATH, "server_pending_upload.log" ) );
m_strCrashLogFilename = g_pServerInterface->GetAbsolutePath( PathJoin( SERVER_DUMP_PATH, "server_pending_upload.log" ) );
m_strCrashDumpMeta = g_pServerInterface->GetAbsolutePath( PathJoin( SERVER_DUMP_PATH, "server_pending_upload_filename" ) );
}

//
Expand All @@ -44,7 +45,7 @@ class CHqComms : public CRefCountable
m_Stage = HQCOMMS_STAGE_QUERY;

CBitStream bitStream;
bitStream->Write( (char)1 );
bitStream->Write( (char)2 ); // Data version
bitStream->WriteStr( g_pGame->GetConfig()->GetServerIP() );
bitStream->Write( g_pGame->GetConfig()->GetServerPort() );
bitStream->WriteStr( CStaticFunctionDefinitions::GetVersionSortable() );
Expand All @@ -56,13 +57,32 @@ class CHqComms : public CRefCountable
bitStream->Write( g_pGame->GetConfig()->GetAseInternetPushEnabled() ? 1 : 0 );
bitStream->Write( g_pGame->GetConfig()->GetAseInternetListenEnabled() ? 1 : 0 );

SString strCrashInfo;
FileLoad( m_strCrashInfoFilename, strCrashInfo, 50000 );
bitStream->WriteStr( strCrashInfo );
SString strCrashLog;
FileLoad( m_strCrashLogFilename, strCrashLog, 50000 );
bitStream->WriteStr( strCrashLog );

// Latest crash dump
SString strCrashDumpFilename, strCrashDumpContent;
if ( FileExists( m_strCrashDumpMeta ) )
{
if ( g_pGame->GetConfig()->GetCrashDumpUploadEnabled() )
{
FileLoad( m_strCrashDumpMeta, strCrashDumpFilename );
FileLoad( strCrashDumpFilename, strCrashDumpContent );
}
// Only attempt to send crashdump once
FileDelete( m_strCrashDumpMeta );
m_strCrashDumpMeta = "";
}
bitStream->WriteStr( ExtractFilename( strCrashDumpFilename ) );
bitStream->WriteStr( strCrashDumpContent );

bitStream->WriteStr( MTA_OS_STRING );
bitStream->WriteStr( g_pGame->GetConfig()->GetServerIPList() );

// Send request
this->AddRef(); // Keep object alive
GetDownloadManager()->QueueFile( m_strURL, NULL, 0, (const char*)bitStream->GetData(), bitStream->GetNumberOfBytesUsed(), true, this, StaticProgressCallback, false, 1 );
GetDownloadManager()->QueueFile( m_strURL, NULL, 0, (const char*)bitStream->GetData(), bitStream->GetNumberOfBytesUsed(), true, this, StaticProgressCallback, false, 2 );
}
}

Expand Down Expand Up @@ -180,7 +200,7 @@ class CHqComms : public CRefCountable
bitStream->Read( iGotCrashInfo );
if ( iGotCrashInfo )
{
FileDelete( m_strCrashInfoFilename );
FileDelete( m_strCrashLogFilename );
}
}

Expand Down Expand Up @@ -223,5 +243,6 @@ class CHqComms : public CRefCountable
CElapsedTime m_CheckTimer;
SString m_strURL;
SString m_strPrevMessage;
SString m_strCrashInfoFilename;
SString m_strCrashLogFilename;
SString m_strCrashDumpMeta; // Filename of file which contains the latest crash dump filename
};

0 comments on commit 19815b3

Please sign in to comment.