Skip to content

Commit 82b5f22

Browse files
committed
Support script debugging and prevent duplicate command registration
1 parent f7fcde0 commit 82b5f22

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

Client/mods/deathmatch/logic/CRegisteredCommands.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*****************************************************************************/
1010

1111
#include "StdInc.h"
12+
#include "luadefs/CLuaDefs.h"
1213

1314
using std::list;
1415

@@ -27,6 +28,12 @@ bool CRegisteredCommands::AddCommand(CLuaMain* pLuaMain, const char* szKey, cons
2728
assert(pLuaMain);
2829
assert(szKey);
2930

31+
if (CommandExists(szKey, NULL))
32+
{
33+
CLuaDefs::m_pScriptDebugging->LogWarning(pLuaMain->GetVM(), "addCommandHandler: Attempt to register duplicate command '%s'", szKey);
34+
return false;
35+
}
36+
3037
// Check if we already have this key and handler
3138
SCommand* pCommand = GetCommand(szKey, pLuaMain);
3239
if (pCommand)

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ bool CGame::Start(int iArgumentCount, char* szArguments[])
617617
m_pACLManager = new CAccessControlListManager;
618618
m_pHqComms = new CHqComms;
619619

620-
m_pRegisteredCommands = new CRegisteredCommands(m_pACLManager);
620+
m_pRegisteredCommands = new CRegisteredCommands(m_pACLManager, m_pScriptDebugging);
621621
m_pLuaManager = new CLuaManager(m_pObjectManager, m_pPlayerManager, m_pVehicleManager, m_pBlipManager, m_pRadarAreaManager, m_pRegisteredCommands,
622622
m_pMapManager, &m_Events);
623623
m_pConsole = new CConsole(m_pBlipManager, m_pMapManager, m_pPlayerManager, m_pRegisteredCommands, m_pVehicleManager, m_pBanManager, m_pACLManager);

Server/mods/deathmatch/logic/CRegisteredCommands.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
#include "CClient.h"
1919
#include "CConsoleClient.h"
2020
#include "CPlayer.h"
21+
#include "CScriptDebugging.h"
2122

22-
CRegisteredCommands::CRegisteredCommands(CAccessControlListManager* pACLManager)
23+
CRegisteredCommands::CRegisteredCommands(CAccessControlListManager* pACLManager, CScriptDebugging* pScriptDebugging)
2324
{
2425
m_pACLManager = pACLManager;
26+
m_pScriptDebugging = pScriptDebugging;
2527
m_bIteratingList = false;
2628
}
2729

@@ -35,9 +37,15 @@ bool CRegisteredCommands::AddCommand(CLuaMain* pLuaMain, const char* szKey, cons
3537
assert(pLuaMain);
3638
assert(szKey);
3739

40+
if (CommandExists(szKey, NULL))
41+
{
42+
m_pScriptDebugging->LogWarning(pLuaMain->GetVM(), "addCommandHandler: Attempt to register duplicate command '%s'", szKey);
43+
return false;
44+
}
45+
3846
// Check if we already have this key and handler
3947
SCommand* pCommand = GetCommand(szKey, pLuaMain);
40-
48+
4149
if (pCommand && iLuaFunction == pCommand->iLuaFunction)
4250
return false;
4351

Server/mods/deathmatch/logic/CRegisteredCommands.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CRegisteredCommands
3030
};
3131

3232
public:
33-
CRegisteredCommands(class CAccessControlListManager* pACLManager);
33+
CRegisteredCommands(class CAccessControlListManager* pACLManager, class CScriptDebugging* pScriptDebugging);
3434
~CRegisteredCommands();
3535

3636
bool AddCommand(class CLuaMain* pLuaMain, const char* szKey, const CLuaFunctionRef& iLuaFunction, bool bRestricted, bool bCaseSensitive);
@@ -56,4 +56,5 @@ class CRegisteredCommands
5656
bool m_bIteratingList;
5757

5858
class CAccessControlListManager* m_pACLManager;
59+
class CScriptDebugging* m_pScriptDebugging;
5960
};

0 commit comments

Comments
 (0)