mirror of
https://github.com/minetest/minetest.git
synced 2024-09-27 15:00:30 +02:00
Optimized minetest.get_connected_players()
Instead of collecting all objects within a huge radius ( which could be a big value ), just register each player that connects and give back the current hold list.
This commit is contained in:
parent
3c4734d69a
commit
f12f74c99d
|
@ -40,15 +40,24 @@ function minetest.check_player_privs(name, privs)
|
||||||
return true, ""
|
return true, ""
|
||||||
end
|
end
|
||||||
|
|
||||||
function minetest.get_connected_players()
|
local player_list = {}
|
||||||
-- This could be optimized a bit, but leave that for later
|
|
||||||
local list = {}
|
minetest.register_on_joinplayer( function( player_ref )
|
||||||
for _, obj in pairs(minetest.get_objects_inside_radius({x=0,y=0,z=0}, 1000000)) do
|
if player_ref:is_player() then
|
||||||
if obj:is_player() then
|
table.insert( player_list, player_ref )
|
||||||
table.insert(list, obj)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return list
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer( function( player_ref )
|
||||||
|
for index, value in pairs( player_list ) do
|
||||||
|
if player_ref:get_player_name() == value:get_player_name() then
|
||||||
|
table.remove( player_list, index )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
function minetest.get_connected_players()
|
||||||
|
return player_list
|
||||||
end
|
end
|
||||||
|
|
||||||
function minetest.hash_node_position(pos)
|
function minetest.hash_node_position(pos)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user