HR_Shaft

Ping Kick v3 for Phasor v2

Mar 1st, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.57 KB | None | 0 0
  1. --[[ ### Ping Kick Script v3 ###]]--
  2. --[[ ###     by H® Shaft     ###]]--
  3. --[[ ###    for Phasor v2    ###]]--
  4. --[[ ###  other thanks below ###]]--
  5.  
  6. -- updated 2/17/2014 to change old code, and to change from players hash to players ip, added remove timers at game end, added game_started
  7. -- Added Spanish warnings.
  8.  
  9. max_ping = 500          -- Max Ping: edit as needed  
  10. pingkick_timeout = 2    -- After this many minutes any player warned of high ping will be forgotten, or kicked if still too high. - edit as needed
  11.  
  12. --don't edit:
  13. pingwarned = {}
  14. game_started = false
  15.  
  16. function GetRequiredVersion()
  17.     return 200
  18. end
  19.  
  20. function OnScriptLoad(process, game, persistent)
  21.  
  22. end
  23.  
  24. function OnNewGame(map)
  25.     game_started = true
  26.     pingwarned = {}
  27.     pingtimer = registertimer(180000, "pingkickTimer") -- check all players pings every 180000ms = 3 minutes
  28.     pingtimeouter = registertimer(pingkick_timeout * 60000, "pingTimeout")
  29. end
  30.  
  31. function pingTimeout(id, count)  --re-evaluate warn or kick
  32.     for i = 0,15 do
  33.         if getplayer(i) then
  34.             pingwarned[getip(i)] = nil
  35.         end
  36.     end
  37. end
  38.  
  39. function pingkickTimer(id, count)
  40.     for i = 0,15 do
  41.         local m_player = getplayer(i)
  42.         if m_player then
  43.             local player_ping = readword(m_player, 0xDC)
  44.             local ping = player_ping
  45.             local maxping = max_ping
  46.             if player_ping > max_ping and game_started then
  47.                 if pingwarned[getip(i)] and not isadmin(i) then
  48.                     say(getname(i) .. " was kicked for having a ping over " .. maxping .. "ms.")
  49.                     svcmd("sv_kick " .. resolveplayer(i))
  50.                     log_msg(1, getname(i) .. " was kicked for high ping: " .. ping)
  51.                     log_msg(3, getname(i) .. " was kicked for high ping: " .. ping)
  52.                 else
  53.                     warn_ping = registertimer(1000, "pingwarn")
  54.                 end
  55.             end
  56.         end
  57.     end
  58.     return true
  59. end
  60.  
  61. function OnPlayerLeave(player)
  62.     pingwarned[getip(player)] = nil
  63. end
  64.  
  65. function pingwarn(id, count)  --warns player they will be kicked, tells them their ping
  66.     if count == 1 then
  67.         for i = 0,15 do
  68.             local m_player = getplayer(i)
  69.             if m_player then
  70.                 local player_ping = readword(m_player, 0xDC)
  71.                 local timeout = pingkick_timeout
  72.                 local ping = player_ping
  73.                 local maxping = max_ping
  74.                 if player_ping > max_ping and game_started then
  75.                     if pingwarned[getip(i)] == nil then
  76.                         pingwarned[getip(i)] = true
  77.                         privatesay(i, "WARNING: Your Ping: " .. ping .. "ms. You will be kicked if your ping is over " .. maxping .. "ms.")
  78.                         privatesay(i, "You have " .. timeout .. " minute(s) to solve it before being kicked.")
  79.                         privatesay(i, "Usted tiene 2 minuto(s) para resolver este PING antes de ser expulsado.")
  80.                         sendconsoletext(i, "YOUR PING IS TOO HIGH! " .. ping .. "ms.  TU PING ES DEMASIADO ALTA: " .. ping .. "ms.")
  81.                     end
  82.                 end
  83.             end
  84.         end
  85.     end
  86.     return true
  87. end
  88.  
  89. function OnGameEnd(stage)
  90.     if stage == 1 then
  91.         game_started = false
  92.         if warn_ping then
  93.             removetimer(warn_ping)
  94.             warn_ping = nil
  95.         end
  96.         if pingtimer then
  97.             removetimer(pingtimer)
  98.             pingtimer = nil
  99.         end
  100.         if pingtimeouter then
  101.             removetimer(pingtimeouter)
  102.             pingtimeouter = nil
  103.         end
  104.     end
  105. end
  106.  
  107. -- 365 is high limit for UK connecting to US server, 333 is too low and will kick even though UK player is not warping nor having packet loss (lag)
  108. -- for regional ping limits (client to host) that is stable such as Chicago to New York a good high is 250 which means UK players would get warned/kicked quickly
  109.  
  110. -- Created by H® Shaft thank you to Oxide, AelitePrime, Nugget & Wizard.
  111. -- Visit http://halorace.org/forum/index.php?topic=514.0 or
  112. -- Visit http://pastebin.com/u/HR_Shaft for more phasor scripts
Advertisement
Add Comment
Please, Sign In to add comment