Scripts:ReservedSlots
A small script to make sure there will always be a few reserved slots for certain players. If a non approved nick logs on and the server has reached its limit, that player will be kicked immediately.
This script should be run as the autobalance.py and tk_punish.py scripts in the standard_admin folder, which means change the __init__.py file to include this script.
The script is very simple, but works well. Later I might add useful bits, like not having to modify the script to approve players or change the player threshold. Also I might change the player threshold to be more dynamic, not counting approved players in the total.
In its current form below, the nicks PLAYER1, PLAYER2 and PLAYER3 will be the only people allowed on the server once 24 players are already present.
# Reserved slots system for Battlefield 2 # Martin Ostergaard <[email protected]> - 2005 import bf2 import host from bf2 import g_debug APPROVED_PLAYERS = ['PLAYER1', 'PLAYER2', 'PLAYER3'] MAX_PLAYERS = 24 def init(): host.registerHandler('PlayerConnect', resPlayerConnect, 1) host.registerHandler('PlayerDeath', resPlayerDeath, 1)#Added by Milton def resPlayerConnect(p): ONLINEPLAYERS = len(bf2.playerManager.getPlayers()) if ONLINEPLAYERS > MAX_PLAYERS: if APPROVED_PLAYERS.count(p.getName()) < 1: host.rcon_invoke('admin.kickPlayer ' + str(p.index))
- Added by Milton
def resPlayerDeath(p, vehicle): ONLINEPLAYERS = len(bf2.playerManager.getPlayers()) name = p.getName() if ONLINEPLAYERS > MAX_PLAYERS: if APPROVED_PLAYERS.count(p.getName()) < 1: host.rcon_invoke('PB_SV_Kick ' + name + ' 0 Sorry, making room for members') return
Note from underplay: Im busy right now, but it wouldnt be a bad idea to check to see if the approved players are already in the server..if they are all present, allow players to connect.
Note from monsterdog: Very nice idea, and I have already changed the running version of it substantially, for instance I have added the capability to change the approved list in runtime. I will edit the script on these pages to reflect that once I'm sure it runs smoothly.
Note from bS: I like the idea of this script, one suggestion though. If you just setup one slot as permanently free? ea. you have a 32 player server and make it 33 slots. A player could always connect to the 33rd slot, when this happens an unapproved player would be kicked stating that he connected to a reserved slot; an approved player however will cause the script to kick an unapproved player who is already on the server and thus opening a new reserved slot to repeat the procedure in the future.
Note from Mugzy: How about using a punkbuster kick so the kicked person can see why they were kicked?
Note from Milton: In reply to bS, I modified it a bit so that it does exactly that, when an approved player joins the next person to die that is not approved gets kicked, however the punkbuster kick will not work right as the person joins, unfortunately it seems punkbuster doesn't recognize them untill they get into the server
Note from monsterdog: Also the PB kick appearantly lags the server a bit everytime someone is kicked. I am deliberately putting off playing more with this script until patch 1.03 is out, where it is reportedly possible to kick with a specific message popping up over the server browser. I have an updated version of the script, however, which will let you change the approved list while the server is still running:
# Reserved slots system for Battlefield 2 # Martin Ostergaard - 2005 import bf2 import host import sys from bf2 import g_debug CONFIG_FILE = '/home/bf2user/bf2/admin/standard_admin/approved_players.cfg' MAX_PLAYERS = 20 def init(): print 'initializing reserved slots script' host.registerHandler('PlayerConnect', resPlayerConnect, 1) sys.stdout.flush() def resPlayerConnect(p): onlineplayers = len(bf2.playerManager.getPlayers()) new_player = p.getName() print new_player + ' connected, checking for a free slot' if onlineplayers > MAX_PLAYERS: print 'unreserved player max reached, checking if ' + new_player + ' is approved' CONFIG_FD = open(CONFIG_FILE) APPROVED_PLAYERS = CONFIG_FD.read() CONFIG_FD.close() if APPROVED_PLAYERS.count(new_player) > 0: print new_player + ' approved for login' else: print new_player + ' not approved, will be kicked' host.rcon_invoke('admin.kickPlayer ' + str(p.index)) sys.stdout.flush()
The "approved_players.cfg" is simply a text file, with each players nick on a line by itself, like this:
PLAYER_1 PLAYER_2 PLAYER_N
Make sure you do not add any empty lines or extra stuff in there. I am pretty certain it will still work if you apply Milton's changes to it. Also note that it actually sends some debugging information out, if you have enabled some kind of error outputting.
Note by monsterdog: OK the above was a bit redundant, saw the new reserved slots script posted on this site, which basically does almost everything I had planned to do, very nice, use that instead :-)