Skip to content

feat(agent): read player counts over the Steam A2S query - #991

Merged
ValgulNecron merged 4 commits into
GameplanePanel:masterfrom
bafulton:feat/a2s-player-count
Nov 17, 2026
Merged

ValgulNecron merged 4 commits into
GameplanePanel:masterfrom
bafulton:feat/a2s-player-count

Conversation

@bafulton

@bafulton bafulton commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The agent reads player counts only through the game's console. Valheim has no RCON, so its servers report no player count: the dashboard shows none, and idle sleep never puts them to sleep ("this game reports no player count"). Valheim does report its player count, through the Steam server query (A2S) on its query port. lloesche/valheim-server's own status.json is built on that query, and the Valheim template already turns STATUS_HTTP on, intending to read it ("player count flows through the status HTTP endpoint"), but nothing read it.

This adds an optional capabilities.players.query to GameTemplate:

capabilities:
  players:
    query:
      protocol: a2s
      port: 2457
  • CRD: PlayerQuerySpec has protocol (enum a2s) and port (1 to 65535). I ran make generate && make manifests.
  • Agent: new agent/internal/a2s package. It sends A2S_INFO over UDP, handles the challenge reply (up to two challenges), and reads players, max players and bots. Split replies aren't supported, since A2S_INFO fits in one datagram. When query is set, the heartbeat takes playersOnline and playersMax from it, not the console. Bots don't count as players. A failed query reports the count as unknown (null), as a failed console list does, so an unreachable server never looks empty. The query goes to --rcon-host (loopback in the pod) with a 2-second timeout.
  • The Players tab still uses the console for its list and moderation. This only adds a count.
  • gp-module validate flags a query port that isn't a declared UDP port in spec.ports. The CRD can't check that: a query aimed at the TCP game port, or a port the game doesn't use, would otherwise only show up as a server that never sleeps.
  • Docs: docs/module-authoring.md covers query, with the Valheim example. Changelog entry: changelog/unreleased/a2s-player-count.md.

Companion module PR: GameplanePanel/module#74 turns it on for Valheim. Operators without this PR prune the unknown field, so nothing changes for them.

Tests

New tests only; no existing test was changed.

  • agent/internal/a2s/a2s_test.go: a reply, a challenge round trip, a server that keeps sending challenges, a timeout, malformed replies, and bots outnumbering players.
  • agent/internal/heartbeat/heartbeat_test.go: the query replaces the console count and leaves bots out. An unreachable server and an unknown protocol are errors.
  • gp-module/internal/validator/validator_test.go: a declared UDP port passes, while a TCP port and an undeclared port are flagged.

Verification

Locally I ran only compile checks: go build ./... and go vet for agent (GOOS=linux), operator and gp-module, plus gofmt -l. CI is the verification authority.

I also checked the A2S client against a live lloesche/valheim-server (Valheim 0.221.x) on a 0.4.0 install, with a throwaway main that I didn't commit. With -public 1 it read {Players:0 MaxPlayers:10 Bots:0}. With -public 0, Valheim doesn't answer A2S at all, and the image's status.json times out as well, so a private Valheim server still reports no player count. The module PR documents this.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6a2f61c and cff984c.

Files selected for processing: 37

  • agent/cmd/main.go
  • agent/internal/a2s/a2s.go
  • agent/internal/a2s/a2s_test.go
  • agent/internal/caps/caps.go
  • agent/internal/heartbeat/heartbeat.go
  • agent/internal/heartbeat/heartbeat_test.go
  • agent/specs.md
  • changelog/unreleased/991-a2s-player-count.md
  • charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backups.yaml
  • charts/gameplane/charts/gameplane-crds/crds/gameplane.local_backupschedules.yaml
  • charts/gameplane/charts/gameplane-crds/crds/gameplane.local_clusters.yaml
  • charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gameservers.yaml
  • charts/gameplane/charts/gameplane-crds/crds/gameplane.local_gametemplates.yaml
  • charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modules.yaml
  • charts/gameplane/charts/gameplane-crds/crds/gameplane.local_modulesources.yaml
  • charts/gameplane/charts/gameplane-crds/crds/gameplane.local_networkcaptures.yaml
  • charts/gameplane/charts/gameplane-crds/crds/gameplane.local_restores.yaml
  • charts/gameplane/crd-manifests/gameplane.local_backups.yaml
  • charts/gameplane/crd-manifests/gameplane.local_backupschedules.yaml
  • charts/gameplane/crd-manifests/gameplane.local_clusters.yaml
  • charts/gameplane/crd-manifests/gameplane.local_gameservers.yaml
  • charts/gameplane/crd-manifests/gameplane.local_gametemplates.yaml
  • charts/gameplane/crd-manifests/gameplane.local_modules.yaml
  • charts/gameplane/crd-manifests/gameplane.local_modulesources.yaml
  • charts/gameplane/crd-manifests/gameplane.local_networkcaptures.yaml
  • charts/gameplane/crd-manifests/gameplane.local_restores.yaml
  • docs/module-authoring.md
  • gp-module/internal/validator/rules.go
  • gp-module/internal/validator/validator.go
  • gp-module/internal/validator/validator_test.go
  • gp-module/specs.md
  • operator/api/v1alpha1/gametemplate_types.go
  • operator/api/v1alpha1/zz_generated.deepcopy.go
  • operator/config/crd/gameplane.local_gametemplates.yaml
  • operator/specs.md
  • test/e2e/a2s_player_count_e2e_test.go
  • test/e2e/buckets.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ValgulNecron

Copy link
Copy Markdown
Collaborator

hey could you please fix the issue causing the ci to fail?

