summaryrefslogtreecommitdiff
path: root/minecctl/misc-commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'minecctl/misc-commands.c')
-rw-r--r--minecctl/misc-commands.c63
1 files changed, 58 insertions, 5 deletions
diff --git a/minecctl/misc-commands.c b/minecctl/misc-commands.c
index f89afb6..1870e07 100644
--- a/minecctl/misc-commands.c
+++ b/minecctl/misc-commands.c
@@ -5,6 +5,7 @@
#include "misc-commands.h"
#include "rcon-commands.h"
#include "mc-commands.h"
+#include "shared/systemd.h"
bool do_list(struct cfg *cfg)
{
@@ -135,13 +136,65 @@ bool do_lint(struct cfg *cfg)
bool do_pcount(struct cfg *cfg)
{
- unsigned x, y;
+ unsigned online, max;
+ struct server *server;
+ const char *error;
+
+ server = server_get_default(cfg);
+ if (!server) {
+ error("failed to get default server");
+ return false;
+ }
- if (do_rcon_pcount(cfg, &y, &x))
- error("Rcon says %u/%u", y, x);
+ if (do_rcon_pcount(cfg, server, &online, &max, &error))
+ info("Rcon says %u/%u", online, max);
- if (do_mc_pcount(cfg, &y, &x))
- error("MC says %u/%u", y, x);
+ if (do_mc_pcount(cfg, server, &online, &max, &error))
+ info("MC says %u/%u", online, max);
return true;
}
+
+bool do_ping(struct cfg *cfg)
+{
+ struct server *server;
+ const char *error;
+ unsigned online, max;
+
+ /* FIXME: Do all servers when default not given */
+ server = server_get_default(cfg);
+ if (!server) {
+ error("failed to get default server");
+ return false;
+ }
+
+ info("• %s", server->name);
+
+ if (list_empty(&server->scfg.rcons))
+ info(" rcon : not configured");
+ else if (!do_rcon_pcount(cfg, server, &online, &max, &error))
+ info(" rcon : %sfail%s (%s)",
+ ansi_red, ansi_normal, error);
+ else
+ info(" rcon : %sok%s", ansi_green, ansi_normal);
+
+ if (list_empty(&server->scfg.remotes))
+ info(" mc : not configured");
+ else if (!do_mc_pcount(cfg, server, &online, &max, &error))
+ info(" mc : %sfail%s (%s)",
+ ansi_red, ansi_normal, error);
+ else
+ info(" mc : %sok%s", ansi_green, ansi_normal);
+
+ if (!server->scfg.systemd_service || !server->scfg.systemd_obj)
+ info(" systemd service : not configured");
+ else if (!systemd_service_running(&server->scfg, &error))
+ info(" systemd service : %sfail%s (%s)",
+ ansi_red, ansi_normal, error);
+ else
+ info(" systemd service : %sactive%s", ansi_green, ansi_normal);
+ systemd_delete();
+
+ return true;
+}
+