mirror of
https://github.com/mt-mods/mail.git
synced 2025-07-12 09:22:20 -04:00
tests
This commit is contained in:
parent
dff068d75b
commit
e8c7fde4c3
8 changed files with 95 additions and 20 deletions
22
storage.lua
22
storage.lua
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue