Proof-of-concept Server-Sent CSMs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sscsm_testing.lua 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. --
  2. -- SSCSM: Server-Sent Client-Side Mods proof-of-concept
  3. -- Testing code
  4. --
  5. -- © 2019 by luk3yx
  6. --
  7. -- Make sure the minifier is sane
  8. a = 0
  9. --[[
  10. a = a + 1
  11. --]]
  12. -- [[
  13. a = a + 2
  14. --]]
  15. --;a = a + 4
  16. a = a + #('Test message with \'"quotes"\' .')
  17. assert(a == 37, 'The minifier is breaking code!')
  18. -- Create a few chatcommands
  19. sscsm.register_chatcommand('error_test', function(param)
  20. error('Testing: ' .. param)
  21. end)
  22. sscsm.register_chatcommand('sscsm', {
  23. func = function(param)
  24. return true, 'Hello from the SSCSM!'
  25. end,
  26. })
  27. sscsm.register_chatcommand('slap', function(param)
  28. if param:gsub(' ', '') == '' then
  29. return false, 'Invalid usage. Usage: ' .. minetest.colorize('#00ffff',
  30. '/slap <victim>') .. '.'
  31. end
  32. minetest.run_server_chatcommand('me', 'slaps ' .. param ..
  33. ' around a bit with a large trout.')
  34. end)
  35. -- A potentially useful example
  36. sscsm.register_chatcommand('msg', function(param)
  37. -- If you're actually using this, remove this.
  38. assert(param ~= '<error>', 'Test')
  39. local sendto, msg = param:match('^(%S+)%s(.+)$')
  40. if not sendto then
  41. return false, 'Invalid usage, see ' .. minetest.colorize('#00ffff',
  42. '/help msg') .. '.'
  43. end
  44. minetest.run_server_chatcommand('msg', param)
  45. end)
  46. sscsm.register_chatcommand('privs', function(param)
  47. if param == '' and minetest.get_privilege_list then
  48. local privs = {}
  49. for priv, n in pairs(minetest.get_privilege_list()) do
  50. if n then
  51. table.insert(privs, priv)
  52. end
  53. end
  54. table.sort(privs)
  55. return true, minetest.colorize('#00ffff', 'Privileges of ' ..
  56. minetest.localplayer:get_name() .. ': ') .. table.concat(privs, ' ')
  57. end
  58. minetest.run_server_chatcommand('privs', param)
  59. end)
  60. -- Create yay() to test dependencies
  61. function yay()
  62. print('yay() called')
  63. end