updated files
This commit is contained in:
parent
ca88374fbd
commit
74b18f38eb
12
.travis.yml
Normal file
12
.travis.yml
Normal 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
|
10
README.md
10
README.md
@ -1,4 +1,4 @@
|
||||
Mail mod for Minetest
|
||||
Mail mod for Minetest (ingame 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
|
||||
|
||||
# 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 forum topic: https://forum.minetest.net/viewtopic.php?t=14464
|
||||
* Old mod: https://cheapiesystems.com/git/mail/
|
||||
|
41
api.lua
41
api.lua
@ -13,49 +13,44 @@ mail sending function, can be invoked with one object argument (new api) or
|
||||
all 4 parameters (old compat version)
|
||||
see: "Mail format" api.md
|
||||
--]]
|
||||
function mail.send(sender, receiver, subject, body)
|
||||
function mail.send(src, dst, subject, body)
|
||||
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)
|
||||
m = sender
|
||||
|
||||
m = src
|
||||
else
|
||||
-- old format
|
||||
-- create mail from params
|
||||
|
||||
m = {}
|
||||
m.sender = sender
|
||||
m.receiver = receiver
|
||||
m.src = src
|
||||
m.dst = dst
|
||||
m.subject = subject
|
||||
m.body = body
|
||||
|
||||
end
|
||||
|
||||
m.unread = true
|
||||
|
||||
if not m.time then
|
||||
-- add timestamp
|
||||
m.time = os.time()
|
||||
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 .. "'")
|
||||
|
||||
local messages = mail.getMessages(m.receiver)
|
||||
local messages = mail.getMessages(m.dst)
|
||||
|
||||
table.insert(messages, 1, m)
|
||||
mail.setMessages(m.receiver, messages)
|
||||
table.insert(messages, 1, {
|
||||
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
|
||||
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 string.len(m.subject) > 30 then
|
||||
m.subject = string.sub(m.subject,1,27) .. "..."
|
||||
end
|
||||
minetest.chat_send_player(m.receiver,
|
||||
string.format(mail.receive_mail_message, m.sender, m.subject))
|
||||
minetest.chat_send_player(m.dst,
|
||||
string.format(mail.receive_mail_message, m.src, m.subject))
|
||||
end
|
||||
end
|
||||
|
||||
|
9
api.md
9
api.md
@ -4,8 +4,8 @@ The mail format in the api hooks
|
||||
|
||||
```lua
|
||||
mail = {
|
||||
sender = "source name",
|
||||
receiver = "destination name",
|
||||
src = "source name",
|
||||
dst = "destination name",
|
||||
subject = "subject line",
|
||||
body = "mail body",
|
||||
-- 8 attachments max
|
||||
@ -22,8 +22,8 @@ mail.send("source name", "destination name", "subject line", "mail body")
|
||||
New variant (1.1+)
|
||||
```lua
|
||||
mail.send({
|
||||
sender = "source name",
|
||||
receiver = "destination name",
|
||||
src = "source name",
|
||||
dst = "destination name",
|
||||
subject = "subject line",
|
||||
body = "mail body"
|
||||
})
|
||||
@ -47,7 +47,6 @@ The mail format on-disk
|
||||
[{
|
||||
"unread": true,
|
||||
"sender": "sender name",
|
||||
"receiver": "receiver name",
|
||||
"subject": "subject name",
|
||||
"body": "main\nmultiline\nbody",
|
||||
"time": 1551258349,
|
||||
|
7
init.lua
7
init.lua
@ -1,4 +1,11 @@
|
||||
mail = {
|
||||
|
||||
-- mark webmail fork for other mods
|
||||
fork = "webmail",
|
||||
|
||||
-- api version
|
||||
apiversion = 1.1,
|
||||
|
||||
-- mail directory
|
||||
maildir = minetest.get_worldpath().."/mails",
|
||||
|
||||
|
BIN
pics/ingame.png
Normal file
BIN
pics/ingame.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
106
webmail.lua
106
webmail.lua
@ -6,10 +6,9 @@ local Channel = dofile(MP .. "/util/channel.lua")
|
||||
local channel
|
||||
|
||||
-- auth request from webmail
|
||||
local function auth_handler(data)
|
||||
local auth = data.params
|
||||
local function auth_handler(auth)
|
||||
local handler = minetest.get_auth_handler()
|
||||
minetest.log("action", "[webmail] auth: " .. auth.playername)
|
||||
minetest.log("action", "[webmail] auth: " .. auth.name)
|
||||
|
||||
local success = false
|
||||
local banned = false
|
||||
@ -17,7 +16,7 @@ local function auth_handler(data)
|
||||
|
||||
if mail.webmail.disallow_banned_players and has_xban2_mod then
|
||||
-- check xban db
|
||||
local xbanentry = xban.find_entry(auth.playername)
|
||||
local xbanentry = xban.find_entry(auth.name)
|
||||
if xbanentry and xbanentry.banned then
|
||||
banned = true
|
||||
message = "Banned!"
|
||||
@ -26,24 +25,24 @@ local function auth_handler(data)
|
||||
|
||||
if not banned then
|
||||
-- check tan
|
||||
local tan = mail.tan[auth.playername]
|
||||
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.playername)
|
||||
if entry and minetest.check_password_entry(auth.playername, entry.password, auth.password) 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
|
||||
|
||||
channel.send({
|
||||
method = data.method,
|
||||
id = data.id,
|
||||
result = {
|
||||
type = "auth",
|
||||
data = {
|
||||
name = auth.name,
|
||||
success = success,
|
||||
message = message
|
||||
}
|
||||
@ -51,74 +50,47 @@ local function auth_handler(data)
|
||||
end
|
||||
|
||||
-- send request from webmail
|
||||
local function send_handler(data)
|
||||
local function send_handler(sendmail)
|
||||
-- send mail from webclient
|
||||
if not data.params then
|
||||
return
|
||||
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
|
||||
}
|
||||
})
|
||||
minetest.log("action", "[webmail] sending mail from webclient: " .. sendmail.src .. " -> " .. sendmail.dst)
|
||||
mail.send(sendmail)
|
||||
end
|
||||
|
||||
-- get player messages request from webmail
|
||||
local function get_player_messages_handler(data)
|
||||
local messages = mail.getMessages(data.params.playername)
|
||||
local function get_player_messages_handler(playername)
|
||||
local messages = mail.getMessages(playername)
|
||||
channel.send({
|
||||
method = data.method,
|
||||
id = data.id,
|
||||
result = messages
|
||||
type = "player-messages",
|
||||
playername = playername,
|
||||
data = messages
|
||||
})
|
||||
end
|
||||
|
||||
-- remove mail
|
||||
local function delete_mail_handler(data)
|
||||
local index = data.params.index
|
||||
local playername = data.params.playername
|
||||
|
||||
local function delete_mail_handler(playername, index)
|
||||
local messages = mail.getMessages(playername)
|
||||
if messages[index] then
|
||||
table.remove(messages, index)
|
||||
end
|
||||
mail.setMessages(playername, messages)
|
||||
-- TODO: check subject
|
||||
|
||||
channel.send({
|
||||
method = data.method,
|
||||
id = data.id,
|
||||
result = { success = true }
|
||||
})
|
||||
end
|
||||
|
||||
-- mark mail as read
|
||||
local function mark_mail_read_handler(data)
|
||||
local index = data.params.index
|
||||
local playername = data.params.playername
|
||||
local read = data.params.read
|
||||
|
||||
local function mark_mail_read_handler(playername, index)
|
||||
local messages = mail.getMessages(playername)
|
||||
|
||||
if messages[index] then
|
||||
messages[index].unread = not read
|
||||
messages[index].unread = false
|
||||
end
|
||||
mail.setMessages(playername, messages)
|
||||
-- TODO: check subject
|
||||
end
|
||||
|
||||
channel.send({
|
||||
method = data.method,
|
||||
id = data.id,
|
||||
result = { success = true }
|
||||
})
|
||||
-- mark mail as unread
|
||||
local function mark_mail_unread_handler(playername, index)
|
||||
local messages = mail.getMessages(playername)
|
||||
if messages[index] then
|
||||
messages[index].unread = true
|
||||
end
|
||||
mail.setMessages(playername, messages)
|
||||
end
|
||||
|
||||
function mail.webmail_send_hook(m)
|
||||
@ -135,21 +107,23 @@ function mail.webmail_init(http, url, key)
|
||||
})
|
||||
|
||||
channel.receive(function(data)
|
||||
if data.method == "auth" then
|
||||
auth_handler(data)
|
||||
if data.type == "auth" then
|
||||
auth_handler(data.data)
|
||||
|
||||
elseif data.method == "get-mails" then
|
||||
get_player_messages_handler(data)
|
||||
elseif data.type == "send" then
|
||||
send_handler(data.data) -- { src, dst, subject, body }
|
||||
|
||||
elseif data.method == "mark-mail-read" then
|
||||
mark_mail_read_handler(data)
|
||||
elseif data.type == "delete-mail" then
|
||||
delete_mail_handler(data.playername, data.index) -- index 1-based
|
||||
|
||||
elseif data.method == "delete-mail" then
|
||||
delete_mail_handler(data)
|
||||
elseif data.type == "mark-mail-read" then
|
||||
mark_mail_read_handler(data.playername, data.index) -- index 1-based
|
||||
|
||||
elseif data.method == "send" then
|
||||
send_handler(data)
|
||||
elseif data.type == "mark-mail-unread" then
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user