Merge branch 'local-lua-commands' into 'next'
Local Lua commands + no magic numbers See merge request STJr/SRB2!602
This commit is contained in:
commit
3b90571987
|
@ -20,6 +20,15 @@
|
||||||
// Command buffer & command execution
|
// Command buffer & command execution
|
||||||
//===================================
|
//===================================
|
||||||
|
|
||||||
|
/* Lua command registration flags. */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
COM_ADMIN = 1,
|
||||||
|
COM_SPLITSCREEN = 2,
|
||||||
|
COM_LOCAL = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Command buffer flags. */
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
COM_SAFE = 1,
|
COM_SAFE = 1,
|
||||||
|
|
|
@ -9741,6 +9741,11 @@ struct {
|
||||||
{"BT_CUSTOM2",BT_CUSTOM2}, // Lua customizable
|
{"BT_CUSTOM2",BT_CUSTOM2}, // Lua customizable
|
||||||
{"BT_CUSTOM3",BT_CUSTOM3}, // Lua customizable
|
{"BT_CUSTOM3",BT_CUSTOM3}, // Lua customizable
|
||||||
|
|
||||||
|
// Lua command registration flags
|
||||||
|
{"COM_ADMIN",COM_ADMIN},
|
||||||
|
{"COM_SPLITSCREEN",COM_SPLITSCREEN},
|
||||||
|
{"COM_LOCAL",COM_LOCAL},
|
||||||
|
|
||||||
// cvflags_t
|
// cvflags_t
|
||||||
{"CV_SAVE",CV_SAVE},
|
{"CV_SAVE",CV_SAVE},
|
||||||
{"CV_CALL",CV_CALL},
|
{"CV_CALL",CV_CALL},
|
||||||
|
|
|
@ -118,12 +118,12 @@ void COM_Lua_f(void)
|
||||||
|
|
||||||
lua_rawgeti(gL, -1, 2); // push flags from command info table
|
lua_rawgeti(gL, -1, 2); // push flags from command info table
|
||||||
if (lua_isboolean(gL, -1))
|
if (lua_isboolean(gL, -1))
|
||||||
flags = (lua_toboolean(gL, -1) ? 1 : 0);
|
flags = (lua_toboolean(gL, -1) ? COM_ADMIN : 0);
|
||||||
else
|
else
|
||||||
flags = (UINT8)lua_tointeger(gL, -1);
|
flags = (UINT8)lua_tointeger(gL, -1);
|
||||||
lua_pop(gL, 1); // pop flags
|
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)
|
if (!splitscreen)
|
||||||
{
|
{
|
||||||
|
@ -133,12 +133,12 @@ void COM_Lua_f(void)
|
||||||
playernum = secondarydisplayplayer;
|
playernum = secondarydisplayplayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (netgame)
|
if (netgame && !( flags & COM_LOCAL ))/* don't send local commands */
|
||||||
{ // Send the command through the network
|
{ // Send the command through the network
|
||||||
UINT8 argc;
|
UINT8 argc;
|
||||||
lua_pop(gL, 1); // pop command info table
|
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"));
|
CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n"));
|
||||||
return;
|
return;
|
||||||
|
@ -158,7 +158,7 @@ void COM_Lua_f(void)
|
||||||
WRITEUINT8(p, argc);
|
WRITEUINT8(p, argc);
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
WRITESTRINGN(p, COM_Argv(i), 255);
|
WRITESTRINGN(p, COM_Argv(i), 255);
|
||||||
if (flags & 2)
|
if (flags & COM_SPLITSCREEN)
|
||||||
SendNetXCmd2(XD_LUACMD, buf, p-buf);
|
SendNetXCmd2(XD_LUACMD, buf, p-buf);
|
||||||
else
|
else
|
||||||
SendNetXCmd(XD_LUACMD, buf, p-buf);
|
SendNetXCmd(XD_LUACMD, buf, p-buf);
|
||||||
|
@ -192,7 +192,15 @@ static int lib_comAddCommand(lua_State *L)
|
||||||
if (lua_gettop(L) >= 3)
|
if (lua_gettop(L) >= 3)
|
||||||
{ // For the third argument, only take a boolean or a number.
|
{ // For the third argument, only take a boolean or a number.
|
||||||
lua_settop(L, 3);
|
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 for admin commands is "
|
||||||
|
"deprecated and will be removed.\n"
|
||||||
|
"Use \"COM_ADMIN\" instead.\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
luaL_checktype(L, 3, LUA_TNUMBER);
|
luaL_checktype(L, 3, LUA_TNUMBER);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue