Use core namespace instead of minetest

This commit is contained in:
Athozus 2024-10-25 23:00:27 +02:00
parent 8a992b7a29
commit 030a7a3fe8
No known key found for this signature in database
GPG key ID: B50895022E8484BF
29 changed files with 135 additions and 135 deletions

View file

@ -69,7 +69,7 @@ function mail.send(m)
extra_log = "" extra_log = ""
end end
minetest.log("action", f("[mail] %q send mail to %q%s with subject %q and body %q", core.log("action", f("[mail] %q send mail to %q%s with subject %q and body %q",
m.from, m.to, extra_log, m.subject, m.body m.from, m.to, extra_log, m.subject, m.body
)) ))
@ -122,7 +122,7 @@ function mail.save_draft(m)
-- defaults -- defaults
m.subject = m.subject or "(No subject)" m.subject = m.subject or "(No subject)"
minetest.log("verbose", f("[mail] %q saves draft with subject %q and body %q", core.log("verbose", f("[mail] %q saves draft with subject %q and body %q",
m.from, m.subject, m.body m.from, m.subject, m.body
)) ))

View file

@ -1,4 +1,4 @@
minetest.register_chatcommand("mail",{ core.register_chatcommand("mail",{
description = "Open the mail interface", description = "Open the mail interface",
func = function(name, param) func = function(name, param)
if #param > 0 then -- if param is not empty if #param > 0 then -- if param is not empty

View file

@ -1,5 +1,5 @@
if minetest.get_modpath("unified_inventory") then if core.get_modpath("unified_inventory") then
unified_inventory.register_button("mail", { unified_inventory.register_button("mail", {
type = "image", type = "image",
@ -11,7 +11,7 @@ if minetest.get_modpath("unified_inventory") then
}) })
end end
if minetest.get_modpath("sfinv_buttons") then if core.get_modpath("sfinv_buttons") then
sfinv_buttons.register_button("mail", { sfinv_buttons.register_button("mail", {
title = "Mail", title = "Mail",
image = "mail_button.png", image = "mail_button.png",

View file

@ -1,7 +1,7 @@
local huddata = {} local huddata = {}
minetest.register_on_joinplayer(function(player) core.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
local data = {} local data = {}
@ -27,7 +27,7 @@ minetest.register_on_joinplayer(function(player)
huddata[name] = data huddata[name] = data
end) end)
minetest.register_on_leaveplayer(function(player) core.register_on_leaveplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
huddata[name] = nil huddata[name] = nil
end) end)
@ -35,7 +35,7 @@ end)
function mail.hud_update(playername, messages) function mail.hud_update(playername, messages)
local data = huddata[playername] local data = huddata[playername]
local player = minetest.get_player_by_name(playername) local player = core.get_player_by_name(playername)
if not data or not player then if not data or not player then
return return

View file

@ -3,10 +3,10 @@ mail = {
version = 3, version = 3,
-- mod storage -- mod storage
storage = minetest.get_mod_storage(), storage = core.get_mod_storage(),
-- translation -- translation
S = minetest.get_translator(minetest.get_current_modname()), S = core.get_translator(core.get_current_modname()),
-- ui theme prepend -- ui theme prepend
theme = "", theme = "",
@ -39,12 +39,12 @@ mail = {
message_drafts = {} message_drafts = {}
} }
if minetest.get_modpath("default") then if core.get_modpath("default") then
mail.theme = default.gui_bg .. default.gui_bg_img mail.theme = default.gui_bg .. default.gui_bg_img
end end
-- sub files -- sub files
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = core.get_modpath(core.get_current_modname())
dofile(MP .. "/util/init.lua") dofile(MP .. "/util/init.lua")
dofile(MP .. "/chatcommands.lua") dofile(MP .. "/chatcommands.lua")
dofile(MP .. "/migrate.lua") dofile(MP .. "/migrate.lua")
@ -60,7 +60,7 @@ dofile(MP .. "/ui/init.lua")
-- migrate storage -- migrate storage
mail.migrate() mail.migrate()
if minetest.get_modpath("mtt") then if core.get_modpath("mtt") then
dofile(MP .. "/mtt.lua") dofile(MP .. "/mtt.lua")
dofile(MP .. "/api.spec.lua") dofile(MP .. "/api.spec.lua")
dofile(MP .. "/migrate.spec.lua") dofile(MP .. "/migrate.spec.lua")

View file

@ -2,12 +2,12 @@ local STORAGE_VERSION_KEY = "@@version"
local CURRENT_VERSION = 3.1 local CURRENT_VERSION = 3.1
local function migrate_v1_to_v3() local function migrate_v1_to_v3()
local file = io.open(minetest.get_worldpath().."/mail.db", "r") local file = io.open(core.get_worldpath().."/mail.db", "r")
assert(file) assert(file)
print("[mail] Migration from v1 to v3 database") print("[mail] Migration from v1 to v3 database")
local data = file:read("*a") local data = file:read("*a")
local oldmails = minetest.deserialize(data) local oldmails = core.deserialize(data)
file:close() file:close()
for name, oldmessages in pairs(oldmails) do for name, oldmessages in pairs(oldmails) do
@ -28,7 +28,7 @@ local function migrate_v1_to_v3()
-- rename file -- rename file
print("[mail,v1] migration done, renaming old mail.db") print("[mail,v1] migration done, renaming old mail.db")
os.rename(minetest.get_worldpath().."/mail.db", minetest.get_worldpath().."/mail.db.old") os.rename(core.get_worldpath().."/mail.db", core.get_worldpath().."/mail.db.old")
end end
local function read_json_file(path) local function read_json_file(path)
@ -36,7 +36,7 @@ local function read_json_file(path)
local content = {} local content = {}
if file then if file then
local json = file:read("*a") local json = file:read("*a")
content = minetest.parse_json(json or "[]") or {} content = core.parse_json(json or "[]") or {}
file:close() file:close()
end end
return content return content
@ -44,13 +44,13 @@ end
-- migrate from v2 to v3 database -- migrate from v2 to v3 database
local function migrate_v2_to_v3() local function migrate_v2_to_v3()
local maildir = minetest.get_worldpath().."/mails" local maildir = core.get_worldpath().."/mails"
minetest.mkdir(maildir) -- if necessary (eg. first login) core.mkdir(maildir) -- if necessary (eg. first login)
print("[mail] Migration from v2 to v3 database") print("[mail] Migration from v2 to v3 database")
-- defer execution until auth-handler ready (first server-step) -- defer execution until auth-handler ready (first server-step)
minetest.after(0, function() core.after(0, function()
for playername, _ in minetest.get_auth_handler().iterate() do for playername, _ in core.get_auth_handler().iterate() do
local entry = mail.get_storage_entry(playername) local entry = mail.get_storage_entry(playername)
local player_contacts = read_json_file(maildir .. "/contacts/" .. playername .. ".json") local player_contacts = read_json_file(maildir .. "/contacts/" .. playername .. ".json")
@ -110,7 +110,7 @@ local function is_uuid_existing(uuid)
end end
end end
else else
for p, _ in minetest.get_auth_handler().iterate() do for p, _ in core.get_auth_handler().iterate() do
local result = search_boxes(p, boxes, uuid) local result = search_boxes(p, boxes, uuid)
if result then return result end if result then return result end
end end
@ -168,7 +168,7 @@ local function fix_box_duplicate_uuids(playername, box)
end end
end end
else else
for p, _ in minetest.get_auth_handler().iterate() do for p, _ in core.get_auth_handler().iterate() do
replace_other_player_message_uuid(p, m, uuid, new_uuid) replace_other_player_message_uuid(p, m, uuid, new_uuid)
end end
end end
@ -195,8 +195,8 @@ local function repair_storage()
end end
end end
else else
minetest.after(0, function() core.after(0, function()
for p, _ in minetest.get_auth_handler().iterate() do for p, _ in core.get_auth_handler().iterate() do
fix_player_duplicate_uuids(p) fix_player_duplicate_uuids(p)
end end
end) end)
@ -213,7 +213,7 @@ function mail.migrate()
end end
-- check for v1 storage -- check for v1 storage
local v1_file = io.open(minetest.get_worldpath().."/mail.db", "r") local v1_file = io.open(core.get_worldpath().."/mail.db", "r")
if v1_file then if v1_file then
-- v1 to v3 -- v1 to v3
migrate_v1_to_v3() migrate_v1_to_v3()

View file

@ -1,7 +1,7 @@
mtt.register("setup", function(callback) mtt.register("setup", function(callback)
-- create test players -- create test players
local auth_handler = minetest.get_auth_handler() local auth_handler = core.get_auth_handler()
auth_handler.set_password("player1", "") auth_handler.set_password("player1", "")
auth_handler.set_password("player2", "") auth_handler.set_password("player2", "")
auth_handler.set_password("player3", "") auth_handler.set_password("player3", "")

View file

@ -1,8 +1,8 @@
-- translation -- translation
local S = mail.S local S = mail.S
minetest.register_on_joinplayer(function(player) core.register_on_joinplayer(function(player)
minetest.after(2, function(name) core.after(2, function(name)
local entry = mail.get_storage_entry(name) local entry = mail.get_storage_entry(name)
local messages = entry.inbox local messages = entry.inbox
mail.hud_update(name, messages) mail.hud_update(name, messages)
@ -16,8 +16,8 @@ minetest.register_on_joinplayer(function(player)
end end
if unreadcount > 0 and mail.get_setting(name, "onjoin_notifications") then if unreadcount > 0 and mail.get_setting(name, "onjoin_notifications") then
minetest.chat_send_player(name, core.chat_send_player(name,
minetest.colorize(mail.get_color("new"), "(" .. unreadcount .. ") " .. S("You have mail! Type /mail to read"))) core.colorize(mail.get_color("new"), "(" .. unreadcount .. ") " .. S("You have mail! Type /mail to read")))
end end
end, player:get_player_name()) end, player:get_player_name())
end) end)

View file

@ -1,7 +1,7 @@
-- translation -- translation
local S = mail.S local S = mail.S
local has_canonical_name = minetest.get_modpath("canonical_name") local has_canonical_name = core.get_modpath("canonical_name")
mail.register_on_player_receive(function(name, msg) mail.register_on_player_receive(function(name, msg)
-- add to inbox -- add to inbox
@ -13,16 +13,16 @@ mail.register_on_player_receive(function(name, msg)
local mail_alert = S("You have a new message from @1! Subject: @2", msg.from, msg.subject) .. local mail_alert = S("You have a new message from @1! Subject: @2", msg.from, msg.subject) ..
"\n" .. S("To view it, type /mail") "\n" .. S("To view it, type /mail")
local inventory_alert = S("You could also use the button in your inventory.") local inventory_alert = S("You could also use the button in your inventory.")
local player = minetest.get_player_by_name(name) local player = core.get_player_by_name(name)
if player then if player then
if mail.get_setting(name, "chat_notifications") == true then if mail.get_setting(name, "chat_notifications") == true then
minetest.chat_send_player(name, mail_alert) core.chat_send_player(name, mail_alert)
if minetest.get_modpath("unified_inventory") or minetest.get_modpath("sfinv_buttons") then if core.get_modpath("unified_inventory") or core.get_modpath("sfinv_buttons") then
minetest.chat_send_player(name, inventory_alert) core.chat_send_player(name, inventory_alert)
end end
end end
if mail.get_setting(name, "sound_notifications") == true then if mail.get_setting(name, "sound_notifications") == true then
minetest.sound_play("mail_notif", {to_player=name}) core.sound_play("mail_notif", {to_player=name})
end end
local receiver_entry = mail.get_storage_entry(name) local receiver_entry = mail.get_storage_entry(name)
local receiver_messages = receiver_entry.inbox local receiver_messages = receiver_entry.inbox
@ -31,7 +31,7 @@ mail.register_on_player_receive(function(name, msg)
end) end)
mail.register_recipient_handler(function(_, pname) mail.register_recipient_handler(function(_, pname)
if not minetest.player_exists(pname) then if not core.player_exists(pname) then
return nil return nil
end end
return true, function(msg) return true, function(msg)

View file

@ -31,7 +31,7 @@ function mail.get_storage_entry(playername)
entry = populate_entry() entry = populate_entry()
else else
-- deserialize existing entry -- deserialize existing entry
local e = minetest.parse_json(str) local e = core.parse_json(str)
entry = populate_entry(e) entry = populate_entry(e)
end end
@ -55,7 +55,7 @@ end
local function save_worker() local function save_worker()
for key, entry in pairs(save_queued_entries) do for key, entry in pairs(save_queued_entries) do
-- write to backend -- write to backend
mail.storage:set_string(key, minetest.write_json(entry)) mail.storage:set_string(key, core.write_json(entry))
end end
-- clear queue -- clear queue
@ -65,13 +65,13 @@ local function save_worker()
cache = {} cache = {}
-- save every second -- save every second
minetest.after(1, save_worker) core.after(1, save_worker)
end end
-- start save-worker loop -- start save-worker loop
save_worker() save_worker()
-- save on shutdown -- save on shutdown
minetest.register_on_shutdown(save_worker) core.register_on_shutdown(save_worker)
-- get a mail by id from the players in- or outbox -- get a mail by id from the players in- or outbox
function mail.get_message(playername, msg_id) function mail.get_message(playername, msg_id)
@ -392,20 +392,20 @@ local function extract_maillists_main(receivers, maillists_owner, expanded_recei
for _, receiver in pairs(receivers) do for _, receiver in pairs(receivers) do
if seen[receiver] then if seen[receiver] then
-- Do not add/expand this receiver as it is already seen -- Do not add/expand this receiver as it is already seen
minetest.log("verbose", ("mail: ignoring duplicate receiver %q during maillist expansion"):format(receiver)) core.log("verbose", ("mail: ignoring duplicate receiver %q during maillist expansion"):format(receiver))
elseif string.find(receiver, "^@") then elseif string.find(receiver, "^@") then
seen[receiver] = true seen[receiver] = true
local listname = string.sub(receiver, 2) local listname = string.sub(receiver, 2)
local maillist = mail.get_maillist_by_name(maillists_owner, listname) local maillist = mail.get_maillist_by_name(maillists_owner, listname)
if maillist then if maillist then
minetest.log("verbose", ("mail: expanding maillist %q"):format(listname)) core.log("verbose", ("mail: expanding maillist %q"):format(listname))
for _, entry in ipairs(maillist.players) do for _, entry in ipairs(maillist.players) do
extract_maillists_main(entry, maillists_owner, expanded_receivers, seen) extract_maillists_main(entry, maillists_owner, expanded_receivers, seen)
end end
end end
else else
seen[receiver] = true seen[receiver] = true
minetest.log("verbose", ("mail: adding %q to receiver list during maillist expansion"):format(receiver)) core.log("verbose", ("mail: adding %q to receiver list during maillist expansion"):format(receiver))
table.insert(expanded_receivers, receiver) table.insert(expanded_receivers, receiver)
end end
end end

View file

@ -119,10 +119,10 @@ function mail.show_about(name)
formspec = formspec .. mail.theme formspec = formspec .. mail.theme
minetest.show_formspec(name, FORMNAME, formspec) core.show_formspec(name, FORMNAME, formspec)
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then if formname ~= FORMNAME then
return return
end end
@ -141,10 +141,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
mail.show_about(playername) mail.show_about(playername)
elseif fields.github then elseif fields.github then
minetest.chat_send_player(playername, "https://github.com/mt-mods/mail") core.chat_send_player(playername, "https://github.com/mt-mods/mail")
elseif fields.contentdb then elseif fields.contentdb then
minetest.chat_send_player(playername, "https://content.minetest.net/packages/mt-mods/mail") core.chat_send_player(playername, "https://content.minetest.net/packages/mt-mods/mail")
elseif fields.contributor_grouping then elseif fields.contributor_grouping then
mail.selected_idxs.contributor_grouping[playername] = fields.contributor_grouping mail.selected_idxs.contributor_grouping[playername] = fields.contributor_grouping
mail.show_about(playername) mail.show_about(playername)

View file

@ -20,18 +20,18 @@ function mail.show_compose(name, to, subject, body, cc, bcc, id)
]] .. mail.theme ]] .. mail.theme
formspec = string.format(formspec, formspec = string.format(formspec,
minetest.formspec_escape(to) or "", core.formspec_escape(to) or "",
minetest.formspec_escape(cc) or "", core.formspec_escape(cc) or "",
minetest.formspec_escape(bcc) or "", core.formspec_escape(bcc) or "",
minetest.formspec_escape(subject) or "", core.formspec_escape(subject) or "",
minetest.formspec_escape(body) or "") core.formspec_escape(body) or "")
mail.selected_idxs.message[name] = id or mail.new_uuid() mail.selected_idxs.message[name] = id or mail.new_uuid()
minetest.show_formspec(name, FORMNAME, formspec) core.show_formspec(name, FORMNAME, formspec)
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then if formname ~= FORMNAME then
return return
end end
@ -63,7 +63,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
body = fields.body, body = fields.body,
}) })
if not success then if not success then
minetest.chat_send_player(name, err) core.chat_send_player(name, err)
return return
end end
@ -87,7 +87,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
end end
minetest.after(0.5, function() core.after(0.5, function()
mail.selected_idxs.drafts[name] = nil mail.selected_idxs.drafts[name] = nil
mail.show_mail_menu(name) mail.show_mail_menu(name)
end) end)

View file

@ -14,10 +14,10 @@ local contacts_formspec = "size[8,9;]" .. mail.theme .. [[
function mail.show_contacts(name) function mail.show_contacts(name)
local formspec = contacts_formspec .. mail.compile_contact_list(name, mail.selected_idxs.contacts[name]) local formspec = contacts_formspec .. mail.compile_contact_list(name, mail.selected_idxs.contacts[name])
minetest.show_formspec(name, FORMNAME, formspec) core.show_formspec(name, FORMNAME, formspec)
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then if formname ~= FORMNAME then
return return
end end
@ -26,7 +26,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local contacts = mail.get_contacts(name) local contacts = mail.get_contacts(name)
if fields.contacts then if fields.contacts then
local evt = minetest.explode_table_event(fields.contacts) local evt = core.explode_table_event(fields.contacts)
for k, _, i in mail.pairs_by_keys(contacts) do for k, _, i in mail.pairs_by_keys(contacts) do
if i == evt.row - 1 then if i == evt.row - 1 then
mail.selected_idxs.contacts[name] = tonumber(k) mail.selected_idxs.contacts[name] = tonumber(k)

View file

@ -32,14 +32,14 @@ function mail.show_drafts(name)
for _, message in ipairs(messages) do for _, message in ipairs(messages) do
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
formspec[#formspec + 1] = minetest.formspec_escape(message.to) formspec[#formspec + 1] = core.formspec_escape(message.to)
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
if message.subject ~= "" then if message.subject ~= "" then
if string.len(message.subject) > 30 then if string.len(message.subject) > 30 then
formspec[#formspec + 1] = minetest.formspec_escape(string.sub(message.subject, 1, 27)) formspec[#formspec + 1] = core.formspec_escape(string.sub(message.subject, 1, 27))
formspec[#formspec + 1] = "..." formspec[#formspec + 1] = "..."
else else
formspec[#formspec + 1] = minetest.formspec_escape(message.subject) formspec[#formspec + 1] = core.formspec_escape(message.subject)
end end
else else
formspec[#formspec + 1] = S("(No subject)") formspec[#formspec + 1] = S("(No subject)")
@ -53,5 +53,5 @@ function mail.show_drafts(name)
else else
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No drafts") .. "]" formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No drafts") .. "]"
end end
minetest.show_formspec(name, "mail:drafts", table.concat(formspec, "")) core.show_formspec(name, "mail:drafts", table.concat(formspec, ""))
end end

View file

@ -24,12 +24,12 @@ function mail.show_edit_contact(name, contact_name, note, illegal_name_hint)
end end
formspec = formspec .. mail.theme formspec = formspec .. mail.theme
formspec = string.format(formspec, formspec = string.format(formspec,
minetest.formspec_escape(contact_name or ""), core.formspec_escape(contact_name or ""),
minetest.formspec_escape(note or "")) core.formspec_escape(note or ""))
minetest.show_formspec(name, FORMNAME, formspec) core.show_formspec(name, FORMNAME, formspec)
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then if formname ~= FORMNAME then
return return
end end

View file

@ -25,13 +25,13 @@ function mail.show_edit_maillist(playername, maillist_name, desc, players, illeg
end end
formspec = formspec .. mail.theme formspec = formspec .. mail.theme
formspec = string.format(formspec, formspec = string.format(formspec,
minetest.formspec_escape(maillist_name or ""), core.formspec_escape(maillist_name or ""),
minetest.formspec_escape(desc or ""), core.formspec_escape(desc or ""),
minetest.formspec_escape(players or "")) core.formspec_escape(players or ""))
minetest.show_formspec(playername, FORMNAME, formspec) core.show_formspec(playername, FORMNAME, formspec)
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then if formname ~= FORMNAME then
return return
end end

View file

@ -14,7 +14,7 @@ local function nonempty(x)
return ((type(x)=="table")and(#x>0)) return ((type(x)=="table")and(#x>0))
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "mail:inbox" and formname ~= "mail:outbox" if formname ~= "mail:inbox" and formname ~= "mail:outbox"
and formname ~= "mail:drafts" and formname ~= "mail:trash" then and formname ~= "mail:drafts" and formname ~= "mail:trash" then
return return
@ -59,7 +59,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- Hanmdle formspec event -- Hanmdle formspec event
if fields.inbox then -- inbox table if fields.inbox then -- inbox table
local evt = minetest.explode_table_event(fields.inbox) local evt = core.explode_table_event(fields.inbox)
if evt.row == 1 then -- header if evt.row == 1 then -- header
if mail.selected_idxs.sortfield[name] == evt.column-1 then -- if already this field, then change direction if mail.selected_idxs.sortfield[name] == evt.column-1 then -- if already this field, then change direction
mail.selected_idxs.sortdirection[name] = mail.selected_idxs.sortdirection[name] == "2" and "1" or "2" mail.selected_idxs.sortdirection[name] = mail.selected_idxs.sortdirection[name] == "2" and "1" or "2"
@ -105,7 +105,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
if fields.outbox then -- outbox table if fields.outbox then -- outbox table
local evt = minetest.explode_table_event(fields.outbox) local evt = core.explode_table_event(fields.outbox)
if evt.row == 1 then -- header if evt.row == 1 then -- header
if mail.selected_idxs.sortfield[name] == evt.column-1 then -- if already this field, then change direction if mail.selected_idxs.sortfield[name] == evt.column-1 then -- if already this field, then change direction
mail.selected_idxs.sortdirection[name] = mail.selected_idxs.sortdirection[name] == "2" and "1" or "2" mail.selected_idxs.sortdirection[name] = mail.selected_idxs.sortdirection[name] == "2" and "1" or "2"
@ -151,7 +151,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
if fields.drafts then -- drafts table if fields.drafts then -- drafts table
local evt = minetest.explode_table_event(fields.drafts) local evt = core.explode_table_event(fields.drafts)
if evt.row == 1 then -- header if evt.row == 1 then -- header
if mail.selected_idxs.sortfield[name] == evt.column-1 then -- if already this field, then change direction if mail.selected_idxs.sortfield[name] == evt.column-1 then -- if already this field, then change direction
mail.selected_idxs.sortdirection[name] = mail.selected_idxs.sortdirection[name] == "2" and "1" or "2" mail.selected_idxs.sortdirection[name] = mail.selected_idxs.sortdirection[name] == "2" and "1" or "2"
@ -176,7 +176,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
if fields.trash then -- trash table if fields.trash then -- trash table
local evt = minetest.explode_table_event(fields.trash) local evt = core.explode_table_event(fields.trash)
if evt.row == 1 then -- header if evt.row == 1 then -- header
if mail.selected_idxs.sortfield[name] == evt.column-1 then -- if already this field, then change direction if mail.selected_idxs.sortfield[name] == evt.column-1 then -- if already this field, then change direction
mail.selected_idxs.sortdirection[name] = mail.selected_idxs.sortdirection[name] == "2" and "1" or "2" mail.selected_idxs.sortdirection[name] = mail.selected_idxs.sortdirection[name] == "2" and "1" or "2"

View file

@ -109,14 +109,14 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
end end
formspec[#formspec + 1] = "," .. mail.get_color(displayed_color) formspec[#formspec + 1] = "," .. mail.get_color(displayed_color)
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
formspec[#formspec + 1] = minetest.formspec_escape(message.from) formspec[#formspec + 1] = core.formspec_escape(message.from)
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
if message.subject ~= "" then if message.subject ~= "" then
if string.len(message.subject) > 30 then if string.len(message.subject) > 30 then
formspec[#formspec + 1] = minetest.formspec_escape(string.sub(message.subject, 1, 27)) formspec[#formspec + 1] = core.formspec_escape(string.sub(message.subject, 1, 27))
formspec[#formspec + 1] = "..." formspec[#formspec + 1] = "..."
else else
formspec[#formspec + 1] = minetest.formspec_escape(message.subject) formspec[#formspec + 1] = core.formspec_escape(message.subject)
end end
else else
formspec[#formspec + 1] = S("(No subject)") formspec[#formspec + 1] = S("(No subject)")
@ -127,5 +127,5 @@ function mail.show_inbox(name, sortfieldindex, sortdirection, filter)
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No mail") .. "]" formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No mail") .. "]"
end end
minetest.show_formspec(name, "mail:inbox", table.concat(formspec, "")) core.show_formspec(name, "mail:inbox", table.concat(formspec, ""))
end end

View file

@ -1,5 +1,5 @@
-- sub files -- sub files
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = core.get_modpath(core.get_current_modname())
dofile(MP .. "/ui/inbox.lua") dofile(MP .. "/ui/inbox.lua")
dofile(MP .. "/ui/outbox.lua") dofile(MP .. "/ui/outbox.lua")

View file

@ -19,14 +19,14 @@ function mail.show_maillists(name)
for _, maillist in ipairs(maillists) do for _, maillist in ipairs(maillists) do
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
formspec[#formspec + 1] = "@" .. minetest.formspec_escape(maillist.name) formspec[#formspec + 1] = "@" .. core.formspec_escape(maillist.name)
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
if maillist.desc ~= "" then if maillist.desc ~= "" then
if string.len(maillist.desc or "") > 30 then if string.len(maillist.desc or "") > 30 then
formspec[#formspec + 1] = minetest.formspec_escape(string.sub(maillist.desc, 1, 27)) formspec[#formspec + 1] = core.formspec_escape(string.sub(maillist.desc, 1, 27))
formspec[#formspec + 1] = "..." formspec[#formspec + 1] = "..."
else else
formspec[#formspec + 1] = minetest.formspec_escape(maillist.desc) formspec[#formspec + 1] = core.formspec_escape(maillist.desc)
end end
else else
formspec[#formspec + 1] = S("(No description)") formspec[#formspec + 1] = S("(No description)")
@ -40,10 +40,10 @@ function mail.show_maillists(name)
else else
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No maillist") .. "]" formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No maillist") .. "]"
end end
minetest.show_formspec(name, FORMNAME, table.concat(formspec, "")) core.show_formspec(name, FORMNAME, table.concat(formspec, ""))
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then if formname ~= FORMNAME then
return return
end end
@ -52,7 +52,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local maillists = mail.get_maillists(name) local maillists = mail.get_maillists(name)
if fields.maillists then if fields.maillists then
local evt = minetest.explode_table_event(fields.maillists) local evt = core.explode_table_event(fields.maillists)
mail.selected_idxs.maillists[name] = evt.row - 1 mail.selected_idxs.maillists[name] = evt.row - 1
if evt.type == "DCL" and maillists[mail.selected_idxs.maillists[name]] then if evt.type == "DCL" and maillists[mail.selected_idxs.maillists[name]] then
local maillist = mail.get_maillist_by_name(name, maillists[mail.selected_idxs.maillists[name]].name) local maillist = mail.get_maillist_by_name(name, maillists[mail.selected_idxs.maillists[name]].name)

View file

@ -52,16 +52,16 @@ function mail.show_message(name, id)
tooltip[forward;]] .. S("Transfer message to other people") .. [[] tooltip[forward;]] .. S("Transfer message to other people") .. [[]
]] .. mail.theme ]] .. mail.theme
local from = minetest.formspec_escape(message.from) or "" local from = core.formspec_escape(message.from) or ""
local to = minetest.formspec_escape(message.to) or "" local to = core.formspec_escape(message.to) or ""
if string.len(to) > 70 then to = string.sub(to, 1, 67) .. "..." end if string.len(to) > 70 then to = string.sub(to, 1, 67) .. "..." end
local cc = minetest.formspec_escape(message.cc) or "" local cc = core.formspec_escape(message.cc) or ""
if string.len(cc) > 50 then cc = string.sub(cc, 1, 47) .. "..." end if string.len(cc) > 50 then cc = string.sub(cc, 1, 47) .. "..." end
local date = type(message.time) == "number" local date = type(message.time) == "number"
and minetest.formspec_escape(os.date(mail.get_setting(name, "date_format"), and core.formspec_escape(os.date(mail.get_setting(name, "date_format"),
message.time+3600*mail.get_setting(name, "timezone_offset"))) or "" message.time+3600*mail.get_setting(name, "timezone_offset"))) or ""
local subject = minetest.formspec_escape(message.subject) or "" local subject = core.formspec_escape(message.subject) or ""
local body = minetest.formspec_escape(message.body) or "" local body = core.formspec_escape(message.body) or ""
formspec = string.format(formspec, from, to, cc, date, subject, body) formspec = string.format(formspec, from, to, cc, date, subject, body)
if not message.read and mail.get_setting(name, "auto_marking_read") then if not message.read and mail.get_setting(name, "auto_marking_read") then
@ -69,14 +69,14 @@ function mail.show_message(name, id)
mail.mark_read(name, id) mail.mark_read(name, id)
end end
minetest.show_formspec(name, FORMNAME, formspec) core.show_formspec(name, FORMNAME, formspec)
end end
function mail.reply(name, message) function mail.reply(name, message)
if not message then if not message then
-- TODO: workaround for https://github.com/mt-mods/mail/issues/84 -- TODO: workaround for https://github.com/mt-mods/mail/issues/84
minetest.log("error", "[mail] reply called with nil message for player: " .. name) core.log("error", "[mail] reply called with nil message for player: " .. name)
minetest.log("error", "[mail] current mail-context: " .. dump(mail.selected_idxs)) core.log("error", "[mail] current mail-context: " .. dump(mail.selected_idxs))
return return
end end
mail.show_compose(name, message.from, "Re: "..message.subject, interleave_msg(message.body)) mail.show_compose(name, message.from, "Re: "..message.subject, interleave_msg(message.body))
@ -85,8 +85,8 @@ end
function mail.replyall(name, message) function mail.replyall(name, message)
if not message then if not message then
-- TODO: workaround for https://github.com/mt-mods/mail/issues/84 -- TODO: workaround for https://github.com/mt-mods/mail/issues/84
minetest.log("error", "[mail] replyall called with nil message for player: " .. name) core.log("error", "[mail] replyall called with nil message for player: " .. name)
minetest.log("error", "[mail] current mail-context: " .. dump(mail.selected_idxs)) core.log("error", "[mail] current mail-context: " .. dump(mail.selected_idxs))
return return
end end
@ -121,7 +121,7 @@ function mail.forward(name, message)
mail.show_compose(name, "", "Fw: " .. (message.subject or ""), interleave_msg(message.body)) mail.show_compose(name, "", "Fw: " .. (message.subject or ""), interleave_msg(message.body))
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then if formname ~= FORMNAME then
return return
end end

View file

@ -90,18 +90,18 @@ function mail.show_outbox(name, sortfieldindex, sortdirection, filter)
formspec[#formspec + 1] = "," .. mail.get_color(displayed_color) formspec[#formspec + 1] = "," .. mail.get_color(displayed_color)
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
if string.len(message.to) > 20 then if string.len(message.to) > 20 then
formspec[#formspec + 1] = minetest.formspec_escape(string.sub(message.to, 1, 17)) formspec[#formspec + 1] = core.formspec_escape(string.sub(message.to, 1, 17))
formspec[#formspec + 1] = "..." formspec[#formspec + 1] = "..."
else else
formspec[#formspec + 1] = minetest.formspec_escape(message.to) formspec[#formspec + 1] = core.formspec_escape(message.to)
end end
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
if message.subject ~= "" then if message.subject ~= "" then
if string.len(message.subject) > 30 then if string.len(message.subject) > 30 then
formspec[#formspec + 1] = minetest.formspec_escape(string.sub(message.subject, 1, 27)) formspec[#formspec + 1] = core.formspec_escape(string.sub(message.subject, 1, 27))
formspec[#formspec + 1] = "..." formspec[#formspec + 1] = "..."
else else
formspec[#formspec + 1] = minetest.formspec_escape(message.subject) formspec[#formspec + 1] = core.formspec_escape(message.subject)
end end
else else
formspec[#formspec + 1] = S("(No subject)") formspec[#formspec + 1] = S("(No subject)")
@ -112,5 +112,5 @@ function mail.show_outbox(name, sortfieldindex, sortdirection, filter)
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No mail") .. "]" formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("No mail") .. "]"
end end
minetest.show_formspec(name, "mail:outbox", table.concat(formspec, "")) core.show_formspec(name, "mail:outbox", table.concat(formspec, ""))
end end

View file

@ -1,5 +1,5 @@
-- translation -- translation
local S = minetest.get_translator("mail") local S = core.get_translator("mail")
local FORMNAME = "mail:receivers" local FORMNAME = "mail:receivers"
@ -23,7 +23,7 @@ function mail.show_receivers(name, id)
table[4,1.5;3.8,4.5;cc;%s] table[4,1.5;3.8,4.5;cc;%s]
]] .. mail.theme ]] .. mail.theme
local from = minetest.formspec_escape(message.from) or "" local from = core.formspec_escape(message.from) or ""
local to = mail.parse_player_list(message.to or "") local to = mail.parse_player_list(message.to or "")
local to_str = mail.get_color("header") .. "," .. S("To") .. ",," local to_str = mail.get_color("header") .. "," .. S("To") .. ",,"
to_str = to_str .. table.concat(to, ",,") to_str = to_str .. table.concat(to, ",,")
@ -31,13 +31,13 @@ function mail.show_receivers(name, id)
local cc_str = mail.get_color("header") .. "," .. S("CC") .. ",," local cc_str = mail.get_color("header") .. "," .. S("CC") .. ",,"
cc_str = cc_str .. table.concat(cc, ",,") cc_str = cc_str .. table.concat(cc, ",,")
local date = type(message.time) == "number" local date = type(message.time) == "number"
and minetest.formspec_escape(os.date(mail.get_setting(name, "date_format"), message.time)) or "" and core.formspec_escape(os.date(mail.get_setting(name, "date_format"), message.time)) or ""
formspec = string.format(formspec, from, date, to_str, cc_str) formspec = string.format(formspec, from, date, to_str, cc_str)
minetest.show_formspec(name, FORMNAME, formspec) core.show_formspec(name, FORMNAME, formspec)
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then if formname ~= FORMNAME then
return return
end end

View file

@ -39,10 +39,10 @@ function mail.show_select_contact(name, to, cc)
bcc = "" bcc = ""
end]]-- end]]--
formspec = string.format(formspec, contacts, to, cc)--, bcc() formspec = string.format(formspec, contacts, to, cc)--, bcc()
minetest.show_formspec(name, FORMNAME, formspec) core.show_formspec(name, FORMNAME, formspec)
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then if formname ~= FORMNAME then
return return
end end
@ -60,7 +60,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
bcc = "bccremove" bcc = "bccremove"
}) do }) do
if fields[k] then if fields[k] then
local evt = minetest.explode_table_event(fields[k]) local evt = core.explode_table_event(fields[k])
mail.selected_idxs[k][name] = evt.row - 1 mail.selected_idxs[k][name] = evt.row - 1
if evt.type == "DCL" and mail.selected_idxs[k][name] then if evt.type == "DCL" and mail.selected_idxs[k][name] then
fields[action] = true fields[action] = true

View file

@ -184,10 +184,10 @@ function mail.show_settings(name)
end end
end end
formspec = formspec .. mail.theme formspec = formspec .. mail.theme
minetest.show_formspec(name, FORMNAME, formspec) core.show_formspec(name, FORMNAME, formspec)
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= FORMNAME then if formname ~= FORMNAME then
return return
end end
@ -215,7 +215,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
mail.selected_idxs[setting][playername] = mail.selected_idxs[setting][playername] or mail.selected_idxs[setting][playername] = mail.selected_idxs[setting][playername] or
mail.get_setting(playername, setting) mail.get_setting(playername, setting)
if fields[setting] then if fields[setting] then
local evt = minetest.explode_table_event(fields[setting]) local evt = core.explode_table_event(fields[setting])
mail.selected_idxs["index_" .. setting][playername] = evt.row-1 mail.selected_idxs["index_" .. setting][playername] = evt.row-1
elseif fields["add_" .. setting] then elseif fields["add_" .. setting] then
table.insert(mail.selected_idxs[setting][playername], fields["field_" .. setting]) table.insert(mail.selected_idxs[setting][playername], fields["field_" .. setting])
@ -233,7 +233,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return return
elseif fields.groups then elseif fields.groups then
local evt = minetest.explode_table_event(fields.groups) local evt = core.explode_table_event(fields.groups)
mail.selected_idxs.settings_group[playername] = mail.settings_groups[tonumber(evt.row)].name mail.selected_idxs.settings_group[playername] = mail.settings_groups[tonumber(evt.row)].name
mail.show_settings(playername) mail.show_settings(playername)
elseif fields.optionstab == "1" then elseif fields.optionstab == "1" then

View file

@ -28,14 +28,14 @@ function mail.show_trash(name)
for _, message in ipairs(messages) do for _, message in ipairs(messages) do
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
formspec[#formspec + 1] = minetest.formspec_escape(message.to) formspec[#formspec + 1] = core.formspec_escape(message.to)
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
if message.subject ~= "" then if message.subject ~= "" then
if string.len(message.subject) > 30 then if string.len(message.subject) > 30 then
formspec[#formspec + 1] = minetest.formspec_escape(string.sub(message.subject, 1, 27)) formspec[#formspec + 1] = core.formspec_escape(string.sub(message.subject, 1, 27))
formspec[#formspec + 1] = "..." formspec[#formspec + 1] = "..."
else else
formspec[#formspec + 1] = minetest.formspec_escape(message.subject) formspec[#formspec + 1] = core.formspec_escape(message.subject)
end end
else else
formspec[#formspec + 1] = S("(No subject)") formspec[#formspec + 1] = S("(No subject)")
@ -49,5 +49,5 @@ function mail.show_trash(name)
else else
formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("Trash is empty") .. "]" formspec[#formspec + 1] = "]label[2.25,4.5;" .. S("Trash is empty") .. "]"
end end
minetest.show_formspec(name, "mail:trash", table.concat(formspec, "")) core.show_formspec(name, "mail:trash", table.concat(formspec, ""))
end end

View file

@ -12,7 +12,7 @@ function mail.compile_contact_list(name, selected, playernames)
if i == 1 then length = l end if i == 1 then length = l end
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
formspec[#formspec + 1] = minetest.formspec_escape(contact.name) formspec[#formspec + 1] = core.formspec_escape(contact.name)
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
local note = contact.note local note = contact.note
-- display an ellipsis if the note spans multiple lines -- display an ellipsis if the note spans multiple lines
@ -20,7 +20,7 @@ function mail.compile_contact_list(name, selected, playernames)
if idx ~= nil then if idx ~= nil then
note = string.sub(note, 1, idx-1) .. ' ...' note = string.sub(note, 1, idx-1) .. ' ...'
end end
formspec[#formspec + 1] = minetest.formspec_escape(note) formspec[#formspec + 1] = core.formspec_escape(note)
if type(selected) == "string" then if type(selected) == "string" then
if string.lower(selected) == k then if string.lower(selected) == k then
selected = i selected = i
@ -43,7 +43,7 @@ function mail.compile_contact_list(name, selected, playernames)
for i,c in ipairs(playernames) do for i,c in ipairs(playernames) do
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
formspec[#formspec + 1] = minetest.formspec_escape(c) formspec[#formspec + 1] = core.formspec_escape(c)
formspec[#formspec + 1] = "," formspec[#formspec + 1] = ","
if contacts[string.lower(c)] == nil then if contacts[string.lower(c)] == nil then
formspec[#formspec + 1] = "" formspec[#formspec + 1] = ""
@ -54,7 +54,7 @@ function mail.compile_contact_list(name, selected, playernames)
if idx ~= nil then if idx ~= nil then
note = string.sub(note, 1, idx-1) .. ' ...' note = string.sub(note, 1, idx-1) .. ' ...'
end end
formspec[#formspec + 1] = minetest.formspec_escape(note) formspec[#formspec + 1] = core.formspec_escape(note)
end end
if not selected then if not selected then
if type(selected) == "string" then if type(selected) == "string" then

View file

@ -1,5 +1,5 @@
-- sub files -- sub files
local MP = minetest.get_modpath(minetest.get_current_modname()) local MP = core.get_modpath(core.get_current_modname())
dofile(MP .. "/util/normalize.lua") dofile(MP .. "/util/normalize.lua")
dofile(MP .. "/util/colors.lua") dofile(MP .. "/util/colors.lua")
dofile(MP .. "/util/contact.lua") dofile(MP .. "/util/contact.lua")

View file

@ -74,7 +74,7 @@ end
function mail.settings.mute_list.check(name, value) function mail.settings.mute_list.check(name, value)
local valid_players = {} local valid_players = {}
for _, p in ipairs(value) do for _, p in ipairs(value) do
if p ~= name and minetest.player_exists(p) then if p ~= name and core.player_exists(p) then
table.insert(valid_players, p) table.insert(valid_players, p)
end end
end end
@ -82,9 +82,9 @@ function mail.settings.mute_list.check(name, value)
end end
function mail.settings.mute_list.sync(name) function mail.settings.mute_list.sync(name)
if minetest.get_modpath("beerchat") then if core.get_modpath("beerchat") then
local players = {} local players = {}
for other_player, _ in minetest.get_auth_handler().iterate() do for other_player, _ in core.get_auth_handler().iterate() do
if beerchat.has_player_muted_player(name, other_player) then if beerchat.has_player_muted_player(name, other_player) then
table.insert(players, other_player) table.insert(players, other_player)
end end
@ -95,16 +95,16 @@ function mail.settings.mute_list.sync(name)
end end
function mail.settings.mute_list.transfer(name, value) function mail.settings.mute_list.transfer(name, value)
if minetest.get_modpath("beerchat") then if core.get_modpath("beerchat") then
for other_player, _ in minetest.get_auth_handler().iterate() do -- unmute all for other_player, _ in core.get_auth_handler().iterate() do -- unmute all
if not beerchat.execute_callbacks("before_mute", name, other_player) then if not beerchat.execute_callbacks("before_mute", name, other_player) then
return false return false
end end
minetest.get_player_by_name(name):get_meta():set_string( core.get_player_by_name(name):get_meta():set_string(
"beerchat:muted:" .. other_player, "") "beerchat:muted:" .. other_player, "")
end end
for _, other_player in ipairs(value) do -- then mute only players in table for _, other_player in ipairs(value) do -- then mute only players in table
minetest.get_player_by_name(name):get_meta():set_string( core.get_player_by_name(name):get_meta():set_string(
"beerchat:muted:" .. other_player, "true") "beerchat:muted:" .. other_player, "true")
end end
return true return true