diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-11-05 23:37:03 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2018-11-14 06:00:50 +0300 |
commit | 94366099f9019643c9e431a35af064283fab5a0c (patch) | |
tree | 809e747ca8bf89cf63ed4643ee348f7a40e74d6c /src | |
parent | 77841351959658c576d1087dfdcc6ea0886ade20 (diff) | |
download | hercules-94366099f9019643c9e431a35af064283fab5a0c.tar.gz hercules-94366099f9019643c9e431a35af064283fab5a0c.tar.bz2 hercules-94366099f9019643c9e431a35af064283fab5a0c.tar.xz hercules-94366099f9019643c9e431a35af064283fab5a0c.zip |
Add interface for packets in common.
For now supported only packet length fields.
Diffstat (limited to 'src')
-rw-r--r-- | src/char/HPMchar.c | 1 | ||||
-rw-r--r-- | src/common/Makefile.in | 10 | ||||
-rw-r--r-- | src/common/core.c | 5 | ||||
-rw-r--r-- | src/common/packets.c | 64 | ||||
-rw-r--r-- | src/common/packets.h | 47 | ||||
-rw-r--r-- | src/common/packets_len.h | 10 | ||||
-rw-r--r-- | src/login/HPMlogin.c | 1 | ||||
-rw-r--r-- | src/login/lclif.c | 4 | ||||
-rw-r--r-- | src/login/lclif.p.h | 4 | ||||
-rw-r--r-- | src/map/HPMmap.c | 1 | ||||
-rw-r--r-- | src/map/atcommand.c | 1 | ||||
-rw-r--r-- | src/map/clif.c | 13 | ||||
-rw-r--r-- | src/map/packets_struct.h | 2 | ||||
-rw-r--r-- | src/plugins/HPMHooking.c | 1 |
14 files changed, 142 insertions, 22 deletions
diff --git a/src/char/HPMchar.c b/src/char/HPMchar.c index db2c3702e..f3cf2cff4 100644 --- a/src/char/HPMchar.c +++ b/src/char/HPMchar.c @@ -57,6 +57,7 @@ #include "common/mapindex.h" #include "common/mmo.h" #include "common/nullpo.h" +#include "common/packets.h" #include "common/random.h" #include "common/showmsg.h" #include "common/socket.h" 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 <http://www.gnu.org/licenses/>. + */ +#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 <string.h> + +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 <http://www.gnu.org/licenses/>. + */ +#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 */ diff --git a/src/login/HPMlogin.c b/src/login/HPMlogin.c index c13bd96a3..e5dc126eb 100644 --- a/src/login/HPMlogin.c +++ b/src/login/HPMlogin.c @@ -41,6 +41,7 @@ #include "common/memmgr.h" #include "common/mutex.h" #include "common/mmo.h" +#include "common/packets.h" #include "common/nullpo.h" #include "common/random.h" #include "common/showmsg.h" diff --git a/src/login/lclif.c b/src/login/lclif.c index 48a9c6b94..1cb8bfdbd 100644 --- a/src/login/lclif.c +++ b/src/login/lclif.c @@ -479,7 +479,7 @@ static const struct login_packet_db *lclif_packet(int16 packet_id) if (packet_id == PACKET_ID_CA_CHARSERVERCONNECT) return &lclif->p->dbs->packet_db[0]; - if (packet_id > MAX_PACKET_DB || packet_id < MIN_PACKET_DB) + if (packet_id > MAX_PACKET_LOGIN_DB || packet_id < MIN_PACKET_DB) return NULL; return &lclif->p->dbs->packet_db[packet_id]; @@ -525,7 +525,7 @@ static void packetdb_loaddb(void) for (i = 0; i < length; ++i) { int16 packet_id = packet[i].packet_id; - Assert_retb(packet_id >= MIN_PACKET_DB && packet_id <= MAX_PACKET_DB); + Assert_retb(packet_id >= MIN_PACKET_DB && packet_id <= MAX_PACKET_LOGIN_DB); lclif->p->dbs->packet_db[packet_id].len = packet[i].packet_len; lclif->p->dbs->packet_db[packet_id].pFunc = packet[i].pFunc; } diff --git a/src/login/lclif.p.h b/src/login/lclif.p.h index 7fa8475f4..a80caafa2 100644 --- a/src/login/lclif.p.h +++ b/src/login/lclif.p.h @@ -35,7 +35,7 @@ // Packet DB #define MIN_PACKET_DB 0x0064 -#define MAX_PACKET_DB 0x0acf +#define MAX_PACKET_LOGIN_DB 0x0acf /* Enums */ @@ -309,7 +309,7 @@ struct packet_AC_ACK_HASH { * Login Client Interface additional data */ struct lclif_interface_dbs { - struct login_packet_db packet_db[MAX_PACKET_DB + 1]; ///< Packet database. + struct login_packet_db packet_db[MAX_PACKET_LOGIN_DB + 1]; ///< Packet database. }; /** diff --git a/src/map/HPMmap.c b/src/map/HPMmap.c index 091a53311..8ea524d23 100644 --- a/src/map/HPMmap.c +++ b/src/map/HPMmap.c @@ -38,6 +38,7 @@ #include "common/mapindex.h" #include "common/mmo.h" #include "common/nullpo.h" +#include "common/packets.h" #include "common/random.h" #include "common/showmsg.h" #include "common/socket.h" diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 236975b32..d65af9dd1 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -62,6 +62,7 @@ #include "common/memmgr.h" #include "common/mmo.h" // MAX_CARTS #include "common/nullpo.h" +#include "common/packets.h" #include "common/random.h" #include "common/showmsg.h" #include "common/socket.h" diff --git a/src/map/clif.c b/src/map/clif.c index 44cefcd7e..6d21e8e0e 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -65,6 +65,7 @@ #include "common/memmgr.h" #include "common/mmo.h" // NEW_CARTS, char_achievements #include "common/nullpo.h" +#include "common/packets.h" #include "common/random.h" #include "common/showmsg.h" #include "common/socket.h" @@ -22200,13 +22201,13 @@ static void packetdb_loaddb(void) memset(packet_db,0,sizeof(packet_db)); #define packet(id, size, ...) packetdb_addpacket((id), (size), ##__VA_ARGS__, 0xFFFF) -#include "packets.h" /* load structure data */ +#include "map/packets.h" /* load structure data */ #ifdef PACKETVER_ZERO -#include "packets_shuffle_zero.h" +#include "map/packets_shuffle_zero.h" #elif defined(PACKETVER_RE) -#include "packets_shuffle_re.h" +#include "map/packets_shuffle_re.h" #else // PACKETVER_ZERO -#include "packets_shuffle_main.h" +#include "map/packets_shuffle_main.h" #endif // PACKETVER_ZERO #undef packet #define packetKeys(a,b,c) do { clif->cryptKey[0] = (a); clif->cryptKey[1] = (b); clif->cryptKey[2] = (c); } while(0) @@ -22214,9 +22215,9 @@ static void packetdb_loaddb(void) packetKeys(OBFUSCATIONKEY1,OBFUSCATIONKEY2,OBFUSCATIONKEY3); #else // defined(OBFUSCATIONKEY1) && defined(OBFUSCATIONKEY2) && defined(OBFUSCATIONKEY3) #ifdef PACKETVER_ZERO -#include "packets_keys_zero.h" +#include "map/packets_keys_zero.h" #else // PACKETVER_ZERO -#include "packets_keys_main.h" +#include "map/packets_keys_main.h" #endif // PACKETVER_ZERO #endif // defined(OBFUSCATIONKEY1) && defined(OBFUSCATIONKEY2) && defined(OBFUSCATIONKEY3) #undef packetKeys diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h index 374769728..5d097104e 100644 --- a/src/map/packets_struct.h +++ b/src/map/packets_struct.h @@ -27,8 +27,6 @@ #include "common/mmo.h" // Packet DB -#define MIN_PACKET_DB 0x0064 -#define MAX_PACKET_DB 0x0F00 #define MAX_PACKET_POS 20 /** diff --git a/src/plugins/HPMHooking.c b/src/plugins/HPMHooking.c index b477cb5c3..64337d8f4 100644 --- a/src/plugins/HPMHooking.c +++ b/src/plugins/HPMHooking.c @@ -25,6 +25,7 @@ #include "common/memmgr.h" #include "common/mmo.h" #include "common/socket.h" +#include "common/packets.h" PRAGMA_GCC5(GCC diagnostic push) PRAGMA_GCC5(GCC diagnostic ignored "-Wdiscarded-qualifiers") |