|
15 | 15 |
|
16 | 16 | extern CGame* g_pGame; |
17 | 17 |
|
| 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 | + |
18 | 35 | CScriptDebugging::CScriptDebugging() |
19 | 36 | { |
20 | 37 | m_uiLogFileLevel = 0; |
@@ -143,16 +160,38 @@ void CScriptDebugging::PrintLog(const char* szText) |
143 | 160 | } |
144 | 161 | } |
145 | 162 |
|
| 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 | + |
146 | 185 | void CScriptDebugging::Broadcast(const CPacket& Packet, unsigned int uiMinimumDebugLevel) |
147 | 186 | { |
148 | 187 | // 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) |
152 | 189 | { |
153 | | - if ((*iter)->m_uiScriptDebugLevel >= uiRequiredDebugLevel) |
| 190 | + bool sufficientDebugLevel = CheckForSufficientDebugLevel(pPlayer->m_uiScriptDebugLevel, uiMinimumDebugLevel); |
| 191 | + |
| 192 | + if (sufficientDebugLevel) |
154 | 193 | { |
155 | | - (*iter)->Send(Packet); |
| 194 | + pPlayer->Send(Packet); |
156 | 195 | } |
157 | 196 | } |
158 | 197 | } |
0 commit comments