Skip to content

Commit fdb0081

Browse files
Synchronize changes from 1.6 master branch [ci skip]
2359d7f Fix client side debugscript level filtering (#3498) (#4323)
2 parents 9e45078 + 2359d7f commit fdb0081

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

Client/mods/deathmatch/logic/CScriptDebugging.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2424
CScriptDebugging::~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
5252
void 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+
120120
void 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

Client/mods/deathmatch/logic/CScriptDebugging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ class CScriptDebugging
6868
SString ComposeErrorMessage(const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage);
6969
void LogString(const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage, unsigned int uiMinimumDebugLevel, unsigned char ucRed = 255,
7070
unsigned char ucGreen = 255, unsigned char ucBlue = 255);
71-
bool CheckForSufficientDebugLevel(std::uint8_t playerDebugLevel, std::uint8_t messageDebugLevel) const noexcept;
7271
void PrintLog(const char* szText);
72+
bool CheckForSufficientDebugLevel(std::uint8_t playerDebugLevel, std::uint8_t messageDebugLevel) const noexcept;
7373

7474
public:
7575
static FILE* m_pLogFile;

Shared/mods/deathmatch/logic/CScriptDebugging.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,17 @@ void CScriptDebugging::LogPCallError(lua_State* luaVM, const SString& strRes, bo
7070

7171
bool CScriptDebugging::CheckForSufficientDebugLevel(std::uint8_t playerDebugLevel, std::uint8_t messageDebugLevel) const noexcept
7272
{
73-
bool sufficientDebugLevel = false;
74-
75-
switch (messageDebugLevel)
73+
switch (messageDebugLevel)
7674
{
7775
case MESSAGE_TYPE_ERROR:
78-
sufficientDebugLevel = (playerDebugLevel >= ERRORS_ONLY);
79-
break;
76+
return playerDebugLevel >= ERRORS_ONLY;
8077
case MESSAGE_TYPE_WARNING:
81-
sufficientDebugLevel = (playerDebugLevel >= ERRORS_AND_WARNINGS);
82-
break;
78+
return playerDebugLevel >= ERRORS_AND_WARNINGS;
8379
case MESSAGE_TYPE_INFO:
8480
case MESSAGE_TYPE_CUSTOM:
8581
case MESSAGE_TYPE_DEBUG:
86-
sufficientDebugLevel = (playerDebugLevel == ALL);
87-
break;
82+
return playerDebugLevel == ALL;
8883
}
89-
90-
return sufficientDebugLevel;
9184
}
9285

9386
void CScriptDebugging::LogCustom(lua_State* luaVM, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, const char* szFormat, ...)

0 commit comments

Comments
 (0)