summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreathenabot <eathenabot@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-11-09 18:15:02 +0000
committereathenabot <eathenabot@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-11-09 18:15:02 +0000
commit61c5676bfe3ee9dcb6fd3f5d06fd9fdf9c54b037 (patch)
tree60b30c788e2833b4f3c021da4ee8445055612e3a
parent01417c0ad837f9113c2e8731b00531cf6535ee3e (diff)
downloadhercules-61c5676bfe3ee9dcb6fd3f5d06fd9fdf9c54b037.tar.gz
hercules-61c5676bfe3ee9dcb6fd3f5d06fd9fdf9c54b037.tar.bz2
hercules-61c5676bfe3ee9dcb6fd3f5d06fd9fdf9c54b037.tar.xz
hercules-61c5676bfe3ee9dcb6fd3f5d06fd9fdf9c54b037.zip
* Merged eAthena changeset ea:15119.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16891 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--src/map/clif.c104
-rw-r--r--src/map/clif.h1
2 files changed, 36 insertions, 69 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 2ef0ee796..1dc1e3b11 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -5382,6 +5382,34 @@ void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val
}
+/// Notification about an another object's chat message (ZC_NOTIFY_CHAT).
+/// 008d <packet len>.W <id>.L <message>.?B
+void clif_notify_chat(struct block_list* bl, const char* message, send_target target)
+{
+ char buf[8+255+1];
+ size_t length;
+
+ if( !message[0] )
+ {// empty message
+ return;
+ }
+
+ length = strlen(message);
+
+ if( length > sizeof(buf)-8 )
+ {
+ ShowWarning("clif_notify_chat: Truncated message '%s' (len=%u, max=%u, id=%d, target=%d).\n", message, length, sizeof(buf)-8, bl ? bl->id : 0, target);
+ length = sizeof(buf)-8;
+ }
+
+ WBUFW(buf,0) = 0x8d;
+ WBUFW(buf,2) = 8+length;
+ WBUFL(buf,4) = bl ? bl->id : 0;
+ safestrncpy((char*)WBUFP(buf,8), message, length+1);
+ clif_send(buf, WBUFW(buf,2), bl, target);
+}
+
+
/// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
/// 008e <packet len>.W <message>.?B
void clif_displaymessage(const int fd, const char* mes)
@@ -5440,27 +5468,7 @@ void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, e
*------------------------------------------*/
void clif_GlobalMessage(struct block_list* bl, const char* message)
{
- char buf[100];
- int len;
-
- nullpo_retv(bl);
-
- if(!message)
- return;
-
- len = strlen(message)+1;
-
- if( len > sizeof(buf)-8 )
- {
- ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
- len = sizeof(buf)-8;
- }
-
- WBUFW(buf,0)=0x8d;
- WBUFW(buf,2)=len+8;
- WBUFL(buf,4)=bl->id;
- safestrncpy((char *) WBUFP(buf,8),message,len);
- clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
+ clif_notify_chat(bl, message, ALL_CLIENT);
}
/*==========================================
@@ -5468,22 +5476,7 @@ void clif_GlobalMessage(struct block_list* bl, const char* message)
*------------------------------------------*/
void clif_MainChatMessage(const char* message)
{
- uint8 buf[200];
- int len;
-
- if(!message)
- return;
-
- len = strlen(message)+1;
- if (len+8 > sizeof(buf)) {
- ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
- len = sizeof(buf)-8;
- }
- WBUFW(buf,0)=0x8d;
- WBUFW(buf,2)=len+8;
- WBUFL(buf,4)=0;
- safestrncpy((char *) WBUFP(buf,8),message,len);
- clif_send(buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
+ clif_notify_chat(NULL, message, CHAT_MAINCHAT);
}
@@ -8206,27 +8199,10 @@ void clif_messagecolor(struct block_list* bl, unsigned long color, const char* m
}
-/// Public chat message [Valaris] (ZC_NOTIFY_CHAT).
-/// 008d <packet len>.W <id>.L <message>.?B
+/// Public chat message [Valaris]
void clif_message(struct block_list* bl, const char* msg)
{
- unsigned short msg_len = strlen(msg) + 1;
- uint8 buf[256];
- // TODO: Merge with other 0x8d functions.
- nullpo_retv(bl);
-
- if( msg_len > sizeof(buf)-8 )
- {
- ShowWarning("clif_message: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
- msg_len = sizeof(buf)-8;
- }
-
- WBUFW(buf,0) = 0x8d;
- WBUFW(buf,2) = msg_len + 8;
- WBUFL(buf,4) = bl->id;
- safestrncpy((char*)WBUFP(buf,8), msg, msg_len);
-
- clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
+ clif_notify_chat(bl, msg, AREA_CHAT_WOC);
}
@@ -8520,11 +8496,7 @@ void clif_disp_overhead(struct map_session_data *sd, const char* mes)
len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
}
// send message to others
- WBUFW(buf,0) = 0x8d;
- WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
- WBUFL(buf,4) = sd->bl.id;
- safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
- clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
+ clif_notify_chat(&sd->bl, mes, AREA_CHAT_WOC);
// send back message to the speaker
WBUFW(buf,0) = 0x8e;
@@ -9669,14 +9641,8 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
strcat(fakename, message);
textlen = strlen(fakename) + 1;
}
- // send message to others (using the send buffer for temp. storage)
- WFIFOHEAD(fd, 8 + textlen);
- WFIFOW(fd,0) = 0x8d;
- WFIFOW(fd,2) = 8 + textlen;
- WFIFOL(fd,4) = sd->bl.id;
- safestrncpy((char*)WFIFOP(fd,8), is_fake ? fakename : text, textlen);
- //FIXME: chat has range of 9 only
- clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
+ // send message to others
+ clif_notify_chat(&sd->bl, is_fake ? fakename : text, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
// send back message to the speaker
if( is_fake ) {
diff --git a/src/map/clif.h b/src/map/clif.h
index e92dc4db5..1079d54ca 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -569,6 +569,7 @@ void clif_instance_leave(int fd);
void clif_font(struct map_session_data *sd);
// atcommand
+void clif_notify_chat(struct block_list* bl, const char* message, send_target target);
void clif_displaymessage(const int fd, const char* mes);
void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len);
void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target);