diff --git a/src/char/inter.c b/src/char/inter.c index 91b537719a0..f3d3dfa0843 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -49,6 +49,7 @@ #include "common/sql.h" #include "common/strlib.h" #include "common/timer.h" +#include "common/packets.h" #include #include @@ -65,21 +66,6 @@ static char default_codepage[32] = ""; //Feature by irmin. int party_share_level = 10; -// recv. packet list -static int inter_recv_packet_length[] = { - 0, 0, 0, 0, -1,13,36, (2 + 4 + 4 + 4 + NAME_LENGTH), 0, 0, 0, 0, 0, 0, 0, 0, // 3000- - 6,-1, 6,-1, 0, 0, 0, 0, 10,-1, 0, 0, 0, 0, 0, 0, // 3010- Account Storage, Achievements [Smokexyz] - -1,10,-1,14, 14,19, 6, 0, 14,14, 0, 0, 0, 0, 0, 0, // 3020- Party - -1, 6,-1,-1, 55,23, 6, 0, 14,-1,-1,-1, 18,19,186,-1, // 3030- - -1, 9, 0, 0, 10,10, 0, 0, 7, 6,10,10, 10,-1, 0, 0, // 3040- Clan System(3044-3045) - -1,-1,10,10, 0,-1,12, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3050- Auction System [Zephyrus], Item Bound [Mhalicot] - 6,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3060- Quest system [Kevin] [Inkfish] - -1,10, 6,-1, 0, 0, 0, 0, 0, 0, 0, 0, -1,10, 6,-1, // 3070- Mercenary packets [Zephyrus], Elemental packets [pakpil] - sizeof(struct PACKET_INTER_CREATE_PET), // 3080 - 14,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3081- - -1,10,-1, 6, 0, 20,10,20, -1,6 + NAME_LENGTH, 0, 0, 0, 0, 0, 0, // 3090- Homunculus packets [albator], RoDEX packets -}; - #define MAX_JOB_NAMES 150 static char *msg_table[MAX_JOB_NAMES]; // messages 550 ~ 699 are job names @@ -1031,11 +1017,11 @@ static int inter_parse_frommap(int fd) int len = 0; cmd = RFIFOW(fd,0); // Check is valid packet entry - if(cmd < 0x3000 || cmd >= 0x3000 + ARRAYLENGTH(inter_recv_packet_length) || inter_recv_packet_length[cmd - 0x3000] == 0) + if (cmd < MIN_INTER_PACKET_DB || cmd >= MAX_INTER_PACKET_DB || packets->inter_db[cmd - MIN_INTER_PACKET_DB] == 0) return 0; // Check packet length - if((len = inter->check_length(fd, inter_recv_packet_length[cmd - 0x3000])) == 0) + if ((len = inter->check_length(fd, packets->inter_db[cmd - MIN_INTER_PACKET_DB])) == 0) return 2; switch(cmd) { diff --git a/src/common/packets.c b/src/common/packets.c index f3dde6dc0bf..bebea681ffd 100644 --- a/src/common/packets.c +++ b/src/common/packets.c @@ -40,6 +40,16 @@ static void packets_addLens(void) { #define packetLen(id, len) packets->addLen(id, len); #include "common/packets_len.h" +#undef packetLen +#define packetLen(id, len) packets->addLenIntif(id, len); +#include "common/packets_intif_len.h" +#undef packetLen +#define packetLen(id, len) packets->addLenInter(id, len); +#include "common/packets_inter_len.h" +#undef packetLen +#define packetLen(id, len) packets->addLenChrif(id, len); +#include "common/packets_chrif_len.h" +#undef packetLen } static void packets_addLen(int id, int len) @@ -48,6 +58,24 @@ static void packets_addLen(int id, int len) packets->db[id] = len; } +static void packets_addLenIntif(int id, int len) +{ + Assert_retv(id <= MAX_INTIF_PACKET_DB && id >= MIN_INTIF_PACKET_DB); + packets->intif_db[id - MIN_INTIF_PACKET_DB] = len; +} + +static void packets_addLenInter(int id, int len) +{ + Assert_retv(id <= MAX_INTER_PACKET_DB && id >= MIN_INTER_PACKET_DB); + packets->inter_db[id - MIN_INTER_PACKET_DB] = len; +} + +static void packets_addLenChrif(int id, int len) +{ + Assert_retv(id <= MAX_CHRIF_PACKET_DB && id >= MIN_CHRIF_PACKET_DB); + packets->chrif_db[id - MIN_CHRIF_PACKET_DB] = len; +} + static void packets_final(void) { } @@ -59,6 +87,12 @@ void packets_defaults(void) packets->final = packets_final; packets->addLens = packets_addLens; packets->addLen = packets_addLen; + packets->addLenIntif = packets_addLenIntif; + packets->addLenInter = packets_addLenInter; + packets->addLenChrif = packets_addLenChrif; memset(&packets->db, 0, sizeof(packets->db)); + memset(&packets->intif_db, 0, sizeof(packets->intif_db)); + memset(&packets->inter_db, 0, sizeof(packets->inter_db)); + memset(&packets->chrif_db, 0, sizeof(packets->chrif_db)); } diff --git a/src/common/packets.h b/src/common/packets.h index 2c1e2596511..96cc7a08bf7 100644 --- a/src/common/packets.h +++ b/src/common/packets.h @@ -30,12 +30,43 @@ #define MAX_PACKET_DB 0x0F00 #endif +#ifndef MIN_INTIF_PACKET_DB +#define MIN_INTIF_PACKET_DB 0x3800 +#endif + +#ifndef MAX_INTIF_PACKET_DB +#define MAX_INTIF_PACKET_DB 0x3900 +#endif + +#ifndef MIN_INTER_PACKET_DB +#define MIN_INTER_PACKET_DB 0x3000 +#endif + +#ifndef MAX_INTER_PACKET_DB +#define MAX_INTER_PACKET_DB 0x30a0 +#endif + +#ifndef MIN_CHRIF_PACKET_DB +#define MIN_CHRIF_PACKET_DB 0x2af8 +#endif + +#ifndef MAX_CHRIF_PACKET_DB +#define MAX_CHRIF_PACKET_DB 0x2b35 +#endif + struct packets_interface { void (*init) (void); void (*final) (void); void (*addLens) (void); void (*addLen) (int id, int len); + void (*addLenIntif) (int id, int len); + void (*addLenInter) (int id, int len); + void (*addLenChrif) (int id, int len); + int db[MAX_PACKET_DB + 1]; + int intif_db[MAX_INTIF_PACKET_DB - MIN_INTIF_PACKET_DB + 1]; + int inter_db[MAX_INTER_PACKET_DB - MIN_INTER_PACKET_DB + 1]; + int chrif_db[MAX_CHRIF_PACKET_DB - MIN_CHRIF_PACKET_DB + 1]; }; #ifdef HERCULES_CORE diff --git a/src/common/packets_chrif_len.h b/src/common/packets_chrif_len.h new file mode 100644 index 00000000000..0b7f398c50d --- /dev/null +++ b/src/common/packets_chrif_len.h @@ -0,0 +1,85 @@ +/** + * This file is part of Hercules. + * http://herc.ws - http://github.com/HerculesWS/Hercules + * + * Copyright (C) 2012-2022 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_CHRIF_LEN_H +#define COMMON_PACKETS_CHRIF_LEN_H + +packetLen(0x2af8, 60) +packetLen(0x2af9, 3) +packetLen(0x2afa, -1) +packetLen(0x2afb, 27) +packetLen(0x2afc, 10) +packetLen(0x2afd, -1) +packetLen(0x2afe, 6) +packetLen(0x2aff, -1) +packetLen(0x2b00, 6) +packetLen(0x2b01, -1) +packetLen(0x2b02, 18) +packetLen(0x2b03, 7) +packetLen(0x2b04, -1) +packetLen(0x2b05, 39) +packetLen(0x2b06, 30) +packetLen(0x2b07, 10) +packetLen(0x2b08, 6) +packetLen(0x2b09, 30) +packetLen(0x2b0a, -1) +packetLen(0x2b0b, 0) +packetLen(0x2b0c, 86) +packetLen(0x2b0d, 7) +packetLen(0x2b0e, 44) +packetLen(0x2b0f, 34) +packetLen(0x2b10, 11) +packetLen(0x2b11, 10) +packetLen(0x2b12, 10) +packetLen(0x2b13, 0) +packetLen(0x2b14, 11) +packetLen(0x2b15, 0) +packetLen(0x2b16, 266) +packetLen(0x2b17, 10) +packetLen(0x2b18, 2) +packetLen(0x2b19, 10) +packetLen(0x2b1a, 2) +packetLen(0x2b1b, -1) +packetLen(0x2b1c, -1) +packetLen(0x2b1d, -1) +packetLen(0x2b1e, 2) +packetLen(0x2b1f, 7) +packetLen(0x2b20, -1) +packetLen(0x2b21, 10) +packetLen(0x2b22, 8) +packetLen(0x2b23, 2) +packetLen(0x2b24, 2) +packetLen(0x2b25, 14) +packetLen(0x2b26, 19) +packetLen(0x2b27, 19) +packetLen(0x2b28, 0) +packetLen(0x2b29, 0) +packetLen(0x2b2a, 0) +packetLen(0x2b2b, 0) +packetLen(0x2b2c, 0) +packetLen(0x2b2d, 0) +packetLen(0x2b2e, 0) +packetLen(0x2b2f, 0) +packetLen(0x2b30, 0) +packetLen(0x2b31, 0) +packetLen(0x2b32, 0) +packetLen(0x2b33, 0) +packetLen(0x2b34, 0) + +#endif /* COMMON_PACKETS_CHRIF_LEN_H */ diff --git a/src/common/packets_inter_len.h b/src/common/packets_inter_len.h new file mode 100644 index 00000000000..4be3865ba17 --- /dev/null +++ b/src/common/packets_inter_len.h @@ -0,0 +1,184 @@ +/** + * This file is part of Hercules. + * http://herc.ws - http://github.com/HerculesWS/Hercules + * + * Copyright (C) 2012-2022 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_INTER_LEN_H +#define COMMON_PACKETS_INTER_LEN_H + +packetLen(0x3000, 0) +packetLen(0x3001, 0) +packetLen(0x3002, 0) +packetLen(0x3003, 0) +packetLen(0x3004, -1) +packetLen(0x3005, 13) +packetLen(0x3006, 36) +packetLen(0x3007, 38) +packetLen(0x3008, 0) +packetLen(0x3009, 0) +packetLen(0x300a, 0) +packetLen(0x300b, 0) +packetLen(0x300c, 0) +packetLen(0x300d, 0) +packetLen(0x300e, 0) +packetLen(0x300f, 0) +packetLen(0x3010, 6) +packetLen(0x3011, -1) +packetLen(0x3012, 6) +packetLen(0x3013, -1) +packetLen(0x3014, 0) +packetLen(0x3015, 0) +packetLen(0x3016, 0) +packetLen(0x3017, 0) +packetLen(0x3018, 10) +packetLen(0x3019, -1) +packetLen(0x301a, 0) +packetLen(0x301b, 0) +packetLen(0x301c, 0) +packetLen(0x301d, 0) +packetLen(0x301e, 0) +packetLen(0x301f, 0) +packetLen(0x3020, -1) +packetLen(0x3021, 10) +packetLen(0x3022, -1) +packetLen(0x3023, 14) +packetLen(0x3024, 14) +packetLen(0x3025, 19) +packetLen(0x3026, 6) +packetLen(0x3027, 0) +packetLen(0x3028, 14) +packetLen(0x3029, 14) +packetLen(0x302a, 0) +packetLen(0x302b, 0) +packetLen(0x302c, 0) +packetLen(0x302d, 0) +packetLen(0x302e, 0) +packetLen(0x302f, 0) +packetLen(0x3030, -1) +packetLen(0x3031, 6) +packetLen(0x3032, -1) +packetLen(0x3033, -1) +packetLen(0x3034, 55) +packetLen(0x3035, 23) +packetLen(0x3036, 6) +packetLen(0x3037, 0) +packetLen(0x3038, 14) +packetLen(0x3039, -1) +packetLen(0x303a, -1) +packetLen(0x303b, -1) +packetLen(0x303c, 18) +packetLen(0x303d, 19) +packetLen(0x303e, 186) +packetLen(0x303f, -1) +packetLen(0x3040, -1) +packetLen(0x3041, 9) +packetLen(0x3042, 0) +packetLen(0x3043, 0) +packetLen(0x3044, 10) +packetLen(0x3045, 10) +packetLen(0x3046, 0) +packetLen(0x3047, 0) +packetLen(0x3048, 7) +packetLen(0x3049, 6) +packetLen(0x304a, 10) +packetLen(0x304b, 10) +packetLen(0x304c, 10) +packetLen(0x304d, -1) +packetLen(0x304e, 0) +packetLen(0x304f, 0) +packetLen(0x3050, -1) +packetLen(0x3051, -1) +packetLen(0x3052, 10) +packetLen(0x3053, 10) +packetLen(0x3054, 0) +packetLen(0x3055, -1) +packetLen(0x3056, 12) +packetLen(0x3057, 0) +packetLen(0x3058, 0) +packetLen(0x3059, 0) +packetLen(0x305a, 0) +packetLen(0x305b, 0) +packetLen(0x305c, 0) +packetLen(0x305d, 0) +packetLen(0x305e, 0) +packetLen(0x305f, 0) +packetLen(0x3060, 6) +packetLen(0x3061, -1) +packetLen(0x3062, 0) +packetLen(0x3063, 0) +packetLen(0x3064, 0) +packetLen(0x3065, 0) +packetLen(0x3066, 0) +packetLen(0x3067, 0) +packetLen(0x3068, 0) +packetLen(0x3069, 0) +packetLen(0x306a, 0) +packetLen(0x306b, 0) +packetLen(0x306c, 0) +packetLen(0x306d, 0) +packetLen(0x306e, 0) +packetLen(0x306f, 0) +packetLen(0x3070, -1) +packetLen(0x3071, 10) +packetLen(0x3072, 6) +packetLen(0x3073, -1) +packetLen(0x3074, 0) +packetLen(0x3075, 0) +packetLen(0x3076, 0) +packetLen(0x3077, 0) +packetLen(0x3078, 0) +packetLen(0x3079, 0) +packetLen(0x307a, 0) +packetLen(0x307b, 0) +packetLen(0x307c, -1) +packetLen(0x307d, 10) +packetLen(0x307e, 6) +packetLen(0x307f, -1) +packetLen(0x3080, 56) +packetLen(0x3081, 14) +packetLen(0x3082, -1) +packetLen(0x3083, 6) +packetLen(0x3084, 0) +packetLen(0x3085, 0) +packetLen(0x3086, 0) +packetLen(0x3087, 0) +packetLen(0x3088, 0) +packetLen(0x3089, 0) +packetLen(0x308a, 0) +packetLen(0x308b, 0) +packetLen(0x308c, 0) +packetLen(0x308d, 0) +packetLen(0x308e, 0) +packetLen(0x308f, 0) +packetLen(0x3090, -1) +packetLen(0x3091, 10) +packetLen(0x3092, -1) +packetLen(0x3093, 6) +packetLen(0x3094, 0) +packetLen(0x3095, 20) +packetLen(0x3096, 10) +packetLen(0x3097, 20) +packetLen(0x3098, -1) +packetLen(0x3099, 30) +packetLen(0x309a, 0) +packetLen(0x309b, 0) +packetLen(0x309c, 0) +packetLen(0x309d, 0) +packetLen(0x309e, 0) +packetLen(0x309f, 0) + +#endif /* COMMON_PACKETS_INTER_LEN_H */ diff --git a/src/common/packets_intif_len.h b/src/common/packets_intif_len.h new file mode 100644 index 00000000000..08053930de9 --- /dev/null +++ b/src/common/packets_intif_len.h @@ -0,0 +1,185 @@ +/** + * This file is part of Hercules. + * http://herc.ws - http://github.com/HerculesWS/Hercules + * + * Copyright (C) 2012-2022 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_INTIF_LEN_H +#define COMMON_PACKETS_INTIF_LEN_H + +packetLen(0x3800, 0) +packetLen(0x3801, 0) +packetLen(0x3802, 0) +packetLen(0x3803, 0) +packetLen(0x3804, -1) +packetLen(0x3805, -1) +packetLen(0x3806, 37) +packetLen(0x3807, -1) +packetLen(0x3808, 7) +packetLen(0x3809, 0) +packetLen(0x380a, 0) +packetLen(0x380b, 0) +packetLen(0x380c, 0) +packetLen(0x380d, 0) +packetLen(0x380e, 0) +packetLen(0x380f, 0) +packetLen(0x3810, -1) +packetLen(0x3811, 0) +packetLen(0x3812, 0) +packetLen(0x3813, 0) +packetLen(0x3814, 0) +packetLen(0x3815, 0) +packetLen(0x3816, 0) +packetLen(0x3817, 0) +packetLen(0x3818, -1) +packetLen(0x3819, 11) +packetLen(0x381a, 0) +packetLen(0x381b, 0) +packetLen(0x381c, 0) +packetLen(0x381d, 0) +packetLen(0x381e, 0) +packetLen(0x381f, 0) +packetLen(0x3820, 39) +packetLen(0x3821, -1) +packetLen(0x3822, 15) +packetLen(0x3823, 15) +packetLen(0x3824, 14) +packetLen(0x3825, 19) +packetLen(0x3826, 7) +packetLen(0x3827, 0) +packetLen(0x3828, 0) +packetLen(0x3829, 0) +packetLen(0x382a, 0) +packetLen(0x382b, 0) +packetLen(0x382c, 0) +packetLen(0x382d, 0) +packetLen(0x382e, 0) +packetLen(0x382f, 0) +packetLen(0x3830, 10) +packetLen(0x3831, -1) +packetLen(0x3832, 15) +packetLen(0x3833, 0) +packetLen(0x3834, 79) +packetLen(0x3835, 25) +packetLen(0x3836, 7) +packetLen(0x3837, 0) +packetLen(0x3838, 0) +packetLen(0x3839, -1) +packetLen(0x383a, -1) +packetLen(0x383b, -1) +packetLen(0x383c, 14) +packetLen(0x383d, 67) +packetLen(0x383e, 186) +packetLen(0x383f, -1) +packetLen(0x3840, -1) +packetLen(0x3841, 0) +packetLen(0x3842, 0) +packetLen(0x3843, 14) +packetLen(0x3844, 0) +packetLen(0x3845, 0) +packetLen(0x3846, 0) +packetLen(0x3847, 0) +packetLen(0x3848, -1) +packetLen(0x3849, 74) +packetLen(0x384a, -1) +packetLen(0x384b, 11) +packetLen(0x384c, 11) +packetLen(0x384d, -1) +packetLen(0x384e, 0) +packetLen(0x384f, 0) +packetLen(0x3850, -1) +packetLen(0x3851, -1) +packetLen(0x3852, 7) +packetLen(0x3853, 7) +packetLen(0x3854, 7) +packetLen(0x3855, 11) +packetLen(0x3856, 8) +packetLen(0x3857, 0) +packetLen(0x3858, 10) +packetLen(0x3859, 0) +packetLen(0x385a, 0) +packetLen(0x385b, 0) +packetLen(0x385c, 0) +packetLen(0x385d, 0) +packetLen(0x385e, 0) +packetLen(0x385f, 0) +packetLen(0x3860, -1) +packetLen(0x3861, 7) +packetLen(0x3862, 0) +packetLen(0x3863, 0) +packetLen(0x3864, 0) +packetLen(0x3865, 0) +packetLen(0x3866, 0) +packetLen(0x3867, 0) +packetLen(0x3868, 0) +packetLen(0x3869, 0) +packetLen(0x386a, 0) +packetLen(0x386b, 0) +packetLen(0x386c, 0) +packetLen(0x386d, 0) +packetLen(0x386e, 0) +packetLen(0x386f, 0) +packetLen(0x3870, -1) +packetLen(0x3871, 3) +packetLen(0x3872, 3) +packetLen(0x3873, 0) +packetLen(0x3874, 0) +packetLen(0x3875, 0) +packetLen(0x3876, 0) +packetLen(0x3877, 0) +packetLen(0x3878, 0) +packetLen(0x3879, 0) +packetLen(0x387a, 0) +packetLen(0x387b, 0) +packetLen(0x387c, -1) +packetLen(0x387d, 3) +packetLen(0x387e, 3) +packetLen(0x387f, 0) +packetLen(0x3880, 14) +packetLen(0x3881, -1) +packetLen(0x3882, 7) +packetLen(0x3883, 3) +packetLen(0x3884, 0) +packetLen(0x3885, 0) +packetLen(0x3886, 0) +packetLen(0x3887, 0) +packetLen(0x3888, 0) +packetLen(0x3889, 0) +packetLen(0x388a, 0) +packetLen(0x388b, 0) +packetLen(0x388c, 0) +packetLen(0x388d, 0) +packetLen(0x388e, 0) +packetLen(0x388f, 0) +packetLen(0x3890, -1) +packetLen(0x3891, -1) +packetLen(0x3892, 7) +packetLen(0x3893, 3) +packetLen(0x3894, 0) +packetLen(0x3895, -1) +packetLen(0x3896, 7) +packetLen(0x3897, 15) +packetLen(0x3898, 42) +packetLen(0x3899, 23) +packetLen(0x389a, 496) +packetLen(0x389b, 0) +packetLen(0x389c, 0) +packetLen(0x389d, 0) +packetLen(0x389e, 0) +packetLen(0x389f, 0) +packetLen(0x38a0, 0) + +#endif /* COMMON_PACKETS_INTIF_LEN_H */ diff --git a/src/common/packets_struct.h b/src/common/packets_struct.h index e939745db73..e8330148ec6 100644 --- a/src/common/packets_struct.h +++ b/src/common/packets_struct.h @@ -24,7 +24,7 @@ #include "common/cbasetypes.h" #include "common/mmo.h" -#include "common/packetsstatic_len.h" +#include "common/packetsmacro.h" #if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute #pragma pack(push, 1) diff --git a/src/common/packetsmacro.h b/src/common/packetsmacro.h new file mode 100644 index 00000000000..07dddc5bea0 --- /dev/null +++ b/src/common/packetsmacro.h @@ -0,0 +1,39 @@ +/** + * This file is part of Hercules. + * http://herc.ws - http://github.com/HerculesWS/Hercules + * + * Copyright (C) 2013-2022 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_PACKETSMACRO_H +#define COMMON_PACKETSMACRO_H + +#ifdef packetLen +#error packetLen already defined +#endif + +#define DEFINE_PACKET_HEADER(name, id) \ + STATIC_ASSERT((int32)(PACKET_LEN_##id) == -1 || sizeof(struct PACKET_##name) == \ + (size_t)PACKET_LEN_##id, "Wrong size PACKET_"#name); \ + enum { HEADER_##name = id }; + +#define DEFINE_PACKET_ID(name, id) \ + enum { HEADER_##name = id }; + +#define CHECK_PACKET_HEADER(name, id) \ + STATIC_ASSERT((int32)(PACKET_LEN_##id) == -1 || sizeof(struct PACKET_##name) == \ + (size_t)PACKET_LEN_##id, "Wrong size PACKET_"#name); \ + +#endif /* COMMON_PACKETSMACRO_H */ diff --git a/src/common/packetsstatic_len.h b/src/common/packetsstatic_len.h index 05db38525aa..5254d7697d2 100644 --- a/src/common/packetsstatic_len.h +++ b/src/common/packetsstatic_len.h @@ -24,17 +24,7 @@ #error packetLen already defined #endif -#define DEFINE_PACKET_HEADER(name, id) \ - STATIC_ASSERT((int32)(PACKET_LEN_##id) == -1 || sizeof(struct PACKET_##name) == \ - (size_t)PACKET_LEN_##id, "Wrong size PACKET_"#name); \ - enum { HEADER_##name = id }; - -#define DEFINE_PACKET_ID(name, id) \ - enum { HEADER_##name = id }; - -#define CHECK_PACKET_HEADER(name, id) \ - STATIC_ASSERT((int32)(PACKET_LEN_##id) == -1 || sizeof(struct PACKET_##name) == \ - (size_t)PACKET_LEN_##id, "Wrong size PACKET_"#name); \ +#include "common/packetsmacro.h" #define packetLen(id, len) PACKET_LEN_##id = (len), enum packet_lengths { diff --git a/src/map/chrif.c b/src/map/chrif.c index e3d972c9fa7..26cbe56ff77 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -48,6 +48,7 @@ #include "common/socket.h" #include "common/strlib.h" #include "common/timer.h" +#include "common/packets.h" #include #include @@ -1476,7 +1477,7 @@ static int chrif_parse(int fd) return 0; } - if (cmd < 0x2af8 || cmd >= 0x2af8 + ARRAYLENGTH(chrif->packet_len_table) || chrif->packet_len_table[cmd-0x2af8] == 0) { + if (cmd < MIN_CHRIF_PACKET_DB || cmd >= MAX_CHRIF_PACKET_DB || packets->chrif_db[cmd - MIN_CHRIF_PACKET_DB] == 0) { int result = intif->parse(fd); // Passed on to the intif if (result == 1) continue; // Treated in intif @@ -1487,7 +1488,7 @@ static int chrif_parse(int fd) return 0; } - if ( ( packet_len = chrif->packet_len_table[cmd-0x2af8] ) == -1) { // dynamic-length packet, second WORD holds the length + if ((packet_len = packets->chrif_db[cmd - MIN_CHRIF_PACKET_DB]) == -1) { // dynamic-length packet, second WORD holds the length if (RFIFOREST(fd) < 4) return 0; packet_len = RFIFOW(fd,2); @@ -1741,22 +1742,12 @@ static void do_init_chrif(bool minimal) *-------------------------------------*/ void chrif_defaults(void) { - const int packet_len_table[CHRIF_PACKET_LEN_TABLE_SIZE] = { // U - used, F - free - 60, 3, -1, 27, 10, -1, 6, -1, // 2af8-2aff: U->2af8, U->2af9, U->2afa, U->2afb, U->2afc, U->2afd, U->2afe, U->2aff - 6, -1, 18, 7, -1, 39, 30, 10, // 2b00-2b07: U->2b00, U->2b01, U->2b02, U->2b03, U->2b04, U->2b05, U->2b06, U->2b07 - 6, 30, -1, 0, 86, 7, 44, 34, // 2b08-2b0f: U->2b08, U->2b09, U->2b0a, F->2b0b, U->2b0c, U->2b0d, U->2b0e, U->2b0f - 11, 10, 10, 0, 11, 0,266, 10, // 2b10-2b17: U->2b10, U->2b11, U->2b12, F->2b13, U->2b14, F->2b15, U->2b16, U->2b17 - 2, 10, 2, -1, -1, -1, 2, 7, // 2b18-2b1f: U->2b18, U->2b19, U->2b1a, U->2b1b, U->2b1c, U->2b1d, U->2b1e, U->2b1f - -1, 10, 8, 2, 2, 14, 19, 19, // 2b20-2b27: U->2b20, U->2b21, U->2b22, U->2b23, U->2b24, U->2b25, U->2b26, U->2b27 - }; - chrif = &chrif_s; /* vars */ chrif->connected = 0; chrif->other_mapserver_count = 0; - memcpy(chrif->packet_len_table,&packet_len_table,sizeof(chrif->packet_len_table)); chrif->fd = -1; chrif->srvinfo = 0; memset(chrif->ip_str,0,sizeof(chrif->ip_str)); diff --git a/src/map/chrif.h b/src/map/chrif.h index fd5a40a491d..f475c1ac868 100644 --- a/src/map/chrif.h +++ b/src/map/chrif.h @@ -37,8 +37,6 @@ struct status_change_entry; //Interval at which map server sends number of connected users. [Skotlex] #define UPDATE_INTERVAL 10000 -#define CHRIF_PACKET_LEN_TABLE_SIZE 0x3d - /** * Enumerations **/ @@ -74,7 +72,6 @@ struct chrif_interface { struct eri *auth_db_ers; //For re-utilizing player login structures. struct DBMap *auth_db; // int id -> struct auth_node* /* */ - int packet_len_table[CHRIF_PACKET_LEN_TABLE_SIZE]; int fd; int srvinfo; char ip_str[128]; diff --git a/src/map/intif.c b/src/map/intif.c index 887a5ff3c11..c4fd51c29df 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -50,6 +50,7 @@ #include "common/socket.h" #include "common/strlib.h" #include "common/timer.h" +#include "common/packets.h" #include #include @@ -2686,13 +2687,11 @@ static int intif_parse(int fd) int packet_len, cmd; cmd = RFIFOW(fd,0); // Verify ID of the packet - if (cmd < 0x3800 || cmd >= 0x3800+(sizeof(intif->packet_len_table)/sizeof(intif->packet_len_table[0])) - || intif->packet_len_table[cmd-0x3800] == 0 - ) { + if (cmd < MIN_INTIF_PACKET_DB || cmd >= MAX_INTIF_PACKET_DB || packets->intif_db[cmd - MIN_INTIF_PACKET_DB] == 0) { return 0; } // Check the length of the packet - packet_len = intif->packet_len_table[cmd-0x3800]; + packet_len = packets->intif_db[cmd - MIN_INTIF_PACKET_DB]; if(packet_len==-1){ if(RFIFOREST(fd)<4) return 2; @@ -2804,24 +2803,8 @@ static int intif_parse(int fd) *-------------------------------------*/ void intif_defaults(void) { - const int packet_len_table [INTIF_PACKET_LEN_TABLE_SIZE] = { - 0, 0, 0, 0, -1,-1,37,-1, 7, 0, 0, 0, 0, 0, 0, 0, //0x3800-0x380f - -1, 0, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810 Achievements [Smokexyz/Hercules] - 39,-1,15,15, 14,19, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3820 - 10,-1,15, 0, 79,25, 7, 0, 0,-1,-1,-1, 14,67,186,-1, //0x3830 - -1, 0, 0,14, 0, 0, 0, 0, -1,74,-1,11, 11,-1, 0, 0, //0x3840 - -1,-1, 7, 7, 7,11, 8, 0, 10, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus] itembound[Akinari] Clan System[Murilo BiO] - -1, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin] [Inkfish] - -1, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 3, 3, 0, //0x3870 Mercenaries [Zephyrus] / Elemental [pakpil] - 14,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3880 - -1,-1, 7, 3, 0,-1, 7, 15,18 + NAME_LENGTH, 23, 16 + sizeof(struct rodex_item) * RODEX_MAX_ITEM, 0, 0, 0, 0, 0, //0x3890 Homunculus [albator] / RoDEX [KirieZ] - }; - intif = &intif_s; - /* */ - memcpy(intif->packet_len_table,&packet_len_table,sizeof(intif->packet_len_table)); - /* funcs */ intif->parse = intif_parse; intif->create_pet = intif_create_pet; diff --git a/src/map/intif.h b/src/map/intif.h index 8c1e933f4fe..7dd84169451 100644 --- a/src/map/intif.h +++ b/src/map/intif.h @@ -45,8 +45,6 @@ struct rodex_message; #define intif_rename_pc(sd, name) (intif->rename((sd), 0, (name))) #define intif_rename_pet(sd, name) (intif->rename((sd), 1, (name))) #define intif_rename_hom(sd, name) (intif->rename((sd), 2, (name))) -#define INTIF_PACKET_LEN_TABLE_SIZE 161 - /*===================================== * Interface : intif.h @@ -54,8 +52,6 @@ struct rodex_message; * created by Susu *-------------------------------------*/ struct intif_interface { - /* */ - int packet_len_table[INTIF_PACKET_LEN_TABLE_SIZE]; /* funcs */ int (*parse) (int fd); int (*create_pet)(int account_id, int char_id, int pet_type, int pet_lv, int pet_egg_id,