@@ -16,9 +16,9 @@ CScriptDebugging::CScriptDebugging(CLuaManager* pLuaManager)
1616{
1717 m_pLuaManager = pLuaManager;
1818 m_uiLogFileLevel = 0 ;
19- m_pLogFile = NULL ;
19+ m_pLogFile = nullptr ;
2020 m_bTriggeringMessageEvent = false ;
21- m_flushTimerHandle = NULL ;
21+ m_flushTimerHandle = nullptr ;
2222}
2323
2424CScriptDebugging::~CScriptDebugging ()
@@ -33,13 +33,13 @@ CScriptDebugging::~CScriptDebugging()
3333 fprintf (m_pLogFile, " INFO: Logging to this file ended\n " );
3434
3535 // if we have a flush timer
36- if (m_flushTimerHandle != NULL )
36+ if (m_flushTimerHandle)
3737 {
3838 // delete our flush timer
39- DeleteTimerQueueTimer (NULL , m_flushTimerHandle, INVALID_HANDLE_VALUE); // INVALID_HANDLE_VALUE = wait for running callbacks to finish
39+ DeleteTimerQueueTimer (nullptr , m_flushTimerHandle, INVALID_HANDLE_VALUE); // INVALID_HANDLE_VALUE = wait for running callbacks to finish
4040 }
4141 fclose (m_pLogFile);
42- m_pLogFile = NULL ;
42+ m_pLogFile = nullptr ;
4343 }
4444}
4545
@@ -52,7 +52,7 @@ void CScriptDebugging::LogBadLevel(lua_State* luaVM, unsigned int uiRequiredLeve
5252void CALLBACK TimerProc (void * lpParametar, BOOLEAN TimerOrWaitFired)
5353{
5454 // Got a logfile?
55- if (CScriptDebugging::m_pLogFile != NULL )
55+ if (CScriptDebugging::m_pLogFile)
5656 {
5757 // flush our log file
5858 fflush ((FILE*)CScriptDebugging::m_pLogFile);
@@ -68,13 +68,13 @@ bool CScriptDebugging::SetLogfile(const char* szFilename, unsigned int uiLevel)
6868 {
6969 fprintf (m_pLogFile, " INFO: Logging to this file ended\n " );
7070 // if we have a flush timer
71- if (m_flushTimerHandle != NULL )
71+ if (m_flushTimerHandle)
7272 {
7373 // delete our flush timer
74- DeleteTimerQueueTimer (NULL , m_flushTimerHandle, INVALID_HANDLE_VALUE); // INVALID_HANDLE_VALUE = wait for running callbacks to finish
74+ DeleteTimerQueueTimer (nullptr , m_flushTimerHandle, INVALID_HANDLE_VALUE); // INVALID_HANDLE_VALUE = wait for running callbacks to finish
7575 }
7676 fclose (m_pLogFile);
77- m_pLogFile = NULL ;
77+ m_pLogFile = nullptr ;
7878 }
7979
8080 // Apply log size limit
@@ -102,38 +102,46 @@ bool CScriptDebugging::SetLogfile(const char* szFilename, unsigned int uiLevel)
102102 // round 37.5 to 38 because we can't have half a message
103103 // 8 * 256 bytes = 6004B
104104 // round 6004 up to the nearest divisible by 1024 = 6144
105- // we have our buffer size.
106- setvbuf (pFile, NULL , _IOFBF, 6144 );
105+ setvbuf (pFile, nullptr , _IOFBF, 6144 );
107106
108107 // Set the new pointer and level and return true
109108 m_uiLogFileLevel = uiLevel;
110109 m_pLogFile = pFile;
111110
112111 // Create a timer
113- ::CreateTimerQueueTimer (&m_flushTimerHandle, NULL , TimerProc, NULL , 50 , 50 , WT_EXECUTEINTIMERTHREAD);
112+ ::CreateTimerQueueTimer (&m_flushTimerHandle, nullptr , TimerProc, nullptr , 50 , 50 , WT_EXECUTEINTIMERTHREAD);
114113 return true ;
115114 }
116115
117116 return false ;
118117}
119118
119+
120120void CScriptDebugging::UpdateLogOutput ()
121121{
122122 SLogLine line;
123123 while (m_DuplicateLineFilter.PopOutputLine (line))
124124 {
125- // Log it to the file if enough level
126125 bool sufficientDebugLevel = CheckForSufficientDebugLevel (m_uiLogFileLevel, line.uiMinimumDebugLevel );
127126
128127 if (sufficientDebugLevel)
129128 {
130129 PrintLog (line.strText );
131130 }
131+
132132 #ifdef MTA_DEBUG
133133 if (!g_pCore->IsDebugVisible ())
134134 return ;
135135 #endif
136- g_pCore->DebugEchoColor (line.strText , line.ucRed , line.ucGreen , line.ucBlue );
136+
137+ std::uint8_t clientDebugLevel = 0 ;
138+ auto * localPlayer = g_pClientGame->GetPlayerManager ()->GetLocalPlayer ();
139+ if (localPlayer)
140+ clientDebugLevel = localPlayer->GetPlayerScriptDebugLevel ();
141+
142+ bool shouldDisplayInConsole = CheckForSufficientDebugLevel (clientDebugLevel, line.uiMinimumDebugLevel );
143+ if (shouldDisplayInConsole)
144+ g_pCore->DebugEchoColor (line.strText , line.ucRed , line.ucGreen , line.ucBlue );
137145 }
138146}
139147
0 commit comments