Skip to content

Commit

Permalink
Do not allow any worldedit_gui commands without privs
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed May 13, 2017
1 parent ea465f8 commit 38e9b42
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions worldedit_gui/init.lua
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Use `nil` for the `options` parameter to unregister the function associated with
Use `nil` for the `get_formspec` field to denote that the function does not have its own screen. Use `nil` for the `get_formspec` field to denote that the function does not have its own screen.
Use `nil` for the `privs` field to denote that no special privileges are required to use the function. The `privs` field may not be `nil`.
If the identifier is already registered to another function, it will be replaced by the new one. If the identifier is already registered to another function, it will be replaced by the new one.
Expand All @@ -24,6 +24,9 @@ The `on_select` function must not call `worldedit.show_page`
worldedit.pages = {} --mapping of identifiers to options worldedit.pages = {} --mapping of identifiers to options
local identifiers = {} --ordered list of identifiers local identifiers = {} --ordered list of identifiers
worldedit.register_gui_function = function(identifier, options) worldedit.register_gui_function = function(identifier, options)
if options.privs == nil or next(options.privs) == nil then
error("privs unset")
end
worldedit.pages[identifier] = options worldedit.pages[identifier] = options
table.insert(identifiers, identifier) table.insert(identifiers, identifier)
end end
Expand All @@ -46,7 +49,7 @@ worldedit.register_gui_handler = function(identifier, handler)


--ensure the player has permission to perform the action --ensure the player has permission to perform the action
local entry = worldedit.pages[identifier] local entry = worldedit.pages[identifier]
if entry and minetest.check_player_privs(name, entry.privs or {}) then if entry and minetest.check_player_privs(name, entry.privs) then
return handler(name, fields) return handler(name, fields)
end end
return false return false
Expand Down Expand Up @@ -272,7 +275,7 @@ worldedit.register_gui_handler("worldedit_gui", function(name, fields)
for identifier, entry in pairs(worldedit.pages) do --check for WorldEdit GUI main formspec button selection for identifier, entry in pairs(worldedit.pages) do --check for WorldEdit GUI main formspec button selection
if fields[identifier] and identifier ~= "worldedit_gui" then if fields[identifier] and identifier ~= "worldedit_gui" then
--ensure player has permission to perform action --ensure player has permission to perform action
local has_privs, missing_privs = minetest.check_player_privs(name, entry.privs or {}) local has_privs, missing_privs = minetest.check_player_privs(name, entry.privs)
if not has_privs then if not has_privs then
worldedit.player_notify(name, "you are not allowed to use this function (missing privileges: " .. table.concat(missing_privs, ", ") .. ")") worldedit.player_notify(name, "you are not allowed to use this function (missing privileges: " .. table.concat(missing_privs, ", ") .. ")")
return false return false
Expand Down

0 comments on commit 38e9b42

Please sign in to comment.