99 lines
2.4 KiB
Lua
99 lines
2.4 KiB
Lua
--
|
|
-- SSCSM: Server-Sent Client-Side Mods proof-of-concept
|
|
-- Testing code
|
|
--
|
|
-- Copyright © 2019 by luk3yx
|
|
-- License: https://luk3yx.mit-license.org/@2019
|
|
--
|
|
|
|
--[==[
|
|
error("Bad")
|
|
]==]
|
|
|
|
-- 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)
|
|
|
|
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)
|
|
|
|
-- Create yay() to test dependencies
|
|
function yay()
|
|
print('yay() called')
|
|
end
|
|
|
|
print('assert = ' .. tostring(assert))
|
|
sscsm.every(60, function(param1)
|
|
assert(param1 == 123)
|
|
print('sscsm.every test called.')
|
|
end, 123)
|
|
|
|
sscsm.register_on_com_receive('sscsm:testing', function(msg)
|
|
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
|
|
end)
|