updated files

This commit is contained in:
NatureFreshMilk 2019-09-16 08:15:43 +02:00
parent ca88374fbd
commit 74b18f38eb
7 changed files with 90 additions and 95 deletions

12
.travis.yml Normal file
View File

@ -0,0 +1,12 @@
language: generic
sudo: false
addons:
apt:
packages:
- luarocks
before_install:
- luarocks install --local luacheck
script:
- $HOME/.luarocks/bin/luacheck --no-color .
notifications:
email: false

View File

@ -1,4 +1,4 @@
Mail mod for Minetest Mail mod for Minetest (ingame mod)
====== ======
This is a fork of cheapies mail mod This is a fork of cheapies mail mod
@ -33,6 +33,14 @@ Mails can be deleted, marked as read or unread, replied to and forwarded to anot
See the "LICENSE" file See the "LICENSE" file
# Textures
* textures/email_mail.png (https://github.com/rubenwardy/email.git WTFPL)
# Contributors
* Cheapie (initial idea/project)
* Rubenwardy (lua/ui improvements)
# Old/Historic stuff # Old/Historic stuff
* Old forum topic: https://forum.minetest.net/viewtopic.php?t=14464 * Old forum topic: https://forum.minetest.net/viewtopic.php?t=14464
* Old mod: https://cheapiesystems.com/git/mail/ * Old mod: https://cheapiesystems.com/git/mail/

41
api.lua
View File

@ -13,49 +13,44 @@ mail sending function, can be invoked with one object argument (new api) or
all 4 parameters (old compat version) all 4 parameters (old compat version)
see: "Mail format" api.md see: "Mail format" api.md
--]] --]]
function mail.send(sender, receiver, subject, body) function mail.send(src, dst, subject, body)
local m local m
if receiver == nil and subject == nil and body == nil then if dst == nil and subject == nil and body == nil then
-- new format (one object param) -- new format (one object param)
m = sender m = src
else else
-- old format -- old format
-- create mail from params
m = {} m = {}
m.sender = sender m.src = src
m.receiver = receiver m.dst = dst
m.subject = subject m.subject = subject
m.body = body m.body = body
end
m.unread = true
if not m.time then
-- add timestamp
m.time = os.time()
end end
minetest.log("action", "[mail] '" .. m.sender .. "' sends mail to '" .. m.receiver .. minetest.log("action", "[mail] '" .. m.src .. "' sends mail to '" .. m.dst ..
"' with subject '" .. m.subject .. "' and body: '" .. m.body .. "'") "' with subject '" .. m.subject .. "' and body: '" .. m.body .. "'")
local messages = mail.getMessages(m.receiver) local messages = mail.getMessages(m.dst)
table.insert(messages, 1, m) table.insert(messages, 1, {
mail.setMessages(m.receiver, messages) unread = true,
sender = m.src,
subject = m.subject,
body = m.body,
time = os.time(),
})
mail.setMessages(m.dst, messages)
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name() local name = player:get_player_name()
if name == m.receiver then if name == m.dst then
if m.subject == "" then m.subject = "(No subject)" end if m.subject == "" then m.subject = "(No subject)" end
if string.len(m.subject) > 30 then if string.len(m.subject) > 30 then
m.subject = string.sub(m.subject,1,27) .. "..." m.subject = string.sub(m.subject,1,27) .. "..."
end end
minetest.chat_send_player(m.receiver, minetest.chat_send_player(m.dst,
string.format(mail.receive_mail_message, m.sender, m.subject)) string.format(mail.receive_mail_message, m.src, m.subject))
end end
end end

9
api.md
View File

