summaryrefslogtreecommitdiff
path: root/minecctl/rcon-commands.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-07-07 22:32:11 +0200
committerDavid Härdeman <david@hardeman.nu>2020-07-07 22:32:11 +0200
commit4ae60696aed938347cc1cf2a5d8f5a2b86292132 (patch)
treeb83ad5727b56f010c0e90bb3f80b4ff95bf04082 /minecctl/rcon-commands.c
parente685df91251ca111e42306e6f36835e55f052c0c (diff)
Improve handling of info and status commands
Diffstat (limited to 'minecctl/rcon-commands.c')
-rw-r--r--minecctl/rcon-commands.c53
1 files changed, 37 insertions, 16 deletions
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, &gtime))
- 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, &gtime))
- 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, &gtime))
- 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;
}