diff --git a/Client/mods/deathmatch/logic/CScriptDebugging.cpp b/Client/mods/deathmatch/logic/CScriptDebugging.cpp index 4af67b1524..8d9898c69a 100644 --- a/Client/mods/deathmatch/logic/CScriptDebugging.cpp +++ b/Client/mods/deathmatch/logic/CScriptDebugging.cpp @@ -16,9 +16,9 @@ CScriptDebugging::CScriptDebugging(CLuaManager* pLuaManager) { m_pLuaManager = pLuaManager; m_uiLogFileLevel = 0; - m_pLogFile = NULL; + m_pLogFile = nullptr; m_bTriggeringMessageEvent = false; - m_flushTimerHandle = NULL; + m_flushTimerHandle = nullptr; } CScriptDebugging::~CScriptDebugging() @@ -33,13 +33,13 @@ CScriptDebugging::~CScriptDebugging() fprintf(m_pLogFile, "INFO: Logging to this file ended\n"); // if we have a flush timer - if (m_flushTimerHandle != NULL) + if (m_flushTimerHandle) { // delete our flush timer - DeleteTimerQueueTimer(NULL, m_flushTimerHandle, INVALID_HANDLE_VALUE); // INVALID_HANDLE_VALUE = wait for running callbacks to finish + DeleteTimerQueueTimer(nullptr, m_flushTimerHandle, INVALID_HANDLE_VALUE); // INVALID_HANDLE_VALUE = wait for running callbacks to finish } fclose(m_pLogFile); - m_pLogFile = NULL; + m_pLogFile = nullptr; } } @@ -52,7 +52,7 @@ void CScriptDebugging::LogBadLevel(lua_State* luaVM, unsigned int uiRequiredLeve void CALLBACK TimerProc(void* lpParametar, BOOLEAN TimerOrWaitFired) { // Got a logfile? - if (CScriptDebugging::m_pLogFile != NULL) + if (CScriptDebugging::m_pLogFile) { // flush our log file fflush((FILE*)CScriptDebugging::m_pLogFile); @@ -68,13 +68,13 @@ bool CScriptDebugging::SetLogfile(const char* szFilename, unsigned int uiLevel) { fprintf(m_pLogFile, "INFO: Logging to this file ended\n"); // if we have a flush timer - if (m_flushTimerHandle != NULL) + if (m_flushTimerHandle) { // delete our flush timer - DeleteTimerQueueTimer(NULL, m_flushTimerHandle, INVALID_HANDLE_VALUE); // INVALID_HANDLE_VALUE = wait for running callbacks to finish + DeleteTimerQueueTimer(nullptr, m_flushTimerHandle, INVALID_HANDLE_VALUE); // INVALID_HANDLE_VALUE = wait for running callbacks to finish } fclose(m_pLogFile); - m_pLogFile = NULL; + m_pLogFile = nullptr; } // Apply log size limit @@ -102,38 +102,46 @@ bool CScriptDebugging::SetLogfile(const char* szFilename, unsigned int uiLevel) // round 37.5 to 38 because we can't have half a message // 8 * 256 bytes = 6004B // round 6004 up to the nearest divisible by 1024 = 6144 - // we have our buffer size. - setvbuf(pFile, NULL, _IOFBF, 6144); + setvbuf(pFile, nullptr, _IOFBF, 6144); // Set the new pointer and level and return true m_uiLogFileLevel = uiLevel; m_pLogFile = pFile; // Create a timer - ::CreateTimerQueueTimer(&m_flushTimerHandle, NULL, TimerProc, NULL, 50, 50, WT_EXECUTEINTIMERTHREAD); + ::CreateTimerQueueTimer(&m_flushTimerHandle, nullptr, TimerProc, nullptr, 50, 50, WT_EXECUTEINTIMERTHREAD); return true; } return false; } + void CScriptDebugging::UpdateLogOutput() { SLogLine line; while (m_DuplicateLineFilter.PopOutputLine(line)) { - // Log it to the file if enough level bool sufficientDebugLevel = CheckForSufficientDebugLevel(m_uiLogFileLevel, line.uiMinimumDebugLevel); if (sufficientDebugLevel) { PrintLog(line.strText); } + #ifdef MTA_DEBUG if (!g_pCore->IsDebugVisible()) return; #endif - g_pCore->DebugEchoColor(line.strText, line.ucRed, line.ucGreen, line.ucBlue); + + std::uint8_t clientDebugLevel = 0; + auto* pLocalPlayer = g_pClientGame->GetPlayerManager()->GetLocalPlayer(); + if (pLocalPlayer) + clientDebugLevel = pLocalPlayer->GetPlayerScriptDebugLevel(); + + bool shouldDisplayInConsole = CheckForSufficientDebugLevel(clientDebugLevel, line.uiMinimumDebugLevel); + if (shouldDisplayInConsole) + g_pCore->DebugEchoColor(line.strText, line.ucRed, line.ucGreen, line.ucBlue); } } diff --git a/Client/mods/deathmatch/logic/CScriptDebugging.h b/Client/mods/deathmatch/logic/CScriptDebugging.h index 48b41b606a..961e9e41d8 100644 --- a/Client/mods/deathmatch/logic/CScriptDebugging.h +++ b/Client/mods/deathmatch/logic/CScriptDebugging.h @@ -68,8 +68,8 @@ class CScriptDebugging SString ComposeErrorMessage(const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage); void LogString(const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage, unsigned int uiMinimumDebugLevel, unsigned char ucRed = 255, unsigned char ucGreen = 255, unsigned char ucBlue = 255); - bool CheckForSufficientDebugLevel(std::uint8_t playerDebugLevel, std::uint8_t messageDebugLevel) const noexcept; void PrintLog(const char* szText); + bool CheckForSufficientDebugLevel(std::uint8_t playerDebugLevel, std::uint8_t messageDebugLevel) const noexcept; public: static FILE* m_pLogFile; diff --git a/Shared/mods/deathmatch/logic/CScriptDebugging.cpp b/Shared/mods/deathmatch/logic/CScriptDebugging.cpp index a303c010ef..a7aaf4422c 100644 --- a/Shared/mods/deathmatch/logic/CScriptDebugging.cpp +++ b/Shared/mods/deathmatch/logic/CScriptDebugging.cpp @@ -70,24 +70,17 @@ void CScriptDebugging::LogPCallError(lua_State* luaVM, const SString& strRes, bo bool CScriptDebugging::CheckForSufficientDebugLevel(std::uint8_t playerDebugLevel, std::uint8_t messageDebugLevel) const noexcept { - bool sufficientDebugLevel = false; - - switch (messageDebugLevel) +switch (messageDebugLevel) { case MESSAGE_TYPE_ERROR: - sufficientDebugLevel = (playerDebugLevel >= ERRORS_ONLY); - break; + return playerDebugLevel >= ERRORS_ONLY; case MESSAGE_TYPE_WARNING: - sufficientDebugLevel = (playerDebugLevel >= ERRORS_AND_WARNINGS); - break; + return playerDebugLevel >= ERRORS_AND_WARNINGS; case MESSAGE_TYPE_INFO: case MESSAGE_TYPE_CUSTOM: case MESSAGE_TYPE_DEBUG: - sufficientDebugLevel = (playerDebugLevel == ALL); - break; + return playerDebugLevel == ALL; } - - return sufficientDebugLevel; } void CScriptDebugging::LogCustom(lua_State* luaVM, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, const char* szFormat, ...)