Skip to content

Commit fe0d97c

Browse files
committed
Logging update + refactor
1 parent 1f2d080 commit fe0d97c

File tree

11 files changed

+76
-60
lines changed

11 files changed

+76
-60
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6532,6 +6532,9 @@ void CClientGame::OutputServerInfo( void )
65326532
//////////////////////////////////////////////////////////////////
65336533
void CClientGame::TellServerSomethingImportant( uint uiId, const SString& strMessage, uint uiSendLimitForThisId )
65346534
{
6535+
g_pCore->GetConsole()->Print(strMessage);
6536+
AddReportLog(3400 + uiId, strMessage + g_pNet->GetConnectedServer(true), 10);
6537+
65356538
if ( uiSendLimitForThisId )
65366539
{
65376540
uint& uiCount = MapGet( m_SentMessageIds, uiId );

Client/mods/deathmatch/logic/CResourceManager.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,6 @@ void CResourceManager::ValidateResourceFile( const SString& strInFilename, const
280280
CMD5Hasher::ConvertToHex( pResourceFile->GetServerChecksum().md5, szMd5Wanted );
281281
SString strMessage( "Resource file checksum failed: %s [Size:%d MD5:%s][Wanted:%s][datasize:%d] ", *ConformResourcePath( strInFilename ), (int)FileSize( strInFilename ), szMd5, szMd5Wanted, fileData.GetSize() );
282282
g_pClientGame->TellServerSomethingImportant( 1007, strMessage );
283-
g_pCore->GetConsole ()->Print( strMessage );
284-
AddReportLog( 7057, strMessage + g_pNet->GetConnectedServer( true ), 10 );
285283
}
286284
else
287285
if ( pResourceFile->IsAutoDownload() )
@@ -290,8 +288,6 @@ void CResourceManager::ValidateResourceFile( const SString& strInFilename, const
290288
CMD5Hasher::ConvertToHex( checksum.md5, szMd5 );
291289
SString strMessage( "Attempt to load resource file before it is ready: %s [Size:%d MD5:%s] ", *ConformResourcePath( strInFilename ), (int)FileSize( strInFilename ), szMd5 );
292290
g_pClientGame->TellServerSomethingImportant( 1008, strMessage );
293-
g_pCore->GetConsole ()->Print( strMessage );
294-
AddReportLog( 7058, strMessage + g_pNet->GetConnectedServer( true ), 10 );
295291
}
296292
}
297293
}

Client/mods/deathmatch/logic/lua/CLuaMain.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ bool CLuaMain::LoadScriptFromBuffer ( const char* cpInBuffer, unsigned int uiInS
217217
{
218218
SString strMessage( "%s is invalid. Please re-compile at http://luac.mtasa.com/", *strNiceFilename );
219219
g_pClientGame->GetScriptDebugging()->LogError ( m_luaVM, "Loading script failed: %s", *strMessage );
220-
g_pCore->GetConsole()->Printf( "Loading script failed: %s", *strMessage );
221-
g_pClientGame->TellServerSomethingImportant( 1003, SStringX( "CLIENT SCRIPT ERROR: " ) + strMessage );
220+
g_pClientGame->TellServerSomethingImportant( 1003, SString( "CLIENT SCRIPT ERROR: %s", *strMessage ) );
222221
return false;
223222
}
224223

Client/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,6 @@ int CLuaResourceDefs::LoadString ( lua_State* luaVM )
459459
SString strMessage ( "argument 1 is invalid. Please re-compile at http://luac.mtasa.com/", 0 );
460460
argStream.SetCustomError ( strMessage );
461461
cpBuffer = NULL;
462-
g_pCore->GetConsole ()->Print ( argStream.GetFullErrorMessage () );
463462
g_pClientGame->TellServerSomethingImportant ( 1004, argStream.GetFullErrorMessage (), 3 );
464463
}
465464

