Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: clif.c
- ===================================================================
- --- clif.c (revisão 16294)
- +++ clif.c (cópia de trabalho)
- @@ -5309,8 +5309,63 @@
- }
- -/// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
- +/// 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)-9 )
- + {
- + ShowWarning("clif_notify_chat: Truncated message '%s' (len=%u, max=%u, id=%d, target=%d).\n", message, length, sizeof(buf)-9, bl ? bl->id : 0, target);
- + length = sizeof(buf)-9;
- + }
- +
- + WBUFW(buf,0) = 0x8d;
- + WBUFW(buf,2) = 8+length+1; // header + message + NUL
- + WBUFL(buf,4) = bl ? bl->id : 0;
- + safestrncpy((char*)WBUFP(buf,8), message, length+1);
- + clif_send(buf, WBUFW(buf,2), bl, target);
- +}
- +
- +
- +/// Notification about player's own chat message (ZC_NOTIFY_PLAYERCHAT).
- /// 008e <packet len>.W <message>.?B
- +void clif_notify_playerchat(struct map_session_data* sd, const char* message)
- +{
- + int fd = sd->fd;
- + size_t length;
- +
- + if( !message[0] )
- + {// don't send a void message (it's not displaying on the client chat). @help can send void line.
- + return;
- + }
- +
- + length = strlen(message);
- +
- + if( length > 255 )
- + {// message is limited to 255+1 characters by the client-side buffer
- + ShowWarning("clif_notify_playerchat: Truncated message '%s' (len=%u, max=%u, char_id=%d).\n", message, length, 255, sd->status.char_id);
- + length = 255;
- + }
- +
- + WFIFOHEAD(fd,4+length+1);
- + WFIFOW(fd,0) = 0x8e;
- + WFIFOW(fd,2) = 4+length+1; // header + message + NUL
- + safestrncpy((char*)WFIFOP(fd,4), message, length+1);
- + WFIFOSET(fd,WFIFOW(fd,2));
- +}
- +
- +
- +/// Send message (modified by [Yor])
- void clif_displaymessage(const int fd, const char* mes)
- {
- nullpo_retv(mes);
- @@ -5337,9 +5392,31 @@
- line = strtok(NULL, "\n");
- }
- aFree(message);
- + // clif_notify_playerchat((struct map_session_data*)(session[fd]->session_data), mes);
- }
- }
- +/// Send formatted message
- +void clif_displayformatted(struct map_session_data* sd, const char* fmt, ...)
- +{
- + int n;
- + char buf[255+1];
- + va_list args;
- +
- + va_start(args, fmt);
- + n = vsnprintf(buf, sizeof(buf), fmt, args);
- + va_end(args);
- +
- + if( n < 1 || n >= sizeof(buf) )
- + {
- + ShowError("Too long message with format '%s' (n=%d).\n", fmt, n);
- + return;
- + }
- +
- + clif_notify_playerchat(sd, buf);
- +}
- +
- +
- /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
- /// 009a <packet len>.W <message>.?B
- void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
- @@ -5367,27 +5444,7 @@
- *------------------------------------------*/
- 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);
- }
- /*==========================================
- @@ -5395,22 +5452,7 @@
- *------------------------------------------*/
- 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);
- }
- @@ -8129,27 +8171,10 @@
- }
- -/// 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);
- }
- @@ -8430,25 +8455,11 @@
- *------------------------------------------*/
- void clif_disp_overhead(struct map_session_data *sd, const char* mes)
- {
- - unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
- - int len_mes = strlen(mes)+1; //Account for \0
- -
- - if (len_mes > sizeof(buf)-8) {
- - ShowError("clif_disp_overhead: Message too long (length %d)\n", len_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;
- - WBUFW(buf, 2) = len_mes + 4;
- - safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
- - clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
- + clif_notify_playerchat(sd, mes);
- }
- /*==========================
- @@ -9561,14 +9572,8 @@
- 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, text, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
- // send back message to the speaker
- if( is_fake ) {
- Index: clif.h
- ===================================================================
- --- clif.h (revisão 16294)
- +++ clif.h (cópia de trabalho)
- @@ -555,7 +555,10 @@
- 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_notify_playerchat(struct map_session_data* sd, const char* message);
- void clif_displaymessage(const int fd, const char* mes);
- +void clif_displayformatted(struct map_session_data* sd, const char* fmt, ...);
- 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);
- void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement