From 8a15e9abc4b36a9c5af0e0f81c7aeea8096ee666 Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 29 Dec 2019 20:46:43 -0800 Subject: [PATCH 1/6] Bro player 2 can't use the console --- src/lua_consolelib.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index 58e720c85..d6c532b65 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -130,7 +130,6 @@ void COM_Lua_f(void) lua_pop(gL, 1); // pop command info table return; // can't execute splitscreen command without player 2! } - playernum = secondarydisplayplayer; } if (netgame) From dc757f3086591729e24772cb213cd33c631fc432 Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 29 Dec 2019 20:59:48 -0800 Subject: [PATCH 2/6] Fuck magic numbers; COM_ flags for Lua commands! --- src/command.h | 7 +++++++ src/dehacked.c | 4 ++++ src/lua_consolelib.c | 15 +++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/command.h b/src/command.h index 51e161cd0..7078c333a 100644 --- a/src/command.h +++ b/src/command.h @@ -20,6 +20,13 @@ // Command buffer & command execution //=================================== +/* Lua command registration flags. */ +enum +{ + COM_ADMIN = 1, + COM_SPLITSCREEN = 2, +}; + typedef void (*com_func_t)(void); void COM_AddCommand(const char *name, com_func_t func); diff --git a/src/dehacked.c b/src/dehacked.c index 4c90211cc..7d473bd51 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9732,6 +9732,10 @@ struct { {"BT_CUSTOM2",BT_CUSTOM2}, // Lua customizable {"BT_CUSTOM3",BT_CUSTOM3}, // Lua customizable + // Lua command registration flags + {"COM_ADMIN",COM_ADMIN}, + {"COM_SPLITSCREEN",COM_SPLITSCREEN}, + // cvflags_t {"CV_SAVE",CV_SAVE}, {"CV_CALL",CV_CALL}, diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index d6c532b65..b861a4ad7 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -118,12 +118,12 @@ void COM_Lua_f(void) lua_rawgeti(gL, -1, 2); // push flags from command info table if (lua_isboolean(gL, -1)) - flags = (lua_toboolean(gL, -1) ? 1 : 0); + flags = (lua_toboolean(gL, -1) ? COM_ADMIN : 0); else flags = (UINT8)lua_tointeger(gL, -1); lua_pop(gL, 1); // pop flags - if (flags & 2) // flag 2: splitscreen player command. + if (flags & COM_SPLITSCREEN) // flag 2: splitscreen player command. { if (!splitscreen) { @@ -137,7 +137,7 @@ void COM_Lua_f(void) UINT8 argc; lua_pop(gL, 1); // pop command info table - if (flags & 1 && !server && !IsPlayerAdmin(playernum)) // flag 1: only server/admin can use this command. + if (flags & COM_ADMIN && !server && !IsPlayerAdmin(playernum)) // flag 1: only server/admin can use this command. { CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); return; @@ -191,7 +191,14 @@ static int lib_comAddCommand(lua_State *L) if (lua_gettop(L) >= 3) { // For the third argument, only take a boolean or a number. lua_settop(L, 3); - if (lua_type(L, 3) != LUA_TBOOLEAN) + if (lua_type(L, 3) == LUA_TBOOLEAN) + { + CONS_Alert(CONS_WARNING, + "Using a boolean is deprecated and will be removed.\n" + "Use \"COM_\" flags instead.\n" + ); + } + else luaL_checktype(L, 3, LUA_TNUMBER); } else From 6546e3c3bc38415150bd3a2c405a465fe67509a0 Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 29 Dec 2019 21:02:42 -0800 Subject: [PATCH 3/6] No. --- src/lua_consolelib.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index b861a4ad7..cbfa42f87 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -157,10 +157,7 @@ void COM_Lua_f(void) WRITEUINT8(p, argc); for (i = 0; i < argc; i++) WRITESTRINGN(p, COM_Argv(i), 255); - if (flags & 2) - SendNetXCmd2(XD_LUACMD, buf, p-buf); - else - SendNetXCmd(XD_LUACMD, buf, p-buf); + SendNetXCmd(XD_LUACMD, buf, p-buf); free(buf); return; } From 802ef0aba1ff9c5dab5b826b5393566b3b5ac40e Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 29 Dec 2019 21:07:28 -0800 Subject: [PATCH 4/6] COM_LOCAL makes your commands NetXCmd free, FUCK NetXCmd --- src/command.h | 1 + src/dehacked.c | 1 + src/lua_consolelib.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/command.h b/src/command.h index 7078c333a..554c1131b 100644 --- a/src/command.h +++ b/src/command.h @@ -25,6 +25,7 @@ enum { COM_ADMIN = 1, COM_SPLITSCREEN = 2, + COM_LOCAL = 4, }; typedef void (*com_func_t)(void); diff --git a/src/dehacked.c b/src/dehacked.c index 7d473bd51..b3a8ed1dd 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -9735,6 +9735,7 @@ struct { // Lua command registration flags {"COM_ADMIN",COM_ADMIN}, {"COM_SPLITSCREEN",COM_SPLITSCREEN}, + {"COM_LOCAL",COM_LOCAL}, // cvflags_t {"CV_SAVE",CV_SAVE}, diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index cbfa42f87..f40b63ac6 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -132,7 +132,7 @@ void COM_Lua_f(void) } } - if (netgame) + if (netgame && !( flags & COM_LOCAL ))/* don't send local commands */ { // Send the command through the network UINT8 argc; lua_pop(gL, 1); // pop command info table From 65921c170207d2e4be1bd2bbfd43f7225d1e0fe9 Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 29 Dec 2019 21:09:07 -0800 Subject: [PATCH 5/6] Improve COM_AddCommand boolean deprecated warning --- src/lua_consolelib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index f40b63ac6..4e397fb32 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -191,8 +191,9 @@ static int lib_comAddCommand(lua_State *L) if (lua_type(L, 3) == LUA_TBOOLEAN) { CONS_Alert(CONS_WARNING, - "Using a boolean is deprecated and will be removed.\n" - "Use \"COM_\" flags instead.\n" + "Using a boolean for admin commands is " + "deprecated and will be removed.\n" + "Use \"COM_ADMIN\" instead.\n" ); } else From d670139404831a32fc57c477223cd286fe2a4cc5 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 30 Dec 2019 12:30:35 -0800 Subject: [PATCH 6/6] Revert revert revert This reverts commit 6546e3c3bc38415150bd3a2c405a465fe67509a0. This reverts commit 8a15e9abc4b36a9c5af0e0f81c7aeea8096ee666. --- src/lua_consolelib.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index 4e397fb32..06a3b3388 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -130,6 +130,7 @@ void COM_Lua_f(void) lua_pop(gL, 1); // pop command info table return; // can't execute splitscreen command without player 2! } + playernum = secondarydisplayplayer; } if (netgame && !( flags & COM_LOCAL ))/* don't send local commands */ @@ -157,7 +158,10 @@ void COM_Lua_f(void) WRITEUINT8(p, argc); for (i = 0; i < argc; i++) WRITESTRINGN(p, COM_Argv(i), 255); - SendNetXCmd(XD_LUACMD, buf, p-buf); + if (flags & COM_SPLITSCREEN) + SendNetXCmd2(XD_LUACMD, buf, p-buf); + else + SendNetXCmd(XD_LUACMD, buf, p-buf); free(buf); return; }