@@ -508,22 +507,22 @@ int CLuaResourceDefs::Load ( lua_State* luaVM )
508507
{
509508
CLuaArguments returnValues;
510509
callbackArguments.Call ( pLuaMain, iLuaFunction, &returnValues );
511-
if (returnValues.Count())
512-
{
513-
CLuaArgument* returnedValue = *returnValues.IterBegin();
514-
int iType = returnedValue->GetType();
515-
if (iType == LUA_TNIL)
516-
break;
517-
518-
else if (iType == LUA_TSTRING)
519-
{
520-
std::string str = returnedValue->GetString();
521-
if (str.length() == 0)
522-
break;
523-
524-
strInput += str;
525-
continue;
526-
}
510+
if (returnValues.Count())
511+
{
512+
CLuaArgument* returnedValue = *returnValues.IterBegin();
513+
int iType = returnedValue->GetType();
514+
if (iType == LUA_TNIL)
515+
break;
516+
517+
else if (iType == LUA_TSTRING)
518+
{
519+
std::string str = returnedValue->GetString();
520+
if (str.length() == 0)
521+
break;
522+
523+
strInput += str;
524+
continue;
525+
}
527526
}
528527
break;
529528
}
@@ -540,7 +539,6 @@ int CLuaResourceDefs::Load ( lua_State* luaVM )
540539
SString strMessage ( "argument 2 is invalid. Please re-compile at http://luac.mtasa.com/", 0 );
541540
argStream.SetCustomError ( strMessage );
542541
cpBuffer = NULL;
543-
g_pCore->GetConsole ()->Print ( argStream.GetFullErrorMessage () );
544542
g_pClientGame->TellServerSomethingImportant ( 1005, argStream.GetFullErrorMessage (), 3 );
545543
}
546544

