diff options
Diffstat (limited to 'minecproxy')
-rw-r--r-- | minecproxy/server.c | 141 |
1 files changed, 8 insertions, 133 deletions
diff --git a/minecproxy/server.c b/minecproxy/server.c index 81d148b..a2f8332 100644 --- a/minecproxy/server.c +++ b/minecproxy/server.c @@ -17,6 +17,7 @@ #include "server-config.h" #include "server-proxy.h" #include "server-rcon.h" +#include "config-parser.h" #include "idle.h" #include "systemd.h" @@ -422,7 +423,6 @@ bool server_announce(struct server *server, int fd) bool server_commit(struct server *server) { struct saddr *saddr, *tmp; - uint16_t port; int r; assert_return(server && server->name, false); @@ -439,143 +439,19 @@ bool server_commit(struct server *server) } if (!list_empty(&server->scfg.dnslookups)) { - debug(DBG_SRV, "called with pending DNS requests"); - return true; - } - - if (server->scfg.stop_method == SERVER_STOP_METHOD_RCON && - list_empty(&server->scfg.rcons)) { - error("%s: rcon stop method missing rcon address", + debug(DBG_SRV, "%s: called with pending DNS requests", server->name); - return false; - } - - if (server->scfg.stop_method == SERVER_STOP_METHOD_RCON && - !server->scfg.rcon_password) { - error("%s: rcon stop method missing rcon password", - server->name); - return false; - } - - if ((server->scfg.start_method == SERVER_START_METHOD_SYSTEMD || - server->scfg.stop_method == SERVER_STOP_METHOD_SYSTEMD) && - !server->scfg.systemd_service) { - error("%s: systemd start/stop method missing systemd service", - server->name); - return false; - } - - if ((server->scfg.systemd_service && !server->scfg.systemd_obj) || - (!server->scfg.systemd_service && server->scfg.systemd_obj)) { - error("%s: systemd service but no object path or vice versa", - server->name); - return false; - } - - if (server->scfg.idle_timeout > 0 && - server->scfg.stop_method == SERVER_STOP_METHOD_UNDEFINED) { - error("%s: idle_timeout set but missing stop method", - server->name); - return false; + return true; } - switch (server->scfg.type) { - case SERVER_TYPE_ANNOUNCE: - if (server->scfg.announce_port == 0) { - error("%s: missing announce port", server->name); - return false; - } - - if (server->scfg.start_method != SERVER_START_METHOD_UNDEFINED) { - error("%s: can't set start_method for announce server", - server->name); - return false; - } - - if (!list_empty(&server->scfg.locals)) { - error("%s: can't set local addresses for announce server", - server->name); - return false; - } - - if (!list_empty(&server->scfg.remotes)) { - error("%s: can't set remote addresses for announce server", - server->name); - return false; - } - - break; - - case SERVER_TYPE_PROXY: - if (server->scfg.announce_port == 0) { - error("%s: can't set announce port for proxy server", - server->name); - return false; - } - - if (list_empty(&server->scfg.locals)) { - error("%s: missing local addresses for proxy server", - server->name); - return false; - } - - if (list_empty(&server->scfg.remotes)) { - error("%s: missing remote addresses for proxy server", - server->name); - return false; - } - - list_for_each_entry(saddr, &server->scfg.locals, list) { - port = saddr_port(saddr); - - if (port == 0) { - error("%s: invalid local port", server->name); - return false; - } - - if (server->scfg.announce_port == 0) - server->scfg.announce_port = port; - - if (server->scfg.announce_port != port) { - error("%s: multiple local ports", server->name); - return false; - } - } - - if (server->scfg.announce_port == 0) { - error("%s: can't determine which port to announce", - server->name); - return false; - } - - break; - - default: - error("%s: can't determine server type", server->name); + if (!scfg_validate(&server->scfg)) { + debug(DBG_SRV, "%s: config file not valid", server->name); return false; } - if (!server->scfg.pretty_name) { - char *suffix; - - suffix = strrchr(server->name, '.'); - if (!suffix || suffix == server->name) { - error("invalid server name: %s", server->name); - return false; - } - - server->scfg.pretty_name = - xstrndup(server->name, suffix - server->name); - if (!server->scfg.pretty_name) { - error("failed to create display name: %s", - server->name); - return false; - } - } - r = snprintf(server->ann_buf.buf, sizeof(server->ann_buf.buf), "[MOTD]%s[/MOTD][AD]%" PRIu16 "[/AD]", - server->scfg.pretty_name, + server->scfg.pretty_name ? server->scfg.pretty_name : server->name, server->scfg.announce_port); if (r < 1 || r >= sizeof(server->ann_buf.buf)) { error("%s: unable to create announce msg: %i\n", server->name, @@ -584,8 +460,7 @@ bool server_commit(struct server *server) } server->ann_buf.len = r; - /* FIXME: config, dont reread config if server running, make sure fd is - * available before this is called */ + /* FIXME: check interactions with inotify */ server_dump(server); list_for_each_entry_safe(saddr, tmp, &server->scfg.locals, list) { @@ -602,7 +477,7 @@ bool server_commit(struct server *server) server_check_running(server); - debug(DBG_SRV, "success"); + debug(DBG_SRV, "%s: success", server->name); return true; } |