Skip to content

Commit fde4755

Browse files
committed
Added server crash dump uploads
1 parent 20164ce commit fde4755

File tree

7 files changed

+97
-46
lines changed

7 files changed

+97
-46
lines changed

MTA10_Server/core/CCrashHandler.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
extern "C" bool g_bNoCurses;
2525
#include <client/linux/handler/exception_handler.h>
2626
bool DumpCallback( const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded );
27-
static SString ms_strDumpPath;
2827
static SString ms_strDumpPathFilename;
2928
#endif
29+
static SString ms_strDumpPath;
3030

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

4444
void CCrashHandler::Init ( const SString& strInServerPath )
4545
{
46+
SString strServerPath = strInServerPath;
47+
if ( strServerPath == "" )
48+
strServerPath = GetSystemCurrentDirectory();
49+
ms_strDumpPath = PathJoin( strServerPath, SERVER_DUMP_PATH );
50+
4651
// Set a global filter
4752
#ifdef WIN32
4853
SetCrashHandlerFilter ( HandleExceptionGlobal );
4954
#else
5055
// Prepare initial dumpfile name
51-
SString strServerPath = strInServerPath;
52-
if ( strServerPath == "" )
53-
strServerPath = GetSystemCurrentDirectory();
54-
ms_strDumpPath = PathJoin( strServerPath, SERVER_DUMP_PATH );
5556
time_t pTime = time( NULL );
5657
struct tm* tm = localtime( &pTime );
5758
SString strFilename( "server_%s_%04d%02d%02d_%02d%02d.dmp",
@@ -151,6 +152,7 @@ bool DumpCallback( const google_breakpad::MinidumpDescriptor& descriptor, void*
151152
rename( ms_strDumpPathFilename, strFinalDumpPathFilename );
152153

153154
SaveBacktraceSummary();
155+
FileSave( PathJoin( ms_strDumpPath, "server_pending_upload_filename" ), strFinalDumpPathFilename );
154156

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

214216
// Create the dump directory
215-
CreateDirectory ( SERVER_DUMP_PATH, 0 );
216-
CreateDirectory ( SERVER_DUMP_PATH "/private", 0 );
217+
CreateDirectory ( ms_strDumpPath, 0 );
218+
CreateDirectory ( PathJoin( ms_strDumpPath, "private" ), 0 );
217219

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

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

237+
SString strFinalDumpPathFilename = PathJoin( ms_strDumpPath, "private", strFilename );
238+
235239
// Create the file
236-
HANDLE hFile = CreateFile ( strFilename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
240+
HANDLE hFile = CreateFile ( strFinalDumpPathFilename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
237241
if ( hFile != INVALID_HANDLE_VALUE )
238242
{
239243
// Create an exception information struct
@@ -247,10 +251,12 @@ void CCrashHandler::DumpMiniDump ( _EXCEPTION_POINTERS* pException, CExceptionIn
247251

248252
// Close the dumpfile
249253
CloseHandle ( hFile );
254+
255+
FileSave( PathJoin( ms_strDumpPath, "server_pending_upload_filename" ), strFinalDumpPathFilename );
250256
}
251257

252258
// Write a log with the generic exception information
253-
FILE* pFile = fopen ( SERVER_DUMP_PATH "/server_pending_upload.log", "a+" );
259+
FILE* pFile = fopen ( PathJoin( ms_strDumpPath, "server_pending_upload.log" ), "a+" );
254260
if ( pFile )
255261
{
256262
// Header

MTA10_Server/mods/deathmatch/editor.conf

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
<servername>Map Editor Server</servername>
66

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

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

23-
<!-- This parameter specifies whether the builtin http server is enabled.
24-
The builtin http server is used for webadmin and (if httpdownloadurl is empty) resource downloads.
25-
Values: 0 - disabled , 1 - enabled ; default value: 1. Optional parameter. -->
26-
<httpserver>1</httpserver>
27-
2824
<!-- This parameter specifies the TCP port on which the server will be accepting incoming http
2925
connections. It can be set to the same value as <serverport>. It is a required parameter
3026
if <httpserver> is set to 1. -->
@@ -50,6 +46,15 @@
5046
Available range: 1 to 100. default value: 20 -->
5147
<httpdosthreshold>20</httpdosthreshold>
5248

49+
<!-- This parameter lists the IP addresses that are to be excluded from http dos threshold limits.
50+
e.g. 88.11.22.33,101.2.3.4 -->
51+
<http_dos_exclude></http_dos_exclude>
52+
53+
<!-- By default, the server will block the use of locally customized gta3.img player skins.
54+
This setting can be used to allow such mods. Not recommended for competitive servers.
55+
Values: none or peds ; default value: none -->
56+
<allow_gta3_img_mods>none</allow_gta3_img_mods>
57+
5358
<!-- By default, the server will block the use of customized GTA:SA data files. -->
5459
<!-- To allow specific client files, add one or more of the following: -->
5560
<!-- <client_file name="data/carmods.dat" verify="0"/> -->
@@ -223,6 +228,10 @@
223228
Values: 0 - Never, 1 - On server start only after basic backup, 2 - On server start always. Default - 1 -->
224229
<compact_internal_databases>0</compact_internal_databases>
225230

231+
<!-- This parameter specifies whether server crash dump files should be sent to MTA HQ.
232+
Values: 0 - Off, 1 - On. Default - 1 -->
233+
<crash_dump_upload>0</crash_dump_upload>
234+
226235
<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
227236
parameter(s). Optional parameter. -->
228237
<!-- <module src="sample_win32.dll"/> -->

MTA10_Server/mods/deathmatch/local.conf

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
<servername>Default MTA Server</servername>
66

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

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

23-
<!-- This parameter specifies whether the builtin http server is enabled.
24-
The builtin http server is used for webadmin and (if httpdownloadurl is empty) resource downloads.
25-
Values: 0 - disabled , 1 - enabled ; default value: 1. Optional parameter. -->
26-
<httpserver>1</httpserver>
27-
2824
<!-- This parameter specifies the TCP port on which the server will be accepting incoming http
2925
connections. It can be set to the same value as <serverport>. It is a required parameter
3026
if <httpserver> is set to 1. -->
@@ -35,12 +31,6 @@
3531
are switched to the internal http server. -->
3632
<httpdownloadurl></httpdownloadurl>
3733

38-
<!-- This parameter specifies whether the client files for hosting on an external web server should be
39-
automatically copied into mods/deathmatch/resource-cache/http-client-files/
40-
Only relevant if <httpdownloadurl> is set.
41-
Values: 0 - disabled , 1 - enabled ; default value: 1. Optional parameter. -->
42-
<httpautoclientfiles>1</httpautoclientfiles>
43-
4434
<!-- This parameter limits the number of http connections each client can make. Depending on the type
4535
of http server that is used, a lower figure may reduce download timeouts.
4636
Available range: 1 to 8. -->
@@ -50,6 +40,15 @@
5040
Available range: 1 to 100. default value: 20 -->
5141
<httpdosthreshold>20</httpdosthreshold>
5242

43+
<!-- This parameter lists the IP addresses that are to be excluded from http dos threshold limits.
44+
e.g. 88.11.22.33,101.2.3.4 -->
45+
<http_dos_exclude></http_dos_exclude>
46+
47+
<!-- By default, the server will block the use of locally customized gta3.img player skins.
48+
This setting can be used to allow such mods. Not recommended for competitive servers.
49+
Values: none or peds ; default value: none -->
50+
<allow_gta3_img_mods>none</allow_gta3_img_mods>
51+
5352
<!-- By default, the server will block the use of customized GTA:SA data files. -->
5453
<!-- To allow specific client files, add one or more of the following: -->
5554
<!-- <client_file name="data/carmods.dat" verify="0"/> -->
@@ -123,8 +122,8 @@
123122
<keysync_analog_sync_interval>100</keysync_analog_sync_interval>
124123

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

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

225+
<!-- This parameter specifies whether server crash dump files should be sent to MTA HQ.
226+
Values: 0 - Off, 1 - On. Default - 1 -->
227+
<crash_dump_upload>0</crash_dump_upload>
228+
226229
<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
227230
parameter(s). Optional parameter. -->
228231
<!-- <module src="sample_win32.dll"/> -->
@@ -238,10 +241,15 @@
238241
<resource src="mapcycler" startup="1" protected="0"/>
239242
<resource src="mapmanager" startup="1" protected="0"/>
240243
<resource src="parachute" startup="1" protected="0"/>
244+
<resource src="performancebrowser" startup="1" protected="0"/>
245+
<resource src="reload" startup="1" protected="0"/>
246+
<resource src="resourcebrowser" startup="1" protected="1" default="true"/>
247+
<resource src="resourcemanager" startup="1" protected="1"/>
241248
<resource src="scoreboard" startup="1" protected="0"/>
242249
<resource src="spawnmanager" startup="1" protected="0"/>
243250
<resource src="voice" startup="1" protected="0" />
244251
<resource src="votemanager" startup="1" protected="0"/>
252+
<resource src="webadmin" startup="1" protected="0"/>
245253

246254
<!-- play is the default freeroam gamemode. Remove the following line to prevent it from starting. -->
247255
<resource src="play" startup="1" protected="0"/>

MTA10_Server/mods/deathmatch/logic/CMainConfig.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,7 @@ const std::vector < SIntSetting >& CMainConfig::GetIntSettingList ( void )
14511451
{ true, true, 0, 1, 2, "minclientversion_auto_update", &m_iMinClientVersionAutoUpdate, NULL },
14521452
{ true, true, 0, 0, 100, "server_logic_fps_limit", &m_iServerLogicFpsLimit, NULL },
14531453
{ true, true, 0, 1, 1, "bad_net_bullet_fix", &m_bBadNetBulletFixEnabled, NULL },
1454+
{ true, true, 0, 1, 1, "crash_dump_upload", &m_bCrashDumpUploadEnabled, NULL },
14541455
};
14551456

14561457
static std::vector < SIntSetting > settingsList;

MTA10_Server/mods/deathmatch/logic/CMainConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class CMainConfig: public CXMLConfig
125125
const SString& GetLoadstringLogFilename ( void ) const { return m_strLoadstringLogFilename; }
126126
bool GetLoadstringLogEnabled ( void ) const { return !m_strLoadstringLogFilename.empty(); }
127127
bool GetBadNetBulletFixEnabled ( void ) const { return m_bBadNetBulletFixEnabled != 0; }
128+
bool GetCrashDumpUploadEnabled ( void ) const { return m_bCrashDumpUploadEnabled != 0; }
128129

129130
SString GetSetting ( const SString& configSetting );
130131
bool GetSetting ( const SString& configSetting, SString& strValue );
@@ -215,6 +216,7 @@ class CMainConfig: public CXMLConfig
215216
int m_iMinClientVersionAutoUpdate;
216217
int m_iServerLogicFpsLimit;
217218
int m_bBadNetBulletFixEnabled;
219+
int m_bCrashDumpUploadEnabled;
218220
};
219221

220222
#endif

MTA10_Server/mods/deathmatch/mtaserver.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@
222222
Values: 0 - Never, 1 - On server start only after basic backup, 2 - On server start always. Default - 1 -->
223223
<compact_internal_databases>1</compact_internal_databases>
224224

225+
<!-- This parameter specifies whether server crash dump files should be sent to MTA HQ.
226+
Values: 0 - Off, 1 - On. Default - 1 -->
227+
<crash_dump_upload>1</crash_dump_upload>
228+
225229
<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
226230
parameter(s). Optional parameter. -->
227231
<!-- <module src="sample_win32.dll"/> -->

MTA10_Server/mods/deathmatch/utils/CHqComms.h

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class CHqComms : public CRefCountable
2929
{
3030
m_iPollInterval = TICKS_FROM_MINUTES( 60 );
3131
m_strURL = HQCOMMS_URL;
32-
m_strCrashInfoFilename = g_pServerInterface->GetAbsolutePath( PathJoin( SERVER_DUMP_PATH, "server_pending_upload.log" ) );
32+
m_strCrashLogFilename = g_pServerInterface->GetAbsolutePath( PathJoin( SERVER_DUMP_PATH, "server_pending_upload.log" ) );
33+
m_strCrashDumpMeta = g_pServerInterface->GetAbsolutePath( PathJoin( SERVER_DUMP_PATH, "server_pending_upload_filename" ) );
3334
}
3435

3536
//
@@ -44,7 +45,7 @@ class CHqComms : public CRefCountable
4445
m_Stage = HQCOMMS_STAGE_QUERY;
4546

4647
CBitStream bitStream;
47-
bitStream->Write( (char)1 );
48+
bitStream->Write( (char)2 ); // Data version
4849
bitStream->WriteStr( g_pGame->GetConfig()->GetServerIP() );
4950
bitStream->Write( g_pGame->GetConfig()->GetServerPort() );
5051
bitStream->WriteStr( CStaticFunctionDefinitions::GetVersionSortable() );
@@ -56,13 +57,32 @@ class CHqComms : public CRefCountable
5657
bitStream->Write( g_pGame->GetConfig()->GetAseInternetPushEnabled() ? 1 : 0 );
5758
bitStream->Write( g_pGame->GetConfig()->GetAseInternetListenEnabled() ? 1 : 0 );
5859

59-
SString strCrashInfo;
60-
FileLoad( m_strCrashInfoFilename, strCrashInfo, 50000 );
61-
bitStream->WriteStr( strCrashInfo );
60+
SString strCrashLog;
61+
FileLoad( m_strCrashLogFilename, strCrashLog, 50000 );
62+
bitStream->WriteStr( strCrashLog );
63+
64+
// Latest crash dump
65+
SString strCrashDumpFilename, strCrashDumpContent;
66+
if ( FileExists( m_strCrashDumpMeta ) )
67+
{
68+
if ( g_pGame->GetConfig()->GetCrashDumpUploadEnabled() )
69+
{
70+
FileLoad( m_strCrashDumpMeta, strCrashDumpFilename );
71+
FileLoad( strCrashDumpFilename, strCrashDumpContent );
72+
}
73+
// Only attempt to send crashdump once
74+
FileDelete( m_strCrashDumpMeta );
75+
m_strCrashDumpMeta = "";
76+
}
77+
bitStream->WriteStr( ExtractFilename( strCrashDumpFilename ) );
78+
bitStream->WriteStr( strCrashDumpContent );
79+
80+
bitStream->WriteStr( MTA_OS_STRING );
81+
bitStream->WriteStr( g_pGame->GetConfig()->GetServerIPList() );
6282

6383
// Send request
6484
this->AddRef(); // Keep object alive
65-
GetDownloadManager()->QueueFile( m_strURL, NULL, 0, (const char*)bitStream->GetData(), bitStream->GetNumberOfBytesUsed(), true, this, StaticProgressCallback, false, 1 );
85+
GetDownloadManager()->QueueFile( m_strURL, NULL, 0, (const char*)bitStream->GetData(), bitStream->GetNumberOfBytesUsed(), true, this, StaticProgressCallback, false, 2 );
6686
}
6787
}
6888

@@ -180,7 +200,7 @@ class CHqComms : public CRefCountable
180200
bitStream->Read( iGotCrashInfo );
181201
if ( iGotCrashInfo )
182202
{
183-
FileDelete( m_strCrashInfoFilename );
203+
FileDelete( m_strCrashLogFilename );
184204
}
185205
}
186206

@@ -223,5 +243,6 @@ class CHqComms : public CRefCountable
223243
CElapsedTime m_CheckTimer;
224244
SString m_strURL;
225245
SString m_strPrevMessage;
226-
SString m_strCrashInfoFilename;
246+
SString m_strCrashLogFilename;
247+
SString m_strCrashDumpMeta; // Filename of file which contains the latest crash dump filename
227248
};

0 commit comments

Comments
 (0)