Client/multiplayer_sa/CMultiplayerSA_CrashFixHacks.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,7 @@ RwFrame* OnMY_CClumpModelInfo_GetFrameFromId_Post ( RwFrame* pFrameResult, DWORD
10931093

10941094
// Couldn't find a replacement frame id
10951095
SString strMsg ( "No frame for vehicle:%d frameId:%d (calledfrom:%08x)", iModelId, id, calledFrom );
1096+
AddReportLog ( 5413, SString ( "GetFrameFromId - %s", *strMsg ) );
10961097
LogEvent ( 5413, "Model frame error", "GetFrameFromId", strMsg );
10971098

10981099
return NULL;

Server/core/CDynamicLibrary.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,19 @@ bool CDynamicLibrary::CheckMtaVersion( const char* szLibName )
176176
FUNC_GetMtaVersion* pfnGetMtaVersion = (FUNC_GetMtaVersion*) ( GetProcedureAddress ( "GetLibMtaVersion" ) );
177177
if ( pfnGetMtaVersion )
178178
pfnGetMtaVersion( buffer, sizeof( buffer ) );
179-
if ( strVersionCore != buffer )
179+
SString strVersionLibrary = buffer;
180+
if ( strVersionCore != strVersionLibrary )
180181
{
181-
Print( "ERROR: '%s' library version is '%s' (Expected '%s')\n", szLibName, buffer, *strVersionCore );
182-
Print( "\n** REINSTALL MTA **\n" );
182+
Print( "ERROR: '%s' library version is '%s' (Expected '%s')\n", szLibName, *strVersionLibrary, *strVersionCore );
183+
if ( MTASA_VERSION_BUILD == 0 )
184+
{
185+
int iBuildLibrary = atoi(strVersionLibrary.SubStr(8));
186+
Print ( "\n(If this is a custom build,\n" );
187+
Print ( " 1. Set MTASA_VERSION_BUILD in version.h to %d\n", iBuildLibrary );
188+
Print ( " 2. Rebuild)\n\n\n" );
189+
}
190+
else
191+
Print( "\n** REINSTALL MTA **\n\n" );
183192
return false;
184193
}
185194

Server/core/CServerImpl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ int CServerImpl::Run ( int iArgumentCount, char* szArguments [] )
350350
Print ( "Network module not compatible! (Expected 0x%x, got 0x%x)\n", MTA_DM_SERVER_NET_MODULE_VERSION, (uint)ulNetModuleVersion );
351351
Print ( "Press Q to shut down the server!\n" );
352352
Print ( "\n\n\n(If this is a custom build,\n" );
353-
Print ( " check MTASA_VERSION_TYPE in version.h is set correctly)\n" );
353+
Print ( " 1. Update source to latest\n" );
354+
Print ( " 2. Get latest net module (run install-data)\n" );
355+
Print ( " 3. Check MTASA_VERSION_TYPE in version.h is set correctly)\n" );
354356
WaitForKey ( 'q' );
355357
DestroyWindow ( );
356358
return ERROR_NETWORK_LIBRARY_FAILED;

Server/mods/deathmatch/logic/CMainConfig.cpp

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ CMainConfig::CMainConfig ( CConsole* pConsole, CLuaManager* pLuaMain ): CXMLConf
7979
m_iHTTPThreadCount = 8;
8080
m_iHTTPDosThreshold = 20;
8181
m_iEnableClientChecks = -1;
82-
m_bAutoUpdateAntiCheatEnabled = true;
8382
m_bJoinFloodProtectionEnabled = true;
8483
m_bScriptDebugLogEnabled = false;
8584
m_uiScriptDebugLogLevel = 0;
@@ -299,9 +298,8 @@ bool CMainConfig::Load ( void )
299298
{
300299
SString strDisableAC;
301300
GetString ( m_pRootNode, "disableac", strDisableAC );
302-
strDisableAC = strDisableAC.Replace( " ", "" );
303301
std::vector < SString > tagACList;
304-
strDisableAC.Split ( ",", tagACList );
302+
ReadCommaSeparatedList(strDisableAC, tagACList);
305303
for ( std::vector < SString >::iterator it = tagACList.begin () ; it != tagACList.end () ; ++it )
306304
if ( isdigit((uchar)***it) )
307305
{
@@ -320,9 +318,8 @@ bool CMainConfig::Load ( void )
320318
{
321319
SString strEnableSD;
322320
GetString ( m_pRootNode, "enablesd", strEnableSD );
323-
strEnableSD = strEnableSD.Replace( " ", "" );
324321
std::vector < SString > tagSDList;
325-
strEnableSD.Split ( ",", tagSDList );
322+
ReadCommaSeparatedList(strEnableSD, tagSDList);
326323
for ( std::vector < SString >::iterator it = tagSDList.begin () ; it != tagSDList.end () ; ++it )
327324
if ( isdigit((uchar)***it) )
328325
{
@@ -355,12 +352,9 @@ bool CMainConfig::Load ( void )
355352
{
356353
SString strEnable;
357354
GetString ( m_pRootNode, "enable_diagnostic", strEnable );
358-
strEnable = strEnable.Replace( " ", "" );
359355
std::vector < SString > tagList;
360-
strEnable.Split ( ",", tagList );
361-
for ( std::vector < SString >::iterator it = tagList.begin () ; it != tagList.end () ; ++it )
362-
if ( (*it).length () )
363-
MapInsert ( m_EnableDiagnosticMap, *it );
356+
ReadCommaSeparatedList(strEnable, tagList);
357+
m_EnableDiagnosticMap = std::set<SString>(tagList.begin(), tagList.end());
364358
}
365359

366360
// Grab the server password
@@ -508,16 +502,7 @@ bool CMainConfig::Load ( void )
508502
// If not defined in conf file, then default to disabled
509503
strGroupList = "";
510504
}
511-
strGroupList.Split( ",", m_AuthSerialGroupList );
512-
for ( auto iter = m_AuthSerialGroupList.begin() ; iter != m_AuthSerialGroupList.end() ; )
513-
{
514-
SString& strGroup = *iter;
515-
strGroup = strGroup.TrimEnd( " " ).TrimStart( " " );
516-
if ( strGroup.empty() )
517-
iter = m_AuthSerialGroupList.erase( iter );
518-
else
519-
++iter;
520-
}
505+
ReadCommaSeparatedList(strGroupList, m_AuthSerialGroupList);
521506

522507
// auth_serial_http
523508
if ( GetBoolean( m_pRootNode, "auth_serial_http", m_bAuthSerialHttpEnabled ) != IS_SUCCESS )
@@ -1351,11 +1336,11 @@ bool CMainConfig::SetSetting ( const SString& strName, const SString& strValue,
13511336
SString strCurSD;
13521337
GetSetting( "enablesd", strCurSD );
13531338
std::vector < SString > curSDList;
1354-
strCurSD.Replace( " ", "" ).Split ( ",", curSDList );
1339+
ReadCommaSeparatedList(strCurSD, curSDList);
13551340

13561341
// Get new setting as as list of ids
13571342
std::vector < SString > newSDList;
1358-
strValue.Replace( " ", "" ).Split( ",", newSDList );
1343+
ReadCommaSeparatedList(strValue, newSDList);
13591344

13601345
// Merge
13611346
std::set < uint > comboSDMap;
@@ -1387,17 +1372,13 @@ bool CMainConfig::SetSetting ( const SString& strName, const SString& strValue,
13871372
{
13881373
if ( true )
13891374
{
1390-
m_EnableDiagnosticMap.clear();
1391-
SString strEnableDiagnostic = strValue.Replace( " ", "" );
13921375
std::vector < SString > tagList;
1393-
strEnableDiagnostic.Split ( ",", tagList );
1394-
for ( std::vector < SString >::iterator it = tagList.begin () ; it != tagList.end () ; ++it )
1395-
if ( (*it).length () )
1396-
MapInsert ( m_EnableDiagnosticMap, *it );
1376+
ReadCommaSeparatedList(strValue, tagList);
1377+
m_EnableDiagnosticMap = std::set<SString>(tagList.begin(), tagList.end());
13971378

13981379
if ( bSave )
13991380
{
1400-
SetString ( m_pRootNode, "enable_diagnostic", strEnableDiagnostic );
1381+
SetString ( m_pRootNode, "enable_diagnostic", SString::Join(",", tagList) );
14011382
Save ();
14021383
}
14031384
return true;

Server/mods/deathmatch/logic/CMainConfig.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ class CMainConfig: public CXMLConfig
8888
inline int GetEnableClientChecks ( void ) { return m_iEnableClientChecks; };
8989
inline const std::string& GetLogFile ( void ) { return m_strLogFile; };
9090
inline const std::string& GetAuthFile ( void ) { return m_strAuthFile; };
91-
inline bool GetAutoUpdateAntiCheatEnabled ( void ) { return m_bAutoUpdateAntiCheatEnabled; };
9291
inline bool GetJoinFloodProtectionEnabled ( void ) { return m_bJoinFloodProtectionEnabled; };
9392
inline bool GetScriptDebugLogEnabled ( void ) { return m_bScriptDebugLogEnabled && !m_strScriptDebugLogFile.empty (); };
9493
inline const std::string& GetScriptDebugLogFile ( void ) { return m_strScriptDebugLogFile; };
@@ -182,7 +181,6 @@ class CMainConfig: public CXMLConfig
182181
int m_iEnableClientChecks;
183182
std::string m_strLogFile;
184183
std::string m_strAuthFile;
185-
bool m_bAutoUpdateAntiCheatEnabled;
186184
bool m_bJoinFloodProtectionEnabled;
187185
bool m_bScriptDebugLogEnabled;
188186
std::string m_strScriptDebugLogFile;

Shared/sdk/SharedUtil.Misc.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,31 @@ namespace SharedUtil
14651465
}
14661466

14671467

1468+
///////////////////////////////////////////////////////////////
1469+
//
1470+
// ReadCommaSeparatedList
1471+
//
1472+
// Split comma separated values into an array.
1473+
// Removes leading/trailing spaces and empty items
1474+
//
1475+
///////////////////////////////////////////////////////////////
1476+
inline
1477+
void ReadCommaSeparatedList(const SString& strInput, std::vector<SString>& outList)
1478+
{
1479+
strInput.Split(",", outList);
1480+
// Remove surrounding spaces for each item
1481+
for ( auto iter = outList.begin(); iter != outList.end(); )
1482+
{
1483+
SString& strItem = *iter;
1484+
strItem = strItem.TrimEnd(" ").TrimStart(" ");
1485+
if ( strItem.empty() )
1486+
iter = outList.erase(iter);
1487+
else
1488+
++iter;
1489+
}
1490+
}
1491+
1492+
14681493
///////////////////////////////////////////////////////////////
14691494
//
14701495
// CFilterMap

0 commit comments

Comments
 (0)