Skip to content

Commit

Permalink
Merge pull request #2321 from 4144/packetlen
Browse files Browse the repository at this point in the history
Add complete packet len table
  • Loading branch information
MishimaHaruna authored Nov 15, 2018
2 parents 3b93418 + 1f23703 commit 47d6523
Show file tree
Hide file tree
Showing 111 changed files with 289,814 additions and 21,367 deletions.
148 changes: 129 additions & 19 deletions Hercules.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/sh
# From configure.ac 26efcebad.
# From configure.ac e207bf99b.
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69.
#
Expand Down
1 change: 1 addition & 0 deletions src/char/HPMchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 10 additions & 7 deletions src/char/char.c
Original file line number Diff line number Diff line change
Expand Up @@ -4364,9 +4364,9 @@ static void char_delete2_cancel(int fd, struct char_session_data *sd)

static void char_send_account_id(int fd, int account_id)
{
WFIFOHEAD(fd,4);
WFIFOL(fd,0) = account_id;
WFIFOSET(fd,4);
WFIFOHEAD(fd, 4);
WFIFOL(fd, 0) = account_id;
WFIFOSET2(fd, 4);
}

static void char_parse_char_connect(int fd, struct char_session_data *sd, uint32 ipl)
Expand Down Expand Up @@ -4930,10 +4930,10 @@ static void char_parse_char_delete2_cancel(int fd, struct char_session_data *sd)
// 3 - error
static void char_login_map_server_ack(int fd, uint8 flag)
{
WFIFOHEAD(fd,3);
WFIFOW(fd,0) = 0x2af9;
WFIFOB(fd,2) = flag;
WFIFOSET(fd,3);
WFIFOHEAD(fd, 3);
WFIFOW(fd, 0) = 0x2af9;
WFIFOB(fd, 2) = flag;
WFIFOSET2(fd, 3);
}

