aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2013-11-17 02:57:40 -0500
committerkwolekr <kwolekr@minetest.net>2013-11-17 15:15:59 -0500
commit86ef7147b60868f86d38d55a1dcf6271d68427ce (patch)
treea449513e687710211b92e4555895f96d14dda460 /src
parenta55c073ce9bd78a6ebbb867ab4db2ec611eb66cf (diff)
downloadminetest-86ef7147b60868f86d38d55a1dcf6271d68427ce.tar.gz
minetest-86ef7147b60868f86d38d55a1dcf6271d68427ce.tar.bz2
minetest-86ef7147b60868f86d38d55a1dcf6271d68427ce.zip
Fix issue #1009 (minetest.get_connected_players() returns non-existing players)
Diffstat (limited to 'src')
-rw-r--r--src/script/lua_api/l_object.cpp11
-rw-r--r--src/script/lua_api/l_object.h3
2 files changed, 14 insertions, 0 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index c324ced1a..cbcaa40eb 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -621,6 +621,16 @@ int ObjectRef::l_is_player(lua_State *L)
return 1;
}
+// is_player_connected(self)
+int ObjectRef::l_is_player_connected(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ Player *player = getplayer(ref);
+ lua_pushboolean(L, (player != NULL && player->peer_id != 0));
+ return 1;
+}
+
// get_player_name(self)
int ObjectRef::l_get_player_name(lua_State *L)
{
@@ -1148,6 +1158,7 @@ const luaL_reg ObjectRef::methods[] = {
luamethod(ObjectRef, get_luaentity),
// Player-only
luamethod(ObjectRef, is_player),
+ luamethod(ObjectRef, is_player_connected),
luamethod(ObjectRef, get_player_name),
luamethod(ObjectRef, get_look_dir),
luamethod(ObjectRef, get_look_pitch),
diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h
index 8fd6c8e71..4b4f5eff7 100644
--- a/src/script/lua_api/l_object.h
+++ b/src/script/lua_api/l_object.h
@@ -158,6 +158,9 @@ private:
// is_player(self)
static int l_is_player(lua_State *L);
+ // is_player_connected(self)
+ static int l_is_player_connected(lua_State *L);
+
// get_player_name(self)
static int l_get_player_name(lua_State *L);