diff options
author | Asheraf <acheraf1998@gmail.com> | 2018-05-26 23:37:18 +0000 |
---|---|---|
committer | Asheraf <acheraf1998@gmail.com> | 2018-06-30 00:33:47 +0100 |
commit | 8ea98a7ff92e0f34f323342b1d69da42d92f39ae (patch) | |
tree | 7fb2e6a0f641ecfdd062b66c19d57088a1b2dae1 /src/map/clif.c | |
parent | a2cfc93a840e51fb1cc1ab132273890c200a9cd3 (diff) | |
download | hercules-8ea98a7ff92e0f34f323342b1d69da42d92f39ae.tar.gz hercules-8ea98a7ff92e0f34f323342b1d69da42d92f39ae.tar.bz2 hercules-8ea98a7ff92e0f34f323342b1d69da42d92f39ae.tar.xz hercules-8ea98a7ff92e0f34f323342b1d69da42d92f39ae.zip |
split clif_disp_overhead into 2 functions and convert to struct format
Diffstat (limited to 'src/map/clif.c')
-rw-r--r-- | src/map/clif.c | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/src/map/clif.c b/src/map/clif.c index 820a219f6..654c43b53 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -8967,31 +8967,52 @@ void clif_slide(struct block_list *bl, int x, int y) /// 008d <packet len>.W <id>.L <message>.?B void clif_disp_overhead(struct block_list *bl, const char *mes) { - unsigned char buf[256]; //This should be more than sufficient, the theoretical max is CHAT_SIZE + 8 (pads and extra inserted crap) + char buf[CHAT_SIZE_MAX + (int)sizeof(struct PACKET_ZC_NOTIFY_CHAT)]; + uint32 max_len = CHAT_SIZE_MAX - (int)sizeof(struct PACKET_ZC_NOTIFY_CHAT); + struct PACKET_ZC_NOTIFY_CHAT *p = (struct PACKET_ZC_NOTIFY_CHAT *)&buf; int mes_len; nullpo_retv(bl); nullpo_retv(mes); - mes_len = (int)strlen(mes)+1; //Account for \0 - if (mes_len > (int)sizeof(buf)-8) { - ShowError("clif_disp_overhead: Message too long (length %d)\n", mes_len); - mes_len = sizeof(buf)-8; //Trunk it to avoid problems. + mes_len = (int)strlen(mes) + 1; //Account for \0 + if (mes_len > max_len) { + ShowError("clif_disp_overhead: Truncated message '%s' (len=%d, max=%u).\n", mes, mes_len, max_len); + mes_len = max_len; //Trunk it to avoid problems. } + // send message to others - WBUFW(buf,0) = 0x8d; - WBUFW(buf,2) = mes_len + 8; // len of message + 8 (command+len+id) - WBUFL(buf,4) = bl->id; - safestrncpy(WBUFP(buf,8), mes, mes_len); - clif->send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); + p->PacketType = 0x8d; + p->PacketLength = mes_len + (int)sizeof(struct PACKET_ZC_NOTIFY_CHAT); // len of message + 8 (command+len+id) + p->GID = bl->id; + safestrncpy(p->Message, mes, mes_len); + clif->send(p, p->PacketLength, bl, AREA_CHAT_WOC); // send back message to the speaker - if (bl->type == BL_PC) { - WBUFW(buf,0) = 0x8e; - WBUFW(buf, 2) = mes_len + 4; - safestrncpy(WBUFP(buf,4), mes, mes_len); - clif->send(buf, WBUFW(buf,2), bl, SELF); + if (bl->type == BL_PC) + clif->notify_playerchat(bl, mes); +} + +void clif_notify_playerchat(struct block_list *bl, const char *mes) +{ + char buf[CHAT_SIZE_MAX + (int)sizeof(struct PACKET_ZC_NOTIFY_PLAYERCHAT)]; + uint32 max_len = CHAT_SIZE_MAX - (int)sizeof(struct PACKET_ZC_NOTIFY_PLAYERCHAT); + struct PACKET_ZC_NOTIFY_PLAYERCHAT *p = (struct PACKET_ZC_NOTIFY_PLAYERCHAT *)&buf; + int mes_len; + + nullpo_retv(bl); + nullpo_retv(mes); + + mes_len = (int)strlen(mes) + 1; // Account for \0 + if (mes_len > max_len) { + ShowError("clif_notify_playerchat: Truncated message '%s' (len=%d, max=%u).\n", mes, mes_len, max_len); + mes_len = max_len; // Truncate to avoid problems. } + + p->PacketType = 0x8e; + p->PacketLength = mes_len + (int)sizeof(struct PACKET_ZC_NOTIFY_PLAYERCHAT); + safestrncpy(p->Message, mes, mes_len); + clif->send(p, p->PacketLength, bl, SELF); } /*========================== @@ -21624,6 +21645,7 @@ void clif_defaults(void) { clif->messagecolor_self = clif_messagecolor_self; clif->messagecolor = clif_messagecolor; clif->disp_overhead = clif_disp_overhead; + clif->notify_playerchat = clif_notify_playerchat; clif->msgtable_skill = clif_msgtable_skill; clif->msgtable = clif_msgtable; clif->msgtable_num = clif_msgtable_num; |