PageRenderTime 158ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 3ms

/src/map/clif.c

https://gitlab.com/evol/hercules
C | 16765 lines | 11831 code | 2253 blank | 2681 comment | 2543 complexity | fbb9af524a00a9cdade18b3f9c85a296 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0
  1. /**
  2. * This file is part of Hercules.
  3. * http://herc.ws - http://github.com/HerculesWS/Hercules
  4. *
  5. * Copyright (C) 2012-2015 Hercules Dev Team
  6. * Copyright (C) Athena Dev Teams
  7. *
  8. * Hercules is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #define HERCULES_CORE
  22. #include "config/core.h" // ANTI_MAYAP_CHEAT, RENEWAL, SECURE_NPCTIMEOUT
  23. #include "clif.h"
  24. #include "map/atcommand.h"
  25. #include "map/battle.h"
  26. #include "map/battleground.h"
  27. #include "map/channel.h"
  28. #include "map/chat.h"
  29. #include "map/chrif.h"
  30. #include "map/elemental.h"
  31. #include "map/guild.h"
  32. #include "map/homunculus.h"
  33. #include "map/instance.h"
  34. #include "map/intif.h"
  35. #include "map/irc-bot.h"
  36. #include "map/itemdb.h"
  37. #include "map/log.h"
  38. #include "map/mail.h"
  39. #include "map/map.h"
  40. #include "map/mercenary.h"
  41. #include "map/mob.h"
  42. #include "map/npc.h"
  43. #include "map/party.h"
  44. #include "map/pc.h"
  45. #include "map/pet.h"
  46. #include "map/quest.h"
  47. #include "map/script.h"
  48. #include "map/skill.h"
  49. #include "map/status.h"
  50. #include "map/storage.h"
  51. #include "map/trade.h"
  52. #include "map/unit.h"
  53. #include "map/vending.h"
  54. #include "common/HPM.h"
  55. #include "common/cbasetypes.h"
  56. #include "common/conf.h"
  57. #include "common/ers.h"
  58. #include "common/grfio.h"
  59. #include "common/memmgr.h"
  60. #include "common/mmo.h" // NEW_CARTS
  61. #include "common/nullpo.h"
  62. #include "common/random.h"
  63. #include "common/showmsg.h"
  64. #include "common/socket.h"
  65. #include "common/strlib.h"
  66. #include "common/timer.h"
  67. #include "common/utils.h"
  68. #include <stdio.h>
  69. #include <stdlib.h>
  70. #include <string.h>
  71. #include <stdarg.h>
  72. #include <time.h>
  73. struct clif_interface clif_s;
  74. struct clif_interface *clif;
  75. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  76. /* re-usable */
  77. static struct packet_itemlist_normal itemlist_normal;
  78. static struct packet_itemlist_equip itemlist_equip;
  79. static struct packet_storelist_normal storelist_normal;
  80. static struct packet_storelist_equip storelist_equip;
  81. static struct packet_viewequip_ack viewequip_list;
  82. #if PACKETVER >= 20131223
  83. static struct packet_npc_market_result_ack npcmarket_result;
  84. static struct packet_npc_market_open npcmarket_open;
  85. #endif
  86. //#define DUMP_UNKNOWN_PACKET
  87. //#define DUMP_INVALID_PACKET
  88. //Converts item type in case of pet eggs.
  89. static inline int itemtype(int type) {
  90. switch( type ) {
  91. #if PACKETVER >= 20080827
  92. case IT_WEAPON:
  93. return IT_ARMOR;
  94. case IT_ARMOR:
  95. case IT_PETARMOR:
  96. #endif
  97. case IT_PETEGG:
  98. return IT_WEAPON;
  99. default:
  100. return type;
  101. }
  102. }
  103. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  104. p += pos;
  105. p[0] = (uint8)(x>>2);
  106. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  107. p[2] = (uint8)((y<<4) | (dir&0xf));
  108. }
  109. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  110. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  111. p += pos;
  112. p[0] = (uint8)(x0>>2);
  113. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  114. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  115. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  116. p[4] = (uint8)y1;
  117. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  118. }
  119. #if 0 // Currently unused
  120. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  121. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  122. }
  123. #endif // 0
  124. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  125. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  126. }
  127. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  128. p += pos;
  129. if( x ) {
  130. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  131. }
  132. if( y ) {
  133. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  134. }
  135. if( dir ) {
  136. dir[0] = ( p[2] & 0x0f );
  137. }
  138. }
  139. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  140. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  141. }
  142. #if 0 // currently unused
  143. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  144. p += pos;
  145. if( x0 ) {
  146. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  147. }
  148. if( y0 ) {
  149. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  150. }
  151. if( x1 ) {
  152. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  153. }
  154. if( y1 ) {
  155. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  156. }
  157. if( sx0 ) {
  158. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  159. }
  160. if( sy0 ) {
  161. sy0[0] = ( p[5] & 0x0f ) >> 0;
  162. }
  163. }
  164. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  165. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  166. }
  167. #endif // 0
  168. //To identify disguised characters.
  169. static inline bool disguised(struct block_list* bl)
  170. {
  171. struct map_session_data *sd = BL_CAST(BL_PC, bl);
  172. if (sd == NULL || sd->disguise == -1)
  173. return false;
  174. return true;
  175. }
  176. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  177. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  178. nullpo_retr(0, mes);
  179. if (len <= 0)
  180. {
  181. mes[0] = '\0';
  182. Assert_retr(0, len > 0);
  183. }
  184. if( len > max )
  185. len = max;
  186. mes[len-1] = '\0';
  187. return len;
  188. }
  189. /*==========================================
  190. * Ip setting of map-server
  191. *------------------------------------------*/
  192. bool clif_setip(const char* ip) {
  193. char ip_str[16];
  194. nullpo_retr(false, ip);
  195. clif->map_ip = sockt->host2ip(ip);
  196. if ( !clif->map_ip ) {
  197. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  198. return false;
  199. }
  200. safestrncpy(clif->map_ip_str, ip, sizeof(clif->map_ip_str));
  201. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, sockt->ip2str(clif->map_ip, ip_str));
  202. return true;
  203. }
  204. bool clif_setbindip(const char* ip) {
  205. nullpo_retr(false, ip);
  206. clif->bind_ip = sockt->host2ip(ip);
  207. if ( clif->bind_ip ) {
  208. char ip_str[16];
  209. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, sockt->ip2str(clif->bind_ip, ip_str));
  210. return true;
  211. }
  212. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  213. return false;
  214. }
  215. /*==========================================
  216. * Sets map port to 'port'
  217. * is run from map.c upon loading map server configuration
  218. *------------------------------------------*/
  219. void clif_setport(uint16 port)
  220. {
  221. clif->map_port = port;
  222. }
  223. /*==========================================
  224. * Returns map server IP
  225. *------------------------------------------*/
  226. uint32 clif_getip(void)
  227. {
  228. return clif->map_ip;
  229. }
  230. /*==========================================
  231. * Returns map port which is set by clif_setport()
  232. *------------------------------------------*/
  233. uint16 clif_getport(void)
  234. {
  235. return clif->map_port;
  236. }
  237. /*==========================================
  238. * Updates server ip resolution and returns it
  239. *------------------------------------------*/
  240. uint32 clif_refresh_ip(void)
  241. {
  242. uint32 new_ip = sockt->host2ip(clif->map_ip_str);
  243. if ( new_ip && new_ip != clif->map_ip ) {
  244. clif->map_ip = new_ip;
  245. ShowInfo("Updating IP resolution of [%s].\n", clif->map_ip_str);
  246. return clif->map_ip;
  247. }
  248. return 0;
  249. }
  250. #if PACKETVER >= 20071106
  251. static inline unsigned char clif_bl_type(struct block_list *bl) {
  252. nullpo_retr(0x1, bl);
  253. switch (bl->type) {
  254. case BL_PC: return (disguised(bl) && !pc->db_checkid(status->get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  255. case BL_ITEM: return 0x2; //ITEM_TYPE
  256. case BL_SKILL: return 0x3; //SKILL_TYPE
  257. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  258. case BL_MOB: return pc->db_checkid(status->get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  259. case BL_NPC: return pc->db_checkid(status->get_viewdata(bl)->class_)?0x0:0x6; //NPC_EVT_TYPE
  260. case BL_PET: return pc->db_checkid(status->get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  261. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  262. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  263. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  264. default: return 0x1; //NPC_TYPE
  265. }
  266. }
  267. #endif
  268. /*==========================================
  269. * sub process of clif_send
  270. * Called from a map_foreachinarea (grabs all players in specific area and subjects them to this function)
  271. * In order to send area-wise packets, such as:
  272. * - AREA : everyone nearby your area
  273. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  274. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  275. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  276. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  277. *------------------------------------------*/
  278. int clif_send_sub(struct block_list *bl, va_list ap) {
  279. struct block_list *src_bl;
  280. struct map_session_data *sd;
  281. void *buf;
  282. int len, type, fd;
  283. nullpo_ret(bl);
  284. Assert_ret(bl->type == BL_PC);
  285. sd = BL_UCAST(BL_PC, bl);
  286. fd = sd->fd;
  287. if (!fd || sockt->session[fd] == NULL) //Don't send to disconnected clients.
  288. return 0;
  289. buf = va_arg(ap,void*);
  290. len = va_arg(ap,int);
  291. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  292. type = va_arg(ap,int);
  293. switch(type) {
  294. case AREA_WOS:
  295. if (bl == src_bl)
  296. return 0;
  297. break;
  298. case AREA_WOC:
  299. if (sd->chatID || bl == src_bl)
  300. return 0;
  301. break;
  302. case AREA_WOSC: {
  303. if (src_bl->type == BL_PC) {
  304. const struct map_session_data *ssd = BL_UCCAST(BL_PC, src_bl);
  305. if (ssd != NULL && sd->chatID != 0 && (sd->chatID == ssd->chatID))
  306. return 0;
  307. } else if (src_bl->type == BL_NPC) {
  308. const struct npc_data *nd = BL_UCCAST(BL_NPC, src_bl);
  309. if (nd != NULL && sd->chatID != 0 && (sd->chatID == nd->chat_id))
  310. return 0;
  311. }
  312. }
  313. break;
  314. /* 0x120 crashes the client when warping for this packetver range [Ind/Hercules], thanks to Judas! */
  315. #if PACKETVER > 20120418 && PACKETVER < 20130000
  316. case AREA:
  317. if( WBUFW(buf, 0) == 0x120 && sd->state.warping )
  318. return 0;
  319. break;
  320. #endif
  321. }
  322. /* unless visible, hold it here */
  323. if( clif->ally_only && !sd->sc.data[SC_CLAIRVOYANCE] && !sd->special_state.intravision && battle->check_target( src_bl, &sd->bl, BCT_ENEMY ) > 0 )
  324. return 0;
  325. return clif->send_actual(fd, buf, len);
  326. }
  327. int clif_send_actual(int fd, void *buf, int len)
  328. {
  329. nullpo_retr(0, buf);
  330. WFIFOHEAD(fd, len);
  331. if (WFIFOP(fd,0) == buf) {
  332. ShowError("WARNING: Invalid use of clif->send function\n");
  333. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  334. ShowError(" Please correct your code.\n");
  335. // don't send to not move the pointer of the packet for next sessions in the loop
  336. //WFIFOSET(fd,0);//## TODO is this ok?
  337. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  338. return 0;
  339. }
  340. memcpy(WFIFOP(fd,0), buf, len);
  341. WFIFOSET(fd,len);
  342. return 0;
  343. }
  344. /*==========================================
  345. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  346. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  347. *------------------------------------------*/
  348. bool clif_send(const void* buf, int len, struct block_list* bl, enum send_target type) {
  349. int i;
  350. struct map_session_data *sd, *tsd;
  351. struct party_data *p = NULL;
  352. struct guild *g = NULL;
  353. struct battleground_data *bgd = NULL;
  354. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  355. struct s_mapiterator* iter;
  356. if( type != ALL_CLIENT )
  357. nullpo_ret(bl);
  358. sd = BL_CAST(BL_PC, bl);
  359. switch(type) {
  360. case ALL_CLIENT: //All player clients.
  361. iter = mapit_getallusers();
  362. while ((tsd = BL_UCAST(BL_PC, mapit->next(iter))) != NULL) {
  363. WFIFOHEAD(tsd->fd, len);
  364. memcpy(WFIFOP(tsd->fd,0), buf, len);
  365. WFIFOSET(tsd->fd,len);
  366. }
  367. mapit->free(iter);
  368. break;
  369. case ALL_SAMEMAP: //All players on the same map
  370. iter = mapit_getallusers();
  371. while ((tsd = BL_UCAST(BL_PC, mapit->next(iter))) != NULL) {
  372. if (bl && bl->m == tsd->bl.m) {
  373. WFIFOHEAD(tsd->fd, len);
  374. memcpy(WFIFOP(tsd->fd,0), buf, len);
  375. WFIFOSET(tsd->fd,len);
  376. }
  377. }
  378. mapit->free(iter);
  379. break;
  380. case AREA:
  381. case AREA_WOSC:
  382. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  383. clif->send (buf, len, bl, SELF);
  384. /* Fall through */
  385. case AREA_WOC:
  386. case AREA_WOS:
  387. nullpo_retr(true, bl);
  388. map->foreachinarea(clif->send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  389. BL_PC, buf, len, bl, type);
  390. break;
  391. case AREA_CHAT_WOC:
  392. nullpo_retr(true, bl);
  393. map->foreachinarea(clif->send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  394. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  395. break;
  396. case CHAT:
  397. case CHAT_WOS:
  398. nullpo_retr(true, bl);
  399. {
  400. const struct chat_data *cd = NULL;
  401. if (sd != NULL) {
  402. cd = map->id2cd(sd->chatID);
  403. } else {
  404. cd = BL_CCAST(BL_CHAT, bl);
  405. }
  406. if (cd == NULL)
  407. break;
  408. for(i = 0; i < cd->users; i++) {
  409. if (type == CHAT_WOS && cd->usersd[i] == sd)
  410. continue;
  411. if ((fd=cd->usersd[i]->fd) >0 && sockt->session[fd]) { // Added check to see if session exists [PoW]
  412. WFIFOHEAD(fd,len);
  413. memcpy(WFIFOP(fd,0), buf, len);
  414. WFIFOSET(fd,len);
  415. }
  416. }
  417. }
  418. break;
  419. case PARTY_AREA:
  420. case PARTY_AREA_WOS:
  421. nullpo_retr(true, bl);
  422. x0 = bl->x - AREA_SIZE;
  423. y0 = bl->y - AREA_SIZE;
  424. x1 = bl->x + AREA_SIZE;
  425. y1 = bl->y + AREA_SIZE;
  426. /* Fall through */
  427. case PARTY:
  428. case PARTY_WOS:
  429. case PARTY_SAMEMAP:
  430. case PARTY_SAMEMAP_WOS:
  431. if (sd && sd->status.party_id)
  432. p = party->search(sd->status.party_id);
  433. if (p) {
  434. for(i=0;i<MAX_PARTY;i++){
  435. if( (sd = p->data[i].sd) == NULL )
  436. continue;
  437. if( !(fd=sd->fd) )
  438. continue;
  439. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  440. continue;
  441. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  442. continue;
  443. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  444. continue;
  445. WFIFOHEAD(fd,len);
  446. memcpy(WFIFOP(fd,0), buf, len);
  447. WFIFOSET(fd,len);
  448. }
  449. if (!map->enable_spy) //Skip unnecessary parsing. [Skotlex]
  450. break;
  451. iter = mapit_getallusers();
  452. while ((tsd = BL_UCAST(BL_PC, mapit->next(iter))) != NULL) {
  453. if( tsd->partyspy == p->party.party_id ) {
  454. WFIFOHEAD(tsd->fd, len);
  455. memcpy(WFIFOP(tsd->fd,0), buf, len);
  456. WFIFOSET(tsd->fd,len);
  457. }
  458. }
  459. mapit->free(iter);
  460. }
  461. break;
  462. case DUEL:
  463. case DUEL_WOS:
  464. if (!sd || !sd->duel_group) break; //Invalid usage.
  465. iter = mapit_getallusers();
  466. while ((tsd = BL_UCAST(BL_PC, mapit->next(iter))) != NULL) {
  467. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  468. continue;
  469. if( sd->duel_group == tsd->duel_group ) {
  470. WFIFOHEAD(tsd->fd, len);
  471. memcpy(WFIFOP(tsd->fd,0), buf, len);
  472. WFIFOSET(tsd->fd,len);
  473. }
  474. }
  475. mapit->free(iter);
  476. break;
  477. case SELF:
  478. if (sd && (fd=sd->fd) != 0) {
  479. WFIFOHEAD(fd,len);
  480. memcpy(WFIFOP(fd,0), buf, len);
  481. WFIFOSET(fd,len);
  482. }
  483. break;
  484. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  485. case GUILD_AREA:
  486. case GUILD_AREA_WOS:
  487. nullpo_retr(true, bl);
  488. x0 = bl->x - AREA_SIZE;
  489. y0 = bl->y - AREA_SIZE;
  490. x1 = bl->x + AREA_SIZE;
  491. y1 = bl->y + AREA_SIZE;
  492. /* Fall through */
  493. case GUILD_SAMEMAP:
  494. case GUILD_SAMEMAP_WOS:
  495. case GUILD:
  496. case GUILD_WOS:
  497. case GUILD_NOBG:
  498. if (sd && sd->status.guild_id)
  499. g = sd->guild;
  500. if (g) {
  501. for(i = 0; i < g->max_member; i++) {
  502. if( (sd = g->member[i].sd) != NULL ) {
  503. if( !(fd=sd->fd) )
  504. continue;
  505. if( type == GUILD_NOBG && sd->bg_id )
  506. continue;
  507. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  508. continue;
  509. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  510. continue;
  511. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  512. continue;
  513. WFIFOHEAD(fd,len);
  514. memcpy(WFIFOP(fd,0), buf, len);
  515. WFIFOSET(fd,len);
  516. }
  517. }
  518. if (!map->enable_spy) //Skip unnecessary parsing. [Skotlex]
  519. break;
  520. iter = mapit_getallusers();
  521. while ((tsd = BL_UCAST(BL_PC, mapit->next(iter))) != NULL) {
  522. if( tsd->guildspy == g->guild_id ) {
  523. WFIFOHEAD(tsd->fd, len);
  524. memcpy(WFIFOP(tsd->fd,0), buf, len);
  525. WFIFOSET(tsd->fd,len);
  526. }
  527. }
  528. mapit->free(iter);
  529. }
  530. break;
  531. case BG_AREA:
  532. case BG_AREA_WOS:
  533. nullpo_retr(true, bl);
  534. x0 = bl->x - AREA_SIZE;
  535. y0 = bl->y - AREA_SIZE;
  536. x1 = bl->x + AREA_SIZE;
  537. y1 = bl->y + AREA_SIZE;
  538. /* Fall through */
  539. case BG_SAMEMAP:
  540. case BG_SAMEMAP_WOS:
  541. case BG:
  542. case BG_WOS:
  543. if( sd && sd->bg_id && (bgd = bg->team_search(sd->bg_id)) != NULL ) {
  544. for( i = 0; i < MAX_BG_MEMBERS; i++ ) {
  545. if( (sd = bgd->members[i].sd) == NULL || !(fd = sd->fd) )
  546. continue;
  547. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  548. continue;
  549. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  550. continue;
  551. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  552. continue;
  553. WFIFOHEAD(fd,len);
  554. memcpy(WFIFOP(fd,0), buf, len);
  555. WFIFOSET(fd,len);
  556. }
  557. }
  558. break;
  559. case BG_QUEUE:
  560. if( sd && sd->bg_queue.arena ) {
  561. struct script_queue *queue = script->queue(sd->bg_queue.arena->queue_id);
  562. for (i = 0; i < VECTOR_LENGTH(queue->entries); i++) {
  563. struct map_session_data *qsd = map->id2sd(VECTOR_INDEX(queue->entries, i));
  564. if (qsd != NULL) {
  565. WFIFOHEAD(qsd->fd,len);
  566. memcpy(WFIFOP(qsd->fd,0), buf, len);
  567. WFIFOSET(qsd->fd,len);
  568. }
  569. }
  570. }
  571. break;
  572. default:
  573. ShowError("clif_send: Unrecognized type %d\n",type);
  574. return false;
  575. }
  576. return true;
  577. }
  578. /// Notifies the client, that it's connection attempt was accepted.
  579. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  580. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  581. void clif_authok(struct map_session_data *sd)
  582. {
  583. struct packet_authok p;
  584. nullpo_retv(sd);
  585. p.PacketType = authokType;
  586. p.startTime = (unsigned int)timer->gettick();
  587. WBUFPOS(&p.PosDir[0],0,sd->bl.x,sd->bl.y,sd->ud.dir); /* do the stupid client math */
  588. p.xSize = p.ySize = 5; /* not-used */
  589. #if PACKETVER >= 20080102
  590. p.font = sd->status.font;
  591. #endif
  592. #if PACKETVER >= 20141016
  593. p.sex = sd->status.sex;
  594. #endif
  595. clif->send(&p,sizeof(p),&sd->bl,SELF);
  596. }
  597. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  598. /// 0074 <error code>.B
  599. /// error code:
  600. /// 0 = client type mismatch
  601. /// 1 = ID mismatch
  602. /// 2 = mobile - out of available time
  603. /// 3 = mobile - already logged in
  604. /// 4 = mobile - waiting state
  605. void clif_authrefuse(int fd, uint8 error_code)
  606. {
  607. WFIFOHEAD(fd,packet_len(0x74));
  608. WFIFOW(fd,0) = 0x74;
  609. WFIFOB(fd,2) = error_code;
  610. WFIFOSET(fd,packet_len(0x74));
  611. }
  612. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  613. /// 0081 <error code>.B
  614. /// error code:
  615. /// 0 = BAN_UNFAIR -> "disconnected from server" -> MsgStringTable[3]
  616. /// 1 = server closed -> MsgStringTable[4]
  617. /// 2 = ID already logged in -> MsgStringTable[5]
  618. /// 3 = timeout/too much lag -> MsgStringTable[241]
  619. /// 4 = server full -> MsgStringTable[264]
  620. /// 5 = underaged -> MsgStringTable[305]
  621. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  622. /// 9 = too many connections from this ip -> MsgStringTable[529]
  623. /// 10 = out of available time paid for -> MsgStringTable[530]
  624. /// 11 = BAN_PAY_SUSPEND
  625. /// 12 = BAN_PAY_CHANGE
  626. /// 13 = BAN_PAY_WRONGIP
  627. /// 14 = BAN_PAY_PNGAMEROOM
  628. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  629. /// 16 = BAN_JAPAN_REFUSE1
  630. /// 17 = BAN_JAPAN_REFUSE2
  631. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  632. /// 100 = BAN_PC_IP_UNFAIR
  633. /// 101 = BAN_PC_IP_COUNT_ALL
  634. /// 102 = BAN_PC_IP_COUNT
  635. /// 103 = BAN_GRAVITY_MEM_AGREE
  636. /// 104 = BAN_GAME_MEM_AGREE
  637. /// 105 = BAN_HAN_VALID
  638. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  639. /// 107 = BAN_OVER_CHARACTER_LIST
  640. /// 108 = BAN_IP_BLOCK
  641. /// 109 = BAN_INVALID_PWD_CNT
  642. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  643. /// ? = disconnected -> MsgStringTable[3]
  644. // TODO: type enum
  645. void clif_authfail_fd(int fd, int type)
  646. {
  647. if (!fd || !sockt->session[fd] || sockt->session[fd]->func_parse != clif->parse) //clif_authfail should only be invoked on players!
  648. return;
  649. WFIFOHEAD(fd, packet_len(0x81));
  650. WFIFOW(fd,0) = 0x81;
  651. WFIFOB(fd,2) = type;
  652. WFIFOSET(fd,packet_len(0x81));
  653. sockt->eof(fd);
  654. }
  655. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  656. /// 00b3 <type>.B
  657. /// type:
  658. /// 1 = disconnect, char-select
  659. /// ? = nothing
  660. void clif_charselectok(int id, uint8 ok) {
  661. struct map_session_data* sd;
  662. int fd;
  663. if ((sd = map->id2sd(id)) == NULL || !sd->fd)
  664. return;
  665. fd = sd->fd;
  666. WFIFOHEAD(fd,packet_len(0xb3));
  667. WFIFOW(fd,0) = 0xb3;
  668. WFIFOB(fd,2) = ok;
  669. WFIFOSET(fd,packet_len(0xb3));
  670. }
  671. /// Makes an item appear on the ground.
  672. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  673. /// 084b (ZC_ITEM_FALL_ENTRY4)
  674. void clif_dropflooritem(struct flooritem_data* fitem) {
  675. struct packet_dropflooritem p;
  676. int view;
  677. nullpo_retv(fitem);
  678. if (fitem->item_data.nameid <= 0)
  679. return;
  680. p.PacketType = dropflooritemType;
  681. p.ITAID = fitem->bl.id;
  682. p.ITID = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  683. #if PACKETVER >= 20130000 /* not sure date */
  684. p.type = itemtype(itemdb_type(fitem->item_data.nameid));
  685. #endif
  686. p.IsIdentified = fitem->item_data.identify ? 1 : 0;
  687. p.xPos = fitem->bl.x;
  688. p.yPos = fitem->bl.y;
  689. p.subX = fitem->subx;
  690. p.subY = fitem->suby;
  691. p.count = fitem->item_data.amount;
  692. clif->send(&p, sizeof(p), &fitem->bl, AREA);
  693. }
  694. /// Makes an item disappear from the ground.
  695. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  696. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  697. {
  698. unsigned char buf[16];
  699. nullpo_retv(fitem);
  700. WBUFW(buf,0) = 0xa1;
  701. WBUFL(buf,2) = fitem->bl.id;
  702. if (fd == 0) {
  703. clif->send(buf, packet_len(0xa1), &fitem->bl, AREA);
  704. } else {
  705. WFIFOHEAD(fd,packet_len(0xa1));
  706. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  707. WFIFOSET(fd,packet_len(0xa1));
  708. }
  709. }
  710. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  711. /// 0080 <id>.L <type>.B
  712. /// type:
  713. /// 0 = out of sight
  714. /// 1 = died
  715. /// 2 = logged out
  716. /// 3 = teleport
  717. /// 4 = trickdead
  718. void clif_clearunit_single(int id, clr_type type, int fd)
  719. {
  720. WFIFOHEAD(fd, packet_len(0x80));
  721. WFIFOW(fd,0) = 0x80;
  722. WFIFOL(fd,2) = id;
  723. WFIFOB(fd,6) = type;
  724. WFIFOSET(fd, packet_len(0x80));
  725. }
  726. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  727. /// 0080 <id>.L <type>.B
  728. /// type:
  729. /// 0 = out of sight
  730. /// 1 = died
  731. /// 2 = logged out
  732. /// 3 = teleport
  733. /// 4 = trickdead
  734. void clif_clearunit_area(struct block_list* bl, clr_type type)
  735. {
  736. unsigned char buf[8];
  737. nullpo_retv(bl);
  738. WBUFW(buf,0) = 0x80;
  739. WBUFL(buf,2) = bl->id;
  740. WBUFB(buf,6) = type;
  741. clif->send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  742. if(disguised(bl)) {
  743. WBUFL(buf,2) = -bl->id;
  744. clif->send(buf, packet_len(0x80), bl, SELF);
  745. }
  746. }
  747. /// Used to make monsters with player-sprites disappear after dying
  748. /// like normal monsters, because the client does not remove those
  749. /// automatically.
  750. int clif_clearunit_delayed_sub(int tid, int64 tick, int id, intptr_t data) {
  751. struct block_list *bl = (struct block_list *)data;
  752. clif->clearunit_area(bl, (clr_type) id);
  753. ers_free(clif->delay_clearunit_ers,bl);
  754. return 0;
  755. }
  756. void clif_clearunit_delayed(struct block_list* bl, clr_type type, int64 tick) {
  757. struct block_list *tbl;
  758. nullpo_retv(bl);
  759. tbl = ers_alloc(clif->delay_clearunit_ers, struct block_list);
  760. memcpy (tbl, bl, sizeof (struct block_list));
  761. timer->add(tick, clif->clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  762. }
  763. /// Gets weapon view info from sd's inventory_data and points (*rhand,*lhand)
  764. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  765. {
  766. nullpo_retv(sd);
  767. nullpo_retv(rhand);
  768. nullpo_retv(lhand);
  769. if(sd->sc.option&OPTION_COSTUME) {
  770. *rhand = *lhand = 0;
  771. return;
  772. }
  773. #if PACKETVER < 4
  774. *rhand = sd->status.weapon;
  775. *lhand = sd->status.shield;
  776. #else
  777. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  778. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  779. {
  780. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  781. if (id->view_id > 0)
  782. *rhand = id->view_id;
  783. else
  784. *rhand = id->nameid;
  785. } else
  786. *rhand = 0;
  787. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  788. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  789. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  790. {
  791. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  792. if (id->view_id > 0)
  793. *lhand = id->view_id;
  794. else
  795. *lhand = id->nameid;
  796. } else
  797. *lhand = 0;
  798. #endif
  799. }
  800. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  801. static int clif_setlevel_sub(int lv) {
  802. if( lv < battle_config.max_lv ) {
  803. ;
  804. } else if( lv < battle_config.aura_lv ) {
  805. lv = battle_config.max_lv - 1;
  806. } else {
  807. lv = battle_config.max_lv;
  808. }
  809. return lv;
  810. }
  811. static int clif_setlevel(struct block_list* bl) {
  812. int lv = status->get_lv(bl);
  813. nullpo_retr(0, bl);
  814. if( battle_config.client_limit_unit_lv&bl->type )
  815. return clif_setlevel_sub(lv);
  816. switch( bl->type ) {
  817. case BL_NPC:
  818. case BL_PET:
  819. // npcs and pets do not have level
  820. return 0;
  821. }
  822. return lv;
  823. }
  824. /* for 'packetver < 20091103' 0x78 non-pc-looking unit handling */
  825. void clif_set_unit_idle2(struct block_list* bl, struct map_session_data *tsd, enum send_target target) {
  826. #if PACKETVER < 20091103
  827. struct map_session_data* sd;
  828. struct status_change* sc = status->get_sc(bl);
  829. struct view_data* vd = status->get_viewdata(bl);
  830. struct packet_idle_unit2 p;
  831. int g_id = status->get_guild_id(bl);
  832. nullpo_retv(bl);
  833. sd = BL_CAST(BL_PC, bl);
  834. p.PacketType = idle_unit2Type;
  835. #if PACKETVER >= 20071106
  836. p.objecttype = clif_bl_type(bl);
  837. #endif
  838. p.GID = bl->id;
  839. p.speed = status->get_speed(bl);
  840. p.bodyState = (sc) ? sc->opt1 : 0;
  841. p.healthState = (sc) ? sc->opt2 : 0;
  842. p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0);
  843. p.job = vd->class_;
  844. p.head = vd->hair_style;
  845. p.weapon = vd->weapon;
  846. p.accessory = vd->head_bottom;
  847. p.shield = vd->shield;
  848. p.accessory2 = vd->head_top;
  849. p.accessory3 = vd->head_mid;
  850. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS ) { //The hell, why flags work like this?
  851. p.shield = status->get_emblem_id(bl);
  852. p.accessory2 = GetWord(g_id, 1);
  853. p.accessory3 = GetWord(g_id, 0);
  854. }
  855. p.headpalette = vd->hair_color;
  856. p.bodypalette = vd->cloth_color;
  857. p.headDir = (sd)? sd->head_dir : 0;
  858. p.GUID = g_id;
  859. p.GEmblemVer = status->get_emblem_id(bl);
  860. p.honor = (sd) ? sd->status.manner : 0;
  861. p.virtue = (sc) ? sc->opt3 : 0;
  862. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  863. p.sex = vd->sex;
  864. WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit->getdir(bl));
  865. p.xSize = p.ySize = (sd) ? 5 : 0;
  866. p.state = vd->dead_sit;
  867. p.clevel = clif_setlevel(bl);
  868. clif->send(&p,sizeof(p),tsd?&tsd->bl:bl,target);
  869. #else
  870. return;
  871. #endif
  872. }
  873. /*==========================================
  874. * Prepares 'unit standing' packet
  875. *------------------------------------------*/
  876. void clif_set_unit_idle(struct block_list* bl, struct map_session_data *tsd, enum send_target target) {
  877. struct map_session_data* sd;
  878. struct status_change* sc = status->get_sc(bl);
  879. struct view_data* vd = status->get_viewdata(bl);
  880. struct packet_idle_unit p;
  881. int g_id = status->get_guild_id(bl);
  882. nullpo_retv(bl);
  883. #if PACKETVER < 20091103
  884. if( !pc->db_checkid(vd->class_) ) {
  885. clif->set_unit_idle2(bl,tsd,target);
  886. return;
  887. }
  888. #endif
  889. sd = BL_CAST(BL_PC, bl);
  890. p.PacketType = idle_unitType;
  891. #if PACKETVER >= 20091103
  892. p.PacketLength = sizeof(p);
  893. p.objecttype = clif_bl_type(bl);
  894. #endif
  895. #if PACKETVER >= 20131223
  896. p.AID = bl->id;
  897. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  898. #else
  899. p.GID = bl->id;
  900. #endif
  901. p.speed = status->get_speed(bl);
  902. p.bodyState = (sc) ? sc->opt1 : 0;
  903. p.healthState = (sc) ? sc->opt2 : 0;
  904. p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0);
  905. p.job = vd->class_;
  906. p.head = vd->hair_style;
  907. p.weapon = vd->weapon;
  908. p.accessory = vd->head_bottom;
  909. #if PACKETVER < 7
  910. p.shield = vd->shield;
  911. #endif
  912. p.accessory2 = vd->head_top;
  913. p.accessory3 = vd->head_mid;
  914. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS ) { //The hell, why flags work like this?
  915. p.accessory = status->get_emblem_id(bl);
  916. p.accessory2 = GetWord(g_id, 1);
  917. p.accessory3 = GetWord(g_id, 0);
  918. }
  919. p.headpalette = vd->hair_color;
  920. p.bodypalette = vd->cloth_color;
  921. p.headDir = (sd)? sd->head_dir : 0;
  922. #if PACKETVER >= 20101124
  923. p.robe = vd->robe;
  924. #endif
  925. p.GUID = g_id;
  926. p.GEmblemVer = status->get_emblem_id(bl);
  927. p.honor = (sd) ? sd->status.manner : 0;
  928. p.virtue = (sc) ? sc->opt3 : 0;
  929. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  930. p.sex = vd->sex;
  931. WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit->getdir(bl));
  932. p.xSize = p.ySize = (sd) ? 5 : 0;
  933. p.state = vd->dead_sit;
  934. p.clevel = clif_setlevel(bl);
  935. #if PACKETVER >= 20080102
  936. p.font = (sd) ? sd->status.font : 0;
  937. #endif
  938. #if PACKETVER >= 20120221
  939. if (battle_config.show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl)) {
  940. const struct mob_data *md = BL_UCCAST(BL_MOB, bl);
  941. p.maxHP = status_get_max_hp(bl);
  942. p.HP = status_get_hp(bl);
  943. p.isBoss = (md->spawn != NULL && md->spawn->state.boss) ? 1 : 0;
  944. } else {
  945. p.maxHP = -1;
  946. p.HP = -1;
  947. p.isBoss = 0;
  948. }
  949. #endif
  950. #if PACKETVER >= 20150513
  951. p.body = vd->body_style;
  952. #endif
  953. clif->send(&p,sizeof(p),tsd?&tsd->bl:bl,target);
  954. if( disguised(bl) ) {
  955. #if PACKETVER >= 20091103
  956. p.objecttype = pc->db_checkid(status->get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  957. p.GID = -bl->id;
  958. #else
  959. p.GID = -bl->id;
  960. #endif
  961. clif->send(&p,sizeof(p),bl,SELF);
  962. }
  963. }
  964. /* for 'packetver < 20091103' 0x7c non-pc-looking unit handling */
  965. void clif_spawn_unit2(struct block_list* bl, enum send_target target) {
  966. #if PACKETVER < 20091103
  967. struct map_session_data* sd;
  968. struct status_change* sc = status->get_sc(bl);
  969. struct view_data* vd = status->get_viewdata(bl);
  970. struct packet_spawn_unit2 p;
  971. int g_id = status->get_guild_id(bl);
  972. nullpo_retv(bl);
  973. sd = BL_CAST(BL_PC, bl);
  974. p.PacketType = spawn_unit2Type;
  975. #if PACKETVER >= 20071106
  976. p.objecttype = clif_bl_type(bl);
  977. #endif
  978. p.GID = bl->id;
  979. p.speed = status->get_speed(bl);
  980. p.bodyState = (sc) ? sc->opt1 : 0;
  981. p.healthState = (sc) ? sc->opt2 : 0;
  982. p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0);
  983. p.head = vd->hair_style;
  984. p.weapon = vd->weapon;
  985. p.accessory = vd->head_bottom;
  986. p.job = vd->class_;
  987. p.shield = vd->shield;
  988. p.accessory2 = vd->head_top;
  989. p.accessory3 = vd->head_mid;
  990. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS ) { //The hell, why flags work like this?
  991. p.shield = status->get_emblem_id(bl);
  992. p.accessory2 = GetWord(g_id, 1);
  993. p.accessory3 = GetWord(g_id, 0);
  994. }
  995. p.headpalette = vd->hair_color;
  996. p.bodypalette = vd->cloth_color;
  997. p.headDir = (sd)? sd->head_dir : 0;
  998. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  999. p.sex = vd->sex;
  1000. WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit->getdir(bl));
  1001. p.xSize = p.ySize = (sd) ? 5 : 0;
  1002. clif->send(&p,sizeof(p),bl,target);
  1003. #else
  1004. return;
  1005. #endif
  1006. }
  1007. void clif_spawn_unit(struct block_list* bl, enum send_target target) {
  1008. struct map_session_data* sd;
  1009. struct status_change* sc = status->get_sc(bl);
  1010. struct view_data* vd = status->get_viewdata(bl);
  1011. struct packet_spawn_unit p;
  1012. int g_id = status->get_guild_id(bl);
  1013. nullpo_retv(bl);
  1014. #if PACKETVER < 20091103
  1015. if( !pc->db_checkid(vd->class_) ) {
  1016. clif->spawn_unit2(bl,target);
  1017. return;
  1018. }
  1019. #endif
  1020. sd = BL_CAST(BL_PC, bl);
  1021. p.PacketType = spawn_unitType;
  1022. #if PACKETVER >= 20091103
  1023. p.PacketLength = sizeof(p);
  1024. p.objecttype = clif_bl_type(bl);
  1025. #endif
  1026. #if PACKETVER >= 20131223
  1027. p.AID = bl->id;
  1028. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1029. #else
  1030. p.GID = bl->id;
  1031. #endif
  1032. p.speed = status->get_speed(bl);
  1033. p.bodyState = (sc) ? sc->opt1 : 0;
  1034. p.healthState = (sc) ? sc->opt2 : 0;
  1035. p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0);
  1036. p.job = vd->class_;
  1037. p.head = vd->hair_style;
  1038. p.weapon = vd->weapon;
  1039. p.accessory = vd->head_bottom;
  1040. #if PACKETVER < 7
  1041. p.shield = vd->shield;
  1042. #endif
  1043. p.accessory2 = vd->head_top;
  1044. p.accessory3 = vd->head_mid;
  1045. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS ) { //The hell, why flags work like this?
  1046. p.accessory = status->get_emblem_id(bl);
  1047. p.accessory2 = GetWord(g_id, 1);
  1048. p.accessory3 = GetWord(g_id, 0);
  1049. }
  1050. p.headpalette = vd->hair_color;
  1051. p.bodypalette = vd->cloth_color;
  1052. p.headDir = (sd)? sd->head_dir : 0;
  1053. #if PACKETVER >= 20101124
  1054. p.robe = vd->robe;
  1055. #endif
  1056. p.GUID = g_id;
  1057. p.GEmblemVer = status->get_emblem_id(bl);
  1058. p.honor = (sd) ? sd->status.manner : 0;
  1059. p.virtue = (sc) ? sc->opt3 : 0;
  1060. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1061. p.sex = vd->sex;
  1062. WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit->getdir(bl));
  1063. p.xSize = p.ySize = (sd) ? 5 : 0;
  1064. p.clevel = clif_setlevel(bl);
  1065. #if PACKETVER >= 20080102
  1066. p.font = (sd) ? sd->status.font : 0;
  1067. #endif
  1068. #if PACKETVER >= 20120221
  1069. if (battle_config.show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl)) {
  1070. const struct mob_data *md = BL_UCCAST(BL_MOB, bl);
  1071. p.maxHP = status_get_max_hp(bl);
  1072. p.HP = status_get_hp(bl);
  1073. p.isBoss = (md->spawn != NULL && md->spawn->state.boss) ? 1 : 0;
  1074. } else {
  1075. p.maxHP = -1;
  1076. p.HP = -1;
  1077. p.isBoss = 0;
  1078. }
  1079. #endif
  1080. #if PACKETVER >= 20150513
  1081. p.body = vd->body_style;
  1082. #endif
  1083. if( disguised(bl) ) {
  1084. nullpo_retv(sd);
  1085. if( sd->status.class_ != sd->disguise )
  1086. clif->send(&p,sizeof(p),bl,target);
  1087. #if PACKETVER >= 20091103
  1088. p.objecttype = pc->db_checkid(status->get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1089. p.GID = -bl->id;
  1090. #else
  1091. p.GID = -bl->id;
  1092. #endif
  1093. clif->send(&p,sizeof(p),bl,SELF);
  1094. } else
  1095. clif->send(&p,sizeof(p),bl,target);
  1096. }
  1097. /*==========================================
  1098. * Prepares 'unit walking' packet
  1099. *------------------------------------------*/
  1100. void clif_set_unit_walking(struct block_list* bl, struct map_session_data *tsd, struct unit_data* ud, enum send_target target) {
  1101. struct map_session_data* sd;
  1102. struct status_change* sc = status->get_sc(bl);
  1103. struct view_data* vd = status->get_viewdata(bl);
  1104. struct packet_unit_walking p;
  1105. int g_id = status->get_guild_id(bl);
  1106. nullpo_retv(bl);
  1107. nullpo_retv(ud);
  1108. sd = BL_CAST(BL_PC, bl);
  1109. p.PacketType = unit_walkingType;
  1110. #if PACKETVER >= 20091103
  1111. p.PacketLength = sizeof(p);
  1112. #endif
  1113. #if PACKETVER >= 20071106
  1114. p.objecttype = clif_bl_type(bl);
  1115. #endif
  1116. #if PACKETVER >= 20131223
  1117. p.AID = bl->id;
  1118. p.GID = (tsd) ? tsd->status.char_id : 0; // CCODE
  1119. #else
  1120. p.GID = bl->id;
  1121. #endif
  1122. p.speed = status->get_speed(bl);
  1123. p.bodyState = (sc) ? sc->opt1 : 0;
  1124. p.healthState = (sc) ? sc->opt2 : 0;
  1125. p.effectState = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0);
  1126. p.job = vd->class_;
  1127. p.head = vd->hair_style;
  1128. p.weapon = vd->weapon;
  1129. p.accessory = vd->head_bottom;
  1130. p.moveStartTime = (unsigned int)timer->gettick();
  1131. #if PACKETVER < 7
  1132. p.shield = vd->shield;
  1133. #endif
  1134. p.accessory2 = vd->head_top;
  1135. p.accessory3 = vd->head_mid;
  1136. p.headpalette = vd->hair_color;
  1137. p.bodypalette = vd->cloth_color;
  1138. p.headDir = (sd)? sd->head_dir : 0;
  1139. #if PACKETVER >= 20101124
  1140. p.robe = vd->robe;
  1141. #endif
  1142. p.GUID = g_id;
  1143. p.GEmblemVer = status->get_emblem_id(bl);
  1144. p.honor = (sd) ? sd->status.manner : 0;
  1145. p.virtue = (sc) ? sc->opt3 : 0;
  1146. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1147. p.sex = vd->sex;
  1148. WBUFPOS2(&p.MoveData[0],0,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1149. p.xSize = p.ySize = (sd) ? 5 : 0;
  1150. p.clevel = clif_setlevel(bl);
  1151. #if PACKETVER >= 20080102
  1152. p.font = (sd) ? sd->status.font : 0;
  1153. #endif
  1154. #if PACKETVER >= 20120221
  1155. if (battle_config.show_monster_hp_bar && bl->type == BL_MOB && status_get_hp(bl) < status_get_max_hp(bl)) {
  1156. const struct mob_data *md = BL_UCCAST(BL_MOB, bl);
  1157. p.maxHP = status_get_max_hp(bl);
  1158. p.HP = status_get_hp(bl);
  1159. p.isBoss = (md->spawn != NULL && md->spawn->state.boss) ? 1 : 0;
  1160. } else {
  1161. p.maxHP = -1;
  1162. p.HP = -1;
  1163. p.isBoss = 0;
  1164. }
  1165. #endif
  1166. #if PACKETVER >= 20150513
  1167. p.body = vd->body_style;
  1168. #endif
  1169. clif->send(&p,sizeof(p),tsd?&tsd->bl:bl,target);
  1170. if( disguised(bl) ) {
  1171. #if PACKETVER >= 20091103
  1172. p.objecttype = pc->db_checkid(status->get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1173. p.GID = -bl->id;
  1174. #else
  1175. p.GID = -bl->id;
  1176. #endif
  1177. clif->send(&p,sizeof(p),bl,SELF);
  1178. }
  1179. }
  1180. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1181. /// 01b0 <id>.L <type>.B <value>.L
  1182. /// type:
  1183. /// unused
  1184. void clif_class_change(struct block_list *bl, int class_, int type)
  1185. {
  1186. nullpo_retv(bl);
  1187. if(!pc->db_checkid(class_))
  1188. {// player classes yield missing sprites
  1189. unsigned char buf[16];
  1190. WBUFW(buf,0)=0x1b0;
  1191. WBUFL(buf,2)=bl->id;
  1192. WBUFB(buf,6)=type;
  1193. WBUFL(buf,7)=class_;
  1194. clif->send(buf,packet_len(0x1b0),bl,AREA);
  1195. }
  1196. }
  1197. /// Notifies the client of an object's spirits.
  1198. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1199. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1200. void clif_spiritball_single(int fd, struct map_session_data *sd) {
  1201. nullpo_retv(sd);
  1202. WFIFOHEAD(fd, packet_len(0x1e1));
  1203. WFIFOW(fd,0)=0x1e1;
  1204. WFIFOL(fd,2)=sd->bl.id;
  1205. WFIFOW(fd,6)=sd->spiritball;
  1206. WFIFOSET(fd, packet_len(0x1e1));
  1207. }
  1208. /*==========================================
  1209. * Kagerou/Oboro amulet spirit
  1210. *------------------------------------------*/
  1211. void clif_charm_single(int fd, struct map_session_data *sd)
  1212. {
  1213. nullpo_retv(sd);
  1214. WFIFOHEAD(fd, packet_len(0x08cf));
  1215. WFIFOW(fd,0) = 0x08cf;
  1216. WFIFOL(fd,2) = sd->bl.id;
  1217. WFIFOW(fd,6) = sd->charm_type;
  1218. WFIFOW(fd,8) = sd->charm_count;
  1219. WFIFOSET(fd, packet_len(0x08cf));
  1220. }
  1221. /*==========================================
  1222. * Run when player changes map / refreshes
  1223. * Tells its client to display all weather settings being used by this map
  1224. *------------------------------------------*/
  1225. void clif_weather_check(struct map_session_data *sd) {
  1226. int16 m;
  1227. int fd;
  1228. nullpo_retv(sd);
  1229. m = sd->bl.m;
  1230. fd = sd->fd;
  1231. if (map->list[m].flag.snow)
  1232. clif->specialeffect_single(&sd->bl, 162, fd);
  1233. if (map->list[m].flag.clouds)
  1234. clif->specialeffect_single(&sd->bl, 233, fd);
  1235. if (map->list[m].flag.clouds2)
  1236. clif->specialeffect_single(&sd->bl, 516, fd);
  1237. if (map->list[m].flag.fog)
  1238. clif->specialeffect_single(&sd->bl, 515, fd);
  1239. if (map->list[m].flag.fireworks) {
  1240. clif->specialeffect_single(&sd->bl, 297, fd);
  1241. clif->specialeffect_single(&sd->bl, 299, fd);
  1242. clif->specialeffect_single(&sd->bl, 301, fd);
  1243. }
  1244. if (map->list[m].flag.sakura)
  1245. clif->specialeffect_single(&sd->bl, 163, fd);
  1246. if (map->list[m].flag.leaves)
  1247. clif->specialeffect_single(&sd->bl, 333, fd);
  1248. }
  1249. /**
  1250. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1251. **/
  1252. void clif_weather(int16 m)
  1253. {
  1254. struct s_mapiterator* iter;
  1255. struct map_session_data *sd=NULL;
  1256. iter = mapit_getallusers();
  1257. for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) {
  1258. if( sd->bl.m == m )
  1259. clif->weather_check(sd);
  1260. }
  1261. mapit->free(iter);
  1262. }
  1263. /**
  1264. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1265. **/
  1266. bool clif_spawn(struct block_list *bl)
  1267. {
  1268. struct view_data *vd;
  1269. nullpo_retr(false, bl);
  1270. vd = status->get_viewdata(bl);
  1271. if( !vd )
  1272. return false;
  1273. if (vd->class_ == INVISIBLE_CLASS)
  1274. return true; // Doesn't need to be spawned, so everything is alright
  1275. if (bl->type == BL_NPC) {
  1276. struct npc_data *nd = BL_UCAST(BL_NPC, bl);
  1277. if (nd->chat_id == 0 && (nd->option&OPTION_INVISIBLE)) // Hide NPC from maya purple card.
  1278. return true; // Doesn't need to be spawned, so everything is alright
  1279. }
  1280. clif->spawn_unit(bl,AREA_WOS);
  1281. if (vd->cloth_color)
  1282. clif->refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1283. if (vd->body_style)
  1284. clif->refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1285. switch (bl->type) {
  1286. case BL_PC:
  1287. {
  1288. struct map_session_data *sd = BL_UCAST(BL_PC, bl);
  1289. int i;
  1290. if (sd->spiritball > 0)
  1291. clif->spiritball(&sd->bl);
  1292. if (sd->state.size == SZ_BIG) // tiny/big players [Valaris]
  1293. clif->specialeffect(bl,423,AREA);
  1294. else if (sd->state.size == SZ_MEDIUM)
  1295. clif->specialeffect(bl,421,AREA);
  1296. if (sd->bg_id != 0 && map->list[sd->bl.m].flag.battleground)
  1297. clif->sendbgemblem_area(sd);
  1298. for (i = 0; i < sd->sc_display_count; i++) {
  1299. clif->sc_load(&sd->bl, sd->bl.id,AREA,status->dbs->IconChangeTable[sd->sc_display[i]->type],sd->sc_display[i]->val1,sd->sc_display[i]->val2,sd->sc_display[i]->val3);
  1300. }
  1301. if (sd->charm_type != CHARM_TYPE_NONE && sd->charm_count > 0)
  1302. clif->spiritcharm(sd);
  1303. if (sd->status.robe)
  1304. clif->refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1305. }
  1306. break;
  1307. case BL_MOB:
  1308. {
  1309. struct mob_data *md = BL_UCAST(BL_MOB, bl);
  1310. if (md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1311. clif->specialeffect(&md->bl,423,AREA);
  1312. else if (md->special_state.size==SZ_MEDIUM)
  1313. clif->specialeffect(&md->bl,421,AREA);
  1314. }
  1315. break;
  1316. case BL_NPC:
  1317. {
  1318. struct npc_data *nd = BL_UCAST(BL_NPC, bl);
  1319. if (nd->size == SZ_BIG)
  1320. clif->specialeffect(&nd->bl,423,AREA);
  1321. else if (nd->size == SZ_MEDIUM)
  1322. clif->specialeffect(&nd->bl,421,AREA);
  1323. }
  1324. break;
  1325. case BL_PET:
  1326. if (vd->head_bottom)
  1327. clif->send_petdata(NULL, BL_UCAST(BL_PET, bl), 3, vd->head_bottom); // needed to display pet equip properly
  1328. break;
  1329. }
  1330. return true;
  1331. }
  1332. /// Sends information about owned homunculus to the client (ZC_PROPERTY_HOMUN). [orn]
  1333. /// 022e <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.W <max hp>.W <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W
  1334. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag) {
  1335. struct status_data *hstatus;
  1336. unsigned char buf[128];
  1337. enum homun_type htype;
  1338. nullpo_retv(sd);
  1339. nullpo_retv(hd);
  1340. hstatus = &hd->battle_status;
  1341. htype = homun->class2type(hd->homunculus.class_);
  1342. memset(buf,0,packet_len(0x22e));
  1343. WBUFW(buf,0)=0x22e;
  1344. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1345. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1346. WBUFB(buf,26)=(battle_config.hom_rename && hd->homunculus.rename_flag ? 0x1 : 0x0) | (hd->homunculus.vaporize == HOM_ST_REST ? 0x2 : 0) | (hd->homunculus.hp > 0 ? 0x4 : 0);
  1347. WBUFW(buf,27)=hd->homunculus.level;
  1348. WBUFW(buf,29)=hd->homunculus.hunger;
  1349. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1350. WBUFW(buf,33)=0; // equip id
  1351. #ifdef RENEWAL
  1352. WBUFW(buf, 35) = cap_value(hstatus->rhw.atk2, 0, INT16_MAX);
  1353. #else
  1354. WBUFW(buf,35)=cap_value(hstatus->rhw.atk2+hstatus->batk, 0, INT16_MAX);
  1355. #endif
  1356. WBUFW(buf,37)=cap_value(hstatus->matk_max, 0, INT16_MAX);
  1357. WBUFW(buf,39)=hstatus->hit;
  1358. if (battle_config.hom_setting&0x10)
  1359. WBUFW(buf,41)=hstatus->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1360. else
  1361. WBUFW(buf,41)=hstatus->cri/10;
  1362. #ifdef RENEWAL
  1363. WBUFW(buf, 43) = hstatus->def + hstatus->def2;
  1364. WBUFW(buf, 45) = hstatus->mdef + hstatus->mdef2;
  1365. #else
  1366. WBUFW(buf,43)=hstatus->def + hstatus->vit ;
  1367. WBUFW(buf, 45) = hstatus->mdef;
  1368. #endif
  1369. WBUFW(buf,47)=hstatus->flee;
  1370. WBUFW(buf,49)=(flag)?0:hstatus->amotion;
  1371. if (hstatus->max_hp > INT16_MAX) {
  1372. WBUFW(buf,51) = hstatus->hp/(hstatus->max_hp/100);
  1373. WBUFW(buf,53) = 100;
  1374. } else {
  1375. WBUFW(buf,51)=hstatus->hp;
  1376. WBUFW(buf,53)=hstatus->max_hp;
  1377. }
  1378. if (hstatus->max_sp > INT16_MAX) {
  1379. WBUFW(buf,55) = hstatus->sp/(hstatus->max_sp/100);
  1380. WBUFW(buf,57) = 100;
  1381. } else {
  1382. WBUFW(buf,55)=hstatus->sp;
  1383. WBUFW(buf,57)=hstatus->max_sp;
  1384. }
  1385. WBUFL(buf,59)=hd->homunculus.exp;
  1386. WBUFL(buf,63)=hd->exp_next;
  1387. switch( htype ) {
  1388. case HT_REG:
  1389. case HT_EVO:
  1390. if( hd->homunculus.level >= battle_config.hom_max_level )
  1391. WBUFL(buf,63)=0;
  1392. break;
  1393. case HT_S:
  1394. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1395. WBUFL(buf,63)=0;
  1396. break;
  1397. }
  1398. WBUFW(buf,67)=hd->homunculus.skillpts;
  1399. WBUFW(buf,69)=status_get_range(&hd->bl);
  1400. clif->send(buf,packet_len(0x22e),&sd->bl,SELF);
  1401. }
  1402. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1403. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1404. /// type:
  1405. /// unused
  1406. /// state:
  1407. /// 0 = pre-init
  1408. /// 1 = intimacy
  1409. /// 2 = hunger
  1410. /// 3 = accessory?
  1411. /// ? = ignored
  1412. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1413. {
  1414. int fd;
  1415. nullpo_retv(sd);
  1416. nullpo_retv(sd->hd);
  1417. fd = sd->fd;
  1418. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1419. homun->calc_skilltree(sd->hd, 0);
  1420. WFIFOHEAD(fd, packet_len(0x230));
  1421. WFIFOW(fd,0)=0x230;
  1422. WFIFOB(fd,2)=0;
  1423. WFIFOB(fd,3)=state;
  1424. WFIFOL(fd,4)=sd->hd->bl.id;
  1425. WFIFOL(fd,8)=param;
  1426. WFIFOSET(fd,packet_len(0x230));
  1427. }
  1428. /// Prepares and sends homun related information [orn]
  1429. void clif_homskillinfoblock(struct map_session_data *sd) {
  1430. struct homun_data *hd;
  1431. int fd;
  1432. int i,j;
  1433. int len=4;
  1434. nullpo_retv(sd);
  1435. fd = sd->fd;
  1436. hd = sd->hd;
  1437. if ( !hd )
  1438. return;
  1439. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1440. WFIFOW(fd,0)=0x235;
  1441. for ( i = 0; i < MAX_HOMUNSKILL; i++ ) {
  1442. int id = hd->homunculus.hskill[i].id;
  1443. if ( id != 0 ) {
  1444. j = id - HM_SKILLBASE;
  1445. WFIFOW(fd, len) = id;
  1446. WFIFOW(fd, len + 2) = skill->get_inf(id);
  1447. WFIFOW(fd, len + 4) = 0;
  1448. WFIFOW(fd, len + 6) = hd->homunculus.hskill[j].lv;
  1449. if ( hd->homunculus.hskill[j].lv ) {
  1450. WFIFOW(fd, len + 8) = skill->get_sp(id, hd->homunculus.hskill[j].lv);
  1451. WFIFOW(fd, len + 10) = skill->get_range2(&sd->hd->bl, id, hd->homunculus.hskill[j].lv);
  1452. } else {
  1453. WFIFOW(fd, len + 8) = 0;
  1454. WFIFOW(fd, len + 10) = 0;
  1455. }
  1456. safestrncpy((char*)WFIFOP(fd, len + 12), skill->get_name(id), NAME_LENGTH);
  1457. WFIFOB(fd, len + 36) = (hd->homunculus.hskill[j].lv < homun->skill_tree_get_max(id, hd->homunculus.class_)) ? 1 : 0;
  1458. len += 37;
  1459. }
  1460. }
  1461. WFIFOW(fd,2)=len;
  1462. WFIFOSET(fd,len);
  1463. return;
  1464. }
  1465. void clif_homskillup(struct map_session_data *sd, uint16 skill_id) { //[orn]
  1466. struct homun_data *hd;
  1467. int fd, idx;
  1468. nullpo_retv(sd);
  1469. nullpo_retv(sd->hd);
  1470. idx = skill_id - HM_SKILLBASE;
  1471. fd=sd->fd;
  1472. hd=sd->hd;
  1473. WFIFOHEAD(fd, packet_len(0x239));
  1474. WFIFOW(fd,0) = 0x239;
  1475. WFIFOW(fd,2) = skill_id;
  1476. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1477. WFIFOW(fd,6) = skill->get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1478. WFIFOW(fd,8) = skill->get_range2(&hd->bl, skill_id,hd->homunculus.hskill[idx].lv);
  1479. WFIFOB(fd,10) = (hd->homunculus.hskill[idx].lv < skill->get_max(hd->homunculus.hskill[idx].id)) ? 1 : 0;
  1480. WFIFOSET(fd,packet_len(0x239));
  1481. }
  1482. void clif_hom_food(struct map_session_data *sd,int foodid,int fail)
  1483. {
  1484. int fd;
  1485. nullpo_retv(sd);
  1486. fd = sd->fd;
  1487. WFIFOHEAD(fd,packet_len(0x22f));
  1488. WFIFOW(fd,0)=0x22f;
  1489. WFIFOB(fd,2)=fail;
  1490. WFIFOW(fd,3)=foodid;
  1491. WFIFOSET(fd,packet_len(0x22f));
  1492. return;
  1493. }
  1494. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1495. /// 0087 <walk start time>.L <walk data>.6B
  1496. void clif_walkok(struct map_session_data *sd)
  1497. {
  1498. int fd;
  1499. nullpo_retv(sd);
  1500. fd = sd->fd;
  1501. WFIFOHEAD(fd, packet_len(0x87));
  1502. WFIFOW(fd,0)=0x87;
  1503. WFIFOL(fd,2)=(unsigned int)timer->gettick();
  1504. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1505. WFIFOSET(fd,packet_len(0x87));
  1506. }
  1507. void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud) {
  1508. #ifdef ANTI_MAYAP_CHEAT
  1509. struct status_change *sc = NULL;
  1510. #endif
  1511. nullpo_retv(bl);
  1512. nullpo_retv(vd);
  1513. nullpo_retv(ud);
  1514. #ifdef ANTI_MAYAP_CHEAT
  1515. if( (sc = status->get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK) )
  1516. clif->ally_only = true;
  1517. #endif
  1518. clif->set_unit_walking(bl,NULL,ud,AREA_WOS);
  1519. if(vd->cloth_color)
  1520. clif->refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1521. if (vd->body_style)
  1522. clif->refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1523. switch(bl->type) {
  1524. case BL_PC:
  1525. {
  1526. struct map_session_data *sd = BL_UCAST(BL_PC, bl);
  1527. //clif_movepc(sd);
  1528. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1529. clif->specialeffect(&sd->bl,423,AREA);
  1530. else if(sd->state.size==SZ_MEDIUM)
  1531. clif->specialeffect(&sd->bl,421,AREA);
  1532. }
  1533. break;
  1534. case BL_MOB:
  1535. {
  1536. struct mob_data *md = BL_UCAST(BL_MOB, bl);
  1537. if (md->special_state.size == SZ_BIG) // tiny/big mobs [Valaris]
  1538. clif->specialeffect(&md->bl,423,AREA);
  1539. else if (md->special_state.size == SZ_MEDIUM)
  1540. clif->specialeffect(&md->bl,421,AREA);
  1541. }
  1542. break;
  1543. case BL_PET:
  1544. if( vd->head_bottom ) // needed to display pet equip properly
  1545. clif->send_petdata(NULL, BL_UCAST(BL_PET, bl), 3, vd->head_bottom);
  1546. break;
  1547. }
  1548. #ifdef ANTI_MAYAP_CHEAT
  1549. clif->ally_only = false;
  1550. #endif
  1551. }
  1552. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1553. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1554. /// Note: unit must not be self
  1555. void clif_move(struct unit_data *ud)
  1556. {
  1557. unsigned char buf[16];
  1558. struct view_data *vd;
  1559. struct block_list *bl;
  1560. #ifdef ANTI_MAYAP_CHEAT
  1561. struct status_change *sc = NULL;
  1562. #endif
  1563. nullpo_retv(ud);
  1564. bl = ud->bl;
  1565. nullpo_retv(bl);
  1566. vd = status->get_viewdata(bl);
  1567. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1568. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1569. if (bl->type == BL_NPC) {
  1570. // Hide NPC from maya purple card.
  1571. struct npc_data *nd = BL_UCAST(BL_NPC, bl);
  1572. if (nd->chat_id == 0 && (nd->option&OPTION_INVISIBLE))
  1573. return;
  1574. }
  1575. if (ud->state.speed_changed) {
  1576. // Since we don't know how to update the speed of other objects,
  1577. // use the old walk packet to update the data.
  1578. ud->state.speed_changed = 0;
  1579. clif->move2(bl, vd, ud);
  1580. return;
  1581. }
  1582. #ifdef ANTI_MAYAP_CHEAT
  1583. if( (sc = status->get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE) )
  1584. clif->ally_only = true;
  1585. #endif
  1586. WBUFW(buf,0)=0x86;
  1587. WBUFL(buf,2)=bl->id;
  1588. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1589. WBUFL(buf,12)=(unsigned int)timer->gettick();
  1590. clif->send(buf, packet_len(0x86), bl, AREA_WOS);
  1591. if (disguised(bl)) {
  1592. WBUFL(buf,2)=-bl->id;
  1593. clif->send(buf, packet_len(0x86), bl, SELF);
  1594. }
  1595. #ifdef ANTI_MAYAP_CHEAT
  1596. clif->ally_only = false;
  1597. #endif
  1598. }
  1599. /*==========================================
  1600. * Delays the map->quit of a player after they are disconnected. [Skotlex]
  1601. *------------------------------------------*/
  1602. int clif_delayquit(int tid, int64 tick, int id, intptr_t data) {
  1603. struct map_session_data *sd = NULL;
  1604. //Remove player from map server
  1605. if ((sd = map->id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1606. map->quit(sd);
  1607. return 0;
  1608. }
  1609. /*==========================================
  1610. *
  1611. *------------------------------------------*/
  1612. void clif_quitsave(int fd, struct map_session_data *sd) {
  1613. nullpo_retv(sd);
  1614. if (!battle_config.prevent_logout ||
  1615. DIFF_TICK(timer->gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1616. map->quit(sd);
  1617. else if (sd->fd) {
  1618. //Disassociate session from player (session is deleted after this function was called)
  1619. //And set a timer to make him quit later.
  1620. sockt->session[sd->fd]->session_data = NULL;
  1621. sd->fd = 0;
  1622. timer->add(timer->gettick() + 10000, clif->delayquit, sd->bl.id, 0);
  1623. }
  1624. }
  1625. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1626. /// 0091 <map name>.16B <x>.W <y>.W
  1627. void clif_changemap(struct map_session_data *sd, short m, int x, int y) {
  1628. int fd;
  1629. nullpo_retv(sd);
  1630. fd = sd->fd;
  1631. WFIFOHEAD(fd,packet_len(0x91));
  1632. WFIFOW(fd,0) = 0x91;
  1633. mapindex->getmapname_ext(map->list[m].custom_name ? map->list[map->list[m].instance_src_map].name : map->list[m].name, (char*)WFIFOP(fd,2));
  1634. WFIFOW(fd,18) = x;
  1635. WFIFOW(fd,20) = y;
  1636. WFIFOSET(fd,packet_len(0x91));
  1637. }
  1638. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1639. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1640. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port) {
  1641. int fd;
  1642. nullpo_retv(sd);
  1643. fd = sd->fd;
  1644. WFIFOHEAD(fd,packet_len(0x92));
  1645. WFIFOW(fd,0) = 0x92;
  1646. mapindex->getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1647. WFIFOW(fd,18) = x;
  1648. WFIFOW(fd,20) = y;
  1649. WFIFOL(fd,22) = htonl(ip);
  1650. WFIFOW(fd,26) = sockt->ntows(htons(port)); // [!] LE byte order here [!]
  1651. WFIFOSET(fd,packet_len(0x92));
  1652. }
  1653. void clif_blown(struct block_list *bl)
  1654. {
  1655. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1656. nullpo_retv(bl);
  1657. clif->fixpos(bl);
  1658. clif->slide(bl, bl->x, bl->y);
  1659. }
  1660. /// Visually moves(slides) a character to x,y. If the target cell
  1661. /// isn't walkable, the char doesn't move at all. If the char is
  1662. /// sitting it will stand up (ZC_STOPMOVE).
  1663. /// 0088 <id>.L <x>.W <y>.W
  1664. void clif_fixpos(struct block_list *bl) {
  1665. unsigned char buf[10];
  1666. nullpo_retv(bl);
  1667. WBUFW(buf,0) = 0x88;
  1668. WBUFL(buf,2) = bl->id;
  1669. WBUFW(buf,6) = bl->x;
  1670. WBUFW(buf,8) = bl->y;
  1671. clif->send(buf, packet_len(0x88), bl, AREA);
  1672. if( disguised(bl) ) {
  1673. WBUFL(buf,2) = -bl->id;
  1674. clif->send(buf, packet_len(0x88), bl, SELF);
  1675. }
  1676. }
  1677. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1678. /// 00c4 <shop id>.L
  1679. void clif_npcbuysell(struct map_session_data* sd, int id)
  1680. {
  1681. int fd;
  1682. nullpo_retv(sd);
  1683. fd=sd->fd;
  1684. WFIFOHEAD(fd, packet_len(0xc4));
  1685. WFIFOW(fd,0)=0xc4;
  1686. WFIFOL(fd,2)=id;
  1687. WFIFOSET(fd,packet_len(0xc4));
  1688. }
  1689. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1690. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1691. void clif_buylist(struct map_session_data *sd, struct npc_data *nd) {
  1692. struct npc_item_list *shop = NULL;
  1693. unsigned short shop_size = 0;
  1694. int fd,i,c;
  1695. nullpo_retv(sd);
  1696. nullpo_retv(nd);
  1697. if( nd->subtype == SCRIPT ) {
  1698. shop = nd->u.scr.shop->item;
  1699. shop_size = nd->u.scr.shop->items;
  1700. } else {
  1701. shop = nd->u.shop.shop_item;
  1702. shop_size = nd->u.shop.count;
  1703. }
  1704. fd = sd->fd;
  1705. WFIFOHEAD(fd, 4 + shop_size * 11);
  1706. WFIFOW(fd,0) = 0xc6;
  1707. c = 0;
  1708. for( i = 0; i < shop_size; i++ ) {
  1709. if( shop[i].nameid ) {
  1710. struct item_data* id = itemdb->exists(shop[i].nameid);
  1711. int val = shop[i].value;
  1712. if( id == NULL )
  1713. continue;
  1714. WFIFOL(fd, 4+c*11) = val;
  1715. WFIFOL(fd, 8+c*11) = pc->modifybuyvalue(sd,val);
  1716. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1717. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1718. c++;
  1719. }
  1720. }
  1721. WFIFOW(fd,2) = 4 + c*11;
  1722. WFIFOSET(fd,WFIFOW(fd,2));
  1723. }
  1724. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1725. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1726. void clif_selllist(struct map_session_data *sd)
  1727. {
  1728. int fd,i,c=0,val;
  1729. nullpo_retv(sd);
  1730. fd=sd->fd;
  1731. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1732. WFIFOW(fd,0)=0xc7;
  1733. for( i = 0; i < MAX_INVENTORY; i++ )
  1734. {
  1735. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1736. {
  1737. if( !itemdb_cansell(&sd->status.inventory[i], pc_get_group_level(sd)) )
  1738. continue;
  1739. if( sd->status.inventory[i].expire_time )
  1740. continue; // Cannot Sell Rental Items
  1741. if( sd->status.inventory[i].bound && !pc_can_give_bound_items(sd))
  1742. continue; // Don't allow sale of bound items
  1743. val=sd->inventory_data[i]->value_sell;
  1744. if( val < 0 )
  1745. continue;
  1746. WFIFOW(fd,4+c*10)=i+2;
  1747. WFIFOL(fd,6+c*10)=val;
  1748. WFIFOL(fd,10+c*10)=pc->modifysellvalue(sd,val);
  1749. c++;
  1750. }
  1751. }
  1752. WFIFOW(fd,2)=c*10+4;
  1753. WFIFOSET(fd,WFIFOW(fd,2));
  1754. }
  1755. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1756. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1757. /// Client behavior (dialog window):
  1758. /// - disable mouse targeting
  1759. /// - open the dialog window
  1760. /// - set npcid of dialog window (0 by default)
  1761. /// - if set to clear on next mes, clear contents
  1762. /// - append this text
  1763. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes) {
  1764. int fd = sd->fd;
  1765. size_t slen;
  1766. nullpo_retv(sd);
  1767. nullpo_retv(mes);
  1768. slen = strlen(mes) + 9;
  1769. sd->state.dialog = 1;
  1770. WFIFOHEAD(fd, slen);
  1771. WFIFOW(fd,0)=0xb4;
  1772. WFIFOW(fd,2)=slen;
  1773. WFIFOL(fd,4)=npcid;
  1774. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1775. WFIFOSET(fd,WFIFOW(fd,2));
  1776. }
  1777. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1778. /// 00b5 <npc id>.L
  1779. /// Client behavior (dialog window):
  1780. /// - disable mouse targeting
  1781. /// - open the dialog window
  1782. /// - add 'next' button
  1783. /// When 'next' is pressed:
  1784. /// - 00B9 <npcid of dialog window>.L
  1785. /// - set to clear on next mes
  1786. /// - remove 'next' button
  1787. void clif_scriptnext(struct map_session_data *sd, int npcid)
  1788. {
  1789. int fd;
  1790. nullpo_retv(sd);
  1791. fd=sd->fd;
  1792. WFIFOHEAD(fd, packet_len(0xb5));
  1793. WFIFOW(fd,0)=0xb5;
  1794. WFIFOL(fd,2)=npcid;
  1795. WFIFOSET(fd,packet_len(0xb5));
  1796. }
  1797. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1798. /// 00b6 <npc id>.L
  1799. /// Client behavior:
  1800. /// - if dialog window is open:
  1801. /// - remove 'next' button
  1802. /// - add 'close' button
  1803. /// - else:
  1804. /// - enable mouse targeting
  1805. /// - close the dialog window
  1806. /// - close the menu window
  1807. /// When 'close' is pressed:
  1808. /// - enable mouse targeting
  1809. /// - close the dialog window
  1810. /// - close the menu window
  1811. /// - 0146 <npcid of dialog window>.L
  1812. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1813. {
  1814. int fd;
  1815. nullpo_retv(sd);
  1816. fd=sd->fd;
  1817. WFIFOHEAD(fd, packet_len(0xb6));
  1818. WFIFOW(fd,0)=0xb6;
  1819. WFIFOL(fd,2)=npcid;
  1820. WFIFOSET(fd,packet_len(0xb6));
  1821. }
  1822. /*==========================================
  1823. *
  1824. *------------------------------------------*/
  1825. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1826. unsigned char *buf;
  1827. int fd;
  1828. nullpo_retv(sd);
  1829. fd = sd->fd;
  1830. sd->state.using_fake_npc = 1;
  1831. WFIFOHEAD(fd, packet_len(0x78));
  1832. buf = WFIFOP(fd,0);
  1833. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1834. WBUFW(buf,0)=0x78;
  1835. #if PACKETVER >= 20071106
  1836. WBUFB(buf,2) = 0; // object type
  1837. buf = WFIFOP(fd,1);
  1838. #endif
  1839. WBUFL(buf,2)=npcid;
  1840. WBUFW(buf,14)=111;
  1841. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1842. WBUFB(buf,49)=5;
  1843. WBUFB(buf,50)=5;
  1844. WFIFOSET(fd, packet_len(0x78));
  1845. }
  1846. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1847. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1848. /// Client behavior:
  1849. /// - disable mouse targeting
  1850. /// - close the menu window
  1851. /// - open the menu window
  1852. /// - add options to the menu (separated in the text by ":")
  1853. /// - set npcid of menu window
  1854. /// - if dialog window is open:
  1855. /// - remove 'next' button
  1856. /// When 'ok' is pressed:
  1857. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1858. /// - close the menu window
  1859. /// When 'cancel' is pressed:
  1860. /// - 00B8 <npcid of menu window>.L <-1>.B
  1861. /// - enable mouse targeting
  1862. /// - close a bunch of windows...
  1863. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1864. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1865. /// TODO investigate behavior of other windows [FlavioJS]
  1866. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes) {
  1867. int fd;
  1868. size_t slen;
  1869. struct block_list *bl = NULL;
  1870. nullpo_retv(sd);
  1871. nullpo_retv(mes);
  1872. fd = sd->fd;
  1873. slen = strlen(mes) + 9;
  1874. if (!sd->state.using_fake_npc && (npcid == npc->fake_nd->bl.id || ((bl = map->id2bl(npcid)) != NULL && (bl->m!=sd->bl.m ||
  1875. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1876. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1877. clif->sendfakenpc(sd, npcid);
  1878. WFIFOHEAD(fd, slen);
  1879. WFIFOW(fd,0)=0xb7;
  1880. WFIFOW(fd,2)=slen;
  1881. WFIFOL(fd,4)=npcid;
  1882. memcpy((char*)WFIFOP(fd,8), mes, slen-8);
  1883. WFIFOSET(fd,WFIFOW(fd,2));
  1884. }
  1885. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  1886. /// 0142 <npc id>.L
  1887. /// Client behavior (inputnum window):
  1888. /// - if npcid exists in the client:
  1889. /// - open the inputnum window
  1890. /// - set npcid of inputnum window
  1891. /// When 'ok' is pressed:
  1892. /// - if inputnum window has text:
  1893. /// - if npcid exists in the client:
  1894. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1895. /// - close inputnum window
  1896. void clif_scriptinput(struct map_session_data *sd, int npcid) {
  1897. int fd;
  1898. struct block_list *bl = NULL;
  1899. nullpo_retv(sd);
  1900. if (!sd->state.using_fake_npc && (npcid == npc->fake_nd->bl.id || ((bl = map->id2bl(npcid)) != NULL && (bl->m!=sd->bl.m ||
  1901. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1902. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1903. clif->sendfakenpc(sd, npcid);
  1904. fd=sd->fd;
  1905. WFIFOHEAD(fd, packet_len(0x142));
  1906. WFIFOW(fd,0)=0x142;
  1907. WFIFOL(fd,2)=npcid;
  1908. WFIFOSET(fd,packet_len(0x142));
  1909. }
  1910. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  1911. /// 01d4 <npc id>.L
  1912. /// Client behavior (inputstr window):
  1913. /// - if npcid is 0 or npcid exists in the client:
  1914. /// - open the inputstr window
  1915. /// - set npcid of inputstr window
  1916. /// When 'ok' is pressed:
  1917. /// - if inputstr window has text and isn't an insult(manner.txt):
  1918. /// - if npcid is 0 or npcid exists in the client:
  1919. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1920. /// - close inputstr window
  1921. void clif_scriptinputstr(struct map_session_data *sd, int npcid) {
  1922. int fd;
  1923. struct block_list *bl = NULL;
  1924. nullpo_retv(sd);
  1925. if (!sd->state.using_fake_npc && (npcid == npc->fake_nd->bl.id || ((bl = map->id2bl(npcid)) != NULL && (bl->m!=sd->bl.m ||
  1926. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1927. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1928. clif->sendfakenpc(sd, npcid);
  1929. fd=sd->fd;
  1930. WFIFOHEAD(fd, packet_len(0x1d4));
  1931. WFIFOW(fd,0)=0x1d4;
  1932. WFIFOL(fd,2)=npcid;
  1933. WFIFOSET(fd,packet_len(0x1d4));
  1934. }
  1935. /// Marks a position on client's minimap (ZC_COMPASS).
  1936. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  1937. /// npc id:
  1938. /// is ignored in the client
  1939. /// type:
  1940. /// 0 = display mark for 15 seconds
  1941. /// 1 = display mark until dead or teleported
  1942. /// 2 = remove mark
  1943. /// color:
  1944. /// 0x00RRGGBB
  1945. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1946. {
  1947. int fd;
  1948. nullpo_retv(sd);
  1949. fd=sd->fd;
  1950. WFIFOHEAD(fd, packet_len(0x144));
  1951. WFIFOW(fd,0)=0x144;
  1952. WFIFOL(fd,2)=npc_id;
  1953. WFIFOL(fd,6)=type;
  1954. WFIFOL(fd,10)=x;
  1955. WFIFOL(fd,14)=y;
  1956. WFIFOB(fd,18)=id;
  1957. WFIFOL(fd,19)=color;
  1958. WFIFOSET(fd,packet_len(0x144));
  1959. }
  1960. /// Displays an illustration image.
  1961. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  1962. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  1963. /// type:
  1964. /// 0 = bottom left corner
  1965. /// 1 = bottom middle
  1966. /// 2 = bottom right corner
  1967. /// 3 = middle of screen, inside a movable window
  1968. /// 4 = middle of screen, movable with a close button, chrome-less
  1969. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  1970. {
  1971. int fd;
  1972. nullpo_retv(sd);
  1973. fd=sd->fd;
  1974. WFIFOHEAD(fd, packet_len(0x1b3));
  1975. WFIFOW(fd,0)=0x1b3;
  1976. strncpy((char*)WFIFOP(fd,2),image,64);
  1977. WFIFOB(fd,66)=type;
  1978. WFIFOSET(fd,packet_len(0x1b3));
  1979. }
  1980. /*==========================================
  1981. * Fills in card data from the given item and into the buffer. [Skotlex]
  1982. *------------------------------------------*/
  1983. void clif_addcards(unsigned char* buf, struct item* item) {
  1984. int i=0,j;
  1985. nullpo_retv(buf);
  1986. if( item == NULL ) { //Blank data
  1987. WBUFW(buf,0) = 0;
  1988. WBUFW(buf,2) = 0;
  1989. WBUFW(buf,4) = 0;
  1990. WBUFW(buf,6) = 0;
  1991. return;
  1992. }
  1993. if( item->card[0] == CARD0_PET ) { //pet eggs
  1994. WBUFW(buf,0) = 0;
  1995. WBUFW(buf,2) = 0;
  1996. WBUFW(buf,4) = 0;
  1997. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1998. return;
  1999. }
  2000. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2001. WBUFW(buf,0) = item->card[0];
  2002. WBUFW(buf,2) = item->card[1];
  2003. WBUFW(buf,4) = item->card[2];
  2004. WBUFW(buf,6) = item->card[3];
  2005. return;
  2006. }
  2007. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2008. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2009. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2010. //Normal items.
  2011. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2012. WBUFW(buf,0) = j;
  2013. else
  2014. WBUFW(buf,0) = item->card[i];
  2015. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2016. WBUFW(buf,2) = j;
  2017. else
  2018. WBUFW(buf,2) = item->card[i];
  2019. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2020. WBUFW(buf,4) = j;
  2021. else
  2022. WBUFW(buf,4) = item->card[i];
  2023. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2024. WBUFW(buf,6) = j;
  2025. else
  2026. WBUFW(buf,6) = item->card[i];
  2027. }
  2028. void clif_addcards2(unsigned short *cards, struct item* item) {
  2029. int i=0,j;
  2030. nullpo_retv(cards);
  2031. if( item == NULL ) { //Blank data
  2032. cards[0] = 0;
  2033. cards[1] = 0;
  2034. cards[2] = 0;
  2035. cards[3] = 0;
  2036. return;
  2037. }
  2038. if( item->card[0] == CARD0_PET ) { //pet eggs
  2039. cards[0] = 0;
  2040. cards[1] = 0;
  2041. cards[2] = 0;
  2042. cards[3] = item->card[3]; //Pet renamed flag.
  2043. return;
  2044. }
  2045. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2046. cards[0] = item->card[0];
  2047. cards[1] = item->card[1];
  2048. cards[2] = item->card[2];
  2049. cards[3] = item->card[3];
  2050. return;
  2051. }
  2052. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2053. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2054. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2055. //Normal items.
  2056. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2057. cards[0] = j;
  2058. else
  2059. cards[0] = item->card[i];
  2060. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2061. cards[1] = j;
  2062. else
  2063. cards[1] = item->card[i];
  2064. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2065. cards[2] = j;
  2066. else
  2067. cards[2] = item->card[i];
  2068. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2069. cards[3] = j;
  2070. else
  2071. cards[3] = item->card[i];
  2072. }
  2073. /**
  2074. * Fills in RandomOptions(Bonuses) of items into the buffer
  2075. *
  2076. * Dummy datais used since this feature isn't supported yet (ITEM_RDM_OPT).
  2077. * A maximum of 5 random options can be supported.
  2078. *
  2079. * @param buf[in,out] The buffer to write to. The pointer must be valid and initialized.
  2080. * @param item[in] The source item.
  2081. */
  2082. void clif_add_random_options(unsigned char* buf, struct item* item)
  2083. {
  2084. int i;
  2085. nullpo_retv(buf);
  2086. for (i = 0; i < 5; i++){
  2087. WBUFW(buf,i*5+0) = 0; // OptIndex
  2088. WBUFW(buf,i*5+2) = 0; // Value
  2089. WBUFB(buf,i*5+4) = 0; // Param1
  2090. }
  2091. }
  2092. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2093. /// 00a0 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B (ZC_ITEM_PICKUP_ACK)
  2094. /// 029a <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B <expire time>.L (ZC_ITEM_PICKUP_ACK2)
  2095. /// 02d4 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK3)
  2096. /// 0990 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK_V5)
  2097. /// 0a0c <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK_V6)
  2098. void clif_additem(struct map_session_data *sd, int n, int amount, int fail) {
  2099. struct packet_additem p;
  2100. nullpo_retv(sd);
  2101. if (!sockt->session_is_active(sd->fd)) //Sasuke-
  2102. return;
  2103. if( fail )
  2104. memset(&p, 0, sizeof(p));
  2105. p.PacketType = additemType;
  2106. p.Index = n+2;
  2107. p.count = amount;
  2108. if( !fail ) {
  2109. #if PACKETVER >= 20150226
  2110. int i;
  2111. #endif
  2112. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  2113. return;
  2114. if (sd->inventory_data[n]->view_id > 0)
  2115. p.nameid = sd->inventory_data[n]->view_id;
  2116. else
  2117. p.nameid = sd->status.inventory[n].nameid;
  2118. p.IsIdentified = sd->status.inventory[n].identify ? 1 : 0;
  2119. p.IsDamaged = sd->status.inventory[n].attribute ? 1 : 0;
  2120. p.refiningLevel =sd->status.inventory[n].refine;
  2121. clif->addcards2(&p.slot.card[0], &sd->status.inventory[n]);
  2122. p.location = pc->equippoint(sd,n);
  2123. p.type = itemtype(sd->inventory_data[n]->type);
  2124. #if PACKETVER >= 20061218
  2125. p.HireExpireDate = sd->status.inventory[n].expire_time;
  2126. #endif
  2127. #if PACKETVER >= 20071002
  2128. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2129. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2130. */
  2131. p.bindOnEquipType = sd->status.inventory[n].bound && !itemdb->isstackable2(sd->inventory_data[n]) ? 2 : sd->inventory_data[n]->flag.bindonequip ? 1 : 0;
  2132. #endif
  2133. #if PACKETVER >= 20150226
  2134. for (i=0; i<5; i++){
  2135. p.option_data[i].index = 0;
  2136. p.option_data[i].value = 0;
  2137. p.option_data[i].param = 0;
  2138. }
  2139. #endif
  2140. }
  2141. p.result = (unsigned char)fail;
  2142. clif->send(&p,sizeof(p),&sd->bl,SELF);
  2143. }
  2144. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2145. /// 00af <index>.W <amount>.W
  2146. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2147. {
  2148. int fd;
  2149. nullpo_retv(sd);
  2150. fd=sd->fd;
  2151. WFIFOHEAD(fd, packet_len(0xaf));
  2152. WFIFOW(fd,0)=0xaf;
  2153. WFIFOW(fd,2)=n+2;
  2154. WFIFOW(fd,4)=amount;
  2155. WFIFOSET(fd,packet_len(0xaf));
  2156. }
  2157. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2158. /// 07fa <delete type>.W <index>.W <amount>.W
  2159. /// delete type: @see enum delitem_reason
  2160. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2161. {
  2162. #if PACKETVER < 20091117
  2163. clif->dropitem(sd,n,amount);
  2164. #else
  2165. int fd;
  2166. nullpo_retv(sd);
  2167. fd=sd->fd;
  2168. WFIFOHEAD(fd, packet_len(0x7fa));
  2169. WFIFOW(fd,0)=0x7fa;
  2170. WFIFOW(fd,2)=reason;
  2171. WFIFOW(fd,4)=n+2;
  2172. WFIFOW(fd,6)=amount;
  2173. WFIFOSET(fd,packet_len(0x7fa));
  2174. #endif
  2175. }
  2176. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2177. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2178. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2179. // look like unused, not adding checks
  2180. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip) {
  2181. if (id->view_id > 0)
  2182. WBUFW(buf,n)=id->view_id;
  2183. else
  2184. WBUFW(buf,n)=i->nameid;
  2185. WBUFB(buf,n+2)=itemtype(id->type);
  2186. WBUFB(buf,n+3)=i->identify;
  2187. if (equip >= 0) { //Equippable item
  2188. WBUFW(buf,n+4)=equip;
  2189. WBUFW(buf,n+6)=i->equip;
  2190. WBUFB(buf,n+8)=i->attribute;
  2191. WBUFB(buf,n+9)=i->refine;
  2192. } else { //Stackable item.
  2193. WBUFW(buf,n+4)=i->amount;
  2194. if (equip == -2 && id->equip == EQP_AMMO)
  2195. WBUFW(buf,n+6)=EQP_AMMO;
  2196. else
  2197. WBUFW(buf,n+6)=0;
  2198. }
  2199. }
  2200. void clif_item_equip(short idx, struct EQUIPITEM_INFO *p, struct item *i, struct item_data *id, int eqp_pos) {
  2201. #if PACKETVER >= 20150226
  2202. int j;
  2203. #endif
  2204. nullpo_retv(p);
  2205. nullpo_retv(i);
  2206. nullpo_retv(id);
  2207. p->index = idx;
  2208. if (id->view_id > 0)
  2209. p->ITID = id->view_id;
  2210. else
  2211. p->ITID = i->nameid;
  2212. p->type = itemtype(id->type);
  2213. #if PACKETVER < 20120925
  2214. p->IsIdentified = i->identify ? 1 : 0;
  2215. #endif
  2216. p->location = eqp_pos;
  2217. p->WearState = i->equip;
  2218. #if PACKETVER < 20120925
  2219. p->IsDamaged = i->attribute ? 1 : 0;
  2220. #endif
  2221. p->RefiningLevel = i->refine;
  2222. clif->addcards2(&p->slot.card[0], i);
  2223. #if PACKETVER >= 20071002
  2224. p->HireExpireDate = i->expire_time;
  2225. #endif
  2226. #if PACKETVER >= 20080102
  2227. p->bindOnEquipType = i->bound ? 2 : id->flag.bindonequip ? 1 : 0;
  2228. #endif
  2229. #if PACKETVER >= 20100629
  2230. p->wItemSpriteNumber = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2231. #endif
  2232. #if PACKETVER >= 20120925
  2233. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2234. p->Flag.IsDamaged = i->attribute ? 1 : 0;
  2235. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2236. p->Flag.SpareBits = 0;
  2237. #endif
  2238. #if PACKETVER >= 20150226
  2239. p->option_count = 0;
  2240. for (j=0; j<5; j++){
  2241. p->option_data[j].index = 0;
  2242. p->option_data[j].value = 0;
  2243. p->option_data[j].param = 0;
  2244. }
  2245. #endif
  2246. }
  2247. void clif_item_normal(short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id) {
  2248. nullpo_retv(p);
  2249. nullpo_retv(i);
  2250. nullpo_retv(id);
  2251. p->index = idx;
  2252. if (id->view_id > 0)
  2253. p->ITID = id->view_id;
  2254. else
  2255. p->ITID = i->nameid;
  2256. p->type = itemtype(id->type);
  2257. #if PACKETVER < 20120925
  2258. p->IsIdentified = i->identify ? 1 : 0;
  2259. #endif
  2260. p->count = i->amount;
  2261. p->WearState = id->equip;
  2262. #if PACKETVER >= 5
  2263. clif->addcards2(&p->slot.card[0], i);
  2264. #endif
  2265. #if PACKETVER >= 20080102
  2266. p->HireExpireDate = i->expire_time;
  2267. #endif
  2268. #if PACKETVER >= 20120925
  2269. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2270. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2271. p->Flag.SpareBits = 0;
  2272. #endif
  2273. }
  2274. void clif_inventorylist(struct map_session_data *sd) {
  2275. int i, normal = 0, equip = 0;
  2276. nullpo_retv(sd);
  2277. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2278. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2279. continue;
  2280. if( !itemdb->isstackable2(sd->inventory_data[i]) ) //Non-stackable (Equippable)
  2281. clif->item_equip(i+2,&itemlist_equip.list[equip++],&sd->status.inventory[i],sd->inventory_data[i],pc->equippoint(sd,i));
  2282. else //Stackable (Normal)
  2283. clif->item_normal(i+2,&itemlist_normal.list[normal++],&sd->status.inventory[i],sd->inventory_data[i]);
  2284. }
  2285. if( normal ) {
  2286. itemlist_normal.PacketType = inventorylistnormalType;
  2287. itemlist_normal.PacketLength = 4 + (sizeof(struct NORMALITEM_INFO) * normal);
  2288. clif->send(&itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF);
  2289. }
  2290. if( sd->equip_index[EQI_AMMO] >= 0 )
  2291. clif->arrowequip(sd,sd->equip_index[EQI_AMMO]);
  2292. if( equip ) {
  2293. itemlist_equip.PacketType = inventorylistequipType;
  2294. itemlist_equip.PacketLength = 4 + (sizeof(struct EQUIPITEM_INFO) * equip);
  2295. clif->send(&itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF);
  2296. }
  2297. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2298. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2299. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2300. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2301. continue;
  2302. if ( sd->status.inventory[i].favorite )
  2303. clif->favorite_item(sd, i);
  2304. }
  2305. #endif
  2306. }
  2307. //Required when items break/get-repaired. Only sends equippable item list.
  2308. void clif_equiplist(struct map_session_data *sd) {
  2309. int i, equip = 0;
  2310. nullpo_retv(sd);
  2311. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2312. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2313. continue;
  2314. if( !itemdb->isstackable2(sd->inventory_data[i]) ) //Non-stackable (Equippable)
  2315. clif->item_equip(i+2,&itemlist_equip.list[equip++],&sd->status.inventory[i],sd->inventory_data[i],pc->equippoint(sd,i));
  2316. }
  2317. if( equip ) {
  2318. itemlist_equip.PacketType = inventorylistequipType;
  2319. itemlist_equip.PacketLength = 4 + (sizeof(struct EQUIPITEM_INFO) * equip);
  2320. clif->send(&itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF);
  2321. }
  2322. /* on 20120925 onwards this is a field on clif_item_equip */
  2323. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2324. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2325. if( sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2326. continue;
  2327. if ( sd->status.inventory[i].favorite )
  2328. clif->favorite_item(sd, i);
  2329. }
  2330. #endif
  2331. }
  2332. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length) {
  2333. int i = 0;
  2334. struct item_data *id;
  2335. nullpo_retv(sd);
  2336. nullpo_retv(items);
  2337. do {
  2338. int normal = 0, equip = 0, k = 0;
  2339. for( ; i < items_length && k < 500; i++, k++ ) {
  2340. if( items[i].nameid <= 0 )
  2341. continue;
  2342. id = itemdb->search(items[i].nameid);
  2343. if( !itemdb->isstackable2(id) ) //Non-stackable (Equippable)
  2344. clif->item_equip(i+1,&storelist_equip.list[equip++],&items[i],id,id->equip);
  2345. else //Stackable (Normal)
  2346. clif->item_normal(i+1,&storelist_normal.list[normal++],&items[i],id);
  2347. }
  2348. if( normal ) {
  2349. storelist_normal.PacketType = storagelistnormalType;
  2350. storelist_normal.PacketLength = ( sizeof( storelist_normal ) - sizeof( storelist_normal.list ) ) + (sizeof(struct NORMALITEM_INFO) * normal);
  2351. #if PACKETVER >= 20120925
  2352. safestrncpy(storelist_normal.name, "Storage", NAME_LENGTH);
  2353. #endif
  2354. clif->send(&storelist_normal, storelist_normal.PacketLength, &sd->bl, SELF);
  2355. }
  2356. if( equip ) {
  2357. storelist_equip.PacketType = storagelistequipType;
  2358. storelist_equip.PacketLength = ( sizeof( storelist_equip ) - sizeof( storelist_equip.list ) ) + (sizeof(struct EQUIPITEM_INFO) * equip);
  2359. #if PACKETVER >= 20120925
  2360. safestrncpy(storelist_equip.name, "Storage", NAME_LENGTH);
  2361. #endif
  2362. clif->send(&storelist_equip, storelist_equip.PacketLength, &sd->bl, SELF);
  2363. }
  2364. } while ( i < items_length );
  2365. }
  2366. void clif_cartlist(struct map_session_data *sd) {
  2367. int i, normal = 0, equip = 0;
  2368. struct item_data *id;
  2369. nullpo_retv(sd);
  2370. for( i = 0; i < MAX_CART; i++ ) {
  2371. if( sd->status.cart[i].nameid <= 0 )
  2372. continue;
  2373. id = itemdb->search(sd->status.cart[i].nameid);
  2374. if( !itemdb->isstackable2(id) ) //Non-stackable (Equippable)
  2375. clif->item_equip(i+2,&itemlist_equip.list[equip++],&sd->status.cart[i],id,id->equip);
  2376. else //Stackable (Normal)
  2377. clif->item_normal(i+2,&itemlist_normal.list[normal++],&sd->status.cart[i],id);
  2378. }
  2379. if( normal ) {
  2380. itemlist_normal.PacketType = cartlistnormalType;
  2381. itemlist_normal.PacketLength = 4 + (sizeof(struct NORMALITEM_INFO) * normal);
  2382. clif->send(&itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF);
  2383. }
  2384. if( equip ) {
  2385. itemlist_equip.PacketType = cartlistequipType;
  2386. itemlist_equip.PacketLength = 4 + (sizeof(struct EQUIPITEM_INFO) * equip);
  2387. clif->send(&itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF);
  2388. }
  2389. }
  2390. /// Removes cart (ZC_CARTOFF).
  2391. /// 012b
  2392. /// Client behavior:
  2393. /// Closes the cart storage and removes all it's items from memory.
  2394. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2395. void clif_clearcart(int fd)
  2396. {
  2397. WFIFOHEAD(fd, packet_len(0x12b));
  2398. WFIFOW(fd,0) = 0x12b;
  2399. WFIFOSET(fd, packet_len(0x12b));
  2400. }
  2401. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2402. /// 01eb <account id>.L <x>.W <y>.W
  2403. void clif_guild_xy(struct map_session_data *sd)
  2404. {
  2405. unsigned char buf[10];
  2406. nullpo_retv(sd);
  2407. WBUFW(buf,0)=0x1eb;
  2408. WBUFL(buf,2)=sd->status.account_id;
  2409. WBUFW(buf,6)=sd->bl.x;
  2410. WBUFW(buf,8)=sd->bl.y;
  2411. clif->send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2412. }
  2413. /*==========================================
  2414. * Sends x/y dot to a single fd. [Skotlex]
  2415. *------------------------------------------*/
  2416. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2417. {
  2418. if( sd->bg_id )
  2419. return;
  2420. nullpo_retv(sd);
  2421. WFIFOHEAD(fd,packet_len(0x1eb));
  2422. WFIFOW(fd,0)=0x1eb;
  2423. WFIFOL(fd,2)=sd->status.account_id;
  2424. WFIFOW(fd,6)=sd->bl.x;
  2425. WFIFOW(fd,8)=sd->bl.y;
  2426. WFIFOSET(fd,packet_len(0x1eb));
  2427. }
  2428. // Guild XY locators [Valaris]
  2429. void clif_guild_xy_remove(struct map_session_data *sd)
  2430. {
  2431. unsigned char buf[10];
  2432. nullpo_retv(sd);
  2433. WBUFW(buf,0)=0x1eb;
  2434. WBUFL(buf,2)=sd->status.account_id;
  2435. WBUFW(buf,6)=-1;
  2436. WBUFW(buf,8)=-1;
  2437. clif->send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2438. }
  2439. /*==========================================
  2440. *
  2441. *------------------------------------------*/
  2442. int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2443. {
  2444. #if PACKETVER < 20100126
  2445. const int cmd = 0x106;
  2446. #else
  2447. const int cmd = 0x80e;
  2448. #endif
  2449. struct map_session_data *sd = va_arg(ap, struct map_session_data *);
  2450. struct map_session_data *tsd = BL_CAST(BL_PC, bl);
  2451. nullpo_ret(sd);
  2452. nullpo_ret(tsd);
  2453. if( !tsd->fd || tsd == sd )
  2454. return 0;
  2455. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2456. return 0;
  2457. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2458. WFIFOW(tsd->fd,0) = cmd;
  2459. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2460. #if PACKETVER < 20100126
  2461. if( sd->battle_status.max_hp > INT16_MAX )
  2462. { //To correctly display the %hp bar. [Skotlex]
  2463. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2464. WFIFOW(tsd->fd,8) = 100;
  2465. } else {
  2466. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2467. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2468. }
  2469. #else
  2470. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2471. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2472. #endif
  2473. WFIFOSET(tsd->fd,packet_len(cmd));
  2474. return 0;
  2475. }
  2476. /*==========================================
  2477. * Server tells all players that are allowed to view HP bars
  2478. * and are nearby 'sd' that 'sd' hp bar was updated.
  2479. *------------------------------------------*/
  2480. int clif_hpmeter(struct map_session_data *sd) {
  2481. nullpo_ret(sd);
  2482. map->foreachinarea(clif->hpmeter_sub, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd);
  2483. return 0;
  2484. }
  2485. /// Notifies client of a character parameter change.
  2486. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2487. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2488. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2489. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2490. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2491. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2492. /// TODO: Extract individual packets.
  2493. void clif_updatestatus(struct map_session_data *sd,int type)
  2494. {
  2495. int fd,len;
  2496. nullpo_retv(sd);
  2497. fd=sd->fd;
  2498. if (!sockt->session_is_active(fd)) // Invalid pointer fix, by sasuke [Kevin]
  2499. return;
  2500. WFIFOHEAD(fd, 14);
  2501. WFIFOW(fd,0)=0xb0;
  2502. WFIFOW(fd,2)=type;
  2503. len = packet_len(0xb0);
  2504. switch(type){
  2505. // 00b0
  2506. case SP_WEIGHT:
  2507. pc->updateweightstatus(sd);
  2508. WFIFOHEAD(fd,14);
  2509. WFIFOW(fd,0)=0xb0; //Need to re-set as pc->updateweightstatus can alter the buffer. [Skotlex]
  2510. WFIFOW(fd,2)=type;
  2511. WFIFOL(fd,4)=sd->weight;
  2512. break;
  2513. case SP_MAXWEIGHT:
  2514. WFIFOL(fd,4)=sd->max_weight;
  2515. break;
  2516. case SP_SPEED:
  2517. WFIFOL(fd,4)=sd->battle_status.speed;
  2518. break;
  2519. case SP_BASELEVEL:
  2520. WFIFOL(fd,4)=sd->status.base_level;
  2521. break;
  2522. case SP_JOBLEVEL:
  2523. WFIFOL(fd,4)=sd->status.job_level;
  2524. break;
  2525. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2526. WFIFOL(fd,4)=sd->status.karma;
  2527. break;
  2528. case SP_MANNER:
  2529. WFIFOL(fd,4)=sd->status.manner;
  2530. break;
  2531. case SP_STATUSPOINT:
  2532. WFIFOL(fd,4)=sd->status.status_point;
  2533. break;
  2534. case SP_SKILLPOINT:
  2535. WFIFOL(fd,4)=sd->status.skill_point;
  2536. break;
  2537. case SP_HIT:
  2538. WFIFOL(fd,4)=sd->battle_status.hit;
  2539. break;
  2540. case SP_FLEE1:
  2541. WFIFOL(fd,4)=sd->battle_status.flee;
  2542. break;
  2543. case SP_FLEE2:
  2544. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2545. break;
  2546. case SP_MAXHP:
  2547. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2548. break;
  2549. case SP_MAXSP:
  2550. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2551. break;
  2552. case SP_HP:
  2553. WFIFOL(fd,4)=sd->battle_status.hp;
  2554. // TODO: Won't these overwrite the current packet?
  2555. if( map->list[sd->bl.m].hpmeter_visible )
  2556. clif->hpmeter(sd);
  2557. if( !battle_config.party_hp_mode && sd->status.party_id )
  2558. clif->party_hp(sd);
  2559. if( sd->bg_id )
  2560. clif->bg_hp(sd);
  2561. break;
  2562. case SP_SP:
  2563. WFIFOL(fd,4)=sd->battle_status.sp;
  2564. break;
  2565. case SP_ASPD:
  2566. WFIFOL(fd,4)=sd->battle_status.amotion;
  2567. break;
  2568. case SP_ATK1:
  2569. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2570. break;
  2571. case SP_DEF1:
  2572. WFIFOL(fd,4)=pc_leftside_def(sd);
  2573. break;
  2574. case SP_MDEF1:
  2575. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2576. break;
  2577. case SP_ATK2:
  2578. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2579. break;
  2580. case SP_DEF2:
  2581. WFIFOL(fd,4)=pc_rightside_def(sd);
  2582. break;
  2583. case SP_MDEF2: {
  2584. //negative check (in case you have something like Berserk active)
  2585. int mdef2 = pc_rightside_mdef(sd);
  2586. WFIFOL(fd,4)=
  2587. #ifndef RENEWAL
  2588. ( mdef2 < 0 ) ? 0 :
  2589. #endif
  2590. mdef2;
  2591. }
  2592. break;
  2593. case SP_CRITICAL:
  2594. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2595. break;
  2596. case SP_MATK1:
  2597. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2598. break;
  2599. case SP_MATK2:
  2600. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2601. break;
  2602. case SP_ZENY:
  2603. WFIFOW(fd,0)=0xb1;
  2604. WFIFOL(fd,4)=sd->status.zeny;
  2605. len = packet_len(0xb1);
  2606. break;
  2607. case SP_BASEEXP:
  2608. WFIFOW(fd,0)=0xb1;
  2609. WFIFOL(fd,4)=sd->status.base_exp;
  2610. len = packet_len(0xb1);
  2611. break;
  2612. case SP_JOBEXP:
  2613. WFIFOW(fd,0)=0xb1;
  2614. WFIFOL(fd,4)=sd->status.job_exp;
  2615. len = packet_len(0xb1);
  2616. break;
  2617. case SP_NEXTBASEEXP:
  2618. WFIFOW(fd,0)=0xb1;
  2619. WFIFOL(fd,4)=pc->nextbaseexp(sd);
  2620. len = packet_len(0xb1);
  2621. break;
  2622. case SP_NEXTJOBEXP:
  2623. WFIFOW(fd,0)=0xb1;
  2624. WFIFOL(fd,4)=pc->nextjobexp(sd);
  2625. len = packet_len(0xb1);
  2626. break;
  2627. /**
  2628. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2629. **/
  2630. case SP_USTR:
  2631. case SP_UAGI:
  2632. case SP_UVIT:
  2633. case SP_UINT:
  2634. case SP_UDEX:
  2635. case SP_ULUK:
  2636. WFIFOW(fd,0)=0xbe;
  2637. WFIFOB(fd,4)=pc->need_status_point(sd,type-SP_USTR+SP_STR,1);
  2638. len = packet_len(0xbe);
  2639. break;
  2640. /**
  2641. * Tells the client how far it is allowed to attack (weapon range)
  2642. **/
  2643. case SP_ATTACKRANGE:
  2644. WFIFOW(fd,0)=0x13a;
  2645. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2646. len = packet_len(0x13a);
  2647. break;
  2648. case SP_STR:
  2649. WFIFOW(fd,0)=0x141;
  2650. WFIFOL(fd,2)=type;
  2651. WFIFOL(fd,6)=sd->status.str;
  2652. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2653. len = packet_len(0x141);
  2654. break;
  2655. case SP_AGI:
  2656. WFIFOW(fd,0)=0x141;
  2657. WFIFOL(fd,2)=type;
  2658. WFIFOL(fd,6)=sd->status.agi;
  2659. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2660. len = packet_len(0x141);
  2661. break;
  2662. case SP_VIT:
  2663. WFIFOW(fd,0)=0x141;
  2664. WFIFOL(fd,2)=type;
  2665. WFIFOL(fd,6)=sd->status.vit;
  2666. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2667. len = packet_len(0x141);
  2668. break;
  2669. case SP_INT:
  2670. WFIFOW(fd,0)=0x141;
  2671. WFIFOL(fd,2)=type;
  2672. WFIFOL(fd,6)=sd->status.int_;
  2673. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2674. len = packet_len(0x141);
  2675. break;
  2676. case SP_DEX:
  2677. WFIFOW(fd,0)=0x141;
  2678. WFIFOL(fd,2)=type;
  2679. WFIFOL(fd,6)=sd->status.dex;
  2680. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2681. len = packet_len(0x141);
  2682. break;
  2683. case SP_LUK:
  2684. WFIFOW(fd,0)=0x141;
  2685. WFIFOL(fd,2)=type;
  2686. WFIFOL(fd,6)=sd->status.luk;
  2687. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2688. len = packet_len(0x141);
  2689. break;
  2690. case SP_CARTINFO:
  2691. WFIFOW(fd,0)=0x121;
  2692. WFIFOW(fd,2)=sd->cart_num;
  2693. WFIFOW(fd,4)=MAX_CART;
  2694. WFIFOL(fd,6)=sd->cart_weight;
  2695. WFIFOL(fd,10)=sd->cart_weight_max;
  2696. len = packet_len(0x121);
  2697. break;
  2698. default:
  2699. ShowError("clif->updatestatus : unrecognized type %d\n",type);
  2700. return;
  2701. }
  2702. WFIFOSET(fd,len);
  2703. }
  2704. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  2705. /// 01ab <account id>.L <var id>.W <value>.L
  2706. void clif_changestatus(struct map_session_data* sd,int type,int val)
  2707. {
  2708. unsigned char buf[12];
  2709. nullpo_retv(sd);
  2710. WBUFW(buf,0)=0x1ab;
  2711. WBUFL(buf,2)=sd->bl.id;
  2712. WBUFW(buf,6)=type;
  2713. switch(type)
  2714. {
  2715. case SP_MANNER:
  2716. WBUFL(buf,8)=val;
  2717. break;
  2718. default:
  2719. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2720. return;
  2721. }
  2722. clif->send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  2723. }
  2724. /// Updates sprite/style properties of an object.
  2725. void clif_changelook(struct block_list *bl,int type,int val)
  2726. {
  2727. struct map_session_data* sd;
  2728. struct status_change* sc;
  2729. struct view_data* vd;
  2730. enum send_target target = AREA;
  2731. int val2 = 0;
  2732. nullpo_retv(bl);
  2733. sd = BL_CAST(BL_PC, bl);
  2734. sc = status->get_sc(bl);
  2735. vd = status->get_viewdata(bl);
  2736. if( vd ) //temp hack to let Warp Portal change appearance
  2737. switch(type) {
  2738. case LOOK_WEAPON:
  2739. if (sd) {
  2740. clif->get_weapon_view(sd, &vd->weapon, &vd->shield);
  2741. val = vd->weapon;
  2742. }
  2743. else
  2744. vd->weapon = val;
  2745. break;
  2746. case LOOK_SHIELD:
  2747. if (sd) {
  2748. clif->get_weapon_view(sd, &vd->weapon, &vd->shield);
  2749. val = vd->shield;
  2750. }
  2751. else
  2752. vd->shield = val;
  2753. break;
  2754. case LOOK_BASE:
  2755. if( !sd ) break;
  2756. if ( val == INVISIBLE_CLASS ) /* nothing to change look */
  2757. return;
  2758. if( sd->sc.option&OPTION_COSTUME )
  2759. vd->weapon = vd->shield = 0;
  2760. if( !vd->cloth_color )
  2761. break;
  2762. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  2763. vd->cloth_color = 0;
  2764. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  2765. vd->cloth_color = 0;
  2766. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  2767. vd->cloth_color = 0;
  2768. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  2769. vd->cloth_color = 0;
  2770. if (sd->sc.option&OPTION_OKTOBERFEST /* TODO: config? */)
  2771. vd->cloth_color = 0;
  2772. if (vd->body_style && (
  2773. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  2774. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  2775. sd->sc.option&OPTION_OKTOBERFEST))
  2776. vd->body_style = 0;
  2777. break;
  2778. case LOOK_HAIR:
  2779. vd->hair_style = val;
  2780. break;
  2781. case LOOK_HEAD_BOTTOM:
  2782. vd->head_bottom = val;
  2783. break;
  2784. case LOOK_HEAD_TOP:
  2785. vd->head_top = val;
  2786. break;
  2787. case LOOK_HEAD_MID:
  2788. vd->head_mid = val;
  2789. break;
  2790. case LOOK_HAIR_COLOR:
  2791. vd->hair_color = val;
  2792. break;
  2793. case LOOK_CLOTHES_COLOR:
  2794. if( val && sd ) {
  2795. if( sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette )
  2796. val = 0;
  2797. if( sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette )
  2798. val = 0;
  2799. if( sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette )
  2800. val = 0;
  2801. if( sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette )
  2802. val = 0;
  2803. if( sd->sc.option&OPTION_OKTOBERFEST /* TODO: config? */ )
  2804. val = 0;
  2805. }
  2806. vd->cloth_color = val;
  2807. break;
  2808. case LOOK_SHOES:
  2809. #if PACKETVER > 3
  2810. if (sd) {
  2811. int n;
  2812. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2813. if(sd->inventory_data[n]->view_id > 0)
  2814. val = sd->inventory_data[n]->view_id;
  2815. else
  2816. val = sd->status.inventory[n].nameid;
  2817. } else
  2818. val = 0;
  2819. }
  2820. #endif
  2821. //Shoes? No packet uses this....
  2822. break;
  2823. case LOOK_BODY:
  2824. case LOOK_FLOOR:
  2825. // unknown purpose
  2826. break;
  2827. case LOOK_ROBE:
  2828. #if PACKETVER < 20110111
  2829. return;
  2830. #else
  2831. vd->robe = val;
  2832. #endif
  2833. break;
  2834. case LOOK_BODY2:
  2835. if (val && (
  2836. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  2837. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  2838. sd->sc.option&OPTION_OKTOBERFEST))
  2839. val = 0;
  2840. vd->body_style = val;
  2841. break;
  2842. }
  2843. // prevent leaking the presence of GM-hidden objects
  2844. if( sc && sc->option&OPTION_INVISIBLE && !disguised(bl) )
  2845. target = SELF;
  2846. #if PACKETVER < 4
  2847. clif->sendlook(bl, bl->id, type, val, 0, target);
  2848. #else
  2849. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2850. nullpo_retv(vd);
  2851. type = LOOK_WEAPON;
  2852. val = vd->weapon;
  2853. val2 = vd->shield;
  2854. }
  2855. if( disguised(bl) ) {
  2856. clif->sendlook(bl, bl->id, type, val, val2, AREA_WOS);
  2857. clif->sendlook(bl, -bl->id, type, val, val2, SELF);
  2858. } else
  2859. clif->sendlook(bl, bl->id, type, val, val2, target);
  2860. #endif
  2861. }
  2862. //Sends a change-base-look packet required for traps as they are triggered.
  2863. void clif_changetraplook(struct block_list *bl,int val)
  2864. {
  2865. clif->sendlook(bl, bl->id, LOOK_BASE, val, 0, AREA);
  2866. }
  2867. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  2868. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  2869. void clif_sendlook(struct block_list *bl, int id, int type, int val, int val2, enum send_target target)
  2870. {
  2871. unsigned char buf[32];
  2872. #if PACKETVER < 4
  2873. WBUFW(buf,0)=0xc3;
  2874. WBUFL(buf,2)=id;
  2875. WBUFB(buf,6)=type;
  2876. WBUFB(buf,7)=val;
  2877. clif->send(buf,packet_len(0xc3),bl,target);
  2878. #else
  2879. WBUFW(buf,0)=0x1d7;
  2880. WBUFL(buf,2)=id;
  2881. WBUFB(buf,6)=type;
  2882. WBUFW(buf,7)=val;
  2883. WBUFW(buf,9)=val2;
  2884. clif->send(buf,packet_len(0x1d7),bl,target);
  2885. #endif
  2886. }
  2887. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2888. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2889. {
  2890. clif->sendlook(bl, id, type, val, 0, target);
  2891. }
  2892. /// Character status (ZC_STATUS).
  2893. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  2894. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  2895. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  2896. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  2897. void clif_initialstatus(struct map_session_data *sd) {
  2898. int fd, mdef2;
  2899. unsigned char *buf;
  2900. nullpo_retv(sd);
  2901. fd=sd->fd;
  2902. WFIFOHEAD(fd,packet_len(0xbd));
  2903. buf=WFIFOP(fd,0);
  2904. WBUFW(buf,0)=0xbd;
  2905. WBUFW(buf,2)=min(sd->status.status_point, INT16_MAX);
  2906. WBUFB(buf,4)=min(sd->status.str, UINT8_MAX);
  2907. WBUFB(buf,5)=pc->need_status_point(sd,SP_STR,1);
  2908. WBUFB(buf,6)=min(sd->status.agi, UINT8_MAX);
  2909. WBUFB(buf,7)=pc->need_status_point(sd,SP_AGI,1);
  2910. WBUFB(buf,8)=min(sd->status.vit, UINT8_MAX);
  2911. WBUFB(buf,9)=pc->need_status_point(sd,SP_VIT,1);
  2912. WBUFB(buf,10)=min(sd->status.int_, UINT8_MAX);
  2913. WBUFB(buf,11)=pc->need_status_point(sd,SP_INT,1);
  2914. WBUFB(buf,12)=min(sd->status.dex, UINT8_MAX);
  2915. WBUFB(buf,13)=pc->need_status_point(sd,SP_DEX,1);
  2916. WBUFB(buf,14)=min(sd->status.luk, UINT8_MAX);
  2917. WBUFB(buf,15)=pc->need_status_point(sd,SP_LUK,1);
  2918. WBUFW(buf,16) = pc_leftside_atk(sd);
  2919. WBUFW(buf,18) = pc_rightside_atk(sd);
  2920. WBUFW(buf,20) = pc_rightside_matk(sd);
  2921. WBUFW(buf,22) = pc_leftside_matk(sd);
  2922. WBUFW(buf,24) = pc_leftside_def(sd);
  2923. WBUFW(buf,26) = pc_rightside_def(sd);
  2924. WBUFW(buf,28) = pc_leftside_mdef(sd);
  2925. mdef2 = pc_rightside_mdef(sd);
  2926. WBUFW(buf,30) =
  2927. #ifndef RENEWAL
  2928. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  2929. #endif
  2930. mdef2;
  2931. WBUFW(buf,32) = sd->battle_status.hit;
  2932. WBUFW(buf,34) = sd->battle_status.flee;
  2933. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2934. WBUFW(buf,38) = sd->battle_status.cri/10;
  2935. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  2936. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  2937. WFIFOSET(fd,packet_len(0xbd));
  2938. clif->updatestatus(sd,SP_STR);
  2939. clif->updatestatus(sd,SP_AGI);
  2940. clif->updatestatus(sd,SP_VIT);
  2941. clif->updatestatus(sd,SP_INT);
  2942. clif->updatestatus(sd,SP_DEX);
  2943. clif->updatestatus(sd,SP_LUK);
  2944. clif->updatestatus(sd,SP_ATTACKRANGE);
  2945. clif->updatestatus(sd,SP_ASPD);
  2946. }
  2947. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  2948. /// 013c <index>.W
  2949. void clif_arrowequip(struct map_session_data *sd,int val)
  2950. {
  2951. int fd;
  2952. nullpo_retv(sd);
  2953. #if PACKETVER >= 20121128
  2954. clif->status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  2955. #endif
  2956. fd=sd->fd;
  2957. WFIFOHEAD(fd, packet_len(0x013c));
  2958. WFIFOW(fd,0)=0x013c;
  2959. WFIFOW(fd,2)=val+2; //Item ID of the arrow
  2960. WFIFOSET(fd,packet_len(0x013c));
  2961. }
  2962. /// Ammunition action message (ZC_ACTION_FAILURE).
  2963. /// 013b <type>.W
  2964. /// type:
  2965. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  2966. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2967. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2968. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2969. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2970. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2971. void clif_arrow_fail(struct map_session_data *sd,int type)
  2972. {
  2973. int fd;
  2974. nullpo_retv(sd);
  2975. fd=sd->fd;
  2976. WFIFOHEAD(fd, packet_len(0x013b));
  2977. WFIFOW(fd,0)=0x013b;
  2978. WFIFOW(fd,2)=type;
  2979. WFIFOSET(fd,packet_len(0x013b));
  2980. }
  2981. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  2982. /// 01ad <packet len>.W { <name id>.W }*
  2983. void clif_arrow_create_list(struct map_session_data *sd)
  2984. {
  2985. int i, c;
  2986. int fd;
  2987. nullpo_retv(sd);
  2988. fd = sd->fd;
  2989. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2990. WFIFOW(fd,0) = 0x1ad;
  2991. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2992. int j;
  2993. if (skill->dbs->arrow_db[i].nameid > 0
  2994. && (j = pc->search_inventory(sd, skill->dbs->arrow_db[i].nameid)) != INDEX_NOT_FOUND
  2995. && !sd->status.inventory[j].equip && sd->status.inventory[j].identify
  2996. ) {
  2997. if ((j = itemdb_viewid(skill->dbs->arrow_db[i].nameid)) > 0)
  2998. WFIFOW(fd,c*2+4) = j;
  2999. else
  3000. WFIFOW(fd,c*2+4) = skill->dbs->arrow_db[i].nameid;
  3001. c++;
  3002. }
  3003. }
  3004. WFIFOW(fd,2) = c*2+4;
  3005. WFIFOSET(fd, WFIFOW(fd,2));
  3006. if (c > 0) {
  3007. sd->menuskill_id = AC_MAKINGARROW;
  3008. sd->menuskill_val = c;
  3009. }
  3010. }
  3011. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3012. /// 00bc <status id>.W <result>.B <value>.B
  3013. /// status id:
  3014. /// SP_STR ~ SP_LUK
  3015. /// result:
  3016. /// 0 = failure
  3017. /// 1 = success
  3018. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  3019. {
  3020. int fd;
  3021. nullpo_retv(sd);
  3022. fd=sd->fd;
  3023. WFIFOHEAD(fd,packet_len(0xbc));
  3024. WFIFOW(fd,0)=0xbc;
  3025. WFIFOW(fd,2)=type;
  3026. WFIFOB(fd,4)=ok;
  3027. WFIFOB(fd,5)=cap_value(val,0,UINT8_MAX);
  3028. WFIFOSET(fd,packet_len(0xbc));
  3029. }
  3030. /// Notifies the client about the result of a request to equip an item (ZC_REQ_WEAR_EQUIP_ACK).
  3031. /// 00aa <index>.W <equip location>.W <result>.B
  3032. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3033. void clif_equipitemack(struct map_session_data *sd,int n,int pos,enum e_EQUIP_ITEM_ACK result) {
  3034. struct packet_equipitem_ack p;
  3035. nullpo_retv(sd);
  3036. p.PacketType = equipitemackType;
  3037. p.index = n+2;
  3038. p.wearLocation = pos;
  3039. #if PACKETVER >= 20100629
  3040. if (result == EIA_SUCCESS && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3041. p.wItemSpriteNumber = sd->inventory_data[n]->look;
  3042. else
  3043. p.wItemSpriteNumber = 0;
  3044. #endif
  3045. p.result = (unsigned char)result;
  3046. clif->send(&p, sizeof(p), &sd->bl, SELF);
  3047. }
  3048. /// Notifies the client about the result of a request to take off an item (ZC_REQ_TAKEOFF_EQUIP_ACK).
  3049. /// 00ac <index>.W <equip location>.W <result>.B
  3050. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,enum e_UNEQUIP_ITEM_ACK result) {
  3051. struct packet_unequipitem_ack p;
  3052. nullpo_retv(sd);
  3053. p.PacketType = unequipitemackType;
  3054. p.index = n+2;
  3055. p.wearLocation = pos;
  3056. p.result = (unsigned char)result;
  3057. clif->send(&p, sizeof(p), &sd->bl, SELF);
  3058. }
  3059. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3060. /// 019b <id>.L <effect id>.L
  3061. /// effect id:
  3062. /// 0 = base level up
  3063. /// 1 = job level up
  3064. /// 2 = refine failure
  3065. /// 3 = refine success
  3066. /// 4 = game over
  3067. /// 5 = pharmacy success
  3068. /// 6 = pharmacy failure
  3069. /// 7 = base level up (super novice)
  3070. /// 8 = job level up (super novice)
  3071. /// 9 = base level up (taekwon)
  3072. void clif_misceffect(struct block_list* bl,int type)
  3073. {
  3074. unsigned char buf[32];
  3075. nullpo_retv(bl);
  3076. WBUFW(buf,0) = 0x19b;
  3077. WBUFL(buf,2) = bl->id;
  3078. WBUFL(buf,6) = type;
  3079. clif->send(buf,packet_len(0x19b),bl,AREA);
  3080. }
  3081. /// Notifies clients in the area of a state change.
  3082. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3083. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3084. void clif_changeoption(struct block_list* bl)
  3085. {
  3086. unsigned char buf[32];
  3087. struct status_change *sc;
  3088. struct map_session_data* sd;
  3089. nullpo_retv(bl);
  3090. if ( !(sc = status->get_sc(bl)) && bl->type != BL_NPC ) return; //How can an option change if there's no sc?
  3091. sd = BL_CAST(BL_PC, bl);
  3092. #if PACKETVER >= 7
  3093. WBUFW(buf,0) = 0x229;
  3094. WBUFL(buf,2) = bl->id;
  3095. WBUFW(buf,6) = (sc) ? sc->opt1 : 0;
  3096. WBUFW(buf,8) = (sc) ? sc->opt2 : 0;
  3097. WBUFL(buf,10) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0);
  3098. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3099. if(disguised(bl)) {
  3100. clif->send(buf,packet_len(0x229),bl,AREA_WOS);
  3101. WBUFL(buf,2) = -bl->id;
  3102. clif->send(buf,packet_len(0x229),bl,SELF);
  3103. WBUFL(buf,2) = bl->id;
  3104. WBUFL(buf,10) = OPTION_INVISIBLE;
  3105. clif->send(buf,packet_len(0x229),bl,SELF);
  3106. } else
  3107. clif->send(buf,packet_len(0x229),bl,AREA);
  3108. #else
  3109. WBUFW(buf,0) = 0x119;
  3110. WBUFL(buf,2) = bl->id;
  3111. WBUFW(buf,6) = (sc) ? sc->opt1 : 0;
  3112. WBUFW(buf,8) = (sc) ? sc->opt2 : 0;
  3113. WBUFL(buf,10) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0);
  3114. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3115. if(disguised(bl)) {
  3116. clif->send(buf,packet_len(0x119),bl,AREA_WOS);
  3117. WBUFL(buf,2) = -bl->id;
  3118. clif->send(buf,packet_len(0x119),bl,SELF);
  3119. WBUFL(buf,2) = bl->id;
  3120. WBUFW(buf,10) = OPTION_INVISIBLE;
  3121. clif->send(buf,packet_len(0x119),bl,SELF);
  3122. } else
  3123. clif->send(buf,packet_len(0x119),bl,AREA);
  3124. #endif
  3125. }
  3126. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3127. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3128. void clif_changeoption2(struct block_list* bl) {
  3129. unsigned char buf[20];
  3130. struct status_change *sc;
  3131. nullpo_retv(bl);
  3132. if ( !(sc = status->get_sc(bl)) && bl->type != BL_NPC ) return; //How can an option change if there's no sc?
  3133. WBUFW(buf,0) = 0x28a;
  3134. WBUFL(buf,2) = bl->id;
  3135. WBUFL(buf,6) = (sc != NULL) ? sc->option : ((bl->type == BL_NPC) ? BL_UCCAST(BL_NPC, bl)->option : 0);
  3136. WBUFL(buf,10) = clif_setlevel(bl);
  3137. WBUFL(buf,14) = (sc) ? sc->opt3 : 0;
  3138. if(disguised(bl)) {
  3139. clif->send(buf,packet_len(0x28a),bl,AREA_WOS);
  3140. WBUFL(buf,2) = -bl->id;
  3141. clif->send(buf,packet_len(0x28a),bl,SELF);
  3142. WBUFL(buf,2) = bl->id;
  3143. WBUFL(buf,6) = OPTION_INVISIBLE;
  3144. clif->send(buf,packet_len(0x28a),bl,SELF);
  3145. } else
  3146. clif->send(buf,packet_len(0x28a),bl,AREA);
  3147. }
  3148. /// Notifies the client about the result of an item use request.
  3149. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3150. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3151. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3152. {
  3153. nullpo_retv(sd);
  3154. if(!ok) {
  3155. int fd=sd->fd;
  3156. WFIFOHEAD(fd,packet_len(0xa8));
  3157. WFIFOW(fd,0)=0xa8;
  3158. WFIFOW(fd,2)=index+2;
  3159. WFIFOW(fd,4)=amount;
  3160. WFIFOB(fd,6)=ok;
  3161. WFIFOSET(fd,packet_len(0xa8));
  3162. }
  3163. else {
  3164. #if PACKETVER < 3
  3165. int fd=sd->fd;
  3166. WFIFOHEAD(fd,packet_len(0xa8));
  3167. WFIFOW(fd,0)=0xa8;
  3168. WFIFOW(fd,2)=index+2;
  3169. WFIFOW(fd,4)=amount;
  3170. WFIFOB(fd,6)=ok;
  3171. WFIFOSET(fd,packet_len(0xa8));
  3172. #else
  3173. unsigned char buf[32];
  3174. WBUFW(buf,0)=0x1c8;
  3175. WBUFW(buf,2)=index+2;
  3176. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3177. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3178. else
  3179. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3180. WBUFL(buf,6)=sd->bl.id;
  3181. WBUFW(buf,10)=amount;
  3182. WBUFB(buf,12)=ok;
  3183. clif->send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3184. #endif
  3185. }
  3186. }
  3187. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3188. /// 00d6 <flag>.B
  3189. /// flag:
  3190. /// 0 = Room has been successfully created (opens chat room)
  3191. /// 1 = Room limit exceeded
  3192. /// 2 = Same room already exists
  3193. // TODO: Flag enum
  3194. void clif_createchat(struct map_session_data* sd, int flag)
  3195. {
  3196. int fd;
  3197. nullpo_retv(sd);
  3198. fd = sd->fd;
  3199. WFIFOHEAD(fd,packet_len(0xd6));
  3200. WFIFOW(fd,0) = 0xd6;
  3201. WFIFOB(fd,2) = flag;
  3202. WFIFOSET(fd,packet_len(0xd6));
  3203. }
  3204. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3205. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3206. /// type:
  3207. /// 0 = private (password protected)
  3208. /// 1 = public
  3209. /// 2 = arena (npc waiting room)
  3210. /// 3 = PK zone (non-clickable)
  3211. void clif_dispchat(struct chat_data* cd, int fd)
  3212. {
  3213. unsigned char buf[128];
  3214. uint8 type;
  3215. if( cd == NULL || cd->owner == NULL )
  3216. return;
  3217. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3218. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3219. : 1;
  3220. WBUFW(buf, 0) = 0xd7;
  3221. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3222. WBUFL(buf, 4) = cd->owner->id;
  3223. WBUFL(buf, 8) = cd->bl.id;
  3224. WBUFW(buf,12) = cd->limit;
  3225. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3226. WBUFB(buf,16) = type;
  3227. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3228. if( fd ) {
  3229. WFIFOHEAD(fd,WBUFW(buf,2));
  3230. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3231. WFIFOSET(fd,WBUFW(buf,2));
  3232. } else {
  3233. clif->send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3234. }
  3235. }
  3236. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3237. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3238. /// type:
  3239. /// 0 = private (password protected)
  3240. /// 1 = public
  3241. /// 2 = arena (npc waiting room)
  3242. /// 3 = PK zone (non-clickable)
  3243. void clif_changechatstatus(struct chat_data* cd)
  3244. {
  3245. unsigned char buf[128];
  3246. uint8 type;
  3247. if( cd == NULL || cd->usersd[0] == NULL )
  3248. return;
  3249. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3250. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3251. : 1;
  3252. WBUFW(buf, 0) = 0xdf;
  3253. WBUFW(buf, 2) = 17 + strlen(cd->title);
  3254. WBUFL(buf, 4) = cd->owner->id;
  3255. WBUFL(buf, 8) = cd->bl.id;
  3256. WBUFW(buf,12) = cd->limit;
  3257. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3258. WBUFB(buf,16) = type;
  3259. memcpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3260. clif->send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3261. }
  3262. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3263. /// 00d8 <chat id>.L
  3264. void clif_clearchat(struct chat_data *cd,int fd)
  3265. {
  3266. unsigned char buf[32];
  3267. nullpo_retv(cd);
  3268. WBUFW(buf,0) = 0xd8;
  3269. WBUFL(buf,2) = cd->bl.id;
  3270. if( fd ) {
  3271. WFIFOHEAD(fd,packet_len(0xd8));
  3272. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3273. WFIFOSET(fd,packet_len(0xd8));
  3274. } else {
  3275. clif->send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3276. }
  3277. }
  3278. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3279. /// 00da <result>.B
  3280. /// result:
  3281. /// 0 = room full
  3282. /// 1 = wrong password
  3283. /// 2 = kicked
  3284. /// 3 = success (no message)
  3285. /// 4 = no enough zeny
  3286. /// 5 = too low level
  3287. /// 6 = too high level
  3288. /// 7 = unsuitable job class
  3289. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3290. {
  3291. int fd;
  3292. nullpo_retv(sd);
  3293. fd = sd->fd;
  3294. WFIFOHEAD(fd,packet_len(0xda));
  3295. WFIFOW(fd,0) = 0xda;
  3296. WFIFOB(fd,2) = flag;
  3297. WFIFOSET(fd,packet_len(0xda));
  3298. }
  3299. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3300. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3301. /// role:
  3302. /// 0 = owner (menu)
  3303. /// 1 = normal
  3304. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3305. {
  3306. int fd;
  3307. int i,t;
  3308. nullpo_retv(sd);
  3309. nullpo_retv(cd);
  3310. fd = sd->fd;
  3311. if (!sockt->session_is_active(fd))
  3312. return;
  3313. t = (int)(cd->owner->type == BL_NPC);
  3314. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3315. WFIFOW(fd, 0) = 0xdb;
  3316. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3317. WFIFOL(fd, 4) = cd->bl.id;
  3318. if(cd->owner->type == BL_NPC) {
  3319. const struct npc_data *nd = BL_UCCAST(BL_NPC, cd->owner);
  3320. WFIFOL(fd, 30) = 1;
  3321. WFIFOL(fd, 8) = 0;
  3322. memcpy(WFIFOP(fd, 12), nd->name, NAME_LENGTH);
  3323. for (i = 0; i < cd->users; i++) {
  3324. WFIFOL(fd, 8+(i+1)*28) = 1;
  3325. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3326. }
  3327. } else
  3328. for (i = 0; i < cd->users; i++) {
  3329. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3330. memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3331. }
  3332. WFIFOSET(fd, WFIFOW(fd, 2));
  3333. }
  3334. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3335. /// 00dc <users>.W <name>.24B
  3336. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3337. {
  3338. unsigned char buf[32];
  3339. nullpo_retv(sd);
  3340. nullpo_retv(cd);
  3341. WBUFW(buf, 0) = 0xdc;
  3342. WBUFW(buf, 2) = cd->users;
  3343. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3344. clif->send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3345. }
  3346. /// Announce the new owner (ZC_ROLE_CHANGE).
  3347. /// 00e1 <role>.L <nick>.24B
  3348. /// role:
  3349. /// 0 = owner (menu)
  3350. /// 1 = normal
  3351. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3352. {
  3353. unsigned char buf[64];
  3354. nullpo_retv(sd);
  3355. nullpo_retv(cd);
  3356. WBUFW(buf, 0) = 0xe1;
  3357. WBUFL(buf, 2) = 1;
  3358. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3359. WBUFW(buf,30) = 0xe1;
  3360. WBUFL(buf,32) = 0;
  3361. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3362. clif->send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3363. }
  3364. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3365. /// 00dd <users>.W <nick>.24B <flag>.B
  3366. /// flag:
  3367. /// 0 = left
  3368. /// 1 = kicked
  3369. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3370. {
  3371. unsigned char buf[32];
  3372. nullpo_retv(sd);
  3373. nullpo_retv(cd);
  3374. WBUFW(buf, 0) = 0xdd;
  3375. WBUFW(buf, 2) = cd->users-1;
  3376. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3377. WBUFB(buf,28) = flag;
  3378. clif->send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3379. }
  3380. /// Opens a trade request window from char 'name'.
  3381. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3382. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3383. void clif_traderequest(struct map_session_data *sd, const char *name)
  3384. {
  3385. int fd;
  3386. #if PACKETVER >= 6
  3387. struct map_session_data* tsd = NULL;
  3388. #endif // PACKETVER >= 6
  3389. nullpo_retv(sd);
  3390. nullpo_retv(name);
  3391. fd = sd->fd;
  3392. #if PACKETVER < 6
  3393. WFIFOHEAD(fd,packet_len(0xe5));
  3394. WFIFOW(fd,0) = 0xe5;
  3395. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3396. WFIFOSET(fd,packet_len(0xe5));
  3397. #else // PACKETVER >= 6
  3398. tsd = map->id2sd(sd->trade_partner);
  3399. if (!tsd)
  3400. return;
  3401. WFIFOHEAD(fd,packet_len(0x1f4));
  3402. WFIFOW(fd,0) = 0x1f4;
  3403. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  3404. WFIFOL(fd,26) = tsd->status.char_id;
  3405. WFIFOW(fd,30) = tsd->status.base_level;
  3406. WFIFOSET(fd,packet_len(0x1f4));
  3407. #endif // PACKETVER < 6
  3408. }
  3409. /// Reply to a trade-request.
  3410. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3411. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3412. /// result:
  3413. /// 0 = Char is too far
  3414. /// 1 = Character does not exist
  3415. /// 2 = Trade failed
  3416. /// 3 = Accept
  3417. /// 4 = Cancel
  3418. /// 5 = Busy
  3419. void clif_tradestart(struct map_session_data *sd, uint8 type)
  3420. {
  3421. int fd;
  3422. #if PACKETVER >= 6
  3423. struct map_session_data *tsd = NULL;
  3424. #endif // PACKETVER >= 6
  3425. nullpo_retv(sd);
  3426. fd = sd->fd;
  3427. #if PACKETVER >= 6
  3428. tsd = map->id2sd(sd->trade_partner);
  3429. if (tsd) {
  3430. WFIFOHEAD(fd,packet_len(0x1f5));
  3431. WFIFOW(fd,0) = 0x1f5;
  3432. WFIFOB(fd,2) = type;
  3433. WFIFOL(fd,3) = tsd->status.char_id;
  3434. WFIFOW(fd,7) = tsd->status.base_level;
  3435. WFIFOSET(fd,packet_len(0x1f5));
  3436. return;
  3437. }
  3438. #endif // PACKETVER >= 6
  3439. WFIFOHEAD(fd,packet_len(0xe7));
  3440. WFIFOW(fd,0) = 0xe7;
  3441. WFIFOB(fd,2) = type;
  3442. WFIFOSET(fd,packet_len(0xe7));
  3443. }
  3444. /// Notifies the client about an item from other player in current trade.
  3445. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3446. /// 080f <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM2)
  3447. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3448. {
  3449. int fd;
  3450. unsigned char *buf;
  3451. nullpo_retv(sd);
  3452. nullpo_retv(tsd);
  3453. fd = tsd->fd;
  3454. buf = WFIFOP(fd,0);
  3455. WFIFOHEAD(fd,packet_len(tradeaddType));
  3456. WBUFW(buf,0) = tradeaddType;
  3457. if( index == 0 )
  3458. {
  3459. #if PACKETVER < 20100223
  3460. WBUFL(buf,2) = amount; //amount
  3461. WBUFW(buf,6) = 0; // type id
  3462. #else
  3463. WBUFW(buf,2) = 0; // type id
  3464. WBUFB(buf,4) = 0; // item type
  3465. WBUFL(buf,5) = amount; // amount
  3466. buf = WBUFP(buf,1); //Advance 1B
  3467. #endif
  3468. WBUFB(buf,8) = 0; //identify flag
  3469. WBUFB(buf,9) = 0; // attribute
  3470. WBUFB(buf,10)= 0; //refine
  3471. WBUFW(buf,11)= 0; //card (4w)
  3472. WBUFW(buf,13)= 0; //card (4w)
  3473. WBUFW(buf,15)= 0; //card (4w)
  3474. WBUFW(buf,17)= 0; //card (4w)
  3475. #if PACKETVER >= 20150226
  3476. clif->add_random_options(WBUFP(buf, 19), &sd->status.inventory[index]);
  3477. #endif
  3478. }
  3479. else
  3480. {
  3481. index -= 2; //index fix
  3482. #if PACKETVER < 20100223
  3483. WBUFL(buf,2) = amount; //amount
  3484. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3485. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3486. else
  3487. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3488. #else
  3489. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3490. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3491. else
  3492. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3493. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3494. WBUFL(buf,5) = amount; // amount
  3495. buf = WBUFP(buf,1); //Advance 1B
  3496. #endif
  3497. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3498. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3499. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3500. clif->addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3501. #if PACKETVER >= 20150226
  3502. clif->add_random_options(WBUFP(buf, 19), &sd->status.inventory[index]);
  3503. #endif
  3504. }
  3505. WFIFOSET(fd,packet_len(tradeaddType));
  3506. }
  3507. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3508. /// 00ea <index>.W <result>.B
  3509. /// result:
  3510. /// 0 = success
  3511. /// 1 = overweight
  3512. /// 2 = trade canceled
  3513. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3514. {
  3515. int fd;
  3516. nullpo_retv(sd);
  3517. fd = sd->fd;
  3518. WFIFOHEAD(fd,packet_len(0xea));
  3519. WFIFOW(fd,0) = 0xea;
  3520. WFIFOW(fd,2) = index;
  3521. WFIFOB(fd,4) = fail;
  3522. WFIFOSET(fd,packet_len(0xea));
  3523. }
  3524. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3525. /// 00ec <who>.B
  3526. /// who:
  3527. /// 0 = self
  3528. /// 1 = other player
  3529. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3530. {
  3531. int fd;
  3532. nullpo_retv(sd);
  3533. fd = sd->fd;
  3534. WFIFOHEAD(fd,packet_len(0xec));
  3535. WFIFOW(fd,0) = 0xec;
  3536. WFIFOB(fd,2) = fail;
  3537. WFIFOSET(fd,packet_len(0xec));
  3538. }
  3539. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3540. /// 00ee
  3541. void clif_tradecancelled(struct map_session_data* sd)
  3542. {
  3543. int fd;
  3544. nullpo_retv(sd);
  3545. fd = sd->fd;
  3546. WFIFOHEAD(fd,packet_len(0xee));
  3547. WFIFOW(fd,0) = 0xee;
  3548. WFIFOSET(fd,packet_len(0xee));
  3549. }
  3550. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3551. /// 00f0 <result>.B
  3552. /// result:
  3553. /// 0 = success
  3554. /// 1 = failure
  3555. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3556. {
  3557. int fd;
  3558. nullpo_retv(sd);
  3559. fd = sd->fd;
  3560. WFIFOHEAD(fd,packet_len(0xf0));
  3561. WFIFOW(fd,0) = 0xf0;
  3562. WFIFOB(fd,2) = fail;
  3563. WFIFOSET(fd,packet_len(0xf0));
  3564. }
  3565. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3566. /// 00f1
  3567. /// NOTE: Unknown purpose. Items are not removed until the window is
  3568. /// refreshed (ex. by putting another item in there).
  3569. /// unused
  3570. void clif_tradeundo(struct map_session_data* sd)
  3571. {
  3572. int fd;
  3573. nullpo_retv(sd);
  3574. fd = sd->fd;
  3575. WFIFOHEAD(fd,packet_len(0xf1));
  3576. WFIFOW(fd,0) = 0xf1;
  3577. WFIFOSET(fd,packet_len(0xf1));
  3578. }
  3579. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3580. /// 00f2 <current count>.W <max count>.W
  3581. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3582. {
  3583. int fd;
  3584. nullpo_retv(sd);
  3585. fd=sd->fd;
  3586. WFIFOHEAD(fd,packet_len(0xf2));
  3587. WFIFOW(fd,0) = 0xf2;
  3588. WFIFOW(fd,2) = amount;
  3589. WFIFOW(fd,4) = max_amount;
  3590. WFIFOSET(fd,packet_len(0xf2));
  3591. }
  3592. /// Notifies the client of an item being added to the storage.
  3593. /// 00f4 <index>.W <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE)
  3594. /// 01c4 <index>.W <amount>.L <nameid>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE2)
  3595. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3596. {
  3597. int view,fd;
  3598. int offset = 0;
  3599. nullpo_retv(sd);
  3600. nullpo_retv(i);
  3601. fd=sd->fd;
  3602. view = itemdb_viewid(i->nameid);
  3603. WFIFOHEAD(fd,packet_len(storageaddType));
  3604. WFIFOW(fd, 0) = storageaddType; // Storage item added
  3605. WFIFOW(fd, 2) = index+1; // index
  3606. WFIFOL(fd, 4) = amount; // amount
  3607. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3608. #if PACKETVER >= 5
  3609. WFIFOB(fd,10) = itemtype(itemdb_type(i->nameid)); //type
  3610. offset += 1;
  3611. #endif
  3612. WFIFOB(fd,10+offset) = i->identify; //identify flag
  3613. WFIFOB(fd,11+offset) = i->attribute; // attribute
  3614. WFIFOB(fd,12+offset) = i->refine; //refine
  3615. clif->addcards(WFIFOP(fd,13+offset), i);
  3616. #if PACKETVER >= 20150226
  3617. clif->add_random_options(WFIFOP(fd,21+offset), i);
  3618. #endif
  3619. WFIFOSET(fd,packet_len(storageaddType));
  3620. }
  3621. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3622. /// 00f6 <index>.W <amount>.L
  3623. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3624. {
  3625. int fd;
  3626. nullpo_retv(sd);
  3627. fd=sd->fd;
  3628. WFIFOHEAD(fd,packet_len(0xf6));
  3629. WFIFOW(fd,0)=0xf6; // Storage item removed
  3630. WFIFOW(fd,2)=index+1;
  3631. WFIFOL(fd,4)=amount;
  3632. WFIFOSET(fd,packet_len(0xf6));
  3633. }
  3634. /// Closes storage (ZC_CLOSE_STORE).
  3635. /// 00f8
  3636. void clif_storageclose(struct map_session_data* sd)
  3637. {
  3638. int fd;
  3639. nullpo_retv(sd);
  3640. fd=sd->fd;
  3641. WFIFOHEAD(fd,packet_len(0xf8));
  3642. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3643. WFIFOSET(fd,packet_len(0xf8));
  3644. }
  3645. /*==========================================
  3646. * Server tells 'sd' player client the abouts of 'dstsd' player
  3647. *------------------------------------------*/
  3648. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd) {
  3649. struct block_list *d_bl;
  3650. int i;
  3651. nullpo_retv(sd);
  3652. nullpo_retv(dstsd);
  3653. if( dstsd->chatID ) {
  3654. struct chat_data *cd = map->id2cd(dstsd->chatID);
  3655. if (cd != NULL && cd->usersd[0] == dstsd)
  3656. clif->dispchat(cd,sd->fd);
  3657. } else if( dstsd->state.vending )
  3658. clif->showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3659. else if( dstsd->state.buyingstore )
  3660. clif->buyingstore_entry_single(sd, dstsd);
  3661. if(dstsd->spiritball > 0)
  3662. clif->spiritball_single(sd->fd, dstsd);
  3663. if (dstsd->charm_type != CHARM_TYPE_NONE && dstsd->charm_count > 0)
  3664. clif->charm_single(sd->fd, dstsd);
  3665. for( i = 0; i < dstsd->sc_display_count; i++ ) {
  3666. clif->sc_load(&sd->bl,dstsd->bl.id,SELF,status->dbs->IconChangeTable[dstsd->sc_display[i]->type],dstsd->sc_display[i]->val1,dstsd->sc_display[i]->val2,dstsd->sc_display[i]->val3);
  3667. }
  3668. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3669. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  3670. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  3671. )
  3672. clif->hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3673. // display link (sd - dstsd) to sd
  3674. ARR_FIND( 0, MAX_PC_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  3675. if( i < MAX_PC_DEVOTION ) clif->devotion(&sd->bl, sd);
  3676. // display links (dstsd - devotees) to sd
  3677. ARR_FIND( 0, MAX_PC_DEVOTION, i, dstsd->devotion[i] > 0 );
  3678. if( i < MAX_PC_DEVOTION ) clif->devotion(&dstsd->bl, sd);
  3679. // display link (dstsd - crusader) to sd
  3680. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map->id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3681. clif->devotion(d_bl, sd);
  3682. }
  3683. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl) {
  3684. struct unit_data *ud;
  3685. struct view_data *vd;
  3686. nullpo_retv(sd);
  3687. nullpo_retv(bl);
  3688. vd = status->get_viewdata(bl);
  3689. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3690. return;
  3691. if (bl->type == BL_NPC) {
  3692. // Hide NPC from maya purple card.
  3693. struct npc_data *nd = BL_UCAST(BL_NPC, bl);
  3694. if (nd->chat_id == 0 && (nd->option&OPTION_INVISIBLE))
  3695. return;
  3696. }
  3697. if ( ( ud = unit->bl2ud(bl) ) && ud->walktimer != INVALID_TIMER )
  3698. clif->set_unit_walking(bl,sd,ud,SELF);
  3699. else
  3700. clif->set_unit_idle(bl,sd,SELF);
  3701. if (vd->cloth_color)
  3702. clif->refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3703. if (vd->body_style)
  3704. clif->refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  3705. switch (bl->type) {
  3706. case BL_PC:
  3707. {
  3708. struct map_session_data *tsd = BL_UCAST(BL_PC, bl);
  3709. clif->getareachar_pc(sd, tsd);
  3710. if (tsd->state.size == SZ_BIG) // tiny/big players [Valaris]
  3711. clif->specialeffect_single(bl,423,sd->fd);
  3712. else if (tsd->state.size == SZ_MEDIUM)
  3713. clif->specialeffect_single(bl,421,sd->fd);
  3714. if (tsd->bg_id != 0 && map->list[tsd->bl.m].flag.battleground)
  3715. clif->sendbgemblem_single(sd->fd,tsd);
  3716. if (tsd->status.robe)
  3717. clif->refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  3718. }
  3719. break;
  3720. case BL_MER: // Devotion Effects
  3721. {
  3722. struct mercenary_data *md = BL_UCAST(BL_MER, bl);
  3723. if (md->devotion_flag)
  3724. clif->devotion(bl, sd);
  3725. }
  3726. break;
  3727. case BL_NPC:
  3728. {
  3729. struct npc_data *nd = BL_UCAST(BL_NPC, bl);
  3730. if (nd->chat_id != 0)
  3731. clif->dispchat(map->id2cd(nd->chat_id), sd->fd);
  3732. if (nd->size == SZ_BIG)
  3733. clif->specialeffect_single(bl,423,sd->fd);
  3734. else if (nd->size == SZ_MEDIUM)
  3735. clif->specialeffect_single(bl,421,sd->fd);
  3736. }
  3737. break;
  3738. case BL_MOB:
  3739. {
  3740. struct mob_data *md = BL_UCAST(BL_MOB, bl);
  3741. if (md->special_state.size == SZ_BIG) // tiny/big mobs [Valaris]
  3742. clif->specialeffect_single(bl,423,sd->fd);
  3743. else if (md->special_state.size == SZ_MEDIUM)
  3744. clif->specialeffect_single(bl,421,sd->fd);
  3745. #if (PACKETVER >= 20120404 && PACKETVER < 20131223)
  3746. if (battle_config.show_monster_hp_bar && !(md->status.mode&MD_BOSS)) {
  3747. int i;
  3748. for (i = 0; i < DAMAGELOG_SIZE; i++) {// must show hp bar to all char who already hit the mob.
  3749. if (md->dmglog[i].id == sd->status.char_id) {
  3750. clif->monster_hp_bar(md, sd);
  3751. break;
  3752. }
  3753. }
  3754. }
  3755. #endif
  3756. }
  3757. break;
  3758. case BL_PET:
  3759. if (vd->head_bottom)
  3760. clif->send_petdata(NULL, BL_UCAST(BL_PET, bl), 3, vd->head_bottom); // needed to display pet equip properly
  3761. break;
  3762. }
  3763. }
  3764. //Modifies the type of damage according to status changes [Skotlex]
  3765. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3766. static inline int clif_calc_delay(int type, int div, int damage, int delay)
  3767. {
  3768. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? 9 : 4 ) : type;
  3769. }
  3770. /*==========================================
  3771. * Estimates walk delay based on the damage criteria. [Skotlex]
  3772. *------------------------------------------*/
  3773. int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_) {
  3774. if (type == 4 || type == 9 || damage <=0)
  3775. return 0;
  3776. nullpo_retr(delay, bl);
  3777. if (bl->type == BL_PC) {
  3778. if (battle_config.pc_walk_delay_rate != 100)
  3779. delay = delay*battle_config.pc_walk_delay_rate/100;
  3780. } else
  3781. if (battle_config.walk_delay_rate != 100)
  3782. delay = delay*battle_config.walk_delay_rate/100;
  3783. if (div_ > 1) //Multi-hit skills mean higher delays.
  3784. delay += battle_config.multihit_delay*(div_-1);
  3785. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3786. }
  3787. /// Sends a 'damage' packet (src performs action on dst)
  3788. /// 008a <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.W <div>.W <type>.B <damage2>.W (ZC_NOTIFY_ACT)
  3789. /// 02e1 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT2)
  3790. /// 08c8 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <IsSPDamage>.B <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT2)
  3791. /// type: @see enum battle_dmg_type
  3792. /// for BDT_NORMAL: [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  3793. int clif_damage(struct block_list* src, struct block_list* dst, int sdelay, int ddelay, int64 in_damage, short div, unsigned char type, int64 in_damage2) {
  3794. struct packet_damage p;
  3795. struct status_change *sc;
  3796. #if PACKETVER < 20071113
  3797. short damage,damage2;
  3798. #else
  3799. int damage,damage2;
  3800. #endif
  3801. nullpo_ret(src);
  3802. nullpo_ret(dst);
  3803. sc = status->get_sc(dst);
  3804. if(sc && sc->count && sc->data[SC_ILLUSION]) {
  3805. if(in_damage) in_damage = in_damage*(sc->data[SC_ILLUSION]->val2) + rnd()%100;
  3806. if(in_damage2) in_damage2 = in_damage2*(sc->data[SC_ILLUSION]->val2) + rnd()%100;
  3807. }
  3808. #if PACKETVER < 20071113
  3809. damage = (short)min(in_damage,INT16_MAX);
  3810. damage2 = (short)min(in_damage2,INT16_MAX);
  3811. #else
  3812. damage = (int)min(in_damage,INT_MAX);
  3813. damage2 = (int)min(in_damage2,INT_MAX);
  3814. #endif
  3815. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3816. p.PacketType = damageType;
  3817. p.GID = src->id;
  3818. p.targetGID = dst->id;
  3819. p.startTime = (uint32)timer->gettick();
  3820. p.attackMT = sdelay;
  3821. p.attackedMT = ddelay;
  3822. p.count = div;
  3823. p.action = type;
  3824. if( battle_config.hide_woe_damage && map_flag_gvg2(src->m) ) {
  3825. p.damage = damage?div:0;
  3826. p.leftDamage = damage2?div:0;
  3827. } else {
  3828. p.damage = damage;
  3829. p.leftDamage = damage2;
  3830. }
  3831. #if PACKETVER >= 20131223
  3832. p.is_sp_damaged = 0; // TODO: IsSPDamage - Displays blue digits.
  3833. #endif
  3834. if(disguised(dst)) {
  3835. clif->send(&p,sizeof(p),dst,AREA_WOS);
  3836. p.targetGID = -dst->id;
  3837. clif->send(&p,sizeof(p),dst,SELF);
  3838. } else
  3839. clif->send(&p,sizeof(p),dst,AREA);
  3840. if(disguised(src)) {
  3841. p.GID = -src->id;
  3842. if (disguised(dst))
  3843. p.targetGID = dst->id;
  3844. if(damage > 0) p.damage = -1;
  3845. if(damage2 > 0) p.leftDamage = -1;
  3846. clif->send(&p,sizeof(p),src,SELF);
  3847. }
  3848. if(src == dst) {
  3849. unit->setdir(src,unit->getdir(src));
  3850. }
  3851. //Return adjusted can't walk delay for further processing.
  3852. return clif->calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3853. }
  3854. /*==========================================
  3855. * src picks up dst
  3856. *------------------------------------------*/
  3857. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3858. {
  3859. //clif->damage(src,dst,0,0,0,0,BDT_PICKUP,0);
  3860. unsigned char buf[32];
  3861. nullpo_retv(src);
  3862. nullpo_retv(dst);
  3863. WBUFW(buf, 0) = 0x8a;
  3864. WBUFL(buf, 2) = src->id;
  3865. WBUFL(buf, 6) = dst->id;
  3866. WBUFB(buf,26) = 1;
  3867. clif->send(buf, packet_len(0x8a), src, AREA);
  3868. }
  3869. /*==========================================
  3870. * inform clients in area that `bl` is sitting
  3871. *------------------------------------------*/
  3872. void clif_sitting(struct block_list* bl)
  3873. {
  3874. unsigned char buf[32];
  3875. nullpo_retv(bl);
  3876. WBUFW(buf, 0) = 0x8a;
  3877. WBUFL(buf, 2) = bl->id;
  3878. WBUFB(buf,26) = 2;
  3879. clif->send(buf, packet_len(0x8a), bl, AREA);
  3880. if(disguised(bl)) {
  3881. WBUFL(buf, 2) = - bl->id;
  3882. clif->send(buf, packet_len(0x8a), bl, SELF);
  3883. }
  3884. }
  3885. /*==========================================
  3886. * inform clients in area that `bl` is standing
  3887. *------------------------------------------*/
  3888. void clif_standing(struct block_list* bl)
  3889. {
  3890. unsigned char buf[32];
  3891. nullpo_retv(bl);
  3892. WBUFW(buf, 0) = 0x8a;
  3893. WBUFL(buf, 2) = bl->id;
  3894. WBUFB(buf,26) = 3;
  3895. clif->send(buf, packet_len(0x8a), bl, AREA);
  3896. if(disguised(bl)) {
  3897. WBUFL(buf, 2) = - bl->id;
  3898. clif->send(buf, packet_len(0x8a), bl, SELF);
  3899. }
  3900. }
  3901. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  3902. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  3903. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target) {
  3904. unsigned char buf[32];
  3905. WBUFW(buf,0) = 0x192;
  3906. WBUFW(buf,2) = x;
  3907. WBUFW(buf,4) = y;
  3908. WBUFW(buf,6) = type;
  3909. mapindex->getmapname_ext(map->list[m].custom_name ? map->list[map->list[m].instance_src_map].name : map->list[m].name,(char*)WBUFP(buf,8));
  3910. if( fd ) {
  3911. WFIFOHEAD(fd,packet_len(0x192));
  3912. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3913. WFIFOSET(fd,packet_len(0x192));
  3914. } else {
  3915. struct block_list dummy_bl;
  3916. dummy_bl.type = BL_NUL;
  3917. dummy_bl.x = x;
  3918. dummy_bl.y = y;
  3919. dummy_bl.m = m;
  3920. clif->send(buf,packet_len(0x192),&dummy_bl,target);
  3921. }
  3922. }
  3923. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  3924. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  3925. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem) {
  3926. int view,fd;
  3927. nullpo_retv(sd);
  3928. nullpo_retv(fitem);
  3929. fd=sd->fd;
  3930. WFIFOHEAD(fd,packet_len(0x9d));
  3931. WFIFOW(fd,0)=0x9d;
  3932. WFIFOL(fd,2)=fitem->bl.id;
  3933. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3934. WFIFOW(fd,6)=view;
  3935. else
  3936. WFIFOW(fd,6)=fitem->item_data.nameid;
  3937. WFIFOB(fd,8)=fitem->item_data.identify;
  3938. WFIFOW(fd,9)=fitem->bl.x;
  3939. WFIFOW(fd,11)=fitem->bl.y;
  3940. WFIFOW(fd,13)=fitem->item_data.amount;
  3941. WFIFOB(fd,15)=fitem->subx;
  3942. WFIFOB(fd,16)=fitem->suby;
  3943. WFIFOSET(fd,packet_len(0x9d));
  3944. }
  3945. void clif_graffiti_entry(struct block_list *bl, struct skill_unit *su, enum send_target target) {
  3946. struct packet_graffiti_entry p;
  3947. nullpo_retv(bl);
  3948. nullpo_retv(su);
  3949. nullpo_retv(su->group);
  3950. p.PacketType = graffiti_entryType;
  3951. p.AID = su->bl.id;
  3952. p.creatorAID = su->group->src_id;
  3953. p.xPos = su->bl.x;
  3954. p.yPos = su->bl.y;
  3955. p.job = su->group->unit_id;
  3956. p.isContens = 1;
  3957. p.isVisible = 1;
  3958. safestrncpy(p.msg, su->group->valstr, 80);
  3959. clif->send(&p,sizeof(p),bl,target);
  3960. }
  3961. /// Notifies the client of a skill unit.
  3962. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  3963. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  3964. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  3965. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  3966. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *su, enum send_target target) {
  3967. struct packet_skill_entry p;
  3968. nullpo_retv(bl);
  3969. nullpo_retv(su);
  3970. nullpo_retv(su->group);
  3971. if( su->group->state.guildaura )
  3972. return;
  3973. #if PACKETVER >= 3
  3974. if(su->group->unit_id == UNT_GRAFFITI) {
  3975. clif->graffiti_entry(bl,su,target);
  3976. return;
  3977. }
  3978. #endif
  3979. p.PacketType = skill_entryType;
  3980. #if PACKETVER >= 20110718
  3981. p.PacketLength = sizeof(p);
  3982. #endif
  3983. p.AID = su->bl.id;
  3984. p.creatorAID = su->group->src_id;
  3985. p.xPos = su->bl.x;
  3986. p.yPos = su->bl.y;
  3987. //Use invisible unit id for traps.
  3988. if ((battle_config.traps_setting&1 && skill->get_inf2(su->group->skill_id)&INF2_TRAP) ||
  3989. (skill->get_unit_flag(su->group->skill_id) & UF_RANGEDSINGLEUNIT && !(su->val2 & UF_RANGEDSINGLEUNIT)))
  3990. p.job = UNT_DUMMYSKILL;
  3991. else
  3992. p.job = su->group->unit_id;
  3993. #if PACKETVER >= 20110718
  3994. p.RadiusRange = (unsigned char)su->range;
  3995. #endif
  3996. p.isVisible = 1;
  3997. #if PACKETVER >= 20130731
  3998. p.level = (unsigned char)su->group->skill_lv;
  3999. #endif
  4000. clif->send(&p,sizeof(p),bl,target);
  4001. if (su->group->skill_id == WZ_ICEWALL) {
  4002. struct map_session_data *sd = BL_CAST(BL_PC, bl);
  4003. clif->changemapcell(sd != NULL ? sd->fd : 0, su->bl.m, su->bl.x, su->bl.y, 5, SELF);
  4004. }
  4005. }
  4006. /*==========================================
  4007. * Server tells client to remove unit of id 'unit->bl.id'
  4008. *------------------------------------------*/
  4009. void clif_clearchar_skillunit(struct skill_unit *su, int fd) {
  4010. nullpo_retv(su);
  4011. WFIFOHEAD(fd,packet_len(0x120));
  4012. WFIFOW(fd, 0)=0x120;
  4013. WFIFOL(fd, 2)=su->bl.id;
  4014. WFIFOSET(fd,packet_len(0x120));
  4015. if(su->group && su->group->skill_id == WZ_ICEWALL)
  4016. clif->changemapcell(fd,su->bl.m,su->bl.x,su->bl.y,su->val2,SELF);
  4017. }
  4018. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4019. /// 0120 <id>.L
  4020. void clif_skill_delunit(struct skill_unit *su) {
  4021. unsigned char buf[16];
  4022. nullpo_retv(su);
  4023. WBUFW(buf, 0)=0x120;
  4024. WBUFL(buf, 2)=su->bl.id;
  4025. clif->send(buf,packet_len(0x120),&su->bl,AREA);
  4026. }
  4027. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4028. /// 01ac <id>.L
  4029. /// Only affects units with class [139,153] client-side.
  4030. void clif_skillunit_update(struct block_list* bl)
  4031. {
  4032. unsigned char buf[6];
  4033. nullpo_retv(bl);
  4034. WBUFW(buf,0) = 0x1ac;
  4035. WBUFL(buf,2) = bl->id;
  4036. clif->send(buf,packet_len(0x1ac),bl,AREA);
  4037. }
  4038. /*==========================================
  4039. *
  4040. *------------------------------------------*/
  4041. int clif_getareachar(struct block_list* bl,va_list ap) {
  4042. struct map_session_data *sd;
  4043. nullpo_ret(bl);
  4044. sd=va_arg(ap,struct map_session_data*);
  4045. if (sd == NULL || !sd->fd)
  4046. return 0;
  4047. switch(bl->type){
  4048. case BL_ITEM:
  4049. clif->getareachar_item(sd, BL_UCAST(BL_ITEM, bl));
  4050. break;
  4051. case BL_SKILL:
  4052. clif->getareachar_skillunit(&sd->bl, BL_UCAST(BL_SKILL, bl), SELF);
  4053. break;
  4054. default:
  4055. if(&sd->bl == bl)
  4056. break;
  4057. clif->getareachar_unit(sd,bl);
  4058. break;
  4059. }
  4060. return 0;
  4061. }
  4062. /*==========================================
  4063. * tbl has gone out of view-size of bl
  4064. *------------------------------------------*/
  4065. int clif_outsight(struct block_list *bl,va_list ap)
  4066. {
  4067. struct block_list *tbl;
  4068. struct view_data *vd;
  4069. struct map_session_data *sd, *tsd;
  4070. tbl=va_arg(ap,struct block_list*);
  4071. if(bl == tbl) return 0;
  4072. // bl can be null pointer? and after if BL_PC, sd will be null pointer too
  4073. sd = BL_CAST(BL_PC, bl);
  4074. tsd = BL_CAST(BL_PC, tbl);
  4075. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4076. nullpo_ret(bl);
  4077. switch(bl->type){
  4078. case BL_PC:
  4079. if (sd->vd.class_ != INVISIBLE_CLASS)
  4080. clif->clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4081. if (sd->chatID) {
  4082. struct chat_data *cd = map->id2cd(sd->chatID);
  4083. if(cd->usersd[0]==sd)
  4084. clif->dispchat(cd,tsd->fd);
  4085. }
  4086. if( sd->state.vending )
  4087. clif->closevendingboard(bl,tsd->fd);
  4088. if( sd->state.buyingstore )
  4089. clif->buyingstore_disappear_entry_single(tsd, sd);
  4090. break;
  4091. case BL_ITEM:
  4092. clif->clearflooritem(BL_UCAST(BL_ITEM, bl), tsd->fd);
  4093. break;
  4094. case BL_SKILL:
  4095. clif->clearchar_skillunit(BL_UCAST(BL_SKILL, bl), tsd->fd);
  4096. break;
  4097. case BL_NPC:
  4098. if (!(BL_UCAST(BL_NPC, bl)->option&OPTION_INVISIBLE))
  4099. clif->clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4100. break;
  4101. default:
  4102. if ((vd=status->get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4103. clif->clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4104. break;
  4105. }
  4106. }
  4107. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4108. nullpo_ret(tbl);
  4109. if (tbl->type == BL_SKILL) //Trap knocked out of sight
  4110. clif->clearchar_skillunit(BL_UCAST(BL_SKILL, tbl), sd->fd);
  4111. else if ((vd = status->get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS
  4112. && !(tbl->type == BL_NPC && (BL_UCAST(BL_NPC, tbl)->option&OPTION_INVISIBLE)))
  4113. clif->clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4114. }
  4115. return 0;
  4116. }
  4117. /*==========================================
  4118. * tbl has come into view of bl
  4119. *------------------------------------------*/
  4120. int clif_insight(struct block_list *bl,va_list ap)
  4121. {
  4122. struct block_list *tbl;
  4123. struct map_session_data *sd, *tsd;
  4124. tbl=va_arg(ap,struct block_list*);
  4125. if (bl == tbl) return 0;
  4126. sd = BL_CAST(BL_PC, bl);
  4127. tsd = BL_CAST(BL_PC, tbl);
  4128. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4129. nullpo_ret(bl);
  4130. switch(bl->type) {
  4131. case BL_ITEM:
  4132. clif->getareachar_item(tsd, BL_UCAST(BL_ITEM, bl));
  4133. break;
  4134. case BL_SKILL:
  4135. clif->getareachar_skillunit(&tsd->bl, BL_UCAST(BL_SKILL, bl), SELF);
  4136. break;
  4137. default:
  4138. clif->getareachar_unit(tsd,bl);
  4139. break;
  4140. }
  4141. }
  4142. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4143. clif->getareachar_unit(sd,tbl);
  4144. }
  4145. return 0;
  4146. }
  4147. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4148. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4149. void clif_skillinfoblock(struct map_session_data *sd)
  4150. {
  4151. int fd;
  4152. int i,len,id;
  4153. nullpo_retv(sd);
  4154. fd=sd->fd;
  4155. if (!fd) return;
  4156. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4157. WFIFOW(fd,0) = 0x10f;
  4158. for ( i = 0, len = 4; i < MAX_SKILL; i++) {
  4159. if( (id = sd->status.skill[i].id) != 0 ) {
  4160. int level;
  4161. // workaround for bugreport:5348
  4162. if (len + 37 > 8192)
  4163. break;
  4164. WFIFOW(fd, len) = id;
  4165. WFIFOL(fd, len + 2) = skill->get_inf(id);
  4166. level = sd->status.skill[i].lv;
  4167. WFIFOW(fd, len + 6) = level;
  4168. if (level) {
  4169. WFIFOW(fd, len + 8) = skill->get_sp(id, level);
  4170. WFIFOW(fd, len + 10)= skill->get_range2(&sd->bl, id, level);
  4171. }
  4172. else {
  4173. WFIFOW(fd, len + 8) = 0;
  4174. WFIFOW(fd, len + 10)= 0;
  4175. }
  4176. safestrncpy((char*)WFIFOP(fd,len+12), skill->get_name(id), NAME_LENGTH);
  4177. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4178. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill->tree_get_max(id, sd->status.class_))? 1:0;
  4179. else
  4180. WFIFOB(fd,len+36) = 0;
  4181. len += 37;
  4182. }
  4183. }
  4184. WFIFOW(fd,2)=len;
  4185. WFIFOSET(fd,len);
  4186. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4187. for ( ; i < MAX_SKILL; i++) {
  4188. if( (id = sd->status.skill[i].id) != 0 ) {
  4189. clif->addskill(sd, id);
  4190. clif->skillinfo(sd, id, 0);
  4191. }
  4192. }
  4193. }
  4194. /**
  4195. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4196. **/
  4197. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4198. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4199. void clif_addskill(struct map_session_data *sd, int id)
  4200. {
  4201. int fd, skill_lv, idx = skill->get_index(id);
  4202. nullpo_retv(sd);
  4203. fd = sd->fd;
  4204. if (!fd) return;
  4205. if (sd->status.skill[idx].id <= 0)
  4206. return;
  4207. skill_lv = sd->status.skill[idx].lv;
  4208. WFIFOHEAD(fd, packet_len(0x111));
  4209. WFIFOW(fd,0) = 0x111;
  4210. WFIFOW(fd,2) = id;
  4211. WFIFOL(fd,4) = skill->get_inf(id);
  4212. WFIFOW(fd,8) = skill_lv;
  4213. if (skill_lv > 0) {
  4214. WFIFOW(fd,10) = skill->get_sp(id, skill_lv);
  4215. WFIFOW(fd,12) = skill->get_range2(&sd->bl, id, skill_lv);
  4216. } else {
  4217. WFIFOW(fd,10) = 0;
  4218. WFIFOW(fd,12) = 0;
  4219. }
  4220. safestrncpy((char*)WFIFOP(fd,14), skill->get_name(id), NAME_LENGTH);
  4221. if (sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT)
  4222. WFIFOB(fd,38) = (skill_lv < skill->tree_get_max(id, sd->status.class_))? 1:0;
  4223. else
  4224. WFIFOB(fd,38) = 0;
  4225. WFIFOSET(fd,packet_len(0x111));
  4226. }
  4227. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4228. /// 0441 <skill id>.W
  4229. void clif_deleteskill(struct map_session_data *sd, int id)
  4230. {
  4231. #if PACKETVER >= 20081217
  4232. int fd;
  4233. nullpo_retv(sd);
  4234. fd = sd->fd;
  4235. if( !fd ) return;
  4236. WFIFOHEAD(fd,packet_len(0x441));
  4237. WFIFOW(fd,0) = 0x441;
  4238. WFIFOW(fd,2) = id;
  4239. WFIFOSET(fd,packet_len(0x441));
  4240. #endif
  4241. clif->skillinfoblock(sd);
  4242. }
  4243. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4244. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4245. /// Merged clif_skillup and clif_guild_skillup, same packet was used [panikon]
  4246. /// flag:
  4247. /// 0: guild call
  4248. /// 1: player call
  4249. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int skill_lv, int flag)
  4250. {
  4251. int fd;
  4252. nullpo_retv(sd);
  4253. fd = sd->fd;
  4254. WFIFOHEAD(fd, packet_len(0x10e));
  4255. WFIFOW(fd, 0) = 0x10e;
  4256. WFIFOW(fd, 2) = skill_id;
  4257. WFIFOW(fd, 4) = skill_lv;
  4258. WFIFOW(fd, 6) = skill->get_sp(skill_id, skill_lv);
  4259. WFIFOW(fd, 8) = (flag)?skill->get_range2(&sd->bl, skill_id, skill_lv) : skill->get_range(skill_id, skill_lv);
  4260. if( flag )
  4261. WFIFOB(fd,10) = (skill_lv < skill->tree_get_max(skill_id, sd->status.class_)) ? 1 : 0;
  4262. else
  4263. WFIFOB(fd,10) = 1;
  4264. WFIFOSET(fd, packet_len(0x10e));
  4265. }
  4266. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4267. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4268. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4269. {
  4270. const int fd = sd->fd;
  4271. int idx = skill->get_index(skill_id);
  4272. int skill_lv;
  4273. nullpo_retv(sd);
  4274. Assert_retv(idx >= 0 && idx < MAX_SKILL);
  4275. skill_lv = sd->status.skill[idx].lv;
  4276. WFIFOHEAD(fd,packet_len(0x7e1));
  4277. WFIFOW(fd,0) = 0x7e1;
  4278. WFIFOW(fd,2) = skill_id;
  4279. WFIFOL(fd,4) = inf?inf:skill->get_inf(skill_id);
  4280. WFIFOW(fd,8) = skill_lv;
  4281. if (skill_lv > 0) {
  4282. WFIFOW(fd,10) = skill->get_sp(skill_id, skill_lv);
  4283. WFIFOW(fd,12) = skill->get_range2(&sd->bl, skill_id, skill_lv);
  4284. } else {
  4285. WFIFOW(fd,10) = 0;
  4286. WFIFOW(fd,12) = 0;
  4287. }
  4288. if (sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT)
  4289. WFIFOB(fd,14) = (skill_lv < skill->tree_get_max(skill_id, sd->status.class_))? 1:0;
  4290. else
  4291. WFIFOB(fd,14) = 0;
  4292. WFIFOSET(fd,packet_len(0x7e1));
  4293. }
  4294. /// Notifies clients in area, that an object is about to use a skill.
  4295. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4296. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4297. /// property:
  4298. /// 0 = Yellow cast aura
  4299. /// 1 = Water elemental cast aura
  4300. /// 2 = Earth elemental cast aura
  4301. /// 3 = Fire elemental cast aura
  4302. /// 4 = Wind elemental cast aura
  4303. /// 5 = Poison elemental cast aura
  4304. /// 6 = Holy elemental cast aura
  4305. /// ? = like 0
  4306. /// is disposable:
  4307. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4308. /// 1 = no text
  4309. void clif_skillcasting(struct block_list* bl, int src_id, int dst_id, int dst_x, int dst_y, uint16 skill_id, int property, int casttime)
  4310. {
  4311. #if PACKETVER < 20091124
  4312. const int cmd = 0x13e;
  4313. #else
  4314. const int cmd = 0x7fb;
  4315. #endif
  4316. unsigned char buf[32];
  4317. WBUFW(buf,0) = cmd;
  4318. WBUFL(buf,2) = src_id;
  4319. WBUFL(buf,6) = dst_id;
  4320. WBUFW(buf,10) = dst_x;
  4321. WBUFW(buf,12) = dst_y;
  4322. WBUFW(buf,14) = skill_id;
  4323. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4324. WBUFL(buf,20) = casttime;
  4325. #if PACKETVER >= 20091124
  4326. WBUFB(buf,24) = 0; // isDisposable
  4327. #endif
  4328. if (disguised(bl)) {
  4329. clif->send(buf,packet_len(cmd), bl, AREA_WOS);
  4330. WBUFL(buf,2) = -src_id;
  4331. clif->send(buf,packet_len(cmd), bl, SELF);
  4332. } else
  4333. clif->send(buf,packet_len(cmd), bl, AREA);
  4334. }
  4335. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4336. /// 01b9 <id>.L
  4337. void clif_skillcastcancel(struct block_list* bl)
  4338. {
  4339. unsigned char buf[16];
  4340. nullpo_retv(bl);
  4341. WBUFW(buf,0) = 0x1b9;
  4342. WBUFL(buf,2) = bl->id;
  4343. clif->send(buf,packet_len(0x1b9), bl, AREA);
  4344. }
  4345. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4346. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4347. /// num (only used when skill id = NV_BASIC and cause = 0):
  4348. /// 0 = "skill failed" MsgStringTable[159]
  4349. /// 1 = "no emotions" MsgStringTable[160]
  4350. /// 2 = "no sit" MsgStringTable[161]
  4351. /// 3 = "no chat" MsgStringTable[162]
  4352. /// 4 = "no party" MsgStringTable[163]
  4353. /// 5 = "no shout" MsgStringTable[164]
  4354. /// 6 = "no PKing" MsgStringTable[165]
  4355. /// 7 = "no aligning" MsgStringTable[383]
  4356. /// ? = ignored
  4357. /// cause:
  4358. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4359. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4360. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4361. /// "skill failed" MsgStringTable[204] (otherwise)
  4362. /// ... = @see enum useskill_fail_cause
  4363. /// ? = ignored
  4364. ///
  4365. /// if(result!=0) doesn't display any of the previous messages
  4366. /// Note: when this packet is received an unknown flag is always set to 0,
  4367. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4368. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4369. {
  4370. int fd;
  4371. if (!sd) {
  4372. //Since this is the most common nullpo....
  4373. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4374. return;
  4375. }
  4376. fd=sd->fd;
  4377. if (!fd) return;
  4378. if(battle_config.display_skill_fail&1)
  4379. return; //Disable all skill failed messages
  4380. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4381. return; //Disable delay failed messages
  4382. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4383. return;
  4384. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4385. return;
  4386. WFIFOHEAD(fd,packet_len(0x110));
  4387. WFIFOW(fd,0) = 0x110;
  4388. WFIFOW(fd,2) = skill_id;
  4389. WFIFOL(fd,4) = btype;
  4390. WFIFOB(fd,8) = 0;// success
  4391. WFIFOB(fd,9) = cause;
  4392. WFIFOSET(fd,packet_len(0x110));
  4393. }
  4394. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4395. /// 043d <skill ID>.W <tick>.L
  4396. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int duration)
  4397. {
  4398. #if PACKETVER>=20081112
  4399. int fd;
  4400. nullpo_retv(sd);
  4401. fd=sd->fd;
  4402. WFIFOHEAD(fd,packet_len(0x43d));
  4403. WFIFOW(fd,0) = 0x43d;
  4404. WFIFOW(fd,2) = skill_id;
  4405. WFIFOL(fd,4) = duration;
  4406. WFIFOSET(fd,packet_len(0x43d));
  4407. #endif
  4408. }
  4409. /// Skill attack effect and damage.
  4410. /// 0114 <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <damage>.W <level>.W <div>.W <type>.B (ZC_NOTIFY_SKILL)
  4411. /// 01de <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <damage>.L <level>.W <div>.W <type>.B (ZC_NOTIFY_SKILL2)
  4412. int clif_skill_damage(struct block_list *src, struct block_list *dst, int64 tick, int sdelay, int ddelay, int64 in_damage, int div, uint16 skill_id, uint16 skill_lv, int type) {
  4413. unsigned char buf[64];
  4414. struct status_change *sc;
  4415. int damage;
  4416. nullpo_ret(src);
  4417. nullpo_ret(dst);
  4418. damage = (int)cap_value(in_damage, INT_MIN, INT_MAX);
  4419. type = clif_calc_delay(type, div, damage, ddelay);
  4420. #if PACKETVER >= 20131223
  4421. if (type == BDT_SKILL) type = BDT_MULTIHIT; //bugreport:8263
  4422. #endif
  4423. if ((sc = status->get_sc(dst)) && sc->count) {
  4424. if (sc->data[SC_ILLUSION] && damage)
  4425. damage = damage * (sc->data[SC_ILLUSION]->val2) + rnd() % 100;
  4426. }
  4427. #if PACKETVER < 3
  4428. WBUFW(buf, 0) = 0x114;
  4429. WBUFW(buf, 2) = skill_id;
  4430. WBUFL(buf, 4) = src->id;
  4431. WBUFL(buf, 8) = dst->id;
  4432. WBUFL(buf, 12) = (uint32)tick;
  4433. WBUFL(buf, 16) = sdelay;
  4434. WBUFL(buf, 20) = ddelay;
  4435. if (battle_config.hide_woe_damage && map_flag_gvg2(src->m)) {
  4436. WBUFW(buf, 24) = damage ? div : 0;
  4437. } else {
  4438. WBUFW(buf, 24) = damage;
  4439. }
  4440. WBUFW(buf, 26) = skill_lv;
  4441. WBUFW(buf, 28) = div;
  4442. WBUFB(buf, 30) = type;
  4443. if (disguised(dst)) {
  4444. clif->send(buf, packet_len(0x114), dst, AREA_WOS);
  4445. WBUFL(buf, 8) = -dst->id;
  4446. clif->send(buf, packet_len(0x114), dst, SELF);
  4447. } else
  4448. clif->send(buf, packet_len(0x114), dst, AREA);
  4449. if (disguised(src)) {
  4450. WBUFL(buf, 4) = -src->id;
  4451. if (disguised(dst))
  4452. WBUFL(buf, 8) = dst->id;
  4453. if (damage > 0)
  4454. WBUFW(buf, 24) = -1;
  4455. clif->send(buf, packet_len(0x114), src, SELF);
  4456. }
  4457. #else
  4458. WBUFW(buf, 0) = 0x1de;
  4459. WBUFW(buf, 2) = skill_id;
  4460. WBUFL(buf, 4) = src->id;
  4461. WBUFL(buf, 8) = dst->id;
  4462. WBUFL(buf, 12) = (uint32)tick;
  4463. WBUFL(buf, 16) = sdelay;
  4464. WBUFL(buf, 20) = ddelay;
  4465. if (battle_config.hide_woe_damage && map_flag_gvg2(src->m)) {
  4466. WBUFL(buf, 24) = damage ? div : 0;
  4467. } else {
  4468. WBUFL(buf, 24) = damage;
  4469. }
  4470. WBUFW(buf, 28) = skill_lv;
  4471. WBUFW(buf, 30) = div;
  4472. // For some reason, late 2013 and newer clients have
  4473. // a issue that causes players and monsters to endure
  4474. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4475. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4476. #if PACKETVER < 20131223
  4477. WBUFB(buf, 32) = type;
  4478. #else
  4479. WBUFB(buf, 32) = (type == BDT_SKILL) ? BDT_MULTIHIT : type;
  4480. #endif
  4481. if (disguised(dst)) {
  4482. clif->send(buf, packet_len(0x1de), dst, AREA_WOS);
  4483. WBUFL(buf,8)=-dst->id;
  4484. clif->send(buf, packet_len(0x1de), dst, SELF);
  4485. } else
  4486. clif->send(buf, packet_len(0x1de), dst, AREA);
  4487. if (disguised(src)) {
  4488. WBUFL(buf, 4) = -src->id;
  4489. if (disguised(dst))
  4490. WBUFL(buf, 8) = dst->id;
  4491. if (damage > 0)
  4492. WBUFL(buf, 24) = -1;
  4493. clif->send(buf, packet_len(0x1de), src, SELF);
  4494. }
  4495. #endif
  4496. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4497. return clif->calc_walkdelay(dst, ddelay, type, damage, div);
  4498. }
  4499. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4500. /// 0115 <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <x>.W <y>.W <damage>.W <level>.W <div>.W <type>.B
  4501. #if 0
  4502. int clif_skill_damage2(struct block_list *src, struct block_list *dst, int64 tick, int sdelay, int ddelay, int damage, int div, uint16 skill_id, uint16 skill_lv, int type) {
  4503. unsigned char buf[64];
  4504. struct status_change *sc;
  4505. nullpo_ret(src);
  4506. nullpo_ret(dst);
  4507. type = (type>0)?type:skill->get_hit(skill_id);
  4508. type = clif_calc_delay(type,div,damage,ddelay);
  4509. sc = status->get_sc(dst);
  4510. if(sc && sc->count) {
  4511. if(sc->data[SC_ILLUSION] && damage)
  4512. damage = damage*(sc->data[SC_ILLUSION]->val2) + rnd()%100;
  4513. }
  4514. WBUFW(buf,0)=0x115;
  4515. WBUFW(buf,2)=skill_id;
  4516. WBUFL(buf,4)=src->id;
  4517. WBUFL(buf,8)=dst->id;
  4518. WBUFL(buf,12)=(uint32)tick;
  4519. WBUFL(buf,16)=sdelay;
  4520. WBUFL(buf,20)=ddelay;
  4521. WBUFW(buf,24)=dst->x;
  4522. WBUFW(buf,26)=dst->y;
  4523. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4524. WBUFW(buf,28)=damage?div:0;
  4525. } else {
  4526. WBUFW(buf,28)=damage;
  4527. }
  4528. WBUFW(buf,30)=skill_lv;
  4529. WBUFW(buf,32)=div;
  4530. WBUFB(buf,34)=type;
  4531. clif->send(buf,packet_len(0x115),src,AREA);
  4532. if(disguised(src)) {
  4533. WBUFL(buf,4)=-src->id;
  4534. if(damage > 0)
  4535. WBUFW(buf,28)=-1;
  4536. clif->send(buf,packet_len(0x115),src,SELF);
  4537. }
  4538. if (disguised(dst)) {
  4539. WBUFL(buf,8)=-dst->id;
  4540. if (disguised(src))
  4541. WBUFL(buf,4)=src->id;
  4542. else if(damage > 0)
  4543. WBUFW(buf,28)=-1;
  4544. clif->send(buf,packet_len(0x115),dst,SELF);
  4545. }
  4546. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4547. return clif->calc_walkdelay(dst,ddelay,type,damage,div);
  4548. }
  4549. #endif // 0
  4550. /// Non-damaging skill effect (ZC_USE_SKILL).
  4551. /// 011a <skill id>.W <skill lv>.W <dst id>.L <src id>.L <result>.B
  4552. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,uint16 skill_id,int heal,int fail)
  4553. {
  4554. unsigned char buf[32];
  4555. nullpo_ret(dst);
  4556. WBUFW(buf,0)=0x11a;
  4557. WBUFW(buf,2)=skill_id;
  4558. WBUFW(buf,4)=min(heal, INT16_MAX);
  4559. WBUFL(buf,6)=dst->id;
  4560. WBUFL(buf,10)=src?src->id:0;
  4561. WBUFB(buf,14)=fail;
  4562. if (disguised(dst)) {
  4563. clif->send(buf,packet_len(0x11a),dst,AREA_WOS);
  4564. WBUFL(buf,6)=-dst->id;
  4565. clif->send(buf,packet_len(0x11a),dst,SELF);
  4566. } else
  4567. clif->send(buf,packet_len(0x11a),dst,AREA);
  4568. if(src && disguised(src)) {
  4569. WBUFL(buf,10)=-src->id;
  4570. if (disguised(dst))
  4571. WBUFL(buf,6)=dst->id;
  4572. clif->send(buf,packet_len(0x11a),src,SELF);
  4573. }
  4574. return fail;
  4575. }
  4576. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  4577. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  4578. void clif_skill_poseffect(struct block_list *src, uint16 skill_id, int val, int x, int y, int64 tick) {
  4579. unsigned char buf[32];
  4580. nullpo_retv(src);
  4581. WBUFW(buf,0)=0x117;
  4582. WBUFW(buf,2)=skill_id;
  4583. WBUFL(buf,4)=src->id;
  4584. WBUFW(buf,8)=val;
  4585. WBUFW(buf,10)=x;
  4586. WBUFW(buf,12)=y;
  4587. WBUFL(buf,14)=(uint32)tick;
  4588. if(disguised(src)) {
  4589. clif->send(buf,packet_len(0x117),src,AREA_WOS);
  4590. WBUFL(buf,4)=-src->id;
  4591. clif->send(buf,packet_len(0x117),src,SELF);
  4592. } else
  4593. clif->send(buf,packet_len(0x117),src,AREA);
  4594. }
  4595. /// Presents a list of available warp destinations (ZC_WARPLIST).
  4596. /// 011c <skill id>.W { <map name>.16B }*4
  4597. void clif_skill_warppoint(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  4598. {
  4599. int fd;
  4600. nullpo_retv(sd);
  4601. fd = sd->fd;
  4602. WFIFOHEAD(fd,packet_len(0x11c));
  4603. WFIFOW(fd,0) = 0x11c;
  4604. WFIFOW(fd,2) = skill_id;
  4605. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4606. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4607. else // normal map name
  4608. if (map1 > 0) mapindex->getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4609. if (map2 > 0) mapindex->getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4610. if (map3 > 0) mapindex->getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4611. if (map4 > 0) mapindex->getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4612. WFIFOSET(fd,packet_len(0x11c));
  4613. sd->menuskill_id = skill_id;
  4614. if (skill_id == AL_WARP){
  4615. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4616. sd->state.workinprogress = 3;
  4617. }else
  4618. sd->menuskill_val = skill_lv;
  4619. }
  4620. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  4621. /// 011e <type>.B
  4622. /// type:
  4623. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4624. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  4625. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  4626. ///
  4627. /// @param sd Who receives the message
  4628. /// @param type What message
  4629. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4630. {
  4631. int fd;
  4632. nullpo_retv(sd);
  4633. fd=sd->fd;
  4634. WFIFOHEAD(fd,packet_len(0x11e));
  4635. WFIFOW(fd,0)=0x11e;
  4636. WFIFOB(fd,2)=type;
  4637. WFIFOSET(fd,packet_len(0x11e));
  4638. }
  4639. /// Teleport message (ZC_NOTIFY_MAPINFO).
  4640. /// 0189 <type>.W
  4641. /// type:
  4642. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4643. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  4644. /// 2 = "This skill cannot be used within this area." in color 0xFFFF00 (cyan)
  4645. ///
  4646. /// @param sd Who receives the message
  4647. /// @param type What message
  4648. void clif_skill_mapinfomessage(struct map_session_data *sd, int type)
  4649. {
  4650. int fd;
  4651. nullpo_retv(sd);
  4652. fd=sd->fd;
  4653. WFIFOHEAD(fd,packet_len(0x189));
  4654. WFIFOW(fd,0)=0x189;
  4655. WFIFOW(fd,2)=type;
  4656. WFIFOSET(fd,packet_len(0x189));
  4657. }
  4658. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  4659. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  4660. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  4661. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst) {
  4662. struct status_data *dstatus;
  4663. unsigned char buf[64];
  4664. int i;//, fix;
  4665. nullpo_retv(sd);
  4666. nullpo_retv(dst);
  4667. if( dst->type != BL_MOB )
  4668. return;
  4669. dstatus = status->get_status_data(dst);
  4670. WBUFW(buf, 0) = 0x18c;
  4671. WBUFW(buf, 2) = status->get_class(dst);
  4672. WBUFW(buf, 4) = status->get_lv(dst);
  4673. WBUFW(buf, 6) = dstatus->size;
  4674. WBUFL(buf, 8) = dstatus->hp;
  4675. WBUFW(buf,12) = ((battle_config.estimation_type&1) ? dstatus->def : 0)
  4676. + ((battle_config.estimation_type&2) ? dstatus->def2 : 0);
  4677. WBUFW(buf,14) = dstatus->race;
  4678. WBUFW(buf,16) = ((battle_config.estimation_type&1) ? dstatus->mdef : 0)
  4679. + ((battle_config.estimation_type&2) ? dstatus->mdef2 : 0);
  4680. WBUFW(buf,18) = dstatus->def_ele;
  4681. for(i=0;i<9;i++) {
  4682. WBUFB(buf,20+i)= (unsigned char)battle->attr_ratio(i+1,dstatus->def_ele, dstatus->ele_lv);
  4683. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4684. //WBUFB(buf,20+i)= (unsigned char)((fix=battle->attr_ratio(i+1,dstatus->def_ele, dstatus->ele_lv))<0?0:fix);
  4685. }
  4686. clif->send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4687. }
  4688. /// Presents a textual list of producible items (ZC_MAKABLEITEMLIST).
  4689. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  4690. /// material id:
  4691. /// unused by the client
  4692. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  4693. {
  4694. int i,c,view,fd;
  4695. nullpo_retv(sd);
  4696. if(sd->menuskill_id == skill_id)
  4697. return; //Avoid resending the menu twice or more times...
  4698. if( skill_id == GC_CREATENEWPOISON )
  4699. skill_id = GC_RESEARCHNEWPOISON;
  4700. fd=sd->fd;
  4701. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4702. WFIFOW(fd, 0)=0x18d;
  4703. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4704. if( skill->can_produce_mix(sd,skill->dbs->produce_db[i].nameid, trigger, 1) &&
  4705. ( ( skill_id > 0 && skill->dbs->produce_db[i].req_skill == skill_id ) || skill_id < 0 )
  4706. ){
  4707. if((view = itemdb_viewid(skill->dbs->produce_db[i].nameid)) > 0)
  4708. WFIFOW(fd,c*8+ 4)= view;
  4709. else
  4710. WFIFOW(fd,c*8+ 4)= skill->dbs->produce_db[i].nameid;
  4711. WFIFOW(fd,c*8+ 6)= 0;
  4712. WFIFOW(fd,c*8+ 8)= 0;
  4713. WFIFOW(fd,c*8+10)= 0;
  4714. c++;
  4715. }
  4716. }
  4717. WFIFOW(fd, 2)=c*8+8;
  4718. WFIFOSET(fd,WFIFOW(fd,2));
  4719. if(c > 0) {
  4720. sd->menuskill_id = skill_id;
  4721. sd->menuskill_val = trigger;
  4722. return;
  4723. }
  4724. }
  4725. /// Present a list of producible items (ZC_MAKINGITEM_LIST).
  4726. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  4727. /// mk type:
  4728. /// 1 = cooking
  4729. /// 2 = arrow
  4730. /// 3 = elemental
  4731. /// 4 = GN_MIX_COOKING
  4732. /// 5 = GN_MAKEBOMB
  4733. /// 6 = GN_S_PHARMACY
  4734. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  4735. {
  4736. int fd;
  4737. int i, c;
  4738. int view;
  4739. nullpo_retv(sd);
  4740. fd = sd->fd;
  4741. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  4742. WFIFOW(fd,0) = 0x25a;
  4743. WFIFOW(fd,4) = list_type; // list type
  4744. c = 0;
  4745. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  4746. if( !skill->can_produce_mix(sd,skill->dbs->produce_db[i].nameid,trigger, qty) )
  4747. continue;
  4748. if( (view = itemdb_viewid(skill->dbs->produce_db[i].nameid)) > 0 )
  4749. WFIFOW(fd, 6 + 2 * c) = view;
  4750. else
  4751. WFIFOW(fd, 6 + 2 * c) = skill->dbs->produce_db[i].nameid;
  4752. c++;
  4753. }
  4754. if( skill_id == AM_PHARMACY ) {
  4755. // Only send it while Cooking else check for c.
  4756. WFIFOW(fd,2) = 6 + 2 * c;
  4757. WFIFOSET(fd,WFIFOW(fd,2));
  4758. }
  4759. if( c > 0 ) {
  4760. sd->menuskill_id = skill_id;
  4761. sd->menuskill_val = trigger;
  4762. if( skill_id != AM_PHARMACY ) {
  4763. sd->menuskill_val2 = qty; // amount.
  4764. WFIFOW(fd,2) = 6 + 2 * c;
  4765. WFIFOSET(fd,WFIFOW(fd,2));
  4766. }
  4767. } else {
  4768. clif_menuskill_clear(sd);
  4769. if( skill_id != AM_PHARMACY ) { // AM_PHARMACY is used to Cooking.
  4770. // It fails.
  4771. #if PACKETVER >= 20090922
  4772. clif->msgtable_skill(sd, skill_id, MSG_COOKING_LIST_FAIL);
  4773. #else
  4774. WFIFOW(fd,2) = 6 + 2 * c;
  4775. WFIFOSET(fd,WFIFOW(fd,2));
  4776. #endif
  4777. }
  4778. }
  4779. }
  4780. void clif_status_change_notick(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3) {
  4781. struct packet_sc_notick p;
  4782. struct map_session_data *sd;
  4783. nullpo_retv(bl);
  4784. if (type == SI_BLANK) //It shows nothing on the client...
  4785. return;
  4786. if (!(status->type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4787. return;
  4788. sd = BL_CAST(BL_PC, bl);
  4789. p.PacketType = sc_notickType;
  4790. p.index = type;
  4791. p.AID = bl->id;
  4792. p.state = (unsigned char)flag;
  4793. clif->send(&p,packet_len(p.PacketType), bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4794. }
  4795. /// Notifies clients of a status change.
  4796. /// 0196 <index>.W <id>.L <state>.B (ZC_MSG_STATE_CHANGE) [used for ending status changes and starting them on non-pc units (when needed)]
  4797. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  4798. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (PACKETVER >= 20111108)
  4799. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (PACKETVER >= 20120618)
  4800. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (PACKETVER >= 20120618)
  4801. void clif_status_change(struct block_list *bl,int type,int flag,int tick,int val1, int val2, int val3) {
  4802. struct packet_status_change p;
  4803. struct map_session_data *sd;
  4804. if (type == SI_BLANK) //It shows nothing on the client...
  4805. return;
  4806. nullpo_retv(bl);
  4807. if (!(status->type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  4808. return;
  4809. if ( tick < 0 )
  4810. tick = 9999;
  4811. sd = BL_CAST(BL_PC, bl);
  4812. p.PacketType = status_changeType;
  4813. p.index = type;
  4814. p.AID = bl->id;
  4815. p.state = (unsigned char)flag;
  4816. #if PACKETVER >= 20120618
  4817. p.Total = tick; /* at this stage remain and total are the same value I believe */
  4818. #endif
  4819. #if PACKETVER >= 20090121
  4820. p.Left = tick;
  4821. p.val1 = val1;
  4822. p.val2 = val2;
  4823. p.val3 = val3;
  4824. #endif
  4825. clif->send(&p,sizeof(p), bl, (sd && sd->status.option&OPTION_INVISIBLE) ? SELF : AREA);
  4826. }
  4827. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  4828. /// 008e <packet len>.W <message>.?B
  4829. void clif_displaymessage(const int fd, const char* mes) {
  4830. nullpo_retv(mes);
  4831. if( map->cpsd_active && fd == 0 ) {
  4832. ShowInfo("HCP: %s\n",mes);
  4833. } else if ( fd > 0 ) {
  4834. #if PACKETVER == 20141022
  4835. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  4836. /** so we redirect to ZC_NPC_CHAT **/
  4837. clif->messagecolor_self(fd, COLOR_DEFAULT, mes);
  4838. #else
  4839. size_t len;
  4840. if ( ( len = strnlen(mes, 255) ) > 0 ) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4841. WFIFOHEAD(fd, 5 + len);
  4842. WFIFOW(fd,0) = 0x8e;
  4843. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL terminate
  4844. safestrncpy((char *)WFIFOP(fd,4), mes, len + 1);
  4845. WFIFOSET(fd, 5 + len);
  4846. }
  4847. #endif
  4848. }
  4849. }
  4850. void clif_displaymessage2(const int fd, const char* mes) {
  4851. nullpo_retv(mes);
  4852. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4853. if (fd == 0 && !map->cpsd_active)
  4854. ;
  4855. else {
  4856. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4857. char *message, *line;
  4858. message = aStrdup(mes);
  4859. line = strtok(message, "\n");
  4860. while(line != NULL) {
  4861. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  4862. size_t len = strnlen(line, 255);
  4863. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4864. if( map->cpsd_active && fd == 0 ) {
  4865. ShowInfo("HCP: %s\n",line);
  4866. } else {
  4867. WFIFOHEAD(fd, 5 + len);
  4868. WFIFOW(fd,0) = 0x8e;
  4869. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL terminate
  4870. safestrncpy((char *)WFIFOP(fd,4), line, len + 1);
  4871. WFIFOSET(fd, 5 + len);
  4872. }
  4873. }
  4874. line = strtok(NULL, "\n");
  4875. }
  4876. aFree(message);
  4877. }
  4878. }
  4879. /* oh noo! another version of 0x8e! */
  4880. void clif_displaymessage_sprintf(const int fd, const char *mes, ...) __attribute__((format(printf, 2, 3)));
  4881. void clif_displaymessage_sprintf(const int fd, const char *mes, ...) {
  4882. va_list ap;
  4883. nullpo_retv(mes);
  4884. if (map->cpsd_active && fd == 0) {
  4885. ShowInfo("HCP: ");
  4886. va_start(ap,mes);
  4887. vShowMessage(mes,ap);
  4888. va_end(ap);
  4889. ShowMessage("\n");
  4890. } else if (fd > 0) {
  4891. int len = 1;
  4892. char *ptr;
  4893. WFIFOHEAD(fd, 5 + 255);/* ensure the maximum */
  4894. /* process */
  4895. va_start(ap,mes);
  4896. len += vsnprintf((char *)WFIFOP(fd,4), 255, mes, ap);
  4897. va_end(ap);
  4898. /* adjusting */
  4899. ptr = (char *)WFIFOP(fd,4);
  4900. ptr[len - 1] = '\0';
  4901. /* */
  4902. WFIFOW(fd,0) = 0x8e;
  4903. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL terminate
  4904. WFIFOSET(fd, 5 + len);
  4905. }
  4906. }
  4907. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  4908. /// 009a <packet len>.W <message>.?B
  4909. void clif_broadcast(struct block_list *bl, const char *mes, size_t len, int type, enum send_target target)
  4910. {
  4911. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  4912. unsigned char *buf = NULL;
  4913. nullpo_retv(mes);
  4914. buf = aMalloc((4 + lp + len)*sizeof(unsigned char));
  4915. WBUFW(buf,0) = 0x9a;
  4916. WBUFW(buf,2) = 4 + lp + len;
  4917. if( type&BC_BLUE )
  4918. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4919. else if( type&BC_WOE )
  4920. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4921. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4922. clif->send(buf, WBUFW(buf,2), bl, target);
  4923. aFree(buf);
  4924. }
  4925. /*==========================================
  4926. * Displays a message on a 'bl' to all it's nearby clients
  4927. * Used by npc_globalmessage
  4928. *------------------------------------------*/
  4929. void clif_GlobalMessage(struct block_list* bl, const char* message) {
  4930. char buf[256];
  4931. size_t len;
  4932. nullpo_retv(bl);
  4933. if(!message)
  4934. return;
  4935. len = strlen(message)+1;
  4936. if (len > sizeof(buf)-8) {
  4937. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%"PRIuS").\n", message, len);
  4938. len = sizeof(buf)-8;
  4939. }
  4940. WBUFW(buf,0)=0x8d;
  4941. WBUFW(buf,2)=len+8;
  4942. WBUFL(buf,4)=bl->id;
  4943. safestrncpy((char *) WBUFP(buf,8),message,len);
  4944. clif->send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4945. }
  4946. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  4947. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4948. void clif_broadcast2(struct block_list* bl, const char* mes, size_t len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target)
  4949. {
  4950. unsigned char *buf;
  4951. nullpo_retv(mes);
  4952. buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  4953. WBUFW(buf,0) = 0x1c3;
  4954. WBUFW(buf,2) = len + 16;
  4955. WBUFL(buf,4) = fontColor;
  4956. WBUFW(buf,8) = fontType;
  4957. WBUFW(buf,10) = fontSize;
  4958. WBUFW(buf,12) = fontAlign;
  4959. WBUFW(buf,14) = fontY;
  4960. memcpy(WBUFP(buf,16), mes, len);
  4961. clif->send(buf, WBUFW(buf,2), bl, target);
  4962. aFree(buf);
  4963. }
  4964. /// Displays heal effect (ZC_RECOVERY).
  4965. /// 013d <var id>.W <amount>.W
  4966. /// var id:
  4967. /// 5 = HP (SP_HP)
  4968. /// 7 = SP (SP_SP)
  4969. /// ? = ignored
  4970. void clif_heal(int fd,int type,int val)
  4971. {
  4972. WFIFOHEAD(fd,packet_len(0x13d));
  4973. WFIFOW(fd,0)=0x13d;
  4974. WFIFOW(fd,2)=type;
  4975. WFIFOW(fd,4)=cap_value(val,0,INT16_MAX);
  4976. WFIFOSET(fd,packet_len(0x13d));
  4977. }
  4978. /// Displays resurrection effect (ZC_RESURRECTION).
  4979. /// 0148 <id>.L <type>.W
  4980. /// type:
  4981. /// ignored
  4982. void clif_resurrection(struct block_list *bl,int type)
  4983. {
  4984. unsigned char buf[16];
  4985. nullpo_retv(bl);
  4986. WBUFW(buf,0)=0x148;
  4987. WBUFL(buf,2)=bl->id;
  4988. WBUFW(buf,6)=0;
  4989. clif->send(buf,packet_len(0x148),bl, type == 1 ? AREA : AREA_WOS);
  4990. if (disguised(bl)) {
  4991. struct map_session_data *sd = BL_UCAST(BL_PC, bl);
  4992. if (sd->fontcolor) {
  4993. WBUFL(buf,2)=-bl->id;
  4994. clif->send(buf,packet_len(0x148),bl, SELF);
  4995. } else {
  4996. clif->spawn(bl);
  4997. }
  4998. }
  4999. }
  5000. /// Sets the map property (ZC_NOTIFY_MAPPROPERTY).
  5001. /// 0199 <type>.W
  5002. void clif_map_property(struct map_session_data* sd, enum map_property property)
  5003. {
  5004. int fd;
  5005. nullpo_retv(sd);
  5006. fd=sd->fd;
  5007. WFIFOHEAD(fd,packet_len(0x199));
  5008. WFIFOW(fd,0)=0x199;
  5009. WFIFOW(fd,2)=property;
  5010. WFIFOSET(fd,packet_len(0x199));
  5011. }
  5012. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5013. /// 01d6 <type>.W
  5014. void clif_map_type(struct map_session_data* sd, enum map_type type) {
  5015. int fd;
  5016. nullpo_retv(sd);
  5017. fd=sd->fd;
  5018. WFIFOHEAD(fd,packet_len(0x1D6));
  5019. WFIFOW(fd,0)=0x1D6;
  5020. WFIFOW(fd,2)=type;
  5021. WFIFOSET(fd,packet_len(0x1D6));
  5022. }
  5023. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5024. /// 019a <id>.L <ranking>.L <total>.L
  5025. // FIXME: missing documentation for the 'type' parameter
  5026. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5027. {
  5028. nullpo_retv(sd);
  5029. if(type == 2) {
  5030. int fd = sd->fd;
  5031. WFIFOHEAD(fd,packet_len(0x19a));
  5032. WFIFOW(fd,0) = 0x19a;
  5033. WFIFOL(fd,2) = sd->bl.id;
  5034. WFIFOL(fd,6) = pvprank;
  5035. WFIFOL(fd,10) = pvpnum;
  5036. WFIFOSET(fd,packet_len(0x19a));
  5037. } else {
  5038. unsigned char buf[32];
  5039. WBUFW(buf,0) = 0x19a;
  5040. WBUFL(buf,2) = sd->bl.id;
  5041. if (sd->sc.option&(OPTION_HIDE|OPTION_CLOAK)) // TODO[Haru] Should this be pc_ishiding(sd)? (i.e. include Chase Walk and any new options)
  5042. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5043. else
  5044. WBUFL(buf,6) = pvprank;
  5045. WBUFL(buf,10) = pvpnum;
  5046. if (pc_isinvisible(sd) || sd->disguise != -1) //Causes crashes when a 'mob' with pvp info dies.
  5047. clif->send(buf,packet_len(0x19a),&sd->bl,SELF);
  5048. else if(!type)
  5049. clif->send(buf,packet_len(0x19a),&sd->bl,AREA);
  5050. else
  5051. clif->send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5052. }
  5053. }
  5054. /*==========================================
  5055. *
  5056. *------------------------------------------*/
  5057. void clif_map_property_mapall(int mapid, enum map_property property)
  5058. {
  5059. struct block_list bl;
  5060. unsigned char buf[16];
  5061. bl.id = 0;
  5062. bl.type = BL_NUL;
  5063. bl.m = mapid;
  5064. WBUFW(buf,0)=0x199;
  5065. WBUFW(buf,2)=property;
  5066. clif->send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  5067. }
  5068. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5069. /// 0188 <result>.W <index>.W <refine>.W
  5070. /// result:
  5071. /// 0 = success
  5072. /// 1 = failure
  5073. /// 2 = downgrade
  5074. void clif_refine(int fd, int fail, int index, int val)
  5075. {
  5076. WFIFOHEAD(fd,packet_len(0x188));
  5077. WFIFOW(fd,0)=0x188;
  5078. WFIFOW(fd,2)=fail;
  5079. WFIFOW(fd,4)=index+2;
  5080. WFIFOW(fd,6)=val;
  5081. WFIFOSET(fd,packet_len(0x188));
  5082. }
  5083. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5084. /// 0223 <result>.L <nameid>.W
  5085. /// result:
  5086. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5087. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5088. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5089. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5090. void clif_upgrademessage(int fd, int result, int item_id)
  5091. {
  5092. WFIFOHEAD(fd,packet_len(0x223));
  5093. WFIFOW(fd,0)=0x223;
  5094. WFIFOL(fd,2)=result;
  5095. WFIFOW(fd,6)=item_id;
  5096. WFIFOSET(fd,packet_len(0x223));
  5097. }
  5098. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5099. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5100. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5101. void clif_wis_message(int fd, const char *nick, const char *mes, size_t mes_len)
  5102. {
  5103. #if PACKETVER >= 20091104
  5104. struct map_session_data *ssd = NULL;
  5105. #endif // PACKETVER >= 20091104
  5106. nullpo_retv(nick);
  5107. nullpo_retv(mes);
  5108. #if PACKETVER < 20091104
  5109. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5110. WFIFOW(fd,0) = 0x97;
  5111. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5112. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5113. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  5114. WFIFOSET(fd,WFIFOW(fd,2));
  5115. #else
  5116. ssd = map->nick2sd(nick);
  5117. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5118. WFIFOW(fd,0) = 0x97;
  5119. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5120. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  5121. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5122. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  5123. WFIFOSET(fd,WFIFOW(fd,2));
  5124. #endif
  5125. }
  5126. /// Inform the player about the result of his whisper action (ZC_ACK_WHISPER).
  5127. /// 0098 <result>.B
  5128. /// result:
  5129. /// 0 = success to send whisper
  5130. /// 1 = target character is not logged in
  5131. /// 2 = ignored by target
  5132. /// 3 = everyone ignored by target
  5133. void clif_wis_end(int fd, int flag) {
  5134. struct map_session_data *sd = sockt->session_is_valid(fd) ? sockt->session[fd]->session_data : NULL;
  5135. struct packet_wis_end p;
  5136. if( !sd )
  5137. return;
  5138. p.PacketType = wisendType;
  5139. p.result = (char)flag;
  5140. #if PACKETVER >= 20131223
  5141. p.unknown = 0;
  5142. #endif
  5143. clif->send(&p, sizeof(p), &sd->bl, SELF);
  5144. }
  5145. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5146. /// 0194 <char id>.L <name>.24B
  5147. void clif_solved_charname(int fd, int charid, const char* name)
  5148. {
  5149. nullpo_retv(name);
  5150. WFIFOHEAD(fd,packet_len(0x194));
  5151. WFIFOW(fd,0)=0x194;
  5152. WFIFOL(fd,2)=charid;
  5153. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  5154. WFIFOSET(fd,packet_len(0x194));
  5155. }
  5156. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5157. /// 017b <packet len>.W { <name id>.W }*
  5158. void clif_use_card(struct map_session_data *sd,int idx)
  5159. {
  5160. int i, c;
  5161. int fd;
  5162. nullpo_retv(sd);
  5163. fd = sd->fd;
  5164. if (sd->state.trading != 0)
  5165. return;
  5166. if (!pc->can_insert_card(sd, idx))
  5167. return;
  5168. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5169. WFIFOW(fd, 0) = 0x17b;
  5170. for (i = c = 0; i < MAX_INVENTORY; i++) {
  5171. if (!pc->can_insert_card_into(sd, idx, i))
  5172. continue;
  5173. WFIFOW(fd, 4 + c * 2) = i + 2;
  5174. c++;
  5175. }
  5176. if (!c) return; // no item is available for card insertion
  5177. WFIFOW(fd, 2) = 4 + c * 2;
  5178. WFIFOSET(fd, WFIFOW(fd, 2));
  5179. }
  5180. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5181. /// 017d <equip index>.W <card index>.W <result>.B
  5182. /// result:
  5183. /// 0 = success
  5184. /// 1 = failure
  5185. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5186. {
  5187. int fd;
  5188. nullpo_retv(sd);
  5189. fd=sd->fd;
  5190. WFIFOHEAD(fd,packet_len(0x17d));
  5191. WFIFOW(fd,0)=0x17d;
  5192. WFIFOW(fd,2)=idx_equip+2;
  5193. WFIFOW(fd,4)=idx_card+2;
  5194. WFIFOB(fd,6)=flag;
  5195. WFIFOSET(fd,packet_len(0x17d));
  5196. }
  5197. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5198. /// 0177 <packet len>.W { <name id>.W }*
  5199. void clif_item_identify_list(struct map_session_data *sd)
  5200. {
  5201. int i,c;
  5202. int fd;
  5203. nullpo_retv(sd);
  5204. fd=sd->fd;
  5205. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5206. WFIFOW(fd,0)=0x177;
  5207. for(i=c=0;i<MAX_INVENTORY;i++){
  5208. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  5209. WFIFOW(fd,c*2+4)=i+2;
  5210. c++;
  5211. }
  5212. }
  5213. if(c > 0) {
  5214. WFIFOW(fd,2)=c*2+4;
  5215. WFIFOSET(fd,WFIFOW(fd,2));
  5216. sd->menuskill_id = MC_IDENTIFY;
  5217. sd->menuskill_val = c;
  5218. sd->state.workinprogress = 3;
  5219. }
  5220. }
  5221. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5222. /// 0179 <index>.W <result>.B
  5223. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5224. {
  5225. int fd;
  5226. nullpo_retv(sd);
  5227. fd=sd->fd;
  5228. WFIFOHEAD(fd,packet_len(0x179));
  5229. WFIFOW(fd, 0)=0x179;
  5230. WFIFOW(fd, 2)=idx+2;
  5231. WFIFOB(fd, 4)=flag;
  5232. WFIFOSET(fd,packet_len(0x179));
  5233. }
  5234. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5235. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5236. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5237. {
  5238. int i,c;
  5239. int fd;
  5240. nullpo_retv(sd);
  5241. nullpo_retv(dstsd);
  5242. fd=sd->fd;
  5243. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5244. WFIFOW(fd,0)=0x1fc;
  5245. for (i = c = 0; i < MAX_INVENTORY; i++) {
  5246. int nameid = dstsd->status.inventory[i].nameid;
  5247. if (nameid > 0 && dstsd->status.inventory[i].attribute != 0) { // && skill_can_repair(sd,nameid)) {
  5248. WFIFOW(fd,c*13+4) = i;
  5249. WFIFOW(fd,c*13+6) = nameid;
  5250. WFIFOB(fd,c*13+8) = dstsd->status.inventory[i].refine;
  5251. clif->addcards(WFIFOP(fd,c*13+9), &dstsd->status.inventory[i]);
  5252. c++;
  5253. }
  5254. }
  5255. if(c > 0) {
  5256. WFIFOW(fd,2)=c*13+4;
  5257. WFIFOSET(fd,WFIFOW(fd,2));
  5258. sd->menuskill_id = BS_REPAIRWEAPON;
  5259. sd->menuskill_val = dstsd->bl.id;
  5260. sd->menuskill_val2 = lv;
  5261. }else
  5262. clif->skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5263. }
  5264. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5265. /// 01fe <index>.W <result>.B
  5266. /// index:
  5267. /// ignored (inventory index)
  5268. /// result:
  5269. /// 0 = Item repair success.
  5270. /// 1 = Item repair failure.
  5271. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5272. {
  5273. int fd;
  5274. nullpo_retv(sd);
  5275. fd = sd->fd;
  5276. WFIFOHEAD(fd,packet_len(0x1fe));
  5277. WFIFOW(fd, 0)=0x1fe;
  5278. WFIFOW(fd, 2)=idx+2;
  5279. WFIFOB(fd, 4)=flag;
  5280. WFIFOSET(fd,packet_len(0x1fe));
  5281. }
  5282. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5283. /// 02bb <equip location>.W <account id>.L
  5284. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5285. {
  5286. int fd;
  5287. nullpo_retv(sd);
  5288. fd = sd->fd;
  5289. WFIFOHEAD(fd,packet_len(0x2bb));
  5290. WFIFOW(fd,0) = 0x2bb;
  5291. WFIFOW(fd,2) = position;
  5292. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5293. WFIFOSET(fd,packet_len(0x2bb));
  5294. }
  5295. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5296. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5297. void clif_item_refine_list(struct map_session_data *sd)
  5298. {
  5299. int i,c;
  5300. int fd;
  5301. uint16 skill_lv;
  5302. nullpo_retv(sd);
  5303. skill_lv = pc->checkskill(sd,WS_WEAPONREFINE);
  5304. fd=sd->fd;
  5305. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5306. WFIFOW(fd,0)=0x221;
  5307. for (i = c = 0; i < MAX_INVENTORY; i++) {
  5308. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify
  5309. && itemdb_wlv(sd->status.inventory[i].nameid) >= 1
  5310. && !sd->inventory_data[i]->flag.no_refine
  5311. && !(sd->status.inventory[i].equip&EQP_ARMS)){
  5312. WFIFOW(fd,c*13+ 4)=i+2;
  5313. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5314. WFIFOB(fd,c*13+ 8)=sd->status.inventory[i].refine;
  5315. clif->addcards(WFIFOP(fd,c*13+9), &sd->status.inventory[i]);
  5316. c++;
  5317. }
  5318. }
  5319. WFIFOW(fd,2)=c*13+4;
  5320. WFIFOSET(fd,WFIFOW(fd,2));
  5321. if (c > 0) {
  5322. sd->menuskill_id = WS_WEAPONREFINE;
  5323. sd->menuskill_val = skill_lv;
  5324. }
  5325. }
  5326. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5327. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradeable>.B
  5328. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5329. {
  5330. int fd;
  5331. nullpo_retv(sd);
  5332. fd=sd->fd;
  5333. WFIFOHEAD(fd,packet_len(0x147));
  5334. WFIFOW(fd, 0)=0x147;
  5335. WFIFOW(fd, 2)=skill_id;
  5336. WFIFOW(fd, 4)=skill->get_inf(skill_id);
  5337. WFIFOW(fd, 6)=0;
  5338. WFIFOW(fd, 8)=skill_lv;
  5339. WFIFOW(fd,10)=skill->get_sp(skill_id,skill_lv);
  5340. WFIFOW(fd,12)=skill->get_range2(&sd->bl, skill_id,skill_lv);
  5341. safestrncpy((char*)WFIFOP(fd,14),skill->get_name(skill_id),NAME_LENGTH);
  5342. WFIFOB(fd,38)=0;
  5343. WFIFOSET(fd,packet_len(0x147));
  5344. }
  5345. /// Adds an item to character's cart.
  5346. /// 0124 <index>.W <amount>.L <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_CART)
  5347. /// 01c5 <index>.W <amount>.L <name id>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_CART2)
  5348. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5349. {
  5350. int view,fd;
  5351. unsigned char *buf;
  5352. int offset = 0;
  5353. nullpo_retv(sd);
  5354. fd=sd->fd;
  5355. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5356. return;
  5357. WFIFOHEAD(fd,packet_len(cartaddType));
  5358. buf=WFIFOP(fd,0);
  5359. WBUFW(buf,0)=cartaddType;
  5360. WBUFW(buf,2)=n+2;
  5361. WBUFL(buf,4)=amount;
  5362. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5363. WBUFW(buf,8)=view;
  5364. else
  5365. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5366. #if PACKETVER >= 5
  5367. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  5368. offset = 1;
  5369. #endif
  5370. WBUFB(buf,10+offset)=sd->status.cart[n].identify;
  5371. WBUFB(buf,11+offset)=sd->status.cart[n].attribute;
  5372. WBUFB(buf,12+offset)=sd->status.cart[n].refine;
  5373. clif->addcards(WBUFP(buf,13+offset), &sd->status.cart[n]);
  5374. #if PACKETVER >= 20150226
  5375. clif->add_random_options(WBUFP(buf,21+offset), &sd->status.cart[n]);
  5376. #endif
  5377. WFIFOSET(fd,packet_len(cartaddType));
  5378. }
  5379. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  5380. /// 0125 <index>.W <amount>.L
  5381. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5382. {
  5383. int fd;
  5384. nullpo_retv(sd);
  5385. fd=sd->fd;
  5386. WFIFOHEAD(fd,packet_len(0x125));
  5387. WFIFOW(fd,0)=0x125;
  5388. WFIFOW(fd,2)=n+2;
  5389. WFIFOL(fd,4)=amount;
  5390. WFIFOSET(fd,packet_len(0x125));
  5391. }
  5392. /// Opens the shop creation menu (ZC_OPENSTORE).
  5393. /// 012d <num>.W
  5394. /// num:
  5395. /// number of allowed item slots
  5396. void clif_openvendingreq(struct map_session_data* sd, int num)
  5397. {
  5398. int fd;
  5399. nullpo_retv(sd);
  5400. fd = sd->fd;
  5401. WFIFOHEAD(fd,packet_len(0x12d));
  5402. WFIFOW(fd,0) = 0x12d;
  5403. WFIFOW(fd,2) = num;
  5404. WFIFOSET(fd,packet_len(0x12d));
  5405. }
  5406. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  5407. /// 0131 <owner id>.L <message>.80B
  5408. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  5409. {
  5410. unsigned char buf[128];
  5411. nullpo_retv(bl);
  5412. WBUFW(buf,0) = 0x131;
  5413. WBUFL(buf,2) = bl->id;
  5414. safestrncpy((char*)WBUFP(buf,6), message, 80);
  5415. if( fd ) {
  5416. WFIFOHEAD(fd,packet_len(0x131));
  5417. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  5418. WFIFOSET(fd,packet_len(0x131));
  5419. } else {
  5420. clif->send(buf,packet_len(0x131),bl,AREA_WOS);
  5421. }
  5422. }
  5423. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  5424. /// 0132 <owner id>.L
  5425. void clif_closevendingboard(struct block_list* bl, int fd)
  5426. {
  5427. unsigned char buf[16];
  5428. nullpo_retv(bl);
  5429. WBUFW(buf,0) = 0x132;
  5430. WBUFL(buf,2) = bl->id;
  5431. if( fd ) {
  5432. WFIFOHEAD(fd,packet_len(0x132));
  5433. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  5434. WFIFOSET(fd,packet_len(0x132));
  5435. } else {
  5436. clif->send(buf,packet_len(0x132),bl,AREA_WOS);
  5437. }
  5438. }
  5439. /// Sends a list of items in a shop.
  5440. /// R 0133 <packet len>.W <owner id>.L { <price>.L <amount>.W <index>.W <type>.B <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_PC_PURCHASE_ITEMLIST_FROMMC)
  5441. /// R 0800 <packet len>.W <owner id>.L <unique id>.L { <price>.L <amount>.W <index>.W <type>.B <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_PC_PURCHASE_ITEMLIST_FROMMC2)
  5442. void clif_vendinglist(struct map_session_data* sd, unsigned int id, struct s_vending* vending_items) {
  5443. int i,fd;
  5444. int count;
  5445. struct map_session_data* vsd;
  5446. #if PACKETVER < 20100105
  5447. const int cmd = 0x133;
  5448. const int offset = 8;
  5449. #else
  5450. const int cmd = 0x800;
  5451. const int offset = 12;
  5452. #endif
  5453. #if PACKETVER >= 20150226
  5454. const int item_length = 47;
  5455. #else
  5456. const int item_length = 22;
  5457. #endif
  5458. nullpo_retv(sd);
  5459. nullpo_retv(vending_items);
  5460. nullpo_retv(vsd=map->id2sd(id));
  5461. fd = sd->fd;
  5462. count = vsd->vend_num;
  5463. WFIFOHEAD(fd, offset+count*item_length);
  5464. WFIFOW(fd,0) = cmd;
  5465. WFIFOW(fd,2) = offset+count*item_length;
  5466. WFIFOL(fd,4) = id;
  5467. #if PACKETVER >= 20100105
  5468. WFIFOL(fd,8) = vsd->vender_id;
  5469. #endif
  5470. for( i = 0; i < count; i++ ) {
  5471. int index = vending_items[i].index;
  5472. struct item_data* data = itemdb->search(vsd->status.cart[index].nameid);
  5473. WFIFOL(fd,offset+ 0+i*item_length) = vending_items[i].value;
  5474. WFIFOW(fd,offset+ 4+i*item_length) = vending_items[i].amount;
  5475. WFIFOW(fd,offset+ 6+i*item_length) = vending_items[i].index + 2;
  5476. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->type);
  5477. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  5478. WFIFOB(fd,offset+11+i*item_length) = vsd->status.cart[index].identify;
  5479. WFIFOB(fd,offset+12+i*item_length) = vsd->status.cart[index].attribute;
  5480. WFIFOB(fd,offset+13+i*item_length) = vsd->status.cart[index].refine;
  5481. clif->addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->status.cart[index]);
  5482. #if PACKETVER >= 20150226
  5483. clif->add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->status.cart[index]);
  5484. #endif
  5485. }
  5486. WFIFOSET(fd,WFIFOW(fd,2));
  5487. }
  5488. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  5489. /// 0135 <index>.W <amount>.W <result>.B
  5490. /// result:
  5491. /// 0 = success
  5492. /// 1 = not enough zeny
  5493. /// 2 = overweight
  5494. /// 4 = out of stock
  5495. /// 5 = "cannot use an npc shop while in a trade"
  5496. /// 6 = Because the store information was incorrect the item was not purchased.
  5497. /// 7 = No sales information.
  5498. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  5499. {
  5500. int fd;
  5501. nullpo_retv(sd);
  5502. fd = sd->fd;
  5503. WFIFOHEAD(fd,packet_len(0x135));
  5504. WFIFOW(fd,0) = 0x135;
  5505. WFIFOW(fd,2) = index+2;
  5506. WFIFOW(fd,4) = amount;
  5507. WFIFOB(fd,6) = fail;
  5508. WFIFOSET(fd,packet_len(0x135));
  5509. }
  5510. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  5511. /// 0136 <packet len>.W <owner id>.L { <price>.L <index>.W <amount>.W <type>.B <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5512. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending_items) {
  5513. int i,fd;
  5514. int count;
  5515. #if PACKETVER >= 20150226
  5516. const int item_length = 47;
  5517. #else
  5518. const int item_length = 22;
  5519. #endif
  5520. nullpo_retv(sd);
  5521. nullpo_retv(vending_items);
  5522. fd = sd->fd;
  5523. count = sd->vend_num;
  5524. WFIFOHEAD(fd, 8+count*item_length);
  5525. WFIFOW(fd,0) = 0x136;
  5526. WFIFOW(fd,2) = 8+count*item_length;
  5527. WFIFOL(fd,4) = id;
  5528. for( i = 0; i < count; i++ ) {
  5529. int index = vending_items[i].index;
  5530. struct item_data* data = itemdb->search(sd->status.cart[index].nameid);
  5531. WFIFOL(fd, 8+i*item_length) = vending_items[i].value;
  5532. WFIFOW(fd,12+i*item_length) = vending_items[i].index + 2;
  5533. WFIFOW(fd,14+i*item_length) = vending_items[i].amount;
  5534. WFIFOB(fd,16+i*item_length) = itemtype(data->type);
  5535. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5536. WFIFOB(fd,19+i*item_length) = sd->status.cart[index].identify;
  5537. WFIFOB(fd,20+i*item_length) = sd->status.cart[index].attribute;
  5538. WFIFOB(fd,21+i*item_length) = sd->status.cart[index].refine;
  5539. clif->addcards(WFIFOP(fd,22+i*item_length), &sd->status.cart[index]);
  5540. #if PACKETVER >= 20150226
  5541. clif->add_random_options(WFIFOP(fd,30+22+i*item_length), &sd->status.cart[index]);
  5542. #endif
  5543. }
  5544. WFIFOSET(fd,WFIFOW(fd,2));
  5545. #if PACKETVER >= 20141022
  5546. /** should go elsewhere perhaps? it has to be bundled with this however. **/
  5547. WFIFOHEAD(fd, 3);
  5548. WFIFOW(fd, 0) = 0xa28;
  5549. WFIFOB(fd, 2) = 0;/** 1 is failure. our current responses to failure are working so not yet implemented **/
  5550. WFIFOSET(fd, 3);
  5551. #endif
  5552. }
  5553. /// Inform merchant that someone has bought an item (ZC_DELETEITEM_FROM_MCSTORE).
  5554. /// 0137 <index>.W <amount>.W
  5555. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5556. {
  5557. int fd;
  5558. nullpo_retv(sd);
  5559. fd = sd->fd;
  5560. WFIFOHEAD(fd,packet_len(0x137));
  5561. WFIFOW(fd,0) = 0x137;
  5562. WFIFOW(fd,2) = index+2;
  5563. WFIFOW(fd,4) = amount;
  5564. WFIFOSET(fd,packet_len(0x137));
  5565. }
  5566. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  5567. /// 00fa <result>.B
  5568. /// result:
  5569. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  5570. /// 1 = MsgStringTable[78]="party name already exists"
  5571. /// 2 = MsgStringTable[79]="already in a party"
  5572. /// 3 = cannot organize parties on this map
  5573. /// ? = nothing
  5574. void clif_party_created(struct map_session_data *sd,int result)
  5575. {
  5576. int fd;
  5577. nullpo_retv(sd);
  5578. fd=sd->fd;
  5579. WFIFOHEAD(fd,packet_len(0xfa));
  5580. WFIFOW(fd,0)=0xfa;
  5581. WFIFOB(fd,2)=result;
  5582. WFIFOSET(fd,packet_len(0xfa));
  5583. }
  5584. /// Adds new member to a party.
  5585. /// 0104 <account id>.L <role>.L <x>.W <y>.W <state>.B <party name>.24B <char name>.24B <map name>.16B (ZC_ADD_MEMBER_TO_GROUP)
  5586. /// 01e9 <account id>.L <role>.L <x>.W <y>.W <state>.B <party name>.24B <char name>.24B <map name>.16B <item pickup rule>.B <item share rule>.B (ZC_ADD_MEMBER_TO_GROUP2)
  5587. /// role:
  5588. /// 0 = leader
  5589. /// 1 = normal
  5590. /// state:
  5591. /// 0 = connected
  5592. /// 1 = disconnected
  5593. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5594. {
  5595. unsigned char buf[81];
  5596. int i;
  5597. nullpo_retv(p);
  5598. nullpo_retv(sd);
  5599. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5600. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5601. } else {
  5602. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5603. }
  5604. if (i >= MAX_PARTY) return; //Should never happen...
  5605. sd = p->data[i].sd;
  5606. WBUFW(buf, 0) = 0x1e9;
  5607. WBUFL(buf, 2) = sd->status.account_id;
  5608. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5609. WBUFW(buf,10) = sd->bl.x;
  5610. WBUFW(buf,12) = sd->bl.y;
  5611. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5612. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5613. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5614. mapindex->getmapname_ext(map->list[sd->bl.m].custom_name ? map->list[map->list[sd->bl.m].instance_src_map].name : map->list[sd->bl.m].name, (char*)WBUFP(buf,63));
  5615. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5616. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5617. clif->send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5618. }
  5619. /// Sends party information (ZC_GROUP_LIST).
  5620. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  5621. /// role:
  5622. /// 0 = leader
  5623. /// 1 = normal
  5624. /// state:
  5625. /// 0 = connected
  5626. /// 1 = disconnected
  5627. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  5628. {
  5629. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5630. struct map_session_data* party_sd = NULL;
  5631. int i, c;
  5632. nullpo_retv(p);
  5633. WBUFW(buf,0) = 0xfb;
  5634. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5635. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5636. {
  5637. struct party_member* m = &p->party.member[i];
  5638. if(!m->account_id) continue;
  5639. if(party_sd == NULL) party_sd = p->data[i].sd;
  5640. WBUFL(buf,28+c*46) = m->account_id;
  5641. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5642. mapindex->getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5643. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5644. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5645. c++;
  5646. }
  5647. WBUFW(buf,2) = 28+c*46;
  5648. if(sd) { // send only to self
  5649. clif->send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5650. } else if (party_sd) { // send to whole party
  5651. clif->send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5652. }
  5653. }
  5654. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  5655. /// 02c9 <flag>.B
  5656. /// flag:
  5657. /// 0 = allow party invites
  5658. /// 1 = auto-deny party invites
  5659. void clif_partyinvitationstate(struct map_session_data* sd)
  5660. {
  5661. int fd;
  5662. nullpo_retv(sd);
  5663. fd = sd->fd;
  5664. WFIFOHEAD(fd, packet_len(0x2c9));
  5665. WFIFOW(fd, 0) = 0x2c9;
  5666. WFIFOB(fd, 2) = sd->status.allow_party ? 1 : 0;
  5667. WFIFOSET(fd, packet_len(0x2c9));
  5668. }
  5669. /// Party invitation request.
  5670. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  5671. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  5672. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5673. {
  5674. #if PACKETVER < 20070821
  5675. const int cmd = 0xfe;
  5676. #else
  5677. const int cmd = 0x2c6;
  5678. #endif
  5679. int fd;
  5680. struct party_data *p;
  5681. nullpo_retv(sd);
  5682. nullpo_retv(tsd);
  5683. fd=tsd->fd;
  5684. if( (p=party->search(sd->status.party_id))==NULL )
  5685. return;
  5686. WFIFOHEAD(fd,packet_len(cmd));
  5687. WFIFOW(fd,0)=cmd;
  5688. WFIFOL(fd,2)=sd->status.party_id;
  5689. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5690. WFIFOSET(fd,packet_len(cmd));
  5691. }
  5692. /// Party invite result.
  5693. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  5694. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  5695. /// result=0 : char is already in a party -> MsgStringTable[80]
  5696. /// result=1 : party invite was rejected -> MsgStringTable[81]
  5697. /// result=2 : party invite was accepted -> MsgStringTable[82]
  5698. /// result=3 : party is full -> MsgStringTable[83]
  5699. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  5700. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  5701. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  5702. /// result=8 : (%s) TODO instance related? -> MsgStringTable[1388] (since 20080527)
  5703. /// return=9 : TODO map prohibits party joining? -> MsgStringTable[1871] (since 20110205)
  5704. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int result)
  5705. {
  5706. int fd;
  5707. nullpo_retv(sd);
  5708. nullpo_retv(nick);
  5709. fd=sd->fd;
  5710. #if PACKETVER < 20070904
  5711. if( result == 7 ) {
  5712. clif->message(fd, msg_sd(sd,3));
  5713. return;
  5714. }
  5715. #endif
  5716. #if PACKETVER < 20070821
  5717. WFIFOHEAD(fd,packet_len(0xfd));
  5718. WFIFOW(fd,0) = 0xfd;
  5719. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5720. WFIFOB(fd,26) = result;
  5721. WFIFOSET(fd,packet_len(0xfd));
  5722. #else
  5723. WFIFOHEAD(fd,packet_len(0x2c5));
  5724. WFIFOW(fd,0) = 0x2c5;
  5725. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5726. WFIFOL(fd,26) = result;
  5727. WFIFOSET(fd,packet_len(0x2c5));
  5728. #endif
  5729. }
  5730. /// Updates party settings.
  5731. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  5732. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  5733. /// exp option:
  5734. /// 0 = exp sharing disabled
  5735. /// 1 = exp sharing enabled
  5736. /// 2 = cannot change exp sharing
  5737. ///
  5738. /// flag:
  5739. /// 0 = send to party
  5740. /// 1 = send to sd
  5741. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5742. {
  5743. unsigned char buf[16];
  5744. #if PACKETVER < 20090603
  5745. const int cmd = 0x101;
  5746. #else
  5747. const int cmd = 0x7d8;
  5748. #endif
  5749. nullpo_retv(p);
  5750. if(!sd && flag==0){
  5751. int i;
  5752. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++)
  5753. ;
  5754. if (i < MAX_PARTY)
  5755. sd = p->data[i].sd;
  5756. }
  5757. if(!sd) return;
  5758. WBUFW(buf,0)=cmd;
  5759. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  5760. #if PACKETVER >= 20090603
  5761. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5762. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5763. #endif
  5764. if(flag==0)
  5765. clif->send(buf,packet_len(cmd),&sd->bl,PARTY);
  5766. else
  5767. clif->send(buf,packet_len(cmd),&sd->bl,SELF);
  5768. }
  5769. /// 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  5770. /// result:
  5771. /// 0 = leave
  5772. /// 1 = expel
  5773. /// 2 = cannot leave party on this map
  5774. /// 3 = cannot expel from party on this map
  5775. void clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5776. {
  5777. unsigned char buf[64];
  5778. nullpo_retv(p);
  5779. nullpo_retv(name);
  5780. if(!sd && (flag&0xf0)==0) { // TODO: Document this flag
  5781. int i;
  5782. // Search for any online party member
  5783. ARR_FIND(0, MAX_PARTY, i, p->data[i].sd != NULL);
  5784. if (i != MAX_PARTY)
  5785. sd = p->data[i].sd;
  5786. }
  5787. if (!sd)
  5788. return;
  5789. WBUFW(buf,0)=0x105;
  5790. WBUFL(buf,2)=account_id;
  5791. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5792. WBUFB(buf,30)=flag&0x0f;
  5793. if((flag&0xf0)==0)
  5794. clif->send(buf,packet_len(0x105),&sd->bl,PARTY);
  5795. else
  5796. clif->send(buf,packet_len(0x105),&sd->bl,SELF);
  5797. }
  5798. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  5799. /// 0109 <packet len>.W <account id>.L <message>.?B
  5800. void clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5801. {
  5802. struct map_session_data *sd;
  5803. int i;
  5804. nullpo_retv(p);
  5805. nullpo_retv(mes);
  5806. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5807. if(i < MAX_PARTY){
  5808. unsigned char buf[1024];
  5809. if (len > sizeof(buf)-8) {
  5810. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%"PRIuS", party_id=%d).\n",
  5811. mes, len, sizeof(buf)-8, p->party.party_id);
  5812. len = sizeof(buf)-8;
  5813. }
  5814. sd = p->data[i].sd;
  5815. WBUFW(buf,0)=0x109;
  5816. WBUFW(buf,2)=len+8;
  5817. WBUFL(buf,4)=account_id;
  5818. safestrncpy((char *)WBUFP(buf,8), mes, len);
  5819. clif->send(buf,len+8,&sd->bl,PARTY);
  5820. }
  5821. }
  5822. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  5823. /// 0107 <account id>.L <x>.W <y>.W
  5824. void clif_party_xy(struct map_session_data *sd)
  5825. {
  5826. unsigned char buf[16];
  5827. nullpo_retv(sd);
  5828. WBUFW(buf,0)=0x107;
  5829. WBUFL(buf,2)=sd->status.account_id;
  5830. WBUFW(buf,6)=sd->bl.x;
  5831. WBUFW(buf,8)=sd->bl.y;
  5832. clif->send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5833. }
  5834. /*==========================================
  5835. * Sends x/y dot to a single fd. [Skotlex]
  5836. *------------------------------------------*/
  5837. void clif_party_xy_single(int fd, struct map_session_data *sd)
  5838. {
  5839. nullpo_retv(sd);
  5840. WFIFOHEAD(fd,packet_len(0x107));
  5841. WFIFOW(fd,0)=0x107;
  5842. WFIFOL(fd,2)=sd->status.account_id;
  5843. WFIFOW(fd,6)=sd->bl.x;
  5844. WFIFOW(fd,8)=sd->bl.y;
  5845. WFIFOSET(fd,packet_len(0x107));
  5846. }
  5847. /// Updates HP bar of a party member.
  5848. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  5849. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  5850. void clif_party_hp(struct map_session_data *sd)
  5851. {
  5852. unsigned char buf[16];
  5853. #if PACKETVER < 20100126
  5854. const int cmd = 0x106;
  5855. #else
  5856. const int cmd = 0x80e;
  5857. #endif
  5858. nullpo_retv(sd);
  5859. WBUFW(buf,0)=cmd;
  5860. WBUFL(buf,2)=sd->status.account_id;
  5861. #if PACKETVER < 20100126
  5862. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  5863. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5864. WBUFW(buf,8) = 100;
  5865. } else {
  5866. WBUFW(buf,6) = sd->battle_status.hp;
  5867. WBUFW(buf,8) = sd->battle_status.max_hp;
  5868. }
  5869. #else
  5870. WBUFL(buf,6) = sd->battle_status.hp;
  5871. WBUFL(buf,10) = sd->battle_status.max_hp;
  5872. #endif
  5873. clif->send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  5874. }
  5875. /*==========================================
  5876. * Sends HP bar to a single fd. [Skotlex]
  5877. *------------------------------------------*/
  5878. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5879. {
  5880. #if PACKETVER < 20100126
  5881. const int cmd = 0x106;
  5882. #else
  5883. const int cmd = 0x80e;
  5884. #endif
  5885. WFIFOHEAD(fd,packet_len(cmd));
  5886. WFIFOW(fd,0) = cmd;
  5887. WFIFOL(fd,2) = id;
  5888. #if PACKETVER < 20100126
  5889. if( maxhp > INT16_MAX )
  5890. {// To correctly display the %hp bar. [Skotlex]
  5891. WFIFOW(fd,6) = hp/(maxhp/100);
  5892. WFIFOW(fd,8) = 100;
  5893. } else {
  5894. WFIFOW(fd,6) = hp;
  5895. WFIFOW(fd,8) = maxhp;
  5896. }
  5897. #else
  5898. WFIFOL(fd,6) = hp;
  5899. WFIFOL(fd,10) = maxhp;
  5900. #endif
  5901. WFIFOSET(fd, packet_len(cmd));
  5902. }
  5903. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  5904. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  5905. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5906. {
  5907. int fd;
  5908. nullpo_retv(sd);
  5909. nullpo_retv(bl);
  5910. fd=sd->fd;
  5911. WFIFOHEAD(fd,packet_len(0x139));
  5912. WFIFOW(fd, 0)=0x139;
  5913. WFIFOL(fd, 2)=bl->id;
  5914. WFIFOW(fd, 6)=bl->x;
  5915. WFIFOW(fd, 8)=bl->y;
  5916. WFIFOW(fd,10)=sd->bl.x;
  5917. WFIFOW(fd,12)=sd->bl.y;
  5918. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5919. WFIFOSET(fd,packet_len(0x139));
  5920. }
  5921. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  5922. /// 018f <result>.W <name id>.W
  5923. /// result:
  5924. /// 0 = success
  5925. /// 1 = failure
  5926. /// 2 = success (alchemist)
  5927. /// 3 = failure (alchemist)
  5928. void clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5929. {
  5930. int view,fd;
  5931. nullpo_retv(sd);
  5932. fd = sd->fd;
  5933. clif->solved_charname(fd, sd->status.char_id, sd->status.name);
  5934. WFIFOHEAD(fd,packet_len(0x18f));
  5935. WFIFOW(fd, 0)=0x18f;
  5936. WFIFOW(fd, 2)=flag;
  5937. if((view = itemdb_viewid(nameid)) > 0)
  5938. WFIFOW(fd, 4)=view;
  5939. else
  5940. WFIFOW(fd, 4)=nameid;
  5941. WFIFOSET(fd,packet_len(0x18f));
  5942. }
  5943. /// Initiates the pet taming process (ZC_START_CAPTURE).
  5944. /// 019e
  5945. void clif_catch_process(struct map_session_data *sd)
  5946. {
  5947. int fd;
  5948. nullpo_retv(sd);
  5949. fd=sd->fd;
  5950. WFIFOHEAD(fd,packet_len(0x19e));
  5951. WFIFOW(fd,0)=0x19e;
  5952. WFIFOSET(fd,packet_len(0x19e));
  5953. }
  5954. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  5955. /// 01a0 <result>.B
  5956. /// 0 = failure
  5957. /// 1 = success
  5958. void clif_pet_roulette(struct map_session_data *sd,int data)
  5959. {
  5960. int fd;
  5961. nullpo_retv(sd);
  5962. fd=sd->fd;
  5963. WFIFOHEAD(fd,packet_len(0x1a0));
  5964. WFIFOW(fd,0)=0x1a0;
  5965. WFIFOB(fd,2)=data;
  5966. WFIFOSET(fd,packet_len(0x1a0));
  5967. }
  5968. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  5969. /// 01a6 <packet len>.W { <index>.W }*
  5970. void clif_sendegg(struct map_session_data *sd) {
  5971. int i, n, fd;
  5972. nullpo_retv(sd);
  5973. fd = sd->fd;
  5974. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5975. clif->message(fd, msg_sd(sd, 866)); // "Pets are not allowed in Guild Wars."
  5976. return;
  5977. }
  5978. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5979. WFIFOW(fd,0) = 0x1a6;
  5980. for (i = n = 0; i < MAX_INVENTORY; i++) {
  5981. if (sd->status.inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL || sd->inventory_data[i]->type!=IT_PETEGG || sd->status.inventory[i].amount <= 0)
  5982. continue;
  5983. WFIFOW(fd, n * 2 + 4) = i + 2;
  5984. n++;
  5985. }
  5986. if (!n) return;
  5987. WFIFOW(fd, 2) = 4 + n * 2;
  5988. WFIFOSET(fd, WFIFOW(fd, 2));
  5989. sd->menuskill_id = SA_TAMINGMONSTER;
  5990. sd->menuskill_val = -1;
  5991. }
  5992. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  5993. /// 01a4 <type>.B <id>.L <data>.L
  5994. /// type:
  5995. /// 0 = pre-init (data = 0)
  5996. /// 1 = intimacy (data = 0~4)
  5997. /// 2 = hunger (data = 0~4)
  5998. /// 3 = accessory
  5999. /// 4 = performance (data = 1~3: normal, 4: special)
  6000. /// 5 = hairstyle
  6001. ///
  6002. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6003. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6004. {
  6005. uint8 buf[16];
  6006. nullpo_retv(pd);
  6007. WBUFW(buf,0) = 0x1a4;
  6008. WBUFB(buf,2) = type;
  6009. WBUFL(buf,3) = pd->bl.id;
  6010. WBUFL(buf,7) = param;
  6011. if (sd)
  6012. clif->send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6013. else
  6014. clif->send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6015. }
  6016. /// Pet's base data (ZC_PROPERTY_PET).
  6017. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6018. void clif_send_petstatus(struct map_session_data *sd)
  6019. {
  6020. int fd;
  6021. struct s_pet *p;
  6022. nullpo_retv(sd);
  6023. nullpo_retv(sd->pd);
  6024. fd=sd->fd;
  6025. p = &sd->pd->pet;
  6026. WFIFOHEAD(fd,packet_len(0x1a2));
  6027. WFIFOW(fd,0)=0x1a2;
  6028. memcpy(WFIFOP(fd,2),p->name,NAME_LENGTH);
  6029. WFIFOB(fd,26)=battle_config.pet_rename?0:p->rename_flag;
  6030. WFIFOW(fd,27)=p->level;
  6031. WFIFOW(fd,29)=p->hungry;
  6032. WFIFOW(fd,31)=p->intimate;
  6033. WFIFOW(fd,33)=p->equip;
  6034. #if PACKETVER >= 20081126
  6035. WFIFOW(fd,35)=p->class_;
  6036. #endif
  6037. WFIFOSET(fd,packet_len(0x1a2));
  6038. }
  6039. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6040. /// 01aa <id>.L <data>.L
  6041. /// data:
  6042. /// @see CZ_PET_ACT.
  6043. void clif_pet_emotion(struct pet_data *pd,int param)
  6044. {
  6045. unsigned char buf[16];
  6046. nullpo_retv(pd);
  6047. memset(buf,0,packet_len(0x1aa));
  6048. WBUFW(buf,0)=0x1aa;
  6049. WBUFL(buf,2)=pd->bl.id;
  6050. if(param >= 100 && pd->petDB->talk_convert_class) {
  6051. if(pd->petDB->talk_convert_class < 0)
  6052. return;
  6053. else if(pd->petDB->talk_convert_class > 0) {
  6054. // replace mob_id component of talk/act data
  6055. param -= (pd->pet.class_ - 100)*100;
  6056. param += (pd->petDB->talk_convert_class - 100)*100;
  6057. }
  6058. }
  6059. WBUFL(buf,6)=param;
  6060. clif->send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6061. }
  6062. /// Result of request to feed a pet (ZC_FEED_PET).
  6063. /// 01a3 <result>.B <name id>.W
  6064. /// result:
  6065. /// 0 = failure
  6066. /// 1 = success
  6067. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6068. {
  6069. int fd;
  6070. nullpo_retv(sd);
  6071. fd=sd->fd;
  6072. WFIFOHEAD(fd,packet_len(0x1a3));
  6073. WFIFOW(fd,0)=0x1a3;
  6074. WFIFOB(fd,2)=fail;
  6075. WFIFOW(fd,3)=foodid;
  6076. WFIFOSET(fd,packet_len(0x1a3));
  6077. }
  6078. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6079. /// 01cd { <skill id>.L }*7
  6080. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6081. {
  6082. int fd;
  6083. nullpo_retv(sd);
  6084. fd=sd->fd;
  6085. WFIFOHEAD(fd,packet_len(0x1cd));
  6086. WFIFOW(fd, 0)=0x1cd;
  6087. if(skill_lv>0 && pc->checkskill(sd,MG_NAPALMBEAT)>0)
  6088. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6089. else
  6090. WFIFOL(fd,2)= 0x00000000;
  6091. if(skill_lv>1 && pc->checkskill(sd,MG_COLDBOLT)>0)
  6092. WFIFOL(fd,6)= MG_COLDBOLT;
  6093. else
  6094. WFIFOL(fd,6)= 0x00000000;
  6095. if(skill_lv>1 && pc->checkskill(sd,MG_FIREBOLT)>0)
  6096. WFIFOL(fd,10)= MG_FIREBOLT;
  6097. else
  6098. WFIFOL(fd,10)= 0x00000000;
  6099. if(skill_lv>1 && pc->checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6100. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6101. else
  6102. WFIFOL(fd,14)= 0x00000000;
  6103. if(skill_lv>4 && pc->checkskill(sd,MG_SOULSTRIKE)>0)
  6104. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6105. else
  6106. WFIFOL(fd,18)= 0x00000000;
  6107. if(skill_lv>7 && pc->checkskill(sd,MG_FIREBALL)>0)
  6108. WFIFOL(fd,22)= MG_FIREBALL;
  6109. else
  6110. WFIFOL(fd,22)= 0x00000000;
  6111. if(skill_lv>9 && pc->checkskill(sd,MG_FROSTDIVER)>0)
  6112. WFIFOL(fd,26)= MG_FROSTDIVER;
  6113. else
  6114. WFIFOL(fd,26)= 0x00000000;
  6115. WFIFOSET(fd,packet_len(0x1cd));
  6116. sd->menuskill_id = SA_AUTOSPELL;
  6117. sd->menuskill_val = skill_lv;
  6118. }
  6119. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6120. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6121. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6122. {
  6123. unsigned char buf[56];
  6124. nullpo_retv(src);
  6125. memset(buf,0,packet_len(0x1cf));
  6126. WBUFW(buf,0) = 0x1cf;
  6127. WBUFL(buf,2) = src->id;
  6128. if( src->type == BL_MER )
  6129. {
  6130. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6131. if( md && md->master && md->devotion_flag )
  6132. WBUFL(buf,6) = md->master->bl.id;
  6133. WBUFW(buf,26) = skill->get_range2(src, ML_DEVOTION, mercenary->checkskill(md, ML_DEVOTION));
  6134. }
  6135. else
  6136. {
  6137. int i;
  6138. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6139. if( sd == NULL )
  6140. return;
  6141. for( i = 0; i < MAX_PC_DEVOTION; i++ )
  6142. WBUFL(buf,6+4*i) = sd->devotion[i];
  6143. WBUFW(buf,26) = skill->get_range2(src, CR_DEVOTION, pc->checkskill(sd, CR_DEVOTION));
  6144. }
  6145. if( tsd )
  6146. clif->send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6147. else
  6148. clif->send(buf, packet_len(0x1cf), src, AREA);
  6149. }
  6150. /*==========================================
  6151. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6152. * Notifies clients in an area of an object's spirits.
  6153. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6154. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6155. *------------------------------------------*/
  6156. void clif_spiritball(struct block_list *bl) {
  6157. unsigned char buf[16];
  6158. struct map_session_data *sd = BL_CAST(BL_PC,bl);
  6159. struct homun_data *hd = BL_CAST(BL_HOM,bl);
  6160. nullpo_retv(bl);
  6161. WBUFW(buf, 0) = 0x1d0;
  6162. WBUFL(buf, 2) = bl->id;
  6163. WBUFW(buf, 6) = 0; //init to 0
  6164. switch(bl->type){
  6165. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6166. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6167. }
  6168. clif->send(buf, packet_len(0x1d0), bl, AREA);
  6169. }
  6170. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6171. /// 01d2 <account id>.L <delay>.L
  6172. void clif_combo_delay(struct block_list *bl,int wait)
  6173. {
  6174. unsigned char buf[32];
  6175. nullpo_retv(bl);
  6176. WBUFW(buf,0)=0x1d2;
  6177. WBUFL(buf,2)=bl->id;
  6178. WBUFL(buf,6)=wait;
  6179. clif->send(buf,packet_len(0x1d2),bl,AREA);
  6180. }
  6181. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6182. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6183. /// flag:
  6184. /// 0 = inactive
  6185. /// 1 = active
  6186. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6187. {
  6188. unsigned char buf[32];
  6189. nullpo_retv(src);
  6190. WBUFW(buf,0)=0x1d1;
  6191. WBUFL(buf,2)=src->id;
  6192. WBUFL(buf,6)=dst_id;
  6193. WBUFL(buf,10)=active;
  6194. clif->send(buf,packet_len(0x1d1),src,AREA);
  6195. }
  6196. /// MVP effect (ZC_MVP).
  6197. /// 010c <account id>.L
  6198. void clif_mvp_effect(struct map_session_data *sd)
  6199. {
  6200. unsigned char buf[16];
  6201. nullpo_retv(sd);
  6202. WBUFW(buf,0)=0x10c;
  6203. WBUFL(buf,2)=sd->bl.id;
  6204. clif->send(buf,packet_len(0x10c),&sd->bl,AREA);
  6205. }
  6206. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  6207. /// 010a <name id>.W
  6208. void clif_mvp_item(struct map_session_data *sd,int nameid)
  6209. {
  6210. int view,fd;
  6211. nullpo_retv(sd);
  6212. fd=sd->fd;
  6213. WFIFOHEAD(fd,packet_len(0x10a));
  6214. WFIFOW(fd,0)=0x10a;
  6215. if((view = itemdb_viewid(nameid)) > 0)
  6216. WFIFOW(fd,2)=view;
  6217. else
  6218. WFIFOW(fd,2)=nameid;
  6219. WFIFOSET(fd,packet_len(0x10a));
  6220. }
  6221. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  6222. /// 010b <exp>.L
  6223. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  6224. {
  6225. int fd;
  6226. nullpo_retv(sd);
  6227. fd=sd->fd;
  6228. WFIFOHEAD(fd,packet_len(0x10b));
  6229. WFIFOW(fd,0)=0x10b;
  6230. WFIFOL(fd,2)=cap_value(exp,0,INT32_MAX);
  6231. WFIFOSET(fd,packet_len(0x10b));
  6232. }
  6233. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  6234. /// 010d
  6235. ///
  6236. /// "You are the MVP, but cannot obtain the reward because
  6237. /// you are overweight."
  6238. void clif_mvp_noitem(struct map_session_data* sd)
  6239. {
  6240. int fd = sd->fd;
  6241. WFIFOHEAD(fd,packet_len(0x10d));
  6242. WFIFOW(fd,0) = 0x10d;
  6243. WFIFOSET(fd,packet_len(0x10d));
  6244. }
  6245. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  6246. /// 0167 <result>.B
  6247. /// result:
  6248. /// 0 = "Guild has been created."
  6249. /// 1 = "You are already in a Guild."
  6250. /// 2 = "That Guild Name already exists."
  6251. /// 3 = "You need the necessary item to create a Guild."
  6252. void clif_guild_created(struct map_session_data *sd,int flag)
  6253. {
  6254. int fd;
  6255. nullpo_retv(sd);
  6256. fd=sd->fd;
  6257. WFIFOHEAD(fd,packet_len(0x167));
  6258. WFIFOW(fd,0)=0x167;
  6259. WFIFOB(fd,2)=flag;
  6260. WFIFOSET(fd,packet_len(0x167));
  6261. }
  6262. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  6263. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  6264. /// mode: @see enum guild_permission
  6265. void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  6266. {
  6267. int ps,fd;
  6268. nullpo_retv(sd);
  6269. nullpo_retv(g);
  6270. fd=sd->fd;
  6271. ps=guild->getposition(g,sd);
  6272. WFIFOHEAD(fd,packet_len(0x16c));
  6273. WFIFOW(fd,0)=0x16c;
  6274. WFIFOL(fd,2)=g->guild_id;
  6275. WFIFOL(fd,6)=g->emblem_id;
  6276. WFIFOL(fd,10)=g->position[ps].mode;
  6277. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag == 1);
  6278. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  6279. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6280. WFIFOSET(fd,packet_len(0x16c));
  6281. }
  6282. /// Guild member login notice.
  6283. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  6284. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  6285. /// status:
  6286. /// 0 = offline
  6287. /// 1 = online
  6288. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6289. {
  6290. unsigned char buf[64];
  6291. struct map_session_data* sd;
  6292. nullpo_retv(g);
  6293. WBUFW(buf, 0)=0x1f2;
  6294. WBUFL(buf, 2)=g->member[idx].account_id;
  6295. WBUFL(buf, 6)=g->member[idx].char_id;
  6296. WBUFL(buf,10)=flag;
  6297. if( ( sd = g->member[idx].sd ) != NULL )
  6298. {
  6299. WBUFW(buf,14) = sd->status.sex;
  6300. WBUFW(buf,16) = sd->status.hair;
  6301. WBUFW(buf,18) = sd->status.hair_color;
  6302. clif->send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  6303. }
  6304. else if( ( sd = guild->getavailablesd(g) ) != NULL )
  6305. {
  6306. WBUFW(buf,14) = 0;
  6307. WBUFW(buf,16) = 0;
  6308. WBUFW(buf,18) = 0;
  6309. clif->send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  6310. }
  6311. }
  6312. // Function `clif_guild_memberlogin_notice` sends info about
  6313. // logins and logouts of a guild member to the rest members.
  6314. // But at the 1st time (after a player login or map changing)
  6315. // the client won't show the message.
  6316. // So I suggest use this function for sending "first-time-info"
  6317. // to some player on entering the game or changing location.
  6318. // At next time the client would always show the message.
  6319. // The function sends all the statuses in the single packet
  6320. // to economize traffic. [LuzZza]
  6321. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  6322. {
  6323. struct guild *g;
  6324. unsigned char buf[14*128];
  6325. int i, count=0, p_len;
  6326. nullpo_retv(sd);
  6327. p_len = packet_len(0x16d);
  6328. if(!(g = sd->guild))
  6329. return;
  6330. for(i=0; i<g->max_member; i++) {
  6331. if(g->member[i].account_id > 0 &&
  6332. g->member[i].account_id != sd->status.account_id) {
  6333. WBUFW(buf,count*p_len) = 0x16d;
  6334. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  6335. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  6336. WBUFL(buf,count*p_len+10) = g->member[i].online;
  6337. count++;
  6338. }
  6339. }
  6340. clif->send(buf, p_len*count, &sd->bl, SELF);
  6341. }
  6342. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  6343. /// 014e <menu flag>.L
  6344. /// menu flag:
  6345. /// 0x00 = Basic Info (always on)
  6346. /// &0x01 = Member manager
  6347. /// &0x02 = Positions
  6348. /// &0x04 = Skills
  6349. /// &0x10 = Expulsion list
  6350. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  6351. /// &0x80 = Notice
  6352. void clif_guild_masterormember(struct map_session_data *sd)
  6353. {
  6354. int fd;
  6355. nullpo_retv(sd);
  6356. fd=sd->fd;
  6357. WFIFOHEAD(fd,packet_len(0x14e));
  6358. WFIFOW(fd,0) = 0x14e;
  6359. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  6360. WFIFOSET(fd,packet_len(0x14e));
  6361. }
  6362. /// Guild basic information (Territories [Valaris])
  6363. /// 0150 <guild id>.L <level>.L <member num>.L <member max>.L <exp>.L <max exp>.L <points>.L <honor>.L <virtue>.L <emblem id>.L <name>.24B <master name>.24B <manage land>.16B (ZC_GUILD_INFO)
  6364. /// 01b6 <guild id>.L <level>.L <member num>.L <member max>.L <exp>.L <max exp>.L <points>.L <honor>.L <virtue>.L <emblem id>.L <name>.24B <master name>.24B <manage land>.16B <zeny>.L (ZC_GUILD_INFO2)
  6365. void clif_guild_basicinfo(struct map_session_data *sd) {
  6366. int fd;
  6367. struct guild *g;
  6368. nullpo_retv(sd);
  6369. fd = sd->fd;
  6370. if( (g = sd->guild) == NULL )
  6371. return;
  6372. WFIFOHEAD(fd,packet_len(0x1b6));
  6373. WFIFOW(fd, 0)=0x1b6;//0x150;
  6374. WFIFOL(fd, 2)=g->guild_id;
  6375. WFIFOL(fd, 6)=g->guild_lv;
  6376. WFIFOL(fd,10)=g->connect_member;
  6377. WFIFOL(fd,14)=g->max_member;
  6378. WFIFOL(fd,18)=g->average_lv;
  6379. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  6380. WFIFOL(fd,26)=g->next_exp;
  6381. WFIFOL(fd,30)=0; // Tax Points
  6382. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  6383. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  6384. WFIFOL(fd,42)=g->emblem_id;
  6385. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6386. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6387. safestrncpy((char*)WFIFOP(fd,94),msg_sd(sd,300+guild->checkcastles(g)),16); // "'N' castles"
  6388. WFIFOL(fd,110) = 0; // zeny
  6389. WFIFOSET(fd,packet_len(0x1b6));
  6390. }
  6391. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  6392. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  6393. void clif_guild_allianceinfo(struct map_session_data *sd)
  6394. {
  6395. int fd,i,c;
  6396. struct guild *g;
  6397. nullpo_retv(sd);
  6398. if( (g = sd->guild) == NULL )
  6399. return;
  6400. fd = sd->fd;
  6401. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6402. WFIFOW(fd, 0)=0x14c;
  6403. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6404. struct guild_alliance *a=&g->alliance[i];
  6405. if(a->guild_id>0){
  6406. WFIFOL(fd,c*32+4)=a->opposition;
  6407. WFIFOL(fd,c*32+8)=a->guild_id;
  6408. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6409. c++;
  6410. }
  6411. }
  6412. WFIFOW(fd, 2)=c*32+4;
  6413. WFIFOSET(fd,WFIFOW(fd,2));
  6414. }
  6415. /// Guild member manager information (ZC_MEMBERMGR_INFO).
  6416. /// 0154 <packet len>.W { <account>.L <char id>.L <hair style>.W <hair color>.W <gender>.W <class>.W <level>.W <contrib exp>.L <state>.L <position>.L <memo>.50B <name>.24B }*
  6417. /// state:
  6418. /// 0 = offline
  6419. /// 1 = online
  6420. /// memo:
  6421. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  6422. void clif_guild_memberlist(struct map_session_data *sd)
  6423. {
  6424. int fd;
  6425. int i,c;
  6426. struct guild *g;
  6427. nullpo_retv(sd);
  6428. if( (fd = sd->fd) == 0 )
  6429. return;
  6430. if( (g = sd->guild) == NULL )
  6431. return;
  6432. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6433. WFIFOW(fd, 0)=0x154;
  6434. for(i=0,c=0;i<g->max_member;i++){
  6435. struct guild_member *m=&g->member[i];
  6436. if(m->account_id==0)
  6437. continue;
  6438. WFIFOL(fd,c*104+ 4)=m->account_id;
  6439. WFIFOL(fd,c*104+ 8)=m->char_id;
  6440. WFIFOW(fd,c*104+12)=m->hair;
  6441. WFIFOW(fd,c*104+14)=m->hair_color;
  6442. WFIFOW(fd,c*104+16)=m->gender;
  6443. WFIFOW(fd,c*104+18)=m->class_;
  6444. WFIFOW(fd,c*104+20)=m->lv;
  6445. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT32_MAX);
  6446. WFIFOL(fd,c*104+26)=m->online;
  6447. WFIFOL(fd,c*104+30)=m->position;
  6448. memset(WFIFOP(fd,c*104+34),0,50); //[Ind] - This is displayed in the 'note' column but being you can't edit it it's sent empty.
  6449. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6450. c++;
  6451. }
  6452. WFIFOW(fd, 2)=c*104+4;
  6453. WFIFOSET(fd,WFIFOW(fd,2));
  6454. }
  6455. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  6456. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  6457. void clif_guild_positionnamelist(struct map_session_data *sd) {
  6458. int i,fd;
  6459. struct guild *g;
  6460. nullpo_retv(sd);
  6461. if( (g = sd->guild) == NULL )
  6462. return;
  6463. fd = sd->fd;
  6464. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6465. WFIFOW(fd, 0)=0x166;
  6466. for(i=0;i<MAX_GUILDPOSITION;i++){
  6467. WFIFOL(fd,i*28+4)=i;
  6468. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6469. }
  6470. WFIFOW(fd,2)=i*28+4;
  6471. WFIFOSET(fd,WFIFOW(fd,2));
  6472. }
  6473. /// Guild position information (ZC_POSITION_INFO).
  6474. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  6475. /// mode: @see enum guild_permission
  6476. /// ranking:
  6477. /// TODO
  6478. void clif_guild_positioninfolist(struct map_session_data *sd) {
  6479. int i,fd;
  6480. struct guild *g;
  6481. nullpo_retv(sd);
  6482. if( (g = sd->guild) == NULL )
  6483. return;
  6484. fd = sd->fd;
  6485. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6486. WFIFOW(fd, 0)=0x160;
  6487. for(i=0;i<MAX_GUILDPOSITION;i++){
  6488. struct guild_position *p=&g->position[i];
  6489. WFIFOL(fd,i*16+ 4)=i;
  6490. WFIFOL(fd,i*16+ 8)=p->mode;
  6491. WFIFOL(fd,i*16+12)=i;
  6492. WFIFOL(fd,i*16+16)=p->exp_mode;
  6493. }
  6494. WFIFOW(fd, 2)=i*16+4;
  6495. WFIFOSET(fd,WFIFOW(fd,2));
  6496. }
  6497. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  6498. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  6499. /// mode: @see enum guild_permission
  6500. /// ranking:
  6501. /// TODO
  6502. void clif_guild_positionchanged(struct guild *g,int idx)
  6503. {
  6504. // FIXME: This packet is intended to update the clients after a
  6505. // commit of position info changes, not sending one packet per
  6506. // position.
  6507. struct map_session_data *sd;
  6508. unsigned char buf[128];
  6509. nullpo_retv(g);
  6510. WBUFW(buf, 0)=0x174;
  6511. WBUFW(buf, 2)=44; // packet len
  6512. // GUILD_REG_POSITION_INFO{
  6513. WBUFL(buf, 4)=idx;
  6514. WBUFL(buf, 8)=g->position[idx].mode;
  6515. WBUFL(buf,12)=idx;
  6516. WBUFL(buf,16)=g->position[idx].exp_mode;
  6517. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6518. // }*
  6519. if( (sd=guild->getavailablesd(g))!=NULL )
  6520. clif->send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6521. }
  6522. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  6523. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  6524. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  6525. {
  6526. // FIXME: This packet is intended to update the clients after a
  6527. // commit of member position assignment changes, not sending one
  6528. // packet per position.
  6529. struct map_session_data *sd;
  6530. unsigned char buf[64];
  6531. nullpo_retv(g);
  6532. WBUFW(buf, 0)=0x156;
  6533. WBUFW(buf, 2)=16; // packet len
  6534. // MEMBER_POSITION_INFO{
  6535. WBUFL(buf, 4)=g->member[idx].account_id;
  6536. WBUFL(buf, 8)=g->member[idx].char_id;
  6537. WBUFL(buf,12)=g->member[idx].position;
  6538. // }*
  6539. if( (sd=guild->getavailablesd(g))!=NULL )
  6540. clif->send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6541. }
  6542. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  6543. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  6544. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6545. {
  6546. int fd;
  6547. nullpo_retv(sd);
  6548. nullpo_retv(g);
  6549. fd = sd->fd;
  6550. if( g->emblem_len <= 0 )
  6551. return;
  6552. WFIFOHEAD(fd,g->emblem_len+12);
  6553. WFIFOW(fd,0)=0x152;
  6554. WFIFOW(fd,2)=g->emblem_len+12;
  6555. WFIFOL(fd,4)=g->guild_id;
  6556. WFIFOL(fd,8)=g->emblem_id;
  6557. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6558. WFIFOSET(fd,WFIFOW(fd,2));
  6559. }
  6560. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  6561. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  6562. void clif_guild_emblem_area(struct block_list* bl)
  6563. {
  6564. uint8 buf[12];
  6565. nullpo_retv(bl);
  6566. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6567. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6568. WBUFW(buf,0) = 0x1b4;
  6569. WBUFL(buf,2) = bl->id;
  6570. WBUFL(buf,6) = status->get_guild_id(bl);
  6571. WBUFW(buf,10) = status->get_emblem_id(bl);
  6572. clif->send(buf, 12, bl, AREA_WOS);
  6573. }
  6574. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  6575. /// 0162 <packet len>.W <skill points>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradeable>.B }*
  6576. void clif_guild_skillinfo(struct map_session_data* sd)
  6577. {
  6578. int fd;
  6579. struct guild* g;
  6580. int i,c;
  6581. nullpo_retv(sd);
  6582. if( (g = sd->guild) == NULL )
  6583. return;
  6584. fd = sd->fd;
  6585. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6586. WFIFOW(fd,0) = 0x0162;
  6587. WFIFOW(fd,4) = g->skill_point;
  6588. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++) {
  6589. if(g->skill[i].id > 0 && guild->check_skill_require(g, g->skill[i].id)) {
  6590. int id = g->skill[i].id;
  6591. int p = 6 + c*37;
  6592. WFIFOW(fd,p+0) = id;
  6593. WFIFOL(fd,p+2) = skill->get_inf(id);
  6594. WFIFOW(fd,p+6) = g->skill[i].lv;
  6595. if ( g->skill[i].lv ) {
  6596. WFIFOW(fd, p + 8) = skill->get_sp(id, g->skill[i].lv);
  6597. WFIFOW(fd, p + 10) = skill->get_range(id, g->skill[i].lv);
  6598. } else {
  6599. WFIFOW(fd, p + 8) = 0;
  6600. WFIFOW(fd, p + 10) = 0;
  6601. }
  6602. safestrncpy((char*)WFIFOP(fd,p+12), skill->get_name(id), NAME_LENGTH);
  6603. WFIFOB(fd,p+36)= (g->skill[i].lv < guild->skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6604. c++;
  6605. }
  6606. }
  6607. WFIFOW(fd,2) = 6 + c*37;
  6608. WFIFOSET(fd,WFIFOW(fd,2));
  6609. }
  6610. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  6611. /// 016f <subject>.60B <notice>.120B
  6612. void clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6613. {
  6614. int fd;
  6615. nullpo_retv(sd);
  6616. nullpo_retv(g);
  6617. fd = sd->fd;
  6618. if (!sockt->session_is_active(fd))
  6619. return;
  6620. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6621. return;
  6622. WFIFOHEAD(fd,packet_len(0x16f));
  6623. WFIFOW(fd,0) = 0x16f;
  6624. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6625. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6626. WFIFOSET(fd,packet_len(0x16f));
  6627. }
  6628. /// Guild invite (ZC_REQ_JOIN_GUILD).
  6629. /// 016a <guild id>.L <guild name>.24B
  6630. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6631. {
  6632. int fd;
  6633. nullpo_retv(sd);
  6634. nullpo_retv(g);
  6635. fd=sd->fd;
  6636. WFIFOHEAD(fd,packet_len(0x16a));
  6637. WFIFOW(fd,0)=0x16a;
  6638. WFIFOL(fd,2)=g->guild_id;
  6639. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6640. WFIFOSET(fd,packet_len(0x16a));
  6641. }
  6642. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  6643. /// 0169 <answer>.B
  6644. /// answer:
  6645. /// 0 = Already in guild.
  6646. /// 1 = Offer rejected.
  6647. /// 2 = Offer accepted.
  6648. /// 3 = Guild full.
  6649. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  6650. {
  6651. int fd;
  6652. nullpo_retv(sd);
  6653. fd=sd->fd;
  6654. WFIFOHEAD(fd,packet_len(0x169));
  6655. WFIFOW(fd,0)=0x169;
  6656. WFIFOB(fd,2)=flag;
  6657. WFIFOSET(fd,packet_len(0x169));
  6658. }
  6659. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  6660. /// 015a <char name>.24B <reason>.40B
  6661. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6662. {
  6663. unsigned char buf[128];
  6664. nullpo_retv(sd);
  6665. WBUFW(buf, 0)=0x15a;
  6666. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6667. memcpy(WBUFP(buf,26),mes,40);
  6668. clif->send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6669. }
  6670. /// Notifies clients of a guild of an expelled member.
  6671. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  6672. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  6673. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, int account_id)
  6674. {
  6675. unsigned char buf[128];
  6676. #if PACKETVER < 20100803
  6677. const unsigned short cmd = 0x15c;
  6678. #else
  6679. const unsigned short cmd = 0x839;
  6680. #endif
  6681. nullpo_retv(sd);
  6682. nullpo_retv(name);
  6683. nullpo_retv(mes);
  6684. WBUFW(buf,0) = cmd;
  6685. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6686. safestrncpy((char*)WBUFP(buf,26), mes, 40);
  6687. #if PACKETVER < 20100803
  6688. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  6689. #endif
  6690. clif->send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  6691. }
  6692. /// Guild expulsion list (ZC_BAN_LIST).
  6693. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  6694. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  6695. void clif_guild_expulsionlist(struct map_session_data* sd) {
  6696. #if PACKETVER < 20100803
  6697. const int offset = NAME_LENGTH*2+40;
  6698. #else
  6699. const int offset = NAME_LENGTH+40;
  6700. #endif
  6701. int fd, i, c = 0;
  6702. struct guild* g;
  6703. nullpo_retv(sd);
  6704. if( (g = sd->guild) == NULL )
  6705. return;
  6706. fd = sd->fd;
  6707. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  6708. WFIFOW(fd,0) = 0x163;
  6709. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  6710. {
  6711. struct guild_expulsion* e = &g->expulsion[i];
  6712. if( e->account_id > 0 )
  6713. {
  6714. memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
  6715. #if PACKETVER < 20100803
  6716. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  6717. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  6718. #else
  6719. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  6720. #endif
  6721. c++;
  6722. }
  6723. }
  6724. WFIFOW(fd,2) = 4 + c*offset;
  6725. WFIFOSET(fd,WFIFOW(fd,2));
  6726. }
  6727. /// Guild chat message (ZC_GUILD_CHAT).
  6728. /// 017f <packet len>.W <message>.?B
  6729. void clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6730. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  6731. struct map_session_data *sd;
  6732. uint8 buf[256];
  6733. nullpo_retv(mes);
  6734. if (len == 0)
  6735. return;
  6736. if (len > sizeof(buf)-5) {
  6737. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%"PRIuS", guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  6738. len = sizeof(buf)-5;
  6739. }
  6740. WBUFW(buf, 0) = 0x17f;
  6741. WBUFW(buf, 2) = len + 5;
  6742. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6743. if ((sd = guild->getavailablesd(g)) != NULL)
  6744. clif->send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6745. }
  6746. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  6747. /// 0171 <inviter account id>.L <guild name>.24B
  6748. void clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6749. {
  6750. int fd;
  6751. nullpo_retv(sd);
  6752. nullpo_retv(name);
  6753. fd=sd->fd;
  6754. WFIFOHEAD(fd,packet_len(0x171));
  6755. WFIFOW(fd,0)=0x171;
  6756. WFIFOL(fd,2)=account_id;
  6757. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6758. WFIFOSET(fd,packet_len(0x171));
  6759. }
  6760. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  6761. /// 0173 <answer>.B
  6762. /// answer:
  6763. /// 0 = Already allied.
  6764. /// 1 = You rejected the offer.
  6765. /// 2 = You accepted the offer.
  6766. /// 3 = They have too any alliances.
  6767. /// 4 = You have too many alliances.
  6768. /// 5 = Alliances are disabled.
  6769. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  6770. {
  6771. int fd;
  6772. nullpo_retv(sd);
  6773. fd=sd->fd;
  6774. WFIFOHEAD(fd,packet_len(0x173));
  6775. WFIFOW(fd,0)=0x173;
  6776. WFIFOL(fd,2)=flag;
  6777. WFIFOSET(fd,packet_len(0x173));
  6778. }
  6779. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  6780. /// 0184 <other guild id>.L <relation>.L
  6781. /// relation:
  6782. /// 0 = Ally
  6783. /// 1 = Enemy
  6784. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6785. {
  6786. int fd;
  6787. nullpo_retv(sd);
  6788. fd = sd->fd;
  6789. if (fd <= 0)
  6790. return;
  6791. WFIFOHEAD(fd,packet_len(0x184));
  6792. WFIFOW(fd,0)=0x184;
  6793. WFIFOL(fd,2)=guild_id;
  6794. WFIFOL(fd,6)=flag;
  6795. WFIFOSET(fd,packet_len(0x184));
  6796. }
  6797. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  6798. /// 0181 <result>.B
  6799. /// result:
  6800. /// 0 = Antagonist has been set.
  6801. /// 1 = Guild has too many Antagonists.
  6802. /// 2 = Already set as an Antagonist.
  6803. /// 3 = Antagonists are disabled.
  6804. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6805. {
  6806. int fd;
  6807. nullpo_retv(sd);
  6808. fd=sd->fd;
  6809. WFIFOHEAD(fd,packet_len(0x181));
  6810. WFIFOW(fd,0)=0x181;
  6811. WFIFOB(fd,2)=flag;
  6812. WFIFOSET(fd,packet_len(0x181));
  6813. }
  6814. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  6815. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  6816. /*
  6817. void clif_guild_allianceadded(struct guild *g,int idx)
  6818. {
  6819. unsigned char buf[64];
  6820. WBUFW(buf,0)=0x185;
  6821. WBUFL(buf,2)=g->alliance[idx].opposition;
  6822. WBUFL(buf,6)=g->alliance[idx].guild_id;
  6823. memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  6824. clif->send(buf,packet_len(0x185),guild->getavailablesd(g),GUILD);
  6825. }
  6826. */
  6827. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  6828. /// 015e <reason>.L
  6829. /// 0 = success
  6830. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  6831. /// 2 = there are still members in the guild
  6832. void clif_guild_broken(struct map_session_data *sd,int flag)
  6833. {
  6834. int fd;
  6835. nullpo_retv(sd);
  6836. fd=sd->fd;
  6837. WFIFOHEAD(fd,packet_len(0x15e));
  6838. WFIFOW(fd,0)=0x15e;
  6839. WFIFOL(fd,2)=flag;
  6840. WFIFOSET(fd,packet_len(0x15e));
  6841. }
  6842. /// Displays emotion on an object (ZC_EMOTION).
  6843. /// 00c0 <id>.L <type>.B
  6844. /// type:
  6845. /// enum emotion_type
  6846. void clif_emotion(struct block_list *bl,int type)
  6847. {
  6848. unsigned char buf[8];
  6849. nullpo_retv(bl);
  6850. WBUFW(buf,0)=0xc0;
  6851. WBUFL(buf,2)=bl->id;
  6852. WBUFB(buf,6)=type;
  6853. clif->send(buf,packet_len(0xc0),bl,AREA);
  6854. }
  6855. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  6856. /// 0191 <id>.L <contents>.80B
  6857. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6858. {
  6859. unsigned char buf[MESSAGE_SIZE+6];
  6860. nullpo_retv(bl);
  6861. nullpo_retv(talkie);
  6862. WBUFW(buf,0) = 0x191;
  6863. WBUFL(buf,2) = bl->id;
  6864. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6865. clif->send(buf,packet_len(0x191),bl,AREA);
  6866. }
  6867. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  6868. /// 01ea <id>.L
  6869. void clif_wedding_effect(struct block_list *bl)
  6870. {
  6871. unsigned char buf[6];
  6872. nullpo_retv(bl);
  6873. WBUFW(buf,0) = 0x1ea;
  6874. WBUFL(buf,2) = bl->id;
  6875. clif->send(buf, packet_len(0x1ea), bl, AREA);
  6876. }
  6877. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  6878. /// 01e6 <partner name>.24B
  6879. void clif_callpartner(struct map_session_data *sd) {
  6880. unsigned char buf[26];
  6881. nullpo_retv(sd);
  6882. WBUFW(buf,0) = 0x1e6;
  6883. if( sd->status.partner_id ) {
  6884. const char *p;
  6885. if( ( p = map->charid2nick(sd->status.partner_id) ) != NULL ) {
  6886. memcpy(WBUFP(buf,2), p, NAME_LENGTH);
  6887. } else {
  6888. WBUFB(buf,2) = 0;
  6889. }
  6890. } else {
  6891. // Send zero-length name if no partner, to initialize the client buffer.
  6892. WBUFB(buf,2) = 0;
  6893. }
  6894. clif->send(buf, packet_len(0x1e6), &sd->bl, AREA);
  6895. }
  6896. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  6897. /// 01e4
  6898. /// This packet while still implemented by the client is no longer being officially used.
  6899. /*
  6900. void clif_marriage_process(struct map_session_data *sd)
  6901. {
  6902. int fd;
  6903. nullpo_retv(sd);
  6904. fd=sd->fd;
  6905. WFIFOHEAD(fd,packet_len(0x1e4));
  6906. WFIFOW(fd,0)=0x1e4;
  6907. WFIFOSET(fd,packet_len(0x1e4));
  6908. }
  6909. */
  6910. /// Notice of divorce (ZC_DIVORCE).
  6911. /// 0205 <partner name>.24B
  6912. void clif_divorced(struct map_session_data* sd, const char* name)
  6913. {
  6914. int fd;
  6915. nullpo_retv(sd);
  6916. fd=sd->fd;
  6917. WFIFOHEAD(fd,packet_len(0x205));
  6918. WFIFOW(fd,0)=0x205;
  6919. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6920. WFIFOSET(fd, packet_len(0x205));
  6921. }
  6922. /// Marriage proposal (ZC_REQ_COUPLE).
  6923. /// 01e2 <account id>.L <char id>.L <char name>.24B
  6924. /// This packet while still implemented by the client is no longer being officially used.
  6925. /*
  6926. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  6927. {
  6928. nullpo_retv(sd);
  6929. WFIFOHEAD(fd,packet_len(0x1e2));
  6930. WFIFOW(fd,0) = 0x1e2;
  6931. WFIFOL(fd,2) = ssd->status.account_id;
  6932. WFIFOL(fd,6) = ssd->status.char_id;
  6933. safestrncpy((char*)WFIFOP(fd,10), ssd->status.name, NAME_LENGTH);
  6934. WFIFOSET(fd, packet_len(0x1e2));
  6935. }
  6936. */
  6937. /*==========================================
  6938. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6939. *------------------------------------------*/
  6940. void clif_disp_message(struct block_list* src, const char* mes, size_t len, enum send_target target)
  6941. {
  6942. unsigned char buf[256];
  6943. if (len == 0)
  6944. return;
  6945. nullpo_retv(src);
  6946. nullpo_retv(mes);
  6947. if (len > sizeof(buf)-5) {
  6948. ShowWarning("clif_disp_message: Truncated message '%s' (len=%"PRIuS", max=%"PRIuS", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  6949. len = sizeof(buf)-5;
  6950. }
  6951. WBUFW(buf, 0) = 0x17f;
  6952. WBUFW(buf, 2) = len + 5;
  6953. safestrncpy((char*)WBUFP(buf,4), mes, len+1);
  6954. clif->send(buf, WBUFW(buf,2), src, target);
  6955. }
  6956. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  6957. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  6958. /// 00cd <result>.B
  6959. /// result:
  6960. /// 0 = failure
  6961. /// 1 = success
  6962. void clif_GM_kickack(struct map_session_data *sd, int result)
  6963. {
  6964. int fd;
  6965. nullpo_retv(sd);
  6966. fd = sd->fd;
  6967. WFIFOHEAD(fd,packet_len(0xcd));
  6968. WFIFOW(fd,0) = 0xcd;
  6969. WFIFOB(fd,2) = result;
  6970. WFIFOSET(fd, packet_len(0xcd));
  6971. }
  6972. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd) {
  6973. int fd;
  6974. nullpo_retv(tsd);
  6975. fd = tsd->fd;
  6976. if (fd > 0)
  6977. clif->authfail_fd(fd, 15);
  6978. else
  6979. map->quit(tsd);
  6980. if (sd)
  6981. clif->GM_kickack(sd, 1);
  6982. }
  6983. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  6984. /// 014a <result>.L
  6985. /// result:
  6986. /// 0 = "A manner point has been successfully aligned."
  6987. /// 1 = MP_FAILURE_EXHAUST
  6988. /// 2 = MP_FAILURE_ALREADY_GIVING
  6989. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  6990. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  6991. /// 5 = "You got a good point from %s."
  6992. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6993. {
  6994. int fd;
  6995. nullpo_retv(sd);
  6996. fd = sd->fd;
  6997. WFIFOHEAD(fd,packet_len(0x14a));
  6998. WFIFOW(fd,0) = 0x14a;
  6999. WFIFOL(fd,2) = type;
  7000. WFIFOSET(fd, packet_len(0x14a));
  7001. }
  7002. /// Follow-up to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7003. /// 014b <type>.B <GM name>.24B
  7004. /// type:
  7005. /// 0 = positive (unmute)
  7006. /// 1 = negative (mute)
  7007. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7008. {
  7009. int fd;
  7010. nullpo_retv(sd);
  7011. nullpo_retv(tsd);
  7012. fd = tsd->fd;
  7013. WFIFOHEAD(fd,packet_len(0x14b));
  7014. WFIFOW(fd,0) = 0x14b;
  7015. WFIFOB(fd,2) = type;
  7016. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7017. WFIFOSET(fd, packet_len(0x14b));
  7018. }
  7019. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7020. /// 00d1 <type>.B <result>.B
  7021. /// type:
  7022. /// 0 = /ex (deny)
  7023. /// 1 = /in (allow)
  7024. /// result:
  7025. /// 0 = success
  7026. /// 1 = failure
  7027. /// 2 = too many blocks
  7028. void clif_wisexin(struct map_session_data *sd,int type,int flag) {
  7029. int fd;
  7030. nullpo_retv(sd);
  7031. fd=sd->fd;
  7032. WFIFOHEAD(fd,packet_len(0xd1));
  7033. WFIFOW(fd,0)=0xd1;
  7034. WFIFOB(fd,2)=type;
  7035. WFIFOB(fd,3)=flag;
  7036. WFIFOSET(fd,packet_len(0xd1));
  7037. }
  7038. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7039. /// 00d2 <type>.B <result>.B
  7040. /// type:
  7041. /// 0 = /exall (deny)
  7042. /// 1 = /inall (allow)
  7043. /// result:
  7044. /// 0 = success
  7045. /// 1 = failure
  7046. void clif_wisall(struct map_session_data *sd,int type,int flag) {
  7047. int fd;
  7048. nullpo_retv(sd);
  7049. fd=sd->fd;
  7050. WFIFOHEAD(fd,packet_len(0xd2));
  7051. WFIFOW(fd,0)=0xd2;
  7052. WFIFOB(fd,2)=type;
  7053. WFIFOB(fd,3)=flag;
  7054. WFIFOSET(fd,packet_len(0xd2));
  7055. }
  7056. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7057. /// 07fe <bgm>.24B
  7058. void clif_playBGM(struct map_session_data* sd, const char* name)
  7059. {
  7060. int fd;
  7061. nullpo_retv(sd);
  7062. fd = sd->fd;
  7063. WFIFOHEAD(fd,packet_len(0x7fe));
  7064. WFIFOW(fd,0) = 0x7fe;
  7065. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7066. WFIFOSET(fd,packet_len(0x7fe));
  7067. }
  7068. /// Plays/stops a wave sound (ZC_SOUND).
  7069. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7070. /// file name:
  7071. /// relative to data\wav
  7072. /// act:
  7073. /// 0 = play (once)
  7074. /// 1 = play (repeat, does not work)
  7075. /// 2 = stops all sound instances of file name (does not work)
  7076. /// term:
  7077. /// unknown purpose, only relevant to act = 1
  7078. /// npc id:
  7079. /// The acoustic direction of the sound is determined by the
  7080. /// relative position of the NPC to the player (3D sound).
  7081. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7082. {
  7083. int fd;
  7084. nullpo_retv(sd);
  7085. nullpo_retv(bl);
  7086. nullpo_retv(name);
  7087. fd = sd->fd;
  7088. WFIFOHEAD(fd,packet_len(0x1d3));
  7089. WFIFOW(fd,0) = 0x1d3;
  7090. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  7091. WFIFOB(fd,26) = type;
  7092. WFIFOL(fd,27) = 0;
  7093. WFIFOL(fd,31) = bl->id;
  7094. WFIFOSET(fd,packet_len(0x1d3));
  7095. }
  7096. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7097. {
  7098. unsigned char buf[40];
  7099. nullpo_retv(bl);
  7100. nullpo_retv(name);
  7101. WBUFW(buf,0) = 0x1d3;
  7102. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  7103. WBUFB(buf,26) = type;
  7104. WBUFL(buf,27) = 0;
  7105. WBUFL(buf,31) = bl->id;
  7106. clif->send(buf, packet_len(0x1d3), bl, coverage);
  7107. }
  7108. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7109. /// 01f3 <id>.L <effect id>.L
  7110. /// effect id:
  7111. /// @see doc/effect_list.txt
  7112. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7113. {
  7114. unsigned char buf[24];
  7115. nullpo_retv(bl);
  7116. memset(buf, 0, packet_len(0x1f3));
  7117. WBUFW(buf,0) = 0x1f3;
  7118. WBUFL(buf,2) = bl->id;
  7119. WBUFL(buf,6) = type;
  7120. clif->send(buf, packet_len(0x1f3), bl, target);
  7121. if (disguised(bl)) {
  7122. WBUFL(buf,2) = -bl->id;
  7123. clif->send(buf, packet_len(0x1f3), bl, SELF);
  7124. }
  7125. }
  7126. void clif_specialeffect_single(struct block_list* bl, int type, int fd) {
  7127. nullpo_retv(bl);
  7128. WFIFOHEAD(fd,10);
  7129. WFIFOW(fd,0) = 0x1f3;
  7130. WFIFOL(fd,2) = bl->id;
  7131. WFIFOL(fd,6) = type;
  7132. WFIFOSET(fd,10);
  7133. }
  7134. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7135. /// 0284 <id>.L <effect id>.L <num data>.L
  7136. /// effect id:
  7137. /// @see doc/effect_list.txt
  7138. /// num data:
  7139. /// effect-dependent value
  7140. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7141. {
  7142. uint8 buf[14];
  7143. WBUFW(buf,0) = 0x284;
  7144. WBUFL(buf,2) = bl->id;
  7145. WBUFL(buf,6) = effect_id;
  7146. WBUFL(buf,10) = num;
  7147. clif->send(buf, packet_len(0x284), bl, target);
  7148. if( disguised(bl) )
  7149. {
  7150. WBUFL(buf,2) = -bl->id;
  7151. clif->send(buf, packet_len(0x284), bl, SELF);
  7152. }
  7153. }
  7154. /**
  7155. * Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead).
  7156. *
  7157. * 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7158. *
  7159. * @param fd Target fd to send the message to
  7160. * @param color Message color (RGB format: 0xRRGGBB)
  7161. * @param msg Message text
  7162. */
  7163. void clif_messagecolor_self(int fd, uint32 color, const char *msg)
  7164. {
  7165. size_t msg_len;
  7166. nullpo_retv(msg);
  7167. msg_len = strlen(msg) + 1;
  7168. WFIFOHEAD(fd,msg_len + 12);
  7169. WFIFOW(fd,0) = 0x2C1;
  7170. WFIFOW(fd,2) = msg_len + 12;
  7171. WFIFOL(fd,4) = 0;
  7172. WFIFOL(fd,8) = RGB2BGR(color);
  7173. safestrncpy((char*)WFIFOP(fd,12), msg, msg_len);
  7174. WFIFOSET(fd, msg_len + 12);
  7175. }
  7176. /**
  7177. * Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  7178. *
  7179. * 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  7180. *
  7181. * @param bl Source block list.
  7182. * @param color Message color (RGB format: 0xRRGGBB)
  7183. * @param msg Message text
  7184. */
  7185. void clif_messagecolor(struct block_list* bl, uint32 color, const char *msg)
  7186. {
  7187. size_t msg_len = strlen(msg) + 1;
  7188. uint8 buf[256];
  7189. nullpo_retv(bl);
  7190. nullpo_retv(msg);
  7191. if (msg_len > sizeof(buf)-12) {
  7192. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%"PRIuS").\n", msg, msg_len);
  7193. msg_len = sizeof(buf)-12;
  7194. }
  7195. WBUFW(buf,0) = 0x2C1;
  7196. WBUFW(buf,2) = msg_len + 12;
  7197. WBUFL(buf,4) = bl->id;
  7198. WBUFL(buf,8) = RGB2BGR(color);
  7199. memcpy(WBUFP(buf,12), msg, msg_len);
  7200. clif->send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7201. }
  7202. /**
  7203. * Notifies the client that the storage window is still open
  7204. *
  7205. * Should only be used in cases where the client closed the
  7206. * storage window without server's consent
  7207. **/
  7208. void clif_refresh_storagewindow(struct map_session_data *sd)
  7209. {
  7210. nullpo_retv(sd);
  7211. // Notify the client that the storage is open
  7212. if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) {
  7213. storage->sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7214. clif->storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items));
  7215. clif->updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE);
  7216. }
  7217. // Notify the client that the gstorage is open otherwise it will
  7218. // remain locked forever and nobody will be able to access it
  7219. if (sd->state.storage_flag == STORAGE_FLAG_GUILD) {
  7220. struct guild_storage *gstor;
  7221. if( (gstor = idb_get(gstorage->db,sd->status.guild_id)) == NULL) {
  7222. // Shouldn't happen... The information should already be at the map-server
  7223. intif->request_guild_storage(sd->status.account_id,sd->status.guild_id);
  7224. } else {
  7225. storage->sortitem(gstor->items, ARRAYLENGTH(gstor->items));
  7226. clif->storagelist(sd, gstor->items, ARRAYLENGTH(gstor->items));
  7227. clif->updatestorageamount(sd, gstor->storage_amount, MAX_GUILD_STORAGE);
  7228. }
  7229. }
  7230. }
  7231. // refresh the client's screen, getting rid of any effects
  7232. void clif_refresh(struct map_session_data *sd)
  7233. {
  7234. nullpo_retv(sd);
  7235. clif->changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7236. clif->inventorylist(sd);
  7237. if(pc_iscarton(sd)) {
  7238. clif->cartlist(sd);
  7239. clif->updatestatus(sd,SP_CARTINFO);
  7240. }
  7241. clif->updatestatus(sd,SP_WEIGHT);
  7242. clif->updatestatus(sd,SP_MAXWEIGHT);
  7243. clif->updatestatus(sd,SP_STR);
  7244. clif->updatestatus(sd,SP_AGI);
  7245. clif->updatestatus(sd,SP_VIT);
  7246. clif->updatestatus(sd,SP_INT);
  7247. clif->updatestatus(sd,SP_DEX);
  7248. clif->updatestatus(sd,SP_LUK);
  7249. if (sd->spiritball)
  7250. clif->spiritball_single(sd->fd, sd);
  7251. if (sd->charm_type != CHARM_TYPE_NONE && sd->charm_count > 0)
  7252. clif->charm_single(sd->fd, sd);
  7253. if (sd->vd.cloth_color)
  7254. clif->refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7255. if (sd->vd.body_style)
  7256. clif->refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  7257. if(homun_alive(sd->hd))
  7258. clif->send_homdata(sd,SP_ACK,0);
  7259. if( sd->md ) {
  7260. clif->mercenary_info(sd);
  7261. clif->mercenary_skillblock(sd);
  7262. }
  7263. if( sd->ed )
  7264. clif->elemental_info(sd);
  7265. map->foreachinrange(clif->getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  7266. clif->weather_check(sd);
  7267. if( sd->chatID )
  7268. chat->leave(sd, false);
  7269. if( sd->state.vending )
  7270. clif->openvending(sd, sd->bl.id, sd->vending);
  7271. if( pc_issit(sd) )
  7272. clif->sitting(&sd->bl); // FIXME: just send to self, not area
  7273. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  7274. clif->clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  7275. else
  7276. clif->changed_dir(&sd->bl, SELF);
  7277. // unlike vending, resuming buyingstore crashes the client.
  7278. buyingstore->close(sd);
  7279. mail->clear(sd);
  7280. if( disguised(&sd->bl) ) {/* refresh-da */
  7281. short disguise = sd->disguise;
  7282. pc->disguise(sd, -1);
  7283. pc->disguise(sd, disguise);
  7284. }
  7285. clif->refresh_storagewindow(sd);
  7286. }
  7287. /// Updates the object's (bl) name on client.
  7288. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  7289. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  7290. void clif_charnameack (int fd, struct block_list *bl)
  7291. {
  7292. unsigned char buf[103];
  7293. int cmd = 0x95;
  7294. nullpo_retv(bl);
  7295. WBUFW(buf,0) = cmd;
  7296. WBUFL(buf,2) = bl->id;
  7297. switch( bl->type ) {
  7298. case BL_PC:
  7299. {
  7300. const struct map_session_data *ssd = BL_UCCAST(BL_PC, bl);
  7301. const struct party_data *p = NULL;
  7302. const struct guild *g = NULL;
  7303. int ps = -1;
  7304. //Requesting your own "shadow" name. [Skotlex]
  7305. if (ssd->fd == fd && ssd->disguise != -1)
  7306. WBUFL(buf,2) = -bl->id;
  7307. if (ssd->fakename[0] != '\0') {
  7308. WBUFW(buf, 0) = cmd = 0x195;
  7309. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7310. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  7311. break;
  7312. }
  7313. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7314. if (ssd->status.party_id != 0) {
  7315. p = party->search(ssd->status.party_id);
  7316. }
  7317. if (ssd->status.guild_id != 0) {
  7318. if ((g = ssd->guild) != NULL) {
  7319. int i;
  7320. ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
  7321. if (i < g->max_member)
  7322. ps = g->member[i].position;
  7323. }
  7324. }
  7325. if (!battle_config.display_party_name && g == NULL) {
  7326. // do not display party unless the player is also in a guild
  7327. p = NULL;
  7328. }
  7329. if (p == NULL && g == NULL)
  7330. break;
  7331. WBUFW(buf, 0) = cmd = 0x195;
  7332. if (p != NULL)
  7333. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7334. else
  7335. WBUFB(buf,30) = 0;
  7336. if (g != NULL && ps >= 0 && ps < MAX_GUILDPOSITION) {
  7337. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7338. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7339. } else { //Assume no guild.
  7340. WBUFB(buf,54) = 0;
  7341. WBUFB(buf,78) = 0;
  7342. }
  7343. }
  7344. break;
  7345. //[blackhole89]
  7346. case BL_HOM:
  7347. memcpy(WBUFP(buf,6), BL_UCCAST(BL_HOM, bl)->homunculus.name, NAME_LENGTH);
  7348. break;
  7349. case BL_MER:
  7350. memcpy(WBUFP(buf,6), BL_UCCAST(BL_MER, bl)->db->name, NAME_LENGTH);
  7351. break;
  7352. case BL_PET:
  7353. memcpy(WBUFP(buf,6), BL_UCCAST(BL_PET, bl)->pet.name, NAME_LENGTH);
  7354. break;
  7355. case BL_NPC:
  7356. memcpy(WBUFP(buf,6), BL_UCCAST(BL_NPC, bl)->name, NAME_LENGTH);
  7357. break;
  7358. case BL_MOB:
  7359. {
  7360. const struct mob_data *md = BL_UCCAST(BL_MOB, bl);
  7361. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7362. if (md->guardian_data && md->guardian_data->g) {
  7363. WBUFW(buf, 0) = cmd = 0x195;
  7364. WBUFB(buf,30) = 0;
  7365. memcpy(WBUFP(buf,54), md->guardian_data->g->name, NAME_LENGTH);
  7366. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7367. } else if (battle_config.show_mob_info) {
  7368. char mobhp[50], *str_p = mobhp;
  7369. WBUFW(buf, 0) = cmd = 0x195;
  7370. if (battle_config.show_mob_info&4)
  7371. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  7372. if (battle_config.show_mob_info&1)
  7373. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  7374. if (battle_config.show_mob_info&2)
  7375. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  7376. //Even thought mobhp ain't a name, we send it as one so the client
  7377. //can parse it. [Skotlex]
  7378. if (str_p != mobhp) {
  7379. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  7380. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7381. WBUFB(buf,54) = 0;
  7382. WBUFB(buf,78) = 0;
  7383. }
  7384. }
  7385. }
  7386. break;
  7387. case BL_CHAT:
  7388. #if 0 //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7389. memcpy(WBUFP(buf,6), BL_UCCAST(BL_CHAT, bl)->title, NAME_LENGTH);
  7390. break;
  7391. #endif
  7392. return;
  7393. case BL_ELEM:
  7394. memcpy(WBUFP(buf,6), BL_UCCAST(BL_ELEM, bl)->db->name, NAME_LENGTH);
  7395. break;
  7396. default:
  7397. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  7398. return;
  7399. }
  7400. // if no recipient specified just update nearby clients
  7401. if (fd == 0) {
  7402. clif->send(buf, packet_len(cmd), bl, AREA);
  7403. } else {
  7404. WFIFOHEAD(fd, packet_len(cmd));
  7405. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  7406. WFIFOSET(fd, packet_len(cmd));
  7407. }
  7408. }
  7409. //Used to update when a char leaves a party/guild. [Skotlex]
  7410. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7411. void clif_charnameupdate (struct map_session_data *ssd)
  7412. {
  7413. unsigned char buf[103];
  7414. int cmd = 0x195, ps = -1;
  7415. struct party_data *p = NULL;
  7416. struct guild *g = NULL;
  7417. nullpo_retv(ssd);
  7418. if( ssd->fakename[0] )
  7419. return; //No need to update as the party/guild was not displayed anyway.
  7420. WBUFW(buf,0) = cmd;
  7421. WBUFL(buf,2) = ssd->bl.id;
  7422. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7423. if (!battle_config.display_party_name) {
  7424. if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
  7425. p = party->search(ssd->status.party_id);
  7426. }else{
  7427. if (ssd->status.party_id > 0)
  7428. p = party->search(ssd->status.party_id);
  7429. }
  7430. if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL )
  7431. {
  7432. int i;
  7433. ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
  7434. if( i < g->max_member ) ps = g->member[i].position;
  7435. }
  7436. if( p )
  7437. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  7438. else
  7439. WBUFB(buf,30) = 0;
  7440. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  7441. {
  7442. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7443. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7444. }
  7445. else
  7446. {
  7447. WBUFB(buf,54) = 0;
  7448. WBUFB(buf,78) = 0;
  7449. }
  7450. // Update nearby clients
  7451. clif->send(buf, packet_len(cmd), &ssd->bl, AREA);
  7452. }
  7453. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  7454. /// 01ff <id>.L <x>.W <y>.W
  7455. ///
  7456. /// Visually moves(instant) a character to x,y. The char moves even
  7457. /// when the target cell isn't walkable. If the char is sitting it
  7458. /// stays that way.
  7459. void clif_slide(struct block_list *bl, int x, int y)
  7460. {
  7461. unsigned char buf[10];
  7462. nullpo_retv(bl);
  7463. WBUFW(buf, 0) = 0x01ff;
  7464. WBUFL(buf, 2) = bl->id;
  7465. WBUFW(buf, 6) = x;
  7466. WBUFW(buf, 8) = y;
  7467. clif->send(buf, packet_len(0x1ff), bl, AREA);
  7468. if( disguised(bl) )
  7469. {
  7470. WBUFL(buf,2) = -bl->id;
  7471. clif->send(buf, packet_len(0x1ff), bl, SELF);
  7472. }
  7473. }
  7474. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  7475. /// 008d <packet len>.W <id>.L <message>.?B
  7476. void clif_disp_overhead(struct block_list *bl, const char* mes)
  7477. {
  7478. unsigned char buf[256]; //This should be more than sufficient, the theoretical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  7479. size_t len_mes;
  7480. nullpo_retv(bl);
  7481. nullpo_retv(mes);
  7482. len_mes = strlen(mes)+1; //Account for \0
  7483. if (len_mes > sizeof(buf)-8) {
  7484. ShowError("clif_disp_overhead: Message too long (length %"PRIuS")\n", len_mes);
  7485. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  7486. }
  7487. // send message to others
  7488. WBUFW(buf,0) = 0x8d;
  7489. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7490. WBUFL(buf,4) = bl->id;
  7491. safestrncpy((char*)WBUFP(buf,8), mes, len_mes);
  7492. clif->send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  7493. // send back message to the speaker
  7494. if( bl->type == BL_PC ) {
  7495. WBUFW(buf,0) = 0x8e;
  7496. WBUFW(buf, 2) = len_mes + 4;
  7497. safestrncpy((char*)WBUFP(buf,4), mes, len_mes);
  7498. clif->send(buf, WBUFW(buf,2), bl, SELF);
  7499. }
  7500. }
  7501. /*==========================
  7502. * Minimap fix [Kevin]
  7503. * Remove dot from minimap
  7504. *--------------------------*/
  7505. void clif_party_xy_remove(struct map_session_data *sd)
  7506. {
  7507. unsigned char buf[16];
  7508. nullpo_retv(sd);
  7509. WBUFW(buf,0)=0x107;
  7510. WBUFL(buf,2)=sd->status.account_id;
  7511. WBUFW(buf,6)=-1;
  7512. WBUFW(buf,8)=-1;
  7513. clif->send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  7514. }
  7515. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  7516. /// 0215 <msg id>.L
  7517. /// msg id:
  7518. /// 0x15 = End all negative status (PA_GOSPEL)
  7519. /// 0x16 = Immunity to all status (PA_GOSPEL)
  7520. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  7521. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  7522. /// 0x19 = All stats +20 (PA_GOSPEL)
  7523. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  7524. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  7525. /// 0x1e = DEF +25% (PA_GOSPEL)
  7526. /// 0x1f = ATK +100% (PA_GOSPEL)
  7527. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  7528. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  7529. /// ? = nothing
  7530. void clif_gospel_info(struct map_session_data *sd, int type)
  7531. {
  7532. int fd;
  7533. nullpo_retv(sd);
  7534. fd = sd->fd;
  7535. WFIFOHEAD(fd,packet_len(0x215));
  7536. WFIFOW(fd,0)=0x215;
  7537. WFIFOL(fd,2)=type;
  7538. WFIFOSET(fd, packet_len(0x215));
  7539. }
  7540. /// Multi-purpose mission information packet (ZC_STARSKILL).
  7541. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  7542. /// result:
  7543. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  7544. /// star:
  7545. /// 0 = Place of the Sun
  7546. /// 1 = Place of the Moon
  7547. /// 2 = Place of the Stars
  7548. /// 1 = Star Gladiator %s's %s: <mapname>
  7549. /// star:
  7550. /// 0 = Place of the Sun
  7551. /// 1 = Place of the Moon
  7552. /// 2 = Place of the Stars
  7553. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  7554. /// star:
  7555. /// 0 = Target of the Sun
  7556. /// 1 = Target of the Moon
  7557. /// 2 = Target of the Stars
  7558. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  7559. /// star:
  7560. /// 0 = Monster of the Sun
  7561. /// 1 = Monster of the Moon
  7562. /// 2 = Monster of the Stars
  7563. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  7564. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  7565. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  7566. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  7567. /// 40 = Target HP : <monster_id used as HP>
  7568. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  7569. {
  7570. int fd;
  7571. nullpo_retv(sd);
  7572. nullpo_retv(mapname);
  7573. fd = sd->fd;
  7574. WFIFOHEAD(fd,packet_len(0x20e));
  7575. WFIFOW(fd,0) = 0x20e;
  7576. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  7577. WFIFOL(fd,26) = monster_id;
  7578. WFIFOB(fd,30) = star;
  7579. WFIFOB(fd,31) = result;
  7580. WFIFOSET(fd,packet_len(0x20e));
  7581. }
  7582. /*==========================================
  7583. * Info about Star Gladiator save map [Komurka]
  7584. * type: 1: Information, 0: Map registered
  7585. *------------------------------------------*/
  7586. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  7587. {
  7588. char mapname[MAP_NAME_LENGTH_EXT];
  7589. nullpo_retv(sd);
  7590. Assert_retv(feel_level < MAX_PC_FEELHATE);
  7591. mapindex->getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  7592. clif->starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  7593. }
  7594. /*==========================================
  7595. * Info about Star Gladiator hate mob [Komurka]
  7596. * type: 1: Register mob, 0: Information.
  7597. *------------------------------------------*/
  7598. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  7599. {
  7600. if( pc->db_checkid(class_) ) {
  7601. clif->starskill(sd, pc->job_name(class_), class_, hate_level, type ? 10 : 11);
  7602. } else if( mob->db_checkid(class_) ) {
  7603. clif->starskill(sd, mob->db(class_)->jname, class_, hate_level, type ? 10 : 11);
  7604. } else {
  7605. ShowWarning("clif_hate_info: Received invalid class %d for this packet (char_id=%d, hate_level=%u, type=%u).\n", class_, sd->status.char_id, (unsigned int)hate_level, (unsigned int)type);
  7606. }
  7607. }
  7608. /*==========================================
  7609. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7610. *------------------------------------------*/
  7611. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  7612. {
  7613. clif->starskill(sd, mob->db(mob_id)->jname, mob_id, progress, 20);
  7614. }
  7615. /*==========================================
  7616. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7617. *------------------------------------------*/
  7618. void clif_feel_hate_reset(struct map_session_data *sd)
  7619. {
  7620. clif->starskill(sd, "", 0, 0, 30);
  7621. }
  7622. /// Equip window (un)tick ack (ZC_CONFIG).
  7623. /// 02d9 <type>.L <value>.L
  7624. /// type:
  7625. /// 0 = open equip window
  7626. /// value:
  7627. /// 0 = disabled
  7628. /// 1 = enabled
  7629. void clif_equiptickack(struct map_session_data* sd, int flag)
  7630. {
  7631. int fd;
  7632. nullpo_retv(sd);
  7633. fd = sd->fd;
  7634. WFIFOHEAD(fd, packet_len(0x2d9));
  7635. WFIFOW(fd, 0) = 0x2d9;
  7636. WFIFOL(fd, 2) = 0;
  7637. WFIFOL(fd, 6) = flag;
  7638. WFIFOSET(fd, packet_len(0x2d9));
  7639. }
  7640. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  7641. /// 02da <open equip window>.B
  7642. /// open equip window:
  7643. /// 0 = disabled
  7644. /// 1 = enabled
  7645. void clif_equpcheckbox(struct map_session_data* sd)
  7646. {
  7647. int fd;
  7648. nullpo_retv(sd);
  7649. fd = sd->fd;
  7650. WFIFOHEAD(fd, packet_len(0x2da));
  7651. WFIFOW(fd, 0) = 0x2da;
  7652. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7653. WFIFOSET(fd, packet_len(0x2da));
  7654. }
  7655. /// Sends info about a player's equipped items.
  7656. /// 02d7 <packet len>.W <name>.24B <class>.W <hairstyle>.W <up-viewid>.W <mid-viewid>.W <low-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.26B* (ZC_EQUIPWIN_MICROSCOPE)
  7657. /// 02d7 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE, PACKETVER >= 20100629)
  7658. /// 0859 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE2, PACKETVER >= 20101124)
  7659. /// 0859 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE2, PACKETVER >= 20110111)
  7660. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd) {
  7661. int i, equip = 0;
  7662. nullpo_retv(sd);
  7663. nullpo_retv(tsd);
  7664. for (i = 0; i < EQI_MAX; i++) {
  7665. int k = tsd->equip_index[i];
  7666. if (k >= 0) {
  7667. if (tsd->status.inventory[k].nameid <= 0 || tsd->inventory_data[k] == NULL) // Item doesn't exist
  7668. continue;
  7669. clif->item_equip(k+2,&viewequip_list.list[equip++],&tsd->status.inventory[k],tsd->inventory_data[k],pc->equippoint(tsd,k));
  7670. }
  7671. }
  7672. viewequip_list.PacketType = viewequipackType;
  7673. viewequip_list.PacketLength = ( sizeof( viewequip_list ) - sizeof( viewequip_list.list ) ) + ( sizeof(struct EQUIPITEM_INFO) * equip );
  7674. safestrncpy(viewequip_list.characterName, tsd->status.name, NAME_LENGTH);
  7675. viewequip_list.job = tsd->status.class_;
  7676. viewequip_list.head = tsd->vd.hair_style;
  7677. viewequip_list.accessory = tsd->vd.head_bottom;
  7678. viewequip_list.accessory2 = tsd->vd.head_mid;
  7679. viewequip_list.accessory3 = tsd->vd.head_top;
  7680. #if PACKETVER >= 20110111
  7681. viewequip_list.robe = tsd->vd.robe;
  7682. #endif
  7683. viewequip_list.headpalette = tsd->vd.hair_color;
  7684. viewequip_list.bodypalette = tsd->vd.cloth_color;
  7685. viewequip_list.sex = tsd->vd.sex;
  7686. clif->send(&viewequip_list, viewequip_list.PacketLength, &sd->bl, SELF);
  7687. }
  7688. /**
  7689. * Displays a string from msgstringtable.txt (ZC_MSG).
  7690. *
  7691. * 0291 <msg id>.W
  7692. *
  7693. * @param sd The target character.
  7694. * @param msg_id msgstringtable message index, 0-based (@see enum clif_messages)
  7695. */
  7696. void clif_msgtable(struct map_session_data* sd, unsigned short msg_id)
  7697. {
  7698. int fd;
  7699. nullpo_retv(sd);
  7700. fd = sd->fd;
  7701. WFIFOHEAD(fd, packet_len(0x291));
  7702. WFIFOW(fd, 0) = 0x291;
  7703. WFIFOW(fd, 2) = msg_id; // zero-based msgstringtable.txt index
  7704. WFIFOSET(fd, packet_len(0x291));
  7705. }
  7706. /**
  7707. * Displays a format string from msgstringtable.txt with a %d value (ZC_MSG_VALUE).
  7708. *
  7709. * 0x7e2 <msg id>.W <value>.L
  7710. *
  7711. * @param sd The target character.
  7712. * @param msg_id msgstringtable message index, 0-based (@see enum clif_messages)
  7713. * @param value The value to fill %d.
  7714. */
  7715. void clif_msgtable_num(struct map_session_data *sd, unsigned short msg_id, int value)
  7716. {
  7717. #if PACKETVER >= 20090805
  7718. int fd;
  7719. nullpo_retv(sd);
  7720. fd = sd->fd;
  7721. WFIFOHEAD(fd, packet_len(0x7e2));
  7722. WFIFOW(fd, 0) = 0x7e2;
  7723. WFIFOW(fd, 2) = msg_id;
  7724. WFIFOL(fd, 4) = value;
  7725. WFIFOSET(fd, packet_len(0x7e2));
  7726. #endif
  7727. }
  7728. /**
  7729. * Displays a string from msgstringtable.txt, prefixed with a skill name (ZC_MSG_SKILL).
  7730. *
  7731. * 07e6 <skill id>.W <msg id>.L
  7732. *
  7733. * NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  7734. * "[SkillName] Message"
  7735. *
  7736. * @param sd The target character.
  7737. * @param skill_id ID of the skill to display.
  7738. * @param msg_id msgstringtable message index, 0-based (@see enum clif_messages)
  7739. */
  7740. void clif_msgtable_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  7741. {
  7742. int fd;
  7743. nullpo_retv(sd);
  7744. fd = sd->fd;
  7745. WFIFOHEAD(fd, packet_len(0x7e6));
  7746. WFIFOW(fd,0) = 0x7e6;
  7747. WFIFOW(fd,2) = skill_id;
  7748. WFIFOL(fd,4) = msg_id;
  7749. WFIFOSET(fd, packet_len(0x7e6));
  7750. }
  7751. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7752. /// Returns true if the packet was parsed successfully.
  7753. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7754. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7755. bool clif_process_message(struct map_session_data *sd, int format, char **name_, size_t *namelen_, char **message_, size_t *messagelen_) {
  7756. char *text, *name, *message;
  7757. unsigned int packetlen, textlen;
  7758. size_t namelen, messagelen;
  7759. int fd = sd->fd;
  7760. nullpo_retr(false, sd);
  7761. nullpo_retr(false, name_);
  7762. nullpo_retr(false, namelen_);
  7763. nullpo_retr(false, message_);
  7764. nullpo_retr(false, messagelen_);
  7765. *name_ = NULL;
  7766. *namelen_ = 0;
  7767. *message_ = NULL;
  7768. *messagelen_ = 0;
  7769. packetlen = RFIFOW(fd,2);
  7770. // basic structure checks
  7771. if (packetlen < 4 + 1) {
  7772. // 4-byte header and at least an empty string is expected
  7773. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7774. return false;
  7775. }
  7776. text = (char*)RFIFOP(fd,4);
  7777. textlen = packetlen - 4;
  7778. // process <name> part of the packet
  7779. if( format == 0 )
  7780. {// name and message are separated by ' : '
  7781. // validate name
  7782. name = text;
  7783. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7784. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7785. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7786. {
  7787. //Hacked message, or infamous "client desynchronize" issue where they pick one char while loading another.
  7788. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7789. sockt->eof(fd); // Just kick them out to correct it.
  7790. return false;
  7791. }
  7792. message = name + namelen + 3;
  7793. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7794. }
  7795. else
  7796. {// name has fixed width
  7797. if( textlen < NAME_LENGTH + 1 )
  7798. {
  7799. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7800. return false;
  7801. }
  7802. // validate name
  7803. name = text;
  7804. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7805. if (name[namelen] != '\0') {
  7806. // only restriction is that the name must be zero-terminated
  7807. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7808. return false;
  7809. }
  7810. message = name + NAME_LENGTH;
  7811. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7812. }
  7813. if (messagelen != strnlen(message, messagelen)+1) {
  7814. // the declared length must match real length
  7815. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7816. return false;
  7817. }
  7818. // verify <message> part of the packet
  7819. if (message[messagelen-1] != '\0') {
  7820. // message must be zero-terminated
  7821. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7822. return false;
  7823. }
  7824. if (messagelen > CHAT_SIZE_MAX-1) {
  7825. // messages mustn't be too long
  7826. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7827. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7828. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7829. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7830. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7831. return false;
  7832. }
  7833. *name_ = name;
  7834. *namelen_ = namelen;
  7835. *message_ = message;
  7836. *messagelen_ = messagelen;
  7837. return true;
  7838. }
  7839. void clif_channel_msg(struct channel_data *chan, struct map_session_data *sd, char *msg)
  7840. {
  7841. DBIterator *iter;
  7842. struct map_session_data *user;
  7843. unsigned short msg_len;
  7844. uint32 color;
  7845. nullpo_retv(chan);
  7846. nullpo_retv(sd);
  7847. nullpo_retv(msg);
  7848. iter = db_iterator(chan->users);
  7849. msg_len = strlen(msg) + 1;
  7850. color = channel->config->colors[chan->color];
  7851. WFIFOHEAD(sd->fd,msg_len + 12);
  7852. WFIFOW(sd->fd,0) = 0x2C1;
  7853. WFIFOW(sd->fd,2) = msg_len + 12;
  7854. WFIFOL(sd->fd,4) = 0;
  7855. WFIFOL(sd->fd,8) = RGB2BGR(color);
  7856. safestrncpy((char*)WFIFOP(sd->fd,12), msg, msg_len);
  7857. for (user = dbi_first(iter); dbi_exists(iter); user = dbi_next(iter)) {
  7858. if( user->fd == sd->fd )
  7859. continue;
  7860. WFIFOHEAD(user->fd,msg_len + 12);
  7861. memcpy(WFIFOP(user->fd,0), WFIFOP(sd->fd,0), msg_len + 12);
  7862. WFIFOSET(user->fd, msg_len + 12);
  7863. }
  7864. WFIFOSET(sd->fd, msg_len + 12);
  7865. dbi_destroy(iter);
  7866. }
  7867. void clif_channel_msg2(struct channel_data *chan, char *msg)
  7868. {
  7869. DBIterator *iter;
  7870. struct map_session_data *user;
  7871. unsigned char buf[210];
  7872. unsigned short msg_len;
  7873. uint32 color;
  7874. nullpo_retv(chan);
  7875. nullpo_retv(msg);
  7876. iter = db_iterator(chan->users);
  7877. msg_len = strlen(msg) + 1;
  7878. color = channel->config->colors[chan->color];
  7879. WBUFW(buf,0) = 0x2C1;
  7880. WBUFW(buf,2) = msg_len + 12;
  7881. WBUFL(buf,4) = 0;
  7882. WBUFL(buf,8) = RGB2BGR(color);
  7883. safestrncpy((char*)WBUFP(buf,12), msg, msg_len);
  7884. for (user = dbi_first(iter); dbi_exists(iter); user = dbi_next(iter)) {
  7885. WFIFOHEAD(user->fd,msg_len + 12);
  7886. memcpy(WFIFOP(user->fd,0), WBUFP(buf,0), msg_len + 12);
  7887. WFIFOSET(user->fd, msg_len + 12);
  7888. }
  7889. dbi_destroy(iter);
  7890. }
  7891. // ------------
  7892. // clif_parse_*
  7893. // ------------
  7894. // Parses incoming (player) connection
  7895. /// Request to connect to map-server.
  7896. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  7897. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  7898. /// There are various variants of this packet, some of them have padding between fields.
  7899. void clif_parse_WantToConnection(int fd, struct map_session_data* sd) {
  7900. struct block_list* bl;
  7901. struct auth_node* node;
  7902. int cmd, account_id, char_id, login_id1, sex;
  7903. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7904. if (sd) {
  7905. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  7906. return;
  7907. }
  7908. // Only valid packet version get here
  7909. cmd = RFIFOW(fd,0);
  7910. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  7911. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  7912. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  7913. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  7914. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  7915. if( core->runflag != MAPSERVER_ST_RUNNING ) { // not allowed
  7916. clif->authfail_fd(fd,1);// server closed
  7917. return;
  7918. }
  7919. //Check for double login.
  7920. bl = map->id2bl(account_id);
  7921. if(bl && bl->type != BL_PC) {
  7922. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7923. WFIFOHEAD(fd,packet_len(0x6a));
  7924. WFIFOW(fd,0) = 0x6a;
  7925. WFIFOB(fd,2) = 3; // Rejected by server
  7926. WFIFOSET(fd,packet_len(0x6a));
  7927. sockt->eof(fd);
  7928. return;
  7929. }
  7930. if (bl ||
  7931. ((node=chrif->search(account_id)) && //An already existing node is valid only if it is for this login.
  7932. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  7933. {
  7934. clif->authfail_fd(fd, 8); //Still recognizes last connection
  7935. return;
  7936. }
  7937. CREATE(sd, struct map_session_data, 1);
  7938. sd->fd = fd;
  7939. sd->cryptKey = (( ((( clif->cryptKey[0] * clif->cryptKey[1] ) + clif->cryptKey[2]) & 0xFFFFFFFF)
  7940. * clif->cryptKey[1] ) + clif->cryptKey[2]) & 0xFFFFFFFF;
  7941. sd->parse_cmd_func = clif->parse_cmd;
  7942. sockt->session[fd]->session_data = sd;
  7943. pc->setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7944. #if PACKETVER < 20070521
  7945. WFIFOHEAD(fd,4);
  7946. WFIFOL(fd,0) = sd->bl.id;
  7947. WFIFOSET(fd,4);
  7948. #else
  7949. WFIFOHEAD(fd,packet_len(0x283));
  7950. WFIFOW(fd,0) = 0x283;
  7951. WFIFOL(fd,2) = sd->bl.id;
  7952. WFIFOSET(fd,packet_len(0x283));
  7953. #endif
  7954. chrif->authreq(sd,false);
  7955. }
  7956. void clif_parse_LoadEndAck(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  7957. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  7958. /// 007d
  7959. void clif_parse_LoadEndAck(int fd, struct map_session_data *sd) {
  7960. bool first_time = false;
  7961. if(sd->bl.prev != NULL)
  7962. return;
  7963. if (!sd->state.active) { //Character loading is not complete yet!
  7964. //Let pc->reg_received reinvoke this when ready.
  7965. sd->state.connect_new = 0;
  7966. return;
  7967. }
  7968. if (sd->state.rewarp) { //Rewarp player.
  7969. sd->state.rewarp = 0;
  7970. clif->changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  7971. return;
  7972. }
  7973. sd->state.warping = 0;
  7974. sd->state.dialog = 0;/* reset when warping, client dialog will go missing */
  7975. // look
  7976. #if PACKETVER < 4
  7977. clif->changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7978. clif->changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7979. #else
  7980. clif->changelook(&sd->bl,LOOK_WEAPON,0);
  7981. #endif
  7982. if(sd->vd.cloth_color)
  7983. clif->refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7984. if (sd->vd.body_style)
  7985. clif->refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  7986. // item
  7987. clif->inventorylist(sd); // inventory list first, otherwise deleted items in pc->checkitem show up as 'unknown item'
  7988. pc->checkitem(sd);
  7989. // cart
  7990. if(pc_iscarton(sd)) {
  7991. clif->cartlist(sd);
  7992. clif->updatestatus(sd,SP_CARTINFO);
  7993. }
  7994. // weight
  7995. clif->updatestatus(sd,SP_WEIGHT);
  7996. clif->updatestatus(sd,SP_MAXWEIGHT);
  7997. // guild
  7998. // (needs to go before clif_spawn() to show guild emblems correctly)
  7999. if(sd->status.guild_id)
  8000. guild->send_memberinfoshort(sd,1);
  8001. if(battle_config.pc_invincible_time > 0) {
  8002. pc->setinvincibletimer(sd,battle_config.pc_invincible_time);
  8003. }
  8004. if( map->list[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8005. map->spawnmobs(sd->bl.m);
  8006. if( map->list[sd->bl.m].instance_id >= 0 ) {
  8007. instance->list[map->list[sd->bl.m].instance_id].users++;
  8008. instance->check_idle(map->list[sd->bl.m].instance_id);
  8009. }
  8010. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  8011. map->list[sd->bl.m].hpmeter_visible++;
  8012. sd->state.hpmeter_visible = 1;
  8013. }
  8014. if (!pc_isinvisible(sd)) { // increment the number of pvp players on the map
  8015. map->list[sd->bl.m].users_pvp++;
  8016. }
  8017. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8018. // reset the callshop flag if the player changes map
  8019. sd->state.callshop = 0;
  8020. map->addblock(&sd->bl);
  8021. clif->spawn(&sd->bl);
  8022. // Party
  8023. // (needs to go after clif_spawn() to show hp bars correctly)
  8024. if(sd->status.party_id) {
  8025. party->send_movemap(sd);
  8026. clif->party_hp(sd); // Show hp after displacement [LuzZza]
  8027. }
  8028. if( sd->bg_id ) clif->bg_hp(sd); // BattleGround System
  8029. if (map->list[sd->bl.m].flag.pvp && !pc_isinvisible(sd)) {
  8030. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8031. if (!map->list[sd->bl.m].flag.pvp_nocalcrank)
  8032. sd->pvp_timer = timer->add(timer->gettick()+200, pc->calc_pvprank_timer, sd->bl.id, 0);
  8033. sd->pvp_rank = 0;
  8034. sd->pvp_lastusers = 0;
  8035. sd->pvp_point = 5;
  8036. sd->pvp_won = 0;
  8037. sd->pvp_lost = 0;
  8038. }
  8039. clif->map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8040. } else
  8041. // set flag, if it's a duel [LuzZza]
  8042. if(sd->duel_group)
  8043. clif->map_property(sd, MAPPROPERTY_FREEPVPZONE);
  8044. if (map->list[sd->bl.m].flag.gvg_dungeon)
  8045. clif->map_property(sd, MAPPROPERTY_FREEPVPZONE); //TODO: Figure out the real packet to send here.
  8046. if( map_flag_gvg2(sd->bl.m) )
  8047. clif->map_property(sd, MAPPROPERTY_AGITZONE);
  8048. // info about nearby objects
  8049. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8050. map->foreachinarea(clif->getareachar, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_ALL, sd);
  8051. // pet
  8052. if( sd->pd ) {
  8053. if( battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8054. clif->message(sd->fd, msg_sd(sd,866)); // "Pets are not allowed in Guild Wars."
  8055. pet->menu(sd, 3); //Option 3 is return to egg.
  8056. } else {
  8057. map->addblock(&sd->pd->bl);
  8058. clif->spawn(&sd->pd->bl);
  8059. clif->send_petdata(sd,sd->pd,0,0);
  8060. clif->send_petstatus(sd);
  8061. //skill->unit_move(&sd->pd->bl,timer->gettick(),1);
  8062. }
  8063. }
  8064. //homunculus [blackhole89]
  8065. if( homun_alive(sd->hd) ) {
  8066. map->addblock(&sd->hd->bl);
  8067. clif->spawn(&sd->hd->bl);
  8068. clif->send_homdata(sd,SP_ACK,0);
  8069. clif->hominfo(sd,sd->hd,1);
  8070. clif->hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8071. clif->homskillinfoblock(sd);
  8072. if( battle_config.hom_setting&0x8 )
  8073. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8074. if( !(battle_config.hom_setting&0x2) )
  8075. skill->unit_move(&sd->hd->bl,timer->gettick(),1); // apply land skills immediately
  8076. }
  8077. if( sd->md ) {
  8078. map->addblock(&sd->md->bl);
  8079. clif->spawn(&sd->md->bl);
  8080. clif->mercenary_info(sd);
  8081. clif->mercenary_skillblock(sd);
  8082. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8083. }
  8084. if( sd->ed ) {
  8085. map->addblock(&sd->ed->bl);
  8086. clif->spawn(&sd->ed->bl);
  8087. clif->elemental_info(sd);
  8088. clif->elemental_updatestatus(sd,SP_HP);
  8089. clif->hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8090. clif->elemental_updatestatus(sd,SP_SP);
  8091. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8092. }
  8093. if(sd->state.connect_new) {
  8094. int lv;
  8095. first_time = true;
  8096. sd->state.connect_new = 0;
  8097. clif->skillinfoblock(sd);
  8098. clif->hotkeys(sd);
  8099. clif->updatestatus(sd,SP_BASEEXP);
  8100. clif->updatestatus(sd,SP_NEXTBASEEXP);
  8101. clif->updatestatus(sd,SP_JOBEXP);
  8102. clif->updatestatus(sd,SP_NEXTJOBEXP);
  8103. clif->updatestatus(sd,SP_SKILLPOINT);
  8104. clif->initialstatus(sd);
  8105. if (pc_isfalcon(sd))
  8106. clif->status_change(&sd->bl, SI_FALCON, 1, 0, 0, 0, 0);
  8107. if (pc_isridingpeco(sd) || pc_isridingdragon(sd))
  8108. clif->status_change(&sd->bl, SI_RIDING, 1, 0, 0, 0, 0);
  8109. else if (pc_isridingwug(sd))
  8110. clif->status_change(&sd->bl, SI_WUGRIDER, 1, 0, 0, 0, 0);
  8111. if(sd->status.manner < 0)
  8112. sc_start(NULL,&sd->bl,SC_NOCHAT,100,0,0);
  8113. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8114. if ((lv = pc->checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8115. int i;
  8116. for (i = 0; i < MAX_PC_FEELHATE; i++) {
  8117. if (sd->bl.m == sd->feel_map[i].m) {
  8118. sc_start(NULL,&sd->bl, SC_KNOWLEDGE, 100, lv, skill->get_time(SG_KNOWLEDGE, lv));
  8119. break;
  8120. }
  8121. }
  8122. }
  8123. if(sd->pd && sd->pd->pet.intimate > 900)
  8124. clif->pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet->hungry_val(sd->pd));
  8125. if(homun_alive(sd->hd))
  8126. homun->init_timers(sd->hd);
  8127. if (map->night_flag && map->list[sd->bl.m].flag.nightenabled) {
  8128. sd->state.night = 1;
  8129. clif->status_change(&sd->bl, SI_SKE, 1, 0, 0, 0, 0);
  8130. }
  8131. // Notify everyone that this char logged in [Skotlex].
  8132. map->foreachpc(clif->friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8133. //Login Event
  8134. npc->script_event(sd, NPCE_LOGIN);
  8135. } else {
  8136. //For some reason the client "loses" these on warp/map-change.
  8137. clif->updatestatus(sd,SP_STR);
  8138. clif->updatestatus(sd,SP_AGI);
  8139. clif->updatestatus(sd,SP_VIT);
  8140. clif->updatestatus(sd,SP_INT);
  8141. clif->updatestatus(sd,SP_DEX);
  8142. clif->updatestatus(sd,SP_LUK);
  8143. if (sd->state.warp_clean) {
  8144. // abort currently running script
  8145. sd->state.using_fake_npc = 0;
  8146. sd->state.menu_or_input = 0;
  8147. sd->npc_menu = 0;
  8148. if(sd->npc_id)
  8149. npc->event_dequeue(sd);
  8150. } else {
  8151. sd->state.warp_clean = 1;
  8152. }
  8153. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || ( battle_config.guild_notice_changemap == 1 && sd->state.changemap ) ) )
  8154. clif->guild_notice(sd,sd->guild);
  8155. }
  8156. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8157. #if PACKETVER >= 20070918
  8158. clif->partyinvitationstate(sd);
  8159. clif->equpcheckbox(sd);
  8160. #endif
  8161. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100)
  8162. && (map_flag_gvg2(sd->state.pmap) || map_flag_gvg2(sd->bl.m)
  8163. || map->list[sd->state.pmap].flag.battleground || map->list[sd->bl.m].flag.battleground) )
  8164. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8165. if( map->night_flag && map->list[sd->bl.m].flag.nightenabled ) {
  8166. //Display night.
  8167. if( !sd->state.night ) {
  8168. sd->state.night = 1;
  8169. clif->status_change(&sd->bl, SI_SKE, 1, 0, 0, 0, 0);
  8170. }
  8171. } else if( sd->state.night ) { //Clear night display.
  8172. sd->state.night = 0;
  8173. clif->sc_end(&sd->bl, sd->bl.id, SELF, SI_SKE);
  8174. }
  8175. if( map->list[sd->bl.m].flag.battleground ) {
  8176. clif->map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  8177. if( map->list[sd->bl.m].flag.battleground == 2 )
  8178. clif->bg_updatescore_single(sd);
  8179. }
  8180. if( map->list[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) ) {
  8181. char output[128];
  8182. sprintf(output, "[ Kill Steal Protection Disabled. KS is allowed in this map ]");
  8183. clif->broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  8184. }
  8185. map->iwall_get(sd); // Updates Walls Info on this Map to Client
  8186. status_calc_pc(sd, SCO_NONE);/* some conditions are map-dependent so we must recalculate */
  8187. sd->state.changemap = false;
  8188. if (channel->config->local && channel->config->local_autojoin) {
  8189. channel->map_join(sd);
  8190. }
  8191. if (channel->config->irc && channel->config->irc_autojoin) {
  8192. channel->irc_join(sd);
  8193. }
  8194. }
  8195. mail->clear(sd);
  8196. clif->maptypeproperty2(&sd->bl,SELF);
  8197. /* Guild Aura Init */
  8198. if( sd->state.gmaster_flag ) {
  8199. guild->aura_refresh(sd,GD_LEADERSHIP,guild->checkskill(sd->guild,GD_LEADERSHIP));
  8200. guild->aura_refresh(sd,GD_GLORYWOUNDS,guild->checkskill(sd->guild,GD_GLORYWOUNDS));
  8201. guild->aura_refresh(sd,GD_SOULCOLD,guild->checkskill(sd->guild,GD_SOULCOLD));
  8202. guild->aura_refresh(sd,GD_HAWKEYES,guild->checkskill(sd->guild,GD_HAWKEYES));
  8203. }
  8204. if( sd->state.vending ) { /* show we have a vending */
  8205. clif->openvending(sd,sd->bl.id,sd->vending);
  8206. clif->showvendingboard(&sd->bl,sd->message,0);
  8207. }
  8208. if(map->list[sd->bl.m].flag.loadevent) // Lance
  8209. npc->script_event(sd, NPCE_LOADMAP);
  8210. if (pc->checkskill(sd, SG_DEVIL) && !pc->nextjobexp(sd)) //blindness [Komurka]
  8211. clif->sc_end(&sd->bl, sd->bl.id, SELF, SI_DEVIL1);
  8212. if (sd->sc.opt2) //Client loses these on warp.
  8213. clif->changeoption(&sd->bl);
  8214. if( sd->sc.data[SC_MONSTER_TRANSFORM] && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m) ){
  8215. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  8216. clif->message(sd->fd, msg_sd(sd,1488)); // Transforming into monster is not allowed in Guild Wars.
  8217. }
  8218. clif->weather_check(sd);
  8219. // This should be displayed last
  8220. if( sd->guild && first_time )
  8221. clif->guild_notice(sd, sd->guild);
  8222. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  8223. if (map->getcell(sd->bl.m, &sd->bl, sd->bl.x, sd->bl.y, CELL_CHKNPC))
  8224. npc->touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8225. else
  8226. npc->untouch_areanpc(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8227. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  8228. if( !sd->status.hp && !pc_isdead(sd) && status->isdead(&sd->bl) )
  8229. pc_setdead(sd);
  8230. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  8231. if(pc_isdead(sd))
  8232. clif->clearunit_area(&sd->bl, CLR_DEAD);
  8233. else {
  8234. skill->usave_trigger(sd);
  8235. sd->ud.dir = 0;/* enforce north-facing (not visually, virtually) */
  8236. }
  8237. // Trigger skill effects if you appear standing on them
  8238. if(!battle_config.pc_invincible_time)
  8239. skill->unit_move(&sd->bl,timer->gettick(),1);
  8240. // NPC Quest / Event Icon Check [Kisuka]
  8241. #if PACKETVER >= 20090218
  8242. {
  8243. int i;
  8244. for(i = 0; i < map->list[sd->bl.m].qi_count; i++) {
  8245. struct questinfo *qi = &map->list[sd->bl.m].qi_data[i];
  8246. if( quest->check(sd, qi->quest_id, HAVEQUEST) == -1 ) {// Check if quest is not started
  8247. if( qi->hasJob ) { // Check if quest is job-specific, check is user is said job class.
  8248. if( sd->class_ == qi->job )
  8249. clif->quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8250. } else {
  8251. clif->quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
  8252. }
  8253. }
  8254. }
  8255. }
  8256. #endif
  8257. }
  8258. /// Server's tick (ZC_NOTIFY_TIME).
  8259. /// 007f <time>.L
  8260. void clif_notify_time(struct map_session_data* sd, int64 time) {
  8261. int fd;
  8262. nullpo_retv(sd);
  8263. fd = sd->fd;
  8264. WFIFOHEAD(fd,packet_len(0x7f));
  8265. WFIFOW(fd,0) = 0x7f;
  8266. WFIFOL(fd,2) = (uint32)time;
  8267. WFIFOSET(fd,packet_len(0x7f));
  8268. }
  8269. void clif_parse_TickSend(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8270. /// Request for server's tick.
  8271. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  8272. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  8273. /// There are various variants of this packet, some of them have padding between fields.
  8274. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  8275. {
  8276. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  8277. clif->notify_time(sd, timer->gettick());
  8278. }
  8279. /// Sends hotkey bar.
  8280. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  8281. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  8282. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  8283. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  8284. void clif_hotkeys_send(struct map_session_data *sd) {
  8285. #ifdef HOTKEY_SAVING
  8286. struct packet_hotkey p;
  8287. int i;
  8288. nullpo_retv(sd);
  8289. p.PacketType = hotkeyType;
  8290. #if PACKETVER >= 20141022
  8291. p.Rotate = sd->status.hotkey_rowshift;
  8292. #endif
  8293. for(i = 0; i < ARRAYLENGTH(p.hotkey); i++) {
  8294. p.hotkey[i].isSkill = sd->status.hotkeys[i].type;
  8295. p.hotkey[i].ID = sd->status.hotkeys[i].id;
  8296. p.hotkey[i].count = sd->status.hotkeys[i].lv;
  8297. }
  8298. clif->send(&p, sizeof(p), &sd->bl, SELF);
  8299. #endif
  8300. }
  8301. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8302. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd)
  8303. {
  8304. int cmd = RFIFOW(fd, 0);
  8305. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[cmd].pos[0]);
  8306. }
  8307. void clif_parse_Hotkey(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8308. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  8309. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  8310. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  8311. #ifdef HOTKEY_SAVING
  8312. unsigned short idx;
  8313. int cmd;
  8314. cmd = RFIFOW(fd, 0);
  8315. idx = RFIFOW(fd, packet_db[cmd].pos[0]);
  8316. if (idx >= MAX_HOTKEYS) return;
  8317. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[cmd].pos[1]);
  8318. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[cmd].pos[2]);
  8319. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[cmd].pos[3]);
  8320. #endif
  8321. }
  8322. /// Displays cast-like progress bar (ZC_PROGRESS).
  8323. /// 02f0 <color>.L <time>.L
  8324. /* TODO ZC_PROGRESS_ACTOR <account_id>.L */
  8325. void clif_progressbar(struct map_session_data * sd, unsigned int color, unsigned int second)
  8326. {
  8327. int fd;
  8328. nullpo_retv(sd);
  8329. fd = sd->fd;
  8330. WFIFOHEAD(fd,packet_len(0x2f0));
  8331. WFIFOW(fd,0) = 0x2f0;
  8332. WFIFOL(fd,2) = color;
  8333. WFIFOL(fd,6) = second;
  8334. WFIFOSET(fd,packet_len(0x2f0));
  8335. }
  8336. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  8337. /// 02f2
  8338. void clif_progressbar_abort(struct map_session_data * sd)
  8339. {
  8340. int fd;
  8341. nullpo_retv(sd);
  8342. fd = sd->fd;
  8343. WFIFOHEAD(fd,packet_len(0x2f2));
  8344. WFIFOW(fd,0) = 0x2f2;
  8345. WFIFOSET(fd,packet_len(0x2f2));
  8346. }
  8347. void clif_parse_progressbar(int fd, struct map_session_data * sd) __attribute__((nonnull (2)));
  8348. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  8349. /// 02f1
  8350. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  8351. {
  8352. int npc_id = sd->progressbar.npc_id;
  8353. if( timer->gettick() < sd->progressbar.timeout && sd->st )
  8354. sd->st->state = END;
  8355. sd->progressbar.timeout = sd->state.workinprogress = sd->progressbar.npc_id = 0;
  8356. npc->scriptcont(sd, npc_id, false);
  8357. }
  8358. void clif_parse_WalkToXY(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8359. /// Request to walk to a certain position on the current map.
  8360. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  8361. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  8362. /// There are various variants of this packet, some of them have padding between fields.
  8363. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  8364. {
  8365. short x, y;
  8366. if (pc_isdead(sd)) {
  8367. clif->clearunit_area(&sd->bl, CLR_DEAD);
  8368. return;
  8369. }
  8370. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  8371. ; //You CAN walk on this OPT1 value.
  8372. /*else if( sd->progressbar.npc_id )
  8373. clif->progressbar_abort(sd);*/
  8374. else if (pc_cant_act(sd))
  8375. return;
  8376. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  8377. return;
  8378. pc->delinvincibletimer(sd);
  8379. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  8380. //Set last idle time... [Skotlex]
  8381. pc->update_idle_time(sd, BCIDLE_WALK);
  8382. unit->walktoxy(&sd->bl, x, y, 4);
  8383. }
  8384. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  8385. /// 018b <result>.W
  8386. /// result:
  8387. /// 0 = disconnect (quit)
  8388. /// 1 = cannot disconnect (wait 10 seconds)
  8389. /// ? = ignored
  8390. void clif_disconnect_ack(struct map_session_data* sd, short result)
  8391. {
  8392. int fd;
  8393. nullpo_retv(sd);
  8394. fd = sd->fd;
  8395. WFIFOHEAD(fd,packet_len(0x18b));
  8396. WFIFOW(fd,0) = 0x18b;
  8397. WFIFOW(fd,2) = result;
  8398. WFIFOSET(fd,packet_len(0x18b));
  8399. }
  8400. void clif_parse_QuitGame(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8401. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  8402. /// 018a <type>.W
  8403. /// type:
  8404. /// 0 = quit
  8405. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  8406. {
  8407. /* Rovert's prevent logout option fixed [Valaris] */
  8408. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC__INVISIBILITY] &&
  8409. (!battle_config.prevent_logout || DIFF_TICK(timer->gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  8410. {
  8411. sockt->eof(fd);
  8412. clif->disconnect_ack(sd, 0);
  8413. } else {
  8414. clif->disconnect_ack(sd, 1);
  8415. }
  8416. }
  8417. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8418. /// Requesting unit's name.
  8419. /// 0094 <id>.L (CZ_REQNAME)
  8420. /// 0368 <id>.L (CZ_REQNAME2)
  8421. /// There are various variants of this packet, some of them have padding between fields.
  8422. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) {
  8423. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  8424. struct block_list* bl;
  8425. //struct status_change *sc;
  8426. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  8427. id = sd->bl.id;
  8428. bl = map->id2bl(id);
  8429. if( bl == NULL )
  8430. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  8431. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  8432. return; // Block namerequests past view range
  8433. // 'see people in GM hide' cheat detection
  8434. #if 0 /* disabled due to false positives (network lag + request name of char that's about to hide = race condition) */
  8435. sc = status->get_sc(bl);
  8436. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  8437. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  8438. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  8439. ) {
  8440. char gm_msg[256];
  8441. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target (id: %d).\n", sd->status.name, sd->status.account_id, id);
  8442. ShowWarning(gm_msg);
  8443. // information is sent to all online GMs
  8444. intif->wis_message_to_gm(map->wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  8445. return;
  8446. }
  8447. #endif // 0
  8448. clif->charnameack(fd, bl);
  8449. }
  8450. int clif_undisguise_timer(int tid, int64 tick, int id, intptr_t data) {
  8451. struct map_session_data * sd;
  8452. if( (sd = map->id2sd(id)) ) {
  8453. sd->fontcolor_tid = INVALID_TIMER;
  8454. if( sd->fontcolor && sd->disguise == sd->status.class_ )
  8455. pc->disguise(sd,-1);
  8456. }
  8457. return 0;
  8458. }
  8459. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  8460. /// Validates and processes global messages
  8461. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  8462. /// There are various variants of this packet.
  8463. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  8464. {
  8465. const char* text = (char*)RFIFOP(fd,4);
  8466. size_t textlen = RFIFOW(fd,2) - 4;
  8467. char *name, *message, *fakename = NULL;
  8468. size_t namelen, messagelen;
  8469. bool is_fake;
  8470. // validate packet and retrieve name and message
  8471. if( !clif->process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8472. return;
  8473. if( atcommand->exec(fd, sd, message, true) )
  8474. return;
  8475. if( !pc->can_talk(sd) )
  8476. return;
  8477. if( battle_config.min_chat_delay ) { //[Skotlex]
  8478. if (DIFF_TICK(sd->cantalk_tick, timer->gettick()) > 0)
  8479. return;
  8480. sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
  8481. }
  8482. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  8483. unsigned int next = pc->nextbaseexp(sd);
  8484. if( next == 0 ) next = pc->thisbaseexp(sd);
  8485. if( next ) { // 0%, 10%, 20%, ...
  8486. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  8487. if( (battle_config.snovice_call_type || percent) && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  8488. switch (sd->state.snovice_call_flag) {
  8489. case 0:
  8490. if( strstr(message, msg_txt(1479)) ) // "Dear angel, can you hear my voice?"
  8491. sd->state.snovice_call_flag = 1;
  8492. break;
  8493. case 1: {
  8494. char buf[256];
  8495. snprintf(buf, 256, msg_txt(1480), sd->status.name);
  8496. if( strstr(message, buf) ) // "I am %s Super Novice~"
  8497. sd->state.snovice_call_flag = 2;
  8498. }
  8499. break;
  8500. case 2:
  8501. if( strstr(message, msg_txt(1481)) ) // "Help me out~ Please~ T_T"
  8502. sd->state.snovice_call_flag = 3;
  8503. break;
  8504. case 3:
  8505. sc_start(NULL,&sd->bl, status->skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill->get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  8506. clif->skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  8507. sd->state.snovice_call_flag = 0;
  8508. break;
  8509. }
  8510. }
  8511. }
  8512. }
  8513. pc->update_idle_time(sd, BCIDLE_CHAT);
  8514. if( sd->gcbind ) {
  8515. channel->send(sd->gcbind,sd,message);
  8516. return;
  8517. } else if ( sd->fontcolor && !sd->chatID ) {
  8518. char mout[200];
  8519. unsigned char mylen = 1;
  8520. uint32 color = 0;
  8521. if( sd->disguise == -1 ) {
  8522. sd->fontcolor_tid = timer->add(timer->gettick()+5000, clif->undisguise_timer, sd->bl.id, 0);
  8523. pc->disguise(sd,sd->status.class_);
  8524. if( pc_isdead(sd) )
  8525. clif->clearunit_single(-sd->bl.id, CLR_DEAD, sd->fd);
  8526. if( unit->is_walking(&sd->bl) )
  8527. clif->move(&sd->ud);
  8528. } else if ( sd->disguise == sd->status.class_ && sd->fontcolor_tid != INVALID_TIMER ) {
  8529. const struct TimerData *td;
  8530. if( (td = timer->get(sd->fontcolor_tid)) ) {
  8531. timer->settick(sd->fontcolor_tid, td->tick+5000);
  8532. }
  8533. }
  8534. mylen += snprintf(mout, 200, "%s : %s",sd->fakename[0]?sd->fakename:sd->status.name,message);
  8535. color = channel->config->colors[sd->fontcolor - 1];
  8536. WFIFOHEAD(fd,mylen + 12);
  8537. WFIFOW(fd,0) = 0x2C1;
  8538. WFIFOW(fd,2) = mylen + 12;
  8539. WFIFOL(fd,4) = sd->bl.id;
  8540. WFIFOL(fd,8) = RGB2BGR(color);
  8541. safestrncpy((char*)WFIFOP(fd,12), mout, mylen);
  8542. clif->send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, AREA_WOS);
  8543. WFIFOL(fd,4) = -sd->bl.id;
  8544. WFIFOSET(fd, mylen + 12);
  8545. return;
  8546. }
  8547. /**
  8548. * Fake Name Design by FatalEror (bug report #9)
  8549. **/
  8550. if( ( is_fake = ( sd->fakename[0] ) ) ) {
  8551. fakename = (char*) aMalloc(strlen(sd->fakename)+messagelen+3);
  8552. strcpy(fakename, sd->fakename);
  8553. strcat(fakename, " : ");
  8554. strcat(fakename, message);
  8555. textlen = strlen(fakename) + 1;
  8556. }
  8557. // send message to others (using the send buffer for temp. storage)
  8558. WFIFOHEAD(fd, 8 + textlen);
  8559. WFIFOW(fd,0) = 0x8d;
  8560. WFIFOW(fd,2) = 8 + textlen;
  8561. WFIFOL(fd,4) = sd->bl.id;
  8562. safestrncpy((char*)WFIFOP(fd,8), is_fake ? fakename : text, textlen);
  8563. //FIXME: chat has range of 9 only
  8564. clif->send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  8565. // send back message to the speaker
  8566. if( is_fake ) {
  8567. WFIFOW(fd,0) = 0x8e;
  8568. WFIFOW(fd,2) = textlen + 4;
  8569. safestrncpy((char*)WFIFOP(fd,4), fakename, textlen);
  8570. aFree(fakename);
  8571. } else {
  8572. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  8573. WFIFOW(fd,0) = 0x8e;
  8574. }
  8575. WFIFOSET(fd, WFIFOW(fd,2));
  8576. // Chat logging type 'O' / Global Chat
  8577. logs->chat(LOG_CHAT_GLOBAL, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  8578. // trigger listening npcs
  8579. map->foreachinrange(npc_chat->sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  8580. }
  8581. void clif_parse_MapMove(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8582. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  8583. /// Request to warp to a map on given coordinates.
  8584. /// 0140 <map name>.16B <x>.W <y>.W
  8585. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  8586. {
  8587. char command[MAP_NAME_LENGTH_EXT+25];
  8588. char* map_name;
  8589. map_name = (char*)RFIFOP(fd,2);
  8590. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  8591. sprintf(command, "%cmapmove %s %d %d", atcommand->at_symbol, map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  8592. atcommand->exec(fd, sd, command, true);
  8593. }
  8594. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  8595. /// 009c <id>.L <head dir>.W <dir>.B
  8596. /// head dir:
  8597. /// 0 = straight
  8598. /// 1 = turned CW
  8599. /// 2 = turned CCW
  8600. /// dir:
  8601. /// 0 = north
  8602. /// 1 = northwest
  8603. /// 2 = west
  8604. /// 3 = southwest
  8605. /// 4 = south
  8606. /// 5 = southeast
  8607. /// 6 = east
  8608. /// 7 = northeast
  8609. void clif_changed_dir(struct block_list *bl, enum send_target target)
  8610. {
  8611. unsigned char buf[64];
  8612. nullpo_retv(bl);
  8613. WBUFW(buf,0) = 0x9c;
  8614. WBUFL(buf,2) = bl->id;
  8615. WBUFW(buf,6) = bl->type == BL_PC ? BL_UCCAST(BL_PC, bl)->head_dir : 0;
  8616. WBUFB(buf,8) = unit->getdir(bl);
  8617. clif->send(buf, packet_len(0x9c), bl, target);
  8618. if (disguised(bl)) {
  8619. WBUFL(buf,2) = -bl->id;
  8620. WBUFW(buf,6) = 0;
  8621. clif->send(buf, packet_len(0x9c), bl, SELF);
  8622. }
  8623. }
  8624. void clif_parse_ChangeDir(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8625. /// Request to change own body and head direction.
  8626. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  8627. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  8628. /// There are various variants of this packet, some of them have padding between fields.
  8629. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  8630. {
  8631. unsigned char headdir, dir;
  8632. headdir = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  8633. dir = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  8634. pc_setdir(sd, dir, headdir);
  8635. clif->changed_dir(&sd->bl, AREA_WOS);
  8636. }
  8637. void clif_parse_Emotion(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8638. /// Request to show an emotion (CZ_REQ_EMOTION).
  8639. /// 00bf <type>.B
  8640. /// type:
  8641. /// @see enum emotion_type
  8642. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  8643. {
  8644. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  8645. if (battle_config.basic_skill_check == 0 || pc->checkskill(sd, NV_BASIC) >= 2) {
  8646. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  8647. clif->skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8648. return;
  8649. }
  8650. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  8651. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  8652. sd->emotionlasttime = time(NULL);
  8653. clif->skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8654. return;
  8655. }
  8656. sd->emotionlasttime = time(NULL);
  8657. pc->update_idle_time(sd, BCIDLE_EMOTION);
  8658. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  8659. emoticon = rnd()%6+E_DICE1;
  8660. }
  8661. clif->emotion(&sd->bl, emoticon);
  8662. } else
  8663. clif->skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  8664. }
  8665. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  8666. /// 00c2 <count>.L
  8667. void clif_user_count(struct map_session_data* sd, int count) {
  8668. int fd;
  8669. nullpo_retv(sd);
  8670. fd = sd->fd;
  8671. WFIFOHEAD(fd,packet_len(0xc2));
  8672. WFIFOW(fd,0) = 0xc2;
  8673. WFIFOL(fd,2) = count;
  8674. WFIFOSET(fd,packet_len(0xc2));
  8675. }
  8676. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8677. /// /w /who (CZ_REQ_USER_COUNT).
  8678. /// Request to display amount of currently connected players.
  8679. /// 00c1
  8680. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) {
  8681. clif->user_count(sd, map->getusers());
  8682. }
  8683. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, int64 tick)
  8684. {
  8685. nullpo_retv(sd);
  8686. if (pc_isdead(sd)) {
  8687. clif->clearunit_area(&sd->bl, CLR_DEAD);
  8688. return;
  8689. }
  8690. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  8691. // (not all are included in pc_can_attack)
  8692. if( sd->sc.count && (
  8693. sd->sc.data[SC_TRICKDEAD] ||
  8694. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  8695. sd->sc.data[SC_BLADESTOP] ||
  8696. sd->sc.data[SC_DEEP_SLEEP] )
  8697. )
  8698. return;
  8699. if(action_type != 0x00 && action_type != 0x07)
  8700. pc_stop_walking(sd, STOPWALKING_FLAG_FIXPOS);
  8701. pc_stop_attack(sd);
  8702. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8703. target_id = sd->bl.id;
  8704. switch(action_type) {
  8705. case 0x00: // once attack
  8706. case 0x07: // continuous attack
  8707. {
  8708. struct npc_data *nd = map->id2nd(target_id);
  8709. if (nd != NULL) {
  8710. npc->click(sd, nd);
  8711. return;
  8712. }
  8713. if( pc_cant_act(sd) || pc_issit(sd) || sd->sc.option&OPTION_HIDE )
  8714. return;
  8715. if( sd->sc.option&OPTION_COSTUME )
  8716. return;
  8717. if (!battle_config.sdelay_attack_enable && pc->checkskill(sd, SA_FREECAST) <= 0) {
  8718. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8719. clif->skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  8720. return;
  8721. }
  8722. }
  8723. pc->delinvincibletimer(sd);
  8724. pc->update_idle_time(sd, BCIDLE_ATTACK);
  8725. unit->attack(&sd->bl, target_id, action_type != 0);
  8726. }
  8727. break;
  8728. case 0x02: // sitdown
  8729. if (battle_config.basic_skill_check && pc->checkskill(sd, NV_BASIC) < 3) {
  8730. clif->skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  8731. break;
  8732. }
  8733. if (sd->sc.data[SC_SITDOWN_FORCE] || sd->sc.data[SC_BANANA_BOMB_SITDOWN_POSTDELAY])
  8734. return;
  8735. if(pc_issit(sd)) {
  8736. //Bugged client? Just refresh them.
  8737. clif->sitting(&sd->bl);
  8738. return;
  8739. }
  8740. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_BURNING ))
  8741. break;
  8742. if (sd->sc.count && (
  8743. sd->sc.data[SC_DANCING] ||
  8744. sd->sc.data[SC_ANKLESNARE] ||
  8745. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  8746. )) //No sitting during these states either.
  8747. break;
  8748. pc->update_idle_time(sd, BCIDLE_SIT);
  8749. pc_setsit(sd);
  8750. skill->sit(sd,1);
  8751. clif->sitting(&sd->bl);
  8752. break;
  8753. case 0x03: // standup
  8754. if (sd->sc.data[SC_SITDOWN_FORCE] || sd->sc.data[SC_BANANA_BOMB_SITDOWN_POSTDELAY])
  8755. return;
  8756. if (!pc_issit(sd)) {
  8757. //Bugged client? Just refresh them.
  8758. clif->standing(&sd->bl);
  8759. return;
  8760. }
  8761. pc->update_idle_time(sd, BCIDLE_SIT);
  8762. pc->setstand(sd);
  8763. skill->sit(sd,0);
  8764. clif->standing(&sd->bl);
  8765. break;
  8766. }
  8767. }
  8768. void clif_parse_ActionRequest(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8769. /// Request for an action.
  8770. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  8771. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  8772. /// action:
  8773. /// 0 = attack
  8774. /// 1 = pick up item
  8775. /// 2 = sit down
  8776. /// 3 = stand up
  8777. /// 7 = continuous attack
  8778. /// 12 = (touch skill?)
  8779. /// There are various variants of this packet, some of them have padding between fields.
  8780. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  8781. {
  8782. clif->pActionRequest_sub(sd,
  8783. RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]),
  8784. RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]),
  8785. timer->gettick()
  8786. );
  8787. }
  8788. void clif_parse_Restart(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8789. /// Response to the death/system menu (CZ_RESTART).
  8790. /// 00b2 <type>.B
  8791. /// type:
  8792. /// 0 = restart (respawn)
  8793. /// 1 = char-select (disconnect)
  8794. void clif_parse_Restart(int fd, struct map_session_data *sd) {
  8795. switch(RFIFOB(fd,2)) {
  8796. case 0x00:
  8797. pc->respawn(sd,CLR_OUTSIGHT);
  8798. break;
  8799. case 0x01:
  8800. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8801. if (!sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK]
  8802. && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC__INVISIBILITY]
  8803. && (!battle_config.prevent_logout || DIFF_TICK(timer->gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  8804. ) {
  8805. //Send to char-server for character selection.
  8806. chrif->charselectreq(sd, sockt->session[fd]->client_addr);
  8807. } else {
  8808. clif->disconnect_ack(sd, 1);
  8809. }
  8810. break;
  8811. }
  8812. }
  8813. void clif_parse_WisMessage(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  8814. /// Validates and processes whispered messages (CZ_WHISPER).
  8815. /// 0096 <packet len>.W <nick>.24B <message>.?B
  8816. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8817. {
  8818. struct map_session_data* dstsd;
  8819. int i;
  8820. char *target, *message;
  8821. size_t namelen, messagelen;
  8822. // validate packet and retrieve name and message
  8823. if( !clif->process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8824. return;
  8825. if ( atcommand->exec(fd, sd, message, true) )
  8826. return;
  8827. // Statuses that prevent the player from whispering
  8828. if( !pc->can_talk(sd) )
  8829. return;
  8830. if (battle_config.min_chat_delay) { //[Skotlex]
  8831. if (DIFF_TICK(sd->cantalk_tick, timer->gettick()) > 0) {
  8832. return;
  8833. }
  8834. sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
  8835. }
  8836. pc->update_idle_time(sd, BCIDLE_CHAT);
  8837. // Chat logging type 'W' / Whisper
  8838. logs->chat(LOG_CHAT_WHISPER, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  8839. //-------------------------------------------------------//
  8840. // Lordalfa - Paperboy - To whisper NPC commands //
  8841. //-------------------------------------------------------//
  8842. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4)) {
  8843. char* str = target+4; //Skip the NPC: string part.
  8844. struct npc_data *nd;
  8845. if ((nd = npc->name2id(str))) {
  8846. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  8847. char *split;
  8848. char output[256];
  8849. str = message;
  8850. // skip codepage indicator, if detected
  8851. if( str[0] == '|' && strlen(str) >= 4 )
  8852. str += 3;
  8853. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  8854. split = strchr(str,'#');
  8855. if( split == NULL ) { // use the remaining string
  8856. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8857. for( ++i; i < NUM_WHISPER_VAR; ++i )
  8858. split_data[i][0] = '\0';
  8859. break;
  8860. }
  8861. *split = '\0';
  8862. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8863. str = split+1;
  8864. }
  8865. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  8866. sprintf(output, "@whispervar%d$", i);
  8867. script->set_var(sd,output,(char *) split_data[i]);
  8868. }
  8869. sprintf(output, "%s::OnWhisperGlobal", nd->exname);
  8870. npc->event(sd,output,0); // Calls the NPC label
  8871. return;
  8872. }
  8873. } else if( target[0] == '#' ) {
  8874. char *chname = target;
  8875. struct channel_data *chan = channel->search(chname, sd);
  8876. if (chan) {
  8877. int k;
  8878. ARR_FIND(0, sd->channel_count, k, sd->channels[k] == chan);
  8879. if (k < sd->channel_count || channel->join(chan, sd, "", true) == HCS_STATUS_OK) {
  8880. channel->send(chan,sd,message);
  8881. } else {
  8882. clif->message(fd, msg_fd(fd,1402));
  8883. }
  8884. return;
  8885. } else if (strcmpi(&chname[1], channel->config->ally_name) == 0) {
  8886. clif->message(fd, msg_fd(fd,1294)); // You're not allowed to talk on this channel
  8887. return;
  8888. }
  8889. }
  8890. // searching destination character
  8891. dstsd = map->nick2sd(target);
  8892. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  8893. // player is not on this map-server
  8894. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8895. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8896. // and if we ask for 'Test', we must not contact 'test' player
  8897. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8898. intif->wis_message(sd, target, message, messagelen);
  8899. return;
  8900. }
  8901. // if player ignores everyone
  8902. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  8903. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  8904. clif->wis_end(fd, 1); // 1: target character is not logged in
  8905. else
  8906. clif->wis_end(fd, 3); // 3: everyone ignored by target
  8907. return;
  8908. }
  8909. // if player is autotrading
  8910. if( dstsd->state.autotrade ) {
  8911. char output[256];
  8912. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8913. clif->wis_message(fd, map->wisp_server_name, output, strlen(output) + 1);
  8914. return;
  8915. }
  8916. if( pc_get_group_level(sd) <= pc_get_group_level(dstsd) ) {
  8917. // if player ignores the source character
  8918. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8919. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  8920. clif->wis_end(fd, 2); // 2: ignored by target
  8921. return;
  8922. }
  8923. }
  8924. // notify sender of success
  8925. clif->wis_end(fd, 0); // 0: success to send wisper
  8926. // Normal message
  8927. clif->wis_message(dstsd->fd, sd->status.name, message, messagelen);
  8928. }
  8929. void clif_parse_Broadcast(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  8930. /// /b /nb (CZ_BROADCAST).
  8931. /// Request to broadcast a message on whole server.
  8932. /// 0099 <packet len>.W <text>.?B 00
  8933. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  8934. char command[CHAT_SIZE_MAX+11];
  8935. char* msg = (char*)RFIFOP(fd,4);
  8936. unsigned int len = RFIFOW(fd,2)-4;
  8937. // as the length varies depending on the command used, just block unreasonably long strings
  8938. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8939. sprintf(command, "%ckami %s", atcommand->at_symbol, msg);
  8940. atcommand->exec(fd, sd, command, true);
  8941. }
  8942. void clif_parse_TakeItem(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8943. /// Request to pick up an item.
  8944. /// 009f <id>.L (CZ_ITEM_PICKUP)
  8945. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  8946. /// There are various variants of this packet, some of them have padding between fields.
  8947. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  8948. {
  8949. int map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  8950. struct flooritem_data *fitem = map->id2fi(map_object_id);
  8951. do {
  8952. if (pc_isdead(sd)) {
  8953. clif->clearunit_area(&sd->bl, CLR_DEAD);
  8954. break;
  8955. }
  8956. if (fitem == NULL || fitem->bl.m != sd->bl.m)
  8957. break;
  8958. if( sd->sc.count && (
  8959. sd->sc.data[SC_HIDING] ||
  8960. sd->sc.data[SC_CLOAKING] ||
  8961. sd->sc.data[SC_TRICKDEAD] ||
  8962. sd->sc.data[SC_BLADESTOP] ||
  8963. sd->sc.data[SC_CLOAKINGEXCEED] ||
  8964. pc_ismuted(&sd->sc, MANNER_NOITEM)
  8965. ) )
  8966. break;
  8967. if (pc_cant_act(sd))
  8968. break;
  8969. if (!pc->takeitem(sd, fitem))
  8970. break;
  8971. return;
  8972. } while (0);
  8973. // Client REQUIRES a fail packet or you can no longer pick items.
  8974. clif->additem(sd,0,0,6);
  8975. }
  8976. void clif_parse_DropItem(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  8977. /// Request to drop an item.
  8978. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  8979. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  8980. /// There are various variants of this packet, some of them have padding between fields.
  8981. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  8982. {
  8983. int item_index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  8984. int item_amount = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  8985. for(;;) {
  8986. if (pc_isdead(sd))
  8987. break;
  8988. if ( pc_cant_act2(sd) || sd->state.vending )
  8989. break;
  8990. if (sd->sc.count && (
  8991. sd->sc.data[SC_AUTOCOUNTER] ||
  8992. sd->sc.data[SC_BLADESTOP] ||
  8993. pc_ismuted(&sd->sc, MANNER_NOITEM)
  8994. ))
  8995. break;
  8996. if (!pc->dropitem(sd, item_index, item_amount))
  8997. break;
  8998. pc->update_idle_time(sd, BCIDLE_DROPITEM);
  8999. return;
  9000. }
  9001. //Because the client does not like being ignored.
  9002. clif->dropitem(sd, item_index, 0);
  9003. }
  9004. void clif_parse_UseItem(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  9005. /// Request to use an item.
  9006. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9007. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9008. /// There are various variants of this packet, some of them have padding between fields.
  9009. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9010. {
  9011. int n;
  9012. if (pc_isdead(sd)) {
  9013. clif->clearunit_area(&sd->bl, CLR_DEAD);
  9014. return;
  9015. }
  9016. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9017. return;
  9018. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9019. pc->update_idle_time(sd, BCIDLE_USEITEM);
  9020. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9021. if (n < 0 || n >= MAX_INVENTORY)
  9022. return;
  9023. if (!pc->useitem(sd,n))
  9024. clif->useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9025. }
  9026. void clif_parse_EquipItem(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9027. /// Request to equip an item (CZ_REQ_WEAR_EQUIP).
  9028. /// 00a9 <index>.W <position>.W
  9029. /// 0998 <index>.W <position>.L
  9030. void clif_parse_EquipItem(int fd,struct map_session_data *sd) {
  9031. struct packet_equip_item *p = P2PTR(fd);
  9032. if(pc_isdead(sd)) {
  9033. clif->clearunit_area(&sd->bl,CLR_DEAD);
  9034. return;
  9035. }
  9036. p->index = p->index - 2;
  9037. if (p->index >= MAX_INVENTORY)
  9038. return; //Out of bounds check.
  9039. if( sd->npc_id ) {
  9040. if ( !sd->npc_item_flag )
  9041. return;
  9042. } else if (sd->state.storage_flag != STORAGE_FLAG_CLOSED || sd->sc.opt1)
  9043. ; //You can equip/unequip stuff while storage is open/under status changes
  9044. else if ( pc_cant_act2(sd) || sd->state.prerefining )
  9045. return;
  9046. if(!sd->status.inventory[p->index].identify) {
  9047. clif->equipitemack(sd,p->index,0,EIA_FAIL);// fail
  9048. return;
  9049. }
  9050. if(!sd->inventory_data[p->index])
  9051. return;
  9052. if(sd->inventory_data[p->index]->type == IT_PETARMOR){
  9053. pet->equipitem(sd,p->index);
  9054. return;
  9055. }
  9056. pc->update_idle_time(sd, BCIDLE_USEITEM);
  9057. //Client doesn't send the position for ammo.
  9058. if(sd->inventory_data[p->index]->type == IT_AMMO)
  9059. pc->equipitem(sd,p->index,EQP_AMMO);
  9060. else
  9061. pc->equipitem(sd,p->index,p->wearLocation);
  9062. }
  9063. void clif_parse_UnequipItem(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9064. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9065. /// 00ab <index>.W
  9066. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9067. {
  9068. int index;
  9069. if(pc_isdead(sd)) {
  9070. clif->clearunit_area(&sd->bl,CLR_DEAD);
  9071. return;
  9072. }
  9073. if( sd->npc_id ) {
  9074. if ( !sd->npc_item_flag )
  9075. return;
  9076. } else if (sd->state.storage_flag != STORAGE_FLAG_CLOSED || sd->sc.opt1)
  9077. ; //You can equip/unequip stuff while storage is open/under status changes
  9078. else if ( pc_cant_act2(sd) || sd->state.prerefining )
  9079. return;
  9080. index = RFIFOW(fd,2)-2;
  9081. pc->update_idle_time(sd, BCIDLE_USEITEM);
  9082. pc->unequipitem(sd,index, PCUNEQUIPITEM_RECALC);
  9083. }
  9084. void clif_parse_NpcClicked(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9085. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9086. /// 0090 <id>.L <type>.B
  9087. /// type:
  9088. /// 1 = click
  9089. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9090. {
  9091. struct block_list *bl;
  9092. if( pc_isdead(sd) ) {
  9093. clif->clearunit_area(&sd->bl,CLR_DEAD);
  9094. return;
  9095. }
  9096. if( sd->npc_id || sd->state.workinprogress&2 ){
  9097. #ifdef RENEWAL
  9098. clif->msgtable(sd, MSG_NPC_WORK_IN_PROGRESS); // TODO look for the client date that has this message.
  9099. #endif
  9100. return;
  9101. }
  9102. if ( pc_cant_act2(sd) || !(bl = map->id2bl(RFIFOL(fd,2))) || sd->state.vending )
  9103. return;
  9104. switch (bl->type) {
  9105. case BL_MOB:
  9106. case BL_PC:
  9107. clif->pActionRequest_sub(sd, 0x07, bl->id, timer->gettick());
  9108. break;
  9109. case BL_NPC:
  9110. if( sd->ud.skill_id < RK_ENCHANTBLADE && sd->ud.skilltimer != INVALID_TIMER ) {// TODO: should only work with none 3rd job skills
  9111. #ifdef RENEWAL
  9112. clif->msgtable(sd, MSG_NPC_WORK_IN_PROGRESS);
  9113. #endif
  9114. break;
  9115. }
  9116. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  9117. npc->click(sd, BL_UCAST(BL_NPC, bl));
  9118. break;
  9119. }
  9120. }
  9121. void clif_parse_NpcBuySellSelected(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  9122. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9123. /// 00c5 <id>.L <type>.B
  9124. /// type:
  9125. /// 0 = buy
  9126. /// 1 = sell
  9127. void clif_parse_NpcBuySellSelected(int fd, struct map_session_data *sd)
  9128. {
  9129. if (sd->state.trading)
  9130. return;
  9131. npc->buysellsel(sd, RFIFOL(fd,2), RFIFOB(fd,6));
  9132. }
  9133. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9134. /// 00ca <result>.B
  9135. /// result:
  9136. /// 0 = "The deal has successfully completed."
  9137. /// 1 = "You do not have enough zeny."
  9138. /// 2 = "You are over your Weight Limit."
  9139. /// 3 = "Out of the maximum capacity, you have too many items."
  9140. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result) {
  9141. int fd;
  9142. nullpo_retv(sd);
  9143. fd = sd->fd;
  9144. WFIFOHEAD(fd,packet_len(0xca));
  9145. WFIFOW(fd,0) = 0xca;
  9146. WFIFOB(fd,2) = result;
  9147. WFIFOSET(fd,packet_len(0xca));
  9148. }
  9149. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  9150. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9151. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9152. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9153. {
  9154. int n = (RFIFOW(fd,2)-4) /4;
  9155. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  9156. int result;
  9157. if( sd->state.trading || !sd->npc_shopid || pc_has_permission(sd,PC_PERM_DISABLE_STORE) )
  9158. result = 1;
  9159. else
  9160. result = npc->buylist(sd,n,item_list);
  9161. sd->npc_shopid = 0; //Clear shop data.
  9162. clif->npc_buy_result(sd, result);
  9163. }
  9164. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9165. /// 00cb <result>.B
  9166. /// result:
  9167. /// 0 = "The deal has successfully completed."
  9168. /// 1 = "The deal has failed."
  9169. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result) {
  9170. int fd;
  9171. nullpo_retv(sd);
  9172. fd = sd->fd;
  9173. WFIFOHEAD(fd,packet_len(0xcb));
  9174. WFIFOW(fd,0) = 0xcb;
  9175. WFIFOB(fd,2) = result;
  9176. WFIFOSET(fd,packet_len(0xcb));
  9177. }
  9178. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9179. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9180. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9181. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9182. {
  9183. int fail=0,n;
  9184. unsigned short *item_list;
  9185. n = (RFIFOW(fd,2)-4) /4;
  9186. item_list = (unsigned short*)RFIFOP(fd,4);
  9187. if (sd->state.trading || !sd->npc_shopid)
  9188. fail = 1;
  9189. else
  9190. fail = npc->selllist(sd,n,item_list);
  9191. sd->npc_shopid = 0; //Clear shop data.
  9192. clif->npc_sell_result(sd, fail);
  9193. }
  9194. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  9195. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9196. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9197. /// type:
  9198. /// 0 = private
  9199. /// 1 = public
  9200. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9201. {
  9202. int len = RFIFOW(fd,2)-15;
  9203. int limit = RFIFOW(fd,4);
  9204. bool pub = (RFIFOB(fd,6) != 0);
  9205. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  9206. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  9207. char s_password[CHATROOM_PASS_SIZE];
  9208. char s_title[CHATROOM_TITLE_SIZE];
  9209. if (pc_ismuted(&sd->sc, MANNER_NOROOM))
  9210. return;
  9211. if(battle_config.basic_skill_check && pc->checkskill(sd,NV_BASIC) < 4) {
  9212. clif->skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9213. return;
  9214. }
  9215. if( npc->isnear(&sd->bl) ) {
  9216. // uncomment for more verbose message.
  9217. //char output[150];
  9218. //sprintf(output, msg_txt(862), battle_config.min_npc_vendchat_distance); // "You're too close to a NPC, you must be at least %d cells away from any NPC."
  9219. //clif_displaymessage(sd->fd, output);
  9220. clif->skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9221. return;
  9222. }
  9223. if( len <= 0 )
  9224. return; // invalid input
  9225. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9226. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9227. chat->create_pc_chat(sd, s_title, s_password, limit, pub);
  9228. }
  9229. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  9230. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9231. /// 00d9 <chat ID>.L <passwd>.8B
  9232. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  9233. {
  9234. int chatid = RFIFOL(fd,2);
  9235. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  9236. chat->join(sd,chatid,password);
  9237. }
  9238. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  9239. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9240. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9241. /// type:
  9242. /// 0 = private
  9243. /// 1 = public
  9244. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  9245. {
  9246. int len = RFIFOW(fd,2)-15;
  9247. int limit = RFIFOW(fd,4);
  9248. bool pub = (RFIFOB(fd,6) != 0);
  9249. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  9250. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  9251. char s_password[CHATROOM_PASS_SIZE];
  9252. char s_title[CHATROOM_TITLE_SIZE];
  9253. if( len <= 0 )
  9254. return; // invalid input
  9255. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9256. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9257. chat->change_status(sd, s_title, s_password, limit, pub);
  9258. }
  9259. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  9260. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  9261. /// 00e0 <role>.L <nick>.24B
  9262. /// role:
  9263. /// 0 = owner
  9264. /// 1 = normal
  9265. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  9266. {
  9267. chat->change_owner(sd,(char*)RFIFOP(fd,6));
  9268. }
  9269. void clif_parse_KickFromChat(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9270. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  9271. /// 00e2 <name>.24B
  9272. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  9273. {
  9274. chat->kick(sd,(char*)RFIFOP(fd,2));
  9275. }
  9276. void clif_parse_ChatLeave(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  9277. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  9278. /// 00e3
  9279. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  9280. {
  9281. chat->leave(sd, false);
  9282. }
  9283. //Handles notifying asker and rejecter of what has just occurred.
  9284. //Type is used to determine the correct msg_txt to use:
  9285. //0:
  9286. void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type) {
  9287. const char* msg;
  9288. char output[256];
  9289. nullpo_retv(src);
  9290. // Your request has been rejected by autoreject option.
  9291. msg = msg_sd(src,392);
  9292. clif_disp_onlyself(src, msg, strlen(msg));
  9293. //Notice that a request was rejected.
  9294. snprintf(output, 256, msg_sd(target,393+type), src->status.name, 256);
  9295. clif_disp_onlyself(target, output, strlen(output));
  9296. }
  9297. void clif_parse_TradeRequest(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9298. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  9299. /// 00e4 <account id>.L
  9300. void clif_parse_TradeRequest(int fd,struct map_session_data *sd) {
  9301. struct map_session_data *t_sd;
  9302. t_sd = map->id2sd(RFIFOL(fd,2));
  9303. if(!sd->chatID && pc_cant_act(sd))
  9304. return; //You can trade while in a chatroom.
  9305. // @noask [LuzZza]
  9306. if(t_sd && t_sd->state.noask) {
  9307. clif->noask_sub(sd, t_sd, 0);
  9308. return;
  9309. }
  9310. if( battle_config.basic_skill_check && pc->checkskill(sd,NV_BASIC) < 1) {
  9311. clif->skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  9312. return;
  9313. }
  9314. trade->request(sd,t_sd);
  9315. }
  9316. void clif_parse_TradeAck(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9317. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  9318. /// 00e6 <result>.B
  9319. /// result:
  9320. /// 3 = accepted
  9321. /// 4 = rejected
  9322. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  9323. {
  9324. trade->ack(sd,RFIFOB(fd,2));
  9325. }
  9326. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9327. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  9328. /// 00e8 <index>.W <amount>.L
  9329. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  9330. {
  9331. short index = RFIFOW(fd,2);
  9332. int amount = RFIFOL(fd,4);
  9333. if( index == 0 )
  9334. trade->addzeny(sd, amount);
  9335. else
  9336. trade->additem(sd, index, (short)amount);
  9337. }
  9338. void clif_parse_TradeOk(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9339. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  9340. /// 00eb
  9341. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  9342. {
  9343. trade->ok(sd);
  9344. }
  9345. void clif_parse_TradeCancel(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9346. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  9347. /// 00ed
  9348. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  9349. {
  9350. trade->cancel(sd);
  9351. }
  9352. void clif_parse_TradeCommit(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9353. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  9354. /// 00ef
  9355. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  9356. {
  9357. trade->commit(sd);
  9358. }
  9359. void clif_parse_StopAttack(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9360. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  9361. /// 0118
  9362. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  9363. {
  9364. pc_stop_attack(sd);
  9365. }
  9366. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9367. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  9368. /// 0126 <index>.W <amount>.L
  9369. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd) {
  9370. int flag = 0;
  9371. if (pc_istrading(sd))
  9372. return;
  9373. if (!pc_iscarton(sd))
  9374. return;
  9375. if ( (flag = pc->putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4))) ) {
  9376. clif->dropitem(sd, RFIFOW(fd,2)-2,0);
  9377. clif->cart_additem_ack(sd,flag == 1?0x0:0x1);
  9378. }
  9379. }
  9380. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9381. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  9382. /// 0127 <index>.W <amount>.L
  9383. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  9384. {
  9385. if (!pc_iscarton(sd))
  9386. return;
  9387. pc->getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  9388. }
  9389. void clif_parse_RemoveOption(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9390. /// Request to remove cart/falcon/peco/dragon (CZ_REQ_CARTOFF).
  9391. /// 012a
  9392. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  9393. {
  9394. if (pc_isridingpeco(sd) || pc_isfalcon(sd) || pc_isridingdragon(sd) || pc_ismadogear(sd)) {
  9395. // priority to remove this option before we can clear cart
  9396. pc->setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  9397. } else {
  9398. #ifdef NEW_CARTS
  9399. if (sd->sc.data[SC_PUSH_CART])
  9400. pc->setcart(sd,0);
  9401. #else // not NEW_CARTS
  9402. pc->setoption(sd,sd->sc.option&~OPTION_CART);
  9403. #endif // NEW_CARTS
  9404. }
  9405. }
  9406. void clif_parse_ChangeCart(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9407. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  9408. /// 01af <num>.W
  9409. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  9410. {// TODO: State tracking?
  9411. int type;
  9412. if( pc->checkskill(sd, MC_CHANGECART) < 1 )
  9413. return;
  9414. #ifdef RENEWAL
  9415. if( sd->npc_id || sd->state.workinprogress&1 ){
  9416. clif->msgtable(sd, MSG_NPC_WORK_IN_PROGRESS);
  9417. return;
  9418. }
  9419. #endif
  9420. type = (int)RFIFOW(fd,2);
  9421. #ifdef NEW_CARTS
  9422. if( (type == 9 && sd->status.base_level > 131) ||
  9423. (type == 8 && sd->status.base_level > 121) ||
  9424. (type == 7 && sd->status.base_level > 111) ||
  9425. (type == 6 && sd->status.base_level > 101) ||
  9426. (type == 5 && sd->status.base_level > 90) ||
  9427. (type == 4 && sd->status.base_level > 80) ||
  9428. (type == 3 && sd->status.base_level > 65) ||
  9429. (type == 2 && sd->status.base_level > 40) ||
  9430. (type == 1))
  9431. #else
  9432. if( (type == 5 && sd->status.base_level > 90) ||
  9433. (type == 4 && sd->status.base_level > 80) ||
  9434. (type == 3 && sd->status.base_level > 65) ||
  9435. (type == 2 && sd->status.base_level > 40) ||
  9436. (type == 1))
  9437. #endif
  9438. pc->setcart(sd,type);
  9439. }
  9440. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  9441. /// 0980 <identity>.L <type>.B
  9442. void clif_parse_SelectCart(int fd, struct map_session_data *sd)
  9443. {
  9444. #if PACKETVER >= 20150805 // RagexeRE
  9445. int type;
  9446. if (!sd || !pc->checkskill(sd, MC_CARTDECORATE) || RFIFOL(fd, 2) != sd->status.account_id)
  9447. return;
  9448. type = (int)RFIFOB(fd, 6);
  9449. if (type <= MAX_BASE_CARTS || type > MAX_CARTS)
  9450. return;
  9451. pc->setcart(sd, type);
  9452. #endif
  9453. }
  9454. void clif_parse_StatusUp(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9455. /// Request to increase status (CZ_STATUS_CHANGE).
  9456. /// 00bb <status id>.W <amount>.B
  9457. /// status id:
  9458. /// SP_STR ~ SP_LUK
  9459. /// amount:
  9460. /// Old clients send always 1 for this, even when using /str+ and the like.
  9461. /// Newer clients (2013-12-23 and newer) send the correct amount.
  9462. void clif_parse_StatusUp(int fd,struct map_session_data *sd) {
  9463. int increase_amount;
  9464. increase_amount = RFIFOB(fd,4);
  9465. if( increase_amount < 0 )
  9466. {
  9467. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  9468. fd, increase_amount);
  9469. }
  9470. pc->statusup(sd, RFIFOW(fd,2), increase_amount);
  9471. }
  9472. void clif_parse_SkillUp(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9473. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  9474. /// 0112 <skill id>.W
  9475. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  9476. {
  9477. pc->skillup(sd,RFIFOW(fd,2));
  9478. }
  9479. void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, int64 tick, uint16 skill_id, uint16 skill_lv, int target_id) {
  9480. int lv;
  9481. nullpo_retv(sd);
  9482. if( !hd )
  9483. return;
  9484. if (skill->not_ok_hom(skill_id, hd)){
  9485. clif->emotion(&hd->bl, E_DOTS);
  9486. return;
  9487. }
  9488. if (hd->bl.id != target_id && skill->get_inf(skill_id)&INF_SELF_SKILL)
  9489. target_id = hd->bl.id;
  9490. if (hd->ud.skilltimer != INVALID_TIMER) {
  9491. if (skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST) return;
  9492. }
  9493. else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0){
  9494. clif->emotion(&hd->bl, E_DOTS);
  9495. if (hd->master)
  9496. clif->skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9497. return;
  9498. }
  9499. lv = homun->checkskill(hd, skill_id);
  9500. if( skill_lv > lv )
  9501. skill_lv = lv;
  9502. if( skill_lv )
  9503. unit->skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  9504. }
  9505. void clif_parse_UseSkillToPos_homun(struct homun_data *hd, struct map_session_data *sd, int64 tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo) {
  9506. int lv;
  9507. nullpo_retv(sd);
  9508. if( !hd )
  9509. return;
  9510. if (skill->not_ok_hom(skill_id, hd)){
  9511. clif->emotion(&hd->bl, E_DOTS);
  9512. return;
  9513. }
  9514. if ( hd->ud.skilltimer != INVALID_TIMER ) {
  9515. if ( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9516. } else if ( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  9517. clif->emotion(&hd->bl, E_DOTS);
  9518. if ( hd->master )
  9519. clif->skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9520. return;
  9521. }
  9522. if( hd->sc.data[SC_BASILICA] )
  9523. return;
  9524. lv = homun->checkskill(hd, skill_id);
  9525. if( skill_lv > lv )
  9526. skill_lv = lv;
  9527. if( skill_lv )
  9528. unit->skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  9529. }
  9530. void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, int64 tick, uint16 skill_id, uint16 skill_lv, int target_id) {
  9531. int lv;
  9532. nullpo_retv(sd);
  9533. if( !md )
  9534. return;
  9535. if( skill->not_ok_mercenary(skill_id, md) )
  9536. return;
  9537. if( md->bl.id != target_id && skill->get_inf(skill_id)&INF_SELF_SKILL )
  9538. target_id = md->bl.id;
  9539. if( md->ud.skilltimer != INVALID_TIMER ) {
  9540. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  9541. } else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  9542. return;
  9543. lv = mercenary->checkskill(md, skill_id);
  9544. if( skill_lv > lv )
  9545. skill_lv = lv;
  9546. if( skill_lv )
  9547. unit->skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  9548. }
  9549. void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, int64 tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo) {
  9550. int lv;
  9551. nullpo_retv(sd);
  9552. if( !md )
  9553. return;
  9554. if( skill->not_ok_mercenary(skill_id, md) )
  9555. return;
  9556. if( md->ud.skilltimer != INVALID_TIMER )
  9557. return;
  9558. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 ) {
  9559. clif->skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9560. return;
  9561. }
  9562. if( md->sc.data[SC_BASILICA] )
  9563. return;
  9564. lv = mercenary->checkskill(md, skill_id);
  9565. if( skill_lv > lv )
  9566. skill_lv = lv;
  9567. if( skill_lv )
  9568. unit->skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  9569. }
  9570. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  9571. /// Request to use a targeted skill.
  9572. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  9573. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  9574. /// There are various variants of this packet, some of them have padding between fields.
  9575. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  9576. {
  9577. uint16 skill_id, skill_lv;
  9578. int tmp, target_id;
  9579. int64 tick = timer->gettick();
  9580. skill_lv = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9581. skill_id = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  9582. target_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  9583. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  9584. tmp = skill->get_inf(skill_id);
  9585. if (tmp&INF_GROUND_SKILL || !tmp)
  9586. return; //Using a ground/passive skill on a target? WRONG.
  9587. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9588. clif->pUseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  9589. return;
  9590. }
  9591. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9592. clif->pUseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  9593. return;
  9594. }
  9595. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9596. pc->update_idle_time(sd, BCIDLE_USESKILLTOID);
  9597. if( sd->npc_id || sd->state.workinprogress&1 ){
  9598. #ifdef RENEWAL
  9599. clif->msgtable(sd, MSG_NPC_WORK_IN_PROGRESS); // TODO look for the client date that has this message.
  9600. #endif
  9601. return;
  9602. }
  9603. if( pc_cant_act(sd)
  9604. && skill_id != RK_REFRESH
  9605. && !(skill_id == SR_GENTLETOUCH_CURE && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN))
  9606. && (sd->state.storage_flag != STORAGE_FLAG_CLOSED && !(tmp&INF_SELF_SKILL)) // SELF skills can be used with the storage open, issue: 8027
  9607. )
  9608. return;
  9609. if( pc_issit(sd) )
  9610. return;
  9611. if( skill->not_ok(skill_id, sd) )
  9612. return;
  9613. if( sd->bl.id != target_id && tmp&INF_SELF_SKILL )
  9614. target_id = sd->bl.id; // never trust the client
  9615. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  9616. target_id = sd->bl.id;
  9617. if( sd->ud.skilltimer != INVALID_TIMER ) {
  9618. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  9619. return;
  9620. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9621. if( sd->skillitem != skill_id ) {
  9622. clif->skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9623. return;
  9624. }
  9625. }
  9626. if( sd->sc.option&OPTION_COSTUME )
  9627. return;
  9628. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9629. return; // On basilica only caster can use Basilica again to stop it.
  9630. if( sd->menuskill_id ) {
  9631. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9632. clif_menuskill_clear(sd); //Cancel pet capture.
  9633. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9634. return; //Can't use skills while a menu is open.
  9635. }
  9636. if( sd->skillitem == skill_id ) {
  9637. if( skill_lv != sd->skillitemlv )
  9638. skill_lv = sd->skillitemlv;
  9639. if( !(tmp&INF_SELF_SKILL) )
  9640. pc->delinvincibletimer(sd); // Target skills through items cancel invincibility. [Inkfish]
  9641. unit->skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9642. return;
  9643. }
  9644. sd->skillitem = sd->skillitemlv = 0;
  9645. if( skill_id >= GD_SKILLBASE ) {
  9646. if( sd->state.gmaster_flag )
  9647. skill_lv = guild->checkskill(sd->guild, skill_id);
  9648. else
  9649. skill_lv = 0;
  9650. } else {
  9651. tmp = pc->checkskill(sd, skill_id);
  9652. if( skill_lv > tmp )
  9653. skill_lv = tmp;
  9654. }
  9655. pc->delinvincibletimer(sd);
  9656. if( skill_lv )
  9657. unit->skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  9658. }
  9659. /*==========================================
  9660. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  9661. *------------------------------------------*/
  9662. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  9663. {
  9664. int64 tick = timer->gettick();
  9665. nullpo_retv(sd);
  9666. if( !(skill->get_inf(skill_id)&INF_GROUND_SKILL) )
  9667. return; //Using a target skill on the ground? WRONG.
  9668. if( skill_id >= HM_SKILLBASE && skill_id < HM_SKILLBASE + MAX_HOMUNSKILL ) {
  9669. clif->pUseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9670. return;
  9671. }
  9672. if( skill_id >= MC_SKILLBASE && skill_id < MC_SKILLBASE + MAX_MERCSKILL ) {
  9673. clif->pUseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  9674. return;
  9675. }
  9676. #ifdef RENEWAL
  9677. if( sd->state.workinprogress&1 ){
  9678. clif->msgtable(sd, MSG_NPC_WORK_IN_PROGRESS); // TODO look for the client date that has this message.
  9679. return;
  9680. }
  9681. #endif
  9682. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  9683. pc->update_idle_time(sd, BCIDLE_USESKILLTOPOS);
  9684. if( skill->not_ok(skill_id, sd) )
  9685. return;
  9686. if( skillmoreinfo != -1 ) {
  9687. if( pc_issit(sd) ) {
  9688. clif->skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  9689. return;
  9690. }
  9691. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  9692. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  9693. }
  9694. if( sd->ud.skilltimer != INVALID_TIMER )
  9695. return;
  9696. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  9697. if( sd->skillitem != skill_id ) {
  9698. clif->skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  9699. return;
  9700. }
  9701. }
  9702. if( sd->sc.option&OPTION_COSTUME )
  9703. return;
  9704. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  9705. return; // On basilica only caster can use Basilica again to stop it.
  9706. if( sd->menuskill_id ) {
  9707. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  9708. clif_menuskill_clear(sd); //Cancel pet capture.
  9709. } else if( sd->menuskill_id != SA_AUTOSPELL )
  9710. return; //Can't use skills while a menu is open.
  9711. }
  9712. pc->delinvincibletimer(sd);
  9713. if( sd->skillitem == skill_id ) {
  9714. if( skill_lv != sd->skillitemlv )
  9715. skill_lv = sd->skillitemlv;
  9716. unit->skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  9717. } else {
  9718. int lv;
  9719. sd->skillitem = sd->skillitemlv = 0;
  9720. if( (lv = pc->checkskill(sd, skill_id)) > 0 ) {
  9721. if( skill_lv > lv )
  9722. skill_lv = lv;
  9723. unit->skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  9724. }
  9725. }
  9726. }
  9727. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  9728. /// Request to use a ground skill.
  9729. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  9730. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  9731. /// There are various variants of this packet, some of them have padding between fields.
  9732. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  9733. {
  9734. if (pc_cant_act(sd))
  9735. return;
  9736. if (pc_issit(sd))
  9737. return;
  9738. clif->pUseSkillToPosSub(fd, sd,
  9739. RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]), //skill lv
  9740. RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[1]), //skill num
  9741. RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[2]), //pos x
  9742. RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[3]), //pos y
  9743. -1 //Skill more info.
  9744. );
  9745. }
  9746. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  9747. /// Request to use a ground skill with text.
  9748. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  9749. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  9750. /// There are various variants of this packet, some of them have padding between fields.
  9751. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  9752. {
  9753. if (pc_cant_act(sd))
  9754. return;
  9755. if (pc_issit(sd))
  9756. return;
  9757. clif->pUseSkillToPosSub(fd, sd,
  9758. RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]), //Skill lv
  9759. RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[1]), //Skill num
  9760. RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[2]), //pos x
  9761. RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[3]), //pos y
  9762. packet_db[RFIFOW(fd,0)].pos[4] //skill more info
  9763. );
  9764. }
  9765. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  9766. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  9767. /// 011b <skill id>.W <map name>.16B
  9768. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  9769. {
  9770. uint16 skill_id = RFIFOW(fd,2);
  9771. char map_name[MAP_NAME_LENGTH];
  9772. mapindex->getmapname((char*)RFIFOP(fd,4), map_name);
  9773. sd->state.workinprogress = 0;
  9774. if(skill_id != sd->menuskill_id)
  9775. return;
  9776. // It is possible to use teleport with the storage window open issue:8027
  9777. if (pc_cant_act(sd) && (sd->state.storage_flag == STORAGE_FLAG_CLOSED && skill_id != AL_TELEPORT)) {
  9778. clif_menuskill_clear(sd);
  9779. return;
  9780. }
  9781. pc->delinvincibletimer(sd);
  9782. skill->castend_map(sd,skill_id,map_name);
  9783. }
  9784. void clif_parse_RequestMemo(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9785. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  9786. /// 011d
  9787. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  9788. {
  9789. if (!pc_isdead(sd))
  9790. pc->memo(sd,-1);
  9791. }
  9792. void clif_parse_ProduceMix(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9793. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  9794. /// 018e <name id>.W { <material id>.W }*3
  9795. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  9796. {
  9797. switch( sd->menuskill_id ) {
  9798. case -1:
  9799. case AM_PHARMACY:
  9800. case RK_RUNEMASTERY:
  9801. case GC_RESEARCHNEWPOISON:
  9802. break;
  9803. default:
  9804. return;
  9805. }
  9806. if (pc_istrading(sd)) {
  9807. //Make it fail to avoid shop exploits where you sell something different than you see.
  9808. clif->skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9809. clif_menuskill_clear(sd);
  9810. return;
  9811. }
  9812. if( skill->can_produce_mix(sd,RFIFOW(fd,2),sd->menuskill_val, 1) )
  9813. skill->produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  9814. clif_menuskill_clear(sd);
  9815. }
  9816. void clif_parse_Cooking(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9817. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  9818. /// 025b <mk type>.W <name id>.W
  9819. /// mk type:
  9820. /// 1 = cooking
  9821. /// 2 = arrow
  9822. /// 3 = elemental
  9823. /// 4 = GN_MIX_COOKING
  9824. /// 5 = GN_MAKEBOMB
  9825. /// 6 = GN_S_PHARMACY
  9826. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  9827. int type = RFIFOW(fd,2);
  9828. int nameid = RFIFOW(fd,4);
  9829. int amount = sd->menuskill_val2?sd->menuskill_val2:1;
  9830. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  9831. return;
  9832. if (pc_istrading(sd)) {
  9833. //Make it fail to avoid shop exploits where you sell something different than you see.
  9834. clif->skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9835. clif_menuskill_clear(sd);
  9836. return;
  9837. }
  9838. if( skill->can_produce_mix(sd,nameid,sd->menuskill_val, amount) )
  9839. skill->produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount);
  9840. clif_menuskill_clear(sd);
  9841. }
  9842. void clif_parse_RepairItem(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  9843. /// Answer to repair weapon item selection dialog (CZ_REQ_ITEMREPAIR).
  9844. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W
  9845. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  9846. {
  9847. if (sd->menuskill_id != BS_REPAIRWEAPON)
  9848. return;
  9849. if (pc_istrading(sd)) {
  9850. //Make it fail to avoid shop exploits where you sell something different than you see.
  9851. clif->skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9852. clif_menuskill_clear(sd);
  9853. return;
  9854. }
  9855. skill->repairweapon(sd,RFIFOW(fd,2));
  9856. clif_menuskill_clear(sd);
  9857. }
  9858. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  9859. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  9860. /// 0222 <index>.L
  9861. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  9862. {
  9863. int idx;
  9864. sd->state.prerefining = 0;
  9865. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  9866. return;
  9867. if (pc_istrading(sd)) {
  9868. //Make it fail to avoid shop exploits where you sell something different than you see.
  9869. clif->skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9870. clif_menuskill_clear(sd);
  9871. return;
  9872. }
  9873. idx = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9874. skill->weaponrefine(sd, idx-2);
  9875. clif_menuskill_clear(sd);
  9876. }
  9877. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9878. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  9879. /// 00b8 <npc id>.L <choice>.B
  9880. /// choice:
  9881. /// 1~254 = menu item
  9882. /// 255 = cancel
  9883. /// NOTE: If there were more than 254 items in the list, choice
  9884. /// overflows to choice%256.
  9885. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  9886. {
  9887. int npc_id = RFIFOL(fd,2);
  9888. uint8 select = RFIFOB(fd,6);
  9889. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  9890. #ifdef SECURE_NPCTIMEOUT
  9891. if( sd->npc_idle_timer != INVALID_TIMER ) {
  9892. #endif
  9893. struct npc_data *nd = map->id2nd(npc_id);
  9894. ShowWarning("Invalid menu selection on npc %d:'%s' - got %d, valid range is [%d..%d] (player AID:%d, CID:%d, name:'%s')!\n", npc_id, (nd)?nd->name:"invalid npc id", select, 1, sd->npc_menu, sd->bl.id, sd->status.char_id, sd->status.name);
  9895. clif->GM_kick(NULL,sd);
  9896. #ifdef SECURE_NPCTIMEOUT
  9897. }
  9898. #endif
  9899. return;
  9900. }
  9901. sd->npc_menu = select;
  9902. npc->scriptcont(sd,npc_id, false);
  9903. }
  9904. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9905. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  9906. /// 00b9 <npc id>.L
  9907. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  9908. {
  9909. npc->scriptcont(sd,RFIFOL(fd,2), false);
  9910. }
  9911. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9912. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  9913. /// 0143 <npc id>.L <value>.L
  9914. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  9915. {
  9916. int npcid = RFIFOL(fd,2);
  9917. int amount = (int)RFIFOL(fd,6);
  9918. if (amount >= 0)
  9919. sd->npc_amount = amount;
  9920. else
  9921. sd->npc_amount = 0;
  9922. npc->scriptcont(sd, npcid, false);
  9923. }
  9924. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  9925. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  9926. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  9927. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  9928. {
  9929. int message_len = RFIFOW(fd,2)-8;
  9930. int npcid = RFIFOL(fd,4);
  9931. const char* message = (char*)RFIFOP(fd,8);
  9932. if( message_len <= 0 )
  9933. return; // invalid input
  9934. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  9935. npc->scriptcont(sd, npcid, false);
  9936. }
  9937. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9938. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  9939. /// 0146 <npc id>.L
  9940. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  9941. {
  9942. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  9943. return;
  9944. sd->state.dialog = 0;
  9945. npc->scriptcont(sd, RFIFOL(fd,2), true);
  9946. }
  9947. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9948. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  9949. /// 0178 <index>.W
  9950. /// index:
  9951. /// -1 = cancel
  9952. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  9953. {
  9954. short idx = RFIFOW(fd,2);
  9955. if (sd->menuskill_id != MC_IDENTIFY)
  9956. return;
  9957. if( idx == -1 ) {// cancel pressed
  9958. sd->state.workinprogress = 0;
  9959. clif->item_identified(sd,idx-2,1);
  9960. clif_menuskill_clear(sd);
  9961. return;
  9962. }
  9963. skill->identify(sd,idx-2);
  9964. clif_menuskill_clear(sd);
  9965. }
  9966. /// Identifying item with right-click (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  9967. /// 0A35 <index>.W
  9968. void clif_parse_OneClick_ItemIdentify(int fd, struct map_session_data *sd)
  9969. {
  9970. int cmd = RFIFOW(fd,0);
  9971. short idx = RFIFOW(fd, packet_db[cmd].pos[0]) - 2;
  9972. int n;
  9973. if (idx < 0 || idx >= MAX_INVENTORY || sd->inventory_data[idx] == NULL || sd->status.inventory[idx].nameid <= 0)
  9974. return;
  9975. if ((n = pc->have_magnifier(sd) ) != INDEX_NOT_FOUND &&
  9976. pc->delitem(sd, n, 1, 0, DELITEM_NORMAL, LOG_TYPE_OTHER) == 0)
  9977. skill->identify(sd, idx);
  9978. }
  9979. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  9980. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  9981. /// 01ae <name id>.W
  9982. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  9983. {
  9984. if (pc_istrading(sd)) {
  9985. //Make it fail to avoid shop exploits where you sell something different than you see.
  9986. clif->skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  9987. clif_menuskill_clear(sd);
  9988. return;
  9989. }
  9990. switch( sd->menuskill_id ) {
  9991. case AC_MAKINGARROW:
  9992. skill->arrow_create(sd,RFIFOW(fd,2));
  9993. break;
  9994. case SA_CREATECON:
  9995. skill->produce_mix(sd,SA_CREATECON,RFIFOW(fd,2),0,0,0, 1);
  9996. break;
  9997. case WL_READING_SB:
  9998. skill->spellbook(sd,RFIFOW(fd,2));
  9999. break;
  10000. case GC_POISONINGWEAPON:
  10001. skill->poisoningweapon(sd,RFIFOW(fd,2));
  10002. break;
  10003. case NC_MAGICDECOY:
  10004. skill->magicdecoy(sd,RFIFOW(fd,2));
  10005. break;
  10006. }
  10007. clif_menuskill_clear(sd);
  10008. }
  10009. void clif_parse_AutoSpell(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  10010. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10011. /// 01ce <skill id>.L
  10012. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10013. {
  10014. uint16 skill_id = RFIFOL(fd,2);
  10015. sd->state.workinprogress = 0;
  10016. if( sd->menuskill_id != SA_AUTOSPELL )
  10017. return;
  10018. if( !skill_id )
  10019. return;
  10020. skill->autospell(sd, skill_id);
  10021. clif_menuskill_clear(sd);
  10022. }
  10023. void clif_parse_UseCard(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  10024. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10025. /// 017a <card index>.W
  10026. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10027. {
  10028. clif->use_card(sd,RFIFOW(fd,2)-2);
  10029. }
  10030. void clif_parse_InsertCard(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  10031. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10032. /// 017c <card index>.W <equip index>.W
  10033. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10034. {
  10035. pc->insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  10036. }
  10037. void clif_parse_SolveCharName(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10038. /// Request of character's name by char ID.
  10039. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10040. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10041. /// There are various variants of this packet, some of them have padding between fields.
  10042. void clif_parse_SolveCharName(int fd, struct map_session_data *sd) {
  10043. int charid;
  10044. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10045. map->reqnickdb(sd, charid);
  10046. }
  10047. void clif_parse_ResetChar(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10048. /// /resetskill /resetstate (CZ_RESET).
  10049. /// Request to reset stats or skills.
  10050. /// 0197 <type>.W
  10051. /// type:
  10052. /// 0 = state
  10053. /// 1 = skill
  10054. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10055. char cmd[15];
  10056. if( RFIFOW(fd,2) )
  10057. sprintf(cmd,"%cskreset",atcommand->at_symbol);
  10058. else
  10059. sprintf(cmd,"%cstreset",atcommand->at_symbol);
  10060. atcommand->exec(fd, sd, cmd, true);
  10061. }
  10062. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10063. /// /lb /nlb (CZ_LOCALBROADCAST).
  10064. /// Request to broadcast a message on current map.
  10065. /// 019c <packet len>.W <text>.?B
  10066. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10067. {
  10068. char command[CHAT_SIZE_MAX+16];
  10069. char* msg = (char*)RFIFOP(fd,4);
  10070. unsigned int len = RFIFOW(fd,2)-4;
  10071. // as the length varies depending on the command used, just block unreasonably long strings
  10072. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10073. sprintf(command, "%clkami %s", atcommand->at_symbol, msg);
  10074. atcommand->exec(fd, sd, command, true);
  10075. }
  10076. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10077. /// Request to move an item from inventory to storage.
  10078. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10079. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10080. /// There are various variants of this packet, some of them have padding between fields.
  10081. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10082. {
  10083. int item_index, item_amount;
  10084. if (pc_istrading(sd))
  10085. return;
  10086. item_index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10087. item_amount = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10088. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10089. return;
  10090. if (sd->state.storage_flag == STORAGE_FLAG_NORMAL)
  10091. storage->add(sd, item_index, item_amount);
  10092. else if (sd->state.storage_flag == STORAGE_FLAG_GUILD)
  10093. gstorage->add(sd, item_index, item_amount);
  10094. }
  10095. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  10096. /// Request to move an item from storage to inventory.
  10097. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10098. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10099. /// There are various variants of this packet, some of them have padding between fields.
  10100. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10101. {
  10102. int item_index, item_amount;
  10103. item_index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-1;
  10104. item_amount = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10105. if (sd->state.storage_flag == STORAGE_FLAG_NORMAL)
  10106. storage->get(sd, item_index, item_amount);
  10107. else if(sd->state.storage_flag == STORAGE_FLAG_GUILD)
  10108. gstorage->get(sd, item_index, item_amount);
  10109. }
  10110. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10111. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10112. /// 0129 <index>.W <amount>.L
  10113. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  10114. {
  10115. if( sd->state.vending )
  10116. return;
  10117. if (!pc_iscarton(sd))
  10118. return;
  10119. if (sd->state.storage_flag == STORAGE_FLAG_NORMAL)
  10120. storage->addfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  10121. else if (sd->state.storage_flag == STORAGE_FLAG_GUILD)
  10122. gstorage->addfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  10123. }
  10124. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10125. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10126. /// 0128 <index>.W <amount>.L
  10127. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  10128. {
  10129. if( sd->state.vending )
  10130. return;
  10131. if (!pc_iscarton(sd))
  10132. return;
  10133. if (sd->state.storage_flag == STORAGE_FLAG_NORMAL)
  10134. storage->gettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  10135. else if (sd->state.storage_flag == STORAGE_FLAG_GUILD)
  10136. gstorage->gettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  10137. }
  10138. void clif_parse_CloseKafra(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10139. /// Request to close storage (CZ_CLOSE_STORE).
  10140. /// 00f7
  10141. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10142. {
  10143. if( sd->state.storage_flag == STORAGE_FLAG_NORMAL )
  10144. storage->close(sd);
  10145. else if( sd->state.storage_flag == STORAGE_FLAG_GUILD )
  10146. gstorage->close(sd);
  10147. }
  10148. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10149. /// 023a <info>.W
  10150. /// info:
  10151. /// 0 = password has not been set yet
  10152. /// 1 = storage is password-protected
  10153. /// 8 = too many wrong passwords
  10154. /// ? = ignored
  10155. /// NOTE: This packet is only available on certain non-kRO clients.
  10156. void clif_storagepassword(struct map_session_data* sd, short info)
  10157. {
  10158. int fd;
  10159. nullpo_retv(sd);
  10160. fd = sd->fd;
  10161. WFIFOHEAD(fd,packet_len(0x23a));
  10162. WFIFOW(fd,0) = 0x23a;
  10163. WFIFOW(fd,2) = info;
  10164. WFIFOSET(fd,packet_len(0x23a));
  10165. }
  10166. void clif_parse_StoragePassword(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10167. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10168. /// 023b <type>.W <password>.16B <new password>.16B
  10169. /// type:
  10170. /// 2 = change password
  10171. /// 3 = check password
  10172. /// NOTE: This packet is only available on certain non-kRO clients.
  10173. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  10174. {
  10175. //TODO
  10176. }
  10177. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10178. /// 023c <result>.W <error count>.W
  10179. /// result:
  10180. /// 4 = password change success
  10181. /// 5 = password change failure
  10182. /// 6 = password check success
  10183. /// 7 = password check failure
  10184. /// 8 = too many wrong passwords
  10185. /// ? = ignored
  10186. /// NOTE: This packet is only available on certain non-kRO clients.
  10187. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10188. {
  10189. int fd;
  10190. nullpo_retv(sd);
  10191. fd = sd->fd;
  10192. WFIFOHEAD(fd,packet_len(0x23c));
  10193. WFIFOW(fd,0) = 0x23c;
  10194. WFIFOW(fd,2) = result;
  10195. WFIFOW(fd,4) = error_count;
  10196. WFIFOSET(fd,packet_len(0x23c));
  10197. }
  10198. void clif_parse_CreateParty(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10199. /// Party creation request
  10200. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10201. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10202. void clif_parse_CreateParty(int fd, struct map_session_data *sd) {
  10203. char* name = (char*)RFIFOP(fd,2);
  10204. name[NAME_LENGTH-1] = '\0';
  10205. if( map->list[sd->bl.m].flag.partylock ) {
  10206. // Party locked.
  10207. clif->message(fd, msg_fd(fd,227));
  10208. return;
  10209. }
  10210. if( battle_config.basic_skill_check && pc->checkskill(sd,NV_BASIC) < 7 ) {
  10211. clif->skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10212. return;
  10213. }
  10214. party->create(sd,name,0,0);
  10215. }
  10216. void clif_parse_CreateParty2(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10217. void clif_parse_CreateParty2(int fd, struct map_session_data *sd) {
  10218. char* name = (char*)RFIFOP(fd,2);
  10219. int item1 = RFIFOB(fd,26);
  10220. int item2 = RFIFOB(fd,27);
  10221. name[NAME_LENGTH-1] = '\0';
  10222. if( map->list[sd->bl.m].flag.partylock ) {
  10223. // Party locked.
  10224. clif->message(fd, msg_fd(fd,227));
  10225. return;
  10226. }
  10227. if( battle_config.basic_skill_check && pc->checkskill(sd,NV_BASIC) < 7 ) {
  10228. clif->skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10229. return;
  10230. }
  10231. party->create(sd,name,item1,item2);
  10232. }
  10233. void clif_parse_PartyInvite(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10234. /// Party invitation request
  10235. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10236. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  10237. void clif_parse_PartyInvite(int fd, struct map_session_data *sd) {
  10238. struct map_session_data *t_sd;
  10239. if(map->list[sd->bl.m].flag.partylock) {
  10240. // Party locked.
  10241. clif->message(fd, msg_fd(fd,227));
  10242. return;
  10243. }
  10244. t_sd = map->id2sd(RFIFOL(fd,2));
  10245. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  10246. clif->noask_sub(sd, t_sd, 1);
  10247. return;
  10248. }
  10249. party->invite(sd, t_sd);
  10250. }
  10251. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10252. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd) {
  10253. struct map_session_data *t_sd;
  10254. char *name = (char*)RFIFOP(fd,2);
  10255. name[NAME_LENGTH-1] = '\0';
  10256. if(map->list[sd->bl.m].flag.partylock) {
  10257. // Party locked.
  10258. clif->message(fd, msg_fd(fd,227));
  10259. return;
  10260. }
  10261. t_sd = map->nick2sd(name);
  10262. if(t_sd && t_sd->state.noask) { // @noask [LuzZza]
  10263. clif->noask_sub(sd, t_sd, 1);
  10264. return;
  10265. }
  10266. party->invite(sd, t_sd);
  10267. }
  10268. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  10269. /// Party invitation reply
  10270. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  10271. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  10272. /// flag:
  10273. /// 0 = reject
  10274. /// 1 = accept
  10275. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  10276. {
  10277. party->reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  10278. }
  10279. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  10280. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  10281. {
  10282. party->reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  10283. }
  10284. void clif_parse_LeaveParty(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10285. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  10286. /// 0100
  10287. void clif_parse_LeaveParty(int fd, struct map_session_data *sd) {
  10288. if(map->list[sd->bl.m].flag.partylock) {
  10289. // Party locked.
  10290. clif->message(fd, msg_fd(fd,227));
  10291. return;
  10292. }
  10293. party->leave(sd);
  10294. }
  10295. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10296. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  10297. /// 0103 <account id>.L <char name>.24B
  10298. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) {
  10299. if(map->list[sd->bl.m].flag.partylock) {
  10300. // Party locked.
  10301. clif->message(fd, msg_fd(fd,227));
  10302. return;
  10303. }
  10304. party->removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  10305. }
  10306. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10307. /// Request to change party options.
  10308. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  10309. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  10310. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  10311. {
  10312. struct party_data *p;
  10313. int i;
  10314. if( !sd->status.party_id )
  10315. return;
  10316. p = party->search(sd->status.party_id);
  10317. if( p == NULL )
  10318. return;
  10319. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  10320. if( i == MAX_PARTY )
  10321. return; //Shouldn't happen
  10322. if( !p->party.member[i].leader )
  10323. return;
  10324. #if PACKETVER < 20090603
  10325. //Client can't change the item-field
  10326. party->changeoption(sd, RFIFOL(fd,2), p->party.item);
  10327. #else
  10328. party->changeoption(sd, RFIFOL(fd,2), ((RFIFOB(fd,6)?1:0)|(RFIFOB(fd,7)?2:0)));
  10329. #endif
  10330. }
  10331. void clif_parse_PartyMessage(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10332. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  10333. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  10334. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  10335. {
  10336. const char* text = (char*)RFIFOP(fd,4);
  10337. int textlen = RFIFOW(fd,2) - 4;
  10338. char *name, *message;
  10339. size_t namelen, messagelen;
  10340. // validate packet and retrieve name and message
  10341. if( !clif->process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  10342. return;
  10343. if( atcommand->exec(fd, sd, message, true) )
  10344. return;
  10345. if( !pc->can_talk(sd) )
  10346. return;
  10347. if (battle_config.min_chat_delay) {
  10348. if (DIFF_TICK(sd->cantalk_tick, timer->gettick()) > 0)
  10349. return;
  10350. sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
  10351. }
  10352. pc->update_idle_time(sd, BCIDLE_CHAT);
  10353. party->send_message(sd, text, textlen);
  10354. }
  10355. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10356. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  10357. /// 07da <account id>.L
  10358. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd) {
  10359. party->changeleader(sd, map->id2sd(RFIFOL(fd,2)));
  10360. }
  10361. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10362. /// Party Booking in KRO [Spiria]
  10363. ///
  10364. /// Request to register a party booking advertisement (CZ_PARTY_BOOKING_REQ_REGISTER).
  10365. /// 0802 <level>.W <map id>.W { <job>.W }*6
  10366. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd)
  10367. {
  10368. #ifndef PARTY_RECRUIT
  10369. short level = RFIFOW(fd,2);
  10370. short mapid = RFIFOW(fd,4);
  10371. short job[PARTY_BOOKING_JOBS];
  10372. int i;
  10373. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10374. job[i] = RFIFOB(fd,6+i*2);
  10375. party->booking_register(sd, level, mapid, job);
  10376. #else
  10377. return;
  10378. #endif
  10379. }
  10380. /// Result of request to register a party booking advertisement (ZC_PARTY_BOOKING_ACK_REGISTER).
  10381. /// 0803 <result>.W
  10382. /// result:
  10383. /// 0 = success
  10384. /// 1 = failure
  10385. /// 2 = already registered
  10386. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  10387. {
  10388. #ifndef PARTY_RECRUIT
  10389. int fd;
  10390. nullpo_retv(sd);
  10391. fd = sd->fd;
  10392. WFIFOHEAD(fd,packet_len(0x803));
  10393. WFIFOW(fd,0) = 0x803;
  10394. WFIFOW(fd,2) = flag;
  10395. WFIFOSET(fd,packet_len(0x803));
  10396. #else
  10397. return;
  10398. #endif
  10399. }
  10400. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10401. /// Request to search for party booking advertisement (CZ_PARTY_BOOKING_REQ_SEARCH).
  10402. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  10403. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd)
  10404. {
  10405. #ifndef PARTY_RECRUIT
  10406. short level = RFIFOW(fd,2);
  10407. short mapid = RFIFOW(fd,4);
  10408. short job = RFIFOW(fd,6);
  10409. unsigned long lastindex = RFIFOL(fd,8);
  10410. short resultcount = RFIFOW(fd,12);
  10411. party->booking_search(sd, level, mapid, job, lastindex, resultcount);
  10412. #else
  10413. return;
  10414. #endif
  10415. }
  10416. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  10417. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  10418. /// more results:
  10419. /// 0 = no
  10420. /// 1 = yes
  10421. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10422. {
  10423. #ifndef PARTY_RECRUIT
  10424. int i, j;
  10425. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  10426. struct party_booking_ad_info *pb_ad;
  10427. nullpo_retv(results);
  10428. WFIFOHEAD(fd,size*count + 5);
  10429. WFIFOW(fd,0) = 0x805;
  10430. WFIFOW(fd,2) = size*count + 5;
  10431. WFIFOB(fd,4) = more_result;
  10432. for(i=0; i<count; i++)
  10433. {
  10434. pb_ad = results[i];
  10435. WFIFOL(fd,i*size+5) = pb_ad->index;
  10436. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  10437. WFIFOL(fd,i*size+33) = pb_ad->expiretime;
  10438. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  10439. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  10440. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  10441. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  10442. }
  10443. WFIFOSET(fd,WFIFOW(fd,2));
  10444. #else
  10445. return;
  10446. #endif
  10447. }
  10448. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10449. /// Request to delete own party booking advertisement (CZ_PARTY_BOOKING_REQ_DELETE).
  10450. /// 0806
  10451. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  10452. {
  10453. #ifndef PARTY_RECRUIT
  10454. if(party->booking_delete(sd))
  10455. clif->PartyBookingDeleteAck(sd, 0);
  10456. #else
  10457. return;
  10458. #endif
  10459. }
  10460. /// Result of request to delete own party booking advertisement (ZC_PARTY_BOOKING_ACK_DELETE).
  10461. /// 0807 <result>.W
  10462. /// result:
  10463. /// 0 = success
  10464. /// 1 = success (auto-removed expired ad)
  10465. /// 2 = failure
  10466. /// 3 = nothing registered
  10467. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  10468. {
  10469. #ifndef PARTY_RECRUIT
  10470. int fd;
  10471. nullpo_retv(sd);
  10472. fd = sd->fd;
  10473. WFIFOHEAD(fd,packet_len(0x807));
  10474. WFIFOW(fd,0) = 0x807;
  10475. WFIFOW(fd,2) = flag;
  10476. WFIFOSET(fd,packet_len(0x807));
  10477. #else
  10478. return;
  10479. #endif
  10480. }
  10481. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10482. /// Request to update party booking advertisement (CZ_PARTY_BOOKING_REQ_UPDATE).
  10483. /// 0808 { <job>.W }*6
  10484. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  10485. {
  10486. #ifndef PARTY_RECRUIT
  10487. short job[PARTY_BOOKING_JOBS];
  10488. int i;
  10489. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10490. job[i] = RFIFOW(fd,2+i*2);
  10491. party->booking_update(sd, job);
  10492. #else
  10493. return;
  10494. #endif
  10495. }
  10496. /// Notification about new party booking advertisement (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  10497. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  10498. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10499. {
  10500. #ifndef PARTY_RECRUIT
  10501. int i;
  10502. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  10503. nullpo_retv(sd);
  10504. if(pb_ad == NULL) return;
  10505. WBUFW(buf,0) = 0x809;
  10506. WBUFL(buf,2) = pb_ad->index;
  10507. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  10508. WBUFL(buf,30) = pb_ad->expiretime;
  10509. WBUFW(buf,34) = pb_ad->p_detail.level;
  10510. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  10511. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10512. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  10513. clif->send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  10514. #else
  10515. return;
  10516. #endif
  10517. }
  10518. /// Notification about updated party booking advertisement (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  10519. /// 080a <index>.L { <job>.W }*6
  10520. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10521. {
  10522. #ifndef PARTY_RECRUIT
  10523. int i;
  10524. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  10525. nullpo_retv(sd);
  10526. if(pb_ad == NULL) return;
  10527. WBUFW(buf,0) = 0x80a;
  10528. WBUFL(buf,2) = pb_ad->index;
  10529. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  10530. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  10531. clif->send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  10532. #else
  10533. return;
  10534. #endif
  10535. }
  10536. /// Notification about deleted party booking advertisement (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  10537. /// 080b <index>.L
  10538. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  10539. {
  10540. #ifndef PARTY_RECRUIT
  10541. uint8 buf[6];
  10542. nullpo_retv(sd);
  10543. WBUFW(buf,0) = 0x80b;
  10544. WBUFL(buf,2) = index;
  10545. clif->send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  10546. #else
  10547. return;
  10548. #endif
  10549. }
  10550. void clif_parse_PartyRecruitRegisterReq(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10551. /// Modified version of Party Booking System for 2012-04-10 or 2012-04-18 (RagexeRE).
  10552. /// Code written by mkbu95, Spiria, Yommy and Ind
  10553. /// Request to register a party booking advertisement (CZ_PARTY_RECRUIT_REQ_REGISTER).
  10554. /// 08e5 <level>.W <notice>.37B
  10555. void clif_parse_PartyRecruitRegisterReq(int fd, struct map_session_data* sd)
  10556. {
  10557. #ifdef PARTY_RECRUIT
  10558. short level = RFIFOW(fd,2);
  10559. const char *notice = (const char*)RFIFOP(fd, 4);
  10560. party->recruit_register(sd, level, notice);
  10561. #else
  10562. return;
  10563. #endif
  10564. }
  10565. /// Party booking search results (ZC_PARTY_RECRUIT_ACK_SEARCH).
  10566. /// 08e8 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <notice>.37B }*
  10567. /// more results:
  10568. /// 0 = no
  10569. /// 1 = yes
  10570. void clif_PartyRecruitSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  10571. {
  10572. #ifdef PARTY_RECRUIT
  10573. int i;
  10574. int size = sizeof(struct party_booking_ad_info);
  10575. struct party_booking_ad_info *pb_ad;
  10576. nullpo_retv(results);
  10577. WFIFOHEAD(fd, (size * count) + 5);
  10578. WFIFOW(fd, 0) = 0x8e8;
  10579. WFIFOW(fd, 2) = (size * count) + 5;
  10580. WFIFOB(fd, 4) = more_result;
  10581. for (i = 0; i < count; ++i) {
  10582. pb_ad = results[i];
  10583. WFIFOL(fd, (i * size) + 5) = pb_ad->index;
  10584. WFIFOL(fd, (i * size) + 9) = pb_ad->expiretime;
  10585. memcpy(WFIFOP(fd, (i * size) + 13), pb_ad->charname, NAME_LENGTH);
  10586. WFIFOW(fd, (i * size) + 13 + NAME_LENGTH) = pb_ad->p_detail.level;
  10587. memcpy(WFIFOP(fd, (i * size) + 13 + NAME_LENGTH + 2), pb_ad->p_detail.notice, PB_NOTICE_LENGTH);
  10588. }
  10589. WFIFOSET(fd,WFIFOW(fd,2));
  10590. #else
  10591. return;
  10592. #endif
  10593. }
  10594. /// Result of request to register a party booking advertisement (ZC_PARTY_RECRUIT_ACK_REGISTER).
  10595. /// 08e6 <result>.W
  10596. /// result:
  10597. /// 0 = success
  10598. /// 1 = failure
  10599. /// 2 = already registered
  10600. void clif_PartyRecruitRegisterAck(struct map_session_data *sd, int flag)
  10601. {
  10602. #ifdef PARTY_RECRUIT
  10603. int fd;
  10604. nullpo_retv(sd);
  10605. fd = sd->fd;
  10606. WFIFOHEAD(fd, packet_len(0x8e6));
  10607. WFIFOW(fd, 0) = 0x8e6;
  10608. WFIFOW(fd, 2) = flag;
  10609. WFIFOSET(fd, packet_len(0x8e6));
  10610. #else
  10611. return;
  10612. #endif
  10613. }
  10614. void clif_parse_PartyRecruitSearchReq(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10615. /// Request to search for party booking advertisement (CZ_PARTY_RECRUIT_REQ_SEARCH).
  10616. /// 08e7 <level>.W <map id>.W <last index>.L <result count>.W
  10617. void clif_parse_PartyRecruitSearchReq(int fd, struct map_session_data* sd)
  10618. {
  10619. #ifdef PARTY_RECRUIT
  10620. short level = RFIFOW(fd, 2);
  10621. short mapid = RFIFOW(fd, 4);
  10622. unsigned long lastindex = RFIFOL(fd, 6);
  10623. short resultcount = RFIFOW(fd, 10);
  10624. party->recruit_search(sd, level, mapid, lastindex, resultcount);
  10625. #else
  10626. return;
  10627. #endif
  10628. }
  10629. void clif_parse_PartyRecruitDeleteReq(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10630. /// Request to delete own party booking advertisement (CZ_PARTY_RECRUIT_REQ_DELETE).
  10631. /// 08e9
  10632. void clif_parse_PartyRecruitDeleteReq(int fd, struct map_session_data* sd)
  10633. {
  10634. #ifdef PARTY_RECRUIT
  10635. if(party->booking_delete(sd))
  10636. clif->PartyRecruitDeleteAck(sd, 0);
  10637. #else
  10638. return;
  10639. #endif
  10640. }
  10641. /// Result of request to delete own party booking advertisement (ZC_PARTY_RECRUIT_ACK_DELETE).
  10642. /// 08ea <result>.W
  10643. /// result:
  10644. /// 0 = success
  10645. /// 1 = success (auto-removed expired ad)
  10646. /// 2 = failure
  10647. /// 3 = nothing registered
  10648. void clif_PartyRecruitDeleteAck(struct map_session_data* sd, int flag)
  10649. {
  10650. #ifdef PARTY_RECRUIT
  10651. int fd;
  10652. nullpo_retv(sd);
  10653. fd = sd->fd;
  10654. WFIFOHEAD(fd, packet_len(0x8ea));
  10655. WFIFOW(fd, 0) = 0x8ea;
  10656. WFIFOW(fd, 2) = flag;
  10657. WFIFOSET(fd, packet_len(0x8ea));
  10658. #else
  10659. return;
  10660. #endif
  10661. }
  10662. void clif_parse_PartyRecruitUpdateReq(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10663. /// Request to update party booking advertisement (CZ_PARTY_RECRUIT_REQ_UPDATE).
  10664. /// 08eb <notice>.37B
  10665. void clif_parse_PartyRecruitUpdateReq(int fd, struct map_session_data *sd)
  10666. {
  10667. #ifdef PARTY_RECRUIT
  10668. const char *notice;
  10669. notice = (const char*)RFIFOP(fd, 2);
  10670. party->recruit_update(sd, notice);
  10671. #else
  10672. return;
  10673. #endif
  10674. }
  10675. /// Notification about new party booking advertisement (ZC_PARTY_RECRUIT_NOTIFY_INSERT).
  10676. /// 08ec <index>.L <expire time>.L <char name>.24B <level>.W <notice>.37B
  10677. void clif_PartyRecruitInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  10678. {
  10679. #ifdef PARTY_RECRUIT
  10680. unsigned char buf[2+6+6+24+4+37+1];
  10681. nullpo_retv(sd);
  10682. if (pb_ad == NULL)
  10683. return;
  10684. WBUFW(buf, 0) = 0x8ec;
  10685. WBUFL(buf, 2) = pb_ad->index;
  10686. WBUFL(buf, 6) = pb_ad->expiretime;
  10687. memcpy(WBUFP(buf, 10), pb_ad->charname, NAME_LENGTH);
  10688. WBUFW(buf,34) = pb_ad->p_detail.level;
  10689. memcpy(WBUFP(buf, 36), pb_ad->p_detail.notice, PB_NOTICE_LENGTH);
  10690. clif->send(buf, packet_len(0x8ec), &sd->bl, ALL_CLIENT);
  10691. #else
  10692. return;
  10693. #endif
  10694. }
  10695. /// Notification about updated party booking advertisement (ZC_PARTY_RECRUIT_NOTIFY_UPDATE).
  10696. /// 08ed <index>.L <notice>.37B
  10697. void clif_PartyRecruitUpdateNotify(struct map_session_data *sd, struct party_booking_ad_info* pb_ad)
  10698. {
  10699. #ifdef PARTY_RECRUIT
  10700. unsigned char buf[2+6+37+1];
  10701. nullpo_retv(sd);
  10702. nullpo_retv(pb_ad);
  10703. WBUFW(buf, 0) = 0x8ed;
  10704. WBUFL(buf, 2) = pb_ad->index;
  10705. memcpy(WBUFP(buf, 6), pb_ad->p_detail.notice, PB_NOTICE_LENGTH);
  10706. clif->send(buf, packet_len(0x8ed), &sd->bl, ALL_CLIENT);
  10707. #else
  10708. return;
  10709. #endif
  10710. }
  10711. /// Notification about deleted party booking advertisement (ZC_PARTY_RECRUIT_NOTIFY_DELETE).
  10712. /// 08ee <index>.L
  10713. void clif_PartyRecruitDeleteNotify(struct map_session_data* sd, int index)
  10714. {
  10715. #ifdef PARTY_RECRUIT
  10716. unsigned char buf[2+6+1];
  10717. nullpo_retv(sd);
  10718. WBUFW(buf, 0) = 0x8ee;
  10719. WBUFL(buf, 2) = index;
  10720. clif->send(buf, packet_len(0x8ee), &sd->bl, ALL_CLIENT);
  10721. #else
  10722. return;
  10723. #endif
  10724. }
  10725. void clif_parse_PartyBookingAddFilteringList(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10726. /// Request to add to filtering list (PARTY_RECRUIT_ADD_FILTERLINGLIST).
  10727. /// 08ef <index>.L
  10728. void clif_parse_PartyBookingAddFilteringList(int fd, struct map_session_data *sd)
  10729. {
  10730. #ifdef PARTY_RECRUIT
  10731. int index = RFIFOL(fd, 2);
  10732. clif->PartyBookingAddFilteringList(index, sd);
  10733. #else
  10734. return;
  10735. #endif
  10736. }
  10737. void clif_parse_PartyBookingSubFilteringList(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10738. /// Request to remove from filtering list (PARTY_RECRUIT_SUB_FILTERLINGLIST).
  10739. /// 08f0 <GID>.L
  10740. void clif_parse_PartyBookingSubFilteringList(int fd, struct map_session_data *sd)
  10741. {
  10742. #ifdef PARTY_RECRUIT
  10743. int gid = RFIFOL(fd, 2);
  10744. clif->PartyBookingSubFilteringList(gid, sd);
  10745. #else
  10746. return;
  10747. #endif
  10748. }
  10749. void clif_parse_PartyBookingReqVolunteer(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10750. /// Request to recruit volunteer (PARTY_RECRUIT_REQ_VOLUNTEER).
  10751. /// 08f1 <index>.L
  10752. void clif_parse_PartyBookingReqVolunteer(int fd, struct map_session_data *sd)
  10753. {
  10754. #ifdef PARTY_RECRUIT
  10755. int index = RFIFOL(fd, 2);
  10756. clif->PartyBookingVolunteerInfo(index, sd);
  10757. #else
  10758. return;
  10759. #endif
  10760. }
  10761. /// Request volunteer information (PARTY_RECRUIT_VOLUNTEER_INFO).
  10762. /// 08f2 <AID>.L <job>.L <level>.W <char name>.24B
  10763. void clif_PartyBookingVolunteerInfo(int index, struct map_session_data *sd)
  10764. {
  10765. #ifdef PARTY_RECRUIT
  10766. unsigned char buf[2+4+4+2+24+1];
  10767. nullpo_retv(sd);
  10768. WBUFW(buf, 0) = 0x8f2;
  10769. WBUFL(buf, 2) = sd->status.account_id;
  10770. WBUFL(buf, 6) = sd->status.class_;
  10771. WBUFW(buf, 10) = sd->status.base_level;
  10772. memcpy(WBUFP(buf, 12), sd->status.name, NAME_LENGTH);
  10773. clif->send(buf, packet_len(0x8f2), &sd->bl, ALL_CLIENT);
  10774. #else
  10775. return;
  10776. #endif
  10777. }
  10778. #if 0 //Disabled for now. Needs more info.
  10779. /// 08f3 <packet type>.W <cost>.L
  10780. void clif_PartyBookingPersonalSetting(int fd, struct map_session_data *sd)
  10781. {
  10782. }
  10783. void clif_parse_PartyBookingShowEquipment(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10784. /// 08f4 <target GID>.L
  10785. void clif_parse_PartyBookingShowEquipment(int fd, struct map_session_data *sd)
  10786. {
  10787. }
  10788. void clif_parse_PartyBookingReqRecall(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10789. /// 08f5 <packet len>.W
  10790. void clif_parse_PartyBookingReqRecall(int fd, struct map_session_data *sd)
  10791. {
  10792. }
  10793. void clif_PartyBookingRecallCost(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10794. /// 08f6 <money>.L <map name>.16B
  10795. void clif_PartyBookingRecallCost(int fd, struct map_session_data *sd)
  10796. {
  10797. }
  10798. void clif_parse_PartyBookingAckRecall(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10799. /// 08f7 <result>.B
  10800. void clif_parse_PartyBookingAckRecall(int fd, struct map_session_data *sd)
  10801. {
  10802. }
  10803. /// 08f8 <caller AID>.L <reason>.B
  10804. /// <reason>:
  10805. /// REASON_PROHIBITION = 0x0
  10806. /// REASON_MASTER_IN_PROHIBITION_MAP = 0x1
  10807. /// REASON_REFUSE = 0x2
  10808. /// REASON_NOT_PARTY_MEMBER = 0x3
  10809. /// REASON_ETC = 0x4
  10810. void clif_PartyBookingFailedRecall(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10811. void clif_PartyBookingFailedRecall(int fd, struct map_session_data *sd)
  10812. {
  10813. }
  10814. #endif //if 0
  10815. void clif_parse_PartyBookingRefuseVolunteer(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10816. /// 08f9 <refuse AID>.L
  10817. void clif_parse_PartyBookingRefuseVolunteer(int fd, struct map_session_data *sd)
  10818. {
  10819. #ifdef PARTY_RECRUIT
  10820. unsigned int aid = RFIFOL(fd, 2);
  10821. clif->PartyBookingRefuseVolunteer(aid, sd);
  10822. #else
  10823. return;
  10824. #endif
  10825. }
  10826. void clif_PartyBookingRefuseVolunteer(unsigned int aid, struct map_session_data *sd) __attribute__((nonnull (2)));
  10827. /// 08fa <index>.L
  10828. void clif_PartyBookingRefuseVolunteer(unsigned int aid, struct map_session_data *sd)
  10829. {
  10830. #ifdef PARTY_RECRUIT
  10831. unsigned char buf[2+6];
  10832. WBUFW(buf, 0) = 0x8fa;
  10833. WBUFL(buf, 2) = aid;
  10834. clif->send(buf, packet_len(0x8fa), &sd->bl, ALL_CLIENT);
  10835. #else
  10836. return;
  10837. #endif
  10838. }
  10839. void clif_parse_PartyBookingCancelVolunteer(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10840. /// 08fb <index>.L
  10841. void clif_parse_PartyBookingCancelVolunteer(int fd, struct map_session_data *sd)
  10842. {
  10843. #ifdef PARTY_RECRUIT
  10844. int index = RFIFOL(fd, 2);
  10845. clif->PartyBookingCancelVolunteer(index, sd);
  10846. #else
  10847. return;
  10848. #endif
  10849. }
  10850. /// 0909 <index>.L
  10851. void clif_PartyBookingCancelVolunteer(int index, struct map_session_data *sd)
  10852. {
  10853. #ifdef PARTY_RECRUIT
  10854. unsigned char buf[2+6+1];
  10855. nullpo_retv(sd);
  10856. WBUFW(buf, 0) = 0x909;
  10857. WBUFL(buf, 2) = index;
  10858. clif->send(buf, packet_len(0x909), &sd->bl, ALL_CLIENT);
  10859. #else
  10860. return;
  10861. #endif
  10862. }
  10863. /// 090b <gid>.L <char name>.24B
  10864. void clif_PartyBookingAddFilteringList(int index, struct map_session_data *sd)
  10865. {
  10866. #ifdef PARTY_RECRUIT
  10867. unsigned char buf[2+6+24+1];
  10868. nullpo_retv(sd);
  10869. WBUFW(buf, 0) = 0x90b;
  10870. WBUFL(buf, 2) = sd->bl.id;
  10871. memcpy(WBUFP(buf, 6), sd->status.name, NAME_LENGTH);
  10872. clif->send(buf, packet_len(0x90b), &sd->bl, ALL_CLIENT);
  10873. #else
  10874. return;
  10875. #endif
  10876. }
  10877. /// 090c <gid>.L <char name>.24B
  10878. void clif_PartyBookingSubFilteringList(int gid, struct map_session_data *sd)
  10879. {
  10880. #ifdef PARTY_RECRUIT
  10881. unsigned char buf[2+6+24+1];
  10882. nullpo_retv(sd);
  10883. WBUFW(buf, 0) = 0x90c;
  10884. WBUFL(buf, 2) = gid;
  10885. memcpy(WBUFP(buf, 6), sd->status.name, NAME_LENGTH);
  10886. clif->send(buf, packet_len(0x90c), &sd->bl, ALL_CLIENT);
  10887. #else
  10888. return;
  10889. #endif
  10890. }
  10891. #if 0
  10892. /// 091c <aid>.L
  10893. void clif_PartyBookingCancelVolunteerToPM(struct map_session_data *sd)
  10894. {
  10895. }
  10896. /// 0971 <pm_aid>.L
  10897. void clif_PartyBookingRefuseVolunteerToPM(struct map_session_data *sd)
  10898. {
  10899. }
  10900. #endif //if 0
  10901. void clif_parse_CloseVending(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10902. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  10903. /// 012e
  10904. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  10905. {
  10906. vending->close(sd);
  10907. }
  10908. void clif_parse_VendingListReq(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10909. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  10910. /// 0130 <account id>.L
  10911. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  10912. {
  10913. if( sd->npc_id ) {// using an NPC
  10914. return;
  10915. }
  10916. vending->list(sd,RFIFOL(fd,2));
  10917. }
  10918. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10919. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  10920. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  10921. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  10922. {
  10923. int len = (int)RFIFOW(fd,2) - 8;
  10924. int id = (int)RFIFOL(fd,4);
  10925. const uint8* data = (uint8*)RFIFOP(fd,8);
  10926. vending->purchase(sd, id, sd->vended_id, data, len/4);
  10927. // whether it fails or not, the buy window is closed
  10928. sd->vended_id = 0;
  10929. }
  10930. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10931. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  10932. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  10933. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd)
  10934. {
  10935. int len = (int)RFIFOW(fd,2) - 12;
  10936. int aid = (int)RFIFOL(fd,4);
  10937. int uid = (int)RFIFOL(fd,8);
  10938. const uint8* data = (uint8*)RFIFOP(fd,12);
  10939. vending->purchase(sd, aid, uid, data, len/4);
  10940. // whether it fails or not, the buy window is closed
  10941. sd->vended_id = 0;
  10942. }
  10943. void clif_parse_OpenVending(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  10944. /// Confirm or cancel the shop preparation window.
  10945. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  10946. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  10947. /// result:
  10948. /// 0 = canceled
  10949. /// 1 = open
  10950. void clif_parse_OpenVending(int fd, struct map_session_data* sd) {
  10951. short len = (short)RFIFOW(fd,2) - 85;
  10952. const char* message = (char*)RFIFOP(fd,4);
  10953. bool flag = (bool)RFIFOB(fd,84);
  10954. const uint8* data = (uint8*)RFIFOP(fd,85);
  10955. if( !flag )
  10956. sd->state.prevend = sd->state.workinprogress = 0;
  10957. if(pc_ismuted(&sd->sc, MANNER_NOROOM))
  10958. return;
  10959. if( map->list[sd->bl.m].flag.novending ) {
  10960. clif->message (sd->fd, msg_sd(sd,276)); // "You can't open a shop on this map"
  10961. return;
  10962. }
  10963. if (map->getcell(sd->bl.m, &sd->bl, sd->bl.x, sd->bl.y, CELL_CHKNOVENDING)) {
  10964. clif->message (sd->fd, msg_sd(sd,204)); // "You can't open a shop on this cell."
  10965. return;
  10966. }
  10967. if( message[0] == '\0' ) // invalid input
  10968. return;
  10969. vending->open(sd, message, data, len/8);
  10970. }
  10971. void clif_parse_CreateGuild(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  10972. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  10973. /// 0165 <char id>.L <guild name>.24B
  10974. void clif_parse_CreateGuild(int fd,struct map_session_data *sd) {
  10975. char* name = (char*)RFIFOP(fd,6);
  10976. name[NAME_LENGTH-1] = '\0';
  10977. if(map->list[sd->bl.m].flag.guildlock) {
  10978. //Guild locked.
  10979. clif->message(fd, msg_fd(fd,228));
  10980. return;
  10981. }
  10982. guild->create(sd, name);
  10983. }
  10984. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10985. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  10986. /// 014d
  10987. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  10988. {
  10989. clif->guild_masterormember(sd);
  10990. }
  10991. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  10992. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  10993. /// 014f <type>.L
  10994. /// type:
  10995. /// 0 = basic info
  10996. /// 1 = member manager
  10997. /// 2 = positions
  10998. /// 3 = skills
  10999. /// 4 = expulsion list
  11000. /// 5 = unknown (GM_ALLGUILDLIST)
  11001. /// 6 = notice
  11002. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11003. {
  11004. if( !sd->status.guild_id && !sd->bg_id )
  11005. return;
  11006. switch( RFIFOL(fd,2) ) {
  11007. case 0: // Basic Information Guild, hostile alliance information
  11008. clif->guild_basicinfo(sd);
  11009. clif->guild_allianceinfo(sd);
  11010. break;
  11011. case 1: // Members list, list job title
  11012. clif->guild_positionnamelist(sd);
  11013. clif->guild_memberlist(sd);
  11014. break;
  11015. case 2: // List job title, title information list
  11016. clif->guild_positionnamelist(sd);
  11017. clif->guild_positioninfolist(sd);
  11018. break;
  11019. case 3: // Skill list
  11020. clif->guild_skillinfo(sd);
  11021. break;
  11022. case 4: // Expulsion list
  11023. clif->guild_expulsionlist(sd);
  11024. break;
  11025. default:
  11026. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  11027. break;
  11028. }
  11029. }
  11030. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11031. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11032. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11033. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11034. {
  11035. int i;
  11036. if(!sd->state.gmaster_flag)
  11037. return;
  11038. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  11039. guild->change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  11040. }
  11041. }
  11042. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11043. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11044. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11045. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11046. {
  11047. int i;
  11048. if(!sd->state.gmaster_flag)
  11049. return;
  11050. for(i=4;i<RFIFOW(fd,2);i+=12){
  11051. guild->change_memberposition(sd->status.guild_id,
  11052. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  11053. }
  11054. }
  11055. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  11056. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11057. /// 0151 <guild id>.L
  11058. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11059. {
  11060. struct guild* g;
  11061. int guild_id = RFIFOL(fd,2);
  11062. if( (g = guild->search(guild_id)) != NULL )
  11063. clif->guild_emblem(sd,g);
  11064. }
  11065. /// Validates data of a guild emblem (compressed bitmap)
  11066. bool clif_validate_emblem(const uint8 *emblem, unsigned long emblem_len) {
  11067. enum e_bitmapconst {
  11068. RGBTRIPLE_SIZE = 3, // sizeof(RGBTRIPLE)
  11069. RGBQUAD_SIZE = 4, // sizeof(RGBQUAD)
  11070. BITMAPFILEHEADER_SIZE = 14, // sizeof(BITMAPFILEHEADER)
  11071. BITMAPINFOHEADER_SIZE = 40, // sizeof(BITMAPINFOHEADER)
  11072. BITMAP_WIDTH = 24,
  11073. BITMAP_HEIGHT = 24,
  11074. };
  11075. #if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute
  11076. #pragma pack(push, 1)
  11077. #endif // not NetBSD < 6 / Solaris
  11078. struct s_bitmaptripple {
  11079. //uint8 b;
  11080. //uint8 g;
  11081. //uint8 r;
  11082. unsigned int rgb:24;
  11083. } __attribute__((packed));
  11084. #if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute
  11085. #pragma pack(pop)
  11086. #endif // not NetBSD < 6 / Solaris
  11087. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11088. unsigned long buf_len = sizeof(buf);
  11089. int header = 0, bitmap = 0, offbits = 0, palettesize = 0;
  11090. nullpo_retr(false, emblem);
  11091. if( decode_zip(buf, &buf_len, emblem, emblem_len) != 0 || buf_len < BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE
  11092. || RBUFW(buf,0) != 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11093. || RBUFL(buf,2) != buf_len // BITMAPFILEHEADER.bfSize (file size)
  11094. || RBUFL(buf,14) != BITMAPINFOHEADER_SIZE // BITMAPINFOHEADER.biSize (other headers are not supported)
  11095. || RBUFL(buf,18) != BITMAP_WIDTH // BITMAPINFOHEADER.biWidth
  11096. || RBUFL(buf,22) != BITMAP_HEIGHT // BITMAPINFOHEADER.biHeight (top-down bitmaps (-24) are not supported)
  11097. || RBUFL(buf,30) != 0 // BITMAPINFOHEADER.biCompression == BI_RGB (compression not supported)
  11098. ) {
  11099. // Invalid data
  11100. return false;
  11101. }
  11102. offbits = RBUFL(buf,10); // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11103. switch( RBUFW(buf,28) ) { // BITMAPINFOHEADER.biBitCount
  11104. case 8:
  11105. palettesize = RBUFL(buf,46); // BITMAPINFOHEADER.biClrUsed (number of colors in the palette)
  11106. if( palettesize == 0 )
  11107. palettesize = 256; // Defaults to 2^n if set to zero
  11108. else if( palettesize > 256 )
  11109. return false;
  11110. header = BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE + RGBQUAD_SIZE * palettesize; // headers + palette
  11111. bitmap = BITMAP_WIDTH * BITMAP_HEIGHT;
  11112. break;
  11113. case 24:
  11114. header = BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE;
  11115. bitmap = BITMAP_WIDTH * BITMAP_HEIGHT * RGBTRIPLE_SIZE;
  11116. break;
  11117. default:
  11118. return false;
  11119. }
  11120. // NOTE: This check gives a little freedom for bitmap-producing implementations,
  11121. // that align the start of bitmap data, which is harmless but unnecessary.
  11122. // If you want it paranoidly strict, change the first condition from < to !=.
  11123. // This also allows files with trailing garbage at the end of the file.
  11124. // If you want to avoid that, change the last condition to !=.
  11125. if( offbits < header || buf_len <= bitmap || offbits > buf_len - bitmap ) {
  11126. return false;
  11127. }
  11128. if( battle_config.client_emblem_max_blank_percent < 100 ) {
  11129. int required_pixels = BITMAP_WIDTH * BITMAP_HEIGHT * (100 - battle_config.client_emblem_max_blank_percent) / 100;
  11130. int found_pixels = 0;
  11131. int i;
  11132. /// Checks what percentage of a guild emblem is blank. A blank emblem
  11133. /// consists solely of magenta pixels. Since the client uses 16-bit
  11134. /// colors, any magenta shade that reduces to #ff00ff passes off as
  11135. /// transparent color as well (down to #f807f8).
  11136. ///
  11137. /// Unlike real magenta, reduced magenta causes the guild window to
  11138. /// become see-through in the transparent parts of the emblem
  11139. /// background (glitch).
  11140. switch( RBUFW(buf,28) ) {
  11141. case 8: // palette indexes
  11142. {
  11143. const uint8 *indexes = (const uint8 *)RBUFP(buf,offbits);
  11144. const uint32 *palette = (const uint32 *)RBUFP(buf,BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE);
  11145. for (i = 0; i < BITMAP_WIDTH * BITMAP_HEIGHT; i++) {
  11146. if( indexes[i] >= palettesize ) // Invalid color
  11147. return false;
  11148. // if( color->r < 0xF8 || color->g > 0x07 || color->b < 0xF8 )
  11149. if( ( palette[indexes[i]]&0x00F8F8F8 ) != 0x00F800F8 ) {
  11150. if( ++found_pixels >= required_pixels ) {
  11151. // Enough valid pixels were found
  11152. return true;
  11153. }
  11154. }
  11155. }
  11156. break;
  11157. }
  11158. case 24: // full colors
  11159. {
  11160. const struct s_bitmaptripple *pixels = (const struct s_bitmaptripple*)RBUFP(buf,offbits);
  11161. for (i = 0; i < BITMAP_WIDTH * BITMAP_HEIGHT; i++) {
  11162. // if( pixels[i].r < 0xF8 || pixels[i].g > 0x07 || pixels[i].b < 0xF8 )
  11163. if( ( pixels[i].rgb&0xF8F8F8 ) != 0xF800F8 ) {
  11164. if( ++found_pixels >= required_pixels ) {
  11165. // Enough valid pixels were found
  11166. return true;
  11167. }
  11168. }
  11169. }
  11170. break;
  11171. }
  11172. }
  11173. // Not enough non-blank pixels found
  11174. return false;
  11175. }
  11176. return true;
  11177. }
  11178. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  11179. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11180. /// 0153 <packet len>.W <emblem data>.?B
  11181. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  11182. {
  11183. unsigned int emblem_len = RFIFOW(fd,2)-4;
  11184. const uint8* emblem = RFIFOP(fd,4);
  11185. if( !emblem_len || !sd->state.gmaster_flag )
  11186. return;
  11187. if (!clif->validate_emblem(emblem, emblem_len)) {
  11188. ShowWarning("clif_parse_GuildChangeEmblem: Rejected malformed guild emblem (size=%u, accound_id=%d, char_id=%d, guild_id=%d).\n",
  11189. emblem_len, sd->status.account_id, sd->status.char_id, sd->status.guild_id);
  11190. return;
  11191. }
  11192. guild->change_emblem(sd, emblem_len, (const char*)emblem);
  11193. }
  11194. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  11195. /// Guild notice update request (CZ_GUILD_NOTICE).
  11196. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11197. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  11198. {
  11199. int guild_id = RFIFOL(fd,2);
  11200. char* msg1 = (char*)RFIFOP(fd,6);
  11201. char* msg2 = (char*)RFIFOP(fd,66);
  11202. if(!sd->state.gmaster_flag)
  11203. return;
  11204. // compensate for some client defects when using multilingual mode
  11205. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11206. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11207. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11208. guild->change_notice(sd, guild_id, msg1, msg2);
  11209. }
  11210. // Helper function for guild invite functions
  11211. bool clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd) {
  11212. if ( t_sd == NULL )// not online or does not exist
  11213. return false;
  11214. nullpo_retr(false, sd);
  11215. nullpo_retr(false, t_sd);
  11216. if ( map->list[sd->bl.m].flag.guildlock ) {
  11217. //Guild locked.
  11218. clif->message(fd, msg_fd(fd,228));
  11219. return false;
  11220. }
  11221. if (t_sd->state.noask) {// @noask [LuzZza]
  11222. clif->noask_sub(sd, t_sd, 2);
  11223. return false;
  11224. }
  11225. guild->invite(sd,t_sd);
  11226. return true;
  11227. }
  11228. void clif_parse_GuildInvite(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  11229. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11230. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11231. void clif_parse_GuildInvite(int fd,struct map_session_data *sd) {
  11232. struct map_session_data *t_sd = map->id2sd(RFIFOL(fd,2));
  11233. if (!clif_sub_guild_invite(fd, sd, t_sd))
  11234. return;
  11235. }
  11236. void clif_parse_GuildInvite2(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11237. /// Guild invite request (/guildinvite) (CZ_REQ_JOIN_GUILD2).
  11238. /// 0916 <char name>.24B
  11239. void clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11240. char *nick = (char*)RFIFOP(fd, 2);
  11241. struct map_session_data *t_sd = map->nick2sd(nick);
  11242. nick[NAME_LENGTH - 1] = '\0';
  11243. if (!clif_sub_guild_invite(fd, sd, t_sd))
  11244. return;
  11245. }
  11246. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  11247. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11248. /// 016b <guild id>.L <answer>.L
  11249. /// answer:
  11250. /// 0 = refuse
  11251. /// 1 = accept
  11252. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  11253. {
  11254. guild->reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  11255. }
  11256. void clif_parse_GuildLeave(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  11257. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11258. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11259. void clif_parse_GuildLeave(int fd,struct map_session_data *sd) {
  11260. if(map->list[sd->bl.m].flag.guildlock) {
  11261. //Guild locked.
  11262. clif->message(fd, msg_fd(fd,228));
  11263. return;
  11264. }
  11265. if( sd->bg_id ) {
  11266. clif->message(fd, msg_fd(fd,870)); //"You can't leave battleground guilds."
  11267. return;
  11268. }
  11269. guild->leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  11270. }
  11271. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  11272. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11273. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11274. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd) {
  11275. if( map->list[sd->bl.m].flag.guildlock || sd->bg_id ) {
  11276. // Guild locked.
  11277. clif->message(fd, msg_fd(fd,228));
  11278. return;
  11279. }
  11280. guild->expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  11281. }
  11282. void clif_parse_GuildMessage(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  11283. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11284. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11285. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  11286. {
  11287. const char* text = (char*)RFIFOP(fd,4);
  11288. int textlen = RFIFOW(fd,2) - 4;
  11289. char *name, *message;
  11290. size_t namelen, messagelen;
  11291. // validate packet and retrieve name and message
  11292. if( !clif->process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  11293. return;
  11294. if( atcommand->exec(fd, sd, message, true) )
  11295. return;
  11296. if( !pc->can_talk(sd) )
  11297. return;
  11298. if (battle_config.min_chat_delay) {
  11299. if (DIFF_TICK(sd->cantalk_tick, timer->gettick()) > 0)
  11300. return;
  11301. sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
  11302. }
  11303. pc->update_idle_time(sd, BCIDLE_CHAT);
  11304. if( sd->bg_id )
  11305. bg->send_message(sd, text, textlen);
  11306. else
  11307. guild->send_message(sd, text, textlen);
  11308. }
  11309. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11310. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11311. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11312. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd) {
  11313. struct map_session_data *t_sd;
  11314. if(!sd->state.gmaster_flag)
  11315. return;
  11316. if(map->list[sd->bl.m].flag.guildlock) {
  11317. //Guild locked.
  11318. clif->message(fd, msg_fd(fd,228));
  11319. return;
  11320. }
  11321. t_sd = map->id2sd(RFIFOL(fd,2));
  11322. // @noask [LuzZza]
  11323. if(t_sd && t_sd->state.noask) {
  11324. clif->noask_sub(sd, t_sd, 3);
  11325. return;
  11326. }
  11327. guild->reqalliance(sd,t_sd);
  11328. }
  11329. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11330. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11331. /// 0172 <inviter account id>.L <answer>.L
  11332. /// answer:
  11333. /// 0 = refuse
  11334. /// 1 = accept
  11335. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  11336. {
  11337. guild->reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  11338. }
  11339. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11340. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11341. /// 0183 <opponent guild id>.L <relation>.L
  11342. /// relation:
  11343. /// 0 = Ally
  11344. /// 1 = Enemy
  11345. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd) {
  11346. if(!sd->state.gmaster_flag)
  11347. return;
  11348. if(map->list[sd->bl.m].flag.guildlock) {
  11349. //Guild locked.
  11350. clif->message(fd, msg_fd(fd,228));
  11351. return;
  11352. }
  11353. guild->delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  11354. }
  11355. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11356. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11357. /// 0180 <account id>.L
  11358. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd) {
  11359. struct map_session_data *t_sd;
  11360. if(!sd->state.gmaster_flag)
  11361. return;
  11362. if(map->list[sd->bl.m].flag.guildlock) {
  11363. //Guild locked.
  11364. clif->message(fd, msg_fd(fd,228));
  11365. return;
  11366. }
  11367. t_sd = map->id2sd(RFIFOL(fd,2));
  11368. // @noask [LuzZza]
  11369. if(t_sd && t_sd->state.noask) {
  11370. clif->noask_sub(sd, t_sd, 4);
  11371. return;
  11372. }
  11373. guild->opposition(sd,t_sd);
  11374. }
  11375. void clif_parse_GuildBreak(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11376. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11377. /// 015d <key>.40B
  11378. /// key:
  11379. /// now guild name; might have been (intended) email, since the
  11380. /// field name and size is same as the one in CH_DELETE_CHAR.
  11381. void clif_parse_GuildBreak(int fd, struct map_session_data *sd) {
  11382. if( map->list[sd->bl.m].flag.guildlock ) {
  11383. //Guild locked.
  11384. clif->message(fd, msg_fd(fd,228));
  11385. return;
  11386. }
  11387. guild->dobreak(sd,(char*)RFIFOP(fd,2));
  11388. }
  11389. /// Pet
  11390. ///
  11391. void clif_parse_PetMenu(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11392. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11393. /// 01a1 <type>.B
  11394. /// type:
  11395. /// 0 = pet information
  11396. /// 1 = feed
  11397. /// 2 = performance
  11398. /// 3 = return to egg
  11399. /// 4 = unequip accessory
  11400. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  11401. {
  11402. pet->menu(sd,RFIFOB(fd,2));
  11403. }
  11404. void clif_parse_CatchPet(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11405. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11406. /// 019f <id>.L
  11407. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  11408. {
  11409. pet->catch_process2(sd,RFIFOL(fd,2));
  11410. }
  11411. void clif_parse_SelectEgg(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11412. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11413. /// 01a7 <index>.W
  11414. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  11415. {
  11416. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1) {
  11417. return;
  11418. }
  11419. pet->select_egg(sd,RFIFOW(fd,2)-2);
  11420. clif_menuskill_clear(sd);
  11421. }
  11422. void clif_parse_SendEmotion(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11423. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11424. /// 01a9 <data>.L
  11425. /// data:
  11426. /// is either emotion (@see enum emotion_type) or a compound value
  11427. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11428. /// entry (given in parentheses) in data\pettalktable.xml
  11429. /// act id:
  11430. /// 0 = feeding
  11431. /// 1 = hunting
  11432. /// 2 = danger
  11433. /// 3 = dead
  11434. /// 4 = normal (stand)
  11435. /// 5 = special performance (perfor_s)
  11436. /// 6 = level up (levelup)
  11437. /// 7 = performance 1 (perfor_1)
  11438. /// 8 = performance 2 (perfor_2)
  11439. /// 9 = performance 3 (perfor_3)
  11440. /// 10 = log-in greeting (connect)
  11441. /// hungry value:
  11442. /// 0 = very hungry (hungry)
  11443. /// 1 = hungry (bit_hungry)
  11444. /// 2 = satisfied (noting)
  11445. /// 3 = stuffed (full)
  11446. /// 4 = full (so_full)
  11447. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11448. {
  11449. if(sd->pd)
  11450. clif->pet_emotion(sd->pd,RFIFOL(fd,2));
  11451. }
  11452. void clif_parse_ChangePetName(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11453. /// Request to change pet's name (CZ_RENAME_PET).
  11454. /// 01a5 <name>.24B
  11455. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11456. {
  11457. pet->change_name(sd,(char*)RFIFOP(fd,2));
  11458. }
  11459. void clif_parse_GMKick(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11460. /// /kill (CZ_DISCONNECT_CHARACTER).
  11461. /// Request to disconnect a character.
  11462. /// 00cc <account id>.L
  11463. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11464. void clif_parse_GMKick(int fd, struct map_session_data *sd) {
  11465. struct block_list *target;
  11466. int tid;
  11467. tid = RFIFOL(fd,2);
  11468. target = map->id2bl(tid);
  11469. if (!target) {
  11470. clif->GM_kickack(sd, 0);
  11471. return;
  11472. }
  11473. switch (target->type) {
  11474. case BL_PC:
  11475. {
  11476. char command[NAME_LENGTH+6];
  11477. sprintf(command, "%ckick %s", atcommand->at_symbol, status->get_name(target));
  11478. atcommand->exec(fd, sd, command, true);
  11479. }
  11480. break;
  11481. /**
  11482. * This one does not invoke any atcommand, so we need to check for permissions.
  11483. */
  11484. case BL_MOB:
  11485. {
  11486. char command[100];
  11487. if( !pc->can_use_command(sd, "@killmonster")) {
  11488. clif->GM_kickack(sd, 0);
  11489. return;
  11490. }
  11491. sprintf(command, "/kick %s (%d)", status->get_name(target), status->get_class(target));
  11492. logs->atcommand(sd, command);
  11493. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11494. }
  11495. break;
  11496. case BL_NPC:
  11497. {
  11498. struct npc_data *nd = BL_UCAST(BL_NPC, target);
  11499. if( !pc->can_use_command(sd, "@unloadnpc")) {
  11500. clif->GM_kickack(sd, 0);
  11501. return;
  11502. }
  11503. npc->unload_duplicates(nd);
  11504. npc->unload(nd,true);
  11505. npc->read_event_script();
  11506. }
  11507. break;
  11508. default:
  11509. clif->GM_kickack(sd, 0);
  11510. }
  11511. }
  11512. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  11513. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11514. /// Request to disconnect all characters.
  11515. /// 00ce
  11516. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11517. char cmd[15];
  11518. sprintf(cmd,"%ckickall",atcommand->at_symbol);
  11519. atcommand->exec(fd, sd, cmd, true);
  11520. }
  11521. void clif_parse_GMShift(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11522. /// /remove (CZ_REMOVE_AID).
  11523. /// Request to warp to a character with given login ID.
  11524. /// 01ba <account name>.24B
  11525. /// /shift (CZ_SHIFT).
  11526. /// Request to warp to a character with given name.
  11527. /// 01bb <char name>.24B
  11528. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11529. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11530. char *player_name;
  11531. char command[NAME_LENGTH+8];
  11532. player_name = (char*)RFIFOP(fd,2);
  11533. player_name[NAME_LENGTH-1] = '\0';
  11534. sprintf(command, "%cjumpto %s", atcommand->at_symbol, player_name);
  11535. atcommand->exec(fd, sd, command, true);
  11536. }
  11537. void clif_parse_GMRemove2(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  11538. /// /remove (CZ_REMOVE_AID_SSO).
  11539. /// Request to warp to a character with given account ID.
  11540. /// 0843 <account id>.L
  11541. void clif_parse_GMRemove2(int fd, struct map_session_data* sd) {
  11542. int account_id;
  11543. struct map_session_data* pl_sd;
  11544. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11545. if( (pl_sd = map->id2sd(account_id)) != NULL ) {
  11546. char command[NAME_LENGTH+8];
  11547. sprintf(command, "%cjumpto %s", atcommand->at_symbol, pl_sd->status.name);
  11548. atcommand->exec(fd, sd, command, true);
  11549. }
  11550. }
  11551. void clif_parse_GMRecall(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11552. /// /recall (CZ_RECALL).
  11553. /// Request to summon a player with given login ID to own position.
  11554. /// 01bc <account name>.24B
  11555. /// /summon (CZ_RECALL_GID).
  11556. /// Request to summon a player with given name to own position.
  11557. /// 01bd <char name>.24B
  11558. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11559. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11560. char *player_name;
  11561. char command [NAME_LENGTH+8];
  11562. player_name = (char*)RFIFOP(fd,2);
  11563. player_name[NAME_LENGTH-1] = '\0';
  11564. sprintf(command, "%crecall %s", atcommand->at_symbol, player_name);
  11565. atcommand->exec(fd, sd, command, true);
  11566. }
  11567. void clif_parse_GMRecall2(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  11568. /// /recall (CZ_RECALL_SSO).
  11569. /// Request to summon a player with given account ID to own position.
  11570. /// 0842 <account id>.L
  11571. void clif_parse_GMRecall2(int fd, struct map_session_data* sd) {
  11572. int account_id;
  11573. struct map_session_data* pl_sd;
  11574. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11575. if( (pl_sd = map->id2sd(account_id)) != NULL ) {
  11576. char command[NAME_LENGTH+8];
  11577. sprintf(command, "%crecall %s", atcommand->at_symbol, pl_sd->status.name);
  11578. atcommand->exec(fd, sd, command, true);
  11579. }
  11580. }
  11581. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11582. /// /item /monster (CZ_ITEM_CREATE).
  11583. /// Request to execute GM commands.
  11584. /// usage:
  11585. /// /item n - summon n monster or acquire n item/s
  11586. /// /item money - grants 2147483647 Zeny
  11587. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11588. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11589. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11590. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11591. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11592. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11593. /// 013f <item/mob name>.24B
  11594. /// 09ce <item/mob name>.100B [Ind/Yommy<3]
  11595. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) {
  11596. struct packet_gm_monster_item *p = P2PTR(fd);
  11597. int i, count;
  11598. char *item_monster_name;
  11599. struct item_data *item_array[10];
  11600. struct mob_db *mob_array[10];
  11601. char command[256];
  11602. item_monster_name = p->str;
  11603. item_monster_name[(sizeof(struct packet_gm_monster_item)-2)-1] = '\0';
  11604. if ( (count=itemdb->search_name_array(item_array, 10, item_monster_name, 1)) > 0 ) {
  11605. for(i = 0; i < count; i++) {
  11606. if( !item_array[i] )
  11607. continue;
  11608. // It only accepts aegis name
  11609. if( battle_config.case_sensitive_aegisnames && strcmp(item_array[i]->name, item_monster_name) == 0 )
  11610. break;
  11611. if( !battle_config.case_sensitive_aegisnames && strcasecmp(item_array[i]->name, item_monster_name) == 0 )
  11612. break;
  11613. }
  11614. if( i < count ) {
  11615. if( item_array[i]->type == IT_WEAPON || item_array[i]->type == IT_ARMOR ) // nonstackable
  11616. snprintf(command, sizeof(command)-1, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand->at_symbol, item_array[i]->nameid);
  11617. else
  11618. snprintf(command, sizeof(command)-1, "%citem %d 20", atcommand->at_symbol, item_array[i]->nameid);
  11619. atcommand->exec(fd, sd, command, true);
  11620. return;
  11621. }
  11622. }
  11623. if( strcmp("money", item_monster_name) == 0 ){
  11624. snprintf(command, sizeof(command)-1, "%czeny %d", atcommand->at_symbol, INT_MAX);
  11625. atcommand->exec(fd, sd, command, true);
  11626. return;
  11627. }
  11628. if( (count=mob->db_searchname_array(mob_array, 10, item_monster_name, 1)) > 0) {
  11629. for(i = 0; i < count; i++) {
  11630. if( !mob_array[i] )
  11631. continue;
  11632. // It only accepts sprite name
  11633. if( battle_config.case_sensitive_aegisnames && strcmp(mob_array[i]->sprite, item_monster_name) == 0 )
  11634. break;
  11635. if( !battle_config.case_sensitive_aegisnames && strcasecmp(mob_array[i]->sprite, item_monster_name) == 0 )
  11636. break;
  11637. }
  11638. if( i < count ){
  11639. snprintf(command, sizeof(command)-1, "%cmonster %s", atcommand->at_symbol, mob_array[i]->sprite);
  11640. atcommand->exec(fd, sd, command, true);
  11641. }
  11642. }
  11643. }
  11644. void clif_parse_GMHide(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11645. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11646. /// 019d <effect state>.L
  11647. /// effect state:
  11648. /// TODO: Any OPTION_* ?
  11649. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11650. char cmd[6];
  11651. sprintf(cmd,"%chide",atcommand->at_symbol);
  11652. atcommand->exec(fd, sd, cmd, true);
  11653. }
  11654. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  11655. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11656. /// 0149 <account id>.L <type>.B <value>.W
  11657. /// type:
  11658. /// 0 = positive points
  11659. /// 1 = negative points
  11660. /// 2 = self mute (+10 minutes)
  11661. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd) {
  11662. int id, type, value;
  11663. struct map_session_data *dstsd;
  11664. char command[NAME_LENGTH+15];
  11665. id = RFIFOL(fd,2);
  11666. type = RFIFOB(fd,6);
  11667. value = RFIFOW(fd,7);
  11668. if( type == 0 )
  11669. value = -value;
  11670. if (type == 2) {
  11671. if (!battle_config.client_accept_chatdori)
  11672. return;
  11673. if (pc_get_group_level(sd) > 0 || sd->bl.id != id)
  11674. return;
  11675. value = battle_config.client_accept_chatdori;
  11676. dstsd = sd;
  11677. } else {
  11678. dstsd = map->id2sd(id);
  11679. if( dstsd == NULL )
  11680. return;
  11681. }
  11682. if (type == 2 || ( (pc_get_group_level(sd)) > pc_get_group_level(dstsd) && !pc->can_use_command(sd, "@mute"))) {
  11683. clif->manner_message(sd, 0);
  11684. clif->manner_message(dstsd, 5);
  11685. if (dstsd->status.manner < value) {
  11686. dstsd->status.manner -= value;
  11687. sc_start(NULL,&dstsd->bl,SC_NOCHAT,100,0,0);
  11688. } else {
  11689. dstsd->status.manner = 0;
  11690. status_change_end(&dstsd->bl, SC_NOCHAT, INVALID_TIMER);
  11691. }
  11692. if( type != 2 )
  11693. clif->GM_silence(sd, dstsd, type);
  11694. }
  11695. sprintf(command, "%cmute %d %s", atcommand->at_symbol, value, dstsd->status.name);
  11696. atcommand->exec(fd, sd, command, true);
  11697. }
  11698. void clif_parse_GMRc(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  11699. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11700. /// GM adjustment of a player's manner value by -60.
  11701. /// 0212 <char name>.24B
  11702. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11703. {
  11704. char command[NAME_LENGTH+15];
  11705. char *name = (char*)RFIFOP(fd,2);
  11706. name[NAME_LENGTH-1] = '\0';
  11707. sprintf(command, "%cmute %d %s", atcommand->at_symbol, 60, name);
  11708. atcommand->exec(fd, sd, command, true);
  11709. }
  11710. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11711. /// 01e0 <account id>.L <account name>.24B
  11712. void clif_account_name(struct map_session_data* sd, int account_id, const char* accname) {
  11713. int fd;
  11714. nullpo_retv(sd);
  11715. fd = sd->fd;
  11716. WFIFOHEAD(fd,packet_len(0x1e0));
  11717. WFIFOW(fd,0) = 0x1e0;
  11718. WFIFOL(fd,2) = account_id;
  11719. safestrncpy((char*)WFIFOP(fd,6), accname, NAME_LENGTH);
  11720. WFIFOSET(fd,packet_len(0x1e0));
  11721. }
  11722. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11723. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11724. /// 01df <account id>.L
  11725. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11726. {
  11727. int account_id = RFIFOL(fd,2);
  11728. //TODO: find out if this works for any player or only for authorized GMs
  11729. clif->account_name(sd, account_id, ""); // insert account name here >_<
  11730. }
  11731. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11732. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11733. /// GM single cell type change request.
  11734. /// 0198 <x>.W <y>.W <type>.W
  11735. /// type:
  11736. /// 0 = not walkable
  11737. /// 1 = walkable
  11738. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd) {
  11739. int x,y,type;
  11740. if (!pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE))
  11741. return;
  11742. x = RFIFOW(fd,2);
  11743. y = RFIFOW(fd,4);
  11744. type = RFIFOW(fd,6);
  11745. map->setgatcell(sd->bl.m,x,y,type);
  11746. clif->changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  11747. //FIXME: once players leave the map, the client 'forgets' this information.
  11748. }
  11749. void clif_parse_PMIgnore(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  11750. /// /in /ex (CZ_SETTING_WHISPER_PC).
  11751. /// Request to allow/deny whispers from a nick.
  11752. /// 00cf <nick>.24B <type>.B
  11753. /// type:
  11754. /// 0 = (/ex nick) deny speech from nick
  11755. /// 1 = (/in nick) allow speech from nick
  11756. void clif_parse_PMIgnore(int fd, struct map_session_data* sd) {
  11757. char* nick;
  11758. uint8 type;
  11759. int i;
  11760. nick = (char*)RFIFOP(fd,2); // speed up
  11761. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  11762. type = RFIFOB(fd,26);
  11763. if( type == 0 ) { // Add name to ignore list (block)
  11764. if (strcmp(map->wisp_server_name, nick) == 0) {
  11765. clif->wisexin(sd, type, 1); // fail
  11766. return;
  11767. }
  11768. // try to find a free spot, while checking for duplicates at the same time
  11769. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11770. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  11771. clif->wisexin(sd, type, 2); // too many blocks
  11772. return;
  11773. }
  11774. if( sd->ignore[i].name[0] != '\0' ) { // name already exists
  11775. clif->wisexin(sd, type, 0); // Aegis reports success.
  11776. return;
  11777. }
  11778. //Insert in position i
  11779. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  11780. } else { // Remove name from ignore list (unblock)
  11781. // find entry
  11782. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  11783. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  11784. clif->wisexin(sd, type, 1); // fail
  11785. return;
  11786. }
  11787. // move everything one place down to overwrite removed entry
  11788. if( i != MAX_IGNORE_LIST - 1 )
  11789. memmove(&sd->ignore[i], &sd->ignore[i+1], (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0]));
  11790. // wipe last entry
  11791. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  11792. }
  11793. clif->wisexin(sd, type, 0); // success
  11794. }
  11795. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11796. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  11797. /// Request to allow/deny all whispers.
  11798. /// 00d0 <type>.B
  11799. /// type:
  11800. /// 0 = (/exall) deny all speech
  11801. /// 1 = (/inall) allow all speech
  11802. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  11803. {
  11804. int type = RFIFOB(fd,2), flag;
  11805. if( type == 0 ) {// Deny all
  11806. if( sd->state.ignoreAll ) {
  11807. flag = 1; // fail
  11808. } else {
  11809. sd->state.ignoreAll = 1;
  11810. flag = 0; // success
  11811. }
  11812. } else {//Unblock everyone
  11813. if( sd->state.ignoreAll ) {
  11814. sd->state.ignoreAll = 0;
  11815. flag = 0; // success
  11816. } else {
  11817. if (sd->ignore[0].name[0] != '\0')
  11818. { //Wipe the ignore list.
  11819. memset(sd->ignore, 0, sizeof(sd->ignore));
  11820. flag = 0; // success
  11821. } else {
  11822. flag = 1; // fail
  11823. }
  11824. }
  11825. }
  11826. clif->wisall(sd, type, flag);
  11827. }
  11828. /// Whisper ignore list (ZC_WHISPER_LIST).
  11829. /// 00d4 <packet len>.W { <char name>.24B }*
  11830. void clif_PMIgnoreList(struct map_session_data* sd) {
  11831. int i, fd;
  11832. nullpo_retv(sd);
  11833. fd = sd->fd;
  11834. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  11835. WFIFOW(fd,0) = 0xd4;
  11836. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  11837. memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  11838. }
  11839. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  11840. WFIFOSET(fd,WFIFOW(fd,2));
  11841. }
  11842. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  11843. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  11844. /// 00d3
  11845. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  11846. {
  11847. clif->PMIgnoreList(sd);
  11848. }
  11849. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11850. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  11851. /// 01e7
  11852. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  11853. {
  11854. if (sd->state.doridori) return;
  11855. switch (sd->class_&MAPID_UPPERMASK) {
  11856. case MAPID_SOUL_LINKER:
  11857. case MAPID_STAR_GLADIATOR:
  11858. case MAPID_TAEKWON:
  11859. if (!sd->state.rest)
  11860. break;
  11861. case MAPID_SUPER_NOVICE:
  11862. sd->state.doridori=1;
  11863. break;
  11864. }
  11865. }
  11866. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11867. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  11868. /// 01ed
  11869. /// Note: This packet is caused by 7 lines of any text, followed by
  11870. /// the prayer and an another line of any text. The prayer is
  11871. /// defined by lines 790~793 in data\msgstringtable.txt
  11872. /// "Dear angel, can you hear my voice?"
  11873. /// "I am" (space separated player name) "Super Novice~"
  11874. /// "Help me out~ Please~ T_T"
  11875. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  11876. {
  11877. /* [Ind/Hercules] */
  11878. /* game client is currently broken on this (not sure the packetver range) */
  11879. /* it sends the request when the criteria doesn't match (and of course we let it fail) */
  11880. /* so restoring the old parse_globalmes method. */
  11881. if( ( sd->class_&MAPID_UPPERMASK ) == MAPID_SUPER_NOVICE ) {
  11882. unsigned int next = pc->nextbaseexp(sd);
  11883. if( next == 0 ) next = pc->thisbaseexp(sd);
  11884. if( next ) {
  11885. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  11886. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  11887. sc_start(NULL,&sd->bl, status->skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill->get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  11888. clif->skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  11889. }
  11890. }
  11891. }
  11892. }
  11893. /// Friends List
  11894. ///
  11895. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  11896. /// 0206 <account id>.L <char id>.L <state>.B
  11897. /// state:
  11898. /// 0 = online
  11899. /// 1 = offline
  11900. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online) {
  11901. int i, fd;
  11902. nullpo_retv(sd);
  11903. fd = sd->fd;
  11904. //Seek friend.
  11905. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  11906. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  11907. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  11908. return; //Not found
  11909. WFIFOHEAD(fd,packet_len(0x206));
  11910. WFIFOW(fd, 0) = 0x206;
  11911. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  11912. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  11913. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  11914. WFIFOSET(fd, packet_len(0x206));
  11915. }
  11916. //Sub-function called from clif_foreachclient to toggle friends on/off [Skotlex]
  11917. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  11918. {
  11919. int account_id, char_id, online;
  11920. account_id = va_arg(ap, int);
  11921. char_id = va_arg(ap, int);
  11922. online = va_arg(ap, int);
  11923. clif->friendslist_toggle(sd, account_id, char_id, online);
  11924. return 0;
  11925. }
  11926. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  11927. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  11928. void clif_friendslist_send(struct map_session_data *sd)
  11929. {
  11930. int i = 0, n, fd = sd->fd;
  11931. nullpo_retv(sd);
  11932. // Send friends list
  11933. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  11934. WFIFOW(fd, 0) = 0x201;
  11935. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  11936. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  11937. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  11938. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  11939. }
  11940. if (i) {
  11941. WFIFOW(fd,2) = 4 + 32 * i;
  11942. WFIFOSET(fd, WFIFOW(fd,2));
  11943. }
  11944. for (n = 0; n < i; n++) { //Sending the online players
  11945. if (map->charid2sd(sd->status.friends[n].char_id))
  11946. clif->friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  11947. }
  11948. }
  11949. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  11950. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  11951. /// result:
  11952. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  11953. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  11954. /// 2 = MsgStringTable[819]="Your Friend List is full."
  11955. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  11956. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  11957. {
  11958. int fd;
  11959. nullpo_retv(sd);
  11960. fd = sd->fd;
  11961. WFIFOHEAD(fd,packet_len(0x209));
  11962. WFIFOW(fd,0) = 0x209;
  11963. WFIFOW(fd,2) = type;
  11964. if (f_sd) {
  11965. WFIFOL(fd,4) = f_sd->status.account_id;
  11966. WFIFOL(fd,8) = f_sd->status.char_id;
  11967. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  11968. }
  11969. WFIFOSET(fd, packet_len(0x209));
  11970. }
  11971. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  11972. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  11973. void clif_friendlist_req(struct map_session_data* sd, int account_id, int char_id, const char* name) {
  11974. int fd;
  11975. nullpo_retv(sd);
  11976. fd = sd->fd;
  11977. WFIFOHEAD(fd,packet_len(0x207));
  11978. WFIFOW(fd,0) = 0x207;
  11979. WFIFOL(fd,2) = account_id;
  11980. WFIFOL(fd,6) = char_id;
  11981. memcpy(WFIFOP(fd,10), name, NAME_LENGTH);
  11982. WFIFOSET(fd,packet_len(0x207));
  11983. }
  11984. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  11985. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  11986. /// 0202 <name>.24B
  11987. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) {
  11988. struct map_session_data *f_sd;
  11989. int i;
  11990. char *nick = (char*)RFIFOP(fd,2);
  11991. nick[NAME_LENGTH - 1] = '\0';
  11992. f_sd = map->nick2sd(nick);
  11993. // ensure that the request player's friend list is not full
  11994. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  11995. if( i == MAX_FRIENDS ) {
  11996. clif->friendslist_reqack(sd, f_sd, 2);
  11997. return;
  11998. }
  11999. // Friend doesn't exist (no player with this name)
  12000. if (f_sd == NULL) {
  12001. clif->message(fd, msg_fd(fd,3));
  12002. return;
  12003. }
  12004. if( sd->bl.id == f_sd->bl.id ) { // adding oneself as friend
  12005. return;
  12006. }
  12007. // @noask [LuzZza]
  12008. if(f_sd->state.noask) {
  12009. clif->noask_sub(sd, f_sd, 5);
  12010. return;
  12011. }
  12012. // Friend already exists
  12013. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12014. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12015. clif->message(fd, msg_fd(fd,871)); //"Friend already exists."
  12016. return;
  12017. }
  12018. }
  12019. f_sd->friend_req = sd->status.char_id;
  12020. sd->friend_req = f_sd->status.char_id;
  12021. clif->friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12022. }
  12023. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12024. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12025. /// 0208 <inviter account id>.L <inviter char id>.L <result>.B
  12026. /// 0208 <inviter account id>.L <inviter char id>.L <result>.L (PACKETVER >= 6)
  12027. /// result:
  12028. /// 0 = rejected
  12029. /// 1 = accepted
  12030. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12031. {
  12032. struct map_session_data *f_sd;
  12033. int account_id;
  12034. char reply;
  12035. account_id = RFIFOL(fd,2);
  12036. //char_id = RFIFOL(fd,6);
  12037. #if PACKETVER < 6
  12038. reply = RFIFOB(fd,10);
  12039. #else
  12040. reply = RFIFOL(fd,10);
  12041. #endif
  12042. if( sd->bl.id == account_id ) { // adding oneself as friend
  12043. return;
  12044. }
  12045. f_sd = map->id2sd(account_id); //The account id is the same as the bl.id of players.
  12046. if (f_sd == NULL)
  12047. return;
  12048. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12049. clif->friendslist_reqack(f_sd, sd, 1);
  12050. else {
  12051. int i;
  12052. // Find an empty slot
  12053. for (i = 0; i < MAX_FRIENDS; i++)
  12054. if (f_sd->status.friends[i].char_id == 0)
  12055. break;
  12056. if (i == MAX_FRIENDS) {
  12057. clif->friendslist_reqack(f_sd, sd, 2);
  12058. return;
  12059. }
  12060. f_sd->status.friends[i].account_id = sd->status.account_id;
  12061. f_sd->status.friends[i].char_id = sd->status.char_id;
  12062. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12063. clif->friendslist_reqack(f_sd, sd, 0);
  12064. if (battle_config.friend_auto_add) {
  12065. // Also add f_sd to sd's friendlist.
  12066. for (i = 0; i < MAX_FRIENDS; i++) {
  12067. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12068. return; //No need to add anything.
  12069. if (sd->status.friends[i].char_id == 0)
  12070. break;
  12071. }
  12072. if (i == MAX_FRIENDS) {
  12073. clif->friendslist_reqack(sd, f_sd, 2);
  12074. return;
  12075. }
  12076. sd->status.friends[i].account_id = f_sd->status.account_id;
  12077. sd->status.friends[i].char_id = f_sd->status.char_id;
  12078. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12079. clif->friendslist_reqack(sd, f_sd, 0);
  12080. }
  12081. }
  12082. }
  12083. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12084. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12085. /// 0203 <account id>.L <char id>.L
  12086. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12087. {
  12088. struct map_session_data *f_sd = NULL;
  12089. int account_id, char_id;
  12090. int i, j;
  12091. account_id = RFIFOL(fd,2);
  12092. char_id = RFIFOL(fd,6);
  12093. // Search friend
  12094. for (i = 0; i < MAX_FRIENDS &&
  12095. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12096. if (i == MAX_FRIENDS) {
  12097. clif->message(fd, msg_fd(fd,872)); //"Name not found in list."
  12098. return;
  12099. }
  12100. //remove from friend's list first
  12101. if( (f_sd = map->id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12102. for (i = 0; i < MAX_FRIENDS &&
  12103. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12104. if (i != MAX_FRIENDS) {
  12105. // move all chars up
  12106. for(j = i + 1; j < MAX_FRIENDS; j++)
  12107. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12108. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12109. //should the guy be notified of some message? we should add it here if so
  12110. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12111. WFIFOW(f_sd->fd,0) = 0x20a;
  12112. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12113. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12114. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12115. }
  12116. } else { //friend not online -- ask char server to delete from his friendlist
  12117. if(!chrif->removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12118. clif->message(fd, msg_fd(fd,873)); //"This action can't be performed at the moment. Please try again later."
  12119. return;
  12120. }
  12121. }
  12122. // We can now delete from original requester
  12123. for (i = 0; i < MAX_FRIENDS &&
  12124. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12125. // move all chars up
  12126. for(j = i + 1; j < MAX_FRIENDS; j++)
  12127. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12128. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12129. clif->message(fd, msg_fd(fd,874)); //"Friend removed"
  12130. WFIFOHEAD(fd,packet_len(0x20a));
  12131. WFIFOW(fd,0) = 0x20a;
  12132. WFIFOL(fd,2) = account_id;
  12133. WFIFOL(fd,6) = char_id;
  12134. WFIFOSET(fd, packet_len(0x20a));
  12135. }
  12136. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12137. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12138. void clif_PVPInfo(struct map_session_data* sd) {
  12139. int fd;
  12140. nullpo_retv(sd);
  12141. fd = sd->fd;
  12142. WFIFOHEAD(fd,packet_len(0x210));
  12143. WFIFOW(fd,0) = 0x210;
  12144. WFIFOL(fd,2) = sd->status.char_id;
  12145. WFIFOL(fd,6) = sd->status.account_id;
  12146. WFIFOL(fd,10) = sd->pvp_won; // times won
  12147. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12148. WFIFOL(fd,18) = sd->pvp_point;
  12149. WFIFOSET(fd, packet_len(0x210));
  12150. }
  12151. void clif_parse_PVPInfo(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  12152. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12153. /// 020f <char id>.L <account id>.L
  12154. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12155. {
  12156. // TODO: Is there a way to use this on an another player (char/acc id)?
  12157. clif->PVPInfo(sd);
  12158. }
  12159. /// Ranking list
  12160. /// ranking pointlist { <name>.24B <point>.L }*10
  12161. void clif_ranklist_sub(unsigned char *buf, enum fame_list_type type) {
  12162. const char* name;
  12163. struct fame_list* list;
  12164. int i;
  12165. nullpo_retv(buf);
  12166. switch( type ) {
  12167. case RANKTYPE_BLACKSMITH: list = pc->smith_fame_list; break;
  12168. case RANKTYPE_ALCHEMIST: list = pc->chemist_fame_list; break;
  12169. case RANKTYPE_TAEKWON: list = pc->taekwon_fame_list; break;
  12170. default: return; // Unsupported
  12171. }
  12172. // Packet size limits this list to 10 elements. [Skotlex]
  12173. for( i = 0; i < 10 && i < MAX_FAME_LIST; i++ ) {
  12174. if( list[i].id > 0 ) {
  12175. if( strcmp(list[i].name, "-") == 0 && (name = map->charid2nick(list[i].id)) != NULL ) {
  12176. strncpy((char *)(WBUFP(buf, 24 * i)), name, NAME_LENGTH);
  12177. } else {
  12178. strncpy((char *)(WBUFP(buf, 24 * i)), list[i].name, NAME_LENGTH);
  12179. }
  12180. } else {
  12181. strncpy((char *)(WBUFP(buf, 24 * i)), "None", 5);
  12182. }
  12183. WBUFL(buf, 24 * 10 + i * 4) = list[i].fame; //points
  12184. }
  12185. for( ;i < 10; i++ ) { // In case the MAX is less than 10.
  12186. strncpy((char *)(WBUFP(buf, 24 * i)), "Unavailable", 12);
  12187. WBUFL(buf, 24 * 10 + i * 4) = 0;
  12188. }
  12189. }
  12190. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  12191. void clif_ranklist(struct map_session_data *sd, enum fame_list_type type) {
  12192. int fd;
  12193. int mypoint = 0;
  12194. int upperMask;
  12195. nullpo_retv(sd);
  12196. fd = sd->fd;
  12197. upperMask = sd->class_&MAPID_UPPERMASK;
  12198. WFIFOHEAD(fd, 288);
  12199. WFIFOW(fd, 0) = 0x97d;
  12200. WFIFOW(fd, 2) = type;
  12201. clif_ranklist_sub(WFIFOP(fd,4), type);
  12202. if( (upperMask == MAPID_BLACKSMITH && type == RANKTYPE_BLACKSMITH)
  12203. || (upperMask == MAPID_ALCHEMIST && type == RANKTYPE_ALCHEMIST)
  12204. || (upperMask == MAPID_TAEKWON && type == RANKTYPE_TAEKWON)
  12205. ) {
  12206. mypoint = sd->status.fame;
  12207. } else {
  12208. mypoint = 0;
  12209. }
  12210. WFIFOL(fd, 284) = mypoint; //mypoint
  12211. WFIFOSET(fd, 288);
  12212. }
  12213. void clif_parse_ranklist(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12214. /*
  12215. * 097c <type> (CZ_REQ_RANKING)
  12216. * */
  12217. void clif_parse_ranklist(int fd, struct map_session_data *sd) {
  12218. int16 type = RFIFOW(fd, 2); //type
  12219. switch( type ) {
  12220. case RANKTYPE_BLACKSMITH:
  12221. case RANKTYPE_ALCHEMIST:
  12222. case RANKTYPE_TAEKWON:
  12223. clif->ranklist(sd, type); // pk_list unsupported atm
  12224. break;
  12225. }
  12226. }
  12227. // 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  12228. void clif_update_rankingpoint(struct map_session_data *sd, enum fame_list_type type, int points) {
  12229. #if PACKETVER < 20130710
  12230. switch( type ) {
  12231. case RANKTYPE_BLACKSMITH: clif->fame_blacksmith(sd,points); break;
  12232. case RANKTYPE_ALCHEMIST: clif->fame_alchemist(sd,points); break;
  12233. case RANKTYPE_TAEKWON: clif->fame_taekwon(sd,points); break;
  12234. }
  12235. #else
  12236. int fd;
  12237. nullpo_retv(sd);
  12238. fd = sd->fd;
  12239. WFIFOHEAD(fd, 12);
  12240. WFIFOW(fd, 0) = 0x97e;
  12241. WFIFOW(fd, 2) = type;
  12242. WFIFOL(fd, 4) = points;
  12243. WFIFOL(fd, 8) = sd->status.fame;
  12244. WFIFOSET(fd, 12);
  12245. #endif
  12246. }
  12247. /// /blacksmith list (ZC_BLACKSMITH_RANK).
  12248. /// 0219 { <name>.24B }*10 { <point>.L }*10
  12249. void clif_blacksmith(struct map_session_data* sd) {
  12250. int fd;
  12251. nullpo_retv(sd);
  12252. fd = sd->fd;
  12253. WFIFOHEAD(fd,packet_len(0x219));
  12254. WFIFOW(fd,0) = 0x219;
  12255. clif_ranklist_sub(WFIFOP(fd, 2), RANKTYPE_BLACKSMITH);
  12256. WFIFOSET(fd, packet_len(0x219));
  12257. }
  12258. void clif_parse_Blacksmith(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  12259. /// /blacksmith (CZ_BLACKSMITH_RANK).
  12260. /// 0217
  12261. void clif_parse_Blacksmith(int fd,struct map_session_data *sd) {
  12262. clif->blacksmith(sd);
  12263. }
  12264. /// Notification about backsmith points (ZC_BLACKSMITH_POINT).
  12265. /// 021b <points>.L <total points>.L
  12266. void clif_fame_blacksmith(struct map_session_data *sd, int points) {
  12267. int fd;
  12268. nullpo_retv(sd);
  12269. fd = sd->fd;
  12270. WFIFOHEAD(fd,packet_len(0x21b));
  12271. WFIFOW(fd,0) = 0x21b;
  12272. WFIFOL(fd,2) = points;
  12273. WFIFOL(fd,6) = sd->status.fame;
  12274. WFIFOSET(fd, packet_len(0x21b));
  12275. }
  12276. /// /alchemist list (ZC_ALCHEMIST_RANK).
  12277. /// 021a { <name>.24B }*10 { <point>.L }*10
  12278. void clif_alchemist(struct map_session_data* sd) {
  12279. int fd;
  12280. nullpo_retv(sd);
  12281. fd = sd->fd;
  12282. WFIFOHEAD(fd,packet_len(0x21a));
  12283. WFIFOW(fd,0) = 0x21a;
  12284. clif_ranklist_sub(WFIFOP(fd,2), RANKTYPE_ALCHEMIST);
  12285. WFIFOSET(fd, packet_len(0x21a));
  12286. }
  12287. void clif_parse_Alchemist(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  12288. /// /alchemist (CZ_ALCHEMIST_RANK).
  12289. /// 0218
  12290. void clif_parse_Alchemist(int fd,struct map_session_data *sd) {
  12291. clif->alchemist(sd);
  12292. }
  12293. /// Notification about alchemist points (ZC_ALCHEMIST_POINT).
  12294. /// 021c <points>.L <total points>.L
  12295. void clif_fame_alchemist(struct map_session_data *sd, int points) {
  12296. int fd;
  12297. nullpo_retv(sd);
  12298. fd = sd->fd;
  12299. WFIFOHEAD(fd,packet_len(0x21c));
  12300. WFIFOW(fd,0) = 0x21c;
  12301. WFIFOL(fd,2) = points;
  12302. WFIFOL(fd,6) = sd->status.fame;
  12303. WFIFOSET(fd, packet_len(0x21c));
  12304. }
  12305. /// /taekwon list (ZC_TAEKWON_RANK).
  12306. /// 0226 { <name>.24B }*10 { <point>.L }*10
  12307. void clif_taekwon(struct map_session_data* sd) {
  12308. int fd;
  12309. nullpo_retv(sd);
  12310. fd = sd->fd;
  12311. WFIFOHEAD(fd,packet_len(0x226));
  12312. WFIFOW(fd,0) = 0x226;
  12313. clif_ranklist_sub(WFIFOP(fd,2), RANKTYPE_TAEKWON);
  12314. WFIFOSET(fd, packet_len(0x226));
  12315. }
  12316. void clif_parse_Taekwon(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  12317. /// /taekwon (CZ_TAEKWON_RANK).
  12318. /// 0225
  12319. void clif_parse_Taekwon(int fd,struct map_session_data *sd) {
  12320. clif->taekwon(sd);
  12321. }
  12322. /// Notification about taekwon points (ZC_TAEKWON_POINT).
  12323. /// 0224 <points>.L <total points>.L
  12324. void clif_fame_taekwon(struct map_session_data *sd, int points) {
  12325. int fd;
  12326. nullpo_retv(sd);
  12327. fd = sd->fd;
  12328. WFIFOHEAD(fd,packet_len(0x224));
  12329. WFIFOW(fd,0) = 0x224;
  12330. WFIFOL(fd,2) = points;
  12331. WFIFOL(fd,6) = sd->status.fame;
  12332. WFIFOSET(fd, packet_len(0x224));
  12333. }
  12334. /// /pk list (ZC_KILLER_RANK).
  12335. /// 0238 { <name>.24B }*10 { <point>.L }*10
  12336. void clif_ranking_pk(struct map_session_data* sd) {
  12337. int i, fd;
  12338. nullpo_retv(sd);
  12339. fd = sd->fd;
  12340. WFIFOHEAD(fd,packet_len(0x238));
  12341. WFIFOW(fd,0) = 0x238;
  12342. for (i = 0; i < 10;i ++) {
  12343. strncpy((char*)WFIFOP(fd, i * 24 + 2), "Unknown", NAME_LENGTH);
  12344. WFIFOL(fd,i*4+242) = 0;
  12345. }
  12346. WFIFOSET(fd, packet_len(0x238));
  12347. }
  12348. void clif_parse_RankingPk(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  12349. /// /pk (CZ_KILLER_RANK).
  12350. /// 0237
  12351. void clif_parse_RankingPk(int fd,struct map_session_data *sd) {
  12352. clif->ranking_pk(sd);
  12353. }
  12354. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  12355. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12356. /// 0254 <which>.B
  12357. /// which:
  12358. /// 0 = sun
  12359. /// 1 = moon
  12360. /// 2 = star
  12361. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12362. {
  12363. int i;
  12364. if (sd->menuskill_id != SG_FEEL)
  12365. return;
  12366. i = sd->menuskill_val-1;
  12367. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12368. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12369. sd->feel_map[i].m = sd->bl.m;
  12370. pc_setglobalreg(sd,script->add_str(pc->sg_info[i].feel_var),sd->feel_map[i].index);
  12371. #if 0 // Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12372. clif_misceffect2(&sd->bl, 0x1b0);
  12373. clif_misceffect2(&sd->bl, 0x21f);
  12374. #endif // 0
  12375. clif->feel_info(sd, i, 0);
  12376. clif_menuskill_clear(sd);
  12377. }
  12378. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12379. /// 0253 <which>.B
  12380. /// which:
  12381. /// 0 = sun
  12382. /// 1 = moon
  12383. /// 2 = star
  12384. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12385. {
  12386. nullpo_retv(sd);
  12387. WFIFOHEAD(fd,packet_len(0x253));
  12388. WFIFOW(fd,0)=0x253;
  12389. WFIFOB(fd,2)=TOB(skill_lv-1);
  12390. WFIFOSET(fd, packet_len(0x253));
  12391. sd->menuskill_id = SG_FEEL;
  12392. sd->menuskill_val = skill_lv;
  12393. }
  12394. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12395. /// Request to change homunculus' name (CZ_RENAME_MER).
  12396. /// 0231 <name>.24B
  12397. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd) {
  12398. homun->change_name(sd,(char*)RFIFOP(fd,2));
  12399. }
  12400. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12401. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12402. /// 0234 <id>.L
  12403. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  12404. {
  12405. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  12406. struct block_list *bl = NULL;
  12407. struct unit_data *ud = NULL;
  12408. if (sd->md && sd->md->bl.id == id)
  12409. bl = &sd->md->bl;
  12410. else if (homun_alive(sd->hd) && sd->hd->bl.id == id)
  12411. bl = &sd->hd->bl; // Moving Homunculus
  12412. else
  12413. return;
  12414. unit->calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12415. ud = unit->bl2ud(bl);
  12416. unit->walktoxy(bl, ud->to_x, ud->to_y, 4);
  12417. }
  12418. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12419. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12420. /// 0232 <id>.L <position data>.3B
  12421. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  12422. {
  12423. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  12424. struct block_list *bl = NULL;
  12425. short x, y;
  12426. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[1], &x, &y, NULL);
  12427. if( sd->md && sd->md->bl.id == id )
  12428. bl = &sd->md->bl; // Moving Mercenary
  12429. else if( homun_alive(sd->hd) && sd->hd->bl.id == id )
  12430. bl = &sd->hd->bl; // Moving Homunculus
  12431. else
  12432. return;
  12433. unit->walktoxy(bl, x, y, 4);
  12434. }
  12435. void clif_parse_HomAttack(int fd,struct map_session_data *sd) __attribute__((nonnull (2)));
  12436. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12437. /// 0233 <id>.L <target id>.L <action>.B
  12438. /// action:
  12439. /// always 0
  12440. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12441. {
  12442. struct block_list *bl = NULL;
  12443. int id = RFIFOL(fd,2),
  12444. target_id = RFIFOL(fd,6),
  12445. action_type = RFIFOB(fd,10);
  12446. if( homun_alive(sd->hd) && sd->hd->bl.id == id )
  12447. bl = &sd->hd->bl;
  12448. else if( sd->md && sd->md->bl.id == id )
  12449. bl = &sd->md->bl;
  12450. else return;
  12451. unit->stop_attack(bl);
  12452. unit->attack(bl, target_id, action_type != 0);
  12453. }
  12454. void clif_parse_HomMenu(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12455. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12456. /// 022d <type>.W <command>.B
  12457. /// type:
  12458. /// always 0
  12459. /// command:
  12460. /// 0 = homunculus information
  12461. /// 1 = feed
  12462. /// 2 = delete
  12463. void clif_parse_HomMenu(int fd, struct map_session_data *sd) { //[orn]
  12464. int cmd;
  12465. cmd = RFIFOW(fd,0);
  12466. if(!homun_alive(sd->hd))
  12467. return;
  12468. homun->menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12469. }
  12470. void clif_parse_AutoRevive(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12471. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12472. /// 0292
  12473. void clif_parse_AutoRevive(int fd, struct map_session_data *sd) {
  12474. int item_position = pc->search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12475. int hpsp = 100;
  12476. if (item_position == INDEX_NOT_FOUND) {
  12477. if (sd->sc.data[SC_LIGHT_OF_REGENE])
  12478. hpsp = 20 * sd->sc.data[SC_LIGHT_OF_REGENE]->val1;
  12479. else
  12480. return;
  12481. }
  12482. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12483. return;
  12484. if (!status->revive(&sd->bl, hpsp, hpsp))
  12485. return;
  12486. if (item_position == INDEX_NOT_FOUND)
  12487. status_change_end(&sd->bl,SC_LIGHT_OF_REGENE,INVALID_TIMER);
  12488. else
  12489. pc->delitem(sd, item_position, 1, 0, DELITEM_SKILLUSE, LOG_TYPE_CONSUME);
  12490. clif->skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  12491. }
  12492. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12493. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12494. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12495. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12496. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12497. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12498. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12499. void clif_check(int fd, struct map_session_data* pl_sd) {
  12500. nullpo_retv(pl_sd);
  12501. WFIFOHEAD(fd,packet_len(0x214));
  12502. WFIFOW(fd, 0) = 0x214;
  12503. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12504. WFIFOB(fd, 3) = pc->need_status_point(pl_sd, SP_STR, 1);
  12505. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12506. WFIFOB(fd, 5) = pc->need_status_point(pl_sd, SP_AGI, 1);
  12507. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12508. WFIFOB(fd, 7) = pc->need_status_point(pl_sd, SP_VIT, 1);
  12509. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12510. WFIFOB(fd, 9) = pc->need_status_point(pl_sd, SP_INT, 1);
  12511. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12512. WFIFOB(fd,11) = pc->need_status_point(pl_sd, SP_DEX, 1);
  12513. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12514. WFIFOB(fd,13) = pc->need_status_point(pl_sd, SP_LUK, 1);
  12515. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12516. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12517. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12518. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12519. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12520. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12521. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12522. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12523. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12524. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12525. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12526. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12527. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12528. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe a delay?
  12529. WFIFOSET(fd,packet_len(0x214));
  12530. }
  12531. void clif_parse_Check(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12532. /// /check (CZ_REQ_STATUS_GM).
  12533. /// Request character's status values.
  12534. /// 0213 <char name>.24B
  12535. void clif_parse_Check(int fd, struct map_session_data *sd)
  12536. {
  12537. char charname[NAME_LENGTH];
  12538. struct map_session_data* pl_sd;
  12539. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12540. return;
  12541. safestrncpy(charname, (const char*)RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12542. if( ( pl_sd = map->nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) ) {
  12543. return;
  12544. }
  12545. clif->check(fd, pl_sd);
  12546. }
  12547. /// MAIL SYSTEM
  12548. /// By Zephyrus
  12549. ///
  12550. /// Notification about the result of adding an item to mail (ZC_ACK_MAIL_ADD_ITEM).
  12551. /// 0255 <index>.W <result>.B
  12552. /// result:
  12553. /// 0 = success
  12554. /// 1 = failure
  12555. void clif_Mail_setattachment(int fd, int index, uint8 flag)
  12556. {
  12557. WFIFOHEAD(fd,packet_len(0x255));
  12558. WFIFOW(fd,0) = 0x255;
  12559. WFIFOW(fd,2) = index;
  12560. WFIFOB(fd,4) = flag;
  12561. WFIFOSET(fd,packet_len(0x255));
  12562. }
  12563. /// Notification about the result of retrieving a mail attachment (ZC_MAIL_REQ_GET_ITEM).
  12564. /// 0245 <result>.B
  12565. /// result:
  12566. /// 0 = success
  12567. /// 1 = failure
  12568. /// 2 = too many items
  12569. void clif_Mail_getattachment(int fd, uint8 flag)
  12570. {
  12571. WFIFOHEAD(fd,packet_len(0x245));
  12572. WFIFOW(fd,0) = 0x245;
  12573. WFIFOB(fd,2) = flag;
  12574. WFIFOSET(fd,packet_len(0x245));
  12575. }
  12576. /// Notification about the result of sending a mail (ZC_MAIL_REQ_SEND).
  12577. /// 0249 <result>.B
  12578. /// result:
  12579. /// 0 = success
  12580. /// 1 = recipient does not exist
  12581. void clif_Mail_send(int fd, bool fail)
  12582. {
  12583. WFIFOHEAD(fd,packet_len(0x249));
  12584. WFIFOW(fd,0) = 0x249;
  12585. WFIFOB(fd,2) = fail;
  12586. WFIFOSET(fd,packet_len(0x249));
  12587. }
  12588. /// Notification about the result of deleting a mail (ZC_ACK_MAIL_DELETE).
  12589. /// 0257 <mail id>.L <result>.W
  12590. /// result:
  12591. /// 0 = success
  12592. /// 1 = failure
  12593. void clif_Mail_delete(int fd, int mail_id, short fail)
  12594. {
  12595. WFIFOHEAD(fd, packet_len(0x257));
  12596. WFIFOW(fd,0) = 0x257;
  12597. WFIFOL(fd,2) = mail_id;
  12598. WFIFOW(fd,6) = fail;
  12599. WFIFOSET(fd, packet_len(0x257));
  12600. }
  12601. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12602. /// 0274 <mail id>.L <result>.W
  12603. /// result:
  12604. /// 0 = success
  12605. /// 1 = failure
  12606. void clif_Mail_return(int fd, int mail_id, short fail)
  12607. {
  12608. WFIFOHEAD(fd,packet_len(0x274));
  12609. WFIFOW(fd,0) = 0x274;
  12610. WFIFOL(fd,2) = mail_id;
  12611. WFIFOW(fd,6) = fail;
  12612. WFIFOSET(fd,packet_len(0x274));
  12613. }
  12614. /// Notification about new mail (ZC_MAIL_RECEIVE).
  12615. /// 024a <mail id>.L <title>.40B <sender>.24B
  12616. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  12617. {
  12618. nullpo_retv(sender);
  12619. nullpo_retv(title);
  12620. WFIFOHEAD(fd,packet_len(0x24a));
  12621. WFIFOW(fd,0) = 0x24a;
  12622. WFIFOL(fd,2) = mail_id;
  12623. safestrncpy((char*)WFIFOP(fd,6), title, MAIL_TITLE_LENGTH);
  12624. safestrncpy((char*)WFIFOP(fd,46), sender, NAME_LENGTH);
  12625. WFIFOSET(fd,packet_len(0x24a));
  12626. }
  12627. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12628. /// 0260 <type>.L
  12629. /// type:
  12630. /// 0 = open
  12631. /// 1 = close
  12632. void clif_Mail_window(int fd, int flag)
  12633. {
  12634. WFIFOHEAD(fd,packet_len(0x260));
  12635. WFIFOW(fd,0) = 0x260;
  12636. WFIFOL(fd,2) = flag;
  12637. WFIFOSET(fd,packet_len(0x260));
  12638. }
  12639. /// Lists mails stored in inbox (ZC_MAIL_REQ_GET_LIST).
  12640. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount
  12641. /// read:
  12642. /// 0 = unread
  12643. /// 1 = read
  12644. void clif_Mail_refreshinbox(struct map_session_data *sd)
  12645. {
  12646. int fd = sd->fd;
  12647. struct mail_data *md;
  12648. struct mail_message *msg;
  12649. int len, i, j;
  12650. nullpo_retv(sd);
  12651. md = &sd->mail.inbox;
  12652. len = 8 + (73 * md->amount);
  12653. WFIFOHEAD(fd,len);
  12654. WFIFOW(fd,0) = 0x240;
  12655. WFIFOW(fd,2) = len;
  12656. WFIFOL(fd,4) = md->amount;
  12657. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12658. {
  12659. msg = &md->msg[i];
  12660. if (msg->id < 1)
  12661. continue;
  12662. WFIFOL(fd,8+73*j) = msg->id;
  12663. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12664. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12665. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12666. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12667. j++;
  12668. }
  12669. WFIFOSET(fd,len);
  12670. if( md->full ) {// TODO: is this official?
  12671. char output[100];
  12672. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12673. clif_disp_onlyself(sd, output, strlen(output));
  12674. }
  12675. }
  12676. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12677. /// Mail inbox list request (CZ_MAIL_GET_LIST).
  12678. /// 023f
  12679. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  12680. {
  12681. struct mail_data* md = &sd->mail.inbox;
  12682. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12683. intif->Mail_requestinbox(sd->status.char_id, 1);
  12684. else
  12685. clif->mail_refreshinbox(sd);
  12686. mail->removeitem(sd, 0);
  12687. mail->removezeny(sd, 0);
  12688. }
  12689. /// Opens a mail (ZC_MAIL_REQ_OPEN).
  12690. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L
  12691. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12692. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  12693. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  12694. {
  12695. int i, fd = sd->fd;
  12696. nullpo_retv(sd);
  12697. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12698. if( i == MAIL_MAX_INBOX ) {
  12699. clif->mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  12700. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  12701. return;
  12702. } else {
  12703. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12704. struct item *item = &msg->item;
  12705. struct item_data *data;
  12706. size_t msg_len = strlen(msg->body), len;
  12707. if( msg_len == 0 ) {
  12708. strcpy(msg->body, "(no message)");
  12709. msg_len = strlen(msg->body);
  12710. }
  12711. len = 101 + msg_len;
  12712. WFIFOHEAD(fd,len);
  12713. WFIFOW(fd,0) = 0x242;
  12714. WFIFOW(fd,2) = len;
  12715. WFIFOL(fd,4) = msg->id;
  12716. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  12717. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  12718. WFIFOL(fd,72) = 0;
  12719. WFIFOL(fd,76) = msg->zeny;
  12720. if( item->nameid && (data = itemdb->exists(item->nameid)) != NULL ) {
  12721. WFIFOL(fd,80) = item->amount;
  12722. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  12723. WFIFOW(fd,86) = data->type;
  12724. WFIFOB(fd,88) = item->identify;
  12725. WFIFOB(fd,89) = item->attribute;
  12726. WFIFOB(fd,90) = item->refine;
  12727. WFIFOW(fd,91) = item->card[0];
  12728. WFIFOW(fd,93) = item->card[1];
  12729. WFIFOW(fd,95) = item->card[2];
  12730. WFIFOW(fd,97) = item->card[3];
  12731. } else // no item, set all to zero
  12732. memset(WFIFOP(fd,80), 0x00, 19);
  12733. WFIFOB(fd,99) = (unsigned char)msg_len;
  12734. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  12735. WFIFOSET(fd,len);
  12736. if (msg->status == MAIL_UNREAD) {
  12737. msg->status = MAIL_READ;
  12738. intif->Mail_read(mail_id);
  12739. clif->pMail_refreshinbox(fd, sd);
  12740. }
  12741. }
  12742. }
  12743. void clif_parse_Mail_read(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12744. /// Request to open a mail (CZ_MAIL_OPEN).
  12745. /// 0241 <mail id>.L
  12746. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  12747. {
  12748. int mail_id = RFIFOL(fd,2);
  12749. if( mail_id <= 0 )
  12750. return;
  12751. if( mail->invalid_operation(sd) )
  12752. return;
  12753. clif->mail_read(sd, RFIFOL(fd,2));
  12754. }
  12755. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12756. /// Request to receive mail's attachment (CZ_MAIL_GET_ITEM).
  12757. /// 0244 <mail id>.L
  12758. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  12759. {
  12760. int mail_id = RFIFOL(fd,2);
  12761. int i;
  12762. bool fail = false;
  12763. if( !chrif->isconnected() )
  12764. return;
  12765. if( mail_id <= 0 )
  12766. return;
  12767. if( mail->invalid_operation(sd) )
  12768. return;
  12769. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12770. if( i == MAIL_MAX_INBOX )
  12771. return;
  12772. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  12773. return;
  12774. if( sd->mail.inbox.msg[i].zeny + sd->status.zeny > MAX_ZENY ) {
  12775. clif->mail_getattachment(fd, 1);
  12776. return;
  12777. }
  12778. if( sd->mail.inbox.msg[i].item.nameid > 0 ) {
  12779. struct item_data *data;
  12780. unsigned int weight;
  12781. if ((data = itemdb->exists(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  12782. return;
  12783. if( pc_is90overweight(sd) ) {
  12784. clif->mail_getattachment(fd, 2);
  12785. return;
  12786. }
  12787. switch( pc->checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) ) {
  12788. case ADDITEM_NEW:
  12789. fail = ( pc->inventoryblank(sd) == 0 );
  12790. break;
  12791. case ADDITEM_OVERAMOUNT:
  12792. fail = true;
  12793. }
  12794. if( fail ) {
  12795. clif->mail_getattachment(fd, 1);
  12796. return;
  12797. }
  12798. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  12799. if( sd->weight + weight > sd->max_weight ) {
  12800. clif->mail_getattachment(fd, 2);
  12801. return;
  12802. }
  12803. }
  12804. sd->mail.inbox.msg[i].zeny = 0;
  12805. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12806. mail->clear(sd);
  12807. clif->mail_read(sd, mail_id);
  12808. intif->Mail_getattach(sd->status.char_id, mail_id);
  12809. }
  12810. void clif_parse_Mail_delete(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12811. /// Request to delete a mail (CZ_MAIL_DELETE).
  12812. /// 0243 <mail id>.L
  12813. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  12814. {
  12815. int mail_id = RFIFOL(fd,2);
  12816. int i;
  12817. if( !chrif->isconnected() )
  12818. return;
  12819. if( mail_id <= 0 )
  12820. return;
  12821. if( mail->invalid_operation(sd) )
  12822. return;
  12823. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12824. if (i < MAIL_MAX_INBOX) {
  12825. struct mail_message *msg = &sd->mail.inbox.msg[i];
  12826. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) {// can't delete mail without removing attachment first
  12827. clif->mail_delete(sd->fd, mail_id, 1);
  12828. return;
  12829. }
  12830. sd->mail.inbox.msg[i].zeny = 0;
  12831. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12832. mail->clear(sd);
  12833. intif->Mail_delete(sd->status.char_id, mail_id);
  12834. }
  12835. }
  12836. void clif_parse_Mail_return(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12837. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  12838. /// 0273 <mail id>.L <receive name>.24B
  12839. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  12840. {
  12841. int mail_id = RFIFOL(fd,2);
  12842. int i;
  12843. if( mail_id <= 0 )
  12844. return;
  12845. if( mail->invalid_operation(sd) )
  12846. return;
  12847. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  12848. if (i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0) {
  12849. sd->mail.inbox.msg[i].zeny = 0;
  12850. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  12851. mail->clear(sd);
  12852. intif->Mail_return(sd->status.char_id, mail_id);
  12853. } else {
  12854. clif->mail_return(sd->fd, mail_id, 1);
  12855. }
  12856. }
  12857. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12858. /// Request to add an item or Zeny to mail (CZ_MAIL_ADD_ITEM).
  12859. /// 0247 <index>.W <amount>.L
  12860. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  12861. {
  12862. int idx = RFIFOW(fd,2);
  12863. int amount = RFIFOL(fd,4);
  12864. unsigned char flag;
  12865. if( !chrif->isconnected() )
  12866. return;
  12867. if (idx < 0 || amount < 0)
  12868. return;
  12869. flag = mail->setitem(sd, idx, amount);
  12870. clif->mail_setattachment(fd,idx,flag);
  12871. }
  12872. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12873. /// Request to reset mail item and/or Zeny (CZ_MAIL_RESET_ITEM).
  12874. /// 0246 <type>.W
  12875. /// type:
  12876. /// 0 = reset all
  12877. /// 1 = remove item
  12878. /// 2 = remove zeny
  12879. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  12880. {
  12881. int flag = RFIFOW(fd,2);
  12882. if (flag == 0 || flag == 1)
  12883. mail->removeitem(sd, 0);
  12884. if (flag == 0 || flag == 2)
  12885. mail->removezeny(sd, 0);
  12886. }
  12887. void clif_parse_Mail_send(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  12888. /// Request to send mail (CZ_MAIL_SEND).
  12889. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B
  12890. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  12891. {
  12892. struct mail_message msg;
  12893. int body_len;
  12894. if( !chrif->isconnected() )
  12895. return;
  12896. if( sd->state.trading )
  12897. return;
  12898. if( RFIFOW(fd,2) < 69 ) {
  12899. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  12900. return;
  12901. }
  12902. if( DIFF_TICK(sd->cansendmail_tick, timer->gettick()) > 0 ) {
  12903. clif->message(sd->fd,msg_sd(sd,875)); //"Cannot send mails too fast!!."
  12904. clif->mail_send(fd, true); // fail
  12905. return;
  12906. }
  12907. body_len = RFIFOB(fd,68);
  12908. if (body_len > MAIL_BODY_LENGTH)
  12909. body_len = MAIL_BODY_LENGTH;
  12910. memset(&msg, 0, sizeof(msg));
  12911. if (!mail->setattachment(sd, &msg)) { // Invalid Append condition
  12912. clif->mail_send(sd->fd, true); // fail
  12913. mail->removeitem(sd,0);
  12914. mail->removezeny(sd,0);
  12915. return;
  12916. }
  12917. msg.id = 0; // id will be assigned by charserver
  12918. msg.send_id = sd->status.char_id;
  12919. msg.dest_id = 0; // will attempt to resolve name
  12920. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  12921. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  12922. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  12923. if (msg.title[0] == '\0') {
  12924. return; // Message has no length and somehow client verification was skipped.
  12925. }
  12926. if (body_len)
  12927. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  12928. else
  12929. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  12930. msg.timestamp = time(NULL);
  12931. if( !intif->Mail_send(sd->status.account_id, &msg) )
  12932. mail->deliveryfail(sd, &msg);
  12933. sd->cansendmail_tick = timer->gettick() + 1000; // 1 Second flood Protection
  12934. }
  12935. /// AUCTION SYSTEM
  12936. /// By Zephyrus
  12937. ///
  12938. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  12939. /// 025f <type>.L
  12940. /// type:
  12941. /// 0 = open
  12942. /// 1 = close
  12943. void clif_Auction_openwindow(struct map_session_data *sd)
  12944. {
  12945. int fd;
  12946. nullpo_retv(sd);
  12947. fd = sd->fd;
  12948. if (sd->state.storage_flag != STORAGE_FLAG_CLOSED || sd->state.vending || sd->state.buyingstore || sd->state.trading)
  12949. return;
  12950. if( !battle_config.feature_auction )
  12951. return;
  12952. WFIFOHEAD(fd,packet_len(0x25f));
  12953. WFIFOW(fd,0) = 0x25f;
  12954. WFIFOL(fd,2) = 0;
  12955. WFIFOSET(fd,packet_len(0x25f));
  12956. }
  12957. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  12958. /// 0252 <packet len>.W <pages>.L <count>.L { <auction id>.L <seller name>.24B <name id>.W <type>.L <amount>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <now price>.L <max price>.L <buyer name>.24B <delete time>.L }*
  12959. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  12960. {
  12961. int i, fd, len = sizeof(struct auction_data);
  12962. struct auction_data auction;
  12963. struct item_data *item;
  12964. nullpo_retv(sd);
  12965. fd = sd->fd;
  12966. WFIFOHEAD(fd,12 + (count * 83));
  12967. WFIFOW(fd,0) = 0x252;
  12968. WFIFOW(fd,2) = 12 + (count * 83);
  12969. WFIFOL(fd,4) = pages;
  12970. WFIFOL(fd,8) = count;
  12971. for( i = 0; i < count; i++ ) {
  12972. int k = 12 + (i * 83);
  12973. memcpy(&auction, RBUFP(buf,i * len), len);
  12974. WFIFOL(fd,k) = auction.auction_id;
  12975. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  12976. if( (item = itemdb->exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  12977. WFIFOW(fd,28+k) = item->view_id;
  12978. else
  12979. WFIFOW(fd,28+k) = auction.item.nameid;
  12980. WFIFOL(fd,30+k) = auction.type;
  12981. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  12982. WFIFOB(fd,36+k) = auction.item.identify;
  12983. WFIFOB(fd,37+k) = auction.item.attribute;
  12984. WFIFOB(fd,38+k) = auction.item.refine;
  12985. WFIFOW(fd,39+k) = auction.item.card[0];
  12986. WFIFOW(fd,41+k) = auction.item.card[1];
  12987. WFIFOW(fd,43+k) = auction.item.card[2];
  12988. WFIFOW(fd,45+k) = auction.item.card[3];
  12989. WFIFOL(fd,47+k) = auction.price;
  12990. WFIFOL(fd,51+k) = auction.buynow;
  12991. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  12992. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  12993. }
  12994. WFIFOSET(fd,WFIFOW(fd,2));
  12995. }
  12996. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  12997. /// 0256 <index>.W <result>.B
  12998. /// result:
  12999. /// 0 = success
  13000. /// 1 = failure
  13001. void clif_Auction_setitem(int fd, int index, bool fail) {
  13002. WFIFOHEAD(fd,packet_len(0x256));
  13003. WFIFOW(fd,0) = 0x256;
  13004. WFIFOW(fd,2) = index;
  13005. WFIFOB(fd,4) = fail;
  13006. WFIFOSET(fd,packet_len(0x256));
  13007. }
  13008. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  13009. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13010. /// 024b <type>.W
  13011. /// type:
  13012. /// 0 = create (any other action in auction window)
  13013. /// 1 = cancel (cancel pressed on register tab)
  13014. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13015. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  13016. {
  13017. if( sd->auction.amount > 0 )
  13018. clif->additem(sd, sd->auction.index, sd->auction.amount, 0);
  13019. sd->auction.amount = 0;
  13020. }
  13021. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  13022. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13023. /// 024c <index>.W <count>.L
  13024. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  13025. {
  13026. int idx = RFIFOW(fd,2) - 2;
  13027. int amount = RFIFOL(fd,4); // Always 1
  13028. struct item_data *item;
  13029. if( !battle_config.feature_auction )
  13030. return;
  13031. if( sd->auction.amount > 0 )
  13032. sd->auction.amount = 0;
  13033. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13034. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13035. return;
  13036. }
  13037. if( amount != 1 || amount > sd->status.inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  13038. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13039. return;
  13040. }
  13041. if( (item = itemdb->exists(sd->status.inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC) )
  13042. { // Consumable or pets are not allowed
  13043. clif->auction_setitem(sd->fd, idx, true);
  13044. return;
  13045. }
  13046. if( !pc_can_give_items(sd) || sd->status.inventory[idx].expire_time ||
  13047. !sd->status.inventory[idx].identify ||
  13048. !itemdb_canauction(&sd->status.inventory[idx],pc_get_group_level(sd)) || // Quest Item or something else
  13049. (sd->status.inventory[idx].bound && !pc_can_give_bound_items(sd)) ) {
  13050. clif->auction_setitem(sd->fd, idx, true);
  13051. return;
  13052. }
  13053. sd->auction.index = idx;
  13054. sd->auction.amount = amount;
  13055. clif->auction_setitem(fd, idx + 2, false);
  13056. }
  13057. /// Result from an auction action (ZC_AUCTION_RESULT).
  13058. /// 0250 <result>.B
  13059. /// result:
  13060. /// 0 = You have failed to bid into the auction
  13061. /// 1 = You have successfully bid in the auction
  13062. /// 2 = The auction has been canceled
  13063. /// 3 = An auction with at least one bidder cannot be canceled
  13064. /// 4 = You cannot register more than 5 items in an auction at a time
  13065. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13066. /// 6 = You have won the auction
  13067. /// 7 = You have failed to win the auction
  13068. /// 8 = You do not have enough Zeny
  13069. /// 9 = You cannot place more than 5 bids at a time
  13070. void clif_Auction_message(int fd, unsigned char flag)
  13071. {
  13072. WFIFOHEAD(fd,packet_len(0x250));
  13073. WFIFOW(fd,0) = 0x250;
  13074. WFIFOB(fd,2) = flag;
  13075. WFIFOSET(fd,packet_len(0x250));
  13076. }
  13077. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13078. /// 025e <result>.W
  13079. /// result:
  13080. /// 0 = You have ended the auction
  13081. /// 1 = You cannot end the auction
  13082. /// 2 = Auction ID is incorrect
  13083. void clif_Auction_close(int fd, unsigned char flag)
  13084. {
  13085. WFIFOHEAD(fd,packet_len(0x25e));
  13086. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13087. WFIFOW(fd,2) = flag;
  13088. WFIFOSET(fd,packet_len(0x25e));
  13089. }
  13090. void clif_parse_Auction_register(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  13091. /// Request to add an auction (CZ_AUCTION_ADD).
  13092. /// 024d <now money>.L <max money>.L <delete hour>.W
  13093. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13094. {
  13095. struct auction_data auction;
  13096. struct item_data *item;
  13097. if (!battle_config.feature_auction)
  13098. return;
  13099. Assert_retv(sd->auction.index >= 0 && sd->auction.index < MAX_INVENTORY);
  13100. memset(&auction, 0, sizeof(auction));
  13101. auction.price = RFIFOL(fd,2);
  13102. auction.buynow = RFIFOL(fd,6);
  13103. auction.hours = RFIFOW(fd,10);
  13104. // Invalid Situations...
  13105. if (auction.price <= 0 || auction.buynow <= 0) {
  13106. ShowWarning("Character %s trying to register auction wit wrong price.\n", sd->status.name);
  13107. return;
  13108. }
  13109. if( sd->auction.amount < 1 ) {
  13110. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13111. return;
  13112. }
  13113. if( auction.price >= auction.buynow ) {
  13114. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13115. return;
  13116. }
  13117. if( auction.hours < 1 || auction.hours > 48 ) {
  13118. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13119. return;
  13120. }
  13121. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13122. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13123. return;
  13124. }
  13125. if( auction.buynow > battle_config.auction_maximumprice )
  13126. { // Zeny Limits
  13127. auction.buynow = battle_config.auction_maximumprice;
  13128. if( auction.price >= auction.buynow )
  13129. auction.price = auction.buynow - 1;
  13130. }
  13131. auction.auction_id = 0;
  13132. auction.seller_id = sd->status.char_id;
  13133. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13134. auction.buyer_id = 0;
  13135. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13136. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  13137. {
  13138. clif->auction_message(fd, 2); // The auction has been canceled
  13139. return;
  13140. }
  13141. if( (item = itemdb->exists(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  13142. { // Just in case
  13143. clif->auction_message(fd, 2); // The auction has been canceled
  13144. return;
  13145. }
  13146. // Auction checks...
  13147. if( sd->status.inventory[sd->auction.index].bound && !pc_can_give_bound_items(sd) ) {
  13148. clif->message(sd->fd, msg_sd(sd,293));
  13149. clif->auction_message(fd, 2); // The auction has been canceled
  13150. return;
  13151. }
  13152. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13153. auction.type = item->type;
  13154. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  13155. auction.item.amount = 1;
  13156. auction.timestamp = 0;
  13157. if( !intif->Auction_register(&auction) )
  13158. clif->auction_message(fd, 4); // No Char Server? lets say something to the client
  13159. else
  13160. {
  13161. int zeny = auction.hours*battle_config.auction_feeperhour;
  13162. pc->delitem(sd, sd->auction.index, sd->auction.amount, 1, DELITEM_SOLD, LOG_TYPE_AUCTION);
  13163. sd->auction.amount = 0;
  13164. pc->payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13165. }
  13166. }
  13167. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  13168. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13169. /// 024e <auction id>.L
  13170. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  13171. {
  13172. unsigned int auction_id = RFIFOL(fd,2);
  13173. intif->Auction_cancel(sd->status.char_id, auction_id);
  13174. }
  13175. void clif_parse_Auction_close(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  13176. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13177. /// 025d <auction id>.L
  13178. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  13179. {
  13180. unsigned int auction_id = RFIFOL(fd,2);
  13181. intif->Auction_close(sd->status.char_id, auction_id);
  13182. }
  13183. void clif_parse_Auction_bid(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  13184. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13185. /// 024f <auction id>.L <money>.L
  13186. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  13187. {
  13188. unsigned int auction_id = RFIFOL(fd,2);
  13189. int bid = RFIFOL(fd,6);
  13190. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13191. clif->message(sd->fd, msg_sd(sd,246));
  13192. return;
  13193. }
  13194. if( bid <= 0 )
  13195. clif->auction_message(fd, 0); // You have failed to bid into the auction
  13196. else if( bid > sd->status.zeny )
  13197. clif->auction_message(fd, 8); // You do not have enough zeny
  13198. else if ( intif->CheckForCharServer() ) // char server is down (bugreport:1138)
  13199. clif->auction_message(fd, 0); // You have failed to bid into the auction
  13200. else {
  13201. pc->payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13202. intif->Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13203. }
  13204. }
  13205. void clif_parse_Auction_search(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  13206. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13207. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13208. /// search type:
  13209. /// 0 = armor
  13210. /// 1 = weapon
  13211. /// 2 = card
  13212. /// 3 = misc
  13213. /// 4 = name search
  13214. /// 5 = auction id search
  13215. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  13216. {
  13217. char search_text[NAME_LENGTH];
  13218. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  13219. int price = RFIFOL(fd,4); // FIXME: bug #5071
  13220. if( !battle_config.feature_auction )
  13221. return;
  13222. clif->pAuction_cancelreg(fd, sd);
  13223. safestrncpy(search_text, (char*)RFIFOP(fd,8), sizeof(search_text));
  13224. intif->Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13225. }
  13226. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  13227. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13228. /// 025c <type>.W
  13229. /// type:
  13230. /// 0 = sell (own auctions)
  13231. /// 1 = buy (own bids)
  13232. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13233. {
  13234. short type = RFIFOW(fd,2) + 6;
  13235. if( !battle_config.feature_auction )
  13236. return;
  13237. clif->pAuction_cancelreg(fd, sd);
  13238. intif->Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13239. }
  13240. /// CASH/POINT SHOP
  13241. ///
  13242. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13243. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13244. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13245. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd) {
  13246. struct npc_item_list *shop = NULL;
  13247. unsigned short shop_size = 0;
  13248. int fd,i, c = 0;
  13249. int currency[2] = { 0,0 };
  13250. #if PACKETVER < 20070711
  13251. const int offset = 8;
  13252. #else
  13253. const int offset = 12;
  13254. #endif
  13255. nullpo_retv(sd);
  13256. nullpo_retv(nd);
  13257. if( nd->subtype == SCRIPT ) {
  13258. shop = nd->u.scr.shop->item;
  13259. shop_size = nd->u.scr.shop->items;
  13260. npc->trader_count_funds(nd, sd);
  13261. currency[0] = npc->trader_funds[0];
  13262. currency[1] = npc->trader_funds[1];
  13263. } else {
  13264. shop = nd->u.shop.shop_item;
  13265. shop_size = nd->u.shop.count;
  13266. currency[0] = sd->cashPoints;
  13267. currency[1] = sd->kafraPoints;
  13268. }
  13269. fd = sd->fd;
  13270. sd->npc_shopid = nd->bl.id;
  13271. WFIFOHEAD(fd,offset+shop_size*11);
  13272. WFIFOW(fd,0) = 0x287;
  13273. /* 0x2 = length, set after parsing */
  13274. WFIFOL(fd,4) = currency[0]; // Cash Points
  13275. #if PACKETVER >= 20070711
  13276. WFIFOL(fd,8) = currency[1]; // Kafra Points
  13277. #endif
  13278. for( i = 0; i < shop_size; i++ ) {
  13279. if( shop[i].nameid ) {
  13280. struct item_data* id = itemdb->search(shop[i].nameid);
  13281. WFIFOL(fd,offset+0+i*11) = shop[i].value;
  13282. WFIFOL(fd,offset+4+i*11) = shop[i].value; // Discount Price
  13283. WFIFOB(fd,offset+8+i*11) = itemtype(id->type);
  13284. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13285. c++;
  13286. }
  13287. }
  13288. WFIFOW(fd,2) = offset+c*11;
  13289. WFIFOSET(fd,WFIFOW(fd,2));
  13290. }
  13291. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13292. /// 0289 <cash point>.L <error>.W
  13293. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13294. /// For error return codes see enum cashshop_error@clif.h
  13295. void clif_cashshop_ack(struct map_session_data* sd, int error) {
  13296. struct npc_data *nd;
  13297. int fd;
  13298. int currency[2] = { 0,0 };
  13299. nullpo_retv(sd);
  13300. fd = sd->fd;
  13301. if( (nd = map->id2nd(sd->npc_shopid)) && nd->subtype == SCRIPT ) {
  13302. npc->trader_count_funds(nd,sd);
  13303. currency[0] = npc->trader_funds[0];
  13304. currency[1] = npc->trader_funds[1];
  13305. } else {
  13306. currency[0] = sd->cashPoints;
  13307. currency[1] = sd->kafraPoints;
  13308. }
  13309. WFIFOHEAD(fd, packet_len(0x289));
  13310. WFIFOW(fd,0) = 0x289;
  13311. WFIFOL(fd,2) = currency[0];
  13312. #if PACKETVER < 20070711
  13313. WFIFOW(fd,6) = TOW(error);
  13314. #else
  13315. WFIFOL(fd,6) = currency[1];
  13316. WFIFOW(fd,10) = TOW(error);
  13317. #endif
  13318. WFIFOSET(fd, packet_len(0x289));
  13319. }
  13320. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  13321. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13322. /// 0288 <name id>.W <amount>.W
  13323. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13324. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13325. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  13326. {
  13327. int fail = 0;
  13328. if( sd->state.trading || !sd->npc_shopid || pc_has_permission(sd,PC_PERM_DISABLE_STORE) )
  13329. fail = 1;
  13330. else {
  13331. #if PACKETVER < 20101116
  13332. short nameid = RFIFOW(fd,2);
  13333. short amount = RFIFOW(fd,4);
  13334. int points = RFIFOL(fd,6);
  13335. fail = npc->cashshop_buy(sd, nameid, amount, points);
  13336. #else
  13337. int len = RFIFOW(fd,2);
  13338. int points = RFIFOL(fd,4);
  13339. int count = RFIFOW(fd,8);
  13340. unsigned short* item_list = (unsigned short*)RFIFOP(fd,10);
  13341. if( len < 10 || len != 10 + count * 4) {
  13342. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * 4);
  13343. return;
  13344. }
  13345. fail = npc->cashshop_buylist(sd,points,count,item_list);
  13346. #endif
  13347. }
  13348. clif->cashshop_ack(sd,fail);
  13349. }
  13350. /// Adoption System
  13351. ///
  13352. /// Adoption message (ZC_BABYMSG).
  13353. /// 0216 <msg>.L
  13354. /// msg:
  13355. /// 0 = "You cannot adopt more than 1 child."
  13356. /// 1 = "You must be at least character level 70 in order to adopt someone."
  13357. /// 2 = "You cannot adopt a married person."
  13358. void clif_Adopt_reply(struct map_session_data *sd, int type)
  13359. {
  13360. int fd;
  13361. nullpo_retv(sd);
  13362. fd = sd->fd;
  13363. WFIFOHEAD(fd,6);
  13364. WFIFOW(fd,0) = 0x216;
  13365. WFIFOL(fd,2) = type;
  13366. WFIFOSET(fd,6);
  13367. }
  13368. /// Adoption confirmation (ZC_REQ_BABY).
  13369. /// 01f6 <account id>.L <char id>.L <name>.B
  13370. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id) {
  13371. int fd;
  13372. nullpo_retv(sd);
  13373. nullpo_retv(src);
  13374. fd = sd->fd;
  13375. WFIFOHEAD(fd,34);
  13376. WFIFOW(fd,0) = 0x1f6;
  13377. WFIFOL(fd,2) = src->status.account_id;
  13378. WFIFOL(fd,6) = p_id;
  13379. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  13380. WFIFOSET(fd,34);
  13381. }
  13382. void clif_parse_Adopt_request(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  13383. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  13384. /// 01f9 <account id>.L
  13385. void clif_parse_Adopt_request(int fd, struct map_session_data *sd) {
  13386. struct map_session_data *tsd = map->id2sd(RFIFOL(fd,2)), *p_sd = map->charid2sd(sd->status.partner_id);
  13387. if( pc->can_Adopt(sd, p_sd, tsd) ) {
  13388. tsd->adopt_invite = sd->status.account_id;
  13389. clif->adopt_request(tsd, sd, p_sd->status.account_id);
  13390. }
  13391. }
  13392. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  13393. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  13394. /// 01f7 <account id>.L <char id>.L <answer>.L
  13395. /// answer:
  13396. /// 0 = rejected
  13397. /// 1 = accepted
  13398. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd) {
  13399. int p1_id = RFIFOL(fd,2);
  13400. int p2_id = RFIFOL(fd,6);
  13401. int result = RFIFOL(fd,10);
  13402. struct map_session_data* p1_sd = map->id2sd(p1_id);
  13403. struct map_session_data* p2_sd = map->id2sd(p2_id);
  13404. int pid = sd->adopt_invite;
  13405. sd->adopt_invite = 0;
  13406. if( p1_sd == NULL || p2_sd == NULL )
  13407. return; // Both players need to be online
  13408. if( pid != p1_sd->status.account_id )
  13409. return; // Incorrect values
  13410. if( result == 0 )
  13411. return; // Rejected
  13412. pc->adoption(p1_sd, p2_sd, sd);
  13413. }
  13414. /// Convex Mirror (ZC_BOSS_INFO).
  13415. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  13416. /// infoType:
  13417. /// 0 = No boss on this map (BOSS_INFO_NOT).
  13418. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  13419. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  13420. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  13421. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  13422. {
  13423. WFIFOHEAD(fd,70);
  13424. memset(WFIFOP(fd,0),0,70);
  13425. WFIFOW(fd,0) = 0x293;
  13426. if( md != NULL ) {
  13427. if( md->bl.prev != NULL ) { // Boss on This Map
  13428. if( flag ) {
  13429. WFIFOB(fd,2) = 1;
  13430. WFIFOL(fd,3) = md->bl.x;
  13431. WFIFOL(fd,7) = md->bl.y;
  13432. } else
  13433. WFIFOB(fd,2) = 2; // First Time
  13434. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  13435. const struct TimerData * timer_data = timer->get(md->spawn_timer);
  13436. unsigned int seconds;
  13437. int hours, minutes;
  13438. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, timer->gettick()) / 1000 + 60);
  13439. hours = seconds / (60 * 60);
  13440. seconds = seconds - (60 * 60 * hours);
  13441. minutes = seconds / 60;
  13442. WFIFOB(fd,2) = 3;
  13443. WFIFOW(fd,11) = hours; // Hours
  13444. WFIFOW(fd,13) = minutes; // Minutes
  13445. }
  13446. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  13447. }
  13448. WFIFOSET(fd,70);
  13449. }
  13450. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  13451. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  13452. /// 02d6 <account id>.L
  13453. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd) {
  13454. int charid = RFIFOL(fd, 2);
  13455. struct map_session_data* tsd = map->id2sd(charid);
  13456. if (!tsd)
  13457. return;
  13458. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  13459. clif->viewequip_ack(sd, tsd);
  13460. else
  13461. clif->msgtable(sd, MSG_EQUIP_NOT_PUBLIC);
  13462. }
  13463. void clif_parse_EquipTick(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  13464. /// Request to change equip window tick (CZ_CONFIG).
  13465. /// 02d8 <type>.L <value>.L
  13466. /// type:
  13467. /// 0 = open equip window
  13468. /// value:
  13469. /// 0 = disabled
  13470. /// 1 = enabled
  13471. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  13472. {
  13473. bool flag = (bool)RFIFOL(fd,6);
  13474. sd->status.show_equip = flag;
  13475. clif->equiptickack(sd, flag);
  13476. }
  13477. void clif_parse_PartyTick(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  13478. /// Request to change party invitation tick.
  13479. /// value:
  13480. /// 0 = disabled
  13481. /// 1 = enabled
  13482. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  13483. {
  13484. bool flag = RFIFOB(fd,6)?true:false;
  13485. sd->status.allow_party = flag;
  13486. clif->partytickack(sd, flag);
  13487. }
  13488. /// Questlog System [Kevin] [Inkfish]
  13489. ///
  13490. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  13491. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  13492. /// 097a <packet len>.W <num>.L { <quest id>.L <active>.B <remaining time>.L <time>.L <count>.W { <mob_id>.L <killed>.W <total>.W <mob name>.24B }*count }*num
  13493. void clif_quest_send_list(struct map_session_data *sd)
  13494. {
  13495. int i, len, real_len;
  13496. uint8 *buf = NULL;
  13497. struct packet_quest_list_header *packet = NULL;
  13498. nullpo_retv(sd);
  13499. len = sizeof(struct packet_quest_list_header)
  13500. + sd->avail_quests * (sizeof(struct packet_quest_list_info)
  13501. + MAX_QUEST_OBJECTIVES * sizeof(struct packet_mission_info_sub)); // >= than the actual length
  13502. buf = aMalloc(len);
  13503. packet = (struct packet_quest_list_header *)WBUFP(buf, 0);
  13504. real_len = sizeof(*packet);
  13505. packet->PacketType = questListType;
  13506. packet->questCount = sd->avail_quests;
  13507. for (i = 0; i < sd->avail_quests; i++) {
  13508. struct packet_quest_list_info *info = (struct packet_quest_list_info *)(buf+real_len);
  13509. #if PACKETVER >= 20141022
  13510. struct quest_db *qi = quest->db(sd->quest_log[i].quest_id);
  13511. int j;
  13512. #endif // PACKETVER >= 20141022
  13513. real_len += sizeof(*info);
  13514. info->questID = sd->quest_log[i].quest_id;
  13515. info->active = sd->quest_log[i].state;
  13516. #if PACKETVER >= 20141022
  13517. info->quest_svrTime = sd->quest_log[i].time - qi->time;
  13518. info->quest_endTime = sd->quest_log[i].time;
  13519. info->hunting_count = qi->objectives_count;
  13520. for (j = 0; j < qi->objectives_count; j++) {
  13521. struct mob_db *mob_data;
  13522. Assert_retb(j < MAX_QUEST_OBJECTIVES);
  13523. real_len += sizeof(info->objectives[j]);
  13524. mob_data = mob->db(qi->objectives[j].mob);
  13525. info->objectives[j].mob_id = qi->objectives[j].mob;
  13526. info->objectives[j].huntCount = sd->quest_log[i].count[j];
  13527. info->objectives[j].maxCount = qi->objectives[j].count;
  13528. safestrncpy(info->objectives[j].mobName, mob_data->jname, sizeof(info->objectives[j].mobName));
  13529. }
  13530. #endif // PACKETVER >= 20141022
  13531. }
  13532. packet->PacketLength = real_len;
  13533. clif->send(buf, real_len, &sd->bl, SELF);
  13534. aFree(buf);
  13535. }
  13536. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  13537. /// 02b2 <packet len>.W <num>.L { <quest id>.L <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3 }*num
  13538. void clif_quest_send_mission(struct map_session_data *sd)
  13539. {
  13540. int fd = sd->fd;
  13541. int i, j;
  13542. int len;
  13543. struct mob_db *monster;
  13544. nullpo_retv(sd);
  13545. len = sd->avail_quests*104+8;
  13546. WFIFOHEAD(fd, len);
  13547. WFIFOW(fd, 0) = 0x2b2;
  13548. WFIFOW(fd, 2) = len;
  13549. WFIFOL(fd, 4) = sd->avail_quests;
  13550. for (i = 0; i < sd->avail_quests; i++) {
  13551. struct quest_db *qi = quest->db(sd->quest_log[i].quest_id);
  13552. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  13553. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  13554. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  13555. WFIFOW(fd, i*104+20) = qi->objectives_count;
  13556. for (j = 0 ; j < qi->objectives_count; j++) {
  13557. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  13558. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  13559. monster = mob->db(qi->objectives[j].mob);
  13560. memcpy(WFIFOP(fd, i*104+28+j*30), monster->jname, NAME_LENGTH);
  13561. }
  13562. }
  13563. WFIFOSET(fd, len);
  13564. }
  13565. /// Notification about a new quest (ZC_ADD_QUEST).
  13566. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  13567. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  13568. {
  13569. int fd;
  13570. int i;
  13571. struct quest_db *qi;
  13572. nullpo_retv(sd);
  13573. nullpo_retv(qd);
  13574. fd = sd->fd;
  13575. qi = quest->db(qd->quest_id);
  13576. WFIFOHEAD(fd, packet_len(0x2b3));
  13577. WFIFOW(fd, 0) = 0x2b3;
  13578. WFIFOL(fd, 2) = qd->quest_id;
  13579. WFIFOB(fd, 6) = qd->state;
  13580. WFIFOB(fd, 7) = qd->time - qi->time;
  13581. WFIFOL(fd, 11) = qd->time;
  13582. WFIFOW(fd, 15) = qi->objectives_count;
  13583. for (i = 0; i < qi->objectives_count; i++) {
  13584. struct mob_db *monster;
  13585. WFIFOL(fd, i*30+17) = qi->objectives[i].mob;
  13586. WFIFOW(fd, i*30+21) = qd->count[i];
  13587. monster = mob->db(qi->objectives[i].mob);
  13588. memcpy(WFIFOP(fd, i*30+23), monster->jname, NAME_LENGTH);
  13589. }
  13590. WFIFOSET(fd, packet_len(0x2b3));
  13591. }
  13592. /// Notification about a quest being removed (ZC_DEL_QUEST).
  13593. /// 02b4 <quest id>.L
  13594. void clif_quest_delete(struct map_session_data *sd, int quest_id) {
  13595. int fd;
  13596. nullpo_retv(sd);
  13597. fd = sd->fd;
  13598. WFIFOHEAD(fd, packet_len(0x2b4));
  13599. WFIFOW(fd, 0) = 0x2b4;
  13600. WFIFOL(fd, 2) = quest_id;
  13601. WFIFOSET(fd, packet_len(0x2b4));
  13602. }
  13603. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  13604. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  13605. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd)
  13606. {
  13607. int fd;
  13608. int i;
  13609. struct quest_db *qi;
  13610. int len;
  13611. nullpo_retv(sd);
  13612. nullpo_retv(qd);
  13613. fd = sd->fd;
  13614. qi = quest->db(qd->quest_id);
  13615. len = qi->objectives_count * 12 + 6;
  13616. WFIFOHEAD(fd, len);
  13617. WFIFOW(fd, 0) = 0x2b5;
  13618. WFIFOW(fd, 2) = len;
  13619. WFIFOW(fd, 4) = qi->objectives_count;
  13620. for (i = 0; i < qi->objectives_count; i++) {
  13621. WFIFOL(fd, i*12+6) = qd->quest_id;
  13622. WFIFOL(fd, i*12+10) = qi->objectives[i].mob;
  13623. WFIFOW(fd, i*12+14) = qi->objectives[i].count;
  13624. WFIFOW(fd, i*12+16) = qd->count[i];
  13625. }
  13626. WFIFOSET(fd, len);
  13627. }
  13628. void clif_parse_questStateAck(int fd, struct map_session_data *sd) __attribute__((nonnull (2)));
  13629. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  13630. /// 02b6 <quest id>.L <active>.B
  13631. void clif_parse_questStateAck(int fd, struct map_session_data *sd) {
  13632. quest->update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
  13633. }
  13634. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  13635. /// 02b7 <quest id>.L <active>.B
  13636. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active) {
  13637. int fd;
  13638. nullpo_retv(sd);
  13639. fd = sd->fd;
  13640. WFIFOHEAD(fd, packet_len(0x2b7));
  13641. WFIFOW(fd, 0) = 0x2b7;
  13642. WFIFOL(fd, 2) = quest_id;
  13643. WFIFOB(fd, 6) = active;
  13644. WFIFOSET(fd, packet_len(0x2b7));
  13645. }
  13646. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  13647. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <type>.W
  13648. /// effect:
  13649. /// 0 = none
  13650. /// 1 = exclamation mark icon
  13651. /// 2 = question mark icon
  13652. /// type:
  13653. /// 0 = yellow
  13654. /// 1 = orange
  13655. /// 2 = green
  13656. /// 3 = purple
  13657. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  13658. {
  13659. #if PACKETVER >= 20090218
  13660. int fd;
  13661. nullpo_retv(sd);
  13662. nullpo_retv(bl);
  13663. fd = sd->fd;
  13664. WFIFOHEAD(fd, packet_len(0x446));
  13665. WFIFOW(fd, 0) = 0x446;
  13666. WFIFOL(fd, 2) = bl->id;
  13667. WFIFOW(fd, 6) = bl->x;
  13668. WFIFOW(fd, 8) = bl->y;
  13669. WFIFOW(fd, 10) = state;
  13670. WFIFOW(fd, 12) = color;
  13671. WFIFOSET(fd, packet_len(0x446));
  13672. #endif
  13673. }
  13674. /// Mercenary System
  13675. ///
  13676. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  13677. /// 02a2 <var id>.W <value>.L
  13678. void clif_mercenary_updatestatus(struct map_session_data *sd, int type) {
  13679. struct mercenary_data *md;
  13680. struct status_data *mstatus;
  13681. int fd;
  13682. if( sd == NULL || (md = sd->md) == NULL )
  13683. return;
  13684. fd = sd->fd;
  13685. mstatus = &md->battle_status;
  13686. WFIFOHEAD(fd,packet_len(0x2a2));
  13687. WFIFOW(fd,0) = 0x2a2;
  13688. WFIFOW(fd,2) = type;
  13689. switch( type ) {
  13690. case SP_ATK1:
  13691. {
  13692. int atk = rnd()%(mstatus->rhw.atk2 - mstatus->rhw.atk + 1) + mstatus->rhw.atk;
  13693. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  13694. }
  13695. break;
  13696. case SP_MATK1:
  13697. WFIFOL(fd,4) = cap_value(mstatus->matk_max, 0, INT16_MAX);
  13698. break;
  13699. case SP_HIT:
  13700. WFIFOL(fd,4) = mstatus->hit;
  13701. break;
  13702. case SP_CRITICAL:
  13703. WFIFOL(fd,4) = mstatus->cri/10;
  13704. break;
  13705. case SP_DEF1:
  13706. WFIFOL(fd,4) = mstatus->def;
  13707. break;
  13708. case SP_MDEF1:
  13709. WFIFOL(fd,4) = mstatus->mdef;
  13710. break;
  13711. case SP_MERCFLEE:
  13712. WFIFOL(fd,4) = mstatus->flee;
  13713. break;
  13714. case SP_ASPD:
  13715. WFIFOL(fd,4) = mstatus->amotion;
  13716. break;
  13717. case SP_HP:
  13718. WFIFOL(fd,4) = mstatus->hp;
  13719. break;
  13720. case SP_MAXHP:
  13721. WFIFOL(fd,4) = mstatus->max_hp;
  13722. break;
  13723. case SP_SP:
  13724. WFIFOL(fd,4) = mstatus->sp;
  13725. break;
  13726. case SP_MAXSP:
  13727. WFIFOL(fd,4) = mstatus->max_sp;
  13728. break;
  13729. case SP_MERCKILLS:
  13730. WFIFOL(fd,4) = md->mercenary.kill_count;
  13731. break;
  13732. case SP_MERCFAITH:
  13733. WFIFOL(fd,4) = mercenary->get_faith(md);
  13734. break;
  13735. }
  13736. WFIFOSET(fd,packet_len(0x2a2));
  13737. }
  13738. /// Mercenary base status data (ZC_MER_INIT).
  13739. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  13740. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  13741. /// <calls>.L <kills>.L <atk range>.W
  13742. void clif_mercenary_info(struct map_session_data *sd) {
  13743. int fd;
  13744. struct mercenary_data *md;
  13745. struct status_data *mstatus;
  13746. int atk;
  13747. if( sd == NULL || (md = sd->md) == NULL )
  13748. return;
  13749. fd = sd->fd;
  13750. mstatus = &md->battle_status;
  13751. WFIFOHEAD(fd,packet_len(0x29b));
  13752. WFIFOW(fd,0) = 0x29b;
  13753. WFIFOL(fd,2) = md->bl.id;
  13754. // Mercenary shows ATK as a random value between ATK ~ ATK2
  13755. #ifdef RENEWAL
  13756. atk = status->get_weapon_atk(&md->bl, &mstatus->rhw, 0);
  13757. #else
  13758. atk = rnd() % (mstatus->rhw.atk2 - mstatus->rhw.atk + 1) + mstatus->rhw.atk;
  13759. #endif
  13760. WFIFOW(fd, 6) = cap_value(atk, 0, INT16_MAX);
  13761. #ifdef RENEWAL
  13762. atk = status->base_matk(&md->bl, mstatus, status->get_lv(&md->bl));
  13763. WFIFOW(fd,8) = cap_value(atk, 0, INT16_MAX);
  13764. #else
  13765. WFIFOW(fd,8) = cap_value(mstatus->matk_max, 0, INT16_MAX);
  13766. #endif
  13767. WFIFOW(fd,10) = mstatus->hit;
  13768. WFIFOW(fd,12) = mstatus->cri/10;
  13769. #ifdef RENEWAL
  13770. WFIFOW(fd, 14) = mstatus->def2;
  13771. WFIFOW(fd, 16) = mstatus->mdef2;
  13772. #else
  13773. WFIFOW(fd,14) = mstatus->def;
  13774. WFIFOW(fd,16) = mstatus->mdef;
  13775. #endif
  13776. WFIFOW(fd,18) = mstatus->flee;
  13777. WFIFOW(fd,20) = mstatus->amotion;
  13778. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  13779. WFIFOW(fd,46) = md->db->lv;
  13780. WFIFOL(fd,48) = mstatus->hp;
  13781. WFIFOL(fd,52) = mstatus->max_hp;
  13782. WFIFOL(fd,56) = mstatus->sp;
  13783. WFIFOL(fd,60) = mstatus->max_sp;
  13784. WFIFOL(fd,64) = (int)time(NULL) + (mercenary->get_lifetime(md) / 1000);
  13785. WFIFOW(fd,68) = mercenary->get_faith(md);
  13786. WFIFOL(fd,70) = mercenary->get_calls(md);
  13787. WFIFOL(fd,74) = md->mercenary.kill_count;
  13788. WFIFOW(fd,78) = md->battle_status.rhw.range;
  13789. WFIFOSET(fd,packet_len(0x29b));
  13790. }
  13791. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  13792. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradeable>.B }*
  13793. void clif_mercenary_skillblock(struct map_session_data *sd)
  13794. {
  13795. struct mercenary_data *md;
  13796. int fd, i, len = 4, j;
  13797. if( sd == NULL || (md = sd->md) == NULL )
  13798. return;
  13799. fd = sd->fd;
  13800. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  13801. WFIFOW(fd,0) = 0x29d;
  13802. for (i = 0; i < MAX_MERCSKILL; i++) {
  13803. int id = md->db->skill[i].id;
  13804. if (id == 0)
  13805. continue;
  13806. j = id - MC_SKILLBASE;
  13807. WFIFOW(fd,len) = id;
  13808. WFIFOL(fd,len+2) = skill->get_inf(id);
  13809. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  13810. if ( md->db->skill[j].lv ) {
  13811. WFIFOW(fd, len + 8) = skill->get_sp(id, md->db->skill[j].lv);
  13812. WFIFOW(fd, len + 10) = skill->get_range2(&md->bl, id, md->db->skill[j].lv);
  13813. } else {
  13814. WFIFOW(fd, len + 8) = 0;
  13815. WFIFOW(fd, len + 10) = 0;
  13816. }
  13817. safestrncpy((char*)WFIFOP(fd,len+12), skill->get_name(id), NAME_LENGTH);
  13818. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  13819. len += 37;
  13820. }
  13821. WFIFOW(fd,2) = len;
  13822. WFIFOSET(fd,len);
  13823. }
  13824. void clif_parse_mercenary_action(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  13825. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  13826. /// 029f <command>.B
  13827. /// 1 = mercenary information
  13828. /// 2 = delete
  13829. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  13830. {
  13831. int option = RFIFOB(fd,2);
  13832. if (sd->md == NULL)
  13833. return;
  13834. if (option == 2)
  13835. mercenary->delete(sd->md, 2);
  13836. }
  13837. /// Mercenary Message
  13838. /// message:
  13839. /// 0 = Mercenary soldier's duty hour is over.
  13840. /// 1 = Your mercenary soldier has been killed.
  13841. /// 2 = Your mercenary soldier has been fired.
  13842. /// 3 = Your mercenary soldier has ran away.
  13843. void clif_mercenary_message(struct map_session_data* sd, int message)
  13844. {
  13845. clif->msgtable(sd, MSG_MERCENARY_EXPIRED + message);
  13846. }
  13847. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  13848. /// 0298 <name id>.W <seconds>.L
  13849. void clif_rental_time(int fd, int nameid, int seconds)
  13850. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  13851. WFIFOHEAD(fd,packet_len(0x298));
  13852. WFIFOW(fd,0) = 0x298;
  13853. WFIFOW(fd,2) = nameid;
  13854. WFIFOL(fd,4) = seconds;
  13855. WFIFOSET(fd,packet_len(0x298));
  13856. }
  13857. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  13858. /// 0299 <index>.W <name id>.W
  13859. void clif_rental_expired(int fd, int index, int nameid)
  13860. { // '<ItemName>' item has been deleted from the Inventory
  13861. WFIFOHEAD(fd,packet_len(0x299));
  13862. WFIFOW(fd,0) = 0x299;
  13863. WFIFOW(fd,2) = index+2;
  13864. WFIFOW(fd,4) = nameid;
  13865. WFIFOSET(fd,packet_len(0x299));
  13866. }
  13867. /// Book Reading (ZC_READ_BOOK).
  13868. /// 0294 <book id>.L <page>.L
  13869. void clif_readbook(int fd, int book_id, int page)
  13870. {
  13871. WFIFOHEAD(fd,packet_len(0x294));
  13872. WFIFOW(fd,0) = 0x294;
  13873. WFIFOL(fd,2) = book_id;
  13874. WFIFOL(fd,6) = page;
  13875. WFIFOSET(fd,packet_len(0x294));
  13876. }
  13877. /// Battlegrounds
  13878. ///
  13879. /// Updates HP bar of a camp member (ZC_BATTLEFIELD_NOTIFY_HP).
  13880. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W
  13881. void clif_bg_hp(struct map_session_data *sd)
  13882. {
  13883. unsigned char buf[34];
  13884. const int cmd = 0x2e0;
  13885. nullpo_retv(sd);
  13886. WBUFW(buf,0) = cmd;
  13887. WBUFL(buf,2) = sd->status.account_id;
  13888. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13889. if( sd->battle_status.max_hp > INT16_MAX )
  13890. { // To correctly display the %hp bar. [Skotlex]
  13891. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  13892. WBUFW(buf,32) = 100;
  13893. }
  13894. else
  13895. {
  13896. WBUFW(buf,30) = sd->battle_status.hp;
  13897. WBUFW(buf,32) = sd->battle_status.max_hp;
  13898. }
  13899. clif->send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  13900. }
  13901. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  13902. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  13903. void clif_bg_xy(struct map_session_data *sd)
  13904. {
  13905. unsigned char buf[36];
  13906. nullpo_retv(sd);
  13907. WBUFW(buf,0)=0x2df;
  13908. WBUFL(buf,2)=sd->status.account_id;
  13909. memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH);
  13910. WBUFW(buf,30)=sd->status.class_;
  13911. WBUFW(buf,32)=sd->bl.x;
  13912. WBUFW(buf,34)=sd->bl.y;
  13913. clif->send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13914. }
  13915. void clif_bg_xy_remove(struct map_session_data *sd)
  13916. {
  13917. unsigned char buf[36];
  13918. nullpo_retv(sd);
  13919. WBUFW(buf,0)=0x2df;
  13920. WBUFL(buf,2)=sd->status.account_id;
  13921. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  13922. WBUFW(buf,30)=0;
  13923. WBUFW(buf,32)=-1;
  13924. WBUFW(buf,34)=-1;
  13925. clif->send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  13926. }
  13927. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  13928. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  13929. void clif_bg_message(struct battleground_data *bgd, int src_id, const char *name, const char *mes, size_t len)
  13930. {
  13931. struct map_session_data *sd;
  13932. unsigned char *buf;
  13933. nullpo_retv(bgd);
  13934. nullpo_retv(name);
  13935. nullpo_retv(mes);
  13936. if( !bgd->count || (sd = bg->getavailablesd(bgd)) == NULL )
  13937. return;
  13938. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  13939. WBUFW(buf,0) = 0x2dc;
  13940. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  13941. WBUFL(buf,4) = src_id;
  13942. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  13943. memcpy(WBUFP(buf,32), mes, len);
  13944. clif->send(buf,WBUFW(buf,2), &sd->bl, BG);
  13945. aFree(buf);
  13946. }
  13947. void clif_parse_BattleChat(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  13948. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  13949. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  13950. void clif_parse_BattleChat(int fd, struct map_session_data* sd)
  13951. {
  13952. const char* text = (char*)RFIFOP(fd,4);
  13953. int textlen = RFIFOW(fd,2) - 4;
  13954. char *name, *message;
  13955. size_t namelen, messagelen;
  13956. if( !clif->process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  13957. return;
  13958. if( atcommand->exec(fd, sd, message, true) )
  13959. return;
  13960. if( !pc->can_talk(sd) )
  13961. return;
  13962. if( battle_config.min_chat_delay ) {
  13963. if( DIFF_TICK(sd->cantalk_tick, timer->gettick()) > 0 )
  13964. return;
  13965. sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
  13966. }
  13967. pc->update_idle_time(sd, BCIDLE_CHAT);
  13968. bg->send_message(sd, text, textlen);
  13969. }
  13970. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  13971. /// 02de <camp A points>.W <camp B points>.W
  13972. void clif_bg_updatescore(int16 m) {
  13973. struct block_list bl;
  13974. unsigned char buf[6];
  13975. bl.id = 0;
  13976. bl.type = BL_NUL;
  13977. bl.m = m;
  13978. WBUFW(buf,0) = 0x2de;
  13979. WBUFW(buf,2) = map->list[m].bgscore_lion;
  13980. WBUFW(buf,4) = map->list[m].bgscore_eagle;
  13981. clif->send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  13982. }
  13983. void clif_bg_updatescore_single(struct map_session_data *sd) {
  13984. int fd;
  13985. nullpo_retv(sd);
  13986. fd = sd->fd;
  13987. WFIFOHEAD(fd,packet_len(0x2de));
  13988. WFIFOW(fd,0) = 0x2de;
  13989. WFIFOW(fd,2) = map->list[sd->bl.m].bgscore_lion;
  13990. WFIFOW(fd,4) = map->list[sd->bl.m].bgscore_eagle;
  13991. WFIFOSET(fd,packet_len(0x2de));
  13992. }
  13993. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  13994. /// 02dd <account id>.L <name>.24B <camp>.W
  13995. void clif_sendbgemblem_area(struct map_session_data *sd)
  13996. {
  13997. unsigned char buf[33];
  13998. nullpo_retv(sd);
  13999. WBUFW(buf, 0) = 0x2dd;
  14000. WBUFL(buf,2) = sd->bl.id;
  14001. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14002. WBUFW(buf,30) = sd->bg_id;
  14003. clif->send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14004. }
  14005. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14006. {
  14007. nullpo_retv(sd);
  14008. WFIFOHEAD(fd,32);
  14009. WFIFOW(fd,0) = 0x2dd;
  14010. WFIFOL(fd,2) = sd->bl.id;
  14011. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  14012. WFIFOW(fd,30) = sd->bg_id;
  14013. WFIFOSET(fd,packet_len(0x2dd));
  14014. }
  14015. /// Custom Fonts (ZC_NOTIFY_FONT).
  14016. /// 02ef <account_id>.L <font id>.W
  14017. void clif_font(struct map_session_data *sd)
  14018. {
  14019. #if PACKETVER >= 20080102
  14020. unsigned char buf[8];
  14021. nullpo_retv(sd);
  14022. WBUFW(buf,0) = 0x2ef;
  14023. WBUFL(buf,2) = sd->bl.id;
  14024. WBUFW(buf,6) = sd->status.font;
  14025. clif->send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14026. #endif
  14027. }
  14028. /*==========================================
  14029. * Instancing Window
  14030. *------------------------------------------*/
  14031. int clif_instance(int instance_id, int type, int flag) {
  14032. struct map_session_data *sd = NULL;
  14033. unsigned char buf[255];
  14034. enum send_target target = PARTY;
  14035. switch( instance->list[instance_id].owner_type ) {
  14036. case IOT_NONE:
  14037. return 0;
  14038. case IOT_GUILD:
  14039. target = GUILD;
  14040. sd = guild->getavailablesd(guild->search(instance->list[instance_id].owner_id));
  14041. break;
  14042. case IOT_PARTY:
  14043. /* default is already PARTY */
  14044. sd = party->getavailablesd(party->search(instance->list[instance_id].owner_id));
  14045. break;
  14046. case IOT_CHAR:
  14047. target = SELF;
  14048. sd = map->id2sd(instance->list[instance_id].owner_id);
  14049. break;
  14050. }
  14051. if( !sd )
  14052. return 0;
  14053. switch( type ) {
  14054. case 1:
  14055. // S 0x2cb <Instance name>.61B <Standby Position>.W
  14056. // Required to start the instancing information window on Client
  14057. // This window re-appear each "refresh" of client automatically until type 4 is send to client.
  14058. WBUFW(buf,0) = 0x02CB;
  14059. memcpy(WBUFP(buf,2),instance->list[instance_id].name,INSTANCE_NAME_LENGTH);
  14060. WBUFW(buf,63) = flag;
  14061. clif->send(buf,packet_len(0x02CB),&sd->bl,target);
  14062. break;
  14063. case 2:
  14064. // S 0x2cc <Standby Position>.W
  14065. // To announce Instancing queue creation if no maps available
  14066. WBUFW(buf,0) = 0x02CC;
  14067. WBUFW(buf,2) = flag;
  14068. clif->send(buf,packet_len(0x02CC),&sd->bl,target);
  14069. break;
  14070. case 3:
  14071. case 4:
  14072. // S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  14073. WBUFW(buf,0) = 0x02CD;
  14074. memcpy(WBUFP(buf,2),instance->list[instance_id].name,61);
  14075. if( type == 3 ) {
  14076. WBUFL(buf,63) = instance->list[instance_id].progress_timeout;
  14077. WBUFL(buf,67) = 0;
  14078. } else {
  14079. WBUFL(buf,63) = 0;
  14080. WBUFL(buf,67) = instance->list[instance_id].idle_timeout;
  14081. }
  14082. clif->send(buf,packet_len(0x02CD),&sd->bl,target);
  14083. break;
  14084. case 5:
  14085. // S 0x2ce <Message ID>.L
  14086. // 0 = Notification (EnterLimitDate update?)
  14087. // 1 = The Memorial Dungeon expired; it has been destroyed
  14088. // 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  14089. // 3 = The Memorial Dungeon has been removed.
  14090. // 4 = Create failure (removes the instance window)
  14091. WBUFW(buf,0) = 0x02CE;
  14092. WBUFL(buf,2) = flag;
  14093. //WBUFL(buf,6) = EnterLimitDate;
  14094. clif->send(buf,packet_len(0x02CE),&sd->bl,target);
  14095. break;
  14096. }
  14097. return 0;
  14098. }
  14099. void clif_instance_join(int fd, int instance_id)
  14100. {
  14101. if( instance->list[instance_id].idle_timer != INVALID_TIMER ) {
  14102. WFIFOHEAD(fd,packet_len(0x02CD));
  14103. WFIFOW(fd,0) = 0x02CD;
  14104. memcpy(WFIFOP(fd,2),instance->list[instance_id].name,61);
  14105. WFIFOL(fd,63) = 0;
  14106. WFIFOL(fd,67) = instance->list[instance_id].idle_timeout;
  14107. WFIFOSET(fd,packet_len(0x02CD));
  14108. } else if( instance->list[instance_id].progress_timer != INVALID_TIMER ) {
  14109. WFIFOHEAD(fd,packet_len(0x02CD));
  14110. WFIFOW(fd,0) = 0x02CD;
  14111. memcpy(WFIFOP(fd,2),instance->list[instance_id].name,61);
  14112. WFIFOL(fd,63) = instance->list[instance_id].progress_timeout;
  14113. WFIFOL(fd,67) = 0;
  14114. WFIFOSET(fd,packet_len(0x02CD));
  14115. } else {
  14116. WFIFOHEAD(fd,packet_len(0x02CB));
  14117. WFIFOW(fd,0) = 0x02CB;
  14118. memcpy(WFIFOP(fd,2),instance->list[instance_id].name,61);
  14119. WFIFOW(fd,63) = 0;
  14120. WFIFOSET(fd,packet_len(0x02CB));
  14121. }
  14122. }
  14123. void clif_instance_leave(int fd)
  14124. {
  14125. WFIFOHEAD(fd,packet_len(0x02CE));
  14126. WFIFOW(fd,0) = 0x02ce;
  14127. WFIFOL(fd,2) = 4;
  14128. WFIFOSET(fd,packet_len(0x02CE));
  14129. }
  14130. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  14131. /// 02b8 <account id>.L <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B
  14132. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  14133. {
  14134. #if PACKETVER >= 20071002
  14135. unsigned char buf[22];
  14136. struct item_data* id;
  14137. nullpo_retv(sd);
  14138. nullpo_retv(item_data);
  14139. id = itemdb->search(item_data->nameid);
  14140. WBUFW(buf,0) = 0x2b8;
  14141. WBUFL(buf,2) = sd->status.account_id;
  14142. WBUFW(buf,6) = item_data->nameid;
  14143. WBUFB(buf,8) = item_data->identify;
  14144. WBUFB(buf,9) = item_data->attribute;
  14145. WBUFB(buf,10) = item_data->refine;
  14146. clif->addcards(WBUFP(buf,11), item_data);
  14147. WBUFW(buf,19) = id->equip; // equip location
  14148. WBUFB(buf,21) = itemtype(id->type); // item type
  14149. clif->send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14150. #endif
  14151. }
  14152. /// Display gained exp (ZC_NOTIFY_EXP).
  14153. /// 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  14154. /// var id:
  14155. /// SP_BASEEXP, SP_JOBEXP
  14156. /// exp type:
  14157. /// 0 = normal exp gain/loss
  14158. /// 1 = quest exp gain/loss
  14159. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool is_quest) {
  14160. int fd;
  14161. nullpo_retv(sd);
  14162. fd = sd->fd;
  14163. WFIFOHEAD(fd, packet_len(0x7f6));
  14164. WFIFOW(fd,0) = 0x7f6;
  14165. WFIFOL(fd,2) = sd->bl.id;
  14166. WFIFOL(fd,6) = exp;
  14167. WFIFOW(fd,10) = type;
  14168. WFIFOW(fd,12) = is_quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  14169. WFIFOSET(fd,packet_len(0x7f6));
  14170. }
  14171. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  14172. /// type:
  14173. /// 0 = Displays 'value' for 5 seconds.
  14174. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  14175. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  14176. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  14177. /// value:
  14178. /// Except for type 3 it is interpreted as seconds for displaying as DD:HH:MM:SS, HH:MM:SS, MM:SS or SS (leftmost '00' is not displayed).
  14179. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  14180. {
  14181. nullpo_retv(sd);
  14182. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  14183. WFIFOW(sd->fd,0) = 0x1b1;
  14184. WFIFOB(sd->fd,2) = type;
  14185. WFIFOL(sd->fd,3) = value;
  14186. WFIFOSET(sd->fd, packet_len(0x1b1));
  14187. }
  14188. void clif_parse_LessEffect(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  14189. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  14190. /// 021d <state>.L
  14191. /// state:
  14192. /// 0 = Full effects
  14193. /// 1 = Reduced effects
  14194. ///
  14195. /// NOTE: The state is used on Aegis for sending skill unit packet
  14196. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  14197. /// whenever possible. Due to the way the decision check is
  14198. /// constructed, this state tracking was rendered useless,
  14199. /// as the only skill unit, that is sent with 0x1c9 is
  14200. /// Graffiti.
  14201. void clif_parse_LessEffect(int fd, struct map_session_data* sd)
  14202. {
  14203. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14204. sd->state.lesseffect = ( isLess != 0 );
  14205. }
  14206. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  14207. /// S 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b*
  14208. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  14209. int n = (RFIFOW(fd,2)-12) / 4;
  14210. int type = RFIFOL(fd,4);
  14211. int flag = RFIFOL(fd,8); // Button clicked: 0 = Cancel, 1 = OK
  14212. unsigned short* item_list = (unsigned short*)RFIFOP(fd,12);
  14213. if( sd->state.trading || sd->npc_shopid )
  14214. return;
  14215. if( flag == 0 || n == 0) {
  14216. clif_menuskill_clear(sd);
  14217. return; // Canceled by player.
  14218. }
  14219. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  14220. clif_menuskill_clear(sd);
  14221. return; // Prevent hacking.
  14222. }
  14223. switch( type ) {
  14224. case 0: // Change Material
  14225. skill->changematerial(sd,n,item_list);
  14226. break;
  14227. case 1: // Level 1: Pure to Rough
  14228. case 2: // Level 2: Rough to Pure
  14229. skill->elementalanalysis(sd,n,type,item_list);
  14230. break;
  14231. }
  14232. clif_menuskill_clear(sd);
  14233. return;
  14234. }
  14235. /*==========================================
  14236. * Elemental System
  14237. *==========================================*/
  14238. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  14239. struct elemental_data *ed;
  14240. struct status_data *estatus;
  14241. int fd;
  14242. if( sd == NULL || (ed = sd->ed) == NULL )
  14243. return;
  14244. fd = sd->fd;
  14245. estatus = &ed->battle_status;
  14246. WFIFOHEAD(fd,8);
  14247. WFIFOW(fd,0) = 0x81e;
  14248. WFIFOW(fd,2) = type;
  14249. switch( type ) {
  14250. case SP_HP:
  14251. WFIFOL(fd,4) = estatus->hp;
  14252. break;
  14253. case SP_MAXHP:
  14254. WFIFOL(fd,4) = estatus->max_hp;
  14255. break;
  14256. case SP_SP:
  14257. WFIFOL(fd,4) = estatus->sp;
  14258. break;
  14259. case SP_MAXSP:
  14260. WFIFOL(fd,4) = estatus->max_sp;
  14261. break;
  14262. }
  14263. WFIFOSET(fd,8);
  14264. }
  14265. void clif_elemental_info(struct map_session_data *sd) {
  14266. int fd;
  14267. struct elemental_data *ed;
  14268. struct status_data *estatus;
  14269. if( sd == NULL || (ed = sd->ed) == NULL )
  14270. return;
  14271. fd = sd->fd;
  14272. estatus = &ed->battle_status;
  14273. WFIFOHEAD(fd,22);
  14274. WFIFOW(fd, 0) = 0x81d;
  14275. WFIFOL(fd, 2) = ed->bl.id;
  14276. WFIFOL(fd, 6) = estatus->hp;
  14277. WFIFOL(fd,10) = estatus->max_hp;
  14278. WFIFOL(fd,14) = estatus->sp;
  14279. WFIFOL(fd,18) = estatus->max_sp;
  14280. WFIFOSET(fd,22);
  14281. }
  14282. /// Buying Store System
  14283. ///
  14284. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  14285. /// 0810 <slots>.B
  14286. void clif_buyingstore_open(struct map_session_data* sd)
  14287. {
  14288. int fd;
  14289. nullpo_retv(sd);
  14290. fd = sd->fd;
  14291. WFIFOHEAD(fd,packet_len(0x810));
  14292. WFIFOW(fd,0) = 0x810;
  14293. WFIFOB(fd,2) = sd->buyingstore.slots;
  14294. WFIFOSET(fd,packet_len(0x810));
  14295. }
  14296. void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  14297. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  14298. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  14299. /// result:
  14300. /// 0 = cancel
  14301. /// 1 = open
  14302. void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd) {
  14303. const unsigned int blocksize = 8;
  14304. uint8* itemlist;
  14305. char storename[MESSAGE_SIZE];
  14306. unsigned char result;
  14307. int zenylimit;
  14308. unsigned int count, packet_len;
  14309. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14310. packet_len = RFIFOW(fd,info->pos[0]);
  14311. // TODO: Make this check global for all variable length packets.
  14312. if( packet_len < 89 )
  14313. {// minimum packet length
  14314. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  14315. return;
  14316. }
  14317. zenylimit = RFIFOL(fd,info->pos[1]);
  14318. result = RFIFOL(fd,info->pos[2]);
  14319. safestrncpy(storename, (const char*)RFIFOP(fd,info->pos[3]), sizeof(storename));
  14320. itemlist = RFIFOP(fd,info->pos[4]);
  14321. // so that buyingstore_create knows, how many elements it has access to
  14322. packet_len-= info->pos[4];
  14323. if( packet_len%blocksize )
  14324. {
  14325. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14326. return;
  14327. }
  14328. count = packet_len/blocksize;
  14329. buyingstore->create(sd, zenylimit, result, storename, itemlist, count);
  14330. }
  14331. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  14332. /// 0812 <result>.W <total weight>.L
  14333. /// result:
  14334. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  14335. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  14336. /// 8 = "No sale (purchase) information available." (0x705)
  14337. /// ? = nothing
  14338. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  14339. {
  14340. int fd;
  14341. nullpo_retv(sd);
  14342. fd = sd->fd;
  14343. WFIFOHEAD(fd,packet_len(0x812));
  14344. WFIFOW(fd,0) = 0x812;
  14345. WFIFOW(fd,2) = result;
  14346. WFIFOL(fd,4) = weight;
  14347. WFIFOSET(fd,packet_len(0x812));
  14348. }
  14349. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  14350. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  14351. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  14352. {
  14353. int fd;
  14354. unsigned int i;
  14355. nullpo_retv(sd);
  14356. fd = sd->fd;
  14357. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  14358. WFIFOW(fd,0) = 0x813;
  14359. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  14360. WFIFOL(fd,4) = sd->bl.id;
  14361. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  14362. for( i = 0; i < sd->buyingstore.slots; i++ )
  14363. {
  14364. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  14365. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  14366. WFIFOB(fd,18+i*9) = itemtype(itemdb_type(sd->buyingstore.items[i].nameid));
  14367. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  14368. }
  14369. WFIFOSET(fd,WFIFOW(fd,2));
  14370. }
  14371. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  14372. /// 0814 <account id>.L <store name>.80B
  14373. void clif_buyingstore_entry(struct map_session_data* sd)
  14374. {
  14375. uint8 buf[86];
  14376. nullpo_retv(sd);
  14377. WBUFW(buf,0) = 0x814;
  14378. WBUFL(buf,2) = sd->bl.id;
  14379. memcpy(WBUFP(buf,6), sd->message, MESSAGE_SIZE);
  14380. clif->send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  14381. }
  14382. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14383. {
  14384. int fd;
  14385. nullpo_retv(sd);
  14386. fd = sd->fd;
  14387. WFIFOHEAD(fd,packet_len(0x814));
  14388. WFIFOW(fd,0) = 0x814;
  14389. WFIFOL(fd,2) = pl_sd->bl.id;
  14390. memcpy(WFIFOP(fd,6), pl_sd->message, MESSAGE_SIZE);
  14391. WFIFOSET(fd,packet_len(0x814));
  14392. }
  14393. void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  14394. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  14395. /// 0815
  14396. void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd) {
  14397. buyingstore->close(sd);
  14398. }
  14399. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  14400. /// 0816 <account id>.L
  14401. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  14402. {
  14403. uint8 buf[6];
  14404. nullpo_retv(sd);
  14405. WBUFW(buf,0) = 0x816;
  14406. WBUFL(buf,2) = sd->bl.id;
  14407. clif->send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  14408. }
  14409. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14410. {
  14411. int fd;
  14412. nullpo_retv(sd);
  14413. nullpo_retv(pl_sd);
  14414. fd = sd->fd;
  14415. WFIFOHEAD(fd,packet_len(0x816));
  14416. WFIFOW(fd,0) = 0x816;
  14417. WFIFOL(fd,2) = pl_sd->bl.id;
  14418. WFIFOSET(fd,packet_len(0x816));
  14419. }
  14420. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  14421. /// 0817 <account id>.L
  14422. void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  14423. {
  14424. int account_id;
  14425. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14426. buyingstore->open(sd, account_id);
  14427. }
  14428. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  14429. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  14430. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  14431. {
  14432. int fd;
  14433. unsigned int i;
  14434. nullpo_retv(sd);
  14435. nullpo_retv(pl_sd);
  14436. fd = sd->fd;
  14437. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  14438. WFIFOW(fd,0) = 0x818;
  14439. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  14440. WFIFOL(fd,4) = pl_sd->bl.id;
  14441. WFIFOL(fd,8) = pl_sd->buyer_id;
  14442. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  14443. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  14444. {
  14445. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  14446. WFIFOW(fd,20+i*9) = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  14447. WFIFOB(fd,22+i*9) = itemtype(itemdb_type(pl_sd->buyingstore.items[i].nameid));
  14448. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  14449. }
  14450. WFIFOSET(fd,WFIFOW(fd,2));
  14451. }
  14452. void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd) __attribute__((nonnull (2)));
  14453. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  14454. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  14455. void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd) {
  14456. const unsigned int blocksize = 6;
  14457. uint8* itemlist;
  14458. int account_id;
  14459. unsigned int count, packet_len, buyer_id;
  14460. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14461. packet_len = RFIFOW(fd,info->pos[0]);
  14462. if( packet_len < 12 )
  14463. {// minimum packet length
  14464. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  14465. return;
  14466. }
  14467. account_id = RFIFOL(fd,info->pos[1]);
  14468. buyer_id = RFIFOL(fd,info->pos[2]);
  14469. itemlist = RFIFOP(fd,info->pos[3]);
  14470. // so that buyingstore_trade knows, how many elements it has access to
  14471. packet_len-= info->pos[3];
  14472. if( packet_len%blocksize )
  14473. {
  14474. ShowError("clif_parse_ReqTradeBuyingStore: Unexpected item list size %u (account_id=%d, buyer_id=%u, block size=%u)\n", packet_len, sd->bl.id, account_id, blocksize);
  14475. return;
  14476. }
  14477. count = packet_len/blocksize;
  14478. buyingstore->trade(sd, account_id, buyer_id, itemlist, count);
  14479. }
  14480. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  14481. /// 081a <result>.W
  14482. /// result:
  14483. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  14484. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  14485. /// ? = nothing
  14486. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  14487. {
  14488. int fd;
  14489. nullpo_retv(sd);
  14490. fd = sd->fd;
  14491. WFIFOHEAD(fd,packet_len(0x81a));
  14492. WFIFOW(fd,0) = 0x81a;
  14493. WFIFOW(fd,2) = result;
  14494. WFIFOSET(fd,packet_len(0x81a));
  14495. }
  14496. /// Updates the zeny limit and an item in the buying store item list (ZC_UPDATE_ITEM_FROM_BUYING_STORE).
  14497. /// 081b <name id>.W <amount>.W <limit zeny>.L
  14498. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount)
  14499. {
  14500. int fd;
  14501. nullpo_retv(sd);
  14502. fd = sd->fd;
  14503. WFIFOHEAD(fd,packet_len(0x81b));
  14504. WFIFOW(fd,0) = 0x81b;
  14505. WFIFOW(fd,2) = nameid;
  14506. WFIFOW(fd,4) = amount; // amount of nameid received
  14507. WFIFOL(fd,6) = sd->buyingstore.zenylimit;
  14508. WFIFOSET(fd,packet_len(0x81b));
  14509. }
  14510. /// Deletes item fro