Add option for console commands to be unlisted.

This commit is contained in:
Jonathan G Rennison
2017-02-21 20:47:38 +00:00
parent 102405e082
commit 3884ea5da1
3 changed files with 5 additions and 3 deletions

View File

@@ -253,13 +253,14 @@ char *RemoveUnderscores(char *name)
* @param name name of the command that will be used * @param name name of the command that will be used
* @param proc function that will be called upon execution of command * @param proc function that will be called upon execution of command
*/ */
void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc, IConsoleHook *hook) void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc, IConsoleHook *hook, bool unlisted)
{ {
IConsoleCmd *item_new = MallocT<IConsoleCmd>(1); IConsoleCmd *item_new = MallocT<IConsoleCmd>(1);
item_new->name = RemoveUnderscores(stredup(name)); item_new->name = RemoveUnderscores(stredup(name));
item_new->next = NULL; item_new->next = NULL;
item_new->proc = proc; item_new->proc = proc;
item_new->hook = hook; item_new->hook = hook;
item_new->unlisted = unlisted;
IConsoleAddSorted(&_iconsole_cmds, item_new); IConsoleAddSorted(&_iconsole_cmds, item_new);
} }

View File

@@ -1500,7 +1500,7 @@ DEF_CONSOLE_CMD(ConListCommands)
for (const IConsoleCmd *cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) { for (const IConsoleCmd *cmd = _iconsole_cmds; cmd != NULL; cmd = cmd->next) {
if (argv[1] == NULL || strstr(cmd->name, argv[1]) != NULL) { if (argv[1] == NULL || strstr(cmd->name, argv[1]) != NULL) {
if (cmd->hook == NULL || cmd->hook(false) != CHR_HIDE) IConsolePrintF(CC_DEFAULT, "%s", cmd->name); if (cmd->unlisted == false && (cmd->hook == NULL || cmd->hook(false) != CHR_HIDE)) IConsolePrintF(CC_DEFAULT, "%s", cmd->name);
} }
} }

View File

@@ -40,6 +40,7 @@ struct IConsoleCmd {
IConsoleCmdProc *proc; ///< process executed when command is typed IConsoleCmdProc *proc; ///< process executed when command is typed
IConsoleHook *hook; ///< any special trigger action that needs executing IConsoleHook *hook; ///< any special trigger action that needs executing
bool unlisted;
}; };
/** /**
@@ -69,7 +70,7 @@ extern IConsoleAlias *_iconsole_aliases; ///< List of registered aliases.
void IConsoleClearBuffer(); void IConsoleClearBuffer();
/* Commands */ /* Commands */
void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc, IConsoleHook *hook = NULL); void IConsoleCmdRegister(const char *name, IConsoleCmdProc *proc, IConsoleHook *hook = NULL, bool unlisted = false);
void IConsoleAliasRegister(const char *name, const char *cmd); void IConsoleAliasRegister(const char *name, const char *cmd);
IConsoleCmd *IConsoleCmdGet(const char *name); IConsoleCmd *IConsoleCmdGet(const char *name);
IConsoleAlias *IConsoleAliasGet(const char *name); IConsoleAlias *IConsoleAliasGet(const char *name);