@github-actions github-actions Bot added area: agent in-pod sidecar area: chart Helm chart and deployment area: modules game template OCI bundles area: operator controller-runtime operator and CRDs area: shared netguard, gameaction, gameproto, svcutil and other shared packages type: feature New capability or user-facing addition labels Nov 16, 2026
@bafulton

Copy link
Copy Markdown
Contributor Author

Thanks for the nudge! Pushed a fix: the A2S query now dials with net.Dialer.DialContext and the tests listen through net.ListenConfig (the noctx lint findings), and two new tests cover the dial and malformed-reply error paths, which were what kept changed-lines coverage just under 90%.

Baylem commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

This fits Gameplane. A2S player counts are useful beyond Valheim, and the template's protocol field gives other modules a way to use them. Keeping failed queries unknown preserves the idle-sleep safety rule.

Please add the required E2E through template configuration, operator injection, agent heartbeat and idle eligibility. It should observe a nonzero count, a real zero, then a failed query that clears the previous count and prevents sleep.

Please also update the agent/operator/toolkit specifications with query precedence, bot handling and failure behavior. The module-authoring docs should state the supported A2S response format and the split-packet limitation.

Keep this PR focused on counts. Additional protocols and player-list or moderation support can follow when a module needs them.

bafulton and others added 4 commits November 17, 2026 08:05
Games with no console that lists players, such as Valheim, which has no
RCON, reported no player count, so they never slept. A module can now
declare capabilities.players.query (protocol a2s and the UDP query port),
and the heartbeat reads the count from A2S_INFO instead of the console.
Bots aren't counted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ben Fulton <fulton.benjamin@gmail.com>
noctx flags net.DialTimeout and net.ListenPacket, so the query dials with
net.Dialer.DialContext (as the RCON clients do) and the tests listen through
net.ListenConfig. New tests send the query to an address without a port and
to a server with a malformed reply, so those error returns are covered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ben Fulton <fulton.benjamin@gmail.com>
contextcheck flags sendOnce -> queryPlayerCounts -> QueryInfo for dropping
the heartbeat's context. QueryInfo and both player-count helpers now take
it, and the dial uses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ben Fulton <fulton.benjamin@gmail.com>
Review follow-ups for capabilities.players.query:

- E2E TestGameServer_A2SPlayerCountDrivesIdle runs a Python A2S
  responder (challenge round trip included) as the game and follows the
  count from template configuration through operator injection and the
  agent heartbeat to idle eligibility: 3 players with 1 bot report 2 and
  keep the idle clock stopped, a bot-only server reports 0 and starts it,
  and a query that stops answering clears the count and the clock, so a
  backdated clock doesn't sleep the server.
- agent, operator and gp-module specs record the query's precedence over
  the console list (no fallback), bot handling, and failure behavior.
- docs/module-authoring.md states the A2S_INFO reply format the agent
  reads and that split replies aren't supported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ben Fulton <fulton.benjamin@gmail.com>
@bafulton
bafulton force-pushed the feat/a2s-player-count branch from e6adb41 to cff984c Compare November 17, 2026 13:09
@bafulton

Copy link
Copy Markdown
Contributor Author

Thanks! Pushed cff984c:

  • E2E TestGameServer_A2SPlayerCountDrivesIdle (operator bucket): the game is a small Python A2S responder on UDP 27015 that also does the challenge round trip. It runs through template configuration, operator injection (GAMEPLANE_CAPABILITIES), the agent heartbeat and idle eligibility. 3 players, 1 of them a bot, report playersOnline: 2 and playersMax: 10, and the idle clock stays stopped. A bot-only server reports a real 0 and the clock starts. Then the responder goes silent: the count is cleared rather than left at 0, the clock is cleared with it, and a clock backdated past the threshold doesn't sleep the server.
  • Specs:
    • agent/specs.md gains the a2s package and, under the heartbeat, query precedence (with players.query set, the console list is never used for the count, even as a fallback; /players and moderation still use the console), bot handling (players − bots, clamped at 0; a max of 0 is unknown), and failure behavior (every failure patches both counts null, never 0).
    • operator/specs.md covers injection and the idle rule.
    • gp-module/specs.md covers the query-port validation.
  • Module authoring docs now state the A2S_INFO reply format the agent reads, the challenge handling, and that split replies aren't supported, so such a server reports no count and doesn't sleep.

The scope stays at counts.

@Baylem Baylem left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest revision addresses my earlier feedback. The E2E exercises template configuration, operator capability injection, the agent's A2S query and heartbeat, then idle eligibility through nonzero, zero and failed-query states. It verifies that query failure clears the previous count and prevents sleep. The agent/operator/toolkit specifications and supported response-format limitations are documented.

Current-head CI is green, including the new E2E. Approved.

@ValgulNecron
ValgulNecron merged commit ff076d7 into GameplanePanel:master Nov 17, 2026
111 checks passed
ValgulNecron pushed a commit to GameplanePanel/module that referenced this pull request Nov 17, 2026
Valheim has no RCON, so its servers reported no player count and never
slept. Read the count over A2S on the query port (2457) through the new
capabilities.players.query. Valheim answers it only when listed publicly,
the default. Regenerate the editor schema from the CRD. Bump the bundle
to 2.4.0.

Needs the agent support in GameplanePanel/Gameplane#991; older operators
drop the field and behave as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ben Fulton <fulton.benjamin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: agent in-pod sidecar area: chart Helm chart and deployment area: modules game template OCI bundles area: operator controller-runtime operator and CRDs area: shared netguard, gameaction, gameproto, svcutil and other shared packages type: feature New capability or user-facing addition

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants