crcon is a lightweight command line interface used to issue commands to the openarena server without having to directly type those commands into the openarena server program.
Purpose[]
The main reason to use crcon is to integrate the power of shell or python scripting (or any other scripting language) with server commands. Scripts can be written to display all sorts of information by calling a specfic server command, and then parsing that information. Seeing how the openarena server cli does not have build in support for coreutils such as grep or sed, and does not have support for more complex scripts involving loops and conditional expressions, crcon is meant to provide a bridge for scripts and server interaction.
Usage[]
While crcon supports multiple games, this guide will focus on openarena. If starting up crcon with no parameters, the user will be greeted with a usage message:
usage: ./crcon [-p password] [-P port] [-t type] [-b buffersize] server command ./crcon -l [-P port] [-t type] [-b buffersize] server ./crcon -v variable -p password [-P port] [-t type] [-b buffersize] server player_name -h | --help diplay this message -l | --list get player list -p password | --password=password set password -P port | --port=port default is 27960 -t gametype | --type=gametype default is q3a, type -h gametype -v variable | --var=variable get player variable -b buffersize-kbytes | --buffersize=buffersize-kbytes defaults to 4k
Here is a simple example of using crcon to receive the output of the "status" command from the server. This particular example is for a server running on the same machine, but that does not neccesarily have to be the case:
./crcon -p password -P 27961 localhost status
Notice here, password is the password for the server (the rconpassword variable in server.cfg). 27961 is the port number the server is running on. Localhost is the ip adress of the server that is being connected to. Status is the particular command being sent. Other commands can be cvarlist or "addbot sarge". Notice for commands spanning more than one word quotation marks need to be added.
An example of a script that automates this process is shown below.
#!/bin/bash CRCONPATH="./crcon" # Path for crcon RCONPASSWORD="<einstein>" # rcon password for the server server1="localhost" port1="27961" server2="" port2="" server3="" port3="" function connect { $CRCONPATH -p $RCONPASSWORD -P $2 $1 "$3" } function connectToServers { connect $server1 $port1 "$1" # connect $server2 $port2 "$1" # connect $server3 $port3 "$1" } message="status" if test "$1" == "" ; then echo supply parameter else if [ $1 == "-p" ] ; then connectToServers "cvarlist" | grep player | \ sed 's/.*g_humanplayers "\([0-9]\)"/\1/' else connectToServers "$1" fi fi
This script simplifies having to type the long string to simply get the status of the server. Assuming the script above is known as crconScript, the script can be launched with:
./crconScript status
Which will output:
num score ping name lastmsg address qport rate --- ----- ---- --------------- ------- --------------------- ----- ----- 0 0 0 S
In the example above, there was one player in the server. With this new script however, the number of players can be returned as a value to stdout, which can be used by other scripts to interact with the players in the server.
./crconScript -p
Will return the number of players currently in the server.
See also[]
External links[]
- crcon source currently developed on github
- crcon source originally on Sourceforge
- Shell Scripting
- OAMPS a similar tool to manage game servers with different options