<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3AKicking_for_high_ping</id>
	<title>Scripts:Kicking for high ping - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3AKicking_for_high_ping"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:Kicking_for_high_ping&amp;action=history"/>
	<updated>2026-08-06T01:14:57Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://bf2tech.uturista.pt/index.php?title=Scripts:Kicking_for_high_ping&amp;diff=103&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;__TOC__  = Introduction =  There are many things that may influence the quality of a BF2 server. One of them is the ping of the players. Playing against a lot of players with...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:Kicking_for_high_ping&amp;diff=103&amp;oldid=prev"/>
		<updated>2018-06-22T15:25:02Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__TOC__  = Introduction =  There are many things that may influence the quality of a BF2 server. One of them is the ping of the players. Playing against a lot of players with...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
There are many things that may influence the quality of a BF2 server. One of them is the ping of the players. Playing against a lot of players with very high ping is straight out frustrating. Therefore a lot of server-operators choose to kick players with high ping, and the best way to do it is of course to do it automatically.&lt;br /&gt;
&lt;br /&gt;
With that in mind, we at [http://www.battlefield.no/ Battlefield.no] have developed a &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;ping kick&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; script that solves this problem on our servers. And hopefully it can be of use to the rest of the community as well.&lt;br /&gt;
&lt;br /&gt;
Current version is 1.2, added 2005-07-03.&lt;br /&gt;
&lt;br /&gt;
= Features =&lt;br /&gt;
&lt;br /&gt;
What the the &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;ping kick&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; script can offer is to&lt;br /&gt;
&lt;br /&gt;
* kick people with high ping based on&lt;br /&gt;
&lt;br /&gt;
** a configurable &amp;#039;&amp;#039;pinglimit&amp;#039;&amp;#039;&lt;br /&gt;
** after a configurable number of &amp;#039;&amp;#039;warnings&amp;#039;&amp;#039; (that only appear in the debug log on the server, if enabled)&lt;br /&gt;
** with a configurable &amp;#039;&amp;#039;interval&amp;#039;&amp;#039; between ping checks&lt;br /&gt;
&lt;br /&gt;
* wait until a player has started playing before checking his/her ping, to avoid kicks on mapchange etc&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Getting Started =&lt;br /&gt;
&lt;br /&gt;
To get started with the &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;ping kick&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; script you need to:&lt;br /&gt;
&lt;br /&gt;
* Download the script [http://www.battlefield.no/filer/pafiledb.php?action=file&amp;amp;id=191 here], and rename it to &amp;#039;&amp;#039;pingkick.py&amp;#039;&amp;#039;.&lt;br /&gt;
* Place it in the &amp;#039;&amp;#039;admin/standard_admin&amp;#039;&amp;#039; directory in your BF2 directory.&lt;br /&gt;
* Place the following code in the &amp;#039;&amp;#039;admin/standard_admin/__init__.py&amp;#039;&amp;#039; file in your BF2 directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import pingkick&lt;br /&gt;
pingkick.init()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For these changes to take effect you will need to restart your BF2 server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= The Ping Kick Script =&lt;br /&gt;
&lt;br /&gt;
This is the &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;ping script&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; as we use it at [http://web.archive.org/web/20081207025345/http://www.battlefield.no/ Battlefield.no]. Feel free to copy it, and since this is a wiki, feel free to modify it. But we would be very grateful of you appended a note to the updates section if you do.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;ping kick&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; script comes with four settings you can change:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
autokick = 1 # Enables/disables autockicking&lt;br /&gt;
pinglimit = 150 # The ping limit, obviously ;-p&lt;br /&gt;
warnings = 3 # The number of warnings a player get before being kicked&lt;br /&gt;
interval = 30 # The interval between ping checks&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can either change these settings directly in the script, or you can make sure there exists a dictionary in the &amp;#039;&amp;#039;bf2&amp;#039;&amp;#039; object, called &amp;#039;&amp;#039;adminoptions&amp;#039;&amp;#039;, with the following keys:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pk.pingAutoKick&lt;br /&gt;
pk.pingLimit&lt;br /&gt;
pk.warnings&lt;br /&gt;
pk.interval&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If they exist, they will override the defaults set in the &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;ping kick&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; script. If you use our [[Scripts:Modified_admin_script|modified admin script]], the &amp;#039;&amp;#039;adminoptions&amp;#039;&amp;#039; dictionary is made available, and populated with the values in the &amp;#039;&amp;#039;adminsettings.con&amp;#039;&amp;#039; file. So remember to add the above keys with appropriate values to the file. See [[Scripts:Modified_admin_script|here]] for more details on that.&lt;br /&gt;
&lt;br /&gt;
== Output ==&lt;br /&gt;
&lt;br /&gt;
There &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;ping kick&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; script prints a variety of messages, but to actually view them you will need to enable debug-logging. This is done by&lt;br /&gt;
&lt;br /&gt;
* setting g_debug to 1 in &amp;#039;&amp;#039;&amp;lt;bf2&amp;gt;/python/bf2/__init__.py&amp;#039;&amp;#039;&lt;br /&gt;
* enabling a writer, like we&amp;#039;ve done in [[Scripts:Modified_admin_script|modified admin script]]&lt;br /&gt;
&lt;br /&gt;
When a player is cought by the &amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039;ping kick&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; script with a ping that is too high, a message like the following is logged:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[2005-07-03 04:44:28] PINGKICK: Player Panic[bf2.no] has exceeded the ping limit 2 time(s) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And when a player has been issued the maximum number of warnings, and is being kicked, a message like the following is logged:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[2005-07-03 04:44:43] PINGKICK: Kicking player Panic[bf2.no] for high ping ([120, 118, 118] &amp;gt; 100) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers inside the braces are ping values that has been detected and that are in violation of the ping limit. And the number to the right of the &amp;#039;&amp;#039;greater than&amp;#039;&amp;#039; sign is the ping limit.&lt;br /&gt;
&lt;br /&gt;
And five seconds before a player in violation of the ping limit is being kicked, a message like the following is printed in-game:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;BF2.NO PING KICKER: Kicking player Panic[bf2.no] for high ping. (Limit is 100, player caught with [120, 118, 118].) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Again the numbers inside the braces are ping values that has been detected and that are in violation of the ping limit, and the first one is the ping limit. &lt;br /&gt;
&lt;br /&gt;
== The Code ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Module: pingkick.py&lt;br /&gt;
# Authors: Kybber and Panic, Battlefield.no&lt;br /&gt;
# Version 1.2&lt;br /&gt;
# Description:&lt;br /&gt;
#   This script kicks players with high ping, based on three different&lt;br /&gt;
#   settings in the file &amp;#039;adminsettings.con&amp;#039;, loaded by the modified admin&lt;br /&gt;
#   script (sv.adminScript = bfno_v1.1.py). See requirements for details.&lt;br /&gt;
# Requirements:&lt;br /&gt;
#   None.&lt;br /&gt;
# Installation:&lt;br /&gt;
#   Save this script as &amp;#039;pingkick.py&amp;#039; in your &amp;lt;bf2&amp;gt;/admin/standard_admin directory,&lt;br /&gt;
#   and add the lines &amp;#039;import pingkick&amp;#039; and &amp;#039;pingkick.init()&amp;#039; to the file&lt;br /&gt;
#   &amp;#039;&amp;lt;bf2&amp;gt;/admin/standard_admin/__init__.py&amp;#039;.&lt;br /&gt;
#&lt;br /&gt;
# Changes from 1.0 to 1.1:&lt;br /&gt;
# - Added support for stand-alone operation. (Will use bf2.adminoptions if available)&lt;br /&gt;
# - The script now only checks ping while game status is &amp;#039;Playing&amp;#039;&lt;br /&gt;
# - Switched from &amp;#039;bfno&amp;#039; to prefix &amp;#039;pk&amp;#039; for ping kick settings in &amp;#039;bf2.adminoptions&amp;#039;.&lt;br /&gt;
# - Other, minor updates.&lt;br /&gt;
#&lt;br /&gt;
# Changes from 1.1. to 1.2:&lt;br /&gt;
# - Added methods to deactivate checking while players are not really playing.&lt;br /&gt;
# - Added safeguard against kicking a player that has gotten a disconnected &amp;quot;ping violater&amp;#039;s&amp;quot; index.&lt;br /&gt;
# - Made the logging more verbose and ingame messaging less verbose.&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
#                     C O N F I G U R A T I O N&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Settings for auto-kicking:&lt;br /&gt;
autokick = 1      # Enables/disables autockicking&lt;br /&gt;
pinglimit = 150   # The ping limit, obviously ;-p&lt;br /&gt;
warnings = 3      # The number of warnings a player get before being kicked&lt;br /&gt;
interval = 30     # The interval between ping checks&lt;br /&gt;
# NB: These settings will be overridden by their counter-parts in&lt;br /&gt;
# bf2.adminoptions[&amp;#039;pk.&amp;lt;autoKick|pingLimit|warnings|interval&amp;#039;]&lt;br /&gt;
# if those are present.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
#                        I M P O R T&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
import host&lt;br /&gt;
import bf2&lt;br /&gt;
from bf2 import g_debug&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
#                       V A R I A B L E S&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
# We need our own debug flag:&lt;br /&gt;
bfno_debug = False&lt;br /&gt;
&lt;br /&gt;
# Some timers:&lt;br /&gt;
pktimer   = None  # Timer firing off the ping checker. Depends on the &amp;#039;interval&amp;#039; variable.&lt;br /&gt;
kicktimer = None  # Timer that delays kicking after the final warning has been issued.&lt;br /&gt;
msgtimer  = None  # Timer that delays the &amp;quot;activated&amp;quot; message after entering bf2.GameStatus.Playing&lt;br /&gt;
&lt;br /&gt;
# List of people to kick for high ping. Will contain touples of p.index and p.getProfileId():&lt;br /&gt;
kicklist = []&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# For keeping track of the game status:&lt;br /&gt;
gamestatus = None&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
#                       F U N C T I O N S&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# The init function run by the standard_admin/__init__ functions:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def init():&lt;br /&gt;
   global interval,bfno_debug&lt;br /&gt;
   try:&lt;br /&gt;
      if bf2.bfno.debug: bfno_debug = True&lt;br /&gt;
   except:&lt;br /&gt;
      pass&lt;br /&gt;
   if bfno_debug or bfno_debug: print &amp;#039;PINGKICK: initializing pingkick script&amp;#039;&lt;br /&gt;
   # Try to read the settings:&lt;br /&gt;
   getSettings()&lt;br /&gt;
   # Force at least 10 seconds between ping checks:&lt;br /&gt;
   if interval &amp;lt; 10: interval = 10&lt;br /&gt;
   # Print debug message if autokick is disabled:&lt;br /&gt;
   if 1 != autokick:&lt;br /&gt;
      if bfno_debug or bfno_debug: print &amp;#039;PINGKICK: High ping autokick not enabled&amp;#039;&lt;br /&gt;
  &lt;br /&gt;
   # Autokick is enabled, so hook it up:&lt;br /&gt;
   else:&lt;br /&gt;
      if bfno_debug or bfno_debug: print &amp;#039;PINGKICK: Enabling kick for high ping. Limit = %s, max warnings = %s.&amp;#039; % (pinglimit, warnings)&lt;br /&gt;
&lt;br /&gt;
      # Register &amp;#039;PlayerConnect&amp;#039; callback:&lt;br /&gt;
      host.registerHandler(&amp;#039;PlayerConnect&amp;#039;, onPlayerConnect, 1)&lt;br /&gt;
      host.registerHandler(&amp;#039;PlayerSpawn&amp;#039;, onPlayerSpawn, 1)&lt;br /&gt;
      host.registerGameStatusHandler(onGameStatusChanged)&lt;br /&gt;
  &lt;br /&gt;
      # Reset TK Warnings&lt;br /&gt;
      for p in bf2.playerManager.getPlayers():&lt;br /&gt;
         onPlayerConnect(p)&lt;br /&gt;
&lt;br /&gt;
      # PingKickTimer:&lt;br /&gt;
      enableCheckTimer()&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Get the settings from the bf2.adminsettings object:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def getSettings():&lt;br /&gt;
   global autokick,pinglimit,warnings,interval&lt;br /&gt;
   # Try to access the autokick setting:&lt;br /&gt;
   try:&lt;br /&gt;
      if bfno_debug: print &amp;quot;PINGKICK: Reading settings from bf2.adminoptions:&amp;quot;&lt;br /&gt;
      autokick  = int(bf2.adminoptions[&amp;#039;pk.autoKick&amp;#039;])&lt;br /&gt;
      pinglimit = int(bf2.adminoptions[&amp;#039;pk.pingLimit&amp;#039;])&lt;br /&gt;
      warnings  = int(bf2.adminoptions[&amp;#039;pk.warnings&amp;#039;])&lt;br /&gt;
      interval  = int(bf2.adminoptions[&amp;#039;pk.interval&amp;#039;])&lt;br /&gt;
   except:&lt;br /&gt;
      if bfno_debug: print &amp;quot;PINGKICK: WARNING - Could not get settings from &amp;#039;bf2.adminoptions&amp;#039;. Using default values:&amp;quot;&lt;br /&gt;
   if bfno_debug:&lt;br /&gt;
      print &amp;quot;  autokick  : &amp;quot; + str(autokick)&lt;br /&gt;
      print &amp;quot;  pinglimit : &amp;quot; + str(pinglimit)&lt;br /&gt;
      print &amp;quot;  maxwarns  : &amp;quot; + str(warnings)&lt;br /&gt;
      print &amp;quot;  interval  : &amp;quot; + str(interval)&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Callback function for the &amp;quot;PlayerConnect&amp;quot; event:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def onPlayerConnect(p):&lt;br /&gt;
   &amp;quot;&amp;quot;&amp;quot;Resets the ping warning counter for the player&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
   resetPlayer(p)&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Callback function for the &amp;quot;PlayerSpawn&amp;quot; event:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def onPlayerSpawn(p,s):&lt;br /&gt;
   &amp;quot;&amp;quot;&amp;quot;Sets the &amp;#039;actuallyPlaying&amp;#039; flag for the player&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
   p.actuallyPlaying = True&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Callback function for the &amp;quot;PreGame&amp;quot; game status event:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def onGameStatusChanged(status):&lt;br /&gt;
   &amp;quot;&amp;quot;&amp;quot;Enables the ping check timer&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
   # Import variables, and update the game status:&lt;br /&gt;
   global gamestatus, kicklist, msgtimer&lt;br /&gt;
   gamestatus = status&lt;br /&gt;
   if gamestatus == bf2.GameStatus.Playing and autokick:&lt;br /&gt;
      if bfno_debug: print &amp;quot;PINGKICK: Setting msgtimer&amp;quot;&lt;br /&gt;
      msgtimer = bf2.Timer(onMsgTimer,10,1)&lt;br /&gt;
   # Return if not PreGame:&lt;br /&gt;
   elif gamestatus == bf2.GameStatus.PreGame:&lt;br /&gt;
      if bfno_debug: print &amp;quot;PINGKICK: Game status changed to PreGame. Get settings and and re-enabling check-timer&amp;quot;&lt;br /&gt;
      # Reset the kicklist&lt;br /&gt;
      kicklist = []&lt;br /&gt;
      # Read the settings again:&lt;br /&gt;
      getSettings()&lt;br /&gt;
      # Enable the ping check timer:&lt;br /&gt;
      enableCheckTimer()&lt;br /&gt;
   elif gamestatus == bf2.GameStatus.EndGame:&lt;br /&gt;
      # Reset players:&lt;br /&gt;
      resetPlayers()&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Reset the bfno pingscript variables placed in the player object:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def resetPlayers():&lt;br /&gt;
   # Reset TK Warnings and more:&lt;br /&gt;
   for p in bf2.playerManager.getPlayers():&lt;br /&gt;
      resetPlayer(p)&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Reset the bfno pingscript variables placed in the player object:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def resetPlayer(p):&lt;br /&gt;
   # Reset TK Warnings and more:&lt;br /&gt;
   p.pingWarnings = 0&lt;br /&gt;
   p.detectedPing = []&lt;br /&gt;
   p.actuallyPlaying = False&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Callback function for timer, that delays a message at round start:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def onMsgTimer(data):&lt;br /&gt;
   global msgtimer&lt;br /&gt;
   if bfno_debug: print &amp;quot;PINGKICK: Entering onMsgTimer&amp;quot;&lt;br /&gt;
   msg = &amp;quot;Activated! Kicking at &amp;quot; + str(pinglimit) + &amp;quot; after &amp;quot; + str(warnings) + &amp;quot; warnings.&amp;quot;&lt;br /&gt;
   sendMsg(msg)&lt;br /&gt;
   msgtimer.destroy()&lt;br /&gt;
   msgtimer = None&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Send text messages to the server, using rcon game.sayAll:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def sendMsg(msg):&lt;br /&gt;
   # Sure you can edit this, and remove &amp;#039;bf2.no&amp;#039;. But hey, why not give us the credit? ;-)&lt;br /&gt;
   host.rcon_invoke(&amp;quot;game.sayAll \&amp;quot;BF2.NO PING KICKER: &amp;quot; + str(msg) + &amp;quot;\&amp;quot;&amp;quot;)&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Enable the pktimer:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def enableKickTimer():&lt;br /&gt;
   &amp;quot;&amp;quot;&amp;quot;Enables the timer that runs the &amp;#039;kickPlayers&amp;#039; functions&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
   global kicktimer&lt;br /&gt;
   if g_debug or bfno_debug: print &amp;quot;PINGKICK: Enabling the kicktimer...&amp;quot;&lt;br /&gt;
   kicktimer = bf2.Timer(kickPlayers, 5, 1)&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Enable the pktimer:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def enableCheckTimer():&lt;br /&gt;
   &amp;quot;&amp;quot;&amp;quot;Enables the timer that runs the &amp;#039;checkPing&amp;#039; function&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
   global pktimer&lt;br /&gt;
   if pktimer:&lt;br /&gt;
      return True&lt;br /&gt;
   else:&lt;br /&gt;
      # Create the timer:&lt;br /&gt;
      if g_debug or bfno_debug: print &amp;quot;PINGKICK: Timer not enabled. Enabling...&amp;quot;&lt;br /&gt;
      pktimer = bf2.Timer(checkPing, interval, 1)&lt;br /&gt;
      pktimer.setRecurring(interval)&lt;br /&gt;
      # Print debug message telling the status of the timer:&lt;br /&gt;
      if pktimer:&lt;br /&gt;
         if g_debug and bfno_debug: print &amp;quot;PINGKICK: Time = %s&amp;quot; % (pktimer.getTime())&lt;br /&gt;
         return True&lt;br /&gt;
      else:&lt;br /&gt;
         if bfno_debug: print &amp;quot;PINGKICK: Not enabled&amp;quot;&lt;br /&gt;
         return False&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Loop all players, checking their ping, kick high-pinger:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def checkPing(data):&lt;br /&gt;
   &amp;quot;&amp;quot;&amp;quot;Checks ping of all players, and kicks high-pingers&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
   global kicklist&lt;br /&gt;
&lt;br /&gt;
   # We only want to check ping during rounds:&lt;br /&gt;
   #if gamestatus != bf2.GameStatus.Playing: return&lt;br /&gt;
  &lt;br /&gt;
   # Make sure our timer is enabled:&lt;br /&gt;
   if not enableCheckTimer(): return&lt;br /&gt;
&lt;br /&gt;
   if bfno_debug: print &amp;quot;PINGKICK: Running checkPing&amp;quot;&lt;br /&gt;
&lt;br /&gt;
   # Loop all players&lt;br /&gt;
   for p in bf2.playerManager.getPlayers():&lt;br /&gt;
      # Do not check players that hasn&amp;#039;t completed their &amp;quot;connect&amp;quot; yet:&lt;br /&gt;
      #if not p.isConnected(): continue&lt;br /&gt;
      if not p.actuallyPlaying: continue&lt;br /&gt;
      # Get the player name. We&amp;#039;ll use it often:&lt;br /&gt;
      name = str(p.getName())&lt;br /&gt;
      # Check the ping if the limit hasn&amp;#039;t been reached:&lt;br /&gt;
      ping = p.getPing()&lt;br /&gt;
      # If we have a valid ping, check it, and issue a warning if the ping exceeds the limit:&lt;br /&gt;
      if ping:&lt;br /&gt;
         #if bfno_debug: print &amp;quot;PINGKICK: &amp;quot; + name + &amp;quot; has &amp;quot; + str(ping) + &amp;quot; in ping and has &amp;quot; + str(p.pingWarnings) + &amp;quot; Ping-warnings&amp;quot;&lt;br /&gt;
         if ping &amp;gt; pinglimit:&lt;br /&gt;
            p.pingWarnings += 1&lt;br /&gt;
            p.detectedPing.append(ping)&lt;br /&gt;
            if g_debug or bfno_debug: print &amp;quot;PINGKICK: Player &amp;quot; + name + &amp;quot; has exceeded the ping limit &amp;quot; + str(p.pingWarnings) + &amp;quot; time(s)&amp;quot;&lt;br /&gt;
            #sendMsg(&amp;quot;WARNING: &amp;quot; + name + &amp;quot; has exeeded the ping limit &amp;quot; + str(p.pingWarnings) + &amp;quot; time(s)&amp;quot;)&lt;br /&gt;
         # Issue a warning if a player has reached the maximum number of warnings. Will be kicked next time &amp;#039;checkPing&amp;#039; is run:&lt;br /&gt;
         if warnings &amp;lt;= p.pingWarnings:&lt;br /&gt;
            sendMsg(&amp;quot;Kicking player &amp;quot; + name + &amp;quot; for high ping. (Limit is &amp;quot; + str(pinglimit) + &amp;quot;, player caught with &amp;quot; + str(p.detectedPing) + &amp;quot;.)&amp;quot;)&lt;br /&gt;
            # Add the player to the kicklist:&lt;br /&gt;
            kicklist.append((p.index,p.getProfileId()))&lt;br /&gt;
   # Check of we shall enable the kicktimer:&lt;br /&gt;
   if len(kicklist):&lt;br /&gt;
      enableKickTimer()&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Function run by the kicktimer:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def kickPlayers(data):&lt;br /&gt;
   &amp;quot;&amp;quot;&amp;quot;Loops through &amp;#039;kicklist&amp;#039;, and kicks players accordingly.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
   #print &amp;quot;PINGKICK: kickPlayers...&amp;quot;&lt;br /&gt;
   global kicklist,kicktimer&lt;br /&gt;
   for i in kicklist:&lt;br /&gt;
      p = bf2.playerManager.getPlayerByIndex(i[0])&lt;br /&gt;
      # Make sure we&amp;#039;re not kicking a player that has gotten a disconnected &amp;quot;ping violater&amp;#039;s&amp;quot; index:&lt;br /&gt;
      if not p.getProfileId() == i[1]: continue&lt;br /&gt;
      # Check if this player has reached the limit for maximum warnongs&lt;br /&gt;
      if warnings &amp;lt;= p.pingWarnings:&lt;br /&gt;
         # Kick if limit is reached:&lt;br /&gt;
         if g_debug or bfno_debug: print &amp;quot;PINGKICK: Kicking player &amp;quot; + p.getName() + &amp;quot; for high ping (&amp;quot; + str(p.detectedPing) + &amp;quot; &amp;gt; &amp;quot;+str(pinglimit)+&amp;quot;)&amp;quot;&lt;br /&gt;
         result = host.rcon_invoke(&amp;quot;admin.kickPlayer &amp;quot; + str(p.index))&lt;br /&gt;
   kicklist = []&lt;br /&gt;
   kicktimer.destroy()&lt;br /&gt;
   kicktimer = None&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Updates ==&lt;br /&gt;
&lt;br /&gt;
Please add a note here if you update the code above.&lt;br /&gt;
&lt;br /&gt;
* 2005-07-03: Updated code and documentation to v1.2 (Panic)&lt;br /&gt;
* 2005-06-18: Updated code and documentation to v1.1 (Panic)&lt;br /&gt;
* 2005-06-18: Added documentation (Panic)&lt;br /&gt;
* 2005-06-17: Added v1.0 of the code (Panic)&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>