summaryrefslogtreecommitdiff
path: root/minecctl
diff options
context:
space:
mode:
Diffstat (limited to 'minecctl')
-rw-r--r--minecctl/minecctl-rcon.c79
-rw-r--r--minecctl/minecctl.c2
2 files changed, 41 insertions, 40 deletions
diff --git a/minecctl/minecctl-rcon.c b/minecctl/minecctl-rcon.c
index 6ef6cc1..16939d1 100644
--- a/minecctl/minecctl-rcon.c
+++ b/minecctl/minecctl-rcon.c
@@ -228,6 +228,20 @@ get_one_status(int fd, char *buf, size_t len, const char *cmd,
return false;
}
+static struct server *
+get_default_server(struct cfg *cfg)
+{
+ struct server *server;
+
+ server = list_first_entry_or_null(&cfg->servers, struct server, list);
+ if (!server)
+ die("No servers defined");
+
+ read_server_config(server);
+
+ return server;
+}
+
void
do_status(struct cfg *cfg) {
char buf[4096];
@@ -239,11 +253,7 @@ do_status(struct cfg *cfg) {
int fd;
struct server *server;
- server = list_first_entry_or_null(&cfg->servers, struct server, list);
- if (!server)
- die("No servers defined");
-
- read_server_config(server);
+ server = get_default_server(cfg);
fd = rcon_login(cfg, server);
if (get_one_status(fd, buf, sizeof(buf), "seed", 1,
@@ -316,16 +326,11 @@ get_player_count(int fd, unsigned *current, unsigned *max)
return false;
}
-void
-do_stop(struct cfg *cfg) {
+static void
+stop_one_server(struct cfg *cfg, struct server *server)
+{
int fd;
- struct server *server;
-
- server = list_first_entry_or_null(&cfg->servers, struct server, list);
- if (!server)
- die("No servers defined");
- read_server_config(server);
fd = rcon_login(cfg, server);
if (cfg->force_stop) {
@@ -333,29 +338,37 @@ do_stop(struct cfg *cfg) {
/* FIXME: args optional */
if (!get_player_count(fd, &current, &max)) {
- error("Unable to get player count");
+ error("%s: unable to get player count, not stopping",
+ server->shortname);
return;
} else if (current > 0) {
- error("Not stopping server, there are active players"
- " (use -f to force stop)");
+ error("%s: has active players (use -f to force)",
+ server->shortname);
return;
}
}
+ info("%s: sending stop command", server->shortname);
send_cmd(fd, "stop");
+ close(fd);
}
void
-do_stop_all(_unused_ struct cfg *cfg) {
- /*
+do_stop(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");
+ server = get_default_server(cfg);
+ stop_one_server(cfg, server);
+}
+
+void
+do_stop_all(struct cfg *cfg) {
+ struct server *server;
+
+ list_for_each_entry(server, &cfg->servers, list) {
+ read_server_config(server);
+ stop_one_server(cfg, server);
+ }
}
void
@@ -364,11 +377,7 @@ do_pcount(struct cfg *cfg) {
unsigned current, max;
struct server *server;
- server = list_first_entry_or_null(&cfg->servers, struct server, list);
- if (!server)
- die("No servers defined");
-
- read_server_config(server);
+ server = get_default_server(cfg);
fd = rcon_login(cfg, server);
if (get_player_count(fd, &current, &max))
@@ -385,11 +394,7 @@ do_console(struct cfg *cfg)
int fd;
struct server *server;
- server = list_first_entry_or_null(&cfg->servers, struct server, list);
- if (!server)
- die("No servers defined");
-
- read_server_config(server);
+ server = get_default_server(cfg);
fd = rcon_login(cfg, server);
prompt = alloca(strlen(program_invocation_short_name) +
@@ -431,11 +436,7 @@ do_command(struct cfg *cfg) {
int fd;
struct server *server;
- server = list_first_entry_or_null(&cfg->servers, struct server, list);
- if (!server)
- die("No servers defined");
-
- read_server_config(server);
+ server = get_default_server(cfg);
fd = rcon_login(cfg, server);
send_cmd(fd, cfg->cmdstr);
}
diff --git a/minecctl/minecctl.c b/minecctl/minecctl.c
index bdf51c1..959121e 100644
--- a/minecctl/minecctl.c
+++ b/minecctl/minecctl.c
@@ -386,7 +386,7 @@ parse_command(char * const *argv)
error("Too many arguments");
usage(false);
}
- cfg->cmd = do_list;
+ cfg->cmd = do_stop_all;
break;
case CMD_STATUS:
get_optional_server_arg(&argv, false);