diff --git a/szutil_basics/init.lua b/szutil_basics/init.lua index ead90e6..2676b4f 100644 --- a/szutil_basics/init.lua +++ b/szutil_basics/init.lua @@ -1,8 +1,8 @@ -- LUALOCALS < --------------------------------------------------------- -local minetest, string - = minetest, string -local string_format - = string.format +local ipairs, minetest, string, table + = ipairs, minetest, string, table +local string_format, table_concat, table_remove + = string.format, table.concat, table.remove -- LUALOCALS > --------------------------------------------------------- -- Chat command to completely destroy a player account, including auth. @@ -29,6 +29,29 @@ minetest.register_chatcommand("destroy_player", { end }) +-- Chat command to write to the server log. +do + local allowed = {"verbose", "info", "action", "warning", "error"} + local allowed_idx = {} + for _, v in ipairs(allowed) do allowed_idx[v] = true end + local allowed_str = table_concat(allowed, ", ") + minetest.register_chatcommand("log", { + params = " ", + description = "Write any message to server log", + privs = {server = true}, + func = function(name, param) + local words = param:split(" ") + local severity = words[1] + table_remove(words, 1) + if not allowed_idx[severity] then + return false, "severity must be one of " .. allowed_str + end + minetest.log("action", name .. " used the log command") + minetest.log(severity, table_concat(words, " ")) + end + }) +end + -- Moderators and admins can always bypass player limits, -- important for emergency access. minetest.register_can_bypass_userlimit(function(name)