summaryrefslogtreecommitdiff
path: root/minecctl/rcon-commands.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-07-09 20:36:15 +0200
committerDavid Härdeman <david@hardeman.nu>2020-07-09 20:36:15 +0200
commitdd6321c0acf7b0570811200a205cc4104bee49c7 (patch)
tree52da75427a0c1d237806fbebba23025afd79d28d /minecctl/rcon-commands.c
parent4ae60696aed938347cc1cf2a5d8f5a2b86292132 (diff)
Implement a basic init command in minecctl to create an initial example config
Diffstat (limited to 'minecctl/rcon-commands.c')
-rw-r--r--minecctl/rcon-commands.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/minecctl/rcon-commands.c b/minecctl/rcon-commands.c
index bab0004..44bb286 100644
--- a/minecctl/rcon-commands.c
+++ b/minecctl/rcon-commands.c
@@ -112,7 +112,7 @@ static int rcon_login(struct cfg *cfg, struct server *server)
fd = connect_any(&server->scfg.rcons, &saddr, &error);
if (fd < 0) {
- error("%s: unable to connect - %s", server->name, error);
+ verbose("%s: unable to connect - %s", server->name, error);
goto error;
} else
verbose("%s: connected to %s", server->name, saddr->addrstr);
@@ -344,24 +344,28 @@ static bool stop_one_server(struct cfg *cfg, struct server *server)
bool rv;
fd = rcon_login(cfg, server);
- if (fd < 0)
+ if (fd < 0) {
+ info("• %s: %sfail%s - unable to login",
+ server->name, ansi_red, ansi_normal);
return false;
+ }
- if (cfg->force_stop) {
+ if (!cfg->force_stop) {
unsigned current;
if (!get_player_count(fd, &current, NULL)) {
- error("%s: unable to get player count, not stopping",
- server->name);
+ info("• %s: %sfail%s - unable to get player count",
+ server->name, ansi_red, ansi_normal);
return false;
} else if (current > 0) {
- error("%s: has active players (use -f to force)",
- server->name);
+ info("• %s: %sfail%s - has active players "
+ "(use -f to force)",
+ server->name, ansi_red, ansi_normal);
return false;
}
}
- info("%s: sending stop command", server->name);
+ info("• %s: sending stop command", server->name);
rv = send_cmd(fd, "stop");
close(fd);
@@ -379,19 +383,12 @@ bool do_stop(struct cfg *cfg)
bool do_stop_all(struct cfg *cfg)
{
struct server *server;
- unsigned lineno;
- const char *error;
bool rv = true;
+ server_read_all_configs(cfg, false);
+
list_for_each_entry(server, &cfg->servers, list) {
- if (!server_read_config(cfg, server, &lineno, &error)) {
- info("• %s: %sfail%s - invalid configuration file "
- "(line %u: %s)",
- server->name, ansi_red, ansi_normal,
- lineno, error);
- rv = false;
- }
- /* FIXME: error checks */
+ /* FIXME: print more info, error checks */
stop_one_server(cfg, server);
}