optimize checks, add player check funtion for bots

This commit is contained in:
mckayshirou 2023-08-07 03:19:12 -04:00
parent 043d3fe7f1
commit 12c12807d3

View File

@ -8,10 +8,17 @@
-- per-player data
local player_data = {}
local is_player = function(player)
-- a table being a player is also supported because it quacks sufficiently
-- like a player if it has the is_player function
local t = type(player)
return (t == "userdata" or t == "table") and type(player.is_player) == "function"
end
-- obtain player data cheats, improved respect beowulf with missing checks and methods
local function get_player_data(name)
if not is_player(player) then return nil end
local player = minetest.get_player_by_name(name)
if not player then return nil end
if not player_data[name] then
player_data[name] = {
fliyers = 0, -- number of checks for fly ( added only with governing)
@ -26,7 +33,7 @@ end
-- clear player data for cheats
local function track_player_clear(player)
if player then
if is_player(player) then
if player:get_player_name() then
player_data[player:get_player_name()] = nil
end
@ -35,6 +42,7 @@ end
-- store player data cheats strikes and checks
local function track_player(player)
if not is_player(player) then return nil end
local name = player:get_player_name()
local data = get_player_data(name)
local pos = player:get_pos()
@ -351,7 +359,9 @@ minetest.register_globalstep(function(dtime)
for _,player in pairs(players) do
local pname = player:get_player_name();
if cheat.players[pname].count>0 then
minetest.chat_send_player(name, "name " .. pname .. ", cheat pos " .. minetest.pos_to_string(cheat.players[pname].cheatpos) .. " last clear pos " .. minetest.pos_to_string(cheat.players[pname].clearpos) .. " cheat type " .. cheat.players[pname].cheattype .. " cheatcount " .. cheat.players[pname].count );
local msgch = "name " .. pname .. ", cheat pos " .. minetest.pos_to_string(cheat.players[pname].cheatpos) .. " last clear pos " .. minetest.pos_to_string(cheat.players[pname].clearpos) .. " cheat type " .. cheat.players[pname].cheattype .. " cheatcount " .. cheat.players[pname].count
minetest.chat_send_player(name, msgch );
minetest.log("warning", "[governing] #anticheat "..msgch)
end
end
end
@ -375,7 +385,7 @@ local check_can_dig = function(pos, digger)
local logtext = os.date("%H:%M.%S") .. "#anticheat: long range dig " .. pname ..", distance " .. dist .. ", pos " .. minetest.pos_to_string(pos);
for name,_ in pairs(cheat.debuglist) do -- show to all watchers
minetest.chat_send_player(name,logtext)
minetest.log("warning", "[governing] "..logtext)
end
local ip = tostring(minetest.get_player_ip(pname));
anticheatdb[ip] = {name = pname, msg = logtext};
@ -404,18 +414,16 @@ minetest.register_on_joinplayer(function(player) -- init stuff on player join
if cheat.players[name] and cheat.players[name].stats == nil then
cheat.players[name].stats = {maxdeltadig=0,deltadig = 0,digxp = 0, state = 0}; -- various statistics about player: max dig xp increase in 2 minutes, current dig xp increase
minetest.after(5, -- load digxp after boneworld loads it
function()
if bonemod then
if boneworld.xp then
cheat.players[name].stats.digxp = boneworld.digxp[name] or 0;
cheat.players[name].stats.state = 1;
if bonemod then
minetest.after(5, function()
if boneworld.xp then -- load digxp after boneworld loads it
cheat.players[name].stats.digxp = boneworld.digxp[name] or 0;
cheat.players[name].stats.state = 1;
end
end
end)
end
)
end
--state 0 = stats not loaded yet