From 4ae60696aed938347cc1cf2a5d8f5a2b86292132 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Tue, 7 Jul 2020 22:32:11 +0200 Subject: Improve handling of info and status commands --- minecctl/rcon-commands.c | 53 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 16 deletions(-) (limited to 'minecctl/rcon-commands.c') diff --git a/minecctl/rcon-commands.c b/minecctl/rcon-commands.c index 0c4fd7e..bab0004 100644 --- a/minecctl/rcon-commands.c +++ b/minecctl/rcon-commands.c @@ -226,7 +226,7 @@ static bool get_one_status(int fd, char *buf, size_t len, const char *cmd, return false; } -bool do_info(struct cfg *cfg) +static bool do_one_info(struct cfg *cfg, struct server *server) { char buf[4096]; char tbuf[4096]; @@ -235,64 +235,85 @@ bool do_info(struct cfg *cfg) unsigned epacks, apacks; unsigned bannedplayers, bannedips; int fd; - struct server *server; - server = server_get_default(cfg); fd = rcon_login(cfg, server); if (fd < 0) return false; + info("• %s", server->name); if (get_one_status(fd, buf, sizeof(buf), "seed", 1, "Seed : [ %[^]]]", &reply, tbuf)) - info("Seed: %s", tbuf); + info(" Seed: %s", tbuf); if (get_one_status(fd, buf, sizeof(buf), "difficulty", 1, "The difficulty is %s", &reply, tbuf)) - info("Difficulty: %s", tbuf); + info(" Difficulty: %s", tbuf); if (get_one_status(fd, buf, sizeof(buf), "list", 2, "There are %u of a max %u players online", &reply, &cplayers, &maxplayers)) - info("Players: %u/%u", cplayers, maxplayers); + info(" Players: %u/%u", cplayers, maxplayers); if (get_one_status(fd, buf, sizeof(buf), "time query day", 1, "The time is %u", &reply, >ime)) - info("In-game days: %u", gtime); + info(" In-game days: %u", gtime); if (get_one_status(fd, buf, sizeof(buf), "time query gametime", 1, "The time is %u", &reply, >ime)) - info("World age: %ud:%02uh:%02um", mctime_days(gtime), + info(" World age: %ud:%02uh:%02um", mctime_days(gtime), mctime_hh(gtime), mctime_mm(gtime)); if (get_one_status(fd, buf, sizeof(buf), "time query daytime", 1, "The time is %u", &reply, >ime)) - info("Current in-game time: %02uh:%02um", + info(" Current in-game time: %02uh:%02um", mctime_hh(gtime + MCTIME_OFFSET), mctime_mm(gtime + MCTIME_OFFSET)); if (get_one_status(fd, buf, sizeof(buf), "datapack list enabled", 2, "There are %u data packs enabled: %[^\n]", &reply, &epacks, tbuf)) - info("Enabled data packs (%u): %s", epacks, tbuf); + info(" Enabled data packs (%u): %s", epacks, tbuf); if (get_one_status(fd, buf, sizeof(buf), "datapack list available", 2, "There are %u data packs available : %[^\n]", &reply, &apacks, tbuf)) - info("Available data packs (%u): %s", apacks, tbuf); + info(" Available data packs (%u): %s", apacks, tbuf); else if (streq(reply, "There are no more data packs available")) - info("Available data packs: none"); + info(" Available data packs: none"); if (get_one_status(fd, buf, sizeof(buf), "banlist players", 1, "There are %u bans", &reply, &bannedplayers)) - info("Banned players: %u", bannedplayers); + info(" Banned players: %u", bannedplayers); else if (streq(reply, "There are no bans")) - info("Banned players: 0"); + info(" Banned players: 0"); if (get_one_status(fd, buf, sizeof(buf), "banlist ips", 1, "There are %u bans", &reply, &bannedips)) - info("Banned IPs: %u", bannedips); + info(" Banned IPs: %u", bannedips); else if (streq(reply, "There are no bans")) - info("Banned IPs: 0"); + info(" Banned IPs: 0"); + + close(fd); + return true; +} + +bool do_info(struct cfg *cfg) +{ + struct server *server; + + if (cfg->default_set) { + server = server_get_default(cfg); + if (!server) { + error("failed to get default server"); + return false; + } + + do_one_info(cfg, server); + } else { + server_read_all_configs(cfg, false); + list_for_each_entry(server, &cfg->servers, list) + do_one_info(cfg, server); + } return true; } -- cgit v1.2.3