Python1320

Exploit prevention test

Jun 11th, 2011
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.93 KB | None | 0 0
  1. -- autorun/server/qbox_rip.lua
  2.  
  3. ----------------------------------------------------------------
  4. -- Maximum mass test
  5. -- Todo: Make it more sane
  6. ----------------------------------------------------------------
  7. local mass = 0
  8. local frozen = false
  9. local localent = NULL
  10. local function IncMass(Entities)
  11.  
  12.         if Entities != nil then
  13.                
  14.                 local PhysObj = NULL
  15.                 for _,t in pairs(Entities) do  
  16.                         local ent = t.Ent2 != localent and t.Ent2 or t.Ent1
  17.                         if ent and ent:IsValid() then
  18.                                
  19.                                 PhysObj = ent:GetPhysicsObject()
  20.                                
  21.                                 if PhysObj:IsValid() then
  22.                                
  23.                                         if not PhysObj:IsMoveable() then
  24.                                                 --D("Pickup deny",ent)
  25.                                                 frozen = true
  26.                                                 return
  27.                                         end
  28.                                         --D(ent,"->",mass,"+",PhysObj:GetMass())
  29.                                         mass = mass + PhysObj:GetMass()
  30.                                        
  31.                                 end
  32.                                
  33.                         end
  34.                 end
  35.                
  36.         end
  37. end
  38. ----------------------------------------------------------------
  39.  
  40.  
  41.  
  42. ----------------------------------------------------------------
  43. -- Prevent lifting odd objects. Slightly more realism but lots of annoyage
  44. -- TODO
  45. ----------------------------------------------------------------
  46. hook.Add('GravGunPickupAllowed','QBox_Rip',function( pl, ent )
  47.  
  48.        
  49.         if ( ent && ent:IsValid() and ent:GetPhysicsObject():IsValid() ) then
  50.                
  51.                 frozen = false
  52.                 mass = ent:GetPhysicsObject():GetMass()
  53.                 localent = ent
  54.                 local maxmass = GetConVarNumber("physcannon_maxmass")
  55.                 local PhysObj = NULL
  56.                
  57.                
  58.                 local entz = constraint.FindConstraints(ent,"Weld")
  59.                 IncMass(entz)  
  60.                 entz = constraint.FindConstraints(ent,"Hydraulic")
  61.                 IncMass(entz)
  62.                 entz = constraint.FindConstraints(ent,"Muscle")
  63.                 IncMass(entz)
  64.                 entz = constraint.FindConstraints(ent,"Pulley")
  65.                 IncMass(entz)
  66.                
  67.                
  68.                 -- TODO: Objects added to the ent count ConstraintsToTargetObject times. Fix
  69.  
  70.                 if mass > maxmass || frozen then
  71.                       --  D("Pickup deny for",pl," frozen="..tostring(frozen).." | "..(maxmass).."(maxmass) < "..tostring(mass))
  72.                         return false
  73.                 end
  74.        
  75.         end
  76.  
  77. end)
Advertisement
Add Comment
Please, Sign In to add comment