From 09f1abfe18258807c412bce88ad459984add0cd3 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Tue, 9 Jun 2020 20:51:44 +0200 Subject: Add an rcon shutdown method --- server.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'server.c') 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 : ""); 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) @@ -422,6 +433,24 @@ server_add_local(struct cfg *cfg, struct server *scfg, struct sockaddr_in46 *add return true; } +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)); -- cgit v1.2.3