Fix crash if non-existent mail was selected (#109)

* Fix crash if non-existent mail was selected

* Fix outbox too
This commit is contained in:
savilli 2023-08-06 13:12:46 +02:00 committed by GitHub
parent 2a18322cdb
commit fe533eeb4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,8 +18,10 @@ minetest.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
elseif fields.quit then end
return
if fields.quit then
return true
end end
-- Get player name and handle / convert common input fields -- Get player name and handle / convert common input fields
@ -64,7 +66,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
mail.selected_idxs.sortfield[name] = evt.column-1 -- update column mail.selected_idxs.sortfield[name] = evt.column-1 -- update column
mail.show_mail_menu(name) mail.show_mail_menu(name)
return return true
end
local inbox = getInbox()[evt.row-1]
if not inbox then
mail.show_mail_menu(name)
return true
end end
if mail.selected_idxs.multipleselection[name] then if mail.selected_idxs.multipleselection[name] then
if not mail.selected_idxs.inbox[name] then if not mail.selected_idxs.inbox[name] then
@ -73,7 +80,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local selected_id = 0 local selected_id = 0
if mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then if mail.selected_idxs.inbox[name] and #mail.selected_idxs.inbox[name] > 0 then
for i, selected_msg in ipairs(mail.selected_idxs.inbox[name]) do for i, selected_msg in ipairs(mail.selected_idxs.inbox[name]) do
if getInbox()[evt.row-1].id == selected_msg then if inbox.id == selected_msg then
selected_id = i selected_id = i
table.remove(mail.selected_idxs.inbox[name], i) table.remove(mail.selected_idxs.inbox[name], i)
break break
@ -81,13 +88,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
end end
if selected_id == 0 then if selected_id == 0 then
table.insert(mail.selected_idxs.inbox[name], getInbox()[evt.row-1].id) table.insert(mail.selected_idxs.inbox[name], inbox.id)
end end
else else
mail.selected_idxs.inbox[name] = { (getInbox()[evt.row-1] or {}).id } mail.selected_idxs.inbox[name] = { inbox.id }
end end
if evt.type == "DCL" and getInbox()[evt.row-1] then if evt.type == "DCL" then
mail.show_message(name, getInbox()[evt.row-1].id) mail.show_message(name, inbox.id)
else else
mail.show_mail_menu(name) mail.show_mail_menu(name)
end end
@ -102,7 +109,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
mail.selected_idxs.sortfield[name] = evt.column-1 -- update column mail.selected_idxs.sortfield[name] = evt.column-1 -- update column
mail.show_mail_menu(name) mail.show_mail_menu(name)
return return true
end
local outbox = getOutbox()[evt.row-1]
if not outbox then
mail.show_mail_menu(name)
return true
end end
if mail.selected_idxs.multipleselection[name] then if mail.selected_idxs.multipleselection[name] then
if not mail.selected_idxs.outbox[name] then if not mail.selected_idxs.outbox[name] then
@ -111,7 +123,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local selected_id = 0 local selected_id = 0
if mail.selected_idxs.outbox[name] and #mail.selected_idxs.outbox[name] > 0 then if mail.selected_idxs.outbox[name] and #mail.selected_idxs.outbox[name] > 0 then
for i, selected_msg in ipairs(mail.selected_idxs.outbox[name]) do for i, selected_msg in ipairs(mail.selected_idxs.outbox[name]) do
if getOutbox()[evt.row-1].id == selected_msg then if outbox.id == selected_msg then
selected_id = i selected_id = i
table.remove(mail.selected_idxs.outbox[name], i) table.remove(mail.selected_idxs.outbox[name], i)
break break
@ -119,13 +131,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
end end
if selected_id == 0 then if selected_id == 0 then
table.insert(mail.selected_idxs.outbox[name], getOutbox()[evt.row-1].id) table.insert(mail.selected_idxs.outbox[name], outbox.id)
end end
else else
mail.selected_idxs.outbox[name] = { (getOutbox()[evt.row-1] or {}).id } mail.selected_idxs.outbox[name] = { outbox.id }
end end
if evt.type == "DCL" and getOutbox()[evt.row-1] then if evt.type == "DCL" then
mail.show_message(name, getOutbox()[evt.row-1].id) mail.show_message(name, outbox.id)
else else
mail.show_mail_menu(name) mail.show_mail_menu(name)
end end