webmail.lua 923 B

1234567891011121314151617181920212223242526272829303132
  1. local MP = minetest.get_modpath(minetest.get_current_modname())
  2. local Channel = dofile(MP .. "/util/channel.lua")
  3. function mail.webmail_init(http, url, key)
  4. mail.channel = Channel(http, url .. "/api/minetest/channel", {
  5. extra_headers = { "webmailkey: " .. key }
  6. })
  7. mail.channel.receive(function(data)
  8. if data.type == "auth" then
  9. mail.handlers.auth(data.data)
  10. elseif data.type == "send" then
  11. mail.handlers.send(data.data) -- { src, dst, subject, body }
  12. elseif data.type == "delete-mail" then
  13. mail.handlers.delete(data.playername, data.index) -- index 1-based
  14. elseif data.type == "mark-mail-read" then
  15. mail.handlers.mark_read(data.playername, data.index) -- index 1-based
  16. elseif data.type == "mark-mail-unread" then
  17. mail.handlers.mark_unread(data.playername, data.index) -- index 1-based
  18. elseif data.type == "player-messages" then
  19. mail.handlers.messages(data.data)
  20. end
  21. end)
  22. end