From dd6321c0acf7b0570811200a205cc4104bee49c7 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Thu, 9 Jul 2020 20:36:15 +0200 Subject: Implement a basic init command in minecctl to create an initial example config --- minecctl/rcon-commands.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'minecctl/rcon-commands.c') 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, ¤t, 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); } -- cgit v1.2.3