Skip to content

Commit 865f4fd

Browse files
authored
Fix #1158: add outputDebugString level 4 to omit debug info (#1167)
Add new debug level (4) for custom colored non-debug messages
1 parent 0af8546 commit 865f4fd

File tree

6 files changed

+77
-49
lines changed

6 files changed

+77
-49
lines changed

Client/mods/deathmatch/logic/CScriptDebugging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class CScriptDebugging
4040
~CScriptDebugging();
4141

4242
void LogCustom(lua_State* luaVM, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, const char* szFormat, ...);
43+
void LogDebug(lua_State* luaVM, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, const char* szFormat, ...);
4344
void LogInformation(lua_State* luaVM, const char* szFormat, ...);
4445
void LogWarning(lua_State* luaVM, const char* szFormat, ...);
4546
void LogError(lua_State* luaVM, const char* szFormat, ...);

Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Output.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,16 @@ int CLuaFunctionDefs::OutputClientDebugString(lua_State* luaVM)
136136
CScriptArgReader argStream(luaVM);
137137
argStream.ReadAnyAsString(strText);
138138
argStream.ReadNumber(uiLevel, 3);
139-
argStream.ReadNumber(ucRed, 255);
140-
argStream.ReadNumber(ucGreen, 255);
141-
argStream.ReadNumber(ucBlue, 255);
139+
140+
if (uiLevel == 0 || uiLevel == 4)
141+
{
142+
argStream.ReadNumber(ucRed, 255);
143+
argStream.ReadNumber(ucGreen, 255);
144+
argStream.ReadNumber(ucBlue, 255);
145+
}
142146

143147
// Too big level?
144-
if (uiLevel > 3)
148+
if (uiLevel > 4)
145149
{
146150
argStream.SetCustomError("Bad level argument");
147151
}
@@ -164,10 +168,14 @@ int CLuaFunctionDefs::OutputClientDebugString(lua_State* luaVM)
164168
{
165169
m_pScriptDebugging->LogInformation(luaVM, "%s", strText.c_str());
166170
}
167-
else if (uiLevel == 0)
171+
else if (uiLevel == 4)
168172
{
169173
m_pScriptDebugging->LogCustom(luaVM, ucRed, ucGreen, ucBlue, "%s", strText.c_str());
170174
}
175+
else if (uiLevel == 0)
176+
{
177+
m_pScriptDebugging->LogDebug(luaVM, ucRed, ucGreen, ucBlue, "%s", strText.c_str());
178+
}
171179

172180
// Success
173181
lua_pushboolean(luaVM, true);

Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.Util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ int CLuaFunctionDefs::DownloadFile(lua_State* luaVM)
373373
}
374374
}
375375
}
376-
m_pScriptDebugging->LogCustom(luaVM, 255, 255, 255, "%s: File doesn't exist", lua_tostring(luaVM, lua_upvalueindex(1)));
376+
m_pScriptDebugging->LogCustom(luaVM, SString("%s: File doesn't exist", lua_tostring(luaVM, lua_upvalueindex(1))));
377377
}
378378
else
379379
{

Server/mods/deathmatch/logic/CScriptDebugging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class CScriptDebugging
4242
void ClearPlayers();
4343

4444
void LogCustom(lua_State* luaVM, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, const char* szFormat, ...);
45+
void LogDebug(lua_State* luaVM, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, const char* szFormat, ...);
4546
void LogInformation(lua_State* luaVM, const char* szFormat, ...);
4647
void LogWarning(lua_State* luaVM, const char* szFormat, ...);
4748
void LogError(lua_State* luaVM, const char* szFormat, ...);

Server/mods/deathmatch/logic/lua/CLuaFunctionDefs.Server.cpp

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,18 @@ int CLuaFunctionDefs::OutputDebugString(lua_State* luaVM)
214214
argStream.ReadAnyAsString(strMessage);
215215
argStream.ReadNumber(uiLevel, 3);
216216

217-
if (uiLevel == 0)
217+
if (uiLevel == 0 || uiLevel == 4)
218218
{
219-
argStream.ReadNumber(ucR, 0xFF);
220-
argStream.ReadNumber(ucG, 0xFF);
221-
argStream.ReadNumber(ucB, 0xFF);
219+
argStream.ReadNumber(ucR, 255);
220+
argStream.ReadNumber(ucG, 255);
221+
argStream.ReadNumber(ucB, 255);
222222
}
223223

224224
if (!argStream.HasErrors())
225225
{
226-
if (uiLevel > 3)
226+
if (uiLevel > 4)
227227
{
228-
m_pScriptDebugging->LogWarning(luaVM, "Bad level argument sent to %s (0-3)", lua_tostring(luaVM, lua_upvalueindex(1)));
228+
m_pScriptDebugging->LogWarning(luaVM, "Bad level argument sent to %s (0-4)", lua_tostring(luaVM, lua_upvalueindex(1)));
229229

230230
lua_pushboolean(luaVM, false);
231231
return 1;
@@ -243,10 +243,14 @@ int CLuaFunctionDefs::OutputDebugString(lua_State* luaVM)
243243
{
244244
m_pScriptDebugging->LogInformation(luaVM, "%s", strMessage.c_str());
245245
}
246-
else if (uiLevel == 0)
246+
else if (uiLevel == 4)
247247
{
248248
m_pScriptDebugging->LogCustom(luaVM, ucR, ucG, ucB, "%s", strMessage.c_str());
249249
}
250+
else if (uiLevel == 0)
251+
{
252+
m_pScriptDebugging->LogDebug(luaVM, ucR, ucG, ucB, "%s", strMessage.c_str());
253+
}
250254
lua_pushboolean(luaVM, true);
251255
return 1;
252256
}
@@ -365,38 +369,38 @@ int CLuaFunctionDefs::ExecuteCommandHandler(lua_State* luaVM)
365369
return 1;
366370
}
367371

368-
int CLuaFunctionDefs::GetCommandHandlers(lua_State* luaVM)
369-
{
370-
// table getCommandHandlers ( [ resource sourceResource ] );
371-
CResource* pResource = nullptr;
372-
373-
CScriptArgReader argStream(luaVM);
374-
375-
if (!argStream.NextIsNil() && !argStream.NextIsNone())
376-
argStream.ReadUserData(pResource);
377-
378-
if (argStream.HasErrors())
379-
{
380-
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
381-
lua_pushnil(luaVM);
382-
return 1;
383-
}
384-
385-
if (pResource)
386-
{
387-
CLuaMain* pLuaMain = pResource->GetVirtualMachine();
388-
389-
if (pLuaMain)
390-
m_pRegisteredCommands->GetCommands(luaVM, pLuaMain);
391-
else
392-
lua_newtable(luaVM);
393-
}
394-
else
395-
{
396-
m_pRegisteredCommands->GetCommands(luaVM);
397-
}
398-
399-
return 1;
372+
int CLuaFunctionDefs::GetCommandHandlers(lua_State* luaVM)
373+
{
374+
// table getCommandHandlers ( [ resource sourceResource ] );
375+
CResource* pResource = nullptr;
376+
377+
CScriptArgReader argStream(luaVM);
378+
379+
if (!argStream.NextIsNil() && !argStream.NextIsNone())
380+
argStream.ReadUserData(pResource);
381+
382+
if (argStream.HasErrors())
383+
{
384+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
385+
lua_pushnil(luaVM);
386+
return 1;
387+
}
388+
389+
if (pResource)
390+
{
391+
CLuaMain* pLuaMain = pResource->GetVirtualMachine();
392+
393+
if (pLuaMain)
394+
m_pRegisteredCommands->GetCommands(luaVM, pLuaMain);
395+
else
396+
lua_newtable(luaVM);
397+
}
398+
else
399+
{
400+
m_pRegisteredCommands->GetCommands(luaVM);
401+
}
402+
403+
return 1;
400404
}
401405

402406
int CLuaFunctionDefs::OutputServerLog(lua_State* luaVM)

Shared/mods/deathmatch/logic/CScriptDebugging.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ void CScriptDebugging::LogCustom(lua_State* luaVM, unsigned char ucRed, unsigned
5555
VSNPRINTF(szBuffer, MAX_STRING_LENGTH, szFormat, marker);
5656
va_end(marker);
5757

58+
SLuaDebugInfo luaDebugInfo;
59+
LogString("", luaDebugInfo, szBuffer, 0, ucRed, ucGreen, ucBlue);
60+
}
61+
62+
void CScriptDebugging::LogDebug(lua_State* luaVM, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue, const char* szFormat, ...)
63+
{
64+
assert(szFormat);
65+
66+
// Compose the formatted message
67+
char szBuffer[MAX_STRING_LENGTH];
68+
va_list marker;
69+
va_start(marker, szFormat);
70+
VSNPRINTF(szBuffer, MAX_STRING_LENGTH, szFormat, marker);
71+
va_end(marker);
72+
5873
LogString("", GetLuaDebugInfo(luaVM), szBuffer, 0, ucRed, ucGreen, ucBlue);
5974
}
6075

@@ -158,11 +173,10 @@ void CScriptDebugging::LogCustom(lua_State* luaVM, const char* szMessage)
158173
void CScriptDebugging::LogString(const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage, unsigned int uiMinimumDebugLevel,
159174
unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue)
160175
{
161-
SString strText = ComposeErrorMessage(szPrePend, luaDebugInfo, szMessage);
176+
SString strText = SString("%s%s", szPrePend, szMessage);
162177

163-
// Create a different message if type is "INFO"
164-
if (uiMinimumDebugLevel > 2)
165-
strText = SString("%s%s", szPrePend, szMessage);
178+
if (luaDebugInfo.infoType != DEBUG_INFO_NONE && uiMinimumDebugLevel <= 2)
179+
strText = ComposeErrorMessage(szPrePend, luaDebugInfo, szMessage);
166180

167181
switch (uiMinimumDebugLevel)
168182
{

0 commit comments

Comments
 (0)