Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Command block server crash fixed
Before that, command block would crash the server if activated when no
players are online
  • Loading branch information
numberZero authored and Jeija committed Jul 9, 2016
1 parent 40487a6 commit f9f7600
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion mesecons_commandblock/init.lua
Expand Up @@ -93,9 +93,22 @@ local function receive_fields(pos, formname, fields, sender)
end

local function resolve_commands(commands, pos)
local players = minetest.get_connected_players()

-- No players online: remove all commands containing
-- @nearest, @farthest and @random
if #players == 0 then
commands = commands:gsub("[^\r\n]+", function (line)
if line:find("@nearest") then return "" end
if line:find("@farthest") then return "" end
if line:find("@random") then return "" end
return line
end)
return commands
end

local nearest, farthest = nil, nil
local min_distance, max_distance = math.huge, -1
local players = minetest.get_connected_players()
for index, player in pairs(players) do
local distance = vector.distance(pos, player:getpos())
if distance < min_distance then
Expand Down

0 comments on commit f9f7600

Please sign in to comment.