Merge lua_consolelib.c

Properly supports 3P/4P commands while we're at it too
This commit is contained in:
Sally Coolatta 2020-08-05 09:58:12 -04:00
parent b546f7d188
commit 7e9efd4e29
3 changed files with 42 additions and 29 deletions

View file

@ -23,9 +23,13 @@
/* Lua command registration flags. */
enum
{
COM_ADMIN = 1,
COM_SPLITSCREEN = 2,
COM_LOCAL = 4,
COM_ADMIN = 0x01,
COM_LOCAL = 0x02,
COM_PLAYER2 = 0x10,
COM_PLAYER3 = 0x20,
COM_PLAYER4 = 0x30,
COM_SPLITSCREEN = COM_PLAYER2|COM_PLAYER3|COM_PLAYER4,
COM_SSSHIFT = 4
};
/* Command buffer flags. */

View file

@ -11455,8 +11455,12 @@ struct {
// Lua command registration flags
{"COM_ADMIN",COM_ADMIN},
{"COM_SPLITSCREEN",COM_SPLITSCREEN},
{"COM_LOCAL",COM_LOCAL},
{"COM_PLAYER2",COM_PLAYER2},
{"COM_PLAYER3",COM_PLAYER3},
{"COM_PLAYER4",COM_PLAYER4},
{"COM_SPLITSCREEN",COM_SPLITSCREEN},
{"COM_SSSHIFT",COM_SSSHIFT},
// cvflags_t
{"CV_SAVE",CV_SAVE},

View file

@ -93,8 +93,10 @@ deny:
void COM_Lua_f(void)
{
char *buf, *p;
UINT8 i, flags;
UINT8 i;
UINT16 len;
UINT16 flags;
UINT8 lpn = 0;
INT32 playernum = consoleplayer;
I_Assert(gL != NULL);
@ -113,21 +115,20 @@ void COM_Lua_f(void)
if (lua_isboolean(gL, -1))
flags = (lua_toboolean(gL, -1) ? COM_ADMIN : 0);
else
flags = (UINT8)lua_tointeger(gL, -1);
flags = (UINT16)lua_tointeger(gL, -1);
lua_pop(gL, 1); // pop flags
<<<<<<< HEAD
if (flags & 2) // flag 2: splitscreen player command. TODO: support 4P
=======
if (flags & COM_SPLITSCREEN) // flag 2: splitscreen player command.
>>>>>>> srb2/next
if (flags & COM_SPLITSCREEN) // splitscreen player command.
{
if (!splitscreen)
lpn = (flags & COM_SPLITSCREEN) >> COM_SSSHIFT;
if (splitscreen < lpn)
{
lua_pop(gL, 1); // pop command info table
return; // can't execute splitscreen command without player 2!
return; // can't execute splitscreen command without the player being in-game!
}
playernum = g_localplayers[1];
playernum = g_localplayers[lpn];
}
if (netgame && !( flags & COM_LOCAL ))/* don't send local commands */
@ -135,7 +136,7 @@ void COM_Lua_f(void)
UINT8 argc;
lua_pop(gL, 1); // pop command info table
if (flags & COM_ADMIN && !server && !IsPlayerAdmin(playernum)) // flag 1: only server/admin can use this command.
if ((flags & COM_ADMIN) && !server && !IsPlayerAdmin(playernum)) // only server/admin can use this command.
{
CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n"));
return;
@ -155,10 +156,24 @@ void COM_Lua_f(void)
WRITEUINT8(p, argc);
for (i = 0; i < argc; i++)
WRITESTRINGN(p, COM_Argv(i), 255);
if (flags & COM_SPLITSCREEN)
SendNetXCmd2(XD_LUACMD, buf, p-buf);
else
SendNetXCmd(XD_LUACMD, buf, p-buf);
switch (lpn)
{
case 3:
SendNetXCmd4(XD_LUACMD, buf, p-buf);
break;
case 2:
SendNetXCmd3(XD_LUACMD, buf, p-buf);
break;
case 1:
SendNetXCmd2(XD_LUACMD, buf, p-buf);
break;
default:
case 0:
SendNetXCmd(XD_LUACMD, buf, p-buf);
break;
}
free(buf);
return;
}
@ -432,7 +447,6 @@ static int lib_cvRegisterVar(lua_State *L)
return 1;
}
<<<<<<< HEAD
// For some reason I couldn't cherry pick this.
// Credits for this function go to james. All hail birb. -Lat'
@ -456,15 +470,6 @@ static int lib_cvFindVar(lua_State *L)
return 0;
}
=======
static int lib_cvFindVar(lua_State *L)
{
LUA_PushLightUserdata(L, CV_FindVar(luaL_checkstring(L,1)), META_CVAR);
return 1;
}
>>>>>>> srb2/next
// CONS_Printf for a single player
// Use 'print' in baselib for a global message.
static int lib_consPrintf(lua_State *L)