Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #418: addCommandHandler: Returning False for Existing Built-in Commands #3017

Merged
merged 1 commit into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CRegisteredCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ bool CRegisteredCommands::AddCommand(CLuaMain* pLuaMain, const char* szKey, cons
assert(pLuaMain);
assert(szKey);

if (g_pCore->GetCommands()->Get(szKey))
return false;

// Check if we already have this key and handler
SCommand* pCommand = GetCommand(szKey, pLuaMain);
if (pCommand)
Expand Down
7 changes: 6 additions & 1 deletion Server/mods/deathmatch/logic/CMainConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ bool CMainConfig::LoadExtended()
}
} while (pNode);

RegisterCommands();

// Handle the <resource> nodes
pNode = NULL;
uiCurrentIndex = 0;
Expand Down Expand Up @@ -749,7 +751,11 @@ bool CMainConfig::LoadExtended()

CLogger::ProgressDotsEnd();
CLogger::SetMinLogLevel(LOGLEVEL_LOW);
return true;
}

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

bool CMainConfig::Save()
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CMainConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CMainConfig : public CXMLConfig

bool Load();
bool LoadExtended();
void RegisterCommands();
bool Save();

const std::string& GetServerName() { return m_strServerName; };
Expand Down
4 changes: 4 additions & 0 deletions Server/mods/deathmatch/logic/CRegisteredCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "CClient.h"
#include "CConsoleClient.h"
#include "CPlayer.h"
#include "CGame.h"

CRegisteredCommands::CRegisteredCommands(CAccessControlListManager* pACLManager)
{
Expand All @@ -35,6 +36,9 @@ bool CRegisteredCommands::AddCommand(CLuaMain* pLuaMain, const char* szKey, cons
assert(pLuaMain);
assert(szKey);

if (g_pGame->GetConsole()->GetCommand(szKey))
return false;

// Check if we already have this key and handler
SCommand* pCommand = GetCommand(szKey, pLuaMain);

Expand Down