summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-10-04 22:50:36 +0200
committerHaru <haru@dotalux.com>2015-10-04 22:50:36 +0200
commitacbbba21c888c7e8c9a6c31652dfd61c90ca6ac8 (patch)
tree3758e0d16b4090f31271682f86133f34598cee97 /src
parent4db986b93566d673c226971fa045f1dc99645242 (diff)
downloadhercules-acbbba21c888c7e8c9a6c31652dfd61c90ca6ac8.tar.gz
hercules-acbbba21c888c7e8c9a6c31652dfd61c90ca6ac8.tar.bz2
hercules-acbbba21c888c7e8c9a6c31652dfd61c90ca6ac8.tar.xz
hercules-acbbba21c888c7e8c9a6c31652dfd61c90ca6ac8.zip
Added clif->packet() to retrieve info about a packet.
- As per Malufett/Michieru request, in order to make it possible for a plugin to obtain information about a packet. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
-rw-r--r--src/map/atcommand.c8
-rw-r--r--src/map/clif.c14
-rw-r--r--src/map/clif.h6
3 files changed, 19 insertions, 9 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 37f50dc5e..15422a74a 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -242,16 +242,16 @@ ACMD(send)
}\
} while(0) //define GET_VALUE
- if (type > 0 && type < MAX_PACKET_DB) {
+ if (type >= MIN_PACKET_DB && type <= MAX_PACKET_DB) {
int off = 2;
if (len) {
// show packet length
- safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,904), type, packet_db[type].len); // Packet 0x%x length: %d
+ safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,904), type, clif->packet(type)->len); // Packet 0x%x length: %d
clif->message(fd, atcmd_output);
return true;
}
- len=packet_db[type].len;
+ len = clif->packet(type)->len;
if (len == 0) {
// unknown packet - ERROR
safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,905), type); // Unknown packet: 0x%x
@@ -402,7 +402,7 @@ ACMD(send)
SKIP_VALUE(message);
}
- if(packet_db[type].len == -1) {// send dynamic packet
+ if (clif->packet(type)->len == -1) { // send dynamic packet
WFIFOW(sd->fd,2)=TOW(off);
WFIFOSET(sd->fd,off);
} else {// send static packet
diff --git a/src/map/clif.c b/src/map/clif.c
index 243aa6a43..59c8a7197 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -18680,6 +18680,19 @@ int clif_parse(int fd) {
return 0;
}
+/**
+ * Returns information about the given packet ID.
+ *
+ * @param packet_id The packet ID.
+ * @return The corresponding packet_db entry, if any.
+ */
+const struct s_packet_db *clif_packet(int packet_id)
+{
+ if (packet_id < MIN_PACKET_DB || packet_id > MAX_PACKET_DB || packet_db[packet_id].len == 0)
+ return NULL;
+ return &packet_db[packet_id];
+}
+
static void __attribute__ ((unused)) packetdb_addpacket(short cmd, int len, ...) {
va_list va;
int i;
@@ -18815,6 +18828,7 @@ void clif_defaults(void) {
clif->parse = clif_parse;
clif->parse_cmd = clif_parse_cmd_optional;
clif->decrypt_cmd = clif_decrypt_cmd;
+ clif->packet = clif_packet;
/* auth */
clif->authok = clif_authok;
clif->authrefuse = clif_authrefuse;
diff --git a/src/map/clif.h b/src/map/clif.h
index f6f0d4fe7..40610b7c1 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -597,6 +597,7 @@ struct clif_interface {
int (*send_sub) (struct block_list *bl, va_list ap);
int (*send_actual) (int fd, void *buf, int len);
int (*parse) (int fd);
+ const struct s_packet_db *(*packet) (int packet_id);
unsigned short (*parse_cmd) ( int fd, struct map_session_data *sd );
unsigned short (*decrypt_cmd) ( int cmd, struct map_session_data *sd );
/* auth */
@@ -1323,11 +1324,6 @@ struct clif_interface {
};
#ifdef HERCULES_CORE
-/**
- * Vars
- **/
-extern struct s_packet_db packet_db[MAX_PACKET_DB + 1];
-
void clif_defaults(void);
#endif // HERCULES_CORE