Only let Lua run commands registered with COM_LUA

This commit is contained in:
James R 2023-03-15 16:32:28 -07:00
parent 8a6f2e568b
commit 49f1462f75
2 changed files with 9 additions and 1 deletions

View file

@ -544,7 +544,7 @@ int COM_AddLuaCommand(const char *name)
cmd = ZZ_Alloc(sizeof *cmd);
cmd->name = name;
cmd->function = COM_Lua_f;
cmd->flags = 0;
cmd->flags = COM_LUA;
cmd->next = com_commands;
com_commands = cmd;
return 0;
@ -640,6 +640,12 @@ static void COM_ExecuteString(char *ptext)
{
if (!stricmp(com_argv[0], cmd->name)) //case insensitive now that we have lower and uppercase!
{
if ((com_flags & COM_LUA) && !(cmd->flags & COM_LUA))
{
CONS_Alert(CONS_WARNING, "Command '%s' cannot be run from Lua.\n", cmd->name);
return;
}
cmd->function();
return;
}

View file

@ -29,6 +29,8 @@ typedef enum
// COM_BufInsertText etc: can only access cvars
// with CV_ALLOWLUA set.
// COM_AddCommand: without this flag, the command
// CANNOT be run from Lua.
COM_LUA = 8,
} com_flags_t;