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.

95 lines
2.3KB

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