Replace the AddRootConsoleCommand API to not expose internal structures.

This commit is contained in:
David Anderson 2015-08-27 22:59:04 -04:00
parent e992c33f35
commit 9d805ea9fb
16 changed files with 83 additions and 90 deletions

View File

@ -66,7 +66,7 @@ ConCmdManager::~ConCmdManager()
void ConCmdManager::OnSourceModAllInitialized() void ConCmdManager::OnSourceModAllInitialized()
{ {
scripts->AddPluginsListener(this); scripts->AddPluginsListener(this);
g_RootMenu.AddRootConsoleCommand("cmds", "List console commands", this); g_RootMenu.AddRootConsoleCommand3("cmds", "List console commands", this);
SH_ADD_HOOK(IServerGameClients, SetCommandClient, serverClients, SH_MEMBER(this, &ConCmdManager::SetCommandClient), false); SH_ADD_HOOK(IServerGameClients, SetCommandClient, serverClients, SH_MEMBER(this, &ConCmdManager::SetCommandClient), false);
} }
@ -634,11 +634,11 @@ ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *descri
return pInfo; return pInfo;
} }
void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command) void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
{ {
if (command.ArgC() >= 3) if (command->ArgC() >= 3)
{ {
const char *text = command.Arg(2); const char *text = command->Arg(2);
IPlugin *pPlugin = scripts->FindPluginByConsoleArg(text); IPlugin *pPlugin = scripts->FindPluginByConsoleArg(text);

View File

@ -131,7 +131,7 @@ public: //SMGlobalClass
public: //IPluginsListener public: //IPluginsListener
void OnPluginDestroyed(IPlugin *plugin); void OnPluginDestroyed(IPlugin *plugin);
public: //IRootConsoleCommand public: //IRootConsoleCommand
void OnRootConsoleCommand(const char *cmdname, const CCommand &command); void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override;
public: //IConCommandTracker 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:

View File

@ -134,7 +134,7 @@ void ConVarManager::OnSourceModAllInitialized()
scripts->AddPluginsListener(this); scripts->AddPluginsListener(this);
/* Add the 'convars' option to the 'sm' console command */ /* Add the 'convars' option to the 'sm' console command */
g_RootMenu.AddRootConsoleCommand("cvars", "View convars created by a plugin", this); g_RootMenu.AddRootConsoleCommand3("cvars", "View convars created by a plugin", this);
} }
void ConVarManager::OnSourceModShutdown() void ConVarManager::OnSourceModShutdown()
@ -340,19 +340,19 @@ bool ConVarManager::GetHandleApproxSize(HandleType_t type, void *object, unsigne
return true; return true;
} }
void ConVarManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command) void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
{ {
int argcount = command.ArgC(); int argcount = command->ArgC();
if (argcount >= 3) if (argcount >= 3)
{ {
bool wantReset = false; bool wantReset = false;
/* Get plugin index that was passed */ /* Get plugin index that was passed */
const char *arg = command.Arg(2); const char *arg = command->Arg(2);
if (argcount >= 4 && strcmp(arg, "reset") == 0) if (argcount >= 4 && strcmp(arg, "reset") == 0)
{ {
wantReset = true; wantReset = true;
arg = command.Arg(3); arg = command->Arg(3);
} }
/* Get plugin object */ /* Get plugin object */

View File

@ -107,7 +107,7 @@ public: // IHandleTypeDispatch
public: // IPluginsListener public: // IPluginsListener
void OnPluginUnloaded(IPlugin *plugin); void OnPluginUnloaded(IPlugin *plugin);
public: //IRootConsoleCommand public: //IRootConsoleCommand
void OnRootConsoleCommand(const char *cmdname, const CCommand &command); void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override;
public: //IConCommandTracker 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: //IClientListener public: //IClientListener

View File

@ -118,7 +118,7 @@ void CheckAndFinalizeConfigs()
void CoreConfig::OnSourceModAllInitialized() void CoreConfig::OnSourceModAllInitialized()
{ {
g_RootMenu.AddRootConsoleCommand("config", "Set core configuration options", this); g_RootMenu.AddRootConsoleCommand3("config", "Set core configuration options", this);
g_pOnServerCfg = forwardsys->CreateForward("OnServerCfg", ET_Ignore, 0, NULL); g_pOnServerCfg = forwardsys->CreateForward("OnServerCfg", ET_Ignore, 0, NULL);
g_pOnConfigsExecuted = forwardsys->CreateForward("OnConfigsExecuted", ET_Ignore, 0, NULL); g_pOnConfigsExecuted = forwardsys->CreateForward("OnConfigsExecuted", ET_Ignore, 0, NULL);
g_pOnAutoConfigsBuffered = forwardsys->CreateForward("OnAutoConfigsBuffered", ET_Ignore, 0, NULL); g_pOnAutoConfigsBuffered = forwardsys->CreateForward("OnAutoConfigsBuffered", ET_Ignore, 0, NULL);
@ -184,13 +184,13 @@ void CoreConfig::OnSourceModLevelChange(const char *mapName)
g_bGotTrigger = false; g_bGotTrigger = false;
} }
void CoreConfig::OnRootConsoleCommand(const char *cmdname, const CCommand &command) void CoreConfig::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
{ {
int argcount = command.ArgC(); int argcount = command->ArgC();
if (argcount >= 4) if (argcount >= 4)
{ {
const char *option = command.Arg(2); const char *option = command->Arg(2);
const char *value = command.Arg(3); const char *value = command->Arg(3);
char error[255]; char error[255];
@ -207,7 +207,7 @@ void CoreConfig::OnRootConsoleCommand(const char *cmdname, const CCommand &comma
return; return;
} else if (argcount >= 3) { } else if (argcount >= 3) {
const char *option = command.Arg(2); const char *option = command->Arg(2);
const char *value = GetCoreConfigValue(option); const char *value = GetCoreConfigValue(option);

View File

@ -55,7 +55,7 @@ public: // SMGlobalClass
public: // ITextListener_SMC public: // ITextListener_SMC
SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value); SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
public: // IRootConsoleCommand public: // IRootConsoleCommand
void OnRootConsoleCommand(const char *cmdname, const CCommand &command); void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override;
public: public:
/** /**
* Initializes CoreConfig by reading from core.cfg file * Initializes CoreConfig by reading from core.cfg file

View File

@ -512,7 +512,7 @@ void CExtensionManager::OnSourceModAllInitialized()
{ {
g_ExtType = g_ShareSys.CreateIdentType("EXTENSION"); g_ExtType = g_ShareSys.CreateIdentType("EXTENSION");
pluginsys->AddPluginsListener(this); pluginsys->AddPluginsListener(this);
rootmenu->AddRootConsoleCommand("exts", "Manage extensions", this); rootmenu->AddRootConsoleCommand3("exts", "Manage extensions", this);
g_ShareSys.AddInterface(NULL, this); g_ShareSys.AddInterface(NULL, this);
} }
@ -929,12 +929,12 @@ void CExtensionManager::AddDependency(IExtension *pSource, const char *file, boo
} }
} }
void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command) void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
{ {
int argcount = smcore.Argc(command); int argcount = command->ArgC();
if (argcount >= 3) if (argcount >= 3)
{ {
const char *cmd = smcore.Arg(command, 2); const char *cmd = command->Arg(2);
if (strcmp(cmd, "list") == 0) if (strcmp(cmd, "list") == 0)
{ {
List<CExtension *>::iterator iter; List<CExtension *>::iterator iter;
@ -990,7 +990,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand
return; return;
} }
const char *filename = smcore.Arg(command, 3); const char *filename = command->Arg(3);
char path[PLATFORM_MAX_PATH]; char path[PLATFORM_MAX_PATH];
char error[256]; char error[256];
@ -1021,7 +1021,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand
return; return;
} }
const char *sId = smcore.Arg(command, 3); const char *sId = command->Arg(3);
unsigned int id = atoi(sId); unsigned int id = atoi(sId);
if (id <= 0) if (id <= 0)
{ {
@ -1106,7 +1106,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand
return; return;
} }
const char *arg = smcore.Arg(command, 3); const char *arg = command->Arg(3);
unsigned int num = atoi(arg); unsigned int num = atoi(arg);
CExtension *pExt = FindByOrder(num); CExtension *pExt = FindByOrder(num);
@ -1118,7 +1118,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand
if (argcount > 4 && pExt->unload_code) if (argcount > 4 && pExt->unload_code)
{ {
const char *unload = smcore.Arg(command, 4); const char *unload = command->Arg(4);
if (pExt->unload_code == (unsigned)atoi(unload)) if (pExt->unload_code == (unsigned)atoi(unload))
{ {
char filename[PLATFORM_MAX_PATH]; char filename[PLATFORM_MAX_PATH];
@ -1223,7 +1223,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const CCommand
return; return;
} }
const char *arg = smcore.Arg(command, 3); const char *arg = command->Arg(3);
unsigned int num = atoi(arg); unsigned int num = atoi(arg);
CExtension *pExt = FindByOrder(num); CExtension *pExt = FindByOrder(num);

View File

@ -161,7 +161,7 @@ public: //IExtensionManager
public: //IPluginsListener public: //IPluginsListener
void OnPluginDestroyed(IPlugin *plugin); void OnPluginDestroyed(IPlugin *plugin);
public: //IRootConsoleCommand public: //IRootConsoleCommand
void OnRootConsoleCommand(const char *cmdname, const CCommand &command); void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override;
public: public:
IExtension *LoadAutoExtension(const char *path, bool bErrorOnMissing=true); IExtension *LoadAutoExtension(const char *path, bool bErrorOnMissing=true);
void BindDependency(IExtension *pOwner, IfaceInfo *pInfo); void BindDependency(IExtension *pOwner, IfaceInfo *pInfo);

View File

@ -900,8 +900,6 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **aResult, const char *path, bool de
if (m_LoadingLocked) if (m_LoadingLocked)
return LoadRes_NeverLoad; return LoadRes_NeverLoad;
int err;
/** /**
* Does this plugin already exist? * Does this plugin already exist?
*/ */
@ -1819,7 +1817,7 @@ void CPluginManager::OnSourceModAllInitialized()
g_PluginType = handlesys->CreateType("Plugin", this, 0, NULL, &sec, m_MyIdent, NULL); g_PluginType = handlesys->CreateType("Plugin", this, 0, NULL, &sec, m_MyIdent, NULL);
g_PluginIdent = g_ShareSys.CreateIdentType("PLUGIN"); g_PluginIdent = g_ShareSys.CreateIdentType("PLUGIN");
rootmenu->AddRootConsoleCommand("plugins", "Manage Plugins", this); rootmenu->AddRootConsoleCommand3("plugins", "Manage Plugins", this);
g_ShareSys.AddInterface(NULL, GetOldAPI()); g_ShareSys.AddInterface(NULL, GetOldAPI());
@ -1941,12 +1939,12 @@ static inline bool IS_STR_FILLED(const char *text)
return text[0] != '\0'; return text[0] != '\0';
} }
void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command) void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
{ {
int argcount = smcore.Argc(command); int argcount = command->ArgC();
if (argcount >= 3) if (argcount >= 3)
{ {
const char *cmd = smcore.Arg(command, 2); const char *cmd = command->Arg(2);
if (strcmp(cmd, "list") == 0) if (strcmp(cmd, "list") == 0)
{ {
char buffer[256]; char buffer[256];
@ -2035,7 +2033,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
char error[128]; char error[128];
bool wasloaded; bool wasloaded;
const char *filename = smcore.Arg(command, 3); const char *filename = command->Arg(3);
char pluginfile[256]; char pluginfile[256];
const char *ext = libsys->GetFileExtension(filename) ? "" : ".smx"; const char *ext = libsys->GetFileExtension(filename) ? "" : ".smx";
@ -2070,7 +2068,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
CPlugin *pl; CPlugin *pl;
char *end; char *end;
const char *arg = smcore.Arg(command, 3); const char *arg = command->Arg(3);
int id = strtol(arg, &end, 10); int id = strtol(arg, &end, 10);
if (*end == '\0') if (*end == '\0')
@ -2160,7 +2158,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
CPlugin *pl; CPlugin *pl;
char *end; char *end;
const char *arg = smcore.Arg(command, 3); const char *arg = command->Arg(3);
int id = strtol(arg, &end, 10); int id = strtol(arg, &end, 10);
if (*end == '\0') if (*end == '\0')
@ -2291,7 +2289,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const CCommand &c
CPlugin *pl; CPlugin *pl;
char *end; char *end;
const char *arg = smcore.Arg(command, 3); const char *arg = command->Arg(3);
int id = strtol(arg, &end, 10); int id = strtol(arg, &end, 10);
if (*end == '\0') if (*end == '\0')

View File

@ -347,7 +347,7 @@ public: //IHandleTypeDispatch
void OnHandleDestroy(HandleType_t type, void *object); void OnHandleDestroy(HandleType_t type, void *object);
bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize); bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize);
public: //IRootConsoleCommand public: //IRootConsoleCommand
void OnRootConsoleCommand(const char *cmdname, const CCommand &command); void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command) override;
public: public:
/** /**
* Loads all plugins not yet loaded * Loads all plugins not yet loaded

View File

@ -40,7 +40,7 @@ ProfileToolManager::ProfileToolManager()
void void
ProfileToolManager::OnSourceModAllInitialized() ProfileToolManager::OnSourceModAllInitialized()
{ {
rootmenu->AddRootConsoleCommand2("prof", "Profiling", this); rootmenu->AddRootConsoleCommand3("prof", "Profiling", this);
} }
void void
@ -95,7 +95,7 @@ ProfileToolManager::StartFromConsole(IProfilingTool *tool)
} }
void void
ProfileToolManager::OnRootConsoleCommand2(const char *cmdname, const ICommandArgs *args) ProfileToolManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *args)
{ {
if (tools_.length() == 0) { if (tools_.length() == 0) {
rootmenu->ConsolePrint("No profiling tools are enabled."); rootmenu->ConsolePrint("No profiling tools are enabled.");

View File

@ -48,7 +48,7 @@ public:
void OnSourceModShutdown() override; void OnSourceModShutdown() override;
// IRootConsoleCommand // IRootConsoleCommand
void OnRootConsoleCommand2(const char *cmdname, const ICommandArgs *args) override; void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *args) override;
void RegisterTool(IProfilingTool *tool) { void RegisterTool(IProfilingTool *tool) {
tools_.append(tool); tools_.append(tool);

View File

@ -52,7 +52,7 @@ using namespace SourceHook;
* Add 1 to the RHS of this expression to bump the intercom file * Add 1 to the RHS of this expression to bump the intercom file
* This is to prevent mismatching core/logic binaries * This is to prevent mismatching core/logic binaries
*/ */
#define SM_LOGIC_MAGIC (0x0F47C0DE - 35) #define SM_LOGIC_MAGIC (0x0F47C0DE - 36)
#if defined SM_LOGIC #if defined SM_LOGIC
class IVEngineServer class IVEngineServer

View File

@ -54,8 +54,8 @@ RootConsoleMenu::~RootConsoleMenu()
void RootConsoleMenu::OnSourceModStartup(bool late) void RootConsoleMenu::OnSourceModStartup(bool late)
{ {
AddRootConsoleCommand("version", "Display version information", this); AddRootConsoleCommand3("version", "Display version information", this);
AddRootConsoleCommand("credits", "Display credits listing", this); AddRootConsoleCommand3("credits", "Display credits listing", this);
} }
void RootConsoleMenu::OnSourceModAllInitialized() void RootConsoleMenu::OnSourceModAllInitialized()
@ -92,18 +92,17 @@ void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler) bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
{ {
return _AddRootConsoleCommand(cmd, text, pHandler, false); return false;
} }
bool RootConsoleMenu::AddRootConsoleCommand2(const char *cmd, const char *text, IRootConsoleCommand *pHandler) bool RootConsoleMenu::AddRootConsoleCommand2(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
{ {
return _AddRootConsoleCommand(cmd, text, pHandler, true); return false;
} }
bool RootConsoleMenu::_AddRootConsoleCommand(const char *cmd, bool RootConsoleMenu::AddRootConsoleCommand3(const char *cmd,
const char *text, const char *text,
IRootConsoleCommand *pHandler, IRootConsoleCommand *pHandler)
bool version2)
{ {
if (m_Commands.contains(cmd)) if (m_Commands.contains(cmd))
return false; return false;
@ -120,7 +119,6 @@ bool RootConsoleMenu::_AddRootConsoleCommand(const char *cmd,
ConsoleEntry *pNew = new ConsoleEntry; ConsoleEntry *pNew = new ConsoleEntry;
pNew->command.assign(cmd); pNew->command.assign(cmd);
pNew->description.assign(text); pNew->description.assign(text);
pNew->version2 = version2;
pNew->cmd = pHandler; pNew->cmd = pHandler;
m_Commands.insert(cmd, pNew); m_Commands.insert(cmd, pNew);
m_Menu.insert(iter, pNew); m_Menu.insert(iter, pNew);
@ -135,7 +133,6 @@ bool RootConsoleMenu::_AddRootConsoleCommand(const char *cmd,
ConsoleEntry *pNew = new ConsoleEntry; ConsoleEntry *pNew = new ConsoleEntry;
pNew->command.assign(cmd); pNew->command.assign(cmd);
pNew->description.assign(text); pNew->description.assign(text);
pNew->version2 = version2;
pNew->cmd = pHandler; pNew->cmd = pHandler;
m_Commands.insert(cmd, pNew); m_Commands.insert(cmd, pNew);
m_Menu.push_back(pNew); m_Menu.push_back(pNew);
@ -235,18 +232,18 @@ public:
}; };
#endif #endif
void RootConsoleMenu::GotRootCmd(const CCommand &cmd) void RootConsoleMenu::GotRootCmd(const ICommandArgs *cmd)
{ {
unsigned int argnum = cmd.ArgC(); unsigned int argnum = cmd->ArgC();
if (argnum >= 2) if (argnum >= 2)
{ {
const char *cmdname = cmd.Arg(1); const char *cmdname = cmd->Arg(1);
if (strcmp(cmdname, "internal") == 0) if (strcmp(cmdname, "internal") == 0)
{ {
if (argnum >= 3) if (argnum >= 3)
{ {
const char *arg = cmd.Arg(2); const char *arg = cmd->Arg(2);
if (strcmp(arg, "1") == 0) if (strcmp(arg, "1") == 0)
{ {
SM_ConfigsExecuted_Global(); SM_ConfigsExecuted_Global();
@ -255,26 +252,17 @@ void RootConsoleMenu::GotRootCmd(const CCommand &cmd)
{ {
if (argnum >= 4) if (argnum >= 4)
{ {
SM_ConfigsExecuted_Plugin(atoi(cmd.Arg(3))); SM_ConfigsExecuted_Plugin(atoi(cmd->Arg(3)));
} }
} }
} }
return; return;
} }
CCommandArgs ocmd(cmd);
ConsoleEntry *entry; ConsoleEntry *entry;
if (m_Commands.retrieve(cmdname, &entry)) if (m_Commands.retrieve(cmdname, &entry))
{ {
if (entry->version2) entry->cmd->OnRootConsoleCommand(cmdname, cmd);
{
entry->cmd->OnRootConsoleCommand2(cmdname, &ocmd);
}
else
{
entry->cmd->OnRootConsoleCommand(cmdname, cmd);
}
return; return;
} }
} }
@ -291,7 +279,7 @@ void RootConsoleMenu::GotRootCmd(const CCommand &cmd)
} }
} }
void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const CCommand &command) void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
{ {
if (strcmp(cmdname, "credits") == 0) if (strcmp(cmdname, "credits") == 0)
{ {
@ -332,7 +320,8 @@ CON_COMMAND(sm, "SourceMod Menu")
#if SOURCE_ENGINE <= SE_DARKMESSIAH #if SOURCE_ENGINE <= SE_DARKMESSIAH
CCommand args; CCommand args;
#endif #endif
g_RootMenu.GotRootCmd(args); CCommandArgs cargs(args);
g_RootMenu.GotRootCmd(&cargs);
} }
FILE *g_pHndlLog = NULL; FILE *g_pHndlLog = NULL;

View File

@ -47,7 +47,6 @@ struct ConsoleEntry
{ {
String command; String command;
String description; String description;
bool version2;
IRootConsoleCommand *cmd; IRootConsoleCommand *cmd;
static inline bool matches(const char *name, const ConsoleEntry *entry) static inline bool matches(const char *name, const ConsoleEntry *entry)
@ -72,7 +71,7 @@ public: //SMGlobalClass
void OnSourceModAllInitialized(); void OnSourceModAllInitialized();
void OnSourceModShutdown(); void OnSourceModShutdown();
public: //IRootConsoleCommand public: //IRootConsoleCommand
void OnRootConsoleCommand(const char *cmdname, const CCommand &command); void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command);
public: //IRootConsole public: //IRootConsole
bool AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler); bool AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler);
bool RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler); bool RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler);
@ -81,12 +80,11 @@ public: //IRootConsole
bool AddRootConsoleCommand2(const char *cmd, bool AddRootConsoleCommand2(const char *cmd,
const char *text, const char *text,
IRootConsoleCommand *pHandler); IRootConsoleCommand *pHandler);
bool _AddRootConsoleCommand(const char *cmd, bool AddRootConsoleCommand3(const char *cmd,
const char *text, const char *text,
IRootConsoleCommand *pHandler, IRootConsoleCommand *pHandler);
bool version2);
public: public:
void GotRootCmd(const CCommand &cmd); void GotRootCmd(const ICommandArgs *cmd);
private: private:
NameHashSet<ConsoleEntry *> m_Commands; NameHashSet<ConsoleEntry *> m_Commands;
List<ConsoleEntry *> m_Menu; List<ConsoleEntry *> m_Menu;

View File

@ -41,7 +41,7 @@
*/ */
#define SMINTERFACE_ROOTCONSOLE_NAME "IRootConsole" #define SMINTERFACE_ROOTCONSOLE_NAME "IRootConsole"
#define SMINTERFACE_ROOTCONSOLE_VERSION 2 #define SMINTERFACE_ROOTCONSOLE_VERSION 3
class CCommand; class CCommand;
@ -82,13 +82,11 @@ namespace SourceMod
class IRootConsoleCommand class IRootConsoleCommand
{ {
public: public:
virtual void OnRootConsoleCommand(const char *cmdname, const CCommand &command) virtual unsigned int GetApiVersion() const {
{ return SMINTERFACE_ROOTCONSOLE_VERSION;
} }
virtual void OnRootConsoleCommand2(const char *cmdname, const ICommandArgs *args) virtual void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *args) = 0;
{
}
}; };
/** /**
@ -98,12 +96,12 @@ namespace SourceMod
{ {
public: public:
/** /**
* @brief Adds a root console command handler. The command must be unique. * @brief Removed.
* *
* @param cmd String containing the console command. * @param cmd Unused.
* @param text Description text. * @param text Unused.
* @param pHandler An IRootConsoleCommand pointer to handle the command. * @param pHandler Unused.
* @return True on success, false on too many commands or duplicate command. * @return False.
*/ */
virtual bool AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler) =0; virtual bool AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler) =0;
@ -136,16 +134,26 @@ namespace SourceMod
virtual void DrawGenericOption(const char *cmd, const char *text) =0; virtual void DrawGenericOption(const char *cmd, const char *text) =0;
/** /**
* @brief Adds a root console command handler. The command must be unique. * @brief Removed.
* *
* This version of the function uses the OnRootConsoleCommand2 callback. * @param cmd Unused.
* @param text Unused.
* @param pHandler Unused.
* @return False.
*/
virtual bool AddRootConsoleCommand2(const char *cmd,
const char *text,
IRootConsoleCommand *pHandler) =0;
/**
* @brief Adds a root console command handler. The command must be unique.
* *
* @param cmd String containing the console command. * @param cmd String containing the console command.
* @param text Description text. * @param text Description text.
* @param pHandler An IRootConsoleCommand pointer to handle the command. * @param pHandler An IRootConsoleCommand pointer to handle the command.
* @return True on success, false on too many commands or duplicate command. * @return True on success, false on too many commands or duplicate command.
*/ */
virtual bool AddRootConsoleCommand2(const char *cmd, virtual bool AddRootConsoleCommand3(const char *cmd,
const char *text, const char *text,
IRootConsoleCommand *pHandler) =0; IRootConsoleCommand *pHandler) =0;
}; };