mirror of
https://github.com/mt-mods/mail.git
synced 2025-07-04 05:37:00 -04:00
add contacts dir, leave mail files as is
- restructured storage.lua so reading/writing json is not duplicated - when a player joins and has no contacts file yet, automatically add all players he wrote to
This commit is contained in:
parent
498ef84026
commit
f82c3d2b82
4 changed files with 78 additions and 11 deletions
26
migrate.lua
26
migrate.lua
|
@ -4,6 +4,7 @@
|
|||
mail.migrate = function()
|
||||
-- create directory, just in case
|
||||
minetest.mkdir(mail.maildir)
|
||||
minetest.mkdir(mail.contactsdir)
|
||||
|
||||
local file = io.open(minetest.get_worldpath().."/mail.db", "r")
|
||||
if file then
|
||||
|
@ -23,3 +24,28 @@ mail.migrate = function()
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
mail.migrate_contacts = function(playername)
|
||||
local file = io.open(mail.getContactsFile(playername), 'r')
|
||||
if not file then
|
||||
file:close() -- file doesn't exist! This is a case for Migrate Man!
|
||||
|
||||
local messages = mail.getMessages(playername)
|
||||
local contacts = {}
|
||||
|
||||
if messages and not contacts then
|
||||
for k,message in pairs(messages) do
|
||||
mail.ensure_new_format(message)
|
||||
if contacts[string.lower(message.from)] == nil then
|
||||
contacts[string.lower(message.from)] = {
|
||||
name = message.from,
|
||||
note = "",
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
file:close() -- uh, um, nope, let's leave those alone, shall we?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue