Add `mcl_player_csm` mod to check if a player have the official CSM enabled

This commit is contained in:
AFCMS 2022-12-09 23:22:50 +01:00
parent 2b46dd60c5
commit 3ec2d17641
Signed by untrusted user: AFCMS
GPG Key ID: 8720389A25B652E3
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,37 @@
mcl_player_csm = {}
---@type table<string, boolean>
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 = "[<name>]",
privs = {debug = true},
func = function(name, param)
local pname = param ~= "" and param or name
return true, "Player [" .. pname .. "]: " .. tostring(activated[pname])
end
})

View File

@ -0,0 +1,5 @@
name = mcl_player_csm
description =
depends =
optional_depends =
author = AFCM