From 22ac33d3f3dbe5771099740d192add6c97af3175 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Wed, 29 Nov 2023 22:46:29 -0500 Subject: [PATCH] Make dev chat commands less dangerous (Remove /lua commands) --- src/dev/chat.c | 22 ---------------------- src/pc/lua/smlua.c | 11 +---------- src/pc/lua/smlua.h | 2 -- 3 files changed, 1 insertion(+), 34 deletions(-) diff --git a/src/dev/chat.c b/src/dev/chat.c index 1686f896..015fb275 100644 --- a/src/dev/chat.c +++ b/src/dev/chat.c @@ -108,32 +108,10 @@ bool exec_dev_chat_command(char* command) { return true; } - if (strcmp("/lua", command) == 0) { - djui_chat_message_create("Missing parameter: [LUA]"); - return true; - } - - if (str_starts_with("/lua ", command)) { - smlua_exec_str(&command[5]); - return true; - } - - if (strcmp("/luaf", command) == 0) { - djui_chat_message_create("Missing parameter: [FILENAME]"); - return true; - } - - if (str_starts_with("/luaf ", command)) { - smlua_exec_file(&command[6]); - return true; - } - return false; } void dev_display_chat_commands(void) { djui_chat_message_create("/warp [LEVEL] [AREA] [ACT] - Level can be either a numeric value or a shorthand name"); - djui_chat_message_create("/lua [LUA] - Execute Lua code from a string"); - djui_chat_message_create("/luaf [FILENAME] - Execute Lua code from a file"); } #endif \ No newline at end of file diff --git a/src/pc/lua/smlua.c b/src/pc/lua/smlua.c index 8216c647..91b22421 100644 --- a/src/pc/lua/smlua.c +++ b/src/pc/lua/smlua.c @@ -46,16 +46,7 @@ int smlua_pcall(lua_State* L, int nargs, int nresults, UNUSED int errfunc) { return rc; } -void smlua_exec_file(const char* path) { - lua_State* L = gLuaState; - if (luaL_dofile(L, path) != LUA_OK) { - LOG_LUA("Failed to load lua file '%s'.", path); - LOG_LUA("%s", smlua_to_string(L, lua_gettop(L))); - } - lua_pop(L, lua_gettop(L)); -} - -void smlua_exec_str(const char* str) { +static void smlua_exec_str(const char* str) { lua_State* L = gLuaState; if (luaL_dostring(L, str) != LUA_OK) { LOG_LUA("Failed to load lua string."); diff --git a/src/pc/lua/smlua.h b/src/pc/lua/smlua.h index 0f55695b..286fcdcf 100644 --- a/src/pc/lua/smlua.h +++ b/src/pc/lua/smlua.h @@ -41,8 +41,6 @@ extern struct Mod* gLuaLastHookMod; void smlua_mod_error(void); int smlua_error_handler(UNUSED lua_State* L); int smlua_pcall(lua_State* L, int nargs, int nresults, int errfunc); -void smlua_exec_file(const char* path); -void smlua_exec_str(const char* str); void smlua_init(void); void smlua_update(void);