summaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-09 20:51:44 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-09 20:51:44 +0200
commit09f1abfe18258807c412bce88ad459984add0cd3 (patch)
treeccbd07eabfb4c1a08de912d2dd0d09678cca090f /server.c
parent5fd0055aee5124b9ad6573e5ed363d5bf63bcf80 (diff)
Add an rcon shutdown method
Diffstat (limited to 'server.c')
-rw-r--r--server.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/server.c b/server.c
index 5cac0a6..c3bb433 100644
--- a/server.c
+++ b/server.c
@@ -13,6 +13,7 @@
#include "proxy.h"
#include "utils.h"
#include "idle.h"
+#include "rcon.h"
struct server_local {
struct sockaddr_in46 addr;
@@ -75,6 +76,7 @@ server_delete(struct cfg *cfg, struct server *scfg)
fprintf(stderr, "Removing server cfg: %s\n", scfg->name);
idle_delete(cfg, scfg);
+ rcon_delete(cfg, scfg);
list_for_each_entry_safe(remote, rtmp, &scfg->remotes, list) {
list_del(&remote->list);
@@ -125,12 +127,15 @@ server_dump(struct server *scfg)
}
fprintf(stderr, " * Pretty name: %s\n", scfg->pretty_name ? scfg->pretty_name : "<undefined>");
fprintf(stderr, " * Announce port: %" PRIu16 "\n", scfg->announce_port);
- fprintf(stderr, " * Listening ports:\n");
+ fprintf(stderr, " * Listening:\n");
list_for_each_entry(local, &scfg->locals, list)
fprintf(stderr, " * %s\n", local->addrstr);
- fprintf(stderr, " * Remote ports:\n");
+ fprintf(stderr, " * Remote:\n");
list_for_each_entry(remote, &scfg->remotes, list)
fprintf(stderr, " * %s\n", sockaddr_to_str(remote, abuf, sizeof(abuf)));
+ fprintf(stderr, " * RCon:\n");
+ list_for_each_entry(remote, &scfg->rcons, list)
+ fprintf(stderr, " * %s\n", sockaddr_to_str(remote, abuf, sizeof(abuf)));
}
static void
@@ -271,7 +276,6 @@ server_start(struct cfg *cfg, struct server *scfg)
switch (scfg->start_method) {
case SERVER_START_METHOD_EXEC:
-
return exec_cmd(cfg, scfg, scfg->start_exec);
case SERVER_START_METHOD_UNDEFINED:
@@ -291,9 +295,12 @@ server_stop(struct cfg *cfg, struct server *scfg)
switch (scfg->stop_method) {
case SERVER_STOP_METHOD_EXEC:
-
return exec_cmd(cfg, scfg, scfg->stop_exec);
+ case SERVER_STOP_METHOD_RCON:
+ rcon_init(cfg, scfg);
+ return true;
+
case SERVER_STOP_METHOD_UNDEFINED:
default:
break;
@@ -316,6 +323,10 @@ server_commit(struct cfg *cfg, struct server *scfg)
/* FIXME: running? */
+ if (scfg->stop_method == SERVER_STOP_METHOD_RCON &&
+ (list_empty(&scfg->rcons) || !scfg->rcon_password))
+ return false;
+
switch (scfg->type) {
case SERVER_TYPE_ANNOUNCE:
if (scfg->announce_port < 1)
@@ -423,6 +434,24 @@ server_add_local(struct cfg *cfg, struct server *scfg, struct sockaddr_in46 *add
}
bool
+server_add_rcon(struct cfg *cfg, struct server *scfg,
+ struct sockaddr_in46 *addr)
+{
+ if (!scfg || !addr)
+ return false;
+
+ list_add(&addr->list, &scfg->rcons);
+ return true;
+}
+
+bool
+server_set_rcon_password(struct cfg *cfg, struct server *scfg,
+ const char *password)
+{
+ return set_property(cfg, scfg, &scfg->rcon_password, password);
+}
+
+bool
server_set_stop_method(struct cfg *cfg, struct server *scfg,
enum server_stop_method stop_method)
{
@@ -532,6 +561,7 @@ server_new(struct cfg *cfg, const char *name)
list_init(&scfg->remotes);
list_init(&scfg->locals);
list_init(&scfg->proxys);
+ list_init(&scfg->rcons);
memset(&scfg->mcast_iov, 0, sizeof(scfg->mcast_iov));
scfg->mcast_iov.iov_base = scfg->mcast_buf;
memset(&scfg->mcast_msg, 0, sizeof(scfg->mcast_msg));