2019-07-07 08:49:59 +02:00
|
|
|
--
|
|
|
|
-- SSCSM: Server-Sent Client-Side Mods proof-of-concept
|
|
|
|
-- Testing code
|
|
|
|
--
|
2019-10-17 08:09:44 +02:00
|
|
|
-- Copyright © 2019 by luk3yx
|
2020-10-01 02:51:49 +02:00
|
|
|
-- License: https://luk3yx.mit-license.org/@2019
|
2019-07-07 08:49:59 +02:00
|
|
|
--
|
|
|
|
|
2019-10-15 06:31:03 +02:00
|
|
|
--[==[
|
|
|
|
error("Bad")
|
|
|
|
]==]
|
|
|
|
|
2019-07-07 08:49:59 +02:00
|
|
|
-- Make sure the minifier is sane
|
|
|
|
a = 0
|
|
|
|
--[[
|
|
|
|
a = a + 1
|
|
|
|
--]]
|
|
|
|
|
|
|
|
-- [[
|
|
|
|
a = a + 2
|
|
|
|
--]]
|
|
|
|
|
|
|
|
--;a = a + 4
|
|
|
|
|
|
|
|
a = a + #('Test message with \'"quotes"\' .')
|
|
|
|
|
|
|
|
assert(a == 37, 'The minifier is breaking code!')
|
|
|
|
|
|
|
|
-- Create a few chatcommands
|
|
|
|
sscsm.register_chatcommand('error_test', function(param)
|
|
|
|
error('Testing: ' .. param)
|
|
|
|
end)
|
|
|
|
|
|
|
|
sscsm.register_chatcommand('sscsm', {
|
|
|
|
func = function(param)
|
|
|
|
return true, 'Hello from the SSCSM!'
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
sscsm.register_chatcommand('slap', function(param)
|
|
|
|
if param:gsub(' ', '') == '' then
|
|
|
|
return false, 'Invalid usage. Usage: ' .. minetest.colorize('#00ffff',
|
|
|
|
'/slap <victim>') .. '.'
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.run_server_chatcommand('me', 'slaps ' .. param ..
|
|
|
|
' around a bit with a large trout.')
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- A potentially useful example
|
|
|
|
sscsm.register_chatcommand('msg', function(param)
|
|
|
|
-- If you're actually using this, remove this.
|
|
|
|
assert(param ~= '<error>', 'Test')
|
|
|
|
|
|
|
|
local sendto, msg = param:match('^(%S+)%s(.+)$')
|
|
|
|
if not sendto then
|
|
|
|
return false, 'Invalid usage, see ' .. minetest.colorize('#00ffff',
|
|
|
|
'/help msg') .. '.'
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.run_server_chatcommand('msg', param)
|
|
|
|
end)
|
|
|
|
|
2019-07-13 06:09:58 +02:00
|
|
|
sscsm.register_chatcommand('privs', function(param)
|
|
|
|
if param == '' and minetest.get_privilege_list then
|
|
|
|
local privs = {}
|
|
|
|
for priv, n in pairs(minetest.get_privilege_list()) do
|
|
|
|
if n then
|
|
|
|
table.insert(privs, priv)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.sort(privs)
|
|
|
|
return true, minetest.colorize('#00ffff', 'Privileges of ' ..
|
|
|
|
minetest.localplayer:get_name() .. ': ') .. table.concat(privs, ' ')
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.run_server_chatcommand('privs', param)
|
|
|
|
end)
|
|
|
|
|
2019-07-07 08:49:59 +02:00
|
|
|
-- Create yay() to test dependencies
|
|
|
|
function yay()
|
|
|
|
print('yay() called')
|
|
|
|
end
|
2019-11-05 01:43:28 +01:00
|
|
|
|
|
|
|
print('assert = ' .. tostring(assert))
|
|
|
|
sscsm.every(60, function(param1)
|
|
|
|
assert(param1 == 123)
|
|
|
|
print('sscsm.every test called.')
|
|
|
|
end, 123)
|
2019-12-28 22:44:41 +01:00
|
|
|
|
|
|
|
sscsm.register_on_com_receive('sscsm:testing', function(msg)
|
2020-02-14 09:17:46 +01:00
|
|
|
if #msg > 400 then
|
|
|
|
print('Got large message of length ' .. #msg .. ' from the server')
|
|
|
|
else
|
|
|
|
sscsm.com_send('sscsm:testing', msg)
|
|
|
|
print('Got ' .. minetest.serialize(msg):sub(8) .. ' from the server')
|
|
|
|
end
|
2019-12-28 22:44:41 +01:00
|
|
|
end)
|