Browse files

add rcon capabilities

extract time off game log lines
implement the say() method
  • Loading branch information...
Courgette committed Apr 30, 2011
1 parent 8a57772 commit e2ebcaa659dc870fc7cd6132b0165c4aa4d02792
Showing with 191 additions and 1 deletion.
  1. +131 −0 b3/conf/b3.altitude_example.xml
  2. +60 −1 b3/parsers/
@@ -0,0 +1,131 @@
If you want to generate a new config file and make sure the format is
correct, you can invoke the setup procedure with the
command : b3_run -s b3.xml
This is B3 main config file (the one you specify when you run B3 with the
command : b3_run -c b3.xml)
For any change made in this config file, you have to restart the bot.
Whenever you can specify a file/directory path, the following shortcuts
can be used :
@b3 : the folder where B3 code is installed in
@conf : the folder containing this config file
<settings name="b3">
Next line: the parser defines the game:
<set name="parser">altitude</set>
<!-- Your database info: [mysql]://[db-user]:[db-password]@[db-server[:port]]/[db-name] -->
<set name="database">mysql://user:pass@localhost/dbname</set>
<!-- Name of the bot -->
<set name="bot_name">b3</set>
<!-- Ingame messages are prefixed with this code, you can use colorcodes -->
<set name="bot_prefix">(b3):</set>
<set name="time_format">%I:%M%p %Z %m/%d/%y</set>
<!-- The timezone your bot is in -->
<set name="time_zone">CST</set>
<!-- How much detail in the b3 logfile: 9 = verbose, 10 = debug, 21 = bot, 22 = console -->
<set name="log_level">9</set>
<!-- Name of the logfile the bot will generate -->
<set name="logfile">@conf/b3.log</set>
<settings name="server">
<!-- The public IP your gameserver is residing on -->
<set name="public_ip"></set>
<!-- The port used by players to join the server -->
<set name="port">27015</set>
<!-- The gameserver generates a logfile, put the path and name here (very important !) -->
<set name="game_log">C:/Program Files (x86)/Altitude/servers/log.txt</set>
<!-- The command file B3 can write RCON commands into -->
<set name="command_file">C:/Program Files (x86)/Altitude/servers/command.txt</set>
<!-- Delay between each log reading. Set a higher value to consume less disk ressources or bandwidth if you remotely connect (ftp or http remote log access) -->
<set name="delay">0.05</set>
<!-- Number of lines to process per second. Set a lower value to consume less CPU ressources -->
<set name="lines_per_second">1000</set>
<settings name="autodoc">
<!-- Autodoc will generate a user documentation for all B3 commands
* type : can be one of : html, htmltable, xml
* maxlevel : if you want to exclude commands reserved for higher levels
* destination : can be a file or a ftp url
by default, a html documentation is created in your conf folder
<set name="type">html</set>
<set name="maxlevel">100</set>
<!-- <set name="destination">C:\Users\b3\Desktop\test_doc.htm</set> -->
<!-- <set name="destination"></set> -->
<settings name="messages">
<set name="kicked_by">$clientname was kicked by $adminname $reason</set>
<set name="kicked">$clientname was kicked $reason</set>
<set name="banned_by">$clientname was banned by $adminname $reason</set>
<set name="banned">$clientname was banned $reason</set>
<set name="temp_banned_by">$clientname was temp banned by $adminname for $banduration $reason</set>
<set name="temp_banned">$clientname was temp banned for $banduration $reason</set>
<set name="unbanned_by">$clientname was un-banned by $adminname $reason</set>
<set name="unbanned">$clientname was un-banned $reason</set>
<settings name="plugins">
<set name="external_dir">@b3/extplugins</set>
<!-- Define here the plugins you want to load.
Plugin order is important. Plugins that add new in-game commands all
depend on the admin plugin. Make sure to have the admin plugin before
You can load a plugin but having it diabled by default. This
allows to later enabled it ingame with the !enable command. To do so use
the following syntax :
<plugin name="adv" config="@conf/plugin_adv.xml" disabled="yes"/>
You can override the plugin path (official plugins and extplugins folders)
by specifying the exact location of the plugin file with the 'path' attribute :
<plugin name="adv" config="@conf/plugin_adv.xml" path="c:/somewhere/else/"/>
<plugin name="admin" config="@conf/plugin_admin.xml" />
<plugin name="censor" config="@conf/plugin_censor.xml" />
<plugin name="spamcontrol" config="@conf/plugin_spamcontrol.xml" />
<plugin name="admin" config="@conf/plugin_admin.xml" />
<plugin name="tk" config="@conf/plugin_tk.xml" />
<plugin name="stats" config="@conf/plugin_stats.xml" />
<plugin name="pingwatch" config="@conf/plugin_pingwatch.xml" />
<plugin name="adv" config="@conf/plugin_adv.xml" />
<plugin name="status" config="@conf/plugin_status.xml" />
<plugin name="welcome" config="@conf/plugin_welcome.xml" />
<!-- The next plugins are external, 3rd party plugins and should reside in the external_dir. Example: -->
<!-- plugin config="@b3/extplugins/conf/newplugin.xml" name="newplugin" -->
<!-- You can add new/custom plugins to this list using the same form as above. -->
This is a non-standard plugin, and quite resource heavy. Please take
a look in the B3 forums (look for XLR Extensions) for more
information before enabling this. Extra database tables are
<plugin name="xlrstats" config="@b3/extplugins/conf/xlrstats.xml"/>
<!-- You can find many others plugin for B3 which can extend functionalities a lot !
Please take a look at the official website for more informations. -->
<settings name="devmode">
<set name="log2console">true</set>
@@ -22,8 +22,67 @@
__author__ = 'Courgette'
__version__ = '0.1'
import re
from b3.parser import Parser
class AltitudeParser(Parser):
gameName = 'altitude'
"""B3 parser for the Altitude game. See"""
## parser code name to use in b3.xml
gameName = 'altitude'
## extract the time off a log line
_lineTime = re.compile(r'^{"port":[0-9]+, "time":(?P<seconds>[0-9]+),.*')
def startup(self):
def _initialize_rcon(self):
"""We need a way to send rcon commands to the gale server. In
Altitude, this is done by writing commands to be run on a new line
of the command.txt file"""
# check that the command file is provided in the b3.xml config file
if not self.config.has_option('server', 'command_file'):
self.critical("The B3 config file for Altitude must provide the location of the command file")
# open the command file
commandfile_name = self.config.getpath('server', 'command_file')
self.output = AltitudeRcon(console=self, commandfile=commandfile_name)
def say(self, msg):
self.write('serverMessage %s' % self.stripColors(msg))
class AltitudeRcon():
"""Object that opens the Altitude command file and allows B3 to write
commands in it"""
def __init__(self, console, commandfile):
self.console = console
self._commandfile_name = commandfile
self._fh = open(commandfile, 'a')
def writelines(self, lines):
for line in lines:
def write(self, cmd, *args, **kwargs):
"""To send a command to the server, the format to respect is :
[server port],[command type],[data]
self.console.verbose(u'RCON :\t %s' % cmd)
self._fh.write("%s,console,%s\n" % (self.console._port, cmd))
def flush(self):
def close(self):
def _get_encoding(self):
return self._fh.encoding
encoding = property(_get_encoding)

0 comments on commit e2ebcaa

Please sign in to comment.