Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move server packet lengths definitions into separate files #3122

Merged
merged 4 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions src/char/inter.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "common/sql.h"
#include "common/strlib.h"
#include "common/timer.h"
#include "common/packets.h"

#include <stdio.h>
#include <stdlib.h>
Expand All @@ -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

Expand Down Expand Up @@ -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) {
Expand Down
34 changes: 34 additions & 0 deletions src/common/packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
{
}
Expand All @@ -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));
}
31 changes: 31 additions & 0 deletions src/common/packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
85 changes: 85 additions & 0 deletions src/common/packets_chrif_len.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
#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 */
Loading