diff options
author | sfan5 <sfan5@live.de> | 2020-03-03 21:14:47 +0100 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2020-03-03 21:21:41 +0100 |
commit | 6d8e2d2483715f05216be86a32f664bcbaac3efe (patch) | |
tree | 02d08db57ae57bcd1e0d24a2db6e436b340770b4 | |
parent | 1761d7d0f8a778e25ca70216520472a61610cbe5 (diff) | |
download | minetest-6d8e2d2483715f05216be86a32f664bcbaac3efe.tar.gz minetest-6d8e2d2483715f05216be86a32f664bcbaac3efe.tar.bz2 minetest-6d8e2d2483715f05216be86a32f664bcbaac3efe.zip |
Fix core.get_player_by_name() returning unusable ObjectRef
Followup to the previous commit.
-rw-r--r-- | src/script/lua_api/l_env.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 6e67e547b..a175569d8 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -667,15 +667,11 @@ int ModApiEnvMod::l_get_player_by_name(lua_State *L) // Do it const char *name = luaL_checkstring(L, 1); RemotePlayer *player = env->getPlayer(name); - if (player == NULL){ - lua_pushnil(L); - return 1; - } + if (!player || player->getPeerId() == PEER_ID_INEXISTENT) + return 0; PlayerSAO *sao = player->getPlayerSAO(); - if(sao == NULL){ - lua_pushnil(L); - return 1; - } + if (!sao || sao->isGone()) + return 0; // Put player on stack getScriptApiBase(L)->objectrefGetOrCreate(L, sao); return 1; |