mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-12 05:20:32 +01:00
Prevent players from storing too many items in the bags
This commit is contained in:
parent
aa851dfdfb
commit
27bb636b83
|
@ -133,6 +133,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
local stack = unified_inventory.extract_bag(player, i)
|
local stack = unified_inventory.extract_bag(player, i)
|
||||||
if not stack then
|
if not stack then
|
||||||
return
|
return
|
||||||
|
elseif stack == "overflow" then
|
||||||
|
minetest.chat_send_player(player:get_player_name(), "You bag is too heavy to be unequipped... Remove some items and retry")
|
||||||
|
return
|
||||||
elseif not player:get_inventory():room_for_item("main", stack) then
|
elseif not player:get_inventory():room_for_item("main", stack) then
|
||||||
local pos = player:getpos()
|
local pos = player:getpos()
|
||||||
pos.y = pos.y + 2
|
pos.y = pos.y + 2
|
||||||
|
@ -275,6 +278,10 @@ function unified_inventory.extract_bag(player, id)
|
||||||
for i, item in pairs(inv) do
|
for i, item in pairs(inv) do
|
||||||
list[i] = item:to_table()
|
list[i] = item:to_table()
|
||||||
end
|
end
|
||||||
|
if minetest.serialize(list):len() >= 4096 then
|
||||||
|
minetest.log("warning", "[U_Inv] Preventing metadata overflow with bag metadata")
|
||||||
|
return "overflow"
|
||||||
|
end
|
||||||
|
|
||||||
pinv:remove_item("bag" .. id, stack)
|
pinv:remove_item("bag" .. id, stack)
|
||||||
minetest.get_inventory({type = "detached", name = minetest.formspec_escape(player:get_player_name()) .. "_bags"}):set_stack("bag" .. id, 1, nil)
|
minetest.get_inventory({type = "detached", name = minetest.formspec_escape(player:get_player_name()) .. "_bags"}):set_stack("bag" .. id, 1, nil)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user