1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-13 16:45:20 +02:00

Avoid packets getting sent to disconnected players (#14444)

Many functions expect RemotePlayer to have a valid peer ID,
this however is not the case immediately after disconnecting
where the object is still alive and pending for removal.

ServerEnvironment::getPlayer(const char *, bool) now only
returns players that are connected unless forced to.
This commit is contained in:
SmallJoker
2024-03-10 13:24:35 +01:00
committed by GitHub
parent 02a893d613
commit 32f68f35cf
6 changed files with 24 additions and 31 deletions

View File

@@ -695,8 +695,6 @@ int ModApiEnv::l_get_connected_players(lua_State *L)
lua_createtable(L, env->getPlayerCount(), 0);
u32 i = 0;
for (RemotePlayer *player : env->getPlayers()) {
if (player->getPeerId() == PEER_ID_INEXISTENT)
continue;
PlayerSAO *sao = player->getPlayerSAO();
if (sao && !sao->isGone()) {
getScriptApiBase(L)->objectrefGetOrCreate(L, sao);
@@ -714,7 +712,7 @@ int ModApiEnv::l_get_player_by_name(lua_State *L)
// Do it
const char *name = luaL_checkstring(L, 1);
RemotePlayer *player = env->getPlayer(name);
if (!player || player->getPeerId() == PEER_ID_INEXISTENT)
if (!player)
return 0;
PlayerSAO *sao = player->getPlayerSAO();
if (!sao || sao->isGone())