<?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%3AIdleKick</id>
	<title>Scripts:IdleKick - 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%3AIdleKick"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:IdleKick&amp;action=history"/>
	<updated>2026-08-06T01:11:31Z</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:IdleKick&amp;diff=102&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;&lt;pre&gt;  # ------------------------------------------------------------------------  # Module: IdleKick.py  # Authors: xlr8or, www.xlr8or.com  # Version 2.02  # Description:  #...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:IdleKick&amp;diff=102&amp;oldid=prev"/>
		<updated>2018-06-22T15:24:32Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;pre&amp;gt;  # ------------------------------------------------------------------------  # Module: IdleKick.py  # Authors: xlr8or, www.xlr8or.com  # Version 2.02  # Description:  #...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
 # ------------------------------------------------------------------------&lt;br /&gt;
 # Module: IdleKick.py&lt;br /&gt;
 # Authors: xlr8or, www.xlr8or.com&lt;br /&gt;
 # Version 2.02&lt;br /&gt;
 # Description:&lt;br /&gt;
 #   This script kicks players who are idle, based on the configuration settings below.&lt;br /&gt;
 # Requirements:&lt;br /&gt;
 #   None.&lt;br /&gt;
 # Installation:&lt;br /&gt;
 #   Save this script as &amp;#039;IdleKick.py&amp;#039; in your &amp;lt;bf2&amp;gt;/admin/standard_admin directory,&lt;br /&gt;
 #   and add the lines &amp;#039;import IdleKick&amp;#039; and &amp;#039;IdleKick.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;
 # Credit:&lt;br /&gt;
 #   This script is based on the pingkick script from the guys at bf2.no&lt;br /&gt;
 #   Format is mainly the same as what they did, and where I could use their&lt;br /&gt;
 #   code I have shamelessly done so.&lt;br /&gt;
 #   Credit therefor goes to Kybber and Panic, Battlefield.no&lt;br /&gt;
 # History:&lt;br /&gt;
 #   Autobalancing is a nice feature, but not when a large part of your team&lt;br /&gt;
 #   is doing something else, while staying ingame to not lose their slot.&lt;br /&gt;
 #   BF2 does not have a spectator ability, so if you&amp;#039;re not participating,&lt;br /&gt;
 #   you&amp;#039;re letting your team down!&lt;br /&gt;
 # Version 1.00 to 2.00:&lt;br /&gt;
 #   Cleaned some code up, added the ability to exclude clanmembers.&lt;br /&gt;
 # Version 2.00 to 2.01:&lt;br /&gt;
 #   Cleaned and corrected some global def&amp;#039;s.&lt;br /&gt;
 # Version 2.01 to 2.02:&lt;br /&gt;
 #   Fixed the clantag protection.&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 autokicking&lt;br /&gt;
 warnings    = 10     # The number of checks/warns a player has to fail/get before being kicked&lt;br /&gt;
 interval    = 30     # The interval between idle checks&lt;br /&gt;
 minplayers  = 5      # The minimum ammount of players online before checking idle players.&lt;br /&gt;
 announceme  = 0      # Announce the module at roundstart?&lt;br /&gt;
 warnme      = 1      # Warn the idle player 3 intervals before the maximum nr of warnings is reached?&lt;br /&gt;
 &lt;br /&gt;
 clantags = [&amp;quot;[XLR]&amp;quot;,&amp;quot;[xlr]&amp;quot;,&amp;quot;xlr8or&amp;quot;] # Clantags to protect from being kicked&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;
 # Let&amp;#039;s set up our debug flag:&lt;br /&gt;
 xlr_debug = False&lt;br /&gt;
 &lt;br /&gt;
 # The timers:&lt;br /&gt;
 IkCheckTimer    = None  # Timer firing off the idle 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;
 AnnounceTimer   = 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 idle. Will contain touples of p.index and p.getProfileId():&lt;br /&gt;
 kicklist = []&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;
 # The init function is run by the standard_admin/__init__ functions:&lt;br /&gt;
 # ------------------------------------------------------------------------&lt;br /&gt;
 def init():&lt;br /&gt;
 &lt;br /&gt;
    if g_debug or xlr_debug: print &amp;#039;IDLEKICK: initializing IdleKick script&amp;#039;&lt;br /&gt;
    # Force at least 20 seconds between idle 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 autokick != 1:&lt;br /&gt;
       if g_debug or xlr_debug: print &amp;#039;IDLEKICK: Idle 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 g_debug or xlr_debug: print &amp;#039;IDLEKICK: Enabling kick for being idle. Max. checkfails = %s.&amp;#039; % (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;
 &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;
    #Resets the idle warning counter for the player&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;
    # Sets the &amp;#039;actuallyPlaying&amp;#039; flag for the player&lt;br /&gt;
    p.actuallyPlaying = True&lt;br /&gt;
    # We can reset the warnings, since the player has actually spawned.&lt;br /&gt;
    p.idleWarnings = 0&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;
    # Enables the idle check timer&lt;br /&gt;
    # Import variables, and update the game status:&lt;br /&gt;
    global gamestatus, kicklist, AnnounceTimer&lt;br /&gt;
   &lt;br /&gt;
    gamestatus = status&lt;br /&gt;
    if gamestatus == bf2.GameStatus.Playing:&lt;br /&gt;
       if announceme ==1:&lt;br /&gt;
          if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Round Started. Setting AnnounceTimer&amp;quot;&lt;br /&gt;
          AnnounceTimer = bf2.Timer(onAnnounceTimer,10,1)&lt;br /&gt;
       if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Round Started. (Re-)enabling check-timer&amp;quot;&lt;br /&gt;
       # Enable the idle check timer:&lt;br /&gt;
       enableCheckTimer()&lt;br /&gt;
    elif gamestatus == bf2.GameStatus.PreGame:&lt;br /&gt;
       if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Game status changed to PreGame. Killing check-timer&amp;quot;&lt;br /&gt;
       # Kill the check-timer&lt;br /&gt;
       disableCheckTimer()&lt;br /&gt;
    elif gamestatus == bf2.GameStatus.Paused:&lt;br /&gt;
       if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Game status changed to Paused. Killing check-timer&amp;quot;&lt;br /&gt;
       # Kill the check-timer&lt;br /&gt;
       disableCheckTimer()&lt;br /&gt;
    elif gamestatus == bf2.GameStatus.EndGame:&lt;br /&gt;
       if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Game status changed to EndGame. Reset Players, Kicklist and killing check-timer&amp;quot;&lt;br /&gt;
       # Kill the check-timer&lt;br /&gt;
       disableCheckTimer()&lt;br /&gt;
       # Reset the kicklist&lt;br /&gt;
       kicklist = []&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 idlescript variables placed in the player object:&lt;br /&gt;
 # ------------------------------------------------------------------------&lt;br /&gt;
 def resetPlayers():&lt;br /&gt;
    # Reset Warnings and stuff:&lt;br /&gt;
    if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Resetting Players&amp;quot;&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 idlescript variables placed in the player object:&lt;br /&gt;
 # ------------------------------------------------------------------------&lt;br /&gt;
 def resetPlayer(p):&lt;br /&gt;
    # Reset Warnings and stuff:&lt;br /&gt;
    p.idleWarnings = 0&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 onAnnounceTimer(data):&lt;br /&gt;
    global AnnounceTimer&lt;br /&gt;
   &lt;br /&gt;
    if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Entering onAnnounceTimer... Sending the Activated announcement&amp;quot;&lt;br /&gt;
    msg = &amp;quot;Activated! Kicking after &amp;quot; + str(warnings) + &amp;quot; checks.&amp;quot;&lt;br /&gt;
    sendMsg(msg)&lt;br /&gt;
    AnnounceTimer.destroy()&lt;br /&gt;
    AnnounceTimer = 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. But hey, why not give us the credit? ;-)&lt;br /&gt;
    host.rcon_invoke(&amp;quot;game.sayAll \&amp;quot;[XLR]No-Idle: &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 KickTimer:&lt;br /&gt;
 # ------------------------------------------------------------------------&lt;br /&gt;
 def enableKickTimer():&lt;br /&gt;
    # Enables the timer that runs the &amp;#039;kickPlayers&amp;#039; functions&lt;br /&gt;
    global KickTimer&lt;br /&gt;
   &lt;br /&gt;
    if g_debug or xlr_debug: print &amp;quot;IDLEKICK: 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 IkCheckTimer:&lt;br /&gt;
 # ------------------------------------------------------------------------&lt;br /&gt;
 def enableCheckTimer():&lt;br /&gt;
    # Enables the timer that runs the &amp;#039;checkidle&amp;#039; function&lt;br /&gt;
    global IkCheckTimer&lt;br /&gt;
   &lt;br /&gt;
    if IkCheckTimer:&lt;br /&gt;
       if g_debug or xlr_debug: print &amp;quot;IDLEKICK: IkCheckTimer (already) running: Next check @ %s&amp;quot; % (IkCheckTimer.getTime())&lt;br /&gt;
       return True&lt;br /&gt;
    else:&lt;br /&gt;
       # Create the timer:&lt;br /&gt;
       if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Timer not enabled. Enabling...&amp;quot;&lt;br /&gt;
       IkCheckTimer = bf2.Timer(checkidle, interval, 1)&lt;br /&gt;
       IkCheckTimer.setRecurring(interval)&lt;br /&gt;
       # Print debug message telling the status of the timer:&lt;br /&gt;
       if IkCheckTimer:&lt;br /&gt;
          if g_debug or xlr_debug: print &amp;quot;IDLEKICK: First check @ %s&amp;quot; % (IkCheckTimer.getTime())&lt;br /&gt;
          return True&lt;br /&gt;
       else:&lt;br /&gt;
          if g_debug or xlr_debug: print &amp;quot;IDLEKICK: ERROR: IkCheckimer Not enabled in def enableCheckTimer()&amp;quot;&lt;br /&gt;
          return False&lt;br /&gt;
 # ------------------------------------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 # ------------------------------------------------------------------------&lt;br /&gt;
 # Disable the IkCheckTimer:&lt;br /&gt;
 # ------------------------------------------------------------------------&lt;br /&gt;
 def disableCheckTimer():&lt;br /&gt;
    global IkCheckTimer&lt;br /&gt;
   &lt;br /&gt;
    IkCheckTimer.destroy()&lt;br /&gt;
    IkCheckTimer = None&lt;br /&gt;
 &lt;br /&gt;
 # ------------------------------------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 # ------------------------------------------------------------------------&lt;br /&gt;
 # Loop all players, checking their idle, kick high-idleer:&lt;br /&gt;
 # ------------------------------------------------------------------------&lt;br /&gt;
 def checkidle(data):&lt;br /&gt;
    # Checks idle of all players, and kicks idlers&lt;br /&gt;
    global kicklist, gamestatus&lt;br /&gt;
 &lt;br /&gt;
    # We only want to check idle 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 bf2.playerManager.getNumberOfPlayers() &amp;lt; minplayers:&lt;br /&gt;
       if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Not enough players to check for idlers...&amp;quot;&lt;br /&gt;
       return&lt;br /&gt;
 &lt;br /&gt;
    if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Running checkidle&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 haven&amp;#039;t completed their &amp;quot;connect&amp;quot; yet:&lt;br /&gt;
       if not p.isConnected():&lt;br /&gt;
         if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Player not yet connected, continuing...&amp;quot;&lt;br /&gt;
         continue&lt;br /&gt;
       if p.isAlive():&lt;br /&gt;
         if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Player is already playing, continuing...&amp;quot;&lt;br /&gt;
         continue&lt;br /&gt;
       if p.isManDown():&lt;br /&gt;
         if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Player in ManDown state, continuing...&amp;quot;&lt;br /&gt;
         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;
 &lt;br /&gt;
       # Prevent Clanmembers from being kicked&lt;br /&gt;
       skip = 0&lt;br /&gt;
       for clantag in clantags:&lt;br /&gt;
         if name.find(clantag)&amp;gt;-1:&lt;br /&gt;
           skip = 1&lt;br /&gt;
           break&lt;br /&gt;
       if skip == 1: continue&lt;br /&gt;
 &lt;br /&gt;
       # If we have a valid idle, check it, and issue a warning if the idle exceeds the limit:&lt;br /&gt;
       p.idleWarnings += 1&lt;br /&gt;
       if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Player &amp;quot; + name + &amp;quot; has been detected as idle &amp;quot; + str(p.idleWarnings) + &amp;quot; time(s)&amp;quot;&lt;br /&gt;
       if warnme == 1 and p.idleWarnings == (warnings - 3):&lt;br /&gt;
         #tmp = p.idleWarnings * interval / 60&lt;br /&gt;
         sendMsg(&amp;quot;WARNING: &amp;quot; + name + &amp;quot; has not returned to duty for quite some time now. Move in fast, you&amp;#039;re about to be court marshalled!&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;checkidle&amp;#039; is run:&lt;br /&gt;
       if warnings &amp;lt;= p.idleWarnings:&lt;br /&gt;
         #tmp = p.idleWarnings * intervals / 60&lt;br /&gt;
         sendMsg(&amp;quot;Desertion Violation: &amp;quot; + name + &amp;quot; is being removed for not returning to duty in time! (aka idling)&amp;quot;)&lt;br /&gt;
         # Add the player to the kicklist:&lt;br /&gt;
         kicklist.append((p.index,p.getProfileId()))&lt;br /&gt;
 &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;
    # Loops through &amp;#039;kicklist&amp;#039;, and kicks players accordingly.&lt;br /&gt;
    #print &amp;quot;IDLEKICK: kickPlayers...&amp;quot;&lt;br /&gt;
    global kicklist, KickTimer&lt;br /&gt;
   &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 an already disconnected &amp;quot;violater&amp;#039;s&amp;quot; index:&lt;br /&gt;
       if not p.getProfileId() == i[1]: continue&lt;br /&gt;
       # Check if this player indeed has reached the limit for maximum warnings&lt;br /&gt;
       if warnings &amp;lt;= p.idleWarnings:&lt;br /&gt;
          # Kick if limit is reached:&lt;br /&gt;
          if g_debug or xlr_debug: print &amp;quot;IDLEKICK: Kicking player &amp;quot; + p.getName() + &amp;quot; for being idle.&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;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>