Skip to content

Commit fcbe3fd

Browse files
authored
Fix server-side debugscript behavior (PR #3499)
1 parent c6fbcc9 commit fcbe3fd

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

Server/mods/deathmatch/logic/CScriptDebugging.cpp

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@
1515

1616
extern CGame* g_pGame;
1717

18+
enum DebugScriptLevels : std::uint8_t
19+
{
20+
NONE,
21+
ERRORS_ONLY,
22+
ERRORS_AND_WARNINGS,
23+
ALL,
24+
};
25+
26+
enum DebugMessageLevels : std::uint8_t
27+
{
28+
MESSAGE_TYPE_DEBUG,
29+
MESSAGE_TYPE_ERROR,
30+
MESSAGE_TYPE_WARNING,
31+
MESSAGE_TYPE_INFO,
32+
MESSAGE_TYPE_CUSTOM,
33+
};
34+
1835
CScriptDebugging::CScriptDebugging()
1936
{
2037
m_uiLogFileLevel = 0;
@@ -143,16 +160,38 @@ void CScriptDebugging::PrintLog(const char* szText)
143160
}
144161
}
145162

163+
bool CScriptDebugging::CheckForSufficientDebugLevel(std::uint8_t playerDebugLevel, std::uint8_t messageDebugLevel) const noexcept
164+
{
165+
bool sufficientDebugLevel = false;
166+
167+
switch (messageDebugLevel)
168+
{
169+
case MESSAGE_TYPE_ERROR:
170+
sufficientDebugLevel = (playerDebugLevel >= ERRORS_ONLY);
171+
break;
172+
case MESSAGE_TYPE_WARNING:
173+
sufficientDebugLevel = (playerDebugLevel >= ERRORS_AND_WARNINGS);
174+
break;
175+
case MESSAGE_TYPE_INFO:
176+
case MESSAGE_TYPE_CUSTOM:
177+
case MESSAGE_TYPE_DEBUG:
178+
sufficientDebugLevel = (playerDebugLevel == ALL);
179+
break;
180+
}
181+
182+
return sufficientDebugLevel;
183+
}
184+
146185
void CScriptDebugging::Broadcast(const CPacket& Packet, unsigned int uiMinimumDebugLevel)
147186
{
148187
// Tell everyone we log to about it
149-
list<CPlayer*>::const_iterator iter = m_Players.begin();
150-
auto uiRequiredDebugLevel = std::min(uiMinimumDebugLevel, 3u); // Make sure it doesn't skip outputDebugString with level 4
151-
for (; iter != m_Players.end(); iter++)
188+
for (const auto& pPlayer : m_Players)
152189
{
153-
if ((*iter)->m_uiScriptDebugLevel >= uiRequiredDebugLevel)
190+
bool sufficientDebugLevel = CheckForSufficientDebugLevel(pPlayer->m_uiScriptDebugLevel, uiMinimumDebugLevel);
191+
192+
if (sufficientDebugLevel)
154193
{
155-
(*iter)->Send(Packet);
194+
pPlayer->Send(Packet);
156195
}
157196
}
158197
}

Server/mods/deathmatch/logic/CScriptDebugging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class CScriptDebugging
7373
unsigned char ucGreen = 255, unsigned char ucBlue = 255);
7474

7575
void PrintLog(const char* szText);
76+
bool CheckForSufficientDebugLevel(std::uint8_t playerDebugLevel, std::uint8_t messageDebugLevel) const noexcept;
7677
void Broadcast(const CPacket& Packet, unsigned int uiMinimumDebugLevel);
7778

7879
unsigned int m_uiLogFileLevel;

0 commit comments

Comments
 (0)