<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Admin_Module</id>
	<title>Admin Module - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Admin_Module"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Admin_Module&amp;action=history"/>
	<updated>2026-08-06T01:08:58Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://bf2tech.uturista.pt/index.php?title=Admin_Module&amp;diff=64&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;Battlefield 2 provides for a Python &quot;administrative&quot; module; this module can do pretty much anything, but the Python code that ships with BF2 serves two basic roles:  * It imp...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Admin_Module&amp;diff=64&amp;oldid=prev"/>
		<updated>2018-05-04T13:18:40Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Battlefield 2 provides for a Python &amp;quot;administrative&amp;quot; module; this module can do pretty much anything, but the Python code that ships with BF2 serves two basic roles:  * It imp...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Battlefield 2 provides for a Python &amp;quot;administrative&amp;quot; module; this module can do pretty much anything, but the Python code that ships with BF2 serves two basic roles:&lt;br /&gt;
&lt;br /&gt;
* It implements the BF2 RCon (&amp;quot;Remote Console&amp;quot;) interface&lt;br /&gt;
* 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 (&amp;quot;TK&amp;quot;ing).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;sv.adminScript&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;Battlefield 2 Server/admin&amp;lt;/code&amp;gt; directory; the default administrative module that ships with BF2 is called, appropriately, &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; sv.adminScript &amp;quot;default&amp;quot; &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can create your own administrative modules; just put them in the &amp;lt;code&amp;gt;Battlefield 2 Server/admin&amp;lt;/code&amp;gt; directory and change the setting for &amp;lt;code&amp;gt;sv.adminScript&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;ServerSettings.con&amp;lt;/code&amp;gt; file. One example of a custom administrative module can be found [[Scripts:Modified_admin_script|here]] (in this case, it&amp;#039;s an expansion of the &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module that adds more features).&lt;br /&gt;
&lt;br /&gt;
== Module Methods  ==&lt;br /&gt;
&lt;br /&gt;
Any administrative module, including &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt;, has three methods which are called by the game engine itsef:&lt;br /&gt;
&lt;br /&gt;
; init()&lt;br /&gt;
: The game engine calls this method while it is [[Big_Picture|starting up]]; in the &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module, this method reads the admin configuration file (&amp;lt;code&amp;gt;default.cfg&amp;lt;/code&amp;gt;), initializes the admin system, registers to receive [[Event_Reference#Command_Events|RemoteCommand]] events, etc.&lt;br /&gt;
; shutdown()&lt;br /&gt;
: The game engine calls this method when the server is shutting down (shutting down completely--not just after each game round). In the &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module this method just closes the TCP socket used for receiving RCon commands from the network.&lt;br /&gt;
; update()&lt;br /&gt;
: The game engine calls this method roughly every 30ms; in the &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module, this method checks for any new input arriving over the network TCP RCon socket.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== RCon  ==&lt;br /&gt;
&lt;br /&gt;
BF2 includes an &amp;quot;RCon&amp;quot; (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 &amp;quot;remote console&amp;quot;--either from within a BF2 game client (accessed by a player pressing the &amp;quot;~&amp;quot; key), or via a TCP network interface.&lt;br /&gt;
&lt;br /&gt;
The RCon interface is implemented completely in Python, with the code in the &amp;lt;code&amp;gt;Battlefield 2 Server/admin&amp;lt;/code&amp;gt; directory. The game engine provides five facilities that this Python code uses:&lt;br /&gt;
&lt;br /&gt;
* As part of it&amp;#039;s [[Big_Picture|start-up procedure]], the server imports the Python module in the &amp;lt;code&amp;gt;admin&amp;lt;/code&amp;gt; directory specified by the &amp;lt;code&amp;gt;sv.adminScript&amp;lt;/code&amp;gt; directive. This is normally the &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module, but the fact that it&amp;#039;s imported based on a configuration directive means that it could easily be changed to a custom module.&lt;br /&gt;
* The game engine provides an event, [[Event_Reference#Command_Events|RemoteCommand]], that fires whenever an in-game player accesses their console and types any line beginning with &amp;quot;rcon&amp;quot;. The event passes any registered callback handlers the actual command typed by the player. This is how the &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module receives RCon commands from players (but it can be used by other Python code, as well).&lt;br /&gt;
* The game engine provides a method, &amp;lt;code&amp;gt;host.rcon_feedback&amp;lt;/code&amp;gt;, that can be used to send messages to a player&amp;#039;s in-game console. This is what the &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module uses to send responses to players&amp;#039; RCon commands back to them (but it can be used by other Python code, also).&lt;br /&gt;
* The game engine calls the &amp;lt;code&amp;gt;update&amp;lt;/code&amp;gt; method of the &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module (or whatever module has been specified by &amp;lt;code&amp;gt;sv.adminScript&amp;lt;/code&amp;gt;) repeatedly, generally about every 30 milliseconds (roughly 30 times per second). The &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module uses this to run a fast check for input on a TCP port (normally port 4711) for RCon commands--this is how the network RCon interface receives commands. More information about the RCon protocol the &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module implements can be found in the [[RCon_Protocol|RCon Protocol Specification]]&lt;br /&gt;
* When the &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module decides to execute a console command from a remote user, it passes it on to the game engine for execution using the &amp;lt;code&amp;gt;host.rcon_invoke&amp;lt;/code&amp;gt; method. This method isn&amp;#039;t specific to RCon commands--in fact, it doesn&amp;#039;t execute RCon commands at all--it executes server console commands, and can be used to good effect by any Python code. Note, however, that there is presently a bug in BF2 that prevents any feedback from PunkBuster commands from being sent back to the caller of &amp;lt;code&amp;gt;host.rcon_invoke&amp;lt;/code&amp;gt;; since this is the only way remote console commands are executed, it means that RCon users can never see any feedback from PunkBuster commands they send via RCon.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module implements just three RCon commands (but could easily be extended to add others):&lt;br /&gt;
&lt;br /&gt;
; login &amp;lt;password&amp;gt;&lt;br /&gt;
: &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; won&amp;#039;t accept any other RCon commands until this command is given with the valid password, as specified in the &amp;lt;code&amp;gt;default.cfg&amp;lt;/code&amp;gt; file.&lt;br /&gt;
; users&lt;br /&gt;
: lists players connected to the server, along with their [[Player_Identity#IP_address|IP Addresses]] and [[Player_Identity#CD_Key_Hash|CD key hashes]]. [edit by cyber37 (i don&amp;#039;t delete last sayed) no it&amp;#039;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]&lt;br /&gt;
; exec &amp;lt;server command&amp;gt;&lt;br /&gt;
: executes any server command.&lt;br /&gt;
&lt;br /&gt;
(Note that from a player&amp;#039;s in-game console window, each of these commands must be preceeded by the word &amp;quot;rcon&amp;quot; to cause the game engine to send it to the &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; module; from a TCP RCon connection, these commands are typed exactly as shown).&lt;br /&gt;
&lt;br /&gt;
== Other Administrative Functions  ==&lt;br /&gt;
&lt;br /&gt;
When the game engine imports the &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; administrative module, one of the things the module does is to import the &amp;lt;code&amp;gt;standard_admin&amp;lt;/code&amp;gt; module. When &amp;lt;code&amp;gt;standard_admin&amp;lt;/code&amp;gt; is imported, it in turn imports and initializes two other modules:&lt;br /&gt;
&lt;br /&gt;
* standard_admin.autobalance&lt;br /&gt;
* standard_admin.tk_punish&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>