kfsone
01-11-2002, 18:43
Download from: http://lawndarts.kfs.org/downloads/TS2.pmod
I've implemented a module for Roxen webserver which provides a standard set of methodologies for interfacing with a teamspeak 2 server - enabling you to add teamspeak 2 management functionality to your own website relatively easily, including adding and removing teamspeak users - so you can automatically add a teamspeak 2 account for users who register on your website.
This is just the pike module for communicating with a teamspeak 2 server, so if you want to use it off-the bat, you will have to use pike scripting (<?pike ...?>). I am, however, writing a tag module so that you will be fully able to control your teamspeak 2 server from HTML/RXML/XML pages with only a few normal tags.
For those wondering what/why Roxen; it predated Apache as "Spinner", it was developed in a language designed for dynamic content, Pike, and so has the most mature and stable content compilation and caching system going. Read: Used properly, it cuts down processing overheads by a factor of 13.
It has also, since its conception, always had a simple XML-style extensible scripting "language" - basically tags like <if ...> ... </if> etc.
What this module does is provide a programmatic interface internally for accessing teamspeak. Once the module is installed and the server restarted, you will be able to do things like this:
<?pike
var.server =
Protocols.TS2.client("localhost", 51234)->server_version() ;
?>
<p> We are running TeamSpeak 2 &var.server; </p>
(Of course, you could just write the result inside the pike tag, I'm just demonstrating :)
Or if you're doing something more elaborate, maybe:
<?pike
object con =
Protocols.TS2.client("localhost", 51234, "user", "pass", 8767) ;
// Where 8767 is the port no. of your server
string server = con->server_version() ;
write("<p> We are running TeamSpeak 2 " + server + "</p>") ;
// Get the players and their number
array(string) plist =
con->list_active_players() ;
int noOfPlayers = sizeof(plist) ;
if ( noOfPlayers == 0 )
write("<p>Our server is currently empty</p>") ;
else {
write("<p>There are " + noOfPlayers + " players on the server: ") ;
?>
All that said, I'll be introducing a module to implement the various, obvious RXML tags that spring to mind =)
Module documentation:
8x --- snip --- snip --- snip --- snip --- x8
//////////////////////////////////////////////////////////////////////////
// Pike Module for communicating with a TeamSpeak 2 server.
// Copyright (C) and By Oliver Smith, 2002 -- email oli@kfs.org
//
// This is the low-level module, if you are looking for RXML tags
// then you will want my upcoming teamspeak tags module.
//
//////////////////////////////////////////////////////////////////////////
// Installation:
//
// Copy to $ROXENHOME/pike/lib/pike/modules/Protocols/
// e.g. /usr/local/roxen/server-2.2.295/pike/lib/pike/modules/Protocols/
//
//////////////////////////////////////////////////////////////////////////
// Functions
//
// Protocols.TS2.client( hostname, portnumber )
// Creates a connection to the query server on the specified host/port
//
// Protocols.TS2.client( hostname, portnumber, username, password, server )
// As above, but logs in as username/password and selects the server
// identified by the "server" port number - default is 8767 I believe.
//
// server_version()
// Returns the current server version string
//
// login( username, password )
// Attempts to log in with the supplied credentials in an existing
// open connection.
//
// select_server( server_port_number )
// Tells the query server you wish to select a specific server. The
// servers are identified by port number, because that's how TS2 does it.
//
// list_channels()
// Returns an array containing the channels as listed by teamspeak 2
//
// list_active_players()
// Returns an array containing the active players as listed by ts2
//
// list_members()
// Returns an array listing all of the registered members
//
// broadcast_message( message )
// msgall( message )
// Sends the specified message to all servers
//
// server_message( server, message )
// msg( server, message)
// Sends the specified message to the server identified by its port no.
//
// add_user( loginname, password, server_admin, superserver_admin )
// Attempts to add the given user. server_admin and superserver_admin
// are booleans - i.e. either 0 or 1, where 1 means "yes".
//
// del_user( loginname )
// Removes a member's registration.
//
// start( [server] )
// stop( [server] )
// restart( [server] )
// Does what it says on the tin to the specified or selected server.
//
// command( "command", arguments... )
// Sends the specified command, with arguments, to the server, and
// returns an array of all the lines the server sends back.
//
//////////////////////////////////////////////////////////////////////////
// Example usages:
//
// int serverno = 8767 ; // Port number of our server
// string error ; // To store error messages
// object con ; // To store the connection object
//
// // Create a connection object thats talking to the local query server
// error = catch {
// // Connect
// con = Protocols.TS2.client("localhost", 51234) ;
//
// // Log in
// con->login("adminuser", "adminpass") ;
//
// // Tell everyone we're restarting the server
// con->server_message(serverno, "We're restarting the server") ;
//
// // Restart that server
// con->restart(serverno) ;
// } ; // end catch
//
// if ( error )
// throw( ({ "TeamSpeak Error: " + error, backtrace() }) ) ;
//
//////////////////////////////////////////////////////////////////////////
// alternatively; you can merge all of the login/selection into one:
//
// saFlag = (isServerAdmin) ? "0" : "1" ;
// ssaFlag = (isSuperServerAdmin) ? "0" : "1" ;
//
// error = catch(
// Protocols.TS2.client("localhost", 51234, "admin", "pass", serverno)
// ->add_user("newusername", password, saFlag, ssaFlag) ;
// ) ;
// if ( error ) ...
//
//////////////////////////////////////////////////////////////////////////
// For a quick list of players:
//
// // Assuming "8767" is the port no of your server...
// array(string) plist =
// Protocols.TS2.client("localhost", 51234)->list_active_players(8767) ;
// foreach ( plist, string line ) {
// array(mixed) fields = line / "\t" ;
// write(fields[14] + "\n") ;
// }
//
// see the list_active_players function for a list of what the fields are
//
I've implemented a module for Roxen webserver which provides a standard set of methodologies for interfacing with a teamspeak 2 server - enabling you to add teamspeak 2 management functionality to your own website relatively easily, including adding and removing teamspeak users - so you can automatically add a teamspeak 2 account for users who register on your website.
This is just the pike module for communicating with a teamspeak 2 server, so if you want to use it off-the bat, you will have to use pike scripting (<?pike ...?>). I am, however, writing a tag module so that you will be fully able to control your teamspeak 2 server from HTML/RXML/XML pages with only a few normal tags.
For those wondering what/why Roxen; it predated Apache as "Spinner", it was developed in a language designed for dynamic content, Pike, and so has the most mature and stable content compilation and caching system going. Read: Used properly, it cuts down processing overheads by a factor of 13.
It has also, since its conception, always had a simple XML-style extensible scripting "language" - basically tags like <if ...> ... </if> etc.
What this module does is provide a programmatic interface internally for accessing teamspeak. Once the module is installed and the server restarted, you will be able to do things like this:
<?pike
var.server =
Protocols.TS2.client("localhost", 51234)->server_version() ;
?>
<p> We are running TeamSpeak 2 &var.server; </p>
(Of course, you could just write the result inside the pike tag, I'm just demonstrating :)
Or if you're doing something more elaborate, maybe:
<?pike
object con =
Protocols.TS2.client("localhost", 51234, "user", "pass", 8767) ;
// Where 8767 is the port no. of your server
string server = con->server_version() ;
write("<p> We are running TeamSpeak 2 " + server + "</p>") ;
// Get the players and their number
array(string) plist =
con->list_active_players() ;
int noOfPlayers = sizeof(plist) ;
if ( noOfPlayers == 0 )
write("<p>Our server is currently empty</p>") ;
else {
write("<p>There are " + noOfPlayers + " players on the server: ") ;
?>
All that said, I'll be introducing a module to implement the various, obvious RXML tags that spring to mind =)
Module documentation:
8x --- snip --- snip --- snip --- snip --- x8
//////////////////////////////////////////////////////////////////////////
// Pike Module for communicating with a TeamSpeak 2 server.
// Copyright (C) and By Oliver Smith, 2002 -- email oli@kfs.org
//
// This is the low-level module, if you are looking for RXML tags
// then you will want my upcoming teamspeak tags module.
//
//////////////////////////////////////////////////////////////////////////
// Installation:
//
// Copy to $ROXENHOME/pike/lib/pike/modules/Protocols/
// e.g. /usr/local/roxen/server-2.2.295/pike/lib/pike/modules/Protocols/
//
//////////////////////////////////////////////////////////////////////////
// Functions
//
// Protocols.TS2.client( hostname, portnumber )
// Creates a connection to the query server on the specified host/port
//
// Protocols.TS2.client( hostname, portnumber, username, password, server )
// As above, but logs in as username/password and selects the server
// identified by the "server" port number - default is 8767 I believe.
//
// server_version()
// Returns the current server version string
//
// login( username, password )
// Attempts to log in with the supplied credentials in an existing
// open connection.
//
// select_server( server_port_number )
// Tells the query server you wish to select a specific server. The
// servers are identified by port number, because that's how TS2 does it.
//
// list_channels()
// Returns an array containing the channels as listed by teamspeak 2
//
// list_active_players()
// Returns an array containing the active players as listed by ts2
//
// list_members()
// Returns an array listing all of the registered members
//
// broadcast_message( message )
// msgall( message )
// Sends the specified message to all servers
//
// server_message( server, message )
// msg( server, message)
// Sends the specified message to the server identified by its port no.
//
// add_user( loginname, password, server_admin, superserver_admin )
// Attempts to add the given user. server_admin and superserver_admin
// are booleans - i.e. either 0 or 1, where 1 means "yes".
//
// del_user( loginname )
// Removes a member's registration.
//
// start( [server] )
// stop( [server] )
// restart( [server] )
// Does what it says on the tin to the specified or selected server.
//
// command( "command", arguments... )
// Sends the specified command, with arguments, to the server, and
// returns an array of all the lines the server sends back.
//
//////////////////////////////////////////////////////////////////////////
// Example usages:
//
// int serverno = 8767 ; // Port number of our server
// string error ; // To store error messages
// object con ; // To store the connection object
//
// // Create a connection object thats talking to the local query server
// error = catch {
// // Connect
// con = Protocols.TS2.client("localhost", 51234) ;
//
// // Log in
// con->login("adminuser", "adminpass") ;
//
// // Tell everyone we're restarting the server
// con->server_message(serverno, "We're restarting the server") ;
//
// // Restart that server
// con->restart(serverno) ;
// } ; // end catch
//
// if ( error )
// throw( ({ "TeamSpeak Error: " + error, backtrace() }) ) ;
//
//////////////////////////////////////////////////////////////////////////
// alternatively; you can merge all of the login/selection into one:
//
// saFlag = (isServerAdmin) ? "0" : "1" ;
// ssaFlag = (isSuperServerAdmin) ? "0" : "1" ;
//
// error = catch(
// Protocols.TS2.client("localhost", 51234, "admin", "pass", serverno)
// ->add_user("newusername", password, saFlag, ssaFlag) ;
// ) ;
// if ( error ) ...
//
//////////////////////////////////////////////////////////////////////////
// For a quick list of players:
//
// // Assuming "8767" is the port no of your server...
// array(string) plist =
// Protocols.TS2.client("localhost", 51234)->list_active_players(8767) ;
// foreach ( plist, string line ) {
// array(mixed) fields = line / "\t" ;
// write(fields[14] + "\n") ;
// }
//
// see the list_active_players function for a list of what the fields are
//