<?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=Cookbook%3AFinding_the_Value_of_a_Server_Configuration_Variable</id>
	<title>Cookbook:Finding the Value of a Server Configuration Variable - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Cookbook%3AFinding_the_Value_of_a_Server_Configuration_Variable"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Cookbook:Finding_the_Value_of_a_Server_Configuration_Variable&amp;action=history"/>
	<updated>2026-08-06T00:31:28Z</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=Cookbook:Finding_the_Value_of_a_Server_Configuration_Variable&amp;diff=92&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;==  Problem  ==  Many configuration options for BF2 are read from &lt;code&gt;.con&lt;/code&gt; files that can be edited by the server administrator. You are writing a cool Python expansi...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Cookbook:Finding_the_Value_of_a_Server_Configuration_Variable&amp;diff=92&amp;oldid=prev"/>
		<updated>2018-06-21T19:29:48Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==  Problem  ==  Many configuration options for BF2 are read from &amp;lt;code&amp;gt;.con&amp;lt;/code&amp;gt; files that can be edited by the server administrator. You are writing a cool Python expansi...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  Problem  ==&lt;br /&gt;
&lt;br /&gt;
Many configuration options for BF2 are read from &amp;lt;code&amp;gt;.con&amp;lt;/code&amp;gt; files that can be edited by the server administrator. You are writing a cool Python expansion for BF2, but for your code to work you need to know the values of some of these configuration parameters; for example, &amp;lt;code&amp;gt;sv.autoDemoHook&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==  Solution  ==&lt;br /&gt;
&lt;br /&gt;
It turns out that if you type the name of a configuration variable into the server console window, the server will respond with the value of that variable, with a newline character appended to it for good measure. You can use the [[Object_Reference#RCon_Methods|&amp;lt;code&amp;gt;host.rcon_invoke&amp;lt;/code&amp;gt;]] method from within your Python program to simulate the same thing, and then use the string &amp;lt;code&amp;gt;strip()&amp;lt;/code&amp;gt; method to get rid of the extraneous newline.&lt;br /&gt;
&lt;br /&gt;
The following function encapsulates this approach:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def serverConfig(variableName):&lt;br /&gt;
    return host.rcon_invoke(variableName).strip()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To use it, just call the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; hook = serverConfig(&amp;quot;sv.autoDemoHook&amp;quot;) # Sets hook to &amp;quot;adminutils/demo/rotate_demo.exe&amp;quot; &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
CAUTION: this &amp;lt;code&amp;gt;serverConfig&amp;lt;/code&amp;gt; function always returns a string value; if the variable you want to read is numeric (for example, &amp;lt;code&amp;gt;sv.serverPort&amp;lt;/code&amp;gt;) you will need to apply &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; or a related function to convert the returned string to a numeric value:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; port = int(serverConfig(&amp;quot;sv.serverPort&amp;quot;)) # Sets port to numeric 16567 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==  Discussion  ==&lt;br /&gt;
&lt;br /&gt;
This technique only works to read standard server configuration variables; the BF2 engine won&amp;#039;t allow you to specify arbitrary custom configuration variables in &amp;lt;code&amp;gt;.con&amp;lt;/code&amp;gt; files, so you can&amp;#039;t use it for that purpose. See [[Cookbook:Easy_Custom_Config_Variables|Easy Custom Config Variables]] for an alternative that would work for custom variables.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Submitted By  ==&lt;br /&gt;
&lt;br /&gt;
--Woody, based on an approach discovered by King of Camelot&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>