Skip to content

Commit e7f92d0

Browse files
author
rnd1
committed
stats collection every 2 minutes: dig xp, delta dig xp, max delta dig xp
display stats in /crep 1 and mark ip that was already detected previously /watch NAME can now watch player if his ip was detected before
1 parent c3ae516 commit e7f92d0

File tree

2 files changed

+69
-14
lines changed

2 files changed

+69
-14
lines changed

depends.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
default
1+
default
2+
boneworld?

init.lua

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ cheat.moderators = anticheatsettings.moderators;
3030
anticheatdb = {}; -- data about detected cheaters
3131

3232
cheat.suspect = "";
33-
cheat.players = {};
33+
cheat.players = {}; -- temporary cheat detection db
3434
cheat.message = "";
3535
cheat.debuglist = {}; -- [name]=true -- who gets to see debug msgs
3636

37-
cheat.scan_timer = 0
37+
cheat.scan_timer = 0; -- global scan of players
38+
cheat.stat_timer = 0; -- used to collect stats
39+
3840
cheat.nodelist = {};
3941
cheat.watcher = {}; -- list of watchers
4042

@@ -96,8 +98,32 @@ minetest.register_globalstep(function(dtime)
9698

9799
cheat.scan_timer = cheat.scan_timer + dtime
98100

101+
99102
-- GENERAL SCAN OF ALL PLAYERS
100103
if cheat.scan_timer>cheat.timestep then
104+
105+
106+
cheat.stat_timer = cheat.stat_timer + cheat.timestep;
107+
-- dig xp stats every 2 minutes
108+
if boneworld and cheat.stat_timer>120 then
109+
cheat.stat_timer = 0;
110+
local players = minetest.get_connected_players();
111+
for _,player in pairs(players) do
112+
local pname = player:get_player_name();
113+
if cheat.players[pname].stats.state == 1 then -- only if dig xp loaded to prevent anomalous stats
114+
local deltadig = cheat.players[pname].stats.digxp;
115+
cheat.players[pname].stats.digxp = boneworld.digxp[pname];
116+
deltadig = boneworld.digxp[pname]-deltadig;
117+
cheat.players[pname].stats.deltadig = deltadig;
118+
119+
if deltadig>cheat.players[pname].stats.maxdeltadig then
120+
cheat.players[pname].stats.maxdeltadig = deltadig;
121+
end
122+
end
123+
end
124+
end
125+
126+
101127
cheat.timestep = CHEAT_TIMESTEP + (2*math.random()-1)*2; -- randomize step so its unpredictable
102128
cheat.scan_timer=0;
103129
--local t = minetest.get_gametime();
@@ -168,25 +194,45 @@ minetest.after(0,
168194

169195

170196

197+
-- DISABLED: lot of false positives
171198
-- collects misc stats on players
172199

173-
minetest.register_on_cheat(
174-
function(player, c)
175-
local name = player:get_player_name(); if name == nil then return end
176-
local stats = cheat.players[name].stats;
177-
if not stats[c.type] then stats[c.type] = 0 end
178-
stats[c.type]=stats[c.type]+1;
179-
end
180-
)
200+
-- minetest.register_on_cheat(
201+
-- function(player, c)
202+
-- local name = player:get_player_name(); if name == nil then return end
203+
-- local stats = cheat.players[name].stats;
204+
-- if not stats[c.type] then stats[c.type] = 0 end
205+
-- stats[c.type]=stats[c.type]+1;
206+
-- end
207+
-- )
181208

182209

183210

184211
local watchers = {}; -- for each player a list of watchers
185212
minetest.register_on_joinplayer(function(player) -- init stuff on player join
186213
local name = player:get_player_name(); if name == nil then return end
187214
local pos = player:getpos();
188-
cheat.players[name]={count=0,cheatpos = pos, clearpos = pos, lastpos = pos, cheattype = 0}; -- type 0: none, 1 noclip, 2 fly
189-
cheat.players[name].stats = {}; -- various statistics about player
215+
216+
if cheat.players[name] == nil then
217+
cheat.players[name]={count=0,cheatpos = pos, clearpos = pos, lastpos = pos, cheattype = 0}; -- type 0: none, 1 noclip, 2 fly
218+
end
219+
220+
if cheat.players[name] and cheat.players[name].stats == nil then
221+
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
222+
223+
minetest.after(5, -- load digxp after boneworld loads it
224+
function()
225+
if boneworld and boneworld.xp then
226+
cheat.players[name].stats.digxp = boneworld.digxp[name] or 0;
227+
cheat.players[name].stats.state = 1;
228+
end
229+
end
230+
)
231+
232+
end
233+
--state 0 = stats not loaded yet
234+
235+
190236
watchers[name] = {}; -- for spectator mod
191237

192238
local ip = tostring(minetest.get_player_ip(name));
@@ -271,7 +317,12 @@ minetest.register_chatcommand("crep", { -- see cheat report
271317
local players = minetest.get_connected_players();
272318
for _,player in pairs(players) do
273319
local pname = player:get_player_name();
274-
text = text .. "name " .. pname .. " ".. string.gsub(dump(cheat.players[pname].stats), "\n", " ") .. "\n";
320+
local ip = tostring(minetest.get_player_ip(pname));
321+
322+
323+
text = text .. "\nname " .. pname .. ", digxp " .. cheat.players[pname].stats.digxp ..
324+
", deltadigxp(2min) " .. cheat.players[pname].stats.deltadig .. ", maxdeltadigxp " .. cheat.players[pname].stats.maxdeltadig; -- .. " ".. string.gsub(dump(cheat.players[pname].stats), "\n", " ");
325+
if anticheatdb[ip] then text = text .. " (DETECTED) ip ".. ip .. ", name " .. anticheatdb[ip].name end
275326
end
276327
if text ~= "" then
277328
local form = "size [10,8] textarea[0,0;10.5,9.;creport;CHEAT STATISTICS;".. text.."]"
@@ -410,6 +461,9 @@ minetest.register_chatcommand("watch", {
410461
break;
411462
end
412463
end
464+
465+
local ip = tostring(minetest.get_player_ip(pname));
466+
if anticheatdb[ip] then canwatch = true end -- can watch since this ip was detected before
413467

414468

415469
if canwatch or cheat.players[param].count>0 or param == cheat.suspect or privs.kick then

0 commit comments

Comments
 (0)