diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2020-11-08 21:16:03 +0100 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2020-11-08 21:23:54 +0100 |
commit | ae059f2061e752700d69da817f217e21f8ec7170 (patch) | |
tree | 24008d20c04873045e6c50f02ca54f9518fe3233 | |
parent | ab14f61bac021d4b9677927bfd326762a61c485a (diff) | |
download | farebox-ae059f2061e752700d69da817f217e21f8ec7170.tar.gz farebox-ae059f2061e752700d69da817f217e21f8ec7170.tar.bz2 farebox-ae059f2061e752700d69da817f217e21f8ec7170.zip |
Security: block access to inventories for hacked clients
This fix forbids unauthorized players from accessing the inventory.
-rw-r--r-- | faregate.lua | 4 | ||||
-rw-r--r-- | init.lua | 39 | ||||
-rw-r--r-- | mod.conf | 3 |
3 files changed, 43 insertions, 3 deletions
diff --git a/faregate.lua b/faregate.lua index e5170bd..2871e54 100644 --- a/faregate.lua +++ b/faregate.lua @@ -43,7 +43,9 @@ minetest.register_node("farebox:faregate", { on_rightclick = function(pos, node, player, itemstack, pointed_thing) farebox.show_formspec(pos, player) end, - + allow_metadata_inventory_put = farebox.allow_metadata_inventory_put, + allow_metadata_inventory_take = farebox.allow_metadata_inventory_take, + allow_metadata_inventory_move = farebox.allow_metadata_inventory_move, }) minetest.register_node("farebox:faregate_open", { @@ -119,6 +119,37 @@ minetest.register_on_leaveplayer(function(player) farebox.players[player:get_player_name()] = nil end) + +can_dig = function(pos, player) + local meta = minetest.get_meta(pos) + local name = player:get_player_name() + local inv = meta:get_inventory() + if inv:is_empty("main") and inv:is_empty("request") and (meta:get_string("owner") == name or minetest.check_player_privs(name, {protection_bypass=true,})) then + return true + end + return false +end + +farebox.allow_metadata_inventory_take = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + local name = player:get_player_name() + if meta:get_string("owner") == name or minetest.check_player_privs(name, {protection_bypass=true,}) then + return stack:get_count() + end + return 0 +end +farebox.allow_metadata_inventory_put = function(pos, listname, index, stack, player) + return farebox.allow_metadata_inventory_take(pos, listname, index, stack, player) +end +farebox.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + local meta = minetest.get_meta(pos) + local name = player:get_player_name() + if meta:get_string("owner") == name or minetest.check_player_privs(name, {protection_bypass=true,}) then + return count + end + return 0 +end + minetest.register_node("farebox:farebox", { description = "Farebox", tiles = { @@ -141,17 +172,21 @@ minetest.register_node("farebox:farebox", { after_place_node = function(pos, player, _) local meta = minetest.get_meta(pos) local player_name = player:get_player_name() - + meta:set_string("owner", player_name) meta:set_string("infotext", "Owned by "..player_name) - + local inv = meta:get_inventory() inv:set_size("request", 1) inv:set_size("main", 32) end, + allow_metadata_inventory_put = farebox.allow_metadata_inventory_put, + allow_metadata_inventory_take = farebox.allow_metadata_inventory_take, + allow_metadata_inventory_move = farebox.allow_metadata_inventory_move, on_rightclick = function(pos, node, player, itemstack, pointed_thing) farebox.show_formspec(pos, player) end, + }) minetest.register_craft({ diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..79b72e2 --- /dev/null +++ b/mod.conf @@ -0,0 +1,3 @@ +name=farebox +description=Farebox and Faregate mod +depends=mesecons, default, doors |