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
urihas to reach the server from their machine.127.0.0.1only 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 (seeGSIServer).
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.