diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 6143bfb41..54ec42436 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -1131,3 +1131,17 @@ if not vector.in_area then (pos.z >= min.z) and (pos.z <= max.z) end end + +function mcl_util.is_fake_player(player) + -- Simple checks + if not player then return true end + if player:is_player() == false then return true end + if not player.get_player_name then return true end + + -- Check if the player is logged in + local objref = minetest.get_player_by_name( player:get_player_name() ) + if not objref then return true end + if objref ~= player then return true end + + return false +end diff --git a/mods/HUD/awards/mod.conf b/mods/HUD/awards/mod.conf index 1657323e2..7627a3011 100644 --- a/mods/HUD/awards/mod.conf +++ b/mods/HUD/awards/mod.conf @@ -6,4 +6,4 @@ license = LGPL 2.1 or later forum = https://forum.minetest.net/viewtopic.php?t=4870 version = 2.3.0 optional_depends = sfinv, unified_inventory -depends = mcl_colors +depends = mcl_colors, mcl_util diff --git a/mods/HUD/awards/triggers.lua b/mods/HUD/awards/triggers.lua index c7194d2c9..68267dcea 100644 --- a/mods/HUD/awards/triggers.lua +++ b/mods/HUD/awards/triggers.lua @@ -15,6 +15,7 @@ -- local S = minetest.get_translator(minetest.get_current_modname()) +local is_fake_player = mcl_util.is_fake_player awards.register_trigger("dig", function(def) local tmp = { @@ -236,7 +237,7 @@ awards.register_onCraft = awards.register_on_craft -- Trigger Handles minetest.register_on_dignode(function(pos, oldnode, digger) - if not digger or not pos or not oldnode then + if is_fake_player(digger) or not pos or not oldnode then return end @@ -261,7 +262,7 @@ minetest.register_on_dignode(function(pos, oldnode, digger) end) minetest.register_on_placenode(function(pos, node, digger) - if not digger or not pos or not node or not digger:get_player_name() or digger:get_player_name()=="" then + if is_fake_player(digger) or not pos or not node or not digger:get_player_name() or digger:get_player_name()=="" then return end local data = awards.players[digger:get_player_name()] @@ -286,6 +287,7 @@ minetest.register_on_placenode(function(pos, node, digger) end) minetest.register_on_item_eat(function(hp_change, replace_with_item, itemstack, user, pointed_thing) + if is_fake_player(user) then return end if not user or not itemstack or not user:get_player_name() or user:get_player_name()=="" then return end @@ -310,7 +312,7 @@ minetest.register_on_item_eat(function(hp_change, replace_with_item, itemstack, end) minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv) - if not player or not itemstack then + if is_fake_player(player) or not itemstack then return end @@ -338,7 +340,7 @@ end) minetest.register_on_dieplayer(function(player) -- Run checks local name = player:get_player_name() - if not player or not name or name=="" then + if is_fake_player(player) or not name or name=="" then return end @@ -359,8 +361,9 @@ end) minetest.register_on_joinplayer(function(player) -- Run checks + if is_fake_player(player) then return end local name = player:get_player_name() - if not player or not name or name=="" then + if not name or name=="" then return end @@ -390,6 +393,7 @@ minetest.register_on_chat_message(function(name, message) awards.assertPlayer(name) local data = awards.players[name] local player = minetest.get_player_by_name(name) + if is_fake_player(player) then return end -- Increment counter data.chats = data.chats + 1 diff --git a/mods/PLAYER/mcl_hunger/hunger.lua b/mods/PLAYER/mcl_hunger/hunger.lua index cf06e48c9..693387d55 100644 --- a/mods/PLAYER/mcl_hunger/hunger.lua +++ b/mods/PLAYER/mcl_hunger/hunger.lua @@ -1,18 +1,6 @@ --local S = minetest.get_translator(minetest.get_current_modname()) -local function is_fake_player(player) - -- Simple checks - if not player then return true end - if player:is_player() == false then return true end - if not player.get_player_name then return true end - - -- Check if the player is logged in - local objref = minetest.get_player_by_name( player:get_player_name() ) - if not objref then return true end - if objref ~= player then return true end - - return false -end +local is_fake_player = mcl_util.is_fake_player -- wrapper for minetest.item_eat (this way we make sure other mods can't break this one) function minetest.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing) diff --git a/mods/PLAYER/mcl_hunger/mod.conf b/mods/PLAYER/mcl_hunger/mod.conf index 99ab71ff3..f2bd6eccb 100644 --- a/mods/PLAYER/mcl_hunger/mod.conf +++ b/mods/PLAYER/mcl_hunger/mod.conf @@ -1,4 +1,4 @@ name = mcl_hunger author = BlockMen description = Adds a simple hunger meachanic with satiation, food poisoning and different healing. -depends = hudbars +depends = hudbars, mcl_util