This extension implements a basic D-Bus binding using the QT library.
This extension is still in development and this release is a beta version.
Currently, it provides 2
interfaces:
- SRCDS
- GetConVarInt|Float|String( string cvarname );
- SetConVarInt|Float|String( string cvarname, int|float|string value );
- ServerCommand( string command );
- GetAllPlayers();
- GetNumPlayers();
- GetMaxPlayers();
- GetPlayer( unsigned int PlayerIndex );
- GetHostName();
- GetMapName();
- GetTeamName( unsigned int teamIndex );
- GetTeamScore( unsigned int teamIndex );
- SM
- GetAllPlugins();
- GetPlugin( int PluginId );
- LoadPlugin( string filename, bool debug, int lifetime );
- UnloadPlugin( int PluginId );
With these interfaces, you should be able to do most of the basic operations. In the package, there is a python script included that demonstrates controlling the server through the D-Bus. Basically, it boils down to this (in Python):
Code:
import dbus;
bus = dbus.SystemBus();
srcds = bus.get_object( "net.sourcemod", "/srcds" );
allplayers = srcds.GetAllPlayers();
flashlight = srcds.GetConVarInt( "mp_flashlight" );
sm = bus.get_object( "net.sourcemod", "/sm" );
allplugins = sm.GetAllPlugins();
Known issues:- As this extension heavily relies on QT, the QT libs must be available.
- PAWN Plugins cannot make use of the extension, neither for calling other processes, nor for providing interfaces to be called.
- SM Plugins can be queried over DBus, but extensions and plugin commands/cvars cannot.
- Getting advanced Server information like "stats" (FPS etc.) is not possible.
Planned Features:- Fix known issues
- Fix any issues you report
Intended use for this extension:
Whenever you want a script/program/web interface/whatever to execute a command or retrieve other info from the server, you currently need to implement the RCon protocol (or use a lib for it), send the server a command of some sort, and parse the command's output. DBus can greatly simplify this procedure by doing all this stuff, all you need to do is use the interface described above. E.g, GetAllPlayers() will return an array of structs, each one containing all the data you need to know about a player:
Code:
mistagee@sphynx:~$ !440
dbus-send --system --type=method_call --dest=net.sourcemod --print-reply /srcds net.sourcemod.srcds.GetAllPlayers
method return sender=:1.4541 -> dest=:1.4579
array [
struct {
int32 1 <-- entity index
string "-[ExTreME-gAmINg]-TV @ delay 90" <-- name
string "127.0.0.1" <-- ip
string "BOT" <-- steam ID
int32 1 <-- Team Index (CS:S: 1 = Spec, 2 = T, 3 = CT)
int32 0 <-- Kills
int32 0 <-- Deaths
boolean true <-- IsConnected
boolean true <-- IsInGame
boolean true <-- IsFakePlayer
boolean false <-- IsAdmin
}
]
You don't need an RCon lib, you don't need to know the RCon password, you don't need to parse any stupid texts, you can simply focus on what you want to do.
How exactly all this works is demonstrated in the included Python script. I've put up a demo website that uses this extension here:
http://www.dingens-kirchen.net/srcds/1
Package contents:
My svn repository contains all the code files needed to compile this extension, and two binaries for the original engine that were compiled against versions 4.2 and 4.4 of the QT library.
As I am not at all familiar with coding/compiling for Windows, this extension is currently in development for Linux only. If someone would like to make this fit for Windows please let me know
Getting the extension:
I'm keeping this extension (including compiled binaries) in a hg repository hosted by BitBucket here:
http://bitbucket.org/Svedrin/sourcemod-dbus/wiki/Home. You can get it from there using the Mercurial client or by downloading a snapshot.
Greetz
__________________