From 88cfff01e6b06cee8ed1b890c6c9a5ae23b8882d Mon Sep 17 00:00:00 2001 From: icxbb-xx Date: Wed, 12 Aug 2015 22:20:48 +0700 Subject: [PATCH] Follow up to 58c2b77 * Fixed #484,Client Crashing 2014-10-22, thank you @gengstergile, @limitro * small fix script command --- src/map/clif.c | 40 +++++++++++++++++++++------------------- src/map/script.c | 6 +++--- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/map/clif.c b/src/map/clif.c index 30dd9eb918..f76ab480da 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -5759,30 +5759,32 @@ void clif_displaymessage(const int fd, const char* mes) if (fd == 0) ; else { -#if PACKETVER == 20141022 - /** for some reason game client crashes depending on message pattern (only for this packet) **/ - /** so we redirect to ZC_NPC_CHAT **/ - //clif_colormes(fd, color_table[COLOR_DEFAULT], mes); - unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR - unsigned short len = strnlen(mes, CHAT_SIZE_MAX); - - if (len > 0) { - WFIFOHEAD(fd, 13 + len); - WFIFOW(fd, 0) = 0x2C1; - WFIFOW(fd, 2) = 13 + len; - WFIFOL(fd, 4) = 0; - WFIFOL(fd, 8) = color; - safestrncpy((char*)WFIFOP(fd, 12), mes, len+1); - WFIFOSET(fd, WFIFOW(fd, 2)); - } -#else char *message, *line; message = aStrdup(mes); line = strtok(message, "\n"); + +#if PACKETVER == 20141022 + /** for some reason game client crashes depending on message pattern (only for this packet) **/ + /** so we redirect to ZC_NPC_CHAT **/ + //clif_colormes(fd, color_table[COLOR_DEFAULT], mes); + while(line != NULL) { + unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR + unsigned short len = strnlen(line, CHAT_SIZE_MAX); + + if (len > 0) { + WFIFOHEAD(fd, 13 + len); + WFIFOW(fd, 0) = 0x2C1; + WFIFOW(fd, 2) = 13 + len; + WFIFOL(fd, 4) = 0; + WFIFOL(fd, 8) = color; + safestrncpy((char*)WFIFOP(fd, 12), line, len + 1); + WFIFOSET(fd, WFIFOW(fd, 2)); + } +#else while(line != NULL) { // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client) - int len = strnlen(line, 255); + int len = strnlen(line, CHAT_SIZE_MAX); if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line. WFIFOHEAD(fd, 5 + len); @@ -5791,10 +5793,10 @@ void clif_displaymessage(const int fd, const char* mes) safestrncpy((char *)WFIFOP(fd,4), line, len + 1); WFIFOSET(fd, 5 + len); } +#endif line = strtok(NULL, "\n"); } aFree(message); -#endif } } diff --git a/src/map/script.c b/src/map/script.c index c7f59730c0..0cb29a51fe 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -11113,7 +11113,7 @@ BUILDIN_FUNC(waitingroomkick) if( nd != NULL && (cd=(struct chat_data *)map_id2bl(nd->chat_id)) != NULL ) chat_npckickchat(cd, kickusername); - return 0; + return SCRIPT_CMD_SUCCESS; } /// Get Users in waiting room and stores gids in .@waitingroom_users[] @@ -11139,7 +11139,7 @@ BUILDIN_FUNC(getwaitingroomusers) } setd_sub(st, NULL, ".@waitingroom_usercount", 0, (void *)__64BPRTSIZE(j), NULL); } - return 0; + return SCRIPT_CMD_SUCCESS; } /// Kicks all the players from the waiting room of the current or target npc. @@ -20338,7 +20338,7 @@ BUILDIN_FUNC(showscript) { } if (!bl) { - ShowError("buildin_showscript: Script not attached. (id=%, rid=%d, oid=%d)\n", id, st->rid, st->oid); + ShowError("buildin_showscript: Script not attached. (id=%d, rid=%d, oid=%d)\n", id, st->rid, st->oid); script_pushint(st,0); return SCRIPT_CMD_FAILURE; }