Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Multiple Players

One server can follow several players at once, with each player running CS2 on their own machine and the same config file pointing them all at that server.

Tracking Several Players

To track more than one player, we pass a list of SteamID64s:

from pygsi import GSIServer, RoundState

gsi = GSIServer(player_ids=["76561198000000001", "76561198000000002"])


@gsi.on_round_end
async def round_end(player_id: str, old: RoundState | None, new: RoundState) -> None:
    print(f"{player_id}: round over, {new.winning_team} won")

Warning

Each player’s uri has to reach the server from their machine. 127.0.0.1 only works for the player on the machine running the server. Everyone else needs that machine’s address, and the server has to listen on it, which it does by default (see GSIServer).

Per-Player State

pygsi keeps each player’s state apart from everyone else’s. We get at it through gsi.states, a dictionary from each SteamID64 to that player’s GameState, or to None before their first payload:

for steamid, state in gsi.states.items():
    if state is not None and state.player is not None:
        print(steamid, state.player.match_stats.kills)

The shortcut gsi.state raises RuntimeError when there’s more than one player, since it can’t know whose state we want.

Routing

To decide whose payload it got, pygsi reads the provider block, which always names the CS2 client that sent it. It doesn’t use the player block, because that switches to someone else when the player dies and spectates (see Spectating After Death). Two tracked players in the same match never mix up their states, then, even when one is watching the other.