Skip to content

Commit 98423bb

Browse files
committed
Move CScriptDebugging::LogString to the shared file
1 parent a0ecd32 commit 98423bb

File tree

5 files changed

+80
-130
lines changed

5 files changed

+80
-130
lines changed

Client/mods/deathmatch/logic/CScriptDebugging.cpp

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ CScriptDebugging::CScriptDebugging ( CLuaManager* pLuaManager )
2323
m_pLuaManager = pLuaManager;
2424
m_uiLogFileLevel = 0;
2525
m_pLogFile = NULL;
26-
m_bTriggeringOnClientDebugMessage = false;
26+
m_bTriggeringMessageEvent = false;
2727
m_flushTimerHandle = NULL;
2828
}
2929

@@ -125,68 +125,6 @@ bool CScriptDebugging::SetLogfile ( const char* szFilename, unsigned int uiLevel
125125
return false;
126126
}
127127

128-
void CScriptDebugging::LogString ( const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage, unsigned int uiMinimumDebugLevel, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue )
129-
{
130-
SString strText = ComposeErrorMessage( szPrePend, luaDebugInfo, szMessage );
131-
132-
// Create a different message if type is "INFO"
133-
if ( uiMinimumDebugLevel > 2 )
134-
strText = SString ( "%s%s", szPrePend, szMessage );
135-
136-
switch ( uiMinimumDebugLevel )
137-
{
138-
case 1:
139-
ucRed = 255, ucGreen = 0, ucBlue = 0;
140-
break;
141-
case 2:
142-
ucRed = 255, ucGreen = 128, ucBlue = 0;
143-
break;
144-
case 3:
145-
ucRed = 0, ucGreen = 255, ucBlue = 0;
146-
break;
147-
default:
148-
break;
149-
}
150-
151-
if ( !m_bTriggeringOnClientDebugMessage )
152-
{
153-
m_bTriggeringOnClientDebugMessage = true;
154-
155-
// Prepare onClientDebugMessage
156-
CLuaArguments Arguments;
157-
Arguments.PushString ( szMessage );
158-
Arguments.PushNumber ( uiMinimumDebugLevel );
159-
160-
// Push the file name (if any)
161-
if ( !luaDebugInfo.strFile.empty() )
162-
Arguments.PushString ( luaDebugInfo.strFile );
163-
else
164-
Arguments.PushNil ( );
165-
166-
// Push the line (if any)
167-
if ( luaDebugInfo.iLine != INVALID_LINE_NUMBER )
168-
Arguments.PushNumber ( luaDebugInfo.iLine );
169-
else
170-
Arguments.PushNil ( );
171-
172-
// Push the colors
173-
Arguments.PushNumber ( ucRed );
174-
Arguments.PushNumber ( ucGreen );
175-
Arguments.PushNumber ( ucBlue );
176-
177-
// Call onClientDebugMessage
178-
g_pClientGame->GetRootEntity ( )->CallEvent ( "onClientDebugMessage", Arguments, false );
179-
180-
m_bTriggeringOnClientDebugMessage = false;
181-
}
182-
183-
m_DuplicateLineFilter.AddLine( { strText, uiMinimumDebugLevel, ucRed, ucGreen, ucBlue } );
184-
if ( g_pCore->GetCVars ()->GetValue < bool > ( "filter_duplicate_log_lines" ) == false )
185-
m_DuplicateLineFilter.Flush();
186-
UpdateLogOutput();
187-
}
188-
189-
190128
void CScriptDebugging::UpdateLogOutput( void )
191129
{
192130
SLogLine line;

Client/mods/deathmatch/logic/CScriptDebugging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class CScriptDebugging
8686
private:
8787
CLuaManager* m_pLuaManager;
8888
unsigned int m_uiLogFileLevel;
89-
bool m_bTriggeringOnClientDebugMessage;
89+
bool m_bTriggeringMessageEvent;
9090
SLuaDebugInfo m_SavedLuaDebugInfo;
9191
std::list < CLuaMain* > m_LuaMainStack;
9292
HANDLE m_flushTimerHandle;

Server/mods/deathmatch/logic/CScriptDebugging.cpp

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ CScriptDebugging::CScriptDebugging ( CLuaManager* pLuaManager )
2222
m_uiLogFileLevel = 0;
2323
m_uiHtmlLogLevel = 0;
2424
m_pLogFile = NULL;
25-
m_bTriggeringOnDebugMessage = false;
25+
m_bTriggeringMessageEvent = false;
2626
}
2727

