summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
Diffstat (limited to 'shared')
-rw-r--r--shared/config-parser.c76
-rw-r--r--shared/config-parser.h3
2 files changed, 76 insertions, 3 deletions
diff --git a/shared/config-parser.c b/shared/config-parser.c
index ea800ad..8ea6557 100644
--- a/shared/config-parser.c
+++ b/shared/config-parser.c
@@ -13,6 +13,7 @@
#include "utils.h"
#include "config-parser.h"
#include "server-config-options.h"
+#include "server-properties-options.h"
#include "config.h"
static bool handle_addrinfo_results(struct addrinfo *results,
@@ -246,11 +247,8 @@ bool scfg_validate(struct server_config *scfg, const char **error)
if (list_empty(&scfg->locals))
ERROR("missing local addresses for proxy server");
- /* FIXME: Reinstate once server.properties parsing is implemented */
- /*
if (list_empty(&scfg->remotes))
ERROR("missing remote addresses for proxy server");
- */
list_for_each_entry(saddr, &scfg->locals, list) {
port = saddr_port(saddr);
@@ -325,6 +323,78 @@ static char *systemd_object_path(const char *service)
return r;
}
+void sprop_parse(struct server_config *scfg, char *buf,
+ unsigned *lineno, const char **error)
+{
+ char *pos = buf;
+
+ assert_return(scfg && buf && lineno && error);
+
+ *lineno = 0;
+
+ while (true) {
+ int key;
+ const char *keyname;
+ struct cfg_value value;
+
+ if (!config_parse_line("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");
+
+ if (!list_empty(&scfg->remotes)) {
+ error("mc server address set both in %s and "
+ "server.properties", scfg->filename);
+ break;
+ }
+
+ scfg_queue_dns(scfg, &value, &scfg->remotes, false);
+
+ break;
+
+ case SPROP_KEY_RCON_PORT:
+ debug(DBG_CFG, "found rcon port in "
+ "server.properties");
+
+ if (!list_empty(&scfg->rcons)) {
+ error("rcon address set both in %s and "
+ "server.properties", scfg->filename);
+ break;
+ }
+
+ scfg_queue_dns(scfg, &value, &scfg->rcons, false);
+
+ break;
+
+ case SPROP_KEY_RCON_PASSWORD:
+ debug(DBG_CFG, "found rcon password in "
+ "server.properties");
+
+ if (scfg->rcon_password) {
+ error("rcon password set both in %s and "
+ "server.properties (%smatching)",
+ scfg->filename,
+ streq(scfg->rcon_password, value.str) ?
+ "" : "not");
+ break;
+ }
+
+ scfg->rcon_password = xstrdup(value.str);
+ break;
+
+ case SPROP_KEY_INVALID:
+ _fallthrough_;
+ default:
+ break;
+ }
+ }
+}
+
bool scfg_parse(struct server_config *scfg, char *buf, bool async,
unsigned *lineno, const char **error)
{
diff --git a/shared/config-parser.h b/shared/config-parser.h
index 129e085..da5250d 100644
--- a/shared/config-parser.h
+++ b/shared/config-parser.h
@@ -99,6 +99,9 @@ bool scfg_async_dns_start(struct server_config *scfg);
bool scfg_validate(struct server_config *scfg, const char **error);
+void sprop_parse(struct server_config *scfg, char *buf,
+ unsigned *lineno, const char **error);
+
bool scfg_parse(struct server_config *scfg, char *buf, bool async,
unsigned *lineno, const char **error);