bug fix for issue #2 (abused fly privs)

This commit is contained in:
Joachim Stolberg 2018-02-27 22:54:35 +01:00
parent 0ef44f7342
commit 4034eb0e6d

@ -3,9 +3,9 @@
Tower Crane Mod Tower Crane Mod
=============== ===============
v0.15 by JoSt v0.16 by JoSt
Copyright (C) 2017 Joachim Stolberg Copyright (C) 2017-2018 Joachim Stolberg
LGPLv2.1+ LGPLv2.1+
See LICENSE.txt for more information See LICENSE.txt for more information
@ -25,6 +25,7 @@
2017-10-17 v0.13 Area protection bugfix 2017-10-17 v0.13 Area protection bugfix
2017-11-01 v0.14 Crane handing over bugfix 2017-11-01 v0.14 Crane handing over bugfix
2017-11-07 v0.15 Working zone is now restricted to areas with necessary rights 2017-11-07 v0.15 Working zone is now restricted to areas with necessary rights
2018-02-27 v0.16 "fly privs" bug fixed (issue #2)
]]-- ]]--
@ -106,12 +107,13 @@ end
--################################################################################################## --##################################################################################################
-- give/take player the necessary privs/physics -- give/take player the necessary privs/physics
local function fly_privs(player, enable) local function fly_privs(pos, player, enable)
local privs = minetest.get_player_privs(player:get_player_name()) local privs = minetest.get_player_privs(player:get_player_name())
local physics = player:get_physics_override() local physics = player:get_physics_override()
if privs then if privs and physics then
if enable == true then if enable == true then
player:set_attribute("tower_crane_active", "true") local spos = minetest.pos_to_string(pos)
player:set_attribute("tower_crane_active", spos)
privs["fly"] = true privs["fly"] = true
privs["fast"] = nil privs["fast"] = nil
physics.speed = 0.7 physics.speed = 0.7
@ -126,6 +128,17 @@ local function fly_privs(player, enable)
end end
end end
-- Normalize the player privs
local function remove_hook(pos, player)
if player then
if pos then
local meta = minetest.get_meta(pos)
meta:set_int("running", 0)
end
fly_privs(pos, player, nil)
end
end
local function control_player(pos, pos1, pos2, player) local function control_player(pos, pos1, pos2, player)
if player then if player then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -154,7 +167,11 @@ local function control_player(pos, pos1, pos2, player)
end end
minetest.after(1, control_player, pos, pos1, pos2, player) minetest.after(1, control_player, pos, pos1, pos2, player)
else
remove_hook(pos, player)
end end
else
remove_hook(pos, player)
end end
else else
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -168,30 +185,19 @@ local function place_hook(pos, dir, player, pos1, pos2)
local switch_pos = {x=pos.x, y=pos.y, z=pos.z} local switch_pos = {x=pos.x, y=pos.y, z=pos.z}
local meta = minetest.get_meta(switch_pos) local meta = minetest.get_meta(switch_pos)
meta:set_int("running", 1) meta:set_int("running", 1)
-- set privs
fly_privs(pos, player, true)
-- place the player -- place the player
pos.y = pos.y - 1 pos.y = pos.y - 1
pos.x = pos.x + dir.x pos.x = pos.x + dir.x
pos.z = pos.z + dir.z pos.z = pos.z + dir.z
player:setpos(pos) player:setpos(pos)
meta:set_string("last_known_pos", minetest.pos_to_string(pos)) meta:set_string("last_known_pos", minetest.pos_to_string(pos))
-- set privs
fly_privs(player, true)
-- control player every second -- control player every second
minetest.after(1, control_player, switch_pos, pos1, pos2, player) minetest.after(1, control_player, switch_pos, pos1, pos2, player)
end end
end end
-- Normalize the player privs
local function remove_hook(pos, player)
if player then
if pos then
local meta = minetest.get_meta(pos)
meta:set_int("running", 0)
end
fly_privs(player, nil)
end
end
--################################################################################################## --##################################################################################################
--## Tower Crane --## Tower Crane
--################################################################################################## --##################################################################################################
@ -422,7 +428,6 @@ minetest.register_node("towercrane:base", {
remove_crane_data(pos) remove_crane_data(pos)
remove_area(id, owner) remove_area(id, owner)
remove_crane(table.copy(pos), dir, height, width) remove_crane(table.copy(pos), dir, height, width)
remove_hook(pos, player)
end end
-- evaluate user input -- evaluate user input
@ -485,7 +490,6 @@ minetest.register_node("towercrane:base", {
end end
-- remove hook -- remove hook
local player = minetest.get_player_by_name(owner) local player = minetest.get_player_by_name(owner)
remove_hook({x=pos.x, y=pos.y+1, z=pos.z}, player)
end, end,
}) })
@ -553,10 +557,15 @@ minetest.register_node("towercrane:mast_ctrl_on", {
if clicker:get_player_name() ~= meta:get_string("owner") then if clicker:get_player_name() ~= meta:get_string("owner") then
return return
end end
-- Check if this is the wrong crane
local spos = minetest.pos_to_string(pos)
if clicker:get_attribute("tower_crane_active") ~= nil
and clicker:get_attribute("tower_crane_active") ~= spos then
return
end
node.name = "towercrane:mast_ctrl_off" node.name = "towercrane:mast_ctrl_off"
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
local id = minetest.hash_node_position(pos)
remove_hook(pos, clicker) remove_hook(pos, clicker)
end, end,
@ -604,7 +613,7 @@ minetest.register_node("towercrane:mast_ctrl_off", {
return return
end end
-- prevent handing over to the next crane -- prevent handing over to the next crane
if clicker:get_attribute("crane_active") ~= nil then if clicker:get_attribute("tower_crane_active") ~= nil then
return return
end end
-- swap to the other node -- swap to the other node
@ -725,9 +734,15 @@ end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local privs = minetest.get_player_privs(player:get_player_name()) local privs = minetest.get_player_privs(player:get_player_name())
local physics = player:get_physics_override() local physics = player:get_physics_override()
-- player still hanging on the crane?
if player:get_attribute("tower_crane_active") ~= nil then
fly_privs(nil, player, nil)
else
-- store the player privs default values
player:set_attribute("tower_crane_store_fast", minetest.serialize(privs["fast"])) player:set_attribute("tower_crane_store_fast", minetest.serialize(privs["fast"]))
player:set_attribute("tower_crane_store_fly", minetest.serialize(privs["fly"])) player:set_attribute("tower_crane_store_fly", minetest.serialize(privs["fly"]))
player:set_attribute("tower_crane_store_speed", minetest.serialize(physics.speed)) player:set_attribute("tower_crane_store_speed", minetest.serialize(physics.speed))
end
end) end)
-- switch back to normal player privs -- switch back to normal player privs