2828
CScriptDebugging::~CScriptDebugging ( void )
@@ -118,70 +118,6 @@ bool CScriptDebugging::SetLogfile ( const char* szFilename, unsigned int uiLevel
118118
return false;
119119
}
120120

121-
void CScriptDebugging::LogString ( const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage, unsigned int uiMinimumDebugLevel, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue )
122-
{
123-
SString strText = ComposeErrorMessage( szPrePend, luaDebugInfo, szMessage );
124-
125-
// Create a different message if type is "INFO"
126-
if ( uiMinimumDebugLevel > 2 )
127-
strText = SString ( "%s%s", szPrePend, szMessage );
128-
129-
switch ( uiMinimumDebugLevel )
130-
{
131-
case 1:
132-
ucRed = 255, ucGreen = 0, ucBlue = 0;
133-
break;
134-
case 2:
135-
ucRed = 255, ucGreen = 128, ucBlue = 0;
136-
break;
137-
case 3:
138-
ucRed = 0, ucGreen = 255, ucBlue = 0;
139-
break;
140-
default:
141-
break;
142-
}
143-
144-
// Check whether onDebugMessage is currently being triggered
145-
if ( !m_bTriggeringOnDebugMessage )
146-
{
147-
// Make sure the state of onDebugMessage being triggered can be retrieved later
148-
m_bTriggeringOnDebugMessage = true;
149-
150-
// Prepare onDebugMessage
151-
CLuaArguments Arguments;
152-
Arguments.PushString ( szMessage );
153-
Arguments.PushNumber ( uiMinimumDebugLevel );
154-
155-
// Push the file name (if any)
156-
if ( !luaDebugInfo.strFile.empty() )
157-
Arguments.PushString ( luaDebugInfo.strFile );
158-
else
159-
Arguments.PushNil ( );
160-
161-
// Push the line (if any)
162-
if ( luaDebugInfo.iLine != INVALID_LINE_NUMBER )
163-
Arguments.PushNumber ( luaDebugInfo.iLine );
164-
else
165-
Arguments.PushNil ( );
166-
167-
// Push the colors
168-
Arguments.PushNumber ( ucRed );
169-
Arguments.PushNumber ( ucGreen );
170-
Arguments.PushNumber ( ucBlue );
171-
172-
// Call onDebugMessage
173-
g_pGame->GetMapManager ( )->GetRootElement ( )->CallEvent ( "onDebugMessage", Arguments );
174-
175-
// Reset trigger state, so onDebugMessage can be called again at a later moment
176-
m_bTriggeringOnDebugMessage = false;
177-
}
178-
179-
m_DuplicateLineFilter.AddLine( { strText, uiMinimumDebugLevel, ucRed, ucGreen, ucBlue } );
180-
if ( g_pGame->GetConfig()->GetFilterDuplicateLogLinesEnabled() == false )
181-
m_DuplicateLineFilter.Flush();
182-
UpdateLogOutput();
183-
}
184-
185121
void CScriptDebugging::UpdateLogOutput( void )
186122
{
187123
SLogLine line;

Server/mods/deathmatch/logic/CScriptDebugging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class CScriptDebugging
8787
unsigned int m_uiHtmlLogLevel;
8888
FILE* m_pLogFile;
8989
list < class CPlayer* > m_Players;
90-
bool m_bTriggeringOnDebugMessage;
90+
bool m_bTriggeringMessageEvent;
9191
SLuaDebugInfo m_SavedLuaDebugInfo;
9292
std::list < CLuaMain* > m_LuaMainStack;
9393
CDuplicateLineFilter < SLogLine > m_DuplicateLineFilter;

Shared/mods/deathmatch/logic/CScriptDebugging.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,82 @@ void CScriptDebugging::LogCustom (lua_State* luaVM, const char* szMessage)
155155
LogWarning (luaVM, "%s", szMessage);
156156
}
157157

