Package: cs-gamestate
cs-gamestateCounter-Strike Game State Integration for Python: Game State Integration (GSI
for short) allows to receive various types of information, for example the name,
state and match statistics of the player, from a running Counter-Strike game
via the HTTP POST method in JSON format. This package aims to provide
structures, documentation and convenience methods for configuring, receiving and
verifying the GSI in python. To learn more about the Counter-Strike Game State
Integration, have a look at theValve Developer Communityor thisexcellent reddit post.InstallationNote: This package is still in early stages of development, installing might
miss dependencies or does not work at all.pip install cs-gamestateConfigurationThe GSI service needs to be configured in the game configuration directory. The
next time the game is launched, this configuration will be loaded automatically.To generate a configration, themake_configtool provided with this package
can be used, save the generated output as a filegamestate_integration_<service-name>.cfginto the game configuration directory:python -m cs_gamestate.utils.make_config "My GSI Service" http://127.0.0.1:1234/my-gsi --subscribe-to-allThis configures a GSI service called "My GSI Service" expecting an endpoint
server running on the localhost, i.e.,127.0.0.1, listening on port1234where HTTP POST requests are handled under the/my-gsipath. This example
service uses default configuration and subscribes to all possible information
components of the game state, even those only available in observer mode.For more information on the available configuration options, try the--helpoption of the configuration util, look into the source code or the
aforementioned articles.Receiving Game StatesOnce configured, the game will start transmitting game states as JSON structures
to the specified endpoint address. You can either implement your own service
handling HTTP POST requests under the specified address and process the raw JSON
data, or use the simple server based onflaskprovided with this package:# Game state integration endpoint serverfromcs_gamestate.endpointimportGSIServer# Create an endpoint listening on the specified path and portserver=GSIServer(path="/my-gsi",port=1234)# Read the next game state received by the server#   Reset the state buffer and block to only receive unique new statesstate=server.read(reset=True,block=True)When running the game and this server on the same host, i.e., the localhost,
this should work with the example configuration as generated above.The returned state object will be of typecs_gamestate.structs.gamestate.GameState, where subcomponents can be accessed
as object attributes, e.g.,state.playergives access to the player
subcomponent if it has been subscribed to, otherwise this attribute will beNone. The state object can be printed to give a string representation of the
game state or can be converted back to JSON (but includingNoneornullfor
fields which are not present) viajson.dumps(asdict(s))using thejsonpackage andasdictfrom thedataclassespackage.The package provides a simple utility program receiving and logging game states
to the console or standard output:python -m cs_gamestate.utils.logger /my-gsi 123This will create a service listening on the localhost, again corresponding to
the example configuration above. Received game states will be printed to the
terminal. Note: thismightbe a lot of output in an active game or just one
update every 30 seconds in the main menu.Verifying Game StatesThis package offers some basic verification of game states against known values
forsomeof the subcomponents, e.g., check received weapon names against the
set of known weapon names collected incs_gamestate.enums.equipment.
Verification is possible via theverifymethod of theGameStateobjects and
yields a list of strings containing a message for each component which cannot
be verified. Theloggerutil can be used to verify each game state it receives
by specifiyng the--verifycommand line option, printing verification messages
to the terminal, actually the standard error output, as well.Please consider reporting any verification issues, especially those regarding
weapon names, types and states still missing incs_gamestate.enumsby
opening an issue on the GitHub repository.