strip down to bare mail mod
This commit is contained in:
parent
3327be9bf4
commit
abe3c29e6d
@ -18,5 +18,5 @@ read_globals = {
|
||||
"unified_inventory", "default",
|
||||
|
||||
-- optional mods
|
||||
"xban", "QoS", "mtt"
|
||||
"mtt"
|
||||
}
|
||||
|
3
LICENSE
3
LICENSE
@ -1,9 +1,6 @@
|
||||
|
||||
The file textures/mail_button.png was created by bas080 and is licensed under the WTFPL.
|
||||
|
||||
Webmail component:
|
||||
WTFPL
|
||||
|
||||
All other files:
|
||||
|
||||
Copyright (c) 2016 Carter Kolwey ("Cheapie Systems")
|
||||
|
@ -22,7 +22,7 @@ Install it like any other mod: copy the directory `mail_mod` to your "worldmods"
|
||||
|
||||
## Webmail
|
||||
|
||||
See: https://github.com/minetest-mail/mail
|
||||
To provide a web-based interface to receive/send mails you can use the [mtui](https://github.com/minetest-go/mtui) project
|
||||
|
||||
# Commands/Howto
|
||||
|
||||
|
@ -1,27 +0,0 @@
|
||||
|
||||
local invmap = {}
|
||||
|
||||
|
||||
mail.getAttachmentInventory = function(playername)
|
||||
return invmap[playername]
|
||||
end
|
||||
|
||||
mail.getAttachmentInventoryName = function(playername)
|
||||
return "mail:" .. playername
|
||||
end
|
||||
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local inv = minetest.create_detached_inventory(mail.getAttachmentInventoryName(name), {})
|
||||
|
||||
invmap[name] = inv
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
invmap[name] = nil
|
||||
if minetest.remove_detached_inventory then
|
||||
minetest.remove_detached_inventory(mail.getAttachmentInventoryName(name))
|
||||
end
|
||||
end)
|
46
init.lua
46
init.lua
@ -1,28 +1,10 @@
|
||||
mail = {
|
||||
|
||||
-- mark webmail fork for other mods
|
||||
fork = "webmail",
|
||||
|
||||
-- api version
|
||||
apiversion = 1.1,
|
||||
|
||||
-- mail directory
|
||||
maildir = minetest.get_worldpath().."/mails",
|
||||
contactsdir = minetest.get_worldpath().."/mails/contacts",
|
||||
|
||||
-- allow item/node attachments
|
||||
allow_attachments = minetest.settings:get("mail.allow_attachments") == "true",
|
||||
|
||||
webmail = {
|
||||
-- disallow banned players in the webmail interface
|
||||
disallow_banned_players = minetest.settings:get("webmail.disallow_banned_players") == "true",
|
||||
|
||||
-- url and key to the webmail server
|
||||
url = minetest.settings:get("webmail.url"),
|
||||
key = minetest.settings:get("webmail.key")
|
||||
},
|
||||
|
||||
tan = {}
|
||||
contactsdir = minetest.get_worldpath().."/mails/contacts"
|
||||
}
|
||||
|
||||
|
||||
@ -30,38 +12,12 @@ local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||
dofile(MP .. "/util/normalize.lua")
|
||||
dofile(MP .. "/chatcommands.lua")
|
||||
dofile(MP .. "/migrate.lua")
|
||||
dofile(MP .. "/attachment.lua")
|
||||
dofile(MP .. "/hud.lua")
|
||||
dofile(MP .. "/storage.lua")
|
||||
dofile(MP .. "/api.lua")
|
||||
dofile(MP .. "/gui.lua")
|
||||
dofile(MP .. "/onjoin.lua")
|
||||
|
||||
-- optional webmail stuff below
|
||||
local http = QoS and QoS(minetest.request_http_api(), 2) or minetest.request_http_api()
|
||||
|
||||
if http then
|
||||
local webmail_url = mail.webmail.url
|
||||
local webmail_key = mail.webmail.key
|
||||
|
||||
if not webmail_url then error("webmail.url is not defined") end
|
||||
if not webmail_key then error("webmail.key is not defined") end
|
||||
|
||||
print("[mail] loading webmail-component with endpoint: " .. webmail_url)
|
||||
|
||||
mail.handlers = {}
|
||||
dofile(MP .. "/webmail/tan.lua")
|
||||
dofile(MP .. "/webmail/webmail.lua")
|
||||
dofile(MP .. "/webmail/hook.lua")
|
||||
dofile(MP .. "/webmail/handler_auth.lua")
|
||||
dofile(MP .. "/webmail/handler_send.lua")
|
||||
dofile(MP .. "/webmail/handler_messages.lua")
|
||||
dofile(MP .. "/webmail/handler_delete.lua")
|
||||
dofile(MP .. "/webmail/handler_mark_read.lua")
|
||||
dofile(MP .. "/webmail/handler_mark_unread.lua")
|
||||
mail.webmail_init(http, webmail_url, webmail_key)
|
||||
end
|
||||
|
||||
-- migrate storage
|
||||
mail.migrate()
|
||||
|
||||
|
2
mod.conf
2
mod.conf
@ -1,3 +1,3 @@
|
||||
name = mail
|
||||
description = ingame mail-system
|
||||
optional_depends = unified_inventory,default,xban2,qos,mtt
|
||||
optional_depends = unified_inventory,default,mtt
|
||||
|
@ -1,45 +0,0 @@
|
||||
local has_xban2_mod = minetest.get_modpath("xban2")
|
||||
|
||||
-- auth request from webmail
|
||||
function mail.handlers.auth(auth)
|
||||
local handler = minetest.get_auth_handler()
|
||||
minetest.log("action", "[webmail] auth: " .. auth.name)
|
||||
|
||||
local success = false
|
||||
local banned = false
|
||||
local message = ""
|
||||
|
||||
if mail.webmail.disallow_banned_players and has_xban2_mod then
|
||||
-- check xban db
|
||||
local xbanentry = xban.find_entry(auth.name)
|
||||
if xbanentry and xbanentry.banned then
|
||||
banned = true
|
||||
message = "Banned!"
|
||||
end
|
||||
end
|
||||
|
||||
if not banned then
|
||||
-- check tan
|
||||
local tan = mail.tan[auth.name]
|
||||
if tan ~= nil then
|
||||
success = tan == auth.password
|
||||
end
|
||||
|
||||
-- check auth
|
||||
if not success then
|
||||
local entry = handler.get_auth(auth.name)
|
||||
if entry and minetest.check_password_entry(auth.name, entry.password, auth.password) then
|
||||
success = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mail.channel.send({
|
||||
type = "auth",
|
||||
data = {
|
||||
name = auth.name,
|
||||
success = success,
|
||||
message = message
|
||||
}
|
||||
})
|
||||
end
|
@ -1,8 +0,0 @@
|
||||
-- remove mail
|
||||
function mail.handlers.delete(playername, index)
|
||||
local messages = mail.getMessages(playername)
|
||||
if messages[index] then
|
||||
table.remove(messages, index)
|
||||
end
|
||||
mail.setMessages(playername, messages)
|
||||
end
|
@ -1,9 +0,0 @@
|
||||
|
||||
-- mark mail as read
|
||||
function mail.handlers.mark_read(playername, index)
|
||||
local messages = mail.getMessages(playername)
|
||||
if messages[index] then
|
||||
messages[index].unread = false
|
||||
end
|
||||
mail.setMessages(playername, messages)
|
||||
end
|
@ -1,9 +0,0 @@
|
||||
|
||||
-- mark mail as unread
|
||||
function mail.handlers.mark_unread(playername, index)
|
||||
local messages = mail.getMessages(playername)
|
||||
if messages[index] then
|
||||
messages[index].unread = true
|
||||
end
|
||||
mail.setMessages(playername, messages)
|
||||
end
|
@ -1,9 +0,0 @@
|
||||
-- get player messages request from webmail
|
||||
function mail.handlers.messages(playername)
|
||||
local messages = mail.getMessages(playername)
|
||||
mail.channel.send({
|
||||
type = "player-messages",
|
||||
playername = playername,
|
||||
data = messages
|
||||
})
|
||||
end
|
@ -1,7 +0,0 @@
|
||||
|
||||
-- send request from webmail
|
||||
function mail.handlers.send(sendmail)
|
||||
-- send mail from webclient
|
||||
minetest.log("action", "[webmail] sending mail from webclient: " .. sendmail.from .. " -> " .. sendmail.to)
|
||||
mail.send(sendmail)
|
||||
end
|
@ -1,8 +0,0 @@
|
||||
function mail.webmail_send_hook(m)
|
||||
mail.channel.send({
|
||||
type = "new-message",
|
||||
data = m
|
||||
})
|
||||
end
|
||||
|
||||
mail.register_on_receive(mail.webmail_send_hook)
|
@ -1,16 +0,0 @@
|
||||
|
||||
|
||||
minetest.register_chatcommand("webmail_tan", {
|
||||
description = "generates a tan (temporary access number) for the webmail access",
|
||||
func = function(name)
|
||||
local tan = "" .. math.random(1000, 9999)
|
||||
mail.tan[name] = tan
|
||||
|
||||
return true, "Your tan is " .. tan .. ", it will expire upon leaving the game"
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
mail.tan[name] = nil
|
||||
end)
|
@ -1,31 +0,0 @@
|
||||
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||
local Channel = dofile(MP .. "/util/channel.lua")
|
||||
|
||||
|
||||
function mail.webmail_init(http, url, key)
|
||||
mail.channel = Channel(http, url .. "/api/minetest/channel", {
|
||||
extra_headers = { "webmailkey: " .. key }
|
||||
})
|
||||
|
||||
mail.channel.receive(function(data)
|
||||
if data.type == "auth" then
|
||||
mail.handlers.auth(data.data)
|
||||
|
||||
elseif data.type == "send" then
|
||||
mail.handlers.send(data.data) -- { src, dst, subject, body }
|
||||
|
||||
elseif data.type == "delete-mail" then
|
||||
mail.handlers.delete(data.playername, data.index) -- index 1-based
|
||||
|
||||
elseif data.type == "mark-mail-read" then
|
||||
mail.handlers.mark_read(data.playername, data.index) -- index 1-based
|
||||
|
||||
elseif data.type == "mark-mail-unread" then
|
||||
mail.handlers.mark_unread(data.playername, data.index) -- index 1-based
|
||||
|
||||
elseif data.type == "player-messages" then
|
||||
mail.handlers.messages(data.data)
|
||||
|
||||
end
|
||||
end)
|
||||
end
|
Loading…
Reference in New Issue
Block a user