@ -4,8 +4,8 @@ The mail format in the api hooks
```lua ```lua
mail = { mail = {
sender = "source name", src = "source name",
receiver = "destination name", dst = "destination name",
subject = "subject line", subject = "subject line",
body = "mail body", body = "mail body",
-- 8 attachments max -- 8 attachments max
@ -22,8 +22,8 @@ mail.send("source name", "destination name", "subject line", "mail body")
New variant (1.1+) New variant (1.1+)
```lua ```lua
mail.send({ mail.send({
sender = "source name", src = "source name",
receiver = "destination name", dst = "destination name",
subject = "subject line", subject = "subject line",
body = "mail body" body = "mail body"
}) })
@ -47,7 +47,6 @@ The mail format on-disk
[{ [{
"unread": true, "unread": true,
"sender": "sender name", "sender": "sender name",
"receiver": "receiver name",
"subject": "subject name", "subject": "subject name",
"body": "main\nmultiline\nbody", "body": "main\nmultiline\nbody",
"time": 1551258349, "time": 1551258349,

View File

@ -1,4 +1,11 @@
mail = { mail = {
-- mark webmail fork for other mods
fork = "webmail",
-- api version
apiversion = 1.1,
-- mail directory -- mail directory
maildir = minetest.get_worldpath().."/mails", maildir = minetest.get_worldpath().."/mails",

BIN
pics/ingame.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View File

@ -6,10 +6,9 @@ local Channel = dofile(MP .. "/util/channel.lua")
local channel local channel
-- auth request from webmail -- auth request from webmail
local function auth_handler(data) local function auth_handler(auth)
local auth = data.params
local handler = minetest.get_auth_handler() local handler = minetest.get_auth_handler()
minetest.log("action", "[webmail] auth: " .. auth.playername) minetest.log("action", "[webmail] auth: " .. auth.name)
local success = false local success = false
local banned = false local banned = false
@ -17,7 +16,7 @@ local function auth_handler(data)
if mail.webmail.disallow_banned_players and has_xban2_mod then if mail.webmail.disallow_banned_players and has_xban2_mod then
-- check xban db -- check xban db
local xbanentry = xban.find_entry(auth.playername) local xbanentry = xban.find_entry(auth.name)
if xbanentry and xbanentry.banned then if xbanentry and xbanentry.banned then
banned = true banned = true
message = "Banned!" message = "Banned!"
@ -26,24 +25,24 @@ local function auth_handler(data)
if not banned then if not banned then
-- check tan -- check tan
local tan = mail.tan[auth.playername] local tan = mail.tan[auth.name]
if tan ~= nil then if tan ~= nil then
success = tan == auth.password success = tan == auth.password
end end
-- check auth -- check auth
if not success then if not success then
local entry = handler.get_auth(auth.playername) local entry = handler.get_auth(auth.name)
if entry and minetest.check_password_entry(auth.playername, entry.password, auth.password) then if entry and minetest.check_password_entry(auth.name, entry.password, auth.password) then
success = true success = true
end end
end end
end end
channel.send({ channel.send({
method = data.method, type = "auth",
id = data.id, data = {
result = { name = auth.name,
success = success, success = success,
message = message message = message
} }
@ -51,74 +50,47 @@ local function auth_handler(data)
end end
-- send request from webmail -- send request from webmail
local function send_handler(data) local function send_handler(sendmail)
-- send mail from webclient -- send mail from webclient
if not data.params then minetest.log("action", "[webmail] sending mail from webclient: " .. sendmail.src .. " -> " .. sendmail.dst)
return mail.send(sendmail)
end
minetest.log("action", "[webmail] sending mail from webclient: " .. data.params.sender ..
" -> " .. data.params.receiver)
mail.send(data.params)
channel.send({
method = data.method,
id = data.id,
result = {
success = true
}
})
end end
-- get player messages request from webmail -- get player messages request from webmail
local function get_player_messages_handler(data) local function get_player_messages_handler(playername)
local messages = mail.getMessages(data.params.playername) local messages = mail.getMessages(playername)
channel.send({ channel.send({
method = data.method, type = "player-messages",
id = data.id, playername = playername,
result = messages data = messages
}) })
end end
-- remove mail -- remove mail
local function delete_mail_handler(data) local function delete_mail_handler(playername, index)
local index = data.params.index
local playername = data.params.playername
local messages = mail.getMessages(playername) local messages = mail.getMessages(playername)
if messages[index] then if messages[index] then
table.remove(messages, index) table.remove(messages, index)
end end
mail.setMessages(playername, messages) mail.setMessages(playername, messages)
-- TODO: check subject
channel.send({
method = data.method,
id = data.id,
result = { success = true }
})
end end
-- mark mail as read -- mark mail as read
local function mark_mail_read_handler(data) local function mark_mail_read_handler(playername, index)
local index = data.params.index
local playername = data.params.playername
local read = data.params.read
local messages = mail.getMessages(playername) local messages = mail.getMessages(playername)
if messages[index] then if messages[index] then
messages[index].unread = not read messages[index].unread = false
end end
mail.setMessages(playername, messages) mail.setMessages(playername, messages)
-- TODO: check subject end
channel.send({ -- mark mail as unread
method = data.method, local function mark_mail_unread_handler(playername, index)
id = data.id, local messages = mail.getMessages(playername)
result = { success = true } if messages[index] then
}) messages[index].unread = true
end
mail.setMessages(playername, messages)
end end
function mail.webmail_send_hook(m) function mail.webmail_send_hook(m)
@ -135,21 +107,23 @@ function mail.webmail_init(http, url, key)
}) })
channel.receive(function(data) channel.receive(function(data)
if data.method == "auth" then if data.type == "auth" then
auth_handler(data) auth_handler(data.data)
elseif data.method == "get-mails" then elseif data.type == "send" then
get_player_messages_handler(data) send_handler(data.data) -- { src, dst, subject, body }
elseif data.method == "mark-mail-read" then elseif data.type == "delete-mail" then
mark_mail_read_handler(data) delete_mail_handler(data.playername, data.index) -- index 1-based
elseif data.method == "delete-mail" then elseif data.type == "mark-mail-read" then
delete_mail_handler(data) mark_mail_read_handler(data.playername, data.index) -- index 1-based
elseif data.method == "send" then elseif data.type == "mark-mail-unread" then
send_handler(data) mark_mail_unread_handler(data.playername, data.index) -- index 1-based
elseif data.type == "player-messages" then
get_player_messages_handler(data.data)
end end
end) end)