summaryrefslogtreecommitdiff
path: root/minecctl/minecctl-rcon.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-26 00:25:30 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-26 00:25:30 +0200
commit30e19ad39ccc099b1b41f4df9be21d8d25cb8f45 (patch)
tree08de5a8afff7336cfc77d560891578735980be98 /minecctl/minecctl-rcon.c
parenta71d847b0a752375e8fa2c82c634a800bede2f9b (diff)
Bring some sanity to cmd parsing
Diffstat (limited to 'minecctl/minecctl-rcon.c')
-rw-r--r--minecctl/minecctl-rcon.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/minecctl/minecctl-rcon.c b/minecctl/minecctl-rcon.c
index 6ee8b50..fd880f5 100644
--- a/minecctl/minecctl-rcon.c
+++ b/minecctl/minecctl-rcon.c
@@ -293,6 +293,21 @@ do_ping(_unused_ struct cfg *cfg) {
die("Not implemented");
}
+static bool
+get_player_count(int fd, unsigned *current, unsigned *max)
+{
+ char buf[4096];
+ const char *reply;
+
+ if (get_one_status(fd, buf, sizeof(buf), "list", 2,
+ "There are %u of a max %u players online",
+ &reply, current, max))
+ return true;
+
+ else
+ return false;
+}
+
void
do_stop(struct cfg *cfg) {
int fd;
@@ -300,22 +315,48 @@ do_stop(struct cfg *cfg) {
assert_die(cfg, "invalid arguments");
fd = rcon_login(cfg);
+ if (cfg->force_stop) {
+ unsigned current, _unused_ max;
+
+ /* FIXME: args optional */
+ if (!get_player_count(fd, &current, &max)) {
+ error("Unable to get player count");
+ return;
+ } else if (current > 0) {
+ error("Not stopping server, there are active players"
+ " (use -f to force stop)");
+ return;
+ }
+ }
+
send_cmd(fd, "stop");
}
void
do_stop_all(_unused_ struct cfg *cfg) {
+ /*
+ struct server *server;
+ int fd;
+
+ list_for_each_entry(server, &cfg->known_servers, list) {
+ read_server_config(server->filename);
+ */
+
die("Not implemented");
}
void
do_pcount(struct cfg *cfg) {
int fd;
+ unsigned current, max;
assert_die(cfg, "invalid arguments");
fd = rcon_login(cfg);
- send_cmd(fd, "list");
+ if (get_player_count(fd, &current, &max))
+ info("Players: %u/%u", current, max);
+ else
+ die("Failed to get player count");
}
void