-
Notifications
You must be signed in to change notification settings - Fork 3
Admin Module
Battlefield 2 provides for a Python "administrative" module; this module can do pretty much anything, but the Python code that ships with BF2 serves two basic roles:
- It implements the BF2 RCon ("Remote Console") interface
- It implements several in-game automatic administration functions; the standard module automatically balances the number of players on each team, and handles punishment of players for killing teammates ("TK"ing).
The sv.adminScript server configuration directive tells the BF2 game
engine which administrative module should be loaded as the engine is
starting up; this directive gives the name of the Python module to load
in the Battlefield 2 Server/admin directory; the default
administrative module that ships with BF2 is called, appropriately,
default:
sv.adminScript "default"
You can create your own administrative modules; just put them in the
Battlefield 2 Server/admin directory and change the setting for
sv.adminScript in the ServerSettings.con file. One example of a
custom administrative module can be found
here (in this case, it's an
expansion of the default module that adds more features).
Any administrative module, including default, has three methods which
are called by the game engine itsef:
- init()
The game engine calls this method while it is starting up; in thedefaultmodule, this method reads the admin configuration file (default.cfg), initializes the admin system, registers to receive RemoteCommand events, etc. - shutdown()
The game engine calls this method when the server is shutting down (shutting down completely--not just after each game round). In thedefaultmodule this method just closes the TCP socket used for receiving RCon commands from the network. - update()
The game engine calls this method roughly every 30ms; in thedefaultmodule, this method checks for any new input arriving over the network TCP RCon socket.
BF2 includes an "RCon" (Remote Console) function that allows many administrative functions that can be done from the regular console (the black-and-white curses interface on the machine running the BF2 server) to be done from a "remote console"--either from within a BF2 game client (accessed by a player pressing the "~" key), or via a TCP network interface.
The RCon interface is implemented completely in Python, with the code in
the Battlefield 2 Server/admin directory. The game engine provides
five facilities that this Python code uses:
- As part of it's start-up procedure, the
server imports the Python module in the
admindirectory specified by thesv.adminScriptdirective. This is normally thedefaultmodule, but the fact