[bf1942] How to test high ping kicker is working

Nicolo Tüllmann Nico at immortalesclan.de
Wed Jun 29 08:14:44 EDT 2005


Hi @ all

ok i have make all waht he say on his side.
I edit the script so
 admin/standard_admin/__init__.py


import autobalance
import tk_punish
import bf2cc
import pingkick.py

pingkick.init()
autobalance.init()
tk_punish.init()




Than I make a file
in the admin/standard_admin/ pingkick.py

exactly so




# ------------------------------------------------------------------------
# Module: pingkick.py
# Authors: Kybber and Panic, Battlefield.no
# Version 1.1
# Description:
#   This script kicks players with high ping, based on three different
#   settings in the file 'adminsettings.con', loaded by the modified admin
#   script (sv.adminScript = bfno_v1.1.py). See requirements for details.
# Requirements:
#   None.
# Installation:
#   Save this script as 'pingkick.py' in your <bf2>/admin/standard_admin
directory,
#   and add the lines 'import pingkick' and 'pingkick.init()' to the file
#   '<bf2>/admin/standard_admin/__init__.py'.
#
# Changes from 1.0 to 1.1:
# - Added support for stand-alone operation. (Will use bf2.adminoptions if
available)
# - The script now only checks ping while game status is 'Playing'
# - Switched from 'bfno' to prefix 'pk' for ping kick settings in
'bf2.adminoptions'.
# - Other, minor updates.
# ------------------------------------------------------------------------

# ------------------------------------------------------------------------
#                     C O N F I G U R A T I O N
# ------------------------------------------------------------------------
# Settings for auto-kicking:
autokick = 1      # Enables/disables autockicking
pinglimit = 20   # The ping limit, obviously ;-p
warnings = 3      # The number of warnings a player get before being kicked
interval = 15     # The interval between ping checks
# NB: These settings will be overridden by their counter-parts in
# bf2.adminoptions['pk.<autoKick|pingLimit|warnings|interval']
# if those are present.


# ------------------------------------------------------------------------
#                        I M P O R T
# ------------------------------------------------------------------------

import host
import bf2
from bf2 import g_debug

# ------------------------------------------------------------------------
#                       V A R I A B L E S
# ------------------------------------------------------------------------

# We need our own debug flag:
bfno_debug = False

# Some timers:
pktimer   = None  # Timer firing off the ping checker. Depends on the
'interval' variable.
kicktimer = None  # Timer that delays kicking after the final warning has
been issued.
msgtimer  = None  # Timer that delays the "activated" message after entering
bf2.GameStatus.Playing

# List of people to kick for high ping:
kicklist = None


# For keeping track of the game status:
gamestatus = None


# ------------------------------------------------------------------------
#                       F U N C T I O N S
# ------------------------------------------------------------------------


# ------------------------------------------------------------------------
# The init function run by the standard_admin/__init__ functions:
# ------------------------------------------------------------------------
def init():
   global interval
   if g_debug or bfno_debug: print 'PINGKICK: initializing pingkick script'
   # Try to read the settings:
   if not getSettings():
      return
   # Force at least 10 seconds between ping checks:
   if interval < 10: interval = 10
   # Print debug message if autokick is disabled:
   if 1 != autokick:
      if g_debug or bfno_debug: print 'PINGKICK: High ping autokick not
enabled'

   # Autokick is enabled, so hook it up:
   else:
      if g_debug or bfno_debug: print 'PINGKICK: Enabling kick for high
ping. Limit = %s, max warnings = %s.' % (pinglimit, warnings)

      # Register 'PlayerConnect' callback:
      host.registerHandler('PlayerConnect', onPlayerConnect, 1)
      host.registerGameStatusHandler(onGameStatusChanged)

      # Reset TK Warnings
      for p in bf2.playerManager.getPlayers():
         onPlayerConnect(p)

      # PingKickTimer:
      enableCheckTimer()
# ------------------------------------------------------------------------


