Advertisement
Guest User

r15119&r15120

a guest
Jun 14th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.39 KB | None | 0 0
  1. Index: clif.c
  2. ===================================================================
  3. --- clif.c  (revisão 16294)
  4. +++ clif.c  (cópia de trabalho)
  5. @@ -5309,8 +5309,63 @@
  6.  }
  7.  
  8.  
  9. -/// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  10. +/// Notification about an another object's chat message (ZC_NOTIFY_CHAT).
  11. +/// 008d <packet len>.W <id>.L <message>.?B
  12. +void clif_notify_chat(struct block_list* bl, const char* message, send_target target)
  13. +{
  14. +   char buf[8+255+1];
  15. +   size_t length;
  16. +
  17. +   if( !message[0] )
  18. +   {// empty message
  19. +       return;
  20. +   }
  21. +
  22. +   length = strlen(message);
  23. +
  24. +   if( length > sizeof(buf)-9 )
  25. +   {
  26. +       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);
  27. +       length = sizeof(buf)-9;
  28. +   }
  29. +
  30. +   WBUFW(buf,0) = 0x8d;
  31. +   WBUFW(buf,2) = 8+length+1;  // header + message + NUL
  32. +   WBUFL(buf,4) = bl ? bl->id : 0;
  33. +   safestrncpy((char*)WBUFP(buf,8), message, length+1);
  34. +   clif_send(buf, WBUFW(buf,2), bl, target);
  35. +}
  36. +
  37. +
  38. +/// Notification about player's own chat message (ZC_NOTIFY_PLAYERCHAT).
  39.  /// 008e <packet len>.W <message>.?B
  40. +void clif_notify_playerchat(struct map_session_data* sd, const char* message)
  41. +{
  42. +   int fd = sd->fd;
  43. +   size_t length;
  44. +
  45. +   if( !message[0] )
  46. +   {// don't send a void message (it's not displaying on the client chat). @help can send void line.
  47. +       return;
  48. +   }
  49. +
  50. +   length = strlen(message);
  51. +
  52. +   if( length > 255 )
  53. +   {// message is limited to 255+1 characters by the client-side buffer
  54. +       ShowWarning("clif_notify_playerchat: Truncated message '%s' (len=%u, max=%u, char_id=%d).\n", message, length, 255, sd->status.char_id);
  55. +       length = 255;
  56. +   }
  57. +
  58. +   WFIFOHEAD(fd,4+length+1);
  59. +   WFIFOW(fd,0) = 0x8e;
  60. +   WFIFOW(fd,2) = 4+length+1;  // header + message + NUL
  61. +   safestrncpy((char*)WFIFOP(fd,4), message, length+1);
  62. +   WFIFOSET(fd,WFIFOW(fd,2));
  63. +}
  64. +
  65. +
  66. +/// Send message (modified by [Yor])
  67.  void clif_displaymessage(const int fd, const char* mes)
  68.  {
  69.     nullpo_retv(mes);
  70. @@ -5337,9 +5392,31 @@
  71.             line = strtok(NULL, "\n");
  72.         }
  73.         aFree(message);
  74. +       // clif_notify_playerchat((struct map_session_data*)(session[fd]->session_data), mes);
  75.     }
  76.  }
  77.  
  78. +/// Send formatted message
  79. +void clif_displayformatted(struct map_session_data* sd, const char* fmt, ...)
  80. +{
  81. +   int n;
  82. +   char buf[255+1];
  83. +   va_list args;
  84. +
  85. +   va_start(args, fmt);
  86. +   n = vsnprintf(buf, sizeof(buf), fmt, args);
  87. +   va_end(args);
  88. +
  89. +   if( n < 1 || n >= sizeof(buf) )
  90. +   {
  91. +       ShowError("Too long message with format '%s' (n=%d).\n", fmt, n);
  92. +       return;
  93. +   }
  94. +
  95. +   clif_notify_playerchat(sd, buf);
  96. +}
  97. +
  98. +
  99.  /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  100.  /// 009a <packet len>.W <message>.?B
  101.  void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  102. @@ -5367,27 +5444,7 @@
  103.   *------------------------------------------*/
  104.  void clif_GlobalMessage(struct block_list* bl, const char* message)
  105.  {
  106. -   char buf[100];
  107. -   int len;
  108. -
  109. -   nullpo_retv(bl);
  110. -
  111. -   if(!message)
  112. -       return;
  113. -
  114. -   len = strlen(message)+1;
  115. -
  116. -   if( len > sizeof(buf)-8 )
  117. -   {
  118. -       ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  119. -       len = sizeof(buf)-8;
  120. -   }
  121. -
  122. -   WBUFW(buf,0)=0x8d;
  123. -   WBUFW(buf,2)=len+8;
  124. -   WBUFL(buf,4)=bl->id;
  125. -   safestrncpy((char *) WBUFP(buf,8),message,len);
  126. -   clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  127. +   clif_notify_chat(bl, message, ALL_CLIENT);
  128.  }
  129.  
  130.  /*==========================================
  131. @@ -5395,22 +5452,7 @@
  132.   *------------------------------------------*/
  133.  void clif_MainChatMessage(const char* message)
  134.  {
  135. -   uint8 buf[200];
  136. -   int len;
  137. -  
  138. -   if(!message)
  139. -       return;
  140. -      
  141. -   len = strlen(message)+1;
  142. -   if (len+8 > sizeof(buf)) {
  143. -       ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  144. -       len = sizeof(buf)-8;
  145. -   }
  146. -   WBUFW(buf,0)=0x8d;
  147. -   WBUFW(buf,2)=len+8;
  148. -   WBUFL(buf,4)=0;
  149. -   safestrncpy((char *) WBUFP(buf,8),message,len);
  150. -   clif_send(buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  151. +   clif_notify_chat(NULL, message, CHAT_MAINCHAT);
  152.  }
  153.  
  154.  
  155. @@ -8129,27 +8171,10 @@
  156.  }
  157.  
  158.  
  159. -/// Public chat message [Valaris] (ZC_NOTIFY_CHAT).
  160. -/// 008d <packet len>.W <id>.L <message>.?B
  161. +/// Public chat message [Valaris]
  162.  void clif_message(struct block_list* bl, const char* msg)
  163.  {
  164. -   unsigned short msg_len = strlen(msg) + 1;
  165. -   uint8 buf[256];
  166. -   // TODO: Merge with other 0x8d functions.
  167. -   nullpo_retv(bl);
  168. -
  169. -   if( msg_len > sizeof(buf)-8 )
  170. -   {
  171. -       ShowWarning("clif_message: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  172. -       msg_len = sizeof(buf)-8;
  173. -   }
  174. -
  175. -   WBUFW(buf,0) = 0x8d;
  176. -   WBUFW(buf,2) = msg_len + 8;
  177. -   WBUFL(buf,4) = bl->id;
  178. -   safestrncpy((char*)WBUFP(buf,8), msg, msg_len);
  179. -
  180. -   clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  181. +   clif_notify_chat(bl, msg, AREA_CHAT_WOC);
  182.  }
  183.  
  184.  
  185. @@ -8430,25 +8455,11 @@
  186.   *------------------------------------------*/
  187.  void clif_disp_overhead(struct map_session_data *sd, const char* mes)
  188.  {
  189. -   unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  190. -   int len_mes = strlen(mes)+1; //Account for \0
  191. -
  192. -   if (len_mes > sizeof(buf)-8) {
  193. -       ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  194. -       len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  195. -   }
  196.     // send message to others
  197. -   WBUFW(buf,0) = 0x8d;
  198. -   WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  199. -   WBUFL(buf,4) = sd->bl.id;
  200. -   safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  201. -   clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  202. +   clif_notify_chat(&sd->bl, mes, AREA_CHAT_WOC);
  203.  
  204.     // send back message to the speaker
  205. -   WBUFW(buf,0) = 0x8e;
  206. -   WBUFW(buf, 2) = len_mes + 4;
  207. -   safestrncpy((char*)WBUFP(buf,4), mes, len_mes);  
  208. -   clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  209. +   clif_notify_playerchat(sd, mes);
  210.  }
  211.  
  212.  /*==========================
  213. @@ -9561,14 +9572,8 @@
  214.         strcat(fakename, message);
  215.         textlen = strlen(fakename) + 1;
  216.     }
  217. -   // send message to others (using the send buffer for temp. storage)
  218. -   WFIFOHEAD(fd, 8 + textlen);
  219. -   WFIFOW(fd,0) = 0x8d;
  220. -   WFIFOW(fd,2) = 8 + textlen;
  221. -   WFIFOL(fd,4) = sd->bl.id;
  222. -   safestrncpy((char*)WFIFOP(fd,8), is_fake ? fakename : text, textlen);
  223. -   //FIXME: chat has range of 9 only
  224. -   clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  225. +   // send message to others
  226. +   clif_notify_chat(&sd->bl, text, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  227.  
  228.     // send back message to the speaker
  229.     if( is_fake ) {
  230. Index: clif.h
  231. ===================================================================
  232. --- clif.h  (revisão 16294)
  233. +++ clif.h  (cópia de trabalho)
  234. @@ -555,7 +555,10 @@
  235.  void clif_font(struct map_session_data *sd);
  236.  
  237.  // atcommand
  238. +void clif_notify_chat(struct block_list* bl, const char* message, send_target target);
  239. +void clif_notify_playerchat(struct map_session_data* sd, const char* message);
  240.  void clif_displaymessage(const int fd, const char* mes);
  241. +void clif_displayformatted(struct map_session_data* sd, const char* fmt, ...);
  242.  void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len);
  243.  void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target);
  244.  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