1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00: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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 24 additions and 31 deletions

View file

@ -124,7 +124,7 @@ Inventory *ServerInventoryManager::createDetachedInventory(
RemotePlayer *p = m_env->getPlayer(name.c_str());
// if player is connected, send him the inventory
if (p && p->getPeerId() != PEER_ID_INEXISTENT) {
if (p) {
m_env->getGameDef()->sendDetachedInventory(
inv, name, p->getPeerId());
}
@ -152,7 +152,7 @@ bool ServerInventoryManager::removeDetachedInventory(const std::string &name)
if (m_env) {
RemotePlayer *player = m_env->getPlayer(owner.c_str());
if (player && player->getPeerId() != PEER_ID_INEXISTENT)
if (player)
m_env->getGameDef()->sendDetachedInventory(
nullptr, name, player->getPeerId());
}