Raised This Month: $12 Target: $400
 3% 

[EXTENSION] DBus Connectivity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MistaGee
Senior Member
Join Date: Aug 2004
Location: Germany (Fulda)
Old 06-28-2008 , 20:23   [EXTENSION] DBus Connectivity
Reply With Quote #1

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
__________________
Ich hab nie behauptet dass ich kein Genie bin!
Mumble-Django: A web interface for Mumble

Last edited by MistaGee; 03-27-2009 at 14:50. Reason: Update: v0.2
MistaGee is offline
Send a message via ICQ to MistaGee
FLOOR_MASTER
Senior Member
Join Date: Mar 2008
Old 06-29-2008 , 19:05   Re: [EXTENSION] DBus Connectivity
Reply With Quote #2

A couple of questions -- will this return data from ServerCommand or is that one-way only? I'm most interested in getting the results of "stats" back for monitoring purposes.

I'm not familiar with DBus - it looks like communication is restricted to processes on the same machine? (you can't connect remotely?)

Is the connection name not being configurable a technical limit or would it be possible to make it configurable (I have multiple servers running on the same machine)?
FLOOR_MASTER is offline
MistaGee
Senior Member
Join Date: Aug 2004
Location: Germany (Fulda)
Old 06-30-2008 , 04:40   Re: [EXTENSION] DBus Connectivity
Reply With Quote #3

Quote:
Originally Posted by FLOOR_MASTER View Post
A couple of questions -- will this return data from ServerCommand or is that one-way only? I'm most interested in getting the results of "stats" back for monitoring purposes.
In the moment, I don't return a command's output because I don't know how to retrieve it Once I find that out I'd be happy to include this function, as I need it myself from time to time...

Btw, if there is a way to get that data directly, I'd include a function in the interface for that to make command parsing obsolete, as that is what this extension was made for in the first place.

Quote:
Originally Posted by FLOOR_MASTER View Post
I'm not familiar with DBus - it looks like communication is restricted to processes on the same machine? (you can't connect remotely?)
As far as I know, D-Bus is designed to allow remote connections, but I have not yet used them, so I can't really tell you how that works...

Quote:
Originally Posted by FLOOR_MASTER View Post
Is the connection name not being configurable a technical limit or would it be possible to make it configurable (I have multiple servers running on the same machine)?
The reason for that was pure laziness - I need to implement reading KeyValues first, which I have not done yet. I myself have a couple of srcds running on the same host, so this has a high priority for me.

Greetz
__________________
Ich hab nie behauptet dass ich kein Genie bin!
Mumble-Django: A web interface for Mumble

Last edited by MistaGee; 06-30-2008 at 04:55.
MistaGee is offline
Send a message via ICQ to MistaGee
MistaGee
Senior Member
Join Date: Aug 2004
Location: Germany (Fulda)
Old 06-30-2008 , 07:23   Re: [EXTENSION] DBus Connectivity
Reply With Quote #4

Update:

The service name can now be configured in addons/sourcemod/configs/dbus.ext.cfg. See the example file in svn for how this works.

Greetz
__________________
Ich hab nie behauptet dass ich kein Genie bin!
Mumble-Django: A web interface for Mumble

Last edited by MistaGee; 07-15-2008 at 14:29.
MistaGee is offline
Send a message via ICQ to MistaGee
BAILOPAN
Join Date: Jan 2004
Old 07-01-2008 , 01:32   Re: [EXTENSION] DBus Connectivity
Reply With Quote #5

Interesting idea!
__________________
egg
BAILOPAN is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode