Repository navigation
feat(agent): read player counts over the Steam A2S query - #991
Conversation
|
Warning Review limit reachedYou'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. View limit details
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. |
|
hey could you please fix the issue causing the ci to fail? |
|
Thanks for the nudge! Pushed a fix: the A2S query now dials with |
|
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. |
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>
e6adb41 to
cff984c
Compare
|
Thanks! Pushed cff984c:
The scope stays at counts. |
Baylem
left a comment
There was a problem hiding this comment.
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.
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>
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 ownstatus.jsonis built on that query, and the Valheim template already turnsSTATUS_HTTPon, intending to read it ("player count flows through the status HTTP endpoint"), but nothing read it.This adds an optional
capabilities.players.querytoGameTemplate:PlayerQuerySpechasprotocol(enuma2s) andport(1 to 65535). I ranmake generate && make manifests.agent/internal/a2spackage. 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. Whenqueryis set, the heartbeat takesplayersOnlineandplayersMaxfrom it, not the console. Bots don't count as players. A failed query reports the count as unknown (null), as a failed consolelistdoes, so an unreachable server never looks empty. The query goes to--rcon-host(loopback in the pod) with a 2-second timeout.gp-module validateflags a queryportthat isn't a declared UDP port inspec.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/module-authoring.mdcoversquery, 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 ./...andgo vetfor agent (GOOS=linux), operator and gp-module, plusgofmt -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 throwawaymainthat I didn't commit. With-public 1it read{Players:0 MaxPlayers:10 Bots:0}. With-public 0, Valheim doesn't answer A2S at all, and the image'sstatus.jsontimes out as well, so a private Valheim server still reports no player count. The module PR documents this.🤖 Generated with Claude Code