Fix issue #1009 (minetest.get_connected_players() returns non-existing players)
authorkwolekr <kwolekr@minetest.net>
Sun, 17 Nov 2013 07:57:40 +0000 (02:57 -0500)
committerkwolekr <kwolekr@minetest.net>
Sun, 17 Nov 2013 20:15:59 +0000 (15:15 -0500)
builtin/misc.lua
src/script/lua_api/l_object.cpp
src/script/lua_api/l_object.h

index a6a1718ad0afaec2dd7c60a9a394be41d43248e6..fd80aacf6d23d9f5533dc9281b3360930574f7ff 100644 (file)
@@ -53,7 +53,9 @@ end)
 function minetest.get_connected_players()
        local temp_table = {}
        for index, value in pairs(player_list) do
-               table.insert(temp_table, value)
+               if value:is_player_connected() then
+                       table.insert(temp_table, value)
+               end
        end
        return temp_table
 end
index c324ced1a390b45875029cff1f19ec3ead265b34..cbcaa40eb7cf173f3fe8b9d0560ef1122755cb55 100644 (file)
@@ -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),
index 8fd6c8e71f96458cb7b483da11ac66d3e65f45f9..4b4f5eff7e193745d771b53ca5510110758d334f 100644 (file)
@@ -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);