From c70cf5908ddb75fd6e1c6372e57c0fb73c63d286 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Wed, 7 Nov 2018 18:07:34 -0500 Subject: [PATCH] IsPlayerAdmin support, since admin was removed # Conflicts: # src/lua_baselib.c --- src/dehacked.c | 8 ++++---- src/lua_baselib.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 2d017642..09432966 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8269,10 +8269,10 @@ static inline int lib_getenum(lua_State *L) return 0; LUA_PushUserdata(L, &players[serverplayer], META_PLAYER); return 1; - } else if (fastcmp(word,"admin")) { - //if (!playeringame[adminplayer] || IsPlayerAdmin(serverplayer)) - //return 0; - //LUA_PushUserdata(L, &players[adminplayer], META_PLAYER); + } else if (fastcmp(word,"admin")) { // BACKWARDS COMPATIBILITY HACK: This was replaced with IsPlayerAdmin(), but some 2.1 Lua scripts still use the admin variable. It now points to the first admin player in the array. + if (!playeringame[adminplayers[0]] || IsPlayerAdmin(serverplayer)) + return 0; + LUA_PushUserdata(L, &players[adminplayers[0]], META_PLAYER); return 1; } else if (fastcmp(word,"emeralds")) { lua_pushinteger(L, emeralds); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index e8e8fd02..892974bd 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -20,6 +20,9 @@ #include "m_random.h" #include "s_sound.h" #include "g_game.h" +#include "hu_stuff.h" +#include "console.h" +#include "d_netcmd.h" // IsPlayerAdmin #include "lua_script.h" #include "lua_libs.h" @@ -93,6 +96,16 @@ static int lib_evalMath(lua_State *L) return 1; } +static int lib_isPlayerAdmin(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + //HUDSAFE + if (!player) + return LUA_ErrInvalid(L, "player_t"); + lua_pushboolean(L, IsPlayerAdmin(player-players)); + return 1; +} + // M_RANDOM ////////////// @@ -1983,6 +1996,7 @@ static int lib_gTicsToMilliseconds(lua_State *L) static luaL_Reg lib[] = { {"print", lib_print}, {"EvalMath", lib_evalMath}, + {"IsPlayerAdmin", lib_isPlayerAdmin}, // m_random {"P_RandomFixed",lib_pRandomFixed},