# ------------------------------------------------------------------------
# Get the settings from the bf2.adminsettings object:
# ------------------------------------------------------------------------
def getSettings():
   global autokick,pinglimit,warnings,interval
   readOk = False
   # Try to access the autokick setting:
   try:
      if g_debug or bfno_debug: print "PINGKICK: Reading settings from
bf2.adminoptions:"
      autokick  = int(bf2.adminoptions['pk.autoKick'])
      pinglimit = int(bf2.adminoptions['pk.pingLimit'])
      warnings  = int(bf2.adminoptions['pk.warnings'])
      interval  = int(bf2.adminoptions['pk.interval'])
      readOk    = True
   except:
      if g_debug or bfno_debug: print "PINGKICK: WARNING - Could not get
settings from 'bf2.adminoptions'. Using default values:"
   if g_debug:
      print "  autokick  : " + str(autokick)
      print "  pinglimit : " + str(pinglimit)
      print "  maxwarns  : " + str(warnings)
      print "  interval  : " + str(interval)
   return readOk
# ------------------------------------------------------------------------


# ------------------------------------------------------------------------
# Callback function for the "PlayerConnect" event:
# ------------------------------------------------------------------------
def onPlayerConnect(p):
   """Resets the ping warning counter for the player"""
   p.pingWarnings = 0 # Reset the 'TK Warnings' counter.
# ------------------------------------------------------------------------


# ------------------------------------------------------------------------
# Callback function for the "PreGame" game status event:
# ------------------------------------------------------------------------
def onGameStatusChanged(status):
   """Enables the ping check timer"""
   # Import variables, and update the game status:
   global gamestatus, kicklist, msgtimer
   gamestatus = status
   if gamestatus == bf2.GameStatus.Playing and autokick:
      if bfno_debug: print "PINGKICK: Setting msgtimer"
      msgtimer = bf2.Timer(onMsgTimer,10,1)
   # Return if not PreGame:
   elif gamestatus == bf2.GameStatus.PreGame:
      if bfno_debug: print "PINGKICK: Game status changed to PreGame.
Resetting warnings and re-enabling check-timer"
      # Reset the kicklist
      kicklist = None
      # Read the settings again:
      getSettings()
      # Reset TK Warnings
      for p in bf2.playerManager.getPlayers():
         p.pingWarnings = 0
      # Enable the ping check timer:
      enableCheckTimer()
# ------------------------------------------------------------------------

# ------------------------------------------------------------------------
# Callback function for timer, that delays a message at round start:
# ------------------------------------------------------------------------
def onMsgTimer(data):
   global msgtimer
   if bfno_debug: print "PINGKICK: Entering onMsgTimer"
   msg = "Activated! Kicking at " + str(pinglimit) + " after " +
str(warnings) + " warnings."
   sendMsg(msg)
   msgtimer.destroy()
   msgtimer = None
# ------------------------------------------------------------------------

# ------------------------------------------------------------------------
# Send text messages to the server, using rcon game.sayAll:
# ------------------------------------------------------------------------
def sendMsg(msg):
   # Sure you can edit this, and remove 'bf2.no'. But hey, why not give us
the credit? ;-)
   host.rcon_invoke("game.sayAll \"BF2.NO PING KICKER: " + str(msg) + "\"")
# ------------------------------------------------------------------------


# ------------------------------------------------------------------------
# Enable the pktimer:
# ------------------------------------------------------------------------
def enableKickTimer():
   """Enables the timer that runs the 'kickPlayers' functions"""
   global kicktimer
   if bfno_debug: print "PINGKICK: Enabling the kicktimer..."
   kicktimer = bf2.Timer(kickPlayers, 5, 1)
# ------------------------------------------------------------------------


# ------------------------------------------------------------------------
# Enable the pktimer:
# ------------------------------------------------------------------------
def enableCheckTimer():
   """Enables the timer that runs the 'checkPing' function"""
   global pktimer
   if pktimer:
      return True
   else:
      # Create the timer:
      if bfno_debug: print "PINGKICK: Timer not enabled. Enabling..."
      pktimer = bf2.Timer(checkPing, interval, 1)
      pktimer.setRecurring(interval)
      # Print debug message telling the status of the timer:
      if pktimer:
         if bfno_debug: print "PINGKICK: Time = %s" % (pktimer.getTime())
         return True
      else:
         if bfno_debug: print "PINGKICK: Not enabled"
         return False
# ------------------------------------------------------------------------


# ------------------------------------------------------------------------
# Loop all players, checking their ping, kick high-pinger:
# ------------------------------------------------------------------------
def checkPing(data):
   """Checks ping of all players, and kicks high-pingers"""

   global kicklist

   # We only want to check ping during rounds:
   if gamestatus != bf2.GameStatus.Playing: return

   # Make sure our timer is enabled:
   if not enableCheckTimer(): return

   if bfno_debug: print "PINGKICK: Running checkPing"

   # Loop all players
   for p in bf2.playerManager.getPlayers():
      name = str(p.getName())
      # Check the ping if the limit hasn't been reached:
      ping = None
      try:
         ping = p.getPing()
      except:
         pass
      # If we have a valid ping, check it, and issue a warning if the ping
exceeds the limit:
      if ping:
         #if g_debug: print "PINGKICK: " + name + " has " + str(ping) + " in
ping and has " + str(p.pingWarnings) + " Ping-warnings"
         if ping > pinglimit:
            p.pingWarnings += 1
            if bfno_debug: print "PINGKICK: Player " + name + " has exceeded
the ping limit " + str(p.pingWarnings) + " time(s)"
            sendMsg("WARNING: " + name + " has exeeded the ping limit " +
str(p.pingWarnings) + " time(s)")
         # Issue a warning if a player has reached the maximum number of
warnings. Will be kicked next time 'checkPing' is run:
         if warnings == p.pingWarnings:
            sendMsg("Kicking player " + name + " for high ping")
            # Add the player to the kicklist:
            if kicklist: kicklist.append(p.index)
            else: kicklist = [p.index]

   # Check of we shall enable the kicktimer:
   if kicklist:
      enableKickTimer()
# ------------------------------------------------------------------------


# ------------------------------------------------------------------------
# Function run by the kicktimer:
# ------------------------------------------------------------------------
def kickPlayers(data):
   """Loops through 'kicklist', and kicks players accordingly."""
   #print "PINGKICK: kickPlayers..."
   global kicklist,kicktimer
   for i in kicklist:
      p = bf2.playerManager.getPlayerByIndex(i)
      # Check if this player has reached the limit for maximum warnongs
      if warnings <= p.pingWarnings:
         # Kick if limit is reached:
         if g_debug or bfno_debug: print "PINGKICK: Kicking player " +
p.getName() + " for high ping"
         result = host.rcon_invoke("admin.kickPlayer " + str(p.index))
   kicklist = None
   kicktimer.destroy()
# ------------------------------------------------------------------------

I have du not other thing
Than i restart the Server but i dosent work.

Please help me

Thx





----- Original Message ----- 
From: "Panic" <panic at battlefield.no>
To: <bf1942 at icculus.org>
Sent: Tuesday, June 28, 2005 8:57 PM
Subject: Re: [bf1942] How to test high ping kicker is working


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I have now updated the pingkick-script, and also updated the wiki.
> Version 1.1 is capable of working stand-alone out of the box. Hope you
> guys find it usefull.
>
> http://bf2.fun-o-matic.org/index.php/Scripts:Kicking_for_high_ping
>
> - -Frode aka Panic
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.0 (MingW32)
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
>
> iD8DBQFCwZ2Pe60yOxQs6tURAkuqAJ0dPdlLjHGuiwXrhmucNDKvUiSY2QCfQWn2
> ni1kjIE0S8DJRGC8EwCY1TQ=
> =Rqxk
> -----END PGP SIGNATURE-----
>
>




More information about the Bf1942 mailing list