diff options
Diffstat (limited to 'minecctl/misc-commands.c')
-rw-r--r-- | minecctl/misc-commands.c | 102 |
1 files changed, 95 insertions, 7 deletions
diff --git a/minecctl/misc-commands.c b/minecctl/misc-commands.c index 8dd6bd2..28d9e3a 100644 --- a/minecctl/misc-commands.c +++ b/minecctl/misc-commands.c @@ -12,31 +12,119 @@ bool do_list(struct cfg *cfg) /* server->scfg.filename check excludes servers created from cmdline */ list_for_each_entry(server, &cfg->servers, list) if (server->scfg.filename) - info("%s", server->name); + info("• %s", server->name); return true; } +static bool saddr_match(struct list_head *la, struct list_head *lb) +{ + struct saddr *a, *b; + + list_for_each_entry(a, la, list) { + list_for_each_entry(b, lb, list) { + if (a->st.ss_family != b->st.ss_family) + continue; + + switch (a->st.ss_family) { + case AF_INET: + if (memcmp(&a->in4.sin_addr, + &b->in4.sin_addr, + sizeof(a->in4.sin_addr))) + continue; + if (a->in4.sin_port != b->in4.sin_port) + continue; + return true; + + case AF_INET6: + if (memcmp(&a->in6.sin6_addr, + &b->in6.sin6_addr, + sizeof(a->in6.sin6_addr))) + continue; + if (a->in6.sin6_port != b->in6.sin6_port) + continue; + return true; + + default: + continue; + } + } + } + + return false; +} + bool do_lint(struct cfg *cfg) { struct server *server; + unsigned lineno; const char *error; bool rv = true; + struct server *a, *b; + unsigned ia, ib; /* server->scfg.filename check excludes servers created from cmdline */ list_for_each_entry(server, &cfg->servers, list) { if (!server->scfg.filename) continue; - info("• %s", server->name); + if (!server_read_config(cfg, server, &lineno, &error)) { + if (lineno != 0) + info("• %s: %sfail%s - line %u: %s", + server->name, ansi_red, ansi_normal, + lineno, error); + else + info("• %s: %sfail%s - %s", + server->name, ansi_red, ansi_normal, + error); + rv = false; + } else if (!scfg_validate(&server->scfg, &error)) { + info("• %s: %sfail%s - %s", + server->name, ansi_red, ansi_normal, + error); + rv = false; + } else { + info("• %s: %sok%s", server->name, ansi_green, + ansi_normal); + } + } - /* FIXME: should return bool */ - server_read_config(cfg, server); + info(""); - if (!scfg_validate(&server->scfg, &error)) { - error("%s: invalid (%s)", server->name, error); - rv = false; + ia = 0; + list_for_each_entry(a, &cfg->servers, list) { + ib = 0; + list_for_each_entry(b, &cfg->servers, list) { + if (ib <= ia) { + ib++; + continue; + } + + if (a->scfg.announce_port != 0 && + b->scfg.announce_port != 0 && + a->scfg.announce_port == b->scfg.announce_port) + info("%sNote:%s %s and %s appear to have the " + "same announce port", ansi_red, + ansi_normal, a->name, b->name); + + if (saddr_match(&a->scfg.locals, &b->scfg.locals)) + info("%sNote:%s %s and %s appear to share at " + "least one local address/port pair", + ansi_red, ansi_normal, a->name, b->name); + + if (saddr_match(&a->scfg.remotes, &b->scfg.remotes)) + info("%sNote:%s %s and %s appear to share at " + "least one remote address/port pair", + ansi_red, ansi_normal, a->name, b->name); + + if (saddr_match(&a->scfg.rcons, &b->scfg.rcons)) + info("%sNote:%s %s and %s appear to share at " + "least one rcon address/port pair", + ansi_red, ansi_normal, a->name, b->name); + + ib++; } + ia++; } return rv; |