Skip to content

Commit 5947012

Browse files
author
Sebastian Jura
authored
Fix #418: addCommandHandler returns true when it should return false in certain scenarios (#3017)
1 parent 4e0a227 commit 5947012

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

Client/mods/deathmatch/logic/CRegisteredCommands.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ bool CRegisteredCommands::AddCommand(CLuaMain* pLuaMain, const char* szKey, cons
2727
assert(pLuaMain);
2828
assert(szKey);
2929

30+
if (g_pCore->GetCommands()->Get(szKey))
31+
return false;
32+
3033
// Check if we already have this key and handler
3134
SCommand* pCommand = GetCommand(szKey, pLuaMain);
3235
if (pCommand)

Server/mods/deathmatch/logic/CMainConfig.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,8 @@ bool CMainConfig::LoadExtended()
660660
}
661661
} while (pNode);
662662

663+
RegisterCommands();
664+
663665
// Handle the <resource> nodes
664666
pNode = NULL;
665667
uiCurrentIndex = 0;
@@ -749,7 +751,11 @@ bool CMainConfig::LoadExtended()
749751

750752
CLogger::ProgressDotsEnd();
751753
CLogger::SetMinLogLevel(LOGLEVEL_LOW);
754+
return true;
755+
}
752756

757+
void CMainConfig::RegisterCommands()
758+
{
753759
// Register the commands
754760
RegisterCommand("start", CConsoleCommands::StartResource, false, "Usage: start <resource-name>\nStart a loaded resource eg: start admin");
755761
RegisterCommand("stop", CConsoleCommands::StopResource, false, "Usage: stop <resource-name>\nStop a resource eg: stop admin");
@@ -819,7 +825,6 @@ bool CMainConfig::LoadExtended()
819825
RegisterCommand("sfakelag", CConsoleCommands::FakeLag, false,
820826
"Usage: sfakelag <packet loss> <extra ping> <ping variance> [<KBPS limit>]\nOnly available if enabled in the mtaserver.conf file.\nAdds "
821827
"artificial packet loss, ping, jitter and bandwidth limits to the server-client connections.");
822-
return true;
823828
}
824829

825830
bool CMainConfig::Save()

Server/mods/deathmatch/logic/CMainConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CMainConfig : public CXMLConfig
4747

4848
bool Load();
4949
bool LoadExtended();
50+
void RegisterCommands();
5051
bool Save();
5152

5253
const std::string& GetServerName() { return m_strServerName; };

Server/mods/deathmatch/logic/CRegisteredCommands.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "CClient.h"
1919
#include "CConsoleClient.h"
2020
#include "CPlayer.h"
21+
#include "CGame.h"
2122

2223
CRegisteredCommands::CRegisteredCommands(CAccessControlListManager* pACLManager)
2324
{
@@ -35,6 +36,9 @@ bool CRegisteredCommands::AddCommand(CLuaMain* pLuaMain, const char* szKey, cons
3536
assert(pLuaMain);
3637
assert(szKey);
3738

39+
if (g_pGame->GetConsole()->GetCommand(szKey))
40+
return false;
41+
3842
// Check if we already have this key and handler
3943
SCommand* pCommand = GetCommand(szKey, pLuaMain);
4044

0 commit comments

Comments
 (0)