Added the ability to override RegConsoleCommand-created commands (bug 5199, r=psychonic).

This commit is contained in:
Asher Baker 2012-11-15 17:53:11 +00:00
parent a991d327e6
commit 247fabaaf0
3 changed files with 5 additions and 52 deletions

View File

@ -559,44 +559,6 @@ bool ConCmdManager::CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmi
return false; return false;
} }
bool ConCmdManager::AddConsoleCommand(IPluginFunction *pFunction,
const char *name,
const char *description,
int flags)
{
ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags);
if (!pInfo)
{
return false;
}
CmdHook *pHook = new CmdHook();
pHook->pf = pFunction;
if (description && description[0])
{
pHook->helptext.assign(description);
}
pInfo->conhooks.push_back(pHook);
/* Add to the plugin */
CmdList *pList;
IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext());
if (!pPlugin->GetProperty("CommandList", (void **)&pList))
{
pList = new CmdList();
pPlugin->SetProperty("CommandList", pList);
}
PlCmdInfo info;
info.pInfo = pInfo;
info.type = Cmd_Console;
info.pHook = pHook;
AddToPlCmdList(pList, info);
return true;
}
bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction, bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
const char *name, const char *name,
const char *group, const char *group,
@ -658,7 +620,6 @@ bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
/* Finally, add the hook */ /* Finally, add the hook */
pInfo->conhooks.push_back(pHook); pInfo->conhooks.push_back(pHook);
pInfo->admin = *(pHook->pAdmin); pInfo->admin = *(pHook->pAdmin);
pInfo->is_admin_set = true;
/* Now add to the plugin */ /* Now add to the plugin */
CmdList *pList; CmdList *pList;
@ -803,7 +764,6 @@ void ConCmdManager::UpdateAdminCmdFlags(const char *cmd, OverrideType type, Flag
pInfo->admin = *(pHook->pAdmin); pInfo->admin = *(pHook->pAdmin);
} }
} }
pInfo->is_admin_set = true;
} }
else if (type == Override_CommandGroup) else if (type == Override_CommandGroup)
{ {
@ -837,7 +797,6 @@ void ConCmdManager::UpdateAdminCmdFlags(const char *cmd, OverrideType type, Flag
} }
} }
} }
pInfo->is_admin_set = true;
} }
} }
@ -905,7 +864,7 @@ bool ConCmdManager::LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags)
*pFlags = pInfo->admin.eflags; *pFlags = pInfo->admin.eflags;
return pInfo->is_admin_set; return true;
} }
ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *description, int flags) ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *description, int flags)
@ -942,7 +901,6 @@ ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *descri
} }
pInfo->pCmd = pCmd; pInfo->pCmd = pCmd;
pInfo->is_admin_set = false;
sm_trie_insert(m_pCmds, name, pInfo); sm_trie_insert(m_pCmds, name, pInfo);
AddToCmdList(pInfo); AddToCmdList(pInfo);
@ -995,13 +953,9 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const CCommand &co
{ {
type = "server"; type = "server";
} }
else if (cmd.type == Cmd_Console)
{
type = "console";
}
else if (cmd.type == Cmd_Admin) else if (cmd.type == Cmd_Admin)
{ {
type = "admin"; type = (cmd.pInfo->admin.eflags == 0)?"console":"admin";
} }
name = cmd.pInfo->pCmd->GetName(); name = cmd.pInfo->pCmd->GetName();
if (cmd.pHook->helptext.size()) if (cmd.pHook->helptext.size())

View File

@ -48,7 +48,6 @@ using namespace SourceHook;
enum CmdType enum CmdType
{ {
Cmd_Server, Cmd_Server,
Cmd_Console,
Cmd_Admin, Cmd_Admin,
}; };
@ -89,7 +88,6 @@ struct ConCmdInfo
List<CmdHook *> srvhooks; /**< Hooks as a server command */ List<CmdHook *> srvhooks; /**< Hooks as a server command */
List<CmdHook *> conhooks; /**< Hooks as a console command */ List<CmdHook *> conhooks; /**< Hooks as a console command */
AdminCmdInfo admin; /**< Admin info, if any */ AdminCmdInfo admin; /**< Admin info, if any */
bool is_admin_set; /**< Whether or not admin info is set */
}; };
typedef List<ConCmdInfo *> ConCmdList; typedef List<ConCmdInfo *> ConCmdList;
@ -119,7 +117,6 @@ public: //IConCommandTracker
void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe); void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe);
public: public:
bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags); bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
bool AddAdminCommand(IPluginFunction *pFunction, bool AddAdminCommand(IPluginFunction *pFunction,
const char *name, const char *name,
const char *group, const char *group,

View File

@ -722,7 +722,9 @@ static cell_t sm_RegConsoleCmd(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Invalid function id (%X)", params[2]); return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
} }
if (!g_ConCmds.AddConsoleCommand(pFunction, name, help, params[4])) CPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext());
const char *group = pPlugin->GetFilename();
if (!g_ConCmds.AddAdminCommand(pFunction, name, group, 0, help, params[4]))
{ {
return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name); return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
} }