<?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%3AEasy_Custom_Config_Variables</id>
	<title>Cookbook:Easy Custom Config Variables - 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%3AEasy_Custom_Config_Variables"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Cookbook:Easy_Custom_Config_Variables&amp;action=history"/>
	<updated>2026-08-06T01:09:26Z</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:Easy_Custom_Config_Variables&amp;diff=93&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;==  Problem  ==  You are writing a script that has some configuration parameters that you want the server operator to be able to set. So as not to reinvent the wheel, can you...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Cookbook:Easy_Custom_Config_Variables&amp;diff=93&amp;oldid=prev"/>
		<updated>2018-06-21T19:30:11Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==  Problem  ==  You are writing a script that has some configuration parameters that you want the server operator to be able to set. So as not to reinvent the wheel, can you...&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;
You are writing a script that has some configuration parameters that you want the server operator to be able to set. So as not to reinvent the wheel, can you make use of one of BF2&amp;#039;s existing configuration files?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Solution  ==&lt;br /&gt;
&lt;br /&gt;
Sure! The main BF2 engine won&amp;#039;t let you create custom configuration variables, so adding your configuration information to one of the &amp;lt;code&amp;gt;.con&amp;lt;/code&amp;gt; files won&amp;#039;t work. . . but the default administration module has it&amp;#039;s own configuration file (&amp;lt;code&amp;gt;Battlefield 2 Server/admin/default.cfg&amp;lt;/code&amp;gt;) that doesn&amp;#039;t follow the normal rules; the administration module reads and parses lines in &amp;lt;code&amp;gt;default.cfg&amp;lt;/code&amp;gt;, consisting of keyword/value pairs, into a dictionary called &amp;lt;code&amp;gt;options&amp;lt;/code&amp;gt;. It doesn&amp;#039;t care what keywords/values are listed in &amp;lt;code&amp;gt;default.cfg&amp;lt;/code&amp;gt;--even though it only uses three keywords itself (&amp;quot;port&amp;quot;, &amp;quot;password&amp;quot;, and &amp;quot;allowBatching&amp;quot;), it will load anything it sees into &amp;lt;code&amp;gt;options&amp;lt;/code&amp;gt;. This makes it easy to add your own configuration settings, as keyword/value pairs, into &amp;lt;code&amp;gt;default.cfg&amp;lt;/code&amp;gt;, and then [http://en.wikipedia.org/wiki/piggyback piggyback] on the parser that&amp;#039;s built into the administration module to do our dirty work for us.&lt;br /&gt;
&lt;br /&gt;
First, add your configuration variables into the &amp;lt;code&amp;gt;Battlefield 2 Server/admin/default.cfg&amp;lt;/code&amp;gt; file, as keyword/value pairs separated by &amp;quot;=&amp;quot; (the parser ignores spaces before and after both the keyword and the value on each line):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clanToKick = EA&lt;br /&gt;
areWeHavingFunYet = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then add the following to your script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; from default import options &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This imports the &amp;lt;code&amp;gt;options&amp;lt;/code&amp;gt; dictionary in &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; (the default administration module) into your script&amp;#039;s namespace, so that you can access it without any need to qualify it. Now, any time you want to check the value of one of your custom configuration variables, you can do so by just looking it up in &amp;lt;code&amp;gt;options&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; options[&amp;#039;clanToKick&amp;#039;] &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Be sure to note that the administration module parser is pretty basic; all values that it stores in &amp;lt;code&amp;gt;options&amp;lt;/code&amp;gt; are strings, so if your parameter has a numeric value, you&amp;#039;ll have to coerce it to a numeric type yourself; for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; int(options[&amp;#039;areWeHavingFunYet&amp;#039;]) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Discussion  ==&lt;br /&gt;
&lt;br /&gt;
It&amp;#039;s not &amp;#039;&amp;#039;entirely&amp;#039;&amp;#039; true that the parses only stores values into &amp;lt;code&amp;gt;options&amp;lt;/code&amp;gt; as strings; it has a hard-coded special case if the variable name happens to be &amp;quot;allowBatching&amp;quot; which will convert several different parameter values into either a boolean True or boolean False. . . but since it&amp;#039;s hard-coded, no one else can really make use of that feature.&lt;br /&gt;
&lt;br /&gt;
If you want anything more elaborate than what the administration module parser provides, it&amp;#039;s not hard to write your own parser!&lt;br /&gt;
&lt;br /&gt;
One final caveat: this trick only works if your script runs &amp;#039;&amp;#039;&amp;#039;after&amp;#039;&amp;#039;&amp;#039; the administration module has been initialized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Submitted By  ==&lt;br /&gt;
&lt;br /&gt;
--Woody, inspired by a question from andrewa (at) bigpond-net-au and a suggestion from brandon (at) bf2cc-com.&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>