Admin Module

From BF2 Technical Information Wiki
Jump to: navigation, search

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:

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).


Module Methods

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 the default module, 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 the default module 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 the default module, this method checks for any new input arriving over the network TCP RCon socket.


RCon

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:


The default module implements just three RCon commands (but could easily be extended to add others):

login <password> 
default won't accept any other RCon commands until this command is given with the valid password, as specified in the default.cfg file.
users 
lists players connected to the server, along with their IP Addresses and CD key hashes. [edit by cyber37 (i don't delete last sayed) no it's not that when you unter users the server send to you the ip of admins who are using the rcon protocol for the server]
exec <server command> 
executes any server command.

(Note that from a player's in-game console window, each of these commands must be preceeded by the word "rcon" to cause the game engine to send it to the default module; from a TCP RCon connection, these commands are typed exactly as shown).

Other Administrative Functions

When the game engine imports the default administrative module, one of the things the module does is to import the standard_admin module. When standard_admin is imported, it in turn imports and initializes two other modules:

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox