Add sscsm.register_on_sscsms_loaded.

This commit is contained in:
luk3yx 2020-02-14 22:32:12 +13:00
parent c1a90bbe66
commit e5edf9a003
2 changed files with 22 additions and 2 deletions

View File

@ -70,6 +70,12 @@ Registers a server-provided CSM with the following definition table.
This definition table must have `name` and either `code` or `file`.
### `sscsm.register_on_sscsms_loaded(function(name))`
Registers a function to be called when a client loads SSCSMs. Note that this
function will not work unless CSMs have the ability to send chat messages as it
relies on the SSCSM communication API described below.
### Communication with SSCSMs
SSCSM provides an API inspired by

View File

@ -278,9 +278,18 @@ minetest.override_chatcommand('admin', {
})
-- Add a callback for sscsm:com_test
local registered_on_loaded = {}
function sscsm.register_on_sscsms_loaded(func)
table.insert(registered_on_loaded, func)
end
sscsm.register_on_com_receive('sscsm:com_test', function(name, msg)
if type(msg) == 'table' and msg.flags == flags then
has_sscsms[name] = true
if type(msg) ~= 'table' or msg.flags ~= flags or has_sscsms[name] then
return
end
has_sscsms[name] = true
for _, func in ipairs(registered_on_loaded) do
func(name)
end
end)
@ -311,6 +320,11 @@ minetest.after(0, function()
-- If not, enter testing mode.
minetest.log('warning', '[SSCSM] Testing mode enabled.')
sscsm.register_on_sscsms_loaded(function(name)
minetest.log('action', '[SSCSM] register_on_sscsms_loaded callback ' ..
'fired for user ' .. name)
end)
sscsm.register({
name = 'sscsm:testing_cmds',
file = modpath .. '/sscsm_testing.lua',