Skip to content

Commit

Permalink
Fix issue #1009 (minetest.get_connected_players() returns non-existin…
Browse files Browse the repository at this point in the history
…g players)
  • Loading branch information
kwolekr committed Nov 17, 2013
1 parent a55c073 commit 86ef714
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion builtin/misc.lua
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/script/lua_api/l_object.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions src/script/lua_api/l_object.h
Expand Up @@ -158,6 +158,9 @@ class ObjectRef : public ModApiBase {
// 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);

Expand Down

0 comments on commit 86ef714

Please sign in to comment.