1+ -- used to check how many explosion/projectile sync packets a client sends overtime
2+ local iExplosionCheckInterval = 3000 ; -- the interval in ms to check for players sending too many explosion and projectile sync packets
3+ local tblPlayerProjectiles = {}; -- store players sending projectile sync packets
4+ local tblRegularExplosions = {}; -- store players sending regular explosion sync packets
5+ local tblVehicleExplosions = {}; -- store players sending vehicle explosion sync packets
6+ local iPlayerProjectileThreshold = 10 ; -- the threshold when we consider client suspicious for projectile creations
7+ local iRegularExplosionThreshold = 10 ; -- the threshold when we consider client suspicious for regular explosions
8+ local iVehicleExplosionThreshold = 10 ; -- the threshold when we consider client suspicious for vehicle explosions
9+
10+
11+
112-- add the elementdatas you want to protect from client updates in here
213local tblProtectedElementDatas = {[" Score" ] = true };
314
@@ -16,6 +27,18 @@ addEventHandler("onElementDataChange", root, clientChangesElementData);
1627
1728
1829
30+ -- https://wiki.multitheftauto.com/wiki/OnPlayerChangesProtectedData
31+ -- gets triggered when a client tries to change protected element data
32+ -- see elementdata_whitelisted config https://wiki.multitheftauto.com/wiki/Server_mtaserver.conf#elementdata_whitelisted
33+ -- this needs to be setup in conjunction with your existing elementdatas to take necessary action!
34+ -- the key feature is to prevent the client from updating non synced server elementdatas if they know the key and attached element
35+ function clientChnagesProtectedData (uElement , strKey , unValue )
36+ logViolation (source , " Tried to change protected elementdata for key " .. tostring (strKey ).. " to value " .. tostring (unValue ).. " for element " .. tostring (uElement ).. " (" .. getElementType (uElement ).. " )" );
37+ end
38+ addEventHandler (" onPlayerChangesProtectedData" , root , clientChnagesProtectedData );
39+
40+
41+
1942-- https://wiki.multitheftauto.com/wiki/OnPlayerACInfo
2043-- gets triggered when AC detects something for client on connect
2144function clientNotifyACInfo (tblDetectedACList , iD3D9Size , strD3D9MD5 , strD3D9SHA256 )
@@ -55,4 +78,80 @@ function clientNetworkStatus(iStatus, iTicks)
5578 logViolation (source , " Network interruption has stopped after " .. iTicks .. " ticks" );
5679 end
5780end
58- addEventHandler (" onPlayerNetworkStatus" , root , clientNetworkStatus );
81+ addEventHandler (" onPlayerNetworkStatus" , root , clientNetworkStatus );
82+
83+
84+
85+ -- https://wiki.multitheftauto.com/wiki/OnPlayerProjectileCreation
86+ -- gets triggered when a player creates a projectile sync packets (eg. shoots a weapon, vehicle weapon or via createProjectile)
87+ function clientCreateProjectile (iWeaponType , fPX , fPY , fPZ , fForce , uTarget , fRX , fRY , fRZ , fVX , fVY , fVZ )
88+ if (isElement (source )) then
89+ if (tblPlayerProjectiles [source ]) then
90+ tblPlayerProjectiles [source ] = tblPlayerProjectiles [source ] + 1 ;
91+ else
92+ tblPlayerProjectiles [source ] = 1 ;
93+ end
94+ end
95+ end
96+ addEventHandler (" onPlayerProjectileCreation" , root , clientCreateProjectile );
97+
98+
99+
100+ -- https://wiki.multitheftauto.com/wiki/OnExplosion
101+ -- gets triggered when an explosion occurs, either via server script or client sync packet
102+ function clientCreateExplosion (fPX , fPY , fPZ , iType )
103+ if (isElement (source )) then
104+ if (getElementType (source ) == " player" ) then
105+ if (tblRegularExplosions [source ]) then
106+ tblRegularExplosions [source ] = tblRegularExplosions [source ] + 1 ;
107+ else
108+ tblRegularExplosions [source ] = 1 ;
109+ end
110+ end
111+ end
112+ end
113+ addEventHandler (" onExplosion" , root , clientCreateExplosion );
114+
115+
116+
117+ -- https://wiki.multitheftauto.com/wiki/OnVehicleExplode
118+ -- gets triggered when a vehicle explodes, either via server script or client sync packet
119+ function clientCreateVehicleExplosion (bWithExplosion , uPlayer )
120+ if (isElement (uPlayer )) then
121+ if (tblVehicleExplosions [uPlayer ]) then
122+ tblVehicleExplosions [uPlayer ] = tblVehicleExplosions [uPlayer ] + 1 ;
123+ else
124+ tblVehicleExplosions [uPlayer ] = 1 ;
125+ end
126+ end
127+ end
128+ addEventHandler (" onVehicleExplode" , root , clientCreateVehicleExplosion );
129+
130+
131+
132+ -- setup a timer with specified interval above and check if any client sent too many sync packets in the given time
133+ -- thresholds need to be adjusted for your need and actions taken!
134+ setTimer (function ()
135+ for uPlayer , iCounter in pairs (tblPlayerProjectiles ) do
136+ if (iCounter >= iPlayerProjectileThreshold ) then
137+ logViolation (uPlayer , " Exceeded projectile threshold " .. tostring (iPlayerProjectileThreshold ).. " - Count: " .. tostring (iCounter ));
138+ end
139+ end
140+
141+ for uPlayer , iCounter in pairs (tblRegularExplosions ) do
142+ if (iCounter >= iRegularExplosionThreshold ) then
143+ logViolation (uPlayer , " Exceeded regular explosions threshold " .. tostring (iRegularExplosionThreshold ).. " - Count: " .. tostring (iCounter ));
144+ end
145+ end
146+
147+ for uPlayer , iCounter in pairs (tblVehicleExplosions ) do
148+ if (iCounter >= iVehicleExplosionThreshold ) then
149+ logViolation (uPlayer , " Exceeded vehicle explosions threshold " .. tostring (iVehicleExplosionThreshold ).. " - Count: " .. tostring (iCounter ));
150+ end
151+ end
152+
153+ tblPlayerProjectiles = {};
154+ tblRegularExplosions = {};
155+ tblVehicleExplosions = {};
156+
157+ end , iExplosionCheckInterval , 0 );
0 commit comments