static void char_parse_char_login_map_server(int fd, uint32 ipl)
Expand All @@ -4960,6 +4960,7 @@ static void char_parse_char_login_map_server(int fd, uint32 ipl)
chr->server[i].users = 0;
sockt->session[fd]->func_parse = chr->parse_frommap;
sockt->session[fd]->flag.server = 1;
sockt->session[fd]->flag.validate = 0;
sockt->realloc_fifo(fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);
chr->mapif_init(fd);
}
Expand Down Expand Up @@ -5329,6 +5330,7 @@ static int char_check_connect_login_server(int tid, int64 tick, int id, intptr_t

sockt->session[chr->login_fd]->func_parse = chr->parse_fromlogin;
sockt->session[chr->login_fd]->flag.server = 1;
sockt->session[chr->login_fd]->flag.validate = 0;
sockt->realloc_fifo(chr->login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK);

loginif->connect_to_server();
Expand Down Expand Up @@ -6321,6 +6323,7 @@ int do_init(int argc, char **argv)
Sql_ShowDebug(inter->sql_handle);

sockt->set_defaultparse(chr->parse_char);
sockt->validate = true;

if ((chr->char_fd = sockt->make_listen_bind(bind_ip,chr->port)) == -1) {
ShowFatalError("Failed to bind to port '"CL_WHITE"%d"CL_RESET"'\n",chr->port);
Expand Down
5 changes: 5 additions & 0 deletions src/common/HPM.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "common/memmgr.h"
#include "common/mapindex.h"
#include "common/mmo.h"
#include "common/packets.h"
#include "common/showmsg.h"
#include "common/socket.h"
#include "common/sql.h"
Expand Down Expand Up @@ -186,6 +187,10 @@ static bool hplugins_addpacket(unsigned short cmd, unsigned short length, void (
packet->len = length;
packet->receive = receive;

if (cmd <= MAX_PACKET_DB && cmd >= MIN_PACKET_DB) {
packets->db[cmd] = length;
}

return true;
}

Expand Down
6 changes: 5 additions & 1 deletion src/common/HPMDataCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
#else
#define COMMON_NULLPO_H
#endif // COMMON_NULLPO_H
#ifdef COMMON_PACKETS_H
{ "packets_interface", sizeof(struct packets_interface), SERVER_TYPE_ALL },
#else
#define COMMON_PACKETS_H
#endif // COMMON_PACKETS_H
#ifdef COMMON_RANDOM_H
{ "rnd_interface", sizeof(struct rnd_interface), SERVER_TYPE_ALL },
#else
Expand Down Expand Up @@ -679,7 +684,6 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
{ "PACKET_ZC_INVENTORY_MOVE_FAILED", sizeof(struct PACKET_ZC_INVENTORY_MOVE_FAILED), SERVER_TYPE_MAP },
{ "PACKET_ZC_ITEM_ENTRY", sizeof(struct PACKET_ZC_ITEM_ENTRY), SERVER_TYPE_MAP },
{ "PACKET_ZC_ITEM_PICKUP_PARTY", sizeof(struct PACKET_ZC_ITEM_PICKUP_PARTY), SERVER_TYPE_MAP },
{ "PACKET_ZC_ITEM_PREVIEW", sizeof(struct PACKET_ZC_ITEM_PREVIEW), SERVER_TYPE_MAP },
{ "PACKET_ZC_MAIL_LIST", sizeof(struct PACKET_ZC_MAIL_LIST), SERVER_TYPE_MAP },
{ "PACKET_ZC_MAKABLEITEMLIST", sizeof(struct PACKET_ZC_MAKABLEITEMLIST), SERVER_TYPE_MAP },
{ "PACKET_ZC_MAKABLEITEMLIST_sub", sizeof(struct PACKET_ZC_MAKABLEITEMLIST_sub), SERVER_TYPE_MAP },
Expand Down
7 changes: 7 additions & 0 deletions src/common/HPMSymbols.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ struct npc_interface *npc;
#ifdef COMMON_NULLPO_H /* nullpo */
struct nullpo_interface *nullpo;
#endif // COMMON_NULLPO_H
#ifdef COMMON_PACKETS_H /* packets */
struct packets_interface *packets;
#endif // COMMON_PACKETS_H
#ifdef MAP_PARTY_H /* party */
struct party_interface *party;
#endif // MAP_PARTY_H
Expand Down Expand Up @@ -559,6 +562,10 @@ HPExport const char *HPM_shared_symbols(int server_type)
if ((server_type&(SERVER_TYPE_ALL)) != 0 && !HPM_SYMBOL("nullpo", nullpo))
return "nullpo";
#endif // COMMON_NULLPO_H
#ifdef COMMON_PACKETS_H /* packets */
if ((server_type&(SERVER_TYPE_ALL)) != 0 && !HPM_SYMBOL("packets", packets))
return "packets";
#endif // COMMON_PACKETS_H
#ifdef MAP_PARTY_H /* party */
if ((server_type&(SERVER_TYPE_MAP)) != 0 && !HPM_SYMBOL("party", party))
return "party";
Expand Down
10 changes: 5 additions & 5 deletions src/common/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ 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) \
console.o core.o memmgr.o socket.o)
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 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
Expand Down
5 changes: 5 additions & 0 deletions src/common/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -261,6 +262,7 @@ static void core_defaults(void)
timer_defaults();
db_defaults();
socket_defaults();
packets_defaults();
rnd_defaults();
md5_defaults();
thread_defaults();
Expand Down Expand Up @@ -526,6 +528,8 @@ int main(int argc, char **argv)

sockt->init();

packets->init();

do_init(argc,argv);

// Main runtime cycle
Expand All @@ -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();
Expand Down
64 changes: 64 additions & 0 deletions src/common/packets.c
Original file line number Diff line number Diff line change
@@ -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));
}
47 changes: 47 additions & 0 deletions src/common/packets.h
Original file line number Diff line number Diff line change
@@ -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 */
Loading

0 comments on commit 47d6523

Please sign in to comment.