summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 97fa322)
raw | patch | inline | side by side (parent: 97fa322)
author | fgsfds <pvt.fgsfds@gmail.com> | |
Thu, 1 Jun 2023 22:19:01 +0000 (22:19 +0000) | ||
committer | Dmitry D. Chernov <blackdoomer@yandex.ru> | |
Sat, 3 Jun 2023 21:58:37 +0000 (07:58 +1000) |
src/mastersrv/master.c | patch | blob | history |
diff --git a/src/mastersrv/master.c b/src/mastersrv/master.c
index 2ea5016bbf538ba65ee5da1e0f7679c5610894bf..9b48afc9a4f091803ac449ab87f0dbd6fca59adf 100644 (file)
--- a/src/mastersrv/master.c
+++ b/src/mastersrv/master.c
#include <ctype.h>
#include <string.h>
#include <time.h>
-#include <errno.h>
+#include <signal.h>
#include <enet/enet.h>
#include <enet/types.h>
@@ -469,6 +469,16 @@ static ban_record_t *ban_record_add_ip(const char *ip, const int cnt, const time
return ban_record_add_addr(addr.host, mask, cnt, cur);
}
+static void ban_free_list(void) {
+ ban_record_t *rec = banlist;
+ while (rec) {
+ ban_record_t *next = rec->next;
+ free(rec);
+ rec = next;
+ }
+ banlist = NULL;
+}
+
static void ban_load_list(const char *fname) {
FILE *f = fopen(fname, "r");
if (!f) {
static void deinit(void) {
// ban_save_list(MS_BAN_FILE);
+ ban_free_list();
if (ms_host) {
enet_host_destroy(ms_host);
ms_host = NULL;
enet_deinitialize();
}
+#ifdef SIGUSR1
+static void sigusr_handler(int signum) {
+ if (signum == SIGUSR1) {
+ u_log(LOG_WARN, "received SIGUSR1, reloading banlist");
+ ban_free_list();
+ ban_load_list(MS_BAN_FILE);
+ }
+}
+#endif
+
static bool handle_msg(const enet_uint8 msgid, ENetPeer *peer) {
server_t *sv = NULL;
server_t tmpsv = { 0 };
atexit(deinit);
+#ifdef SIGUSR1
+ signal(SIGUSR1, sigusr_handler);
+#endif
+
ENetAddress addr;
addr.host = 0;
addr.port = ms_port;