Fix admin echo

This commit is contained in:
2026-09-24 22:55:08 -03:00
parent a5af824c91
commit 2023cf0f0d
9 changed files with 42 additions and 12 deletions
+42 -12
View File
@@ -510,23 +510,48 @@ static void cmd_ban_key(const char *key, const char *label)
puts("[admin] Failed to save the ban list.");
}
static void cmd_say(char *message)
/* A console broadcast is meant for everyone on the machine, so by default it
goes to every lobby rather than only the one picked with "use". */
static void cmd_say(char *message, bool every_lobby)
{
Server *server = selected_server();
if (!server)
return;
message = skip_space(message);
if (!message || !*message)
{
puts("usage: say <message>");
puts("usage: say <message> (all lobbies)");
puts(" say-here <message> (only the selected lobby)");
return;
}
CLI_MUTEX_LOCK(server->state_lock);
server_broadcast_msg(server, message);
CLI_MUTEX_UNLOCK(server->state_lock);
puts("[admin] Broadcast sent.");
if (!every_lobby)
{
Server *server = selected_server();
if (!server)
return;
CLI_MUTEX_LOCK(server->state_lock);
server_broadcast_msg(server, message);
CLI_MUTEX_UNLOCK(server->state_lock);
printf("[admin] Broadcast sent to lobby %d.\n", g_cli_server);
return;
}
int lobbies = 0;
int players = 0;
for (int i = 0; i < disaster_count(); i++)
{
Server *server = disaster_get(i);
if (!server)
continue;
CLI_MUTEX_LOCK(server->state_lock);
server_broadcast_msg(server, message);
players += (int)server->peers.noitems;
CLI_MUTEX_UNLOCK(server->state_lock);
lobbies++;
}
printf("[admin] Broadcast sent to %d lobbies (%d player(s) online).\n",
lobbies, players);
}
static void cmd_lobby(void)
@@ -738,7 +763,8 @@ static void print_help(void)
puts(" lobby-unblock <key|all> clear per-lobby timeouts for a player");
puts(" reports [key] list player reports (key shows full history)");
puts(" reports-clear <key|all> dismiss reports for one player, or all");
puts(" say <message> broadcast a server message");
puts(" say <message> broadcast to EVERY lobby");
puts(" say-here <message> broadcast to the selected lobby only");
puts(" lobby force selected server back to lobby");
puts(" win <exe|surv> force the current game result");
puts(" help show this command list");
@@ -879,7 +905,11 @@ int admin_cli_run(void)
}
else if (strcmp(command, "say") == 0 || strcmp(command, "broadcast") == 0)
{
cmd_say(cursor);
cmd_say(cursor, true);
}
else if (strcmp(command, "say-here") == 0 || strcmp(command, "sayhere") == 0)
{
cmd_say(cursor, false);
}
else if (strcmp(command, "lobby") == 0)
{