summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/char/char.c32
-rw-r--r--src/common/HPM.c84
-rw-r--r--src/common/HPM.h3
-rw-r--r--src/login/login.c25
-rw-r--r--src/map/chrif.c22
-rw-r--r--src/map/clif.c12
6 files changed, 91 insertions, 87 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 3cc8853a4..1226a03cd 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -2626,10 +2626,12 @@ int char_parse_fromlogin(int fd) {
while(RFIFOREST(fd) >= 2) {
uint16 command = RFIFOW(fd,0);
- if( HPM->packetsc[hpParse_FromLogin] ) {
- int success = HPM->parse_packets(fd,hpParse_FromLogin);
- if( success == 1 ) continue;
- else if( success == 2 ) return 0;
+ if (VECTOR_LENGTH(HPM->packets[hpParse_FromLogin]) > 0) {
+ int result = HPM->parse_packets(fd,hpParse_FromLogin);
+ if (result == 1)
+ continue;
+ if (result == 2)
+ return 0;
}
switch (command) {
@@ -3896,7 +3898,6 @@ void char_parse_frommap_scdata_delete(int fd)
int char_parse_frommap(int fd)
{
- int i;
int id;
ARR_FIND( 0, ARRAYLENGTH(chr->server), id, chr->server[id].fd == fd );
@@ -3913,11 +3914,12 @@ int char_parse_frommap(int fd)
}
while(RFIFOREST(fd) >= 2) {
- if( HPM->packetsc[hpParse_FromMap] ) {
- if( (i = HPM->parse_packets(fd,hpParse_FromMap)) ) {
- if( i == 1 ) continue;
- if( i == 2 ) return 0;
- }
+ if (VECTOR_LENGTH(HPM->packets[hpParse_FromMap]) > 0) {
+ int result = HPM->parse_packets(fd,hpParse_FromMap);
+ if (result == 1)
+ continue;
+ if (result == 2)
+ return 0;
}
switch(RFIFOW(fd,0)) {
@@ -5095,10 +5097,12 @@ int char_parse_char(int fd)
//For use in packets that depend on an sd being present [Skotlex]
#define FIFOSD_CHECK(rest) do { if(RFIFOREST(fd) < (rest)) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,(rest)); return 0; } } while (0)
- if( HPM->packetsc[hpParse_Char] ) {
- int success = HPM->parse_packets(fd,hpParse_Char);
- if( success == 1 ) continue;
- else if( success == 2 ) return 0;
+ if (VECTOR_LENGTH(HPM->packets[hpParse_Char]) > 0) {
+ int result = HPM->parse_packets(fd,hpParse_Char);
+ if (result == 1)
+ continue;
+ if (result == 2)
+ return 0;
}
cmd = RFIFOW(fd,0);
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 12b879357..0bbfbbb49 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -138,24 +138,27 @@ struct hplugin *hplugin_create(void)
return plugin;
}
-bool hplugins_addpacket(unsigned short cmd, unsigned short length, void (*receive) (int fd), unsigned int point,unsigned int pluginID) {
+bool hplugins_addpacket(unsigned short cmd, unsigned short length, void (*receive) (int fd), unsigned int point, unsigned int pluginID)
+{
struct HPluginPacket *packet;
- unsigned int i;
+ int i;
- if( point >= hpPHP_MAX ) {
+ if (point >= hpPHP_MAX) {
ShowError("HPM->addPacket:%s: unknown point '%u' specified for packet 0x%04x (len %d)\n",HPM->pid2name(pluginID),point,cmd,length);
return false;
}
- for(i = 0; i < HPM->packetsc[point]; i++) {
- if( HPM->packets[point][i].cmd == cmd ) {
- ShowError("HPM->addPacket:%s: can't add packet 0x%04x, already in use by '%s'!",HPM->pid2name(pluginID),cmd,HPM->pid2name(HPM->packets[point][i].pluginID));
+ for (i = 0; i < VECTOR_LENGTH(HPM->packets[point]); i++) {
+ if (VECTOR_INDEX(HPM->packets[point], i).cmd == cmd ) {
+ ShowError("HPM->addPacket:%s: can't add packet 0x%04x, already in use by '%s'!",
+ HPM->pid2name(pluginID), cmd, HPM->pid2name(VECTOR_INDEX(HPM->packets[point], i).pluginID));
return false;
}
}
- RECREATE(HPM->packets[point], struct HPluginPacket, ++HPM->packetsc[point]);
- packet = &HPM->packets[point][HPM->packetsc[point] - 1];
+ VECTOR_ENSURE(HPM->packets[point], 1, 1);
+ VECTOR_PUSHZEROED(HPM->packets[point]);
+ packet = &VECTOR_LAST(HPM->packets[point]);
packet->pluginID = pluginID;
packet->cmd = cmd;
@@ -646,34 +649,37 @@ CPCMD(plugins)
}
}
-/*
- 0 = unknown
- 1 = OK
- 2 = incomplete
+/**
+ * Parses a packet through the registered plugin.
+ *
+ * @param fd The connection fd.
+ * @param point The packet hooking point.
+ * @retval 0 unknown packet
+ * @retval 1 OK
+ * @retval 2 incomplete packet
*/
-unsigned char hplugins_parse_packets(int fd, enum HPluginPacketHookingPoints point) {
- unsigned int i;
+unsigned char hplugins_parse_packets(int fd, enum HPluginPacketHookingPoints point)
+{
+ struct HPluginPacket *packet = NULL;
+ int i;
+ int16 length;
- for(i = 0; i < HPM->packetsc[point]; i++) {
- if( HPM->packets[point][i].cmd == RFIFOW(fd,0) )
- break;
- }
+ ARR_FIND(0, VECTOR_LENGTH(HPM->packets[point]), i, VECTOR_INDEX(HPM->packets[point], i).cmd == RFIFOW(fd,0));
- if( i != HPM->packetsc[point] ) {
- struct HPluginPacket *packet = &HPM->packets[point][i];
- short length;
+ if (i == VECTOR_LENGTH(HPM->packets[point]))
+ return 0;
- if( (length = packet->len) == -1 ) {
- if( (length = RFIFOW(fd, 2)) > (int)RFIFOREST(fd) )
- return 2;
- }
+ packet = &VECTOR_INDEX(HPM->packets[point], i);
+ length = packet->len;
+ if (length == -1)
+ length = RFIFOW(fd, 2);
- packet->receive(fd);
- RFIFOSKIP(fd, length);
- return 1;
- }
+ if (length > (int)RFIFOREST(fd))
+ return 2;
- return 0;
+ packet->receive(fd);
+ RFIFOSKIP(fd, length);
+ return 1;
}
/**
@@ -802,7 +808,7 @@ void HPM_datacheck_final(void) {
}
void hpm_init(void) {
- unsigned int i;
+ int i;
datacheck_db = NULL;
datacheck_data = NULL;
datacheck_version = 0;
@@ -827,9 +833,8 @@ void hpm_init(void) {
return;
}
- for(i = 0; i < hpPHP_MAX; i++) {
- HPM->packets[i] = NULL;
- HPM->packetsc[i] = 0;
+ for (i = 0; i < hpPHP_MAX; i++) {
+ VECTOR_INIT(HPM->packets[i]);
}
#ifdef CONSOLE_INPUT
@@ -851,7 +856,7 @@ void hpm_memdown(void)
}
void hpm_final(void)
{
- unsigned int i;
+ int i;
HPM->off = true;
@@ -865,9 +870,8 @@ void hpm_final(void)
}
VECTOR_CLEAR(HPM->symbols);
- for( i = 0; i < hpPHP_MAX; i++ ) {
- if( HPM->packets[i] )
- aFree(HPM->packets[i]);
+ for (i = 0; i < hpPHP_MAX; i++) {
+ VECTOR_CLEAR(HPM->packets[i]);
}
for( i = 0; i < HPCT_MAX; i++ ) {
@@ -899,10 +903,6 @@ void hpm_defaults(void) {
/* */
HPM->fnames = NULL;
HPM->fnamec = 0;
- for(i = 0; i < hpPHP_MAX; i++) {
- HPM->packets[i] = NULL;
- HPM->packetsc[i] = 0;
- }
for(i = 0; i < HPCT_MAX; i++) {
HPM->confs[i] = NULL;
HPM->confsc[i] = 0;
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 6d44cd474..adbba5eda 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -109,8 +109,7 @@ struct HPM_interface {
VECTOR_DECL(struct hplugin *) plugins;
VECTOR_DECL(struct hpm_symbol *) symbols;
/* packet hooking points */
- struct HPluginPacket *packets[hpPHP_MAX];
- unsigned int packetsc[hpPHP_MAX];
+ VECTOR_DECL(struct HPluginPacket) packets[hpPHP_MAX];
/* plugin file ptr caching */
struct HPMFileNameCache *fnames;
unsigned int fnamec;
diff --git a/src/login/login.c b/src/login/login.c
index 572bd594f..1d8ef489a 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -768,7 +768,7 @@ void login_fromchar_parse_accinfo(int fd)
//--------------------------------
int login_parse_fromchar(int fd)
{
- int j, id;
+ int id;
uint32 ipl;
char ip[16];
@@ -795,11 +795,12 @@ int login_parse_fromchar(int fd)
while( RFIFOREST(fd) >= 2 ) {
uint16 command = RFIFOW(fd,0);
- if( HPM->packetsc[hpParse_FromChar] ) {
- if( (j = HPM->parse_packets(fd,hpParse_FromChar)) ) {
- if( j == 1 ) continue;
- if( j == 2 ) return 0;
- }
+ if (VECTOR_LENGTH(HPM->packets[hpParse_FromChar]) > 0) {
+ int result = HPM->parse_packets(fd,hpParse_FromChar);
+ if (result == 1)
+ continue;
+ if (result == 2)
+ return 0;
}
switch( command ) {
@@ -1574,7 +1575,6 @@ void login_parse_request_connection(int fd, struct login_session_data* sd, const
int login_parse_login(int fd)
{
struct login_session_data* sd = (struct login_session_data*)sockt->session[fd]->session_data;
- int result;
char ip[16];
uint32 ipl = sockt->session[fd]->client_addr;
@@ -1608,11 +1608,12 @@ int login_parse_login(int fd)
while( RFIFOREST(fd) >= 2 ) {
uint16 command = RFIFOW(fd,0);
- if( HPM->packetsc[hpParse_Login] ) {
- if( (result = HPM->parse_packets(fd,hpParse_Login)) ) {
- if( result == 1 ) continue;
- if( result == 2 ) return 0;
- }
+ if (VECTOR_LENGTH(HPM->packets[hpParse_Login]) > 0) {
+ int result = HPM->parse_packets(fd,hpParse_Login);
+ if (result == 1)
+ continue;
+ if (result == 2)
+ return 0;
}
switch( command ) {
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 1e376e3bc..a27038ff7 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -1351,7 +1351,7 @@ void chrif_skillid2idx(int fd) {
*
*------------------------------------------*/
int chrif_parse(int fd) {
- int packet_len, cmd, r;
+ int packet_len, cmd;
// only process data from the char-server
if ( fd != chrif->fd ) {
@@ -1375,22 +1375,22 @@ int chrif_parse(int fd) {
}
}
- while ( RFIFOREST(fd) >= 2 ) {
-
- if( HPM->packetsc[hpChrif_Parse] ) {
- if( (r = HPM->parse_packets(fd,hpChrif_Parse)) ) {
- if( r == 1 ) continue;
- if( r == 2 ) return 0;
- }
+ while (RFIFOREST(fd) >= 2) {
+ if (VECTOR_LENGTH(HPM->packets[hpChrif_Parse]) > 0) {
+ int result = HPM->parse_packets(fd,hpChrif_Parse);
+ if (result == 1)
+ continue;
+ if (result == 2)
+ return 0;
}
cmd = RFIFOW(fd,0);
if (cmd < 0x2af8 || cmd >= 0x2af8 + ARRAYLENGTH(chrif->packet_len_table) || chrif->packet_len_table[cmd-0x2af8] == 0) {
- r = intif->parse(fd); // Passed on to the intif
+ int result = intif->parse(fd); // Passed on to the intif
- if (r == 1) continue; // Treated in intif
- if (r == 2) return 0; // Didn't have enough data (len==-1)
+ if (result == 1) continue; // Treated in intif
+ if (result == 2) return 0; // Didn't have enough data (len==-1)
ShowWarning("chrif_parse: session #%d, intif->parse failed (unrecognized command 0x%.4x).\n", fd, cmd);
sockt->eof(fd);
diff --git a/src/map/clif.c b/src/map/clif.c
index 59c8a7197..9c7d327e6 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -18578,12 +18578,12 @@ int clif_parse(int fd) {
if (RFIFOREST(fd) < 2)
return 0;
- if( HPM->packetsc[hpClif_Parse] ) {
- int r;
- if( (r = HPM->parse_packets(fd,hpClif_Parse)) ) {
- if( r == 1 ) continue;
- if( r == 2 ) return 0;
- }
+ if (VECTOR_LENGTH(HPM->packets[hpClif_Parse]) > 0) {
+ int result = HPM->parse_packets(fd,hpClif_Parse);
+ if (result == 1)
+ continue;
+ if (result == 2)
+ return 0;
}
if( sd )