This commit is contained in:
BuckarooBanzay 2023-03-28 15:47:53 +02:00 committed by Athozus
parent dff068d75b
commit e8c7fde4c3
No known key found for this signature in database
GPG key ID: B50895022E8484BF
8 changed files with 95 additions and 20 deletions

View file

@ -1,23 +1,29 @@
-- storage getter/setter
-- create or populate empty fields on an entry
local function populate_entry(e)
e = e or {}
e.contacts = e.contacts or {}
e.inbox = e.inbox or {}
e.outbox = e.outbox or {}
e.lists = e.lists or {}
return e
end
function mail.get_storage_entry(playername)
local str = mail.storage:get_string(playername)
if str == "" then
-- new entry
return {
contacts = {},
inbox = {},
outbox = {},
lists = {}
}
return populate_entry()
else
-- deserialize existing entry
return minetest.parse_json(str)
local e = minetest.parse_json(str)
return populate_entry(e)
end
end
function mail.set_storage_entry(playername, entry)
mail.storage:get_string(playername, minetest.write_json(entry))
mail.storage:set_string(playername, minetest.write_json(entry))
end
-- get a mail by id from the players in- or outbox