mirror of
https://github.com/mt-mods/mail.git
synced 2025-04-30 08:21:44 -04:00
Remove goto statements
Due to uncompatibility with LuaJIT
This commit is contained in:
parent
c076c62841
commit
865632933a
2 changed files with 50 additions and 64 deletions
82
migrate.lua
82
migrate.lua
|
@ -91,17 +91,15 @@ end
|
||||||
|
|
||||||
local function is_uuid_existing(uuid)
|
local function is_uuid_existing(uuid)
|
||||||
for _, k in ipairs(mail.storage:get_keys()) do
|
for _, k in ipairs(mail.storage:get_keys()) do
|
||||||
if string.sub(k,1,5) ~= "mail/" then
|
if string.sub(k,1,5) == "mail/" then
|
||||||
goto continue
|
local p = string.sub(k, 6)
|
||||||
end
|
local result
|
||||||
local p = string.sub(k, 6)
|
local boxes = {"inbox", "outbox", "drafts", "trash"}
|
||||||
local result
|
for _, b in ipairs(boxes) do
|
||||||
local boxes = {"inbox", "outbox", "drafts", "trash"}
|
result = search_box(p, b, uuid)
|
||||||
for _, b in ipairs(boxes) do
|
if result then return result end
|
||||||
result = search_box(p, b, uuid)
|
end
|
||||||
if result then return result end
|
|
||||||
end
|
end
|
||||||
::continue::
|
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -121,44 +119,36 @@ local function repair_box(playername, box)
|
||||||
for _, m in ipairs(e[box]) do
|
for _, m in ipairs(e[box]) do
|
||||||
local uuid = m.id
|
local uuid = m.id
|
||||||
local exists = is_uuid_existing(uuid)
|
local exists = is_uuid_existing(uuid)
|
||||||
if not exists then
|
if exists and not are_message_sames(exists, m) then
|
||||||
goto continue
|
|
||||||
elseif are_message_sames(exists, m) then
|
|
||||||
-- same message, continue
|
|
||||||
goto continue
|
|
||||||
else
|
|
||||||
local new_uuid = mail.new_uuid() -- generates a new uuid to replace doublons
|
local new_uuid = mail.new_uuid() -- generates a new uuid to replace doublons
|
||||||
for _, k in ipairs(mail.storage:get_keys()) do
|
for _, k in ipairs(mail.storage:get_keys()) do
|
||||||
if string.sub(k,1,5) ~= "mail/" then
|
if string.sub(k,1,5) == "mail/" then
|
||||||
goto continue_r
|
local p = string.sub(k, 6)
|
||||||
end
|
local er = mail.get_storage_entry(p)
|
||||||
local p = string.sub(k, 6)
|
for _, r in ipairs(er.inbox) do
|
||||||
local er = mail.get_storage_entry(p)
|
if r.id == uuid and not are_message_sames(m, r) then
|
||||||
for _, r in ipairs(er.inbox) do
|
r.id = new_uuid
|
||||||
if r.id == uuid and not are_message_sames(m, r) then
|
end
|
||||||
r.id = new_uuid
|
|
||||||
end
|
end
|
||||||
end
|
for _, r in ipairs(er.outbox) do
|
||||||
for _, r in ipairs(er.outbox) do
|
if r.id == uuid and not are_message_sames(m, r) then
|
||||||
if r.id == uuid and not are_message_sames(m, r) then
|
r.id = new_uuid
|
||||||
r.id = new_uuid
|
end
|
||||||
end
|
end
|
||||||
end
|
for _, r in ipairs(er.drafts) do
|
||||||
for _, r in ipairs(er.drafts) do
|
if r.id == uuid and not are_message_sames(m, r) then
|
||||||
if r.id == uuid and not are_message_sames(m, r) then
|
r.id = new_uuid
|
||||||
r.id = new_uuid
|
end
|
||||||
end
|
end
|
||||||
end
|
for _, r in ipairs(er.trash) do
|
||||||
for _, r in ipairs(er.trash) do
|
if r.id == uuid and not are_message_sames(m, r) then
|
||||||
if r.id == uuid and not are_message_sames(m, r) then
|
r.id = new_uuid
|
||||||
r.id = new_uuid
|
end
|
||||||
end
|
end
|
||||||
|
mail.set_storage_entry(p, er)
|
||||||
end
|
end
|
||||||
mail.set_storage_entry(p, er)
|
|
||||||
::continue_r::
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
::continue::
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -166,15 +156,13 @@ end
|
||||||
local function repair_storage()
|
local function repair_storage()
|
||||||
-- iterate through players
|
-- iterate through players
|
||||||
for _, k in ipairs(mail.storage:get_keys()) do
|
for _, k in ipairs(mail.storage:get_keys()) do
|
||||||
if string.sub(k,1,5) ~= "mail/" then
|
if string.sub(k,1,5) == "mail/" then
|
||||||
goto continue
|
local p = string.sub(k, 6)
|
||||||
|
repair_box(p, "inbox")
|
||||||
|
repair_box(p, "outbox")
|
||||||
|
repair_box(p, "drafts")
|
||||||
|
repair_box(p, "trash")
|
||||||
end
|
end
|
||||||
local p = string.sub(k, 6)
|
|
||||||
repair_box(p, "inbox")
|
|
||||||
repair_box(p, "outbox")
|
|
||||||
repair_box(p, "drafts")
|
|
||||||
repair_box(p, "trash")
|
|
||||||
::continue::
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,24 +3,22 @@ local random = math.random
|
||||||
|
|
||||||
local function is_uuid_unexisting(uuid)
|
local function is_uuid_unexisting(uuid)
|
||||||
for _, k in ipairs(mail.storage:get_keys()) do
|
for _, k in ipairs(mail.storage:get_keys()) do
|
||||||
if string.sub(k,1,5) ~= "mail/" then
|
if string.sub(k,1,5) == "mail/" then
|
||||||
goto continue
|
local p = string.sub(k, 6)
|
||||||
|
local e = mail.get_storage_entry(p)
|
||||||
|
for _, m in ipairs(e.inbox) do
|
||||||
|
if m.id == uuid then return false end
|
||||||
|
end
|
||||||
|
for _, m in ipairs(e.outbox) do
|
||||||
|
if m.id == uuid then return false end
|
||||||
|
end
|
||||||
|
for _, m in ipairs(e.drafts) do
|
||||||
|
if m.id == uuid then return false end
|
||||||
|
end
|
||||||
|
for _, m in ipairs(e.trash) do
|
||||||
|
if m.id == uuid then return false end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local p = string.sub(k, 6)
|
|
||||||
local e = mail.get_storage_entry(p)
|
|
||||||
for _, m in ipairs(e.inbox) do
|
|
||||||
if m.id == uuid then return false end
|
|
||||||
end
|
|
||||||
for _, m in ipairs(e.outbox) do
|
|
||||||
if m.id == uuid then return false end
|
|
||||||
end
|
|
||||||
for _, m in ipairs(e.drafts) do
|
|
||||||
if m.id == uuid then return false end
|
|
||||||
end
|
|
||||||
for _, m in ipairs(e.trash) do
|
|
||||||
if m.id == uuid then return false end
|
|
||||||
end
|
|
||||||
::continue::
|
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue