mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-13 13:21:31 +00:00
Always allow access to the serverplayer
This commit is contained in:
parent
1d8608c00d
commit
29d8e44055
4 changed files with 27 additions and 5 deletions
|
@ -9704,11 +9704,10 @@ static inline int lib_getenum(lua_State *L)
|
||||||
lua_pushinteger(L, mapmusposition);
|
lua_pushinteger(L, mapmusposition);
|
||||||
return 1;
|
return 1;
|
||||||
} else if (fastcmp(word,"server")) {
|
} else if (fastcmp(word,"server")) {
|
||||||
if ((!multiplayer || !(netgame || demo.playback)) && !playeringame[serverplayer])
|
return LUA_PushServerPlayer(L);
|
||||||
return 0;
|
|
||||||
LUA_PushUserdata(L, &players[serverplayer], META_PLAYER);
|
|
||||||
return 1;
|
|
||||||
} else if (fastcmp(word,"consoleplayer")) { // Player controlling the console, basically our local player
|
} else if (fastcmp(word,"consoleplayer")) { // Player controlling the console, basically our local player
|
||||||
|
if (consoleplayer == serverplayer)
|
||||||
|
return LUA_PushServerPlayer(L);
|
||||||
if (consoleplayer < 0 || !playeringame[consoleplayer])
|
if (consoleplayer < 0 || !playeringame[consoleplayer])
|
||||||
return 0;
|
return 0;
|
||||||
LUA_PushUserdata(L, &players[consoleplayer], META_PLAYER);
|
LUA_PushUserdata(L, &players[consoleplayer], META_PLAYER);
|
||||||
|
|
|
@ -27,17 +27,28 @@
|
||||||
static int lib_iteratePlayers(lua_State *L)
|
static int lib_iteratePlayers(lua_State *L)
|
||||||
{
|
{
|
||||||
INT32 i = -1;
|
INT32 i = -1;
|
||||||
|
|
||||||
if (lua_gettop(L) < 2)
|
if (lua_gettop(L) < 2)
|
||||||
{
|
{
|
||||||
//return luaL_error(L, "Don't call players.iterate() directly, use it as 'for player in players.iterate do <block> end'.");
|
//return luaL_error(L, "Don't call players.iterate() directly, use it as 'for player in players.iterate do <block> end'.");
|
||||||
lua_pushcfunction(L, lib_iteratePlayers);
|
lua_pushcfunction(L, lib_iteratePlayers);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_settop(L, 2);
|
lua_settop(L, 2);
|
||||||
lua_remove(L, 1); // state is unused.
|
lua_remove(L, 1); // state is unused.
|
||||||
|
|
||||||
if (!lua_isnil(L, 1))
|
if (!lua_isnil(L, 1))
|
||||||
i = (INT32)(*((player_t **)luaL_checkudata(L, 1, META_PLAYER)) - players);
|
i = (INT32)(*((player_t **)luaL_checkudata(L, 1, META_PLAYER)) - players);
|
||||||
for (i++; i < MAXPLAYERS; i++)
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
if (i == serverplayer)
|
||||||
|
{
|
||||||
|
return LUA_PushServerPlayer(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; i < MAXPLAYERS; i++)
|
||||||
{
|
{
|
||||||
if (!playeringame[i])
|
if (!playeringame[i])
|
||||||
continue;
|
continue;
|
||||||
|
@ -46,6 +57,7 @@ static int lib_iteratePlayers(lua_State *L)
|
||||||
LUA_PushUserdata(L, &players[i], META_PLAYER);
|
LUA_PushUserdata(L, &players[i], META_PLAYER);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +70,8 @@ static int lib_getPlayer(lua_State *L)
|
||||||
lua_Integer i = luaL_checkinteger(L, 2);
|
lua_Integer i = luaL_checkinteger(L, 2);
|
||||||
if (i < 0 || i >= MAXPLAYERS)
|
if (i < 0 || i >= MAXPLAYERS)
|
||||||
return luaL_error(L, "players[] index %d out of range (0 - %d)", i, MAXPLAYERS-1);
|
return luaL_error(L, "players[] index %d out of range (0 - %d)", i, MAXPLAYERS-1);
|
||||||
|
if (i == serverplayer)
|
||||||
|
return LUA_PushServerPlayer(L);
|
||||||
if (!playeringame[i])
|
if (!playeringame[i])
|
||||||
return 0;
|
return 0;
|
||||||
if (!players[i].mo)
|
if (!players[i].mo)
|
||||||
|
|
|
@ -367,6 +367,14 @@ void LUA_PushUserdata(lua_State *L, void *data, const char *meta)
|
||||||
lua_remove(L, -2); // remove LREG_VALID
|
lua_remove(L, -2); // remove LREG_VALID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LUA_PushServerPlayer(lua_State *L)
|
||||||
|
{
|
||||||
|
if ((!multiplayer || !(netgame || demo.playback)) && !playeringame[serverplayer])
|
||||||
|
return 0;
|
||||||
|
LUA_PushUserdata(L, &players[serverplayer], META_PLAYER);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// When userdata is freed, use this function to remove it from Lua.
|
// When userdata is freed, use this function to remove it from Lua.
|
||||||
void LUA_InvalidateUserdata(void *data)
|
void LUA_InvalidateUserdata(void *data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,6 +46,7 @@ void LUA_DumpFile(const char *filename);
|
||||||
#endif
|
#endif
|
||||||
fixed_t LUA_EvalMath(const char *word);
|
fixed_t LUA_EvalMath(const char *word);
|
||||||
void LUA_PushUserdata(lua_State *L, void *data, const char *meta);
|
void LUA_PushUserdata(lua_State *L, void *data, const char *meta);
|
||||||
|
int LUA_PushServerPlayer(lua_State *L);
|
||||||
void LUA_InvalidateUserdata(void *data);
|
void LUA_InvalidateUserdata(void *data);
|
||||||
void LUA_InvalidateLevel(void);
|
void LUA_InvalidateLevel(void);
|
||||||
void LUA_InvalidateMapthings(void);
|
void LUA_InvalidateMapthings(void);
|
||||||
|
|
Loading…
Reference in a new issue