mirror of
https://github.com/minetest/minetest.git
synced 2024-11-30 11:33:44 +01:00
Script API: Check that SAOs are still usable before attempting to use them
This commit is contained in:
parent
b14aa1c847
commit
91eef646a5
@ -864,7 +864,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t p
|
|||||||
m_peer_id(peer_id_),
|
m_peer_id(peer_id_),
|
||||||
m_is_singleplayer(is_singleplayer)
|
m_is_singleplayer(is_singleplayer)
|
||||||
{
|
{
|
||||||
assert(m_peer_id != 0); // pre-condition
|
SANITY_CHECK(m_peer_id != PEER_ID_INEXISTENT);
|
||||||
|
|
||||||
m_prop.hp_max = PLAYER_MAX_HP_DEFAULT;
|
m_prop.hp_max = PLAYER_MAX_HP_DEFAULT;
|
||||||
m_prop.breath_max = PLAYER_MAX_BREATH_DEFAULT;
|
m_prop.breath_max = PLAYER_MAX_BREATH_DEFAULT;
|
||||||
@ -1393,7 +1393,7 @@ bool PlayerSAO::setWieldedItem(const ItemStack &item)
|
|||||||
|
|
||||||
void PlayerSAO::disconnected()
|
void PlayerSAO::disconnected()
|
||||||
{
|
{
|
||||||
m_peer_id = 0;
|
m_peer_id = PEER_ID_INEXISTENT;
|
||||||
m_pending_removal = true;
|
m_pending_removal = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +60,8 @@ LuaEntitySAO* ObjectRef::getluaobject(ObjectRef *ref)
|
|||||||
return NULL;
|
return NULL;
|
||||||
if (obj->getType() != ACTIVEOBJECT_TYPE_LUAENTITY)
|
if (obj->getType() != ACTIVEOBJECT_TYPE_LUAENTITY)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (obj->isGone())
|
||||||
|
return NULL;
|
||||||
return (LuaEntitySAO*)obj;
|
return (LuaEntitySAO*)obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +72,8 @@ PlayerSAO* ObjectRef::getplayersao(ObjectRef *ref)
|
|||||||
return NULL;
|
return NULL;
|
||||||
if (obj->getType() != ACTIVEOBJECT_TYPE_PLAYER)
|
if (obj->getType() != ACTIVEOBJECT_TYPE_PLAYER)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (obj->isGone())
|
||||||
|
return NULL;
|
||||||
return (PlayerSAO*)obj;
|
return (PlayerSAO*)obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1768,10 +1768,7 @@ void Server::SendTimeOfDay(session_t peer_id, u16 time, f32 time_speed)
|
|||||||
void Server::SendPlayerHP(session_t peer_id)
|
void Server::SendPlayerHP(session_t peer_id)
|
||||||
{
|
{
|
||||||
PlayerSAO *playersao = getPlayerSAO(peer_id);
|
PlayerSAO *playersao = getPlayerSAO(peer_id);
|
||||||
// In some rare case if the player is disconnected
|
assert(playersao);
|
||||||
// while Lua call l_punch, for example, this can be NULL
|
|
||||||
if (!playersao)
|
|
||||||
return;
|
|
||||||
|
|
||||||
SendHP(peer_id, playersao->getHP());
|
SendHP(peer_id, playersao->getHP());
|
||||||
m_script->player_event(playersao,"health_changed");
|
m_script->player_event(playersao,"health_changed");
|
||||||
@ -2701,10 +2698,7 @@ void Server::sendDetachedInventories(session_t peer_id, bool incremental)
|
|||||||
void Server::DiePlayer(session_t peer_id, const PlayerHPChangeReason &reason)
|
void Server::DiePlayer(session_t peer_id, const PlayerHPChangeReason &reason)
|
||||||
{
|
{
|
||||||
PlayerSAO *playersao = getPlayerSAO(peer_id);
|
PlayerSAO *playersao = getPlayerSAO(peer_id);
|
||||||
// In some rare cases this can be NULL -- if the player is disconnected
|
assert(playersao);
|
||||||
// when a Lua function modifies l_punch, for example
|
|
||||||
if (!playersao)
|
|
||||||
return;
|
|
||||||
|
|
||||||
infostream << "Server::DiePlayer(): Player "
|
infostream << "Server::DiePlayer(): Player "
|
||||||
<< playersao->getPlayer()->getName()
|
<< playersao->getPlayer()->getName()
|
||||||
|
Loading…
Reference in New Issue
Block a user