diff options
Diffstat (limited to 'src/client.c')
| -rw-r--r-- | src/client.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/client.c b/src/client.c index 034ea74..e1816f2 100644 --- a/src/client.c +++ b/src/client.c @@ -134,28 +134,6 @@ void client_broadcast_output(const char *unit_name, /* ── Command handlers ────────────────────────────────────────────────────── */ -static void cmd_list(Client *c) { - /* Build a JSON array of unit summaries */ - char buf[PROTO_MAX_MSG]; - int pos = 0; - - pos += snprintf(buf + pos, sizeof(buf) - pos, - "{\"type\":\"list\",\"units\":["); - - for (int i = 0; i < g.unit_count; i++) { - Unit *u = &g.units[i]; - if (i > 0) - pos += snprintf(buf + pos, sizeof(buf) - pos, ","); - pos += snprintf(buf + pos, sizeof(buf) - pos, - "{\"name\":\"%s\",\"display\":\"%s\"," - "\"state\":\"%s\"}", - u->name, u->display, unit_state_str(u->state)); - } - - snprintf(buf + pos, sizeof(buf) - pos, "]}"); - proto_send(c->fd, buf); -} - static const char *probe_rcon_state(Unit *u) { if (u->console.type != CONSOLE_RCON) return unit_state_str(u->state); @@ -177,6 +155,28 @@ static const char *probe_rcon_state(Unit *u) { return (r == 0) ? "running" : "unreachable"; } +static void cmd_list(Client *c) { + /* Build a JSON array of unit summaries, using active probing for state */ + char buf[PROTO_MAX_MSG]; + int pos = 0; + + pos += snprintf(buf + pos, sizeof(buf) - pos, + "{\"type\":\"list\",\"units\":["); + + for (int i = 0; i < g.unit_count; i++) { + Unit *u = &g.units[i]; + if (i > 0) + pos += snprintf(buf + pos, sizeof(buf) - pos, ","); + pos += snprintf(buf + pos, sizeof(buf) - pos, + "{\"name\":\"%s\",\"display\":\"%s\"," + "\"state\":\"%s\"}", + u->name, u->display, probe_rcon_state(u)); + } + + snprintf(buf + pos, sizeof(buf) - pos, "]}"); + proto_send(c->fd, buf); +} + static void cmd_status(Client *c, const char *unit_name) { Unit *u = unit_find(unit_name); if (!u) { proto_send_error(c->fd, "unit not found"); return; } |
