diff options
-rw-r--r-- | config.h.in | 23 | ||||
-rw-r--r-- | examples/example.minecserver (renamed from examples/example.mcserver) | 2 | ||||
-rw-r--r-- | examples/meson.build | 2 | ||||
-rw-r--r-- | examples/minecproxy.conf | 13 | ||||
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | minecctl/misc-commands.c | 18 | ||||
-rw-r--r-- | minecctl/server.c | 2 | ||||
-rw-r--r-- | minecproxy/main.c | 87 | ||||
-rw-r--r-- | minecproxy/minecproxy-config-options.h | 77 | ||||
-rw-r--r-- | minecproxy/server-config.c | 2 | ||||
-rw-r--r-- | shared/config-parser.c | 20 |
11 files changed, 138 insertions, 110 deletions
diff --git a/config.h.in b/config.h.in index e9bb485..9c485ee 100644 --- a/config.h.in +++ b/config.h.in @@ -7,8 +7,6 @@ #define DEFAULT_DATA_DIR @DEFAULT_DATA_DIR@ -#define DEFAULT_MAIN_CFG_FILE @DEFAULT_MAIN_CFG_FILE@ - #define VERSION @VERSION@ #define DEFAULT_ANNOUNCE_INTERVAL 3 @@ -27,11 +25,26 @@ #define DEFAULT_SOCKET_NODELAY true -#define SERVER_CONFIG_FILE_SUFFIX "mcserver" +#define MINECPROXY_CFG_FILE "minecproxy.conf" + +#define MINECPROXY_CFG_HEADER "minecproxy" + +#define MINECPROXY_SYSTEMD_SERVICE "minecproxy.service" + +#define MINECCTL_CFG_FILE "minecctl.conf" + +#define MINECCTL_CFG_HEADER "minecctl" + +#define SERVER_CONFIG_FILE_HEADER "minecserver" + +#define SERVER_CONFIG_FILE_SUFFIX "minecserver" + +#define SERVER_SYSTEMD_SERVICE "minecserver@.service" -#define SYSTEMD_DBUS_SERVICE "org.freedesktop.systemd1" +#define SYSTEMD_DBUS_SERVICE "org.freedesktop.systemd1" -#define SYSTEMD_DBUS_INTERFACE "org.freedesktop.systemd1.Unit" +#define SYSTEMD_DBUS_INTERFACE "org.freedesktop.systemd1.Unit" #define SYSTEMD_DBUS_PATH_PREFIX "/org/freedesktop/systemd1/unit/" +#define MC_SERVER_PROPERTIES "server.properties" diff --git a/examples/example.mcserver b/examples/example.minecserver index ea7f9bd..9cd9c9d 100644 --- a/examples/example.mcserver +++ b/examples/example.minecserver @@ -1,4 +1,4 @@ -[server] +[minecserver] type = proxy name = Example Server local = 20003 diff --git a/examples/meson.build b/examples/meson.build index 67ddf01..bad1b4a 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -26,7 +26,7 @@ foreach xxd_file: xxd_files endforeach install_files = [ - 'example.mcserver', + 'example.minecserver', 'minecctl.conf', 'minecproxy.conf', 'minecproxy.service', diff --git a/examples/minecproxy.conf b/examples/minecproxy.conf index b17d8ef..3950da7 100644 --- a/examples/minecproxy.conf +++ b/examples/minecproxy.conf @@ -1 +1,12 @@ -This is the minecproxy conf example +[minecproxy] +#These are the default values +#igmp = no +#igmp_iface = +#announce_interval = 3 +#proxy_connection_interval = 3 +#proxy_connection_attempts = 20 +#socket_defer = true +#socket_freebind = true +#socket_keepalive = true +#socket_iptos = true +#socket_nodelay = true diff --git a/meson.build b/meson.build index 725aba8..9f1cbc5 100644 --- a/meson.build +++ b/meson.build @@ -41,13 +41,11 @@ add_project_link_arguments(ld_flags, language: 'c') sysconfdir = join_paths(get_option('sysconfdir'), meson.project_name()) localstatedir = join_paths(get_option('prefix'), get_option('sharedstatedir'), meson.project_name()) -mainconfname = meson.project_name() + '.conf' conf = configuration_data() conf.set_quoted('VERSION', '@0@-@VCS_TAG@'.format(meson.project_version())) conf.set_quoted('DEFAULT_CFG_DIR', sysconfdir) conf.set_quoted('DEFAULT_DATA_DIR', localstatedir) -conf.set_quoted('DEFAULT_MAIN_CFG_FILE', mainconfname) inc_config_h = include_directories('.') dep_config_h = declare_dependency( diff --git a/minecctl/misc-commands.c b/minecctl/misc-commands.c index 3ad9792..752b0e9 100644 --- a/minecctl/misc-commands.c +++ b/minecctl/misc-commands.c @@ -171,7 +171,7 @@ static bool write_server_cfg(struct cfg *cfg, const char *name, ___examples_eula_txt_len)) return false; - if (!write_cfg_file(sfd, "server.properties", + if (!write_cfg_file(sfd, MC_SERVER_PROPERTIES, properties, properties_len)) return false; @@ -196,22 +196,22 @@ bool do_init(_unused_ struct cfg *cfg) if (mcfd < 0) return false; - if (!write_cfg_file(mcfd, "minecproxy.conf", + if (!write_cfg_file(mcfd, MINECPROXY_CFG_FILE, ___examples_minecproxy_conf, ___examples_minecproxy_conf_len)) return false; - if (!write_cfg_file(mcfd, "minecctl.conf", + if (!write_cfg_file(mcfd, MINECCTL_CFG_FILE, ___examples_minecctl_conf, ___examples_minecctl_conf_len)) return false; - if (!create_user_service(xcfd, "minecserver@.service", + if (!create_user_service(xcfd, SERVER_SYSTEMD_SERVICE, ___examples_minecserver__service, ___examples_minecserver__service_len)) return false; - if (!create_user_service(xcfd, "minecproxy.service", + if (!create_user_service(xcfd, MINECPROXY_SYSTEMD_SERVICE, ___examples_minecproxy_service, ___examples_minecproxy_service_len)) return false; @@ -309,14 +309,14 @@ static unsigned char *create_mc_server(const char *name, uint16_t local_port, /* FIXME: Add comments, commented out options */ mcserver = xsprintf(len, - "[server]\n" + "[%s]\n" "type = proxy\n" "name = %s\n" "local = %" PRIu16 "\n" "idle_timeout = 600\n" "start_method = systemd\n" "stop_method = systemd\n", - name, local_port); + SERVER_CONFIG_FILE_HEADER, name, local_port); if (!mcserver) error("xsprintf: %m"); @@ -487,8 +487,8 @@ bool do_new(struct cfg *cfg) if (!valid_name(name)) return false; - char filename[strlen(name) + STRLEN(".mcserver") + 1]; - sprintf(filename, "%s.mcserver", name); + char filename[strlen(name) + STRLEN(".") + STRLEN(SERVER_CONFIG_FILE_SUFFIX) + 1]; + sprintf(filename, "%s.%s", name, SERVER_CONFIG_FILE_SUFFIX); if (!server_read_all_configs(cfg, false)) { error("Failed to read all existing server configurations, " diff --git a/minecctl/server.c b/minecctl/server.c index e50e10c..979f85e 100644 --- a/minecctl/server.c +++ b/minecctl/server.c @@ -117,7 +117,7 @@ bool server_read_config(struct cfg *cfg, struct server *server, if (dfd < 0) goto out; - if (!read_file(dfd, "server.properties", buf, sizeof(buf), + if (!read_file(dfd, MC_SERVER_PROPERTIES, buf, sizeof(buf), error)) goto out; diff --git a/minecproxy/main.c b/minecproxy/main.c index 7e17369..92065cc 100644 --- a/minecproxy/main.c +++ b/minecproxy/main.c @@ -29,6 +29,7 @@ #include "idle.h" #include "ptimer.h" #include "config.h" +#include "minecproxy-config-options.h" /* Global */ struct cfg *cfg = NULL; @@ -196,78 +197,6 @@ static void cfg_free(struct uring_task *task) /* The cfg struct is free:d in main() */ } -enum mcfg_keys { - MCFG_KEY_INVALID = 0, - MCFG_KEY_IGMP, - MCFG_KEY_IGMP_IFACE, - MCFG_KEY_ANNOUNCE_INTERVAL, - MCFG_KEY_PROXY_CONN_INTERVAL, - MCFG_KEY_PROXY_CONN_ATTEMPTS, - MCFG_KEY_SOCKET_DEFER, - MCFG_KEY_SOCKET_FREEBIND, - MCFG_KEY_SOCKET_KEEPALIVE, - MCFG_KEY_SOCKET_IPTOS, - MCFG_KEY_SOCKET_NODELAY, -}; - -struct cfg_key_value_map mcfg_key_map[] = { - { - .key_name = "igmp", - .key_value = MCFG_KEY_IGMP, - .value_type = CFG_VAL_TYPE_BOOL, - }, - { - .key_name = "igmp_iface", - .key_value = MCFG_KEY_IGMP_IFACE, - .value_type = CFG_VAL_TYPE_STRING, - }, - { - .key_name = "announce_interval", - .key_value = MCFG_KEY_ANNOUNCE_INTERVAL, - .value_type = CFG_VAL_TYPE_UINT16, - }, - { - .key_name = "proxy_connection_interval", - .key_value = MCFG_KEY_PROXY_CONN_INTERVAL, - .value_type = CFG_VAL_TYPE_UINT16, - }, - { - .key_name = "proxy_connection_attempts", - .key_value = MCFG_KEY_PROXY_CONN_ATTEMPTS, - .value_type = CFG_VAL_TYPE_UINT16, - }, - { - .key_name = "socket_defer", - .key_value = MCFG_KEY_SOCKET_DEFER, - .value_type = CFG_VAL_TYPE_BOOL, - }, - { - .key_name = "socket_freebind", - .key_value = MCFG_KEY_SOCKET_FREEBIND, - .value_type = CFG_VAL_TYPE_BOOL, - }, - { - .key_name = "socket_keepalive", - .key_value = MCFG_KEY_SOCKET_KEEPALIVE, - .value_type = CFG_VAL_TYPE_BOOL, - }, - { - .key_name = "socket_iptos", - .key_value = MCFG_KEY_SOCKET_IPTOS, - .value_type = CFG_VAL_TYPE_BOOL, - }, - { - .key_name = "socket_nodelay", - .key_value = MCFG_KEY_SOCKET_NODELAY, - .value_type = CFG_VAL_TYPE_BOOL, - }, - { - .key_name = NULL, - .key_value = MCFG_KEY_INVALID, - .value_type = CFG_VAL_TYPE_INVALID, - } -}; - static void cfg_read() { char buf[4096]; @@ -280,7 +209,7 @@ static void cfg_read() assert_return(cfg); - fd = openat(dirfd(cfg->cfg_dir), DEFAULT_MAIN_CFG_FILE, + fd = openat(dirfd(cfg->cfg_dir), MINECPROXY_CFG_FILE, O_RDONLY | O_CLOEXEC | O_NOCTTY); if (fd < 0) return; @@ -291,7 +220,7 @@ static void cfg_read() fd = -1; debug(DBG_CFG, "opened main config file %s/%s", cfg->cfg_real_path, - DEFAULT_MAIN_CFG_FILE); + MINECPROXY_CFG_FILE); for (off = 0; off < sizeof(buf); off += r) { r = fread(buf + off, 1, sizeof(buf) - off, cfgfile); @@ -301,14 +230,14 @@ static void cfg_read() if (off >= sizeof(buf) - 1) die("main config file %s/%s too large", cfg->cfg_real_path, - DEFAULT_MAIN_CFG_FILE); + MINECPROXY_CFG_FILE); buf[off] = '\0'; pos = buf; - if (!config_parse_header("mcproxy", &pos, &lineno)) + if (!config_parse_header(MINECPROXY_CFG_HEADER, &pos, &lineno)) die("main config file %s/%s missing/invalid header", - cfg->cfg_real_path, DEFAULT_MAIN_CFG_FILE); + cfg->cfg_real_path, MINECPROXY_CFG_FILE); while (true) { int key; @@ -316,14 +245,14 @@ static void cfg_read() struct cfg_value value; const char *error; - if (!config_parse_line(DEFAULT_MAIN_CFG_FILE, &pos, + if (!config_parse_line(MINECPROXY_CFG_FILE, &pos, mcfg_key_map, &key, &keyname, &value, false, &lineno, &error)) break; if (key == MCFG_KEY_INVALID) die("main config file %s/%s invalid: line %u: %s", - cfg->cfg_real_path, DEFAULT_MAIN_CFG_FILE, lineno, + cfg->cfg_real_path, MINECPROXY_CFG_FILE, lineno, error); debug(DBG_CFG, "main cfg: key %s", keyname); diff --git a/minecproxy/minecproxy-config-options.h b/minecproxy/minecproxy-config-options.h new file mode 100644 index 0000000..5107f27 --- /dev/null +++ b/minecproxy/minecproxy-config-options.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef foominecproxyconfigoptionshfoo +#define foominecproxyconfigoptionshfoo + +enum mcfg_keys { + MCFG_KEY_INVALID = 0, + MCFG_KEY_IGMP, + MCFG_KEY_IGMP_IFACE, + MCFG_KEY_ANNOUNCE_INTERVAL, + MCFG_KEY_PROXY_CONN_INTERVAL, + MCFG_KEY_PROXY_CONN_ATTEMPTS, + MCFG_KEY_SOCKET_DEFER, + MCFG_KEY_SOCKET_FREEBIND, + MCFG_KEY_SOCKET_KEEPALIVE, + MCFG_KEY_SOCKET_IPTOS, + MCFG_KEY_SOCKET_NODELAY, +}; + +struct cfg_key_value_map mcfg_key_map[] = { + { + .key_name = "igmp", + .key_value = MCFG_KEY_IGMP, + .value_type = CFG_VAL_TYPE_BOOL, + }, + { + .key_name = "igmp_iface", + .key_value = MCFG_KEY_IGMP_IFACE, + .value_type = CFG_VAL_TYPE_STRING, + }, + { + .key_name = "announce_interval", + .key_value = MCFG_KEY_ANNOUNCE_INTERVAL, + .value_type = CFG_VAL_TYPE_UINT16, + }, + { + .key_name = "proxy_connection_interval", + .key_value = MCFG_KEY_PROXY_CONN_INTERVAL, + .value_type = CFG_VAL_TYPE_UINT16, + }, + { + .key_name = "proxy_connection_attempts", + .key_value = MCFG_KEY_PROXY_CONN_ATTEMPTS, + .value_type = CFG_VAL_TYPE_UINT16, + }, + { + .key_name = "socket_defer", + .key_value = MCFG_KEY_SOCKET_DEFER, + .value_type = CFG_VAL_TYPE_BOOL, + }, + { + .key_name = "socket_freebind", + .key_value = MCFG_KEY_SOCKET_FREEBIND, + .value_type = CFG_VAL_TYPE_BOOL, + }, + { + .key_name = "socket_keepalive", + .key_value = MCFG_KEY_SOCKET_KEEPALIVE, + .value_type = CFG_VAL_TYPE_BOOL, + }, + { + .key_name = "socket_iptos", + .key_value = MCFG_KEY_SOCKET_IPTOS, + .value_type = CFG_VAL_TYPE_BOOL, + }, + { + .key_name = "socket_nodelay", + .key_value = MCFG_KEY_SOCKET_NODELAY, + .value_type = CFG_VAL_TYPE_BOOL, + }, + { + .key_name = NULL, + .key_value = MCFG_KEY_INVALID, + .value_type = CFG_VAL_TYPE_INVALID, + } +}; + +#endif diff --git a/minecproxy/server-config.c b/minecproxy/server-config.c index baf47fb..4e77716 100644 --- a/minecproxy/server-config.c +++ b/minecproxy/server-config.c @@ -111,7 +111,7 @@ static void server_cfg_read_cb(struct uring_task *task, int res) return; } - sprop = xstrcat(server->scfg.name, "/server.properties", NULL); + sprop = xstrcat(server->scfg.name, "/" MC_SERVER_PROPERTIES, NULL); if (!sprop) { error("%s: xstrcat %m", server->scfg.name); server_delete(server); diff --git a/shared/config-parser.c b/shared/config-parser.c index 8cb6dcd..00f9944 100644 --- a/shared/config-parser.c +++ b/shared/config-parser.c @@ -339,19 +339,19 @@ void sprop_parse(struct server_config *scfg, char *buf, const char *keyname; struct cfg_value value; - if (!config_parse_line("server.properties", &pos, sprop_key_map, - &key, &keyname, &value, false, lineno, - error)) + if (!config_parse_line(MC_SERVER_PROPERTIES, &pos, + sprop_key_map, &key, &keyname, &value, + false, lineno, error)) break; switch (key) { case SPROP_KEY_SERVER_PORT: debug(DBG_CFG, "found remote server port in " - "server.properties"); + MC_SERVER_PROPERTIES); if (!list_empty(&scfg->remotes)) { error("mc server address set both in %s and " - "server.properties", scfg->filename); + MC_SERVER_PROPERTIES, scfg->filename); break; } @@ -361,11 +361,11 @@ void sprop_parse(struct server_config *scfg, char *buf, case SPROP_KEY_RCON_PORT: debug(DBG_CFG, "found rcon port in " - "server.properties"); + MC_SERVER_PROPERTIES); if (!list_empty(&scfg->rcons)) { error("rcon address set both in %s and " - "server.properties", scfg->filename); + MC_SERVER_PROPERTIES, scfg->filename); break; } @@ -375,11 +375,11 @@ void sprop_parse(struct server_config *scfg, char *buf, case SPROP_KEY_RCON_PASSWORD: debug(DBG_CFG, "found rcon password in " - "server.properties"); + MC_SERVER_PROPERTIES); if (scfg->rcon_password) { error("rcon password set both in %s and " - "server.properties (%smatching)", + MC_SERVER_PROPERTIES " (%smatching)", scfg->filename, streq(scfg->rcon_password, value.str) ? "" : "not"); @@ -406,7 +406,7 @@ bool scfg_parse(struct server_config *scfg, char *buf, bool async, *lineno = 0; - if (!config_parse_header(SERVER_CFG_HEADER, &pos, lineno)) + if (!config_parse_header(SERVER_CONFIG_FILE_HEADER, &pos, lineno)) ERROR("missing/invalid header"); while (true) { |