158+
159+
void CScriptDebugging::LogString (const char* szPrePend, const SLuaDebugInfo& luaDebugInfo, const char* szMessage, unsigned int uiMinimumDebugLevel, unsigned char ucRed, unsigned char ucGreen, unsigned char ucBlue)
160+
{
161+
SString strText = ComposeErrorMessage (szPrePend, luaDebugInfo, szMessage);
162+
163+
// Create a different message if type is "INFO"
164+
if (uiMinimumDebugLevel > 2)
165+
strText = SString ("%s%s", szPrePend, szMessage);
166+
167+
switch (uiMinimumDebugLevel)
168+
{
169+
case 1:
170+
ucRed = 255, ucGreen = 0, ucBlue = 0;
171+
break;
172+
case 2:
173+
ucRed = 255, ucGreen = 128, ucBlue = 0;
174+
break;
175+
case 3:
176+
ucRed = 0, ucGreen = 255, ucBlue = 0;
177+
break;
178+
default:
179+
break;
180+
}
181+
182+
// Check whether on(Client)DebugMessage is currently being triggered
183+
if (!m_bTriggeringMessageEvent)
184+
{
185+
// Make sure the state of on(Client)DebugMessage being triggered can be retrieved later
186+
m_bTriggeringMessageEvent = true;
187+
188+
// Prepare onDebugMessage
189+
CLuaArguments Arguments;
190+
Arguments.PushString (szMessage);
191+
Arguments.PushNumber (uiMinimumDebugLevel);
192+
193+
// Push the file name (if any)
194+
if (!luaDebugInfo.strFile.empty ())
195+
Arguments.PushString (luaDebugInfo.strFile);
196+
else
197+
Arguments.PushNil ();
198+
199+
// Push the line (if any)
200+
if (luaDebugInfo.iLine != INVALID_LINE_NUMBER)
201+
Arguments.PushNumber (luaDebugInfo.iLine);
202+
else
203+
Arguments.PushNil ();
204+
205+
// Push the colors
206+
Arguments.PushNumber (ucRed);
207+
Arguments.PushNumber (ucGreen);
208+
Arguments.PushNumber (ucBlue);
209+
210+
// Call on(Client)DebugMessage
211+
#ifdef MTA_CLIENT
212+
g_pClientGame->GetRootEntity ()->CallEvent ("onClientDebugMessage", Arguments, false);
213+
#else
214+
g_pGame->GetMapManager ()->GetRootElement ()->CallEvent ("onDebugMessage", Arguments);
215+
#endif
216+
217+
// Reset trigger state, so onDebugMessage can be called again at a later moment
218+
m_bTriggeringMessageEvent = false;
219+
}
220+
221+
m_DuplicateLineFilter.AddLine ({ strText, uiMinimumDebugLevel, ucRed, ucGreen, ucBlue });
222+
223+
#ifdef MTA_CLIENT
224+
if (g_pCore->GetCVars ()->GetValue < bool > ("filter_duplicate_log_lines") == false)
225+
#else
226+
if (g_pGame->GetConfig ()->GetFilterDuplicateLogLinesEnabled () == false)
227+
#endif
228+
{
229+
m_DuplicateLineFilter.Flush ();
230+
}
231+
UpdateLogOutput ();
232+
}
233+
158234
//
159235
// Get best debug info we possibly can from the relevent lua state
160236
//

0 commit comments

Comments
 (0)