diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-11-29 16:00:17 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-11-29 16:00:55 +0300 |
commit | 60833f07d7d563092570dbfdffaf1876921711d1 (patch) | |
tree | b2303e729ff13f7d0f936a03f6e5620e74723395 | |
parent | aa3110d092a545c027a4c568a9158e7c1210d547 (diff) | |
download | evol-hercules-60833f07d7d563092570dbfdffaf1876921711d1.tar.gz evol-hercules-60833f07d7d563092570dbfdffaf1876921711d1.tar.bz2 evol-hercules-60833f07d7d563092570dbfdffaf1876921711d1.tar.xz evol-hercules-60833f07d7d563092570dbfdffaf1876921711d1.zip |
char: add ability to filter inter servers connections by ip
New config option: inter_server_ip
Example:
inter_server_ip 127.0.0.1,127.0.0.2
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/char/char.c | 32 | ||||
-rw-r--r-- | src/char/char.h | 9 | ||||
-rw-r--r-- | src/char/config.c | 35 | ||||
-rw-r--r-- | src/char/config.h | 12 | ||||
-rw-r--r-- | src/char/init.c | 9 |
6 files changed, 100 insertions, 3 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7ed1330..896fb9b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,10 @@ AUTOMAKE_OPTIONS = subdir-objects -CHAR_SRC = char/init.c \ +CHAR_SRC = char/char.c \ + char/char.h \ + char/config.c \ + char/config.h \ + char/init.c \ common/interfaces.c \ common/interfaces.h diff --git a/src/char/char.c b/src/char/char.c new file mode 100644 index 0000000..fc9dd2d --- /dev/null +++ b/src/char/char.c @@ -0,0 +1,32 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "../../../common/HPMi.h" +#include "../../../common/malloc.h" +#include "../../../common/mmo.h" +#include "../../../common/socket.h" +#include "../../../common/strlib.h" +#include "../../../char/char.h" + +#include "char/char.h" +#include "char/config.h" + +void echar_parse_char_login_map_server(int *fd) +{ + if (!inter_server_ip) + return; + + const uint32 ipl = session[*fd]->client_addr; + + const char *const ip = ip2str(ipl, NULL); + if (!strstr(inter_server_ip, ip)) + { + hookStop(); + ShowNotice("Connection of the map-server from ip %s REFUSED.\n", ip); + chr->login_map_server_ack(*fd, 3); + } +} diff --git a/src/char/char.h b/src/char/char.h new file mode 100644 index 0000000..f1be161 --- /dev/null +++ b/src/char/char.h @@ -0,0 +1,9 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_CHAR_CHAR +#define EVOL_CHAR_CHAR + +void echar_parse_char_login_map_server(int *fd); + +#endif // EVOL_CHAR_CHAR diff --git a/src/char/config.c b/src/char/config.c new file mode 100644 index 0000000..5eefbc1 --- /dev/null +++ b/src/char/config.c @@ -0,0 +1,35 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "../../../common/HPMi.h" +#include "../../../common/malloc.h" +#include "../../../common/mmo.h" +#include "../../../common/socket.h" +#include "../../../common/strlib.h" + +#include "char/config.h" + +char *inter_server_ip = NULL; + +void config_inter_server_ip(const char *val) +{ + char buf[1000]; + + if (strlen(val) > 900) + return; + + strcpy(buf, ","); + strcat(buf, val); + strcat(buf, ","); + inter_server_ip = aStrdup(buf); +} + +void config_final(void) +{ + if (inter_server_ip) + aFree(inter_server_ip); +} diff --git a/src/char/config.h b/src/char/config.h new file mode 100644 index 0000000..930c293 --- /dev/null +++ b/src/char/config.h @@ -0,0 +1,12 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_CHAR_CONFIG +#define EVOL_CHAR_CONFIG + +void config_final(void); +void config_inter_server_ip(const char *val); + +extern char *inter_server_ip; + +#endif // EVOL_CHAR_CONFIG diff --git a/src/char/init.c b/src/char/init.c index bfe7097..639c19b 100644 --- a/src/char/init.c +++ b/src/char/init.c @@ -27,6 +27,8 @@ #include "../../../char/mapif.h" #include "common/interfaces.h" +#include "char/char.h" +#include "char/config.h" #include "../../../common/HPMDataCheck.h" /* should always be the last file included! (if you don't make it last, it'll intentionally break compile time) */ @@ -40,8 +42,6 @@ HPExport struct hplugin_info pinfo = HPExport void plugin_init (void) { - interfaces_init_common(); - chr = GET_SYMBOL("chr"); geoip = GET_SYMBOL("geoip"); inter_auction = GET_SYMBOL("inter_auction"); @@ -57,10 +57,15 @@ HPExport void plugin_init (void) inter = GET_SYMBOL("inter"); loginif = GET_SYMBOL("loginif"); mapif = GET_SYMBOL("mapif"); + + addHookPre("chr->parse_char_login_map_server", echar_parse_char_login_map_server); } HPExport void server_preinit (void) { + interfaces_init_common(); + + addCharInterConf("inter_server_ip", config_inter_server_ip); } HPExport void server_online (void) |