From 3ec2d176417f376f63016fbe74861e0bbec4b038 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 9 Dec 2022 23:22:50 +0100 Subject: [PATCH] Add `mcl_player_csm` mod to check if a player have the official CSM enabled --- mods/PLAYER/mcl_player_csm/init.lua | 37 +++++++++++++++++++++++++++++ mods/PLAYER/mcl_player_csm/mod.conf | 5 ++++ 2 files changed, 42 insertions(+) create mode 100644 mods/PLAYER/mcl_player_csm/init.lua create mode 100644 mods/PLAYER/mcl_player_csm/mod.conf diff --git a/mods/PLAYER/mcl_player_csm/init.lua b/mods/PLAYER/mcl_player_csm/init.lua new file mode 100644 index 000000000..3dfe26712 --- /dev/null +++ b/mods/PLAYER/mcl_player_csm/init.lua @@ -0,0 +1,37 @@ +mcl_player_csm = {} + +---@type table +local activated = {} + +---Return whatever player with specified name have official CSM enabled +---@param name string +---@return boolean? # `nil` if player not found, boolean overwise +function mcl_player_csm.is_enabled(name) + return activated[name] +end + +minetest.mod_channel_join("mcl_player_csm:activate") + +minetest.register_on_modchannel_message(function(channel_name, sender, message) + if channel_name == "mcl_player_csm:activate" and message == "activated" then + activated[sender] = true + end +end) + +minetest.register_on_joinplayer(function(player, last_login) + activated[player:get_player_name()] = false +end) + +minetest.register_on_leaveplayer(function(player, timed_out) + activated[player:get_player_name()] = nil +end) + +minetest.register_chatcommand("have_csm", { + description = "Show whatever player have official CSM enabled", + params = "[]", + privs = {debug = true}, + func = function(name, param) + local pname = param ~= "" and param or name + return true, "Player [" .. pname .. "]: " .. tostring(activated[pname]) + end +}) diff --git a/mods/PLAYER/mcl_player_csm/mod.conf b/mods/PLAYER/mcl_player_csm/mod.conf new file mode 100644 index 000000000..331a75036 --- /dev/null +++ b/mods/PLAYER/mcl_player_csm/mod.conf @@ -0,0 +1,5 @@ +name = mcl_player_csm +description = +depends = +optional_depends = +author = AFCM