summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-01-07 03:24:06 +0100
committerHaru <haru@dotalux.com>2016-02-24 19:40:31 +0100
commita9326b175d42b9f6448d97b52108be907194854c (patch)
tree91c9b0e594217bf54130709beeed588f6d830a5a
parent9ee06831aec11a8ffea77f3b5c81465579f993e9 (diff)
downloadhercules-a9326b175d42b9f6448d97b52108be907194854c.tar.gz
hercules-a9326b175d42b9f6448d97b52108be907194854c.tar.bz2
hercules-a9326b175d42b9f6448d97b52108be907194854c.tar.xz
hercules-a9326b175d42b9f6448d97b52108be907194854c.zip
Added const qualifier to the {RFIFO,RBUF}{B,W,L,Q} families
A read FIFO/buffer should be, well, read-only. Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r--src/common/socket.h18
-rw-r--r--src/map/clif.c4
2 files changed, 12 insertions, 10 deletions
diff --git a/src/common/socket.h b/src/common/socket.h
index e1ea94f5a..29f3eb3d7 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -50,13 +50,13 @@ struct config_setting_t;
#define RFIFOP(fd,pos) (sockt->session[fd]->rdata + sockt->session[fd]->rdata_pos + (pos))
#define WFIFOP(fd,pos) (sockt->session[fd]->wdata + sockt->session[fd]->wdata_size + (pos))
-#define RFIFOB(fd,pos) (*(uint8*)RFIFOP((fd),(pos)))
+#define RFIFOB(fd,pos) (*(const uint8*)RFIFOP((fd),(pos)))
#define WFIFOB(fd,pos) (*(uint8*)WFIFOP((fd),(pos)))
-#define RFIFOW(fd,pos) (*(uint16*)RFIFOP((fd),(pos)))
+#define RFIFOW(fd,pos) (*(const uint16*)RFIFOP((fd),(pos)))
#define WFIFOW(fd,pos) (*(uint16*)WFIFOP((fd),(pos)))
-#define RFIFOL(fd,pos) (*(uint32*)RFIFOP((fd),(pos)))
+#define RFIFOL(fd,pos) (*(const uint32*)RFIFOP((fd),(pos)))
#define WFIFOL(fd,pos) (*(uint32*)WFIFOP((fd),(pos)))
-#define RFIFOQ(fd,pos) (*(uint64*)RFIFOP((fd),(pos)))
+#define RFIFOQ(fd,pos) (*(const uint64*)RFIFOP((fd),(pos)))
#define WFIFOQ(fd,pos) (*(uint64*)WFIFOP((fd),(pos)))
#define RFIFOSPACE(fd) (sockt->session[fd]->max_rdata - sockt->session[fd]->rdata_size)
#define WFIFOSPACE(fd) (sockt->session[fd]->max_wdata - sockt->session[fd]->wdata_size)
@@ -85,11 +85,11 @@ struct config_setting_t;
#define WP2PTR(fd) WFIFO2PTR(fd)
// buffer I/O macros
-#define RBUFP(p,pos) (((const uint8*)(p)) + (pos))
-#define RBUFB(p,pos) (*(const uint8*)RBUFP((p),(pos)))
-#define RBUFW(p,pos) (*(const uint16*)RBUFP((p),(pos)))
-#define RBUFL(p,pos) (*(const uint32*)RBUFP((p),(pos)))
-#define RBUFQ(p,pos) (*(const uint64*)RBUFP((p),(pos)))
+#define RBUFP(p,pos) (((const uint8 *)(p)) + (pos))
+#define RBUFB(p,pos) (*(const uint8 *)RBUFP((p),(pos)))
+#define RBUFW(p,pos) (*(const uint16 *)RBUFP((p),(pos)))
+#define RBUFL(p,pos) (*(const uint32 *)RBUFP((p),(pos)))
+#define RBUFQ(p,pos) (*(const uint64 *)RBUFP((p),(pos)))
#define WBUFP(p,pos) (((uint8*)(p)) + (pos))
#define WBUFB(p,pos) (*(uint8*)WBUFP((p),(pos)))
diff --git a/src/map/clif.c b/src/map/clif.c
index a7d73d91f..a7d7dca97 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -18787,7 +18787,9 @@ int clif_parse(int fd) {
return 0; // not enough data received to form the packet
if( battle_config.packet_obfuscation == 2 || cmd != RFIFOW(fd, 0) || (sd && sd->parse_cmd_func == clif_parse_cmd_decrypt) ) {
- RFIFOW(fd, 0) = cmd;
+ // Note: Overriding const qualifier to re-inject the decoded packet ID.
+ int16 *packet_id = (int16 *)RFIFOP(fd, 0);
+ *packet_id = cmd;
if( sd ) {
sd->cryptKey = (( sd->cryptKey * clif->cryptKey[1] ) + clif->cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
}