summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-07-04 12:20:53 +0200
committerDavid Härdeman <david@hardeman.nu>2020-07-04 12:20:53 +0200
commit45af0d8c8603f037efe5f7bc1b1020b9cc42acdd (patch)
treeb35ef246c703c6237cfa165ddc950d61dbeabeae
parentbf24a9ac317f55ffa85df60ddffd171abc347e65 (diff)
Add debug option for minecctl and prettify the output of dump_config() a bit
-rw-r--r--minecctl/minecctl.c138
-rw-r--r--minecctl/minecctl.h2
-rw-r--r--minecctl/misc-commands.c2
3 files changed, 111 insertions, 31 deletions
diff --git a/minecctl/minecctl.c b/minecctl/minecctl.c
index b8d26d9..1752e25 100644
--- a/minecctl/minecctl.c
+++ b/minecctl/minecctl.c
@@ -21,39 +21,114 @@
#include "misc.h"
#include "config.h"
-static void dump_config(struct cfg *cfg)
+static void dump_server(struct server *server)
{
- /* FIXME: return unless debugging enabled */
- struct server *server;
struct saddr *saddr;
+ info("│");
+ info("│ ▷ server");
+ info("│ ┌─────");
+ info("│ │ name : %s", server->name);
+ info("│ │ file_read : %s", server->file_read ? "yes" : "no");
+ info("│ │ filename : %s", server->scfg.filename);
+
+ switch (server->scfg.type) {
+ case SERVER_TYPE_ANNOUNCE:
+ info("│ │ type : announce");
+ break;
+ case SERVER_TYPE_PROXY:
+ info("│ │ type : proxy");
+ break;
+ case SERVER_TYPE_UNDEFINED:
+ _fallthrough_;
+ default:
+ info("│ │ type : <unknown>");
+ break;
+ }
+
+ info("│ │ pretty_name : %s", server->scfg.pretty_name);
+ info("│ │ announce_port : %" PRIu16, server->scfg.announce_port);
+ info("│ │ idle_timeout : %u", server->scfg.idle_timeout);
+
+ switch (server->scfg.stop_method) {
+ case SERVER_STOP_METHOD_RCON:
+ info("│ │ stop_method : rcon");
+ break;
+ case SERVER_STOP_METHOD_SYSTEMD:
+ info("│ │ stop_method : systemd");
+ break;
+ case SERVER_STOP_METHOD_EXEC:
+ info("│ │ stop_method : exec");
+ break;
+ case SERVER_STOP_METHOD_UNDEFINED:
+ _fallthrough_;
+ default:
+ info("│ │ stop_method : <undefined>");
+ break;
+ }
+
+ switch (server->scfg.start_method) {
+ case SERVER_START_METHOD_SYSTEMD:
+ info("│ │ start_method : systemd");
+ break;
+ case SERVER_START_METHOD_EXEC:
+ info("│ │ start_method : exec");
+ break;
+ case SERVER_START_METHOD_UNDEFINED:
+ _fallthrough_;
+ default:
+ info("│ │ start_method : <undefined>");
+ break;
+ }
+
+ info("│ │ stop_exec : %s", server->scfg.stop_exec);
+ info("│ │ start_exec : %s", server->scfg.start_exec);
+ info("│ │ rcon_password : %s", server->scfg.rcon_password);
+ info("│ │ systemd_service : %s", server->scfg.systemd_service);
+ info("│ │ systemd_obj : %s", server->scfg.systemd_obj);
+
+ info("│ │ locals%s",
+ list_empty(&server->scfg.locals) ? " : none": "");
+ list_for_each_entry(saddr, &server->scfg.locals, list)
+ info("│ │ ⁃ %s", saddr->addrstr);
+
+ info("│ │ remotes%s",
+ list_empty(&server->scfg.remotes) ? " : none": "");
+ list_for_each_entry(saddr, &server->scfg.remotes, list)
+ info("│ │ ⁃ %s", saddr->addrstr);
+
+ info("│ │ rcons%s",
+ list_empty(&server->scfg.rcons) ? " : none": "");
+ list_for_each_entry(saddr, &server->scfg.rcons, list)
+ info("│ │ ⁃ %s", saddr->addrstr);
+ info("│ └─────");
+}
+
+void dump_config(struct cfg *cfg)
+{
+ struct server *server;
+
+ if (!(debug_mask & ~(DBG_ERROR | DBG_INFO | DBG_VERBOSE)))
+ return;
+
info("Configuration");
- info("=============");
- info("cfgdir : %s", cfg->cfgdir);
- info("rcon_password : %s", cfg->rcon_password);
- info("rcon_addrstr : %s", cfg->rcon_addrstr);
- info("mc_addrstr : %s", cfg->mc_addrstr);
+ info("┌────────────");
+ info("│ cfgdir : %s", cfg->cfgdir);
+ info("│ rcon_password : %s", cfg->rcon_password);
+ info("│ rcon_addrstr : %s", cfg->rcon_addrstr);
+ info("│ mc_addrstr : %s", cfg->mc_addrstr);
+ info("│ cmd : %p", cfg->cmd);
+ info("│ force stop : %s", cfg->force_stop ? "yes" : "no");
+ info("│ commands%s", cfg->commands ? "" : " : none");
if (cfg->commands) {
for (char *const *cmd = cfg->commands; *cmd; cmd++)
- info("command : %s", *cmd);
- }
- info("cmd : %p", cfg->cmd);
- info("force stop : %s", cfg->force_stop ? "yes" : "no");
-
- list_for_each_entry(server, &cfg->servers, list) {
- info(" * server");
- info(" name : %s", server->name);
- info(" filename : %s", server->scfg.filename);
- info(" rcon_password : %s", server->scfg.rcon_password);
- info(" file_read : %s",
- server->file_read ? "yes" : "no");
- list_for_each_entry(saddr, &server->scfg.rcons, list)
- info(" * rcon addr : %s", saddr->addrstr);
- list_for_each_entry(saddr, &server->scfg.remotes, list)
- info(" * mc addr : %s", saddr->addrstr);
+ info("│ ⁃ %s", *cmd);
}
- info("=============");
+ list_for_each_entry(server, &cfg->servers, list)
+ dump_server(server);
+
+ info("└────────────");
}
_noreturn_ static void usage(bool no_error)
@@ -72,6 +147,7 @@ _noreturn_ static void usage(bool no_error)
" (default: %s)\n"
" -f, --force stop server even if it has players\n"
" -v, --verbose enable extra logging\n"
+ " -d, --debug enable debugging information\n"
" -h, --help print this information\n"
"\n"
"Valid commands:\n"
@@ -301,14 +377,12 @@ static void parse_cmdline(struct cfg *cfg, int argc, char *const *argv)
assert_die(argc && argv && cfg, "invalid arguments");
if (argc < 2) {
- error("Missing options");
+ error("Missing arguments");
usage(false);
}
cfg->cfgdir = DEFAULT_CFG_DIR;
- /* FIXME: add debug option */
-
while (true) {
int option_index = 0;
/* clang-format off */
@@ -318,13 +392,14 @@ static void parse_cmdline(struct cfg *cfg, int argc, char *const *argv)
{ "mc-address", required_argument, 0, 'm' },
{ "cfgdir", required_argument, 0, 'c' },
{ "verbose", no_argument, 0, 'v' },
+ { "debug", no_argument, 0, 'd' },
{ "force", no_argument, 0, 'f' },
{ "help", no_argument, 0, 'h' },
{ 0, 0, 0, 0 }
};
/* clang-format on */
- c = getopt_long(argc, argv, ":p:r:m:c:vfh", long_options,
+ c = getopt_long(argc, argv, ":p:r:m:c:vdfh", long_options,
&option_index);
if (c == -1)
@@ -346,6 +421,9 @@ static void parse_cmdline(struct cfg *cfg, int argc, char *const *argv)
case 'v':
debug_mask |= DBG_VERBOSE;
break;
+ case 'd':
+ debug_mask = ~0;
+ break;
case 'f':
cfg->force_stop = true;
break;
@@ -402,8 +480,6 @@ int main(int argc, char *const *argv)
if (!create_server_from_cmdline_args(&cfg))
goto out;
- dump_config(&cfg);
-
success = cfg.cmd(&cfg);
out:
diff --git a/minecctl/minecctl.h b/minecctl/minecctl.h
index 898a93f..5025cc4 100644
--- a/minecctl/minecctl.h
+++ b/minecctl/minecctl.h
@@ -12,4 +12,6 @@ struct cfg {
struct list_head servers;
};
+void dump_config(struct cfg *cfg);
+
#endif
diff --git a/minecctl/misc-commands.c b/minecctl/misc-commands.c
index 28d9e3a..a880e15 100644
--- a/minecctl/misc-commands.c
+++ b/minecctl/misc-commands.c
@@ -91,6 +91,8 @@ bool do_lint(struct cfg *cfg)
info("");
+ dump_config(cfg);
+
ia = 0;
list_for_each_entry(a, &cfg->servers, list) {
ib = 0;