Evie Addon Details

Watch - Add Favorite

SRCDS tools - Version 0.8.0811

posted on 2008-08-11 14:45:24
by GODJonez
8
w00ts
w00t!
Requires: Tags: console css hl2dm script-helper sdk tools

Description

This Python module package will contain some advanced functions to interact more with the Source server itself. For any ideas on what to add, please post in the forum topic.

Currently usable modules are:
console

  • This module contains functions for directly interacting with the server console.
  • NOTE: Console functions work on Linux servers only!
  • dbgmsg(text)

    • Prints selected text on stderr stream. This will make the text appear in the console even if output capture was active.
    • text - the text you want to print, a new line character is appended by the function

  • get_concmd_output(command, callback, args=(), kw={}, bufsize=1024)

    • Executes a console command and captures whatever it outputs to the server console and calls the callback function with the data. The captured output will not visible in the server console.
    • command - the command string to be executed using es.ServerCommand (equal to es.server.queuecmd)
    • callback - a Python callable object that should accept at least one parameter, the captured text string
    • args - optional parameter containing extra parameters that should be used with the callback function in a tuple
    • kw - optional parameter containing the keyword parameters that should be used with the callback function in a dict
    • bufsize - optional parameter specifying the maximum length of output to be saved from the console (no, there is no 'unlimited' option)

  • get_console_output(function, args=(), kw={}, bufsize=1024)

    • Calls a Python function with given parameters, captures any console output the function creates and returns a tuple of type (return_value, captured_output) where return_value is whatever the Python function returned and captured_output is the text that would had appeared on the server console during executing the function.
    • function - the Python callable object to execute
    • args - optional parameter being a tuple of parameters for the function
    • kw - optional parameter being a dictionary of keyword arguments for the function
    • bufsize - optional parameter specifying the maximum length of output to be saved from the console (no, there is still no 'unlimited' option)



In other words, currently this has any value only on Linux servers. Valve has made the Windows servers not use standard ways to input and output data in the console, so it is not possible to directly manipulate them without hacking the function in the engine level, which in turn is not possible with EventScripts.

EXAMPLES

A simple example demonstrating how to capture the output of a Python function and that the text is not visible in console at all:
import es
import srcds.console # IMPORT THE console MODULE FROM srcds PACKAGE!
 
# print some message
es.dbgmsg(0, 'First message!')
# capture the output of the next message:
retval, output = srcds.console.get_console_output(es.dbgmsg, (0, 'Second message!'))
# print another message
es.dbgmsg(0, 'Third message!')
 
# now print what was captured before
es.dbgmsg(0, 'es.dbgmsg returned %s and the text it put was: "%s"'%(
retval,
output[:-1],
)
)
'''
Note that since es.dbgmsg prints a line feed,
that line feed is captured also,
so we are removing it in this example using slice operator [:-1]
'
''


The above example will output this on a Linux server:
First message!
Third message!
es.dbgmsg returned None and the text it put was: "Second message!"


Another example that makes some real use of console output capture feature, it captures output of the console command "status" and parses it.

import es
import srcds.console # IMPORT THE console MODULE FROM srcds PACKAGE!
 
'''
Some script could call get_server_info from this module
and then receive the server info as a dictionary to its callback function
'
''
def get_server_info(callback):
# capture the output of "status" and parse it in our callback:
srcds.console.get_concmd_output('status', status_callback, callback)
# Note that we are passing the callback function as extra parameter here
 
def status_callback(text, callback):
# this callback is called when the output of "status" is saved
# the parameter callback is the extra parameter from previous function
# The layout of the output, as saved in the text parameter is like this:
'''
hostname: Counter-Strike: Source
version : 1.0.0.34/7 3224 secure
udp/ip : 192.168.11.150:27015
map : de_dust at: 0 x, 0 y, 0 z
players : 0 (32 max)
 
# userid name uniqueid connected ping loss state adr
'
''
# Create a dictionary into which to save the info
info = {}
# Split the text into lines and parse them based on the info above
lines = text.split('\n')
info['hostname'] = lines[0].split(':', 1)[1].strip()
version_info = lines[1].split(':', 1)[1].strip().split(' ', 2)
info['version'] = version_info[0]
info['build'] = version_info[1]
info['secure'] = (version_info[2] == 'secure')
info['address'] = lines[2].split(':', 1)[1].strip()
info['map'] = lines[3].split(':', 1)[1].strip().split(' ', 1)[0]
player_info = lines[4].split(':', 1)[1].strip().split(' ', 2)
info['players'] = int(player_info[0])
info['maxplayers'] = int(player_info[1][1:])
# Now call the callback function with our parsed dict info
callback(info)
 
# test the script:
import pprint # pretty printer for nicer output of the dictionary
 
def print_it(info):
pprint.pprint(info)
 
get_server_info(print_it)


With the test part in previous example this is the output in console:
{'address': '192.168.11.150:27015',
'build': '3224',
'hostname': 'Counter-Strike: Source',
'map': 'de_dust',
'maxplayers': 32,
'players': 0,
'secure': True,
'version': '1.0.0.34/7'}



Note: This has been tested only on Linux Source Dedicated Server for Counter-Strike: Source. It should work in Orange Box version of the dedicated server too, but I have not been able to test it on one yet.

Installation

  1. Download the ZIP file: http://addons.eventscripts.com/addons/download/srcds
  2. Extract it to your game folder
  3. Load some scripts that utilize this package or create your own!

Version Notes For 0.8.0811

Updated on: 2008-08-11 14:45:24 EST by GODJonez
First release containing console output capture for Linux servers.
( Previous Versions )