Scripts:Patches:BF2CCdefault.py
From BF2 Technical Information Wiki
This is a diff from the original default.py file to the version supplied in http://www.bf2cc.com/downloads/BF2CC_Admin_Scripts_Rev_2.1.zip it also contains a bugfix for not de-authing disconnecting authed players.
--- default.py.orig 2005-07-06 16:45:59.000000000 +0200
+++ default.py 2005-07-07 21:10:12.454046928 +0200
@@ -32,14 +32,16 @@
import md5
import string
import random
+import standard_admin
options = {
'port': '4711',
- 'password': None,
+ 'password': 'test',
# True if multiple commands should be processed in one update and
# if as many responses as possible should be sent each update.
- 'allowBatching': False
+ 'allowBatching': True,
+ 'scriptRev': '2'
}
# Returns a seed string of random characters to be used as a salt to protect
@@ -196,11 +198,16 @@
self.backlog = 1
self.peers = []
self.openSocket()
+ self.currentGameStatus = 1
+ self.mapStartTime = int(host.timer_getWallTime())
+ self.pausedFor = 0
+ self.pauseStart = 0
# state for in-game rcon connections
- host.registerHandler('RemoteCommand', self.onRemoteCommand, 1)
- host.registerHandler('PlayerDisconnect', self.onPlayerDisconnect, 1)
- host.registerHandler('ChatMessage', self.onChatMessage, 1)
+ host.registerHandler('RemoteCommand', self.onRemoteCommand)
+ host.registerHandler('PlayerDisconnect', self.onPlayerDisconnect)
+ host.registerHandler('ChatMessage', self.onChatMessage)
+ host.registerGameStatusHandler(self.onGameStatusChanged)
# contains player ids for players which have successfully authenticated
# themselves with 'rcon login <passwd>'
@@ -213,8 +220,21 @@
self.rcon_cmds = {
'login': self.rcmd_login,
'users': self.rcmd_users,
- 'exec': self.rcmd_exec
+ 'exec': self.rcmd_exec,
+ 'pl': self.rcmd_playerlist,
+ 'si': self.rcmd_serverinfo,
+ 'pause': self.rcmd_pause,
+ 'unpause': self.rcmd_unpause,
+ 'check': self.rcmd_check
}
+
+ def onGameStatusChanged(self, status):
+ print "!!!!!!!!!!!!!!!!!!!!!!Settings status %s" % str(status)
+ if status == 1 and self.currentGameStatus != 4: # only reset when the status is start and not paused
+ self.pausedFor = 0
+ self.mapStartTime = int(host.timer_getWallTime())
+
+ self.currentGameStatus = status
# Called when a user types 'rcon ' followed by any string in a client
# console window or when a TCP client sends a complete line to be
@@ -246,7 +266,10 @@
ctx.write('error: not authenticated: you can only invoke \'login\'\n')
else:
if self.rcon_cmds.has_key(subcmd):
- self.rcon_cmds[subcmd](ctx, cmd[spacepos+1:])
+ try:
+ self.rcon_cmds[subcmd](ctx, cmd[spacepos+1:])
+ except Exception:
+ ctx.write('Error processing command: \'%s\' %s\n' %(subcmd, str(Exception)))
else:
ctx.write('unknown command: \'%s\'\n' % (subcmd))
@@ -262,13 +285,13 @@
# When players disconnect, remove them from the auth map if they were
# authenticated so that the next user with the same id doesn't get rcon
# access.
- def onPlayerDisconnect(self, player_id):
- if self.authed_players.has_key(player_id):
- del self.authed_players[player_id]
+ def onPlayerDisconnect(self, player):
+ if self.authed_players.has_key(player.index):
+ del self.authed_players[player.index]
# Called whenever a player issues a chat string.
- def onChatMessage(self, player_id, text, channel, flags):
- print 'chat: pid=%d text=\'%s\' channel=%s' % (player_id, text, channel)
+ def onChatMessage(self, player, text, channel, flags):
+ print 'chat: pid=%d text=\'%s\' channel=%s' % (player.index, text, channel)
# Sets up the listening TCP RCON socket. This binds to 0.0.0.0, which may
# not be what you want but it's a sane default for most installations.
@@ -315,6 +338,18 @@
# Command implementations go here (member functions of the AdminServer)
+ def rcmd_pause(self, ctx, cmd):
+ if self.currentGameStatus == 1: # in a playing state only; set the pause start for total paused time.
+ self.pauseStart = int(host.timer_getWallTime())
+ ctx.write(host.rcon_invoke('gamelogic.togglepause'))
+ self.onGameStatusChanged(4)
+
+ def rcmd_unpause(self, ctx, cmd):
+ if self.currentGameStatus == 4: # in a paused state only; also adjust the pausedfor for accurate game remaining time.
+ self.pausedFor = self.pausedFor + (int(host.timer_getWallTime()) - self.pauseStart)
+ ctx.write(host.rcon_invoke('gamelogic.togglepause'))
+ self.onGameStatusChanged(1)
+
# Allows a in-game rcon client to authenticate and get access.
def rcmd_login(self, ctx, cmd):
success = 0
@@ -336,6 +371,7 @@
if self.authed_sockets.has_key(ctx.socket):
del self.authed_sockets[ctx.socket]
print 'rcon: tcp client from %s:%d failed pw challenge' % ctx.socket.addr
+ print 'error: %s to %s' % (ctx.socket.correct_digest, cmd.strip())
if success:
ctx.write('Authentication successful, rcon ready.\n')
@@ -360,8 +396,44 @@
# Executes a console command on the server.
def rcmd_exec(self, ctx, cmd):
+ # remove gamelogic.togglepause command abilities.
+ if cmd.lower() == 'gamelogic.togglepause':
+ ctx.write('This command is disabled, use \'rcon pause\' and \'unpause\'\n')
+ return 0
+
ctx.write(host.rcon_invoke(cmd))
+ def rcmd_playerlist(self, ctx, cmd):
+ BF2CCGame = standard_admin.bf2cc.Game()
+ #import standard_admin.players
+ #reload(standard_admin.players)
+
+ ctx.write('%s\n' % BF2CCGame.GetPlayerList())
+ #ctx.write('test')
+ #ctx.write('%s\n' % standard_admin.players.GetPlayerList())
+ #for p in bf2.playerManager.getPlayers()
+ # ctx.write('%s\n' % p.getName())
+
+ def rcmd_serverinfo(self, ctx, cmd):
+ tmpPause = 0
+ # adjust possible pause time if still in pause
+ if self.currentGameStatus == 4: # in a paused state
+ tmpPause = self.pausedFor + (int(host.timer_getWallTime()) - self.pauseStart)
+ else:
+ tmpPause = self.pausedFor
+
+ BF2CCServer = standard_admin.bf2cc.Server()
+
+ #ctx.write('test')
+ ctx.write('%s\n' % BF2CCServer.GetSnapshot(self.currentGameStatus, self.mapStartTime, tmpPause))
+
+ #for p in bf2.playerManager.getPlayers()
+ # ctx.write('%s\n' % p.getName())
+
+ def rcmd_check(self, ctx, cmd):
+ BF2CCServer = standard_admin.bf2cc.Server()
+ ctx.write('%s\n' % BF2CCServer.Check(str(options['allowBatching']), str(options['scriptRev'])))
+
# parse the configuration file
parseConfig()
@@ -376,8 +448,7 @@
print 'initializing default admin/rcon module'
# load (optional) admin scripts like teamkill punish and autobalance
- import standard_admin
-
+ #import standard_admin
def shutdown():
if server: