From 94366099f9019643c9e431a35af064283fab5a0c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 5 Nov 2018 23:37:03 +0300 Subject: Add interface for packets in common. For now supported only packet length fields. --- src/common/Makefile.in | 10 ++++---- src/common/core.c | 5 ++++ src/common/packets.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ src/common/packets.h | 47 +++++++++++++++++++++++++++++++++++ src/common/packets_len.h | 10 ++++---- 5 files changed, 126 insertions(+), 10 deletions(-) create mode 100644 src/common/packets.c create mode 100644 src/common/packets.h (limited to 'src/common') diff --git a/src/common/Makefile.in b/src/common/Makefile.in index 6ea7f5514..708780595 100644 --- a/src/common/Makefile.in +++ b/src/common/Makefile.in @@ -38,8 +38,8 @@ MT19937AR_OBJ = $(MT19937AR_D)/mt19937ar.o MT19937AR_H = $(MT19937AR_D)/mt19937ar.h COMMON_SHARED_C = conf.c db.c des.c ers.c grfio.c HPM.c mapindex.c md5calc.c \ - mutex.c nullpo.c random.c showmsg.c strlib.c sysinfo.c \ - thread.c timer.c utils.c + mutex.c nullpo.c packets.c random.c showmsg.c strlib.c \ + sysinfo.c thread.c timer.c utils.c COMMON_C = $(COMMON_SHARED_C) COMMON_SHARED_OBJ = $(patsubst %.c,%.o,$(COMMON_SHARED_C)) COMMON_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \ @@ -47,9 +47,9 @@ COMMON_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \ COMMON_C += console.c core.c memmgr.c socket.c COMMON_H = atomic.h cbasetypes.h conf.h console.h core.h db.h des.h ers.h \ grfio.h hercules.h HPM.h HPMi.h memmgr.h mapindex.h md5calc.h \ - mmo.h mutex.h nullpo.h packets_len.h random.h showmsg.h socket.h \ - spinlock.h sql.h strlib.h sysinfo.h thread.h timer.h utils.h \ - winapi.h ../plugins/HPMHooking.h + mmo.h mutex.h nullpo.h packets.h packets_len.h random.h showmsg.h \ + socket.h spinlock.h sql.h strlib.h sysinfo.h thread.h timer.h \ + utils.h winapi.h ../plugins/HPMHooking.h COMMON_PH = COMMON_SQL_OBJ = obj_sql/sql.o diff --git a/src/common/core.c b/src/common/core.c index 1ecf1df83..dbd1d2596 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -36,6 +36,7 @@ #include "common/mmo.h" #include "common/mutex.h" #include "common/nullpo.h" +#include "common/packets.h" #include "common/random.h" #include "common/showmsg.h" #include "common/socket.h" @@ -261,6 +262,7 @@ static void core_defaults(void) timer_defaults(); db_defaults(); socket_defaults(); + packets_defaults(); rnd_defaults(); md5_defaults(); thread_defaults(); @@ -526,6 +528,8 @@ int main(int argc, char **argv) sockt->init(); + packets->init(); + do_init(argc,argv); // Main runtime cycle @@ -539,6 +543,7 @@ int main(int argc, char **argv) retval = do_final(); HPM->final(); timer->final(); + packets->final(); sockt->final(); DB->final(); thread->final(); diff --git a/src/common/packets.c b/src/common/packets.c new file mode 100644 index 000000000..429418e0a --- /dev/null +++ b/src/common/packets.c @@ -0,0 +1,64 @@ +/** + * This file is part of Hercules. + * http://herc.ws - http://github.com/HerculesWS/Hercules + * + * Copyright (C) 2012-2018 Hercules Dev Team + * + * Hercules is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#define HERCULES_CORE + +#include "config/core.h" // CONSOLE_INPUT, MAX_CONSOLE_INPUT +#include "common/packets.h" + +#include "common/cbasetypes.h" +#include "common/mmo.h" +#include "common/nullpo.h" + +#include + +static struct packets_interface packets_s; +struct packets_interface *packets; + +static void packets_init(void) +{ + packets->addLens(); +} + +static void packets_addLens(void) +{ +#define packetLen(id, len) packets->addLen(id, len); +#include "common/packets_len.h" +} + +static void packets_addLen(int id, int len) +{ + Assert_retv(id <= MAX_PACKET_DB && id >= MIN_PACKET_DB); + packets->db[id] = len; +} + +static void packets_final(void) +{ +} + +void packets_defaults(void) +{ + packets = &packets_s; + packets->init = packets_init; + packets->final = packets_final; + packets->addLens = packets_addLens; + packets->addLen = packets_addLen; + + memset(&packets->db, 0, sizeof(packets->db)); +} diff --git a/src/common/packets.h b/src/common/packets.h new file mode 100644 index 000000000..83c92c7fa --- /dev/null +++ b/src/common/packets.h @@ -0,0 +1,47 @@ +/** + * This file is part of Hercules. + * http://herc.ws - http://github.com/HerculesWS/Hercules + * + * Copyright (C) 2013-2018 Hercules Dev Team + * + * Hercules is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef COMMON_PACKETS_H +#define COMMON_PACKETS_H + +#include "common/hercules.h" + +#ifndef MIN_PACKET_DB +#define MIN_PACKET_DB 0x0064 +#endif + +#ifndef MAX_PACKET_DB +#define MAX_PACKET_DB 0x0F00 +#endif + +struct packets_interface { + void (*init) (void); + void (*final) (void); + void (*addLens) (void); + void (*addLen) (int id, int len); + int db[MAX_PACKET_DB + 1]; +}; + +#ifdef HERCULES_CORE +void packets_defaults(void); +#endif // HERCULES_CORE + +HPShared struct packets_interface *packets; + +#endif /* COMMON_PACKETS_H */ diff --git a/src/common/packets_len.h b/src/common/packets_len.h index 02e6b51aa..02f63ae0d 100644 --- a/src/common/packets_len.h +++ b/src/common/packets_len.h @@ -21,15 +21,15 @@ #define COMMON_PACKETS_LEN_H #if defined(PACKETVER_ZERO) -#include "common/packets_len_zero.h" +#include "common/packets/packets_len_zero.h" #elif defined(PACKETVER_RE) -#include "common/packets_len_re.h" +#include "common/packets/packets_len_re.h" #elif defined(PACKETVER_SAK) -#include "common/packets_len_sak.h" +#include "common/packets/packets_len_sak.h" #elif defined(PACKETVER_AD) -#include "common/packets_len_ad.h" +#include "common/packets/packets_len_ad.h" #else -#include "common/packets_len_main.h" +#include "common/packets/packets_len_main.h" #endif #endif /* COMMON_PACKETS_LEN_H */ -- cgit v1.2.3-70-g09d2