Skip to content

Commit

Permalink
Fix server-side debugscript behavior (PR #3499)
Browse files Browse the repository at this point in the history
  • Loading branch information
ds1-e authored Jun 26, 2024
1 parent c6fbcc9 commit fcbe3fd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
49 changes: 44 additions & 5 deletions Server/mods/deathmatch/logic/CScriptDebugging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@

extern CGame* g_pGame;

enum DebugScriptLevels : std::uint8_t
{
NONE,
ERRORS_ONLY,
ERRORS_AND_WARNINGS,
ALL,
};

enum DebugMessageLevels : std::uint8_t
{
MESSAGE_TYPE_DEBUG,
MESSAGE_TYPE_ERROR,
MESSAGE_TYPE_WARNING,
MESSAGE_TYPE_INFO,
MESSAGE_TYPE_CUSTOM,
};

CScriptDebugging::CScriptDebugging()
{
m_uiLogFileLevel = 0;
Expand Down Expand Up @@ -143,16 +160,38 @@ void CScriptDebugging::PrintLog(const char* szText)
}
}

bool CScriptDebugging::CheckForSufficientDebugLevel(std::uint8_t playerDebugLevel, std::uint8_t messageDebugLevel) const noexcept
{
bool sufficientDebugLevel = false;

switch (messageDebugLevel)
{
case MESSAGE_TYPE_ERROR:
sufficientDebugLevel = (playerDebugLevel >= ERRORS_ONLY);
break;
case MESSAGE_TYPE_WARNING:
sufficientDebugLevel = (playerDebugLevel >= ERRORS_AND_WARNINGS);
break;
case MESSAGE_TYPE_INFO:
case MESSAGE_TYPE_CUSTOM:
case MESSAGE_TYPE_DEBUG:
sufficientDebugLevel = (playerDebugLevel == ALL);
break;
}

return sufficientDebugLevel;
}

void CScriptDebugging::Broadcast(const CPacket& Packet, unsigned int uiMinimumDebugLevel)
{
// Tell everyone we log to about it
list<CPlayer*>::const_iterator iter = m_Players.begin();
auto uiRequiredDebugLevel = std::min(uiMinimumDebugLevel, 3u); // Make sure it doesn't skip outputDebugString with level 4
for (; iter != m_Players.end(); iter++)
for (const auto& pPlayer : m_Players)
{
if ((*iter)->m_uiScriptDebugLevel >= uiRequiredDebugLevel)
bool sufficientDebugLevel = CheckForSufficientDebugLevel(pPlayer->m_uiScriptDebugLevel, uiMinimumDebugLevel);

if (sufficientDebugLevel)
{
(*iter)->Send(Packet);
pPlayer->Send(Packet);
}
}
}
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CScriptDebugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class CScriptDebugging
unsigned char ucGreen = 255, unsigned char ucBlue = 255);

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

unsigned int m_uiLogFileLevel;
Expand Down

0 comments on commit fcbe3fd

Please sign in to comment.