Skip to content

Commit f9f7600

Browse files
numberZeroJeija
authored andcommittedJul 9, 2016
Command block server crash fixed
Before that, command block would crash the server if activated when no players are online
1 parent 40487a6 commit f9f7600

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed
 

‎mesecons_commandblock/init.lua

+14-1
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,22 @@ local function receive_fields(pos, formname, fields, sender)
9393
end
9494

9595
local function resolve_commands(commands, pos)
96+
local players = minetest.get_connected_players()
97+
98+
-- No players online: remove all commands containing
99+
-- @nearest, @farthest and @random
100+
if #players == 0 then
101+
commands = commands:gsub("[^\r\n]+", function (line)
102+
if line:find("@nearest") then return "" end
103+
if line:find("@farthest") then return "" end
104+
if line:find("@random") then return "" end
105+
return line
106+
end)
107+
return commands
108+
end
109+
96110
local nearest, farthest = nil, nil
97111
local min_distance, max_distance = math.huge, -1
98-
local players = minetest.get_connected_players()
99112
for index, player in pairs(players) do
100113
local distance = vector.distance(pos, player:getpos())
101114
if distance < min_distance then

0 commit comments

Comments
 (0)
Please sign in to comment.