From a06d4feee2124fe9df9f9345c0d28bf94c11194e Mon Sep 17 00:00:00 2001 From: Aaron Suen Date: Sat, 6 Mar 2021 18:47:23 -0500 Subject: [PATCH] Import new /admin command mod --- README.md | 1 + szutil_admin/README | 7 +++++++ szutil_admin/init.lua | 33 +++++++++++++++++++++++++++++++++ szutil_admin/mod.conf | 1 + 4 files changed, 42 insertions(+) create mode 100644 szutil_admin/README create mode 100644 szutil_admin/init.lua create mode 100644 szutil_admin/mod.conf diff --git a/README.md b/README.md index 3755f21..4751e52 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ A collection of miscellaneous mods for minetest providing "utility" functonality Each mod in the pack is effectively independent, with minimal or no dependencies (including on any assumed underlying game) and they can be enabled/disabled individually. Mods are distributed as a single pack because they have a single shared maintenance/release cycle. +- `szutil_admin`: Alternative to the "admin" command that lists moderation team members. - `szutil_chatsocket`: Expose in-game chat stream as a unix-domain socket for arbitrary chat integrations. - `szutil_chatsounds`: Configurable beep notifications for in-game chat. - `szutil_clocksync`: Synchronize in-game clock smoothly with real-time clock so users can log in at predictable times of day. diff --git a/szutil_admin/README b/szutil_admin/README new file mode 100644 index 0000000..4271e1e --- /dev/null +++ b/szutil_admin/README @@ -0,0 +1,7 @@ +------------------------------------------------------------------------ + +Replacement for the /admin command that lists any members of the server +moderation team that are online (configurable based on privs), or a +configurable fallback message if none are in-game. + +------------------------------------------------------------------------ diff --git a/szutil_admin/init.lua b/szutil_admin/init.lua new file mode 100644 index 0000000..553b859 --- /dev/null +++ b/szutil_admin/init.lua @@ -0,0 +1,33 @@ +-- LUALOCALS < --------------------------------------------------------- +local minetest, pairs, string, table + = minetest, pairs, string, table +local string_format, table_concat, table_sort + = string.format, table.concat, table.sort +-- LUALOCALS > --------------------------------------------------------- + +local modname = minetest.get_current_modname() + +local function conf(n) + return minetest.settings:get(modname .. "_" .. n) +end + +local modprivs = minetest.string_to_privs(conf("priv") or "basic_privs") +local hideprivs = minetest.string_to_privs(conf("hide") or "stealth") +local onlinemsg = conf("online") or "Moderators currently online: %s" +local offlinemsg = conf("offline") or "No moderators in-game currently; try public chat for help." + +minetest.registered_chatcommands.admin.func = function() + local names = {} + for _, player in pairs(minetest.get_connected_players()) do + local pname = player:get_player_name() + if minetest.check_player_privs(pname, modprivs) + and not minetest.check_player_privs(pname, hideprivs) then + names[#names + 1] = pname + end + end + if #names > 0 then + table_sort(names) + return true, string_format(onlinemsg, table_concat(names, ", ")) + end + return true, offlinemsg +end diff --git a/szutil_admin/mod.conf b/szutil_admin/mod.conf new file mode 100644 index 0000000..fa0b8d8 --- /dev/null +++ b/szutil_admin/mod.conf @@ -0,0 +1 @@ +name = szutil_admin