PageRenderTime 66ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 1ms

/src/map/intif.c

https://gitlab.com/evol/hercules
C | 2545 lines | 1951 code | 338 blank | 256 comment | 301 complexity | 7f38d21e6493c58c442ba3d115bf2f88 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  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" // GP_BOUND_ITEMS
  23. #include "intif.h"
  24. #include "map/atcommand.h"
  25. #include "map/battle.h"
  26. #include "map/chrif.h"
  27. #include "map/clif.h"
  28. #include "map/elemental.h"
  29. #include "map/guild.h"
  30. #include "map/homunculus.h"
  31. #include "map/log.h"
  32. #include "map/mail.h"
  33. #include "map/map.h"
  34. #include "map/mercenary.h"
  35. #include "map/party.h"
  36. #include "map/pc.h"
  37. #include "map/pet.h"
  38. #include "map/quest.h"
  39. #include "map/storage.h"
  40. #include "common/memmgr.h"
  41. #include "common/nullpo.h"
  42. #include "common/showmsg.h"
  43. #include "common/socket.h"
  44. #include "common/strlib.h"
  45. #include "common/timer.h"
  46. #include <fcntl.h>
  47. #include <signal.h>
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #include <sys/types.h>
  52. struct intif_interface intif_s;
  53. struct intif_interface *intif;
  54. #define inter_fd (chrif->fd) // alias
  55. //-----------------------------------------------------------------
  56. // Send to inter server
  57. int CheckForCharServer(void)
  58. {
  59. return ((chrif->fd <= 0) || sockt->session[chrif->fd] == NULL || sockt->session[chrif->fd]->wdata == NULL);
  60. }
  61. // pet
  62. int intif_create_pet(int account_id,int char_id,short pet_class,short pet_lv,short pet_egg_id,
  63. short pet_equip,short intimate,short hungry,char rename_flag,char incubate,char *pet_name)
  64. {
  65. if (intif->CheckForCharServer())
  66. return 0;
  67. nullpo_ret(pet_name);
  68. WFIFOHEAD(inter_fd, 24 + NAME_LENGTH);
  69. WFIFOW(inter_fd,0) = 0x3080;
  70. WFIFOL(inter_fd,2) = account_id;
  71. WFIFOL(inter_fd,6) = char_id;
  72. WFIFOW(inter_fd,10) = pet_class;
  73. WFIFOW(inter_fd,12) = pet_lv;
  74. WFIFOW(inter_fd,14) = pet_egg_id;
  75. WFIFOW(inter_fd,16) = pet_equip;
  76. WFIFOW(inter_fd,18) = intimate;
  77. WFIFOW(inter_fd,20) = hungry;
  78. WFIFOB(inter_fd,22) = rename_flag;
  79. WFIFOB(inter_fd,23) = incubate;
  80. memcpy(WFIFOP(inter_fd,24),pet_name,NAME_LENGTH);
  81. WFIFOSET(inter_fd,24+NAME_LENGTH);
  82. return 0;
  83. }
  84. int intif_request_petdata(int account_id,int char_id,int pet_id)
  85. {
  86. if (intif->CheckForCharServer())
  87. return 0;
  88. WFIFOHEAD(inter_fd, 14);
  89. WFIFOW(inter_fd,0) = 0x3081;
  90. WFIFOL(inter_fd,2) = account_id;
  91. WFIFOL(inter_fd,6) = char_id;
  92. WFIFOL(inter_fd,10) = pet_id;
  93. WFIFOSET(inter_fd,14);
  94. return 0;
  95. }
  96. int intif_save_petdata(int account_id,struct s_pet *p)
  97. {
  98. if (intif->CheckForCharServer())
  99. return 0;
  100. nullpo_ret(p);
  101. WFIFOHEAD(inter_fd, sizeof(struct s_pet) + 8);
  102. WFIFOW(inter_fd,0) = 0x3082;
  103. WFIFOW(inter_fd,2) = sizeof(struct s_pet) + 8;
  104. WFIFOL(inter_fd,4) = account_id;
  105. memcpy(WFIFOP(inter_fd,8),p,sizeof(struct s_pet));
  106. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  107. return 0;
  108. }
  109. int intif_delete_petdata(int pet_id)
  110. {
  111. if (intif->CheckForCharServer())
  112. return 0;
  113. WFIFOHEAD(inter_fd,6);
  114. WFIFOW(inter_fd,0) = 0x3083;
  115. WFIFOL(inter_fd,2) = pet_id;
  116. WFIFOSET(inter_fd,6);
  117. return 1;
  118. }
  119. int intif_rename(struct map_session_data *sd, int type, char *name)
  120. {
  121. if (intif->CheckForCharServer())
  122. return 1;
  123. nullpo_ret(sd);
  124. nullpo_ret(name);
  125. WFIFOHEAD(inter_fd,NAME_LENGTH+12);
  126. WFIFOW(inter_fd,0) = 0x3006;
  127. WFIFOL(inter_fd,2) = sd->status.account_id;
  128. WFIFOL(inter_fd,6) = sd->status.char_id;
  129. WFIFOB(inter_fd,10) = type; //Type: 0 - PC, 1 - PET, 2 - HOM
  130. memcpy(WFIFOP(inter_fd,11),name, NAME_LENGTH);
  131. WFIFOSET(inter_fd,NAME_LENGTH+12);
  132. return 0;
  133. }
  134. // GM Send a message
  135. int intif_broadcast(const char* mes, size_t len, int type)
  136. {
  137. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  138. nullpo_ret(mes);
  139. Assert_ret(len < 32000);
  140. // Send to the local players
  141. clif->broadcast(NULL, mes, len, type, ALL_CLIENT);
  142. if (intif->CheckForCharServer())
  143. return 0;
  144. if (chrif->other_mapserver_count < 1)
  145. return 0; //No need to send.
  146. WFIFOHEAD(inter_fd, 16 + lp + len);
  147. WFIFOW(inter_fd,0) = 0x3000;
  148. WFIFOW(inter_fd,2) = 16 + lp + len;
  149. WFIFOL(inter_fd,4) = 0xFF000000; // 0xFF000000 color signals standard broadcast
  150. WFIFOW(inter_fd,8) = 0; // fontType not used with standard broadcast
  151. WFIFOW(inter_fd,10) = 0; // fontSize not used with standard broadcast
  152. WFIFOW(inter_fd,12) = 0; // fontAlign not used with standard broadcast
  153. WFIFOW(inter_fd,14) = 0; // fontY not used with standard broadcast
  154. if (type&BC_BLUE)
  155. WFIFOL(inter_fd,16) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  156. else if (type&BC_WOE)
  157. WFIFOL(inter_fd,16) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  158. memcpy(WFIFOP(inter_fd,16 + lp), mes, len);
  159. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  160. return 0;
  161. }
  162. int intif_broadcast2(const char* mes, size_t len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY)
  163. {
  164. nullpo_ret(mes);
  165. Assert_ret(len < 32000);
  166. // Send to the local players
  167. clif->broadcast2(NULL, mes, len, fontColor, fontType, fontSize, fontAlign, fontY, ALL_CLIENT);
  168. if (intif->CheckForCharServer())
  169. return 0;
  170. if (chrif->other_mapserver_count < 1)
  171. return 0; //No need to send.
  172. WFIFOHEAD(inter_fd, 16 + len);
  173. WFIFOW(inter_fd,0) = 0x3000;
  174. WFIFOW(inter_fd,2) = 16 + len;
  175. WFIFOL(inter_fd,4) = fontColor;
  176. WFIFOW(inter_fd,8) = fontType;
  177. WFIFOW(inter_fd,10) = fontSize;
  178. WFIFOW(inter_fd,12) = fontAlign;
  179. WFIFOW(inter_fd,14) = fontY;
  180. memcpy(WFIFOP(inter_fd,16), mes, len);
  181. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  182. return 0;
  183. }
  184. /// send a message using the main chat system
  185. /// <sd> the source of message
  186. /// <message> the message that was sent
  187. int intif_main_message(struct map_session_data* sd, const char* message)
  188. {
  189. char output[256];
  190. nullpo_ret(sd);
  191. nullpo_ret(message);
  192. // format the message for main broadcasting
  193. snprintf( output, sizeof(output), msg_txt(386), sd->status.name, message );
  194. // send the message using the inter-server broadcast service
  195. intif->broadcast2( output, strlen(output) + 1, 0xFE000000, 0, 0, 0, 0 );
  196. // log the chat message
  197. logs->chat( LOG_CHAT_MAINCHAT, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message );
  198. return 0;
  199. }
  200. // The transmission of Wisp/Page to inter-server (player not found on this server)
  201. int intif_wis_message(struct map_session_data *sd, char *nick, char *mes, size_t mes_len)
  202. {
  203. if (intif->CheckForCharServer())
  204. return 0;
  205. nullpo_ret(sd);
  206. nullpo_ret(nick);
  207. nullpo_ret(mes);
  208. if (chrif->other_mapserver_count < 1) {
  209. //Character not found.
  210. clif->wis_end(sd->fd, 1);
  211. return 0;
  212. }
  213. WFIFOHEAD(inter_fd,mes_len + 52);
  214. WFIFOW(inter_fd,0) = 0x3001;
  215. WFIFOW(inter_fd,2) = mes_len + 52;
  216. memcpy(WFIFOP(inter_fd,4), sd->status.name, NAME_LENGTH);
  217. memcpy(WFIFOP(inter_fd,4+NAME_LENGTH), nick, NAME_LENGTH);
  218. memcpy(WFIFOP(inter_fd,4+2*NAME_LENGTH), mes, mes_len);
  219. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  220. if (battle_config.etc_log)
  221. ShowInfo("intif_wis_message from %s to %s (message: '%s')\n", sd->status.name, nick, mes);
  222. return 0;
  223. }
  224. // The reply of Wisp/page
  225. int intif_wis_replay(int id, int flag)
  226. {
  227. if (intif->CheckForCharServer())
  228. return 0;
  229. WFIFOHEAD(inter_fd,7);
  230. WFIFOW(inter_fd,0) = 0x3002;
  231. WFIFOL(inter_fd,2) = id;
  232. WFIFOB(inter_fd,6) = flag; // flag: 0: success to send whisper, 1: target character is not logged in?, 2: ignored by target
  233. WFIFOSET(inter_fd,7);
  234. if (battle_config.etc_log)
  235. ShowInfo("intif_wis_replay: id: %d, flag:%d\n", id, flag);
  236. return 0;
  237. }
  238. // The transmission of GM only Wisp/Page from server to inter-server
  239. int intif_wis_message_to_gm(char *wisp_name, int permission, char *mes)
  240. {
  241. size_t mes_len;
  242. if (intif->CheckForCharServer())
  243. return 0;
  244. nullpo_ret(wisp_name);
  245. nullpo_ret(mes);
  246. mes_len = strlen(mes) + 1; // + null
  247. WFIFOHEAD(inter_fd, mes_len + 32);
  248. WFIFOW(inter_fd,0) = 0x3003;
  249. WFIFOW(inter_fd,2) = mes_len + 32;
  250. memcpy(WFIFOP(inter_fd,4), wisp_name, NAME_LENGTH);
  251. WFIFOL(inter_fd,4+NAME_LENGTH) = permission;
  252. memcpy(WFIFOP(inter_fd,8+NAME_LENGTH), mes, mes_len);
  253. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  254. if (battle_config.etc_log)
  255. ShowNotice("intif_wis_message_to_gm: from: '%s', required permission: %d, message: '%s'.\n", wisp_name, permission, mes);
  256. return 0;
  257. }
  258. //Request for saving registry values.
  259. int intif_saveregistry(struct map_session_data *sd) {
  260. DBIterator *iter;
  261. DBKey key;
  262. DBData *data;
  263. int plen = 0;
  264. size_t len;
  265. nullpo_ret(sd);
  266. if (intif->CheckForCharServer() || !sd->regs.vars)
  267. return -1;
  268. WFIFOHEAD(inter_fd, 60000 + 300);
  269. WFIFOW(inter_fd,0) = 0x3004;
  270. /* 0x2 = length (set later) */
  271. WFIFOL(inter_fd,4) = sd->status.account_id;
  272. WFIFOL(inter_fd,8) = sd->status.char_id;
  273. WFIFOW(inter_fd,12) = 0;/* count */
  274. plen = 14;
  275. iter = db_iterator(sd->regs.vars);
  276. for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) {
  277. const char *varname = NULL;
  278. struct script_reg_state *src = NULL;
  279. if( data->type != DB_DATA_PTR ) /* its a @number */
  280. continue;
  281. varname = script->get_str(script_getvarid(key.i64));
  282. if( varname[0] == '@' ) /* @string$ can get here, so we skip */
  283. continue;
  284. if (strlen(varname) > SCRIPT_VARNAME_LENGTH) {
  285. ShowError("Variable name too big: %s\n", varname);
  286. continue;
  287. }
  288. src = DB->data2ptr(data);
  289. /* no need! */
  290. if( !src->update )
  291. continue;
  292. src->update = false;
  293. len = strlen(varname)+1;
  294. WFIFOB(inter_fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */
  295. plen += 1;
  296. safestrncpy((char*)WFIFOP(inter_fd,plen), varname, len);
  297. plen += len;
  298. WFIFOL(inter_fd, plen) = script_getvaridx(key.i64);
  299. plen += 4;
  300. if( src->type ) {
  301. struct script_reg_str *p = (struct script_reg_str *)src;
  302. WFIFOB(inter_fd, plen) = p->value ? 2 : 3;
  303. plen += 1;
  304. if( p->value ) {
  305. len = strlen(p->value)+1;
  306. WFIFOB(inter_fd, plen) = (unsigned char)len;/* won't be higher; the column size is 254 */
  307. plen += 1;
  308. safestrncpy((char*)WFIFOP(inter_fd,plen), p->value, len);
  309. plen += len;
  310. } else {
  311. script->reg_destroy_single(sd,key.i64,&p->flag);
  312. }
  313. } else {
  314. struct script_reg_num *p = (struct script_reg_num *)src;
  315. WFIFOB(inter_fd, plen) = p->value ? 0 : 1;
  316. plen += 1;
  317. if( p->value ) {
  318. WFIFOL(inter_fd, plen) = p->value;
  319. plen += 4;
  320. } else {
  321. script->reg_destroy_single(sd,key.i64,&p->flag);
  322. }
  323. }
  324. WFIFOW(inter_fd,12) += 1;
  325. if( plen > 60000 ) {
  326. WFIFOW(inter_fd, 2) = plen;
  327. WFIFOSET(inter_fd, plen);
  328. /* prepare follow up */
  329. WFIFOHEAD(inter_fd, 60000 + 300);
  330. WFIFOW(inter_fd,0) = 0x3004;
  331. /* 0x2 = length (set later) */
  332. WFIFOL(inter_fd,4) = sd->status.account_id;
  333. WFIFOL(inter_fd,8) = sd->status.char_id;
  334. WFIFOW(inter_fd,12) = 0;/* count */
  335. plen = 14;
  336. }
  337. }
  338. dbi_destroy(iter);
  339. /* mark & go. */
  340. WFIFOW(inter_fd, 2) = plen;
  341. WFIFOSET(inter_fd, plen);
  342. sd->vars_dirty = false;
  343. return 0;
  344. }
  345. //Request the registries for this player.
  346. int intif_request_registry(struct map_session_data *sd, int flag)
  347. {
  348. nullpo_ret(sd);
  349. /* if char server ain't online it doesn't load, shouldn't we kill the session then? */
  350. if (intif->CheckForCharServer())
  351. return 0;
  352. WFIFOHEAD(inter_fd,6);
  353. WFIFOW(inter_fd,0) = 0x3005;
  354. WFIFOL(inter_fd,2) = sd->status.account_id;
  355. WFIFOL(inter_fd,6) = sd->status.char_id;
  356. WFIFOB(inter_fd,10) = (flag&1) ? 1 : 0; //Request Acc Reg 2
  357. WFIFOB(inter_fd,11) = (flag&2) ? 1 : 0; //Request Acc Reg
  358. WFIFOB(inter_fd,12) = (flag&4) ? 1 : 0; //Request Char Reg
  359. WFIFOSET(inter_fd,13);
  360. return 0;
  361. }
  362. int intif_request_guild_storage(int account_id,int guild_id)
  363. {
  364. if (intif->CheckForCharServer())
  365. return 0;
  366. WFIFOHEAD(inter_fd,10);
  367. WFIFOW(inter_fd,0) = 0x3018;
  368. WFIFOL(inter_fd,2) = account_id;
  369. WFIFOL(inter_fd,6) = guild_id;
  370. WFIFOSET(inter_fd,10);
  371. return 0;
  372. }
  373. int intif_send_guild_storage(int account_id,struct guild_storage *gstor)
  374. {
  375. if (intif->CheckForCharServer())
  376. return 0;
  377. nullpo_ret(gstor);
  378. WFIFOHEAD(inter_fd,sizeof(struct guild_storage)+12);
  379. WFIFOW(inter_fd,0) = 0x3019;
  380. WFIFOW(inter_fd,2) = (unsigned short)sizeof(struct guild_storage)+12;
  381. WFIFOL(inter_fd,4) = account_id;
  382. WFIFOL(inter_fd,8) = gstor->guild_id;
  383. memcpy( WFIFOP(inter_fd,12),gstor, sizeof(struct guild_storage) );
  384. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  385. return 0;
  386. }
  387. // Party creation request
  388. int intif_create_party(struct party_member *member,char *name,int item,int item2)
  389. {
  390. if (intif->CheckForCharServer())
  391. return 0;
  392. nullpo_ret(member);
  393. nullpo_ret(name);
  394. WFIFOHEAD(inter_fd,64);
  395. WFIFOW(inter_fd,0) = 0x3020;
  396. WFIFOW(inter_fd,2) = 30+sizeof(struct party_member);
  397. memcpy(WFIFOP(inter_fd,4),name, NAME_LENGTH);
  398. WFIFOB(inter_fd,28)= item;
  399. WFIFOB(inter_fd,29)= item2;
  400. memcpy(WFIFOP(inter_fd,30), member, sizeof(struct party_member));
  401. WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
  402. return 0;
  403. }
  404. // Party information request
  405. int intif_request_partyinfo(int party_id, int char_id)
  406. {
  407. if (intif->CheckForCharServer())
  408. return 0;
  409. WFIFOHEAD(inter_fd,10);
  410. WFIFOW(inter_fd,0) = 0x3021;
  411. WFIFOL(inter_fd,2) = party_id;
  412. WFIFOL(inter_fd,6) = char_id;
  413. WFIFOSET(inter_fd,10);
  414. return 0;
  415. }
  416. // Request to add a member to party
  417. int intif_party_addmember(int party_id,struct party_member *member)
  418. {
  419. if (intif->CheckForCharServer())
  420. return 0;
  421. nullpo_ret(member);
  422. WFIFOHEAD(inter_fd,42);
  423. WFIFOW(inter_fd,0)=0x3022;
  424. WFIFOW(inter_fd,2)=8+sizeof(struct party_member);
  425. WFIFOL(inter_fd,4)=party_id;
  426. memcpy(WFIFOP(inter_fd,8),member,sizeof(struct party_member));
  427. WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
  428. return 1;
  429. }
  430. // Request to change party configuration (exp,item share)
  431. int intif_party_changeoption(int party_id,int account_id,int exp,int item)
  432. {
  433. if (intif->CheckForCharServer())
  434. return 0;
  435. WFIFOHEAD(inter_fd,14);
  436. WFIFOW(inter_fd,0)=0x3023;
  437. WFIFOL(inter_fd,2)=party_id;
  438. WFIFOL(inter_fd,6)=account_id;
  439. WFIFOW(inter_fd,10)=exp;
  440. WFIFOW(inter_fd,12)=item;
  441. WFIFOSET(inter_fd,14);
  442. return 0;
  443. }
  444. // Request to leave party
  445. int intif_party_leave(int party_id,int account_id, int char_id)
  446. {
  447. if (intif->CheckForCharServer())
  448. return 0;
  449. WFIFOHEAD(inter_fd,14);
  450. WFIFOW(inter_fd,0)=0x3024;
  451. WFIFOL(inter_fd,2)=party_id;
  452. WFIFOL(inter_fd,6)=account_id;
  453. WFIFOL(inter_fd,10)=char_id;
  454. WFIFOSET(inter_fd,14);
  455. return 0;
  456. }
  457. // Request keeping party for new map ??
  458. int intif_party_changemap(struct map_session_data *sd,int online) {
  459. int16 m, map_index;
  460. if (intif->CheckForCharServer())
  461. return 0;
  462. if(!sd)
  463. return 0;
  464. if( (m=map->mapindex2mapid(sd->mapindex)) >= 0 && map->list[m].instance_id >= 0 )
  465. map_index = map_id2index(map->list[m].instance_src_map);
  466. else
  467. map_index = sd->mapindex;
  468. WFIFOHEAD(inter_fd,19);
  469. WFIFOW(inter_fd,0)=0x3025;
  470. WFIFOL(inter_fd,2)=sd->status.party_id;
  471. WFIFOL(inter_fd,6)=sd->status.account_id;
  472. WFIFOL(inter_fd,10)=sd->status.char_id;
  473. WFIFOW(inter_fd,14)=map_index;
  474. WFIFOB(inter_fd,16)=online;
  475. WFIFOW(inter_fd,17)=sd->status.base_level;
  476. WFIFOSET(inter_fd,19);
  477. return 1;
  478. }
  479. // Request breaking party
  480. int intif_break_party(int party_id)
  481. {
  482. if (intif->CheckForCharServer())
  483. return 0;
  484. WFIFOHEAD(inter_fd,6);
  485. WFIFOW(inter_fd,0)=0x3026;
  486. WFIFOL(inter_fd,2)=party_id;
  487. WFIFOSET(inter_fd,6);
  488. return 0;
  489. }
  490. // Sending party chat
  491. int intif_party_message(int party_id,int account_id,const char *mes,int len)
  492. {
  493. if (intif->CheckForCharServer())
  494. return 0;
  495. if (chrif->other_mapserver_count < 1)
  496. return 0; //No need to send.
  497. nullpo_ret(mes);
  498. Assert_ret(len > 0 && len < 32000);
  499. WFIFOHEAD(inter_fd,len + 12);
  500. WFIFOW(inter_fd,0)=0x3027;
  501. WFIFOW(inter_fd,2)=len+12;
  502. WFIFOL(inter_fd,4)=party_id;
  503. WFIFOL(inter_fd,8)=account_id;
  504. memcpy(WFIFOP(inter_fd,12),mes,len);
  505. WFIFOSET(inter_fd,len+12);
  506. return 0;
  507. }
  508. // Request a new leader for party
  509. int intif_party_leaderchange(int party_id,int account_id,int char_id)
  510. {
  511. if (intif->CheckForCharServer())
  512. return 0;
  513. WFIFOHEAD(inter_fd,14);
  514. WFIFOW(inter_fd,0)=0x3029;
  515. WFIFOL(inter_fd,2)=party_id;
  516. WFIFOL(inter_fd,6)=account_id;
  517. WFIFOL(inter_fd,10)=char_id;
  518. WFIFOSET(inter_fd,14);
  519. return 0;
  520. }
  521. // Request a Guild creation
  522. int intif_guild_create(const char *name,const struct guild_member *master)
  523. {
  524. if (intif->CheckForCharServer())
  525. return 0;
  526. nullpo_ret(master);
  527. nullpo_ret(name);
  528. WFIFOHEAD(inter_fd,sizeof(struct guild_member)+(8+NAME_LENGTH));
  529. WFIFOW(inter_fd,0)=0x3030;
  530. WFIFOW(inter_fd,2)=sizeof(struct guild_member)+(8+NAME_LENGTH);
  531. WFIFOL(inter_fd,4)=master->account_id;
  532. memcpy(WFIFOP(inter_fd,8),name,NAME_LENGTH);
  533. memcpy(WFIFOP(inter_fd,8+NAME_LENGTH),master,sizeof(struct guild_member));
  534. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  535. return 0;
  536. }
  537. // Request Guild information
  538. int intif_guild_request_info(int guild_id)
  539. {
  540. if (intif->CheckForCharServer())
  541. return 0;
  542. WFIFOHEAD(inter_fd,6);
  543. WFIFOW(inter_fd,0) = 0x3031;
  544. WFIFOL(inter_fd,2) = guild_id;
  545. WFIFOSET(inter_fd,6);
  546. return 0;
  547. }
  548. // Request to add member to the guild
  549. int intif_guild_addmember(int guild_id,struct guild_member *m)
  550. {
  551. if (intif->CheckForCharServer())
  552. return 0;
  553. nullpo_ret(m);
  554. WFIFOHEAD(inter_fd,sizeof(struct guild_member)+8);
  555. WFIFOW(inter_fd,0) = 0x3032;
  556. WFIFOW(inter_fd,2) = sizeof(struct guild_member)+8;
  557. WFIFOL(inter_fd,4) = guild_id;
  558. memcpy(WFIFOP(inter_fd,8),m,sizeof(struct guild_member));
  559. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  560. return 0;
  561. }
  562. // Request a new leader for guild
  563. int intif_guild_change_gm(int guild_id, const char* name, size_t len)
  564. {
  565. if (intif->CheckForCharServer())
  566. return 0;
  567. nullpo_ret(name);
  568. Assert_ret(len > 0 && len < 32000);
  569. WFIFOHEAD(inter_fd, len + 8);
  570. WFIFOW(inter_fd, 0)=0x3033;
  571. WFIFOW(inter_fd, 2)=len+8;
  572. WFIFOL(inter_fd, 4)=guild_id;
  573. memcpy(WFIFOP(inter_fd,8),name,len);
  574. WFIFOSET(inter_fd,len+8);
  575. return 0;
  576. }
  577. // Request to leave guild
  578. int intif_guild_leave(int guild_id,int account_id,int char_id,int flag,const char *mes)
  579. {
  580. if (intif->CheckForCharServer())
  581. return 0;
  582. nullpo_ret(mes);
  583. WFIFOHEAD(inter_fd, 55);
  584. WFIFOW(inter_fd, 0) = 0x3034;
  585. WFIFOL(inter_fd, 2) = guild_id;
  586. WFIFOL(inter_fd, 6) = account_id;
  587. WFIFOL(inter_fd,10) = char_id;
  588. WFIFOB(inter_fd,14) = flag;
  589. safestrncpy((char*)WFIFOP(inter_fd,15),mes,40);
  590. WFIFOSET(inter_fd,55);
  591. return 0;
  592. }
  593. //Update request / Lv online status of the guild members
  594. int intif_guild_memberinfoshort(int guild_id,int account_id,int char_id,int online,int lv,int class_)
  595. {
  596. if (intif->CheckForCharServer())
  597. return 0;
  598. WFIFOHEAD(inter_fd, 19);
  599. WFIFOW(inter_fd, 0) = 0x3035;
  600. WFIFOL(inter_fd, 2) = guild_id;
  601. WFIFOL(inter_fd, 6) = account_id;
  602. WFIFOL(inter_fd,10) = char_id;
  603. WFIFOB(inter_fd,14) = online;
  604. WFIFOW(inter_fd,15) = lv;
  605. WFIFOW(inter_fd,17) = class_;
  606. WFIFOSET(inter_fd,19);
  607. return 0;
  608. }
  609. //Guild disbanded notification
  610. int intif_guild_break(int guild_id)
  611. {
  612. if (intif->CheckForCharServer())
  613. return 0;
  614. WFIFOHEAD(inter_fd, 6);
  615. WFIFOW(inter_fd, 0) = 0x3036;
  616. WFIFOL(inter_fd, 2) = guild_id;
  617. WFIFOSET(inter_fd,6);
  618. return 0;
  619. }
  620. // Send a guild message
  621. int intif_guild_message(int guild_id,int account_id,const char *mes,int len)
  622. {
  623. if (intif->CheckForCharServer())
  624. return 0;
  625. if (chrif->other_mapserver_count < 1)
  626. return 0; //No need to send.
  627. nullpo_ret(mes);
  628. Assert_ret(len > 0 && len < 32000);
  629. WFIFOHEAD(inter_fd, len + 12);
  630. WFIFOW(inter_fd,0)=0x3037;
  631. WFIFOW(inter_fd,2)=len+12;
  632. WFIFOL(inter_fd,4)=guild_id;
  633. WFIFOL(inter_fd,8)=account_id;
  634. memcpy(WFIFOP(inter_fd,12),mes,len);
  635. WFIFOSET(inter_fd,len+12);
  636. return 0;
  637. }
  638. /**
  639. * Requests to change a basic guild information, it is parsed via mapif_parse_GuildBasicInfoChange
  640. * To see the information types that can be changed see mmo.h::guild_basic_info
  641. **/
  642. int intif_guild_change_basicinfo(int guild_id,int type,const void *data,int len)
  643. {
  644. if (intif->CheckForCharServer())
  645. return 0;
  646. nullpo_ret(data);
  647. Assert_ret(len >= 0 && len < 32000);
  648. WFIFOHEAD(inter_fd, len + 10);
  649. WFIFOW(inter_fd,0)=0x3039;
  650. WFIFOW(inter_fd,2)=len+10;
  651. WFIFOL(inter_fd,4)=guild_id;
  652. WFIFOW(inter_fd,8)=type;
  653. memcpy(WFIFOP(inter_fd,10),data,len);
  654. WFIFOSET(inter_fd,len+10);
  655. return 0;
  656. }
  657. // Request a change of Guild member information
  658. int intif_guild_change_memberinfo(int guild_id,int account_id,int char_id,
  659. int type,const void *data,int len)
  660. {
  661. if (intif->CheckForCharServer())
  662. return 0;
  663. nullpo_ret(data);
  664. Assert_ret(len >= 0 && len < 32000);
  665. WFIFOHEAD(inter_fd, len + 18);
  666. WFIFOW(inter_fd, 0)=0x303a;
  667. WFIFOW(inter_fd, 2)=len+18;
  668. WFIFOL(inter_fd, 4)=guild_id;
  669. WFIFOL(inter_fd, 8)=account_id;
  670. WFIFOL(inter_fd,12)=char_id;
  671. WFIFOW(inter_fd,16)=type;
  672. memcpy(WFIFOP(inter_fd,18),data,len);
  673. WFIFOSET(inter_fd,len+18);
  674. return 0;
  675. }
  676. // Request a change of Guild title
  677. int intif_guild_position(int guild_id,int idx,struct guild_position *p)
  678. {
  679. if (intif->CheckForCharServer())
  680. return 0;
  681. nullpo_ret(p);
  682. WFIFOHEAD(inter_fd, sizeof(struct guild_position)+12);
  683. WFIFOW(inter_fd,0)=0x303b;
  684. WFIFOW(inter_fd,2)=sizeof(struct guild_position)+12;
  685. WFIFOL(inter_fd,4)=guild_id;
  686. WFIFOL(inter_fd,8)=idx;
  687. memcpy(WFIFOP(inter_fd,12),p,sizeof(struct guild_position));
  688. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  689. return 0;
  690. }
  691. // Request an update of Guildskill skill_id
  692. int intif_guild_skillup(int guild_id, uint16 skill_id, int account_id, int max)
  693. {
  694. if( intif->CheckForCharServer() )
  695. return 0;
  696. WFIFOHEAD(inter_fd, 18);
  697. WFIFOW(inter_fd, 0) = 0x303c;
  698. WFIFOL(inter_fd, 2) = guild_id;
  699. WFIFOL(inter_fd, 6) = skill_id;
  700. WFIFOL(inter_fd, 10) = account_id;
  701. WFIFOL(inter_fd, 14) = max;
  702. WFIFOSET(inter_fd, 18);
  703. return 0;
  704. }
  705. // Request a new guild relationship
  706. int intif_guild_alliance(int guild_id1,int guild_id2,int account_id1,int account_id2,int flag)
  707. {
  708. if (intif->CheckForCharServer())
  709. return 0;
  710. WFIFOHEAD(inter_fd,19);
  711. WFIFOW(inter_fd, 0)=0x303d;
  712. WFIFOL(inter_fd, 2)=guild_id1;
  713. WFIFOL(inter_fd, 6)=guild_id2;
  714. WFIFOL(inter_fd,10)=account_id1;
  715. WFIFOL(inter_fd,14)=account_id2;
  716. WFIFOB(inter_fd,18)=flag;
  717. WFIFOSET(inter_fd,19);
  718. return 0;
  719. }
  720. // Request to change guild notice
  721. int intif_guild_notice(int guild_id,const char *mes1,const char *mes2)
  722. {
  723. if (intif->CheckForCharServer())
  724. return 0;
  725. nullpo_ret(mes1);
  726. nullpo_ret(mes2);
  727. WFIFOHEAD(inter_fd,186);
  728. WFIFOW(inter_fd,0)=0x303e;
  729. WFIFOL(inter_fd,2)=guild_id;
  730. memcpy(WFIFOP(inter_fd,6),mes1,MAX_GUILDMES1);
  731. memcpy(WFIFOP(inter_fd,66),mes2,MAX_GUILDMES2);
  732. WFIFOSET(inter_fd,186);
  733. return 0;
  734. }
  735. // Request to change guild emblem
  736. int intif_guild_emblem(int guild_id,int len,const char *data)
  737. {
  738. if (intif->CheckForCharServer())
  739. return 0;
  740. if(guild_id<=0 || len<0 || len>2000)
  741. return 0;
  742. nullpo_ret(data);
  743. Assert_ret(len >= 0 && len < 32000);
  744. WFIFOHEAD(inter_fd,len + 12);
  745. WFIFOW(inter_fd,0)=0x303f;
  746. WFIFOW(inter_fd,2)=len+12;
  747. WFIFOL(inter_fd,4)=guild_id;
  748. WFIFOL(inter_fd,8)=0;
  749. memcpy(WFIFOP(inter_fd,12),data,len);
  750. WFIFOSET(inter_fd,len+12);
  751. return 0;
  752. }
  753. /**
  754. * Requests guild castles data from char-server.
  755. * @param num Number of castles, size of castle_ids array.
  756. * @param castle_ids Pointer to array of castle IDs.
  757. */
  758. int intif_guild_castle_dataload(int num, int *castle_ids)
  759. {
  760. if (intif->CheckForCharServer())
  761. return 0;
  762. nullpo_ret(castle_ids);
  763. WFIFOHEAD(inter_fd, 4 + num * sizeof(int));
  764. WFIFOW(inter_fd, 0) = 0x3040;
  765. WFIFOW(inter_fd, 2) = 4 + num * sizeof(int);
  766. memcpy(WFIFOP(inter_fd, 4), castle_ids, num * sizeof(int));
  767. WFIFOSET(inter_fd, WFIFOW(inter_fd, 2));
  768. return 1;
  769. }
  770. // Request change castle guild owner and save data
  771. int intif_guild_castle_datasave(int castle_id,int index, int value)
  772. {
  773. if (intif->CheckForCharServer())
  774. return 0;
  775. WFIFOHEAD(inter_fd,9);
  776. WFIFOW(inter_fd,0)=0x3041;
  777. WFIFOW(inter_fd,2)=castle_id;
  778. WFIFOB(inter_fd,4)=index;
  779. WFIFOL(inter_fd,5)=value;
  780. WFIFOSET(inter_fd,9);
  781. return 1;
  782. }
  783. //-----------------------------------------------------------------
  784. // Homunculus Packets send to Inter server [albator]
  785. //-----------------------------------------------------------------
  786. int intif_homunculus_create(int account_id, struct s_homunculus *sh)
  787. {
  788. if (intif->CheckForCharServer())
  789. return 0;
  790. nullpo_ret(sh);
  791. WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
  792. WFIFOW(inter_fd,0) = 0x3090;
  793. WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
  794. WFIFOL(inter_fd,4) = account_id;
  795. memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
  796. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  797. return 0;
  798. }
  799. bool intif_homunculus_requestload(int account_id, int homun_id) {
  800. if (intif->CheckForCharServer())
  801. return false;
  802. WFIFOHEAD(inter_fd, 10);
  803. WFIFOW(inter_fd,0) = 0x3091;
  804. WFIFOL(inter_fd,2) = account_id;
  805. WFIFOL(inter_fd,6) = homun_id;
  806. WFIFOSET(inter_fd, 10);
  807. return true;
  808. }
  809. int intif_homunculus_requestsave(int account_id, struct s_homunculus* sh)
  810. {
  811. if (intif->CheckForCharServer())
  812. return 0;
  813. nullpo_ret(sh);
  814. WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
  815. WFIFOW(inter_fd,0) = 0x3092;
  816. WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
  817. WFIFOL(inter_fd,4) = account_id;
  818. memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
  819. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  820. return 0;
  821. }
  822. int intif_homunculus_requestdelete(int homun_id)
  823. {
  824. if (intif->CheckForCharServer())
  825. return 0;
  826. WFIFOHEAD(inter_fd, 6);
  827. WFIFOW(inter_fd, 0) = 0x3093;
  828. WFIFOL(inter_fd,2) = homun_id;
  829. WFIFOSET(inter_fd,6);
  830. return 0;
  831. }
  832. //-----------------------------------------------------------------
  833. // Packets receive from inter server
  834. // Wisp/Page reception // rewritten by [Yor]
  835. void intif_parse_WisMessage(int fd) {
  836. struct map_session_data* sd;
  837. char *wisp_source;
  838. char name[NAME_LENGTH];
  839. int id, i;
  840. id=RFIFOL(fd,4);
  841. safestrncpy(name, (char*)RFIFOP(fd,32), NAME_LENGTH);
  842. sd = map->nick2sd(name);
  843. if(sd == NULL || strcmp(sd->status.name, name) != 0) {
  844. //Not found
  845. intif_wis_replay(id,1);
  846. return;
  847. }
  848. if(sd->state.ignoreAll) {
  849. intif_wis_replay(id, 2);
  850. return;
  851. }
  852. wisp_source = (char *) RFIFOP(fd,8); // speed up [Yor]
  853. for(i=0; i < MAX_IGNORE_LIST &&
  854. sd->ignore[i].name[0] != '\0' &&
  855. strcmp(sd->ignore[i].name, wisp_source) != 0
  856. ; i++);
  857. if (i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0') {
  858. //Ignored
  859. intif_wis_replay(id, 2);
  860. return;
  861. }
  862. //Success to send whisper.
  863. clif->wis_message(sd->fd, wisp_source, (char*)RFIFOP(fd,56),RFIFOW(fd,2)-56);
  864. intif_wis_replay(id,0); // success
  865. }
  866. // Wisp/page transmission result reception
  867. void intif_parse_WisEnd(int fd) {
  868. struct map_session_data* sd;
  869. if (battle_config.etc_log)
  870. ShowInfo("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP(fd,2), RFIFOB(fd,26)); // flag: 0: success to send whisper, 1: target character is not logged in?, 2: ignored by target
  871. sd = map->nick2sd((char *)RFIFOP(fd,2));
  872. if (sd != NULL)
  873. clif->wis_end(sd->fd, RFIFOB(fd,26));
  874. return;
  875. }
  876. int mapif_parse_WisToGM_sub(struct map_session_data* sd,va_list va) {
  877. int permission = va_arg(va, int);
  878. char *wisp_name;
  879. char *message;
  880. int len;
  881. nullpo_ret(sd);
  882. if (!pc_has_permission(sd, permission))
  883. return 0;
  884. wisp_name = va_arg(va, char*);
  885. message = va_arg(va, char*);
  886. len = va_arg(va, int);
  887. clif->wis_message(sd->fd, wisp_name, message, len);
  888. return 1;
  889. }
  890. // Received wisp message from map-server via char-server for ALL gm
  891. // 0x3003/0x3803 <packet_len>.w <wispname>.24B <permission>.l <message>.?B
  892. void mapif_parse_WisToGM(int fd)
  893. {
  894. int permission, mes_len;
  895. char Wisp_name[NAME_LENGTH];
  896. char mbuf[255] = { 0 };
  897. char *message;
  898. mes_len = RFIFOW(fd,2) - 32;
  899. Assert_retv(mes_len > 0 && mes_len < 32000);
  900. message = (char *) (mes_len >= 255 ? (char *) aMalloc(mes_len) : mbuf);
  901. permission = RFIFOL(fd,28);
  902. safestrncpy(Wisp_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  903. safestrncpy(message, (char*)RFIFOP(fd,32), mes_len);
  904. // information is sent to all online GM
  905. map->foreachpc(mapif_parse_WisToGM_sub, permission, Wisp_name, message, mes_len);
  906. if (message != mbuf)
  907. aFree(message);
  908. }
  909. // Request player registre
  910. void intif_parse_Registers(int fd)
  911. {
  912. int flag;
  913. struct map_session_data *sd;
  914. int account_id = RFIFOL(fd,4), char_id = RFIFOL(fd,8);
  915. struct auth_node *node = chrif->auth_check(account_id, char_id, ST_LOGIN);
  916. char type = RFIFOB(fd, 13);
  917. if (node)
  918. sd = node->sd;
  919. else { //Normally registries should arrive for in log-in chars.
  920. sd = map->id2sd(account_id);
  921. }
  922. if (!sd || sd->status.char_id != char_id) {
  923. return; //Character registry from another character.
  924. }
  925. flag = ( sd->vars_received&PRL_ACCG && sd->vars_received&PRL_ACCL && sd->vars_received&PRL_CHAR ) ? 0 : 1;
  926. switch (RFIFOB(fd,12)) {
  927. case 3: //Character Registry
  928. sd->vars_received |= PRL_CHAR;
  929. break;
  930. case 2: //Account Registry
  931. sd->vars_received |= PRL_ACCL;
  932. break;
  933. case 1: //Account2 Registry
  934. sd->vars_received |= PRL_ACCG;
  935. break;
  936. case 0:
  937. break;
  938. default:
  939. ShowError("intif_parse_Registers: Unrecognized type %d\n",RFIFOB(fd,12));
  940. return;
  941. }
  942. /* have it not complain about insertion of vars before loading, and not set those vars as new or modified */
  943. pc->reg_load = true;
  944. if (RFIFOW(fd, 14) != 0) {
  945. char key[SCRIPT_VARNAME_LENGTH+1];
  946. unsigned int index;
  947. int max = RFIFOW(fd, 14), cursor = 16, i;
  948. script->parser_current_file = "loading char/acc variables";//for script_add_str to refer to here in case errors occur
  949. /**
  950. * Vessel!char_reg_num_db
  951. *
  952. * str type
  953. * { keyLength(B), key(<keyLength>), index(L), valLength(B), val(<valLength>) }
  954. **/
  955. if (type) {
  956. char sval[254];
  957. for (i = 0; i < max; i++) {
  958. int len = RFIFOB(fd, cursor);
  959. safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), min((int)sizeof(key), len));
  960. cursor += len + 1;
  961. index = RFIFOL(fd, cursor);
  962. cursor += 4;
  963. len = RFIFOB(fd, cursor);
  964. safestrncpy(sval, (char*)RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len));
  965. cursor += len + 1;
  966. script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, (void*)sval, NULL);
  967. }
  968. /**
  969. * Vessel!
  970. *
  971. * int type
  972. * { keyLength(B), key(<keyLength>), index(L), value(L) }
  973. **/
  974. } else {
  975. for (i = 0; i < max; i++) {
  976. int ival;
  977. int len = RFIFOB(fd, cursor);
  978. safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), min((int)sizeof(key), len));
  979. cursor += len + 1;
  980. index = RFIFOL(fd, cursor);
  981. cursor += 4;
  982. ival = RFIFOL(fd, cursor);
  983. cursor += 4;
  984. script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, (void*)h64BPTRSIZE(ival), NULL);
  985. }
  986. }
  987. script->parser_current_file = NULL;/* reset */
  988. }
  989. /* flag it back */
  990. pc->reg_load = false;
  991. if (flag && sd->vars_received&PRL_ACCG && sd->vars_received&PRL_ACCL && sd->vars_received&PRL_CHAR)
  992. pc->reg_received(sd); //Received all registry values, execute init scripts and what-not. [Skotlex]
  993. }
  994. void intif_parse_LoadGuildStorage(int fd)
  995. {
  996. struct guild_storage *gstor;
  997. struct map_session_data *sd;
  998. int guild_id, flag;
  999. guild_id = RFIFOL(fd,8);
  1000. flag = RFIFOL(fd,12);
  1001. if(guild_id <= 0)
  1002. return;
  1003. sd=map->id2sd( RFIFOL(fd,4) );
  1004. if( flag ){ //If flag != 0, we attach a player and open the storage
  1005. if(sd==NULL){
  1006. ShowError("intif_parse_LoadGuildStorage: user not found %d\n",RFIFOL(fd,4));
  1007. return;
  1008. }
  1009. }
  1010. gstor=gstorage->ensure(guild_id);
  1011. if(!gstor) {
  1012. ShowWarning("intif_parse_LoadGuildStorage: error guild_id %d not exist\n",guild_id);
  1013. return;
  1014. }
  1015. if (gstor->storage_status == 1) { // Already open.. lets ignore this update
  1016. ShowWarning("intif_parse_LoadGuildStorage: storage received for a client already open (User %d:%d)\n", flag?sd->status.account_id:0, flag?sd->status.char_id:0);
  1017. return;
  1018. }
  1019. if (gstor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex]
  1020. ShowWarning("intif_parse_LoadGuildStorage: received storage for an already modified non-saved storage! (User %d:%d)\n", flag?sd->status.account_id:0, flag?sd->status.char_id:0);
  1021. return;
  1022. }
  1023. if (RFIFOW(fd,2)-13 != sizeof(struct guild_storage)) {
  1024. ShowError("intif_parse_LoadGuildStorage: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd,2)-13, sizeof(struct guild_storage));
  1025. gstor->storage_status = 0;
  1026. return;
  1027. }
  1028. memcpy(gstor,RFIFOP(fd,13),sizeof(struct guild_storage));
  1029. if( flag )
  1030. gstorage->open(sd);
  1031. }
  1032. // ACK guild_storage saved
  1033. void intif_parse_SaveGuildStorage(int fd)
  1034. {
  1035. gstorage->saved(/*RFIFOL(fd,2), */RFIFOL(fd,6));
  1036. }
  1037. // ACK party creation
  1038. void intif_parse_PartyCreated(int fd)
  1039. {
  1040. if(battle_config.etc_log)
  1041. ShowInfo("intif: party created by account %d\n\n", RFIFOL(fd,2));
  1042. party->created(RFIFOL(fd,2), RFIFOL(fd,6),RFIFOB(fd,10),RFIFOL(fd,11), (char *)RFIFOP(fd,15));
  1043. }
  1044. // Receive party info
  1045. void intif_parse_PartyInfo(int fd) {
  1046. if (RFIFOW(fd,2) == 12) {
  1047. ShowWarning("intif: party noinfo (char_id=%d party_id=%d)\n", RFIFOL(fd,4), RFIFOL(fd,8));
  1048. party->recv_noinfo(RFIFOL(fd,8), RFIFOL(fd,4));
  1049. return;
  1050. }
  1051. if (RFIFOW(fd,2) != 8+sizeof(struct party))
  1052. ShowError("intif: party info: data size mismatch (char_id=%d party_id=%d packet_len=%d expected_len=%"PRIuS")\n",
  1053. RFIFOL(fd,4), RFIFOL(fd,8), RFIFOW(fd,2), 8+sizeof(struct party));
  1054. party->recv_info((struct party *)RFIFOP(fd,8), RFIFOL(fd,4));
  1055. }
  1056. // ACK adding party member
  1057. void intif_parse_PartyMemberAdded(int fd)
  1058. {
  1059. if(battle_config.etc_log)
  1060. ShowInfo("intif: party member added Party (%d), Account(%d), Char(%d)\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
  1061. party->member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10), RFIFOB(fd, 14));
  1062. }
  1063. // ACK changing party option
  1064. void intif_parse_PartyOptionChanged(int fd)
  1065. {
  1066. party->optionchanged(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOW(fd,10),RFIFOW(fd,12),RFIFOB(fd,14));
  1067. }
  1068. // ACK member leaving party
  1069. void intif_parse_PartyMemberWithdraw(int fd)
  1070. {
  1071. if(battle_config.etc_log)
  1072. ShowInfo("intif: party member withdraw: Party(%d), Account(%d), Char(%d)\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
  1073. party->member_withdraw(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
  1074. }
  1075. // ACK party break
  1076. void intif_parse_PartyBroken(int fd) {
  1077. party->broken(RFIFOL(fd,2));
  1078. }
  1079. // ACK party on new map
  1080. void intif_parse_PartyMove(int fd)
  1081. {
  1082. party->recv_movemap(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOW(fd,14),RFIFOB(fd,16),RFIFOW(fd,17));
  1083. }
  1084. // ACK party messages
  1085. void intif_parse_PartyMessage(int fd) {
  1086. party->recv_message(RFIFOL(fd,4),RFIFOL(fd,8),(char *) RFIFOP(fd,12),RFIFOW(fd,2)-12);
  1087. }
  1088. // ACK guild creation
  1089. void intif_parse_GuildCreated(int fd) {
  1090. guild->created(RFIFOL(fd,2),RFIFOL(fd,6));
  1091. }
  1092. // ACK guild infos
  1093. void intif_parse_GuildInfo(int fd) {
  1094. if (RFIFOW(fd,2) == 8) {
  1095. ShowWarning("intif: guild noinfo %d\n",RFIFOL(fd,4));
  1096. guild->recv_noinfo(RFIFOL(fd,4));
  1097. return;
  1098. }
  1099. if (RFIFOW(fd,2)!=sizeof(struct guild)+4)
  1100. ShowError("intif: guild info: data size mismatch - Gid: %d recv size: %d Expected size: %"PRIuS"\n",
  1101. RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild)+4);
  1102. guild->recv_info((struct guild *)RFIFOP(fd,4));
  1103. }
  1104. // ACK adding guild member
  1105. void intif_parse_GuildMemberAdded(int fd) {
  1106. if(battle_config.etc_log)
  1107. ShowInfo("intif: guild member added %d %d %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14));
  1108. guild->member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14));
  1109. }
  1110. // ACK member leaving guild
  1111. void intif_parse_GuildMemberWithdraw(int fd) {
  1112. guild->member_withdraw(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),(char *)RFIFOP(fd,55),(char *)RFIFOP(fd,15));
  1113. }
  1114. // ACK guild member basic info
  1115. void intif_parse_GuildMemberInfoShort(int fd) {
  1116. guild->recv_memberinfoshort(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOW(fd,15),RFIFOW(fd,17));
  1117. }
  1118. // ACK guild break
  1119. void intif_parse_GuildBroken(int fd) {
  1120. guild->broken(RFIFOL(fd,2),RFIFOB(fd,6));
  1121. }
  1122. // basic guild info change notice
  1123. // 0x3839 <packet len>.w <guild id>.l <type>.w <data>.?b
  1124. void intif_parse_GuildBasicInfoChanged(int fd) {
  1125. //int len = RFIFOW(fd,2) - 10;
  1126. int guild_id = RFIFOL(fd,4);
  1127. int type = RFIFOW(fd,8);
  1128. //void* data = RFIFOP(fd,10);
  1129. struct guild* g = guild->search(guild_id);
  1130. if( g == NULL )
  1131. return;
  1132. switch(type) {
  1133. case GBI_EXP: g->exp = RFIFOQ(fd,10); break;
  1134. case GBI_GUILDLV: g->guild_lv = RFIFOW(fd,10); break;
  1135. case GBI_SKILLPOINT: g->skill_point = RFIFOL(fd,10); break;
  1136. case GBI_SKILLLV: {
  1137. int idx, max;
  1138. struct guild_skill *gs = (struct guild_skill *)RFIFOP(fd,10);
  1139. idx = gs->id - GD_SKILLBASE;
  1140. Assert_retv(idx >= 0 && idx < MAX_GUILDSKILL);
  1141. max = guild->skill_get_max(gs->id);
  1142. if( gs->lv > max )
  1143. gs->lv = max;
  1144. memcpy(&(g->skill[idx]), gs, sizeof(g->skill[idx]));
  1145. break;
  1146. }
  1147. }
  1148. }
  1149. // guild member info change notice
  1150. // 0x383a <packet len>.w <guild id>.l <account id>.l <char id>.l <type>.w <data>.?b
  1151. void intif_parse_GuildMemberInfoChanged(int fd) {
  1152. //int len = RFIFOW(fd,2) - 18;
  1153. int guild_id = RFIFOL(fd,4);
  1154. int account_id = RFIFOL(fd,8);
  1155. int char_id = RFIFOL(fd,12);
  1156. int type = RFIFOW(fd,16);
  1157. //void* data = RFIFOP(fd,18);
  1158. struct guild* g;
  1159. int idx;
  1160. g = guild->search(guild_id);
  1161. if( g == NULL )
  1162. return;
  1163. idx = guild->getindex(g,account_id,char_id);
  1164. if( idx == -1 )
  1165. return;
  1166. switch( type ) {
  1167. case GMI_POSITION: g->member[idx].position = RFIFOW(fd,18); guild->memberposition_changed(g,idx,RFIFOW(fd,18)); break;
  1168. case GMI_EXP: g->member[idx].exp = RFIFOQ(fd,18); break;
  1169. case GMI_HAIR: g->member[idx].hair = RFIFOW(fd,18); break;
  1170. case GMI_HAIR_COLOR: g->member[idx].hair_color = RFIFOW(fd,18); break;
  1171. case GMI_GENDER: g->member[idx].gender = RFIFOW(fd,18); break;
  1172. case GMI_CLASS: g->member[idx].class_ = RFIFOW(fd,18); break;
  1173. case GMI_LEVEL: g->member[idx].lv = RFIFOW(fd,18); break;
  1174. }
  1175. }
  1176. // ACK change of guild title
  1177. void intif_parse_GuildPosition(int fd) {
  1178. if (RFIFOW(fd,2)!=sizeof(struct guild_position)+12)
  1179. ShowError("intif: guild info: data size mismatch (%d) %d != %"PRIuS"\n",
  1180. RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild_position)+12);
  1181. guild->position_changed(RFIFOL(fd,4),RFIFOL(fd,8),(struct guild_position *)RFIFOP(fd,12));
  1182. }
  1183. // ACK change of guild skill update
  1184. void intif_parse_GuildSkillUp(int fd) {
  1185. guild->skillupack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
  1186. }
  1187. // ACK change of guild relationship
  1188. void intif_parse_GuildAlliance(int fd) {
  1189. guild->allianceack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOL(fd,14),RFIFOB(fd,18),(char *) RFIFOP(fd,19),(char *) RFIFOP(fd,43));
  1190. }
  1191. // ACK change of guild notice
  1192. void intif_parse_GuildNotice(int fd) {
  1193. guild->notice_changed(RFIFOL(fd,2),(char *) RFIFOP(fd,6),(char *) RFIFOP(fd,66));
  1194. }
  1195. // ACK change of guild emblem
  1196. void intif_parse_GuildEmblem(int fd) {
  1197. guild->emblem_changed(RFIFOW(fd,2)-12,RFIFOL(fd,4),RFIFOL(fd,8), (char *)RFIFOP(fd,12));
  1198. }
  1199. // ACK guild message
  1200. void intif_parse_GuildMessage(int fd) {
  1201. guild->recv_message(RFIFOL(fd,4),RFIFOL(fd,8),(char *) RFIFOP(fd,12),RFIFOW(fd,2)-12);
  1202. }
  1203. // Reply guild castle data request
  1204. void intif_parse_GuildCastleDataLoad(int fd) {
  1205. guild->castledataloadack(RFIFOW(fd,2), (struct guild_castle *)RFIFOP(fd,4));
  1206. }
  1207. // ACK change of guildmaster
  1208. void intif_parse_GuildMasterChanged(int fd) {
  1209. guild->gm_changed(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
  1210. }
  1211. // Request pet creation
  1212. void intif_parse_CreatePet(int fd) {
  1213. pet->get_egg(RFIFOL(fd,2), RFIFOW(fd,6), RFIFOL(fd,8));
  1214. }
  1215. // ACK pet data
  1216. void intif_parse_RecvPetData(int fd) {
  1217. struct s_pet p;
  1218. int len;
  1219. len=RFIFOW(fd,2);
  1220. if (sizeof(struct s_pet) != len-9) {
  1221. if (battle_config.etc_log)
  1222. ShowError("intif: pet data: data size mismatch %d != %"PRIuS"\n", len-9, sizeof(struct s_pet));
  1223. } else {
  1224. memcpy(&p,RFIFOP(fd,9),sizeof(struct s_pet));
  1225. pet->recv_petdata(RFIFOL(fd,4),&p,RFIFOB(fd,8));
  1226. }
  1227. }
  1228. /* Really? Whats the point, shouldn't be sent when successful then [Ind] */
  1229. // ACK pet save data
  1230. void intif_parse_SavePetOk(int fd) {
  1231. if(RFIFOB(fd,6) == 1)
  1232. ShowError("pet data save failure\n");
  1233. }
  1234. /* Really? Whats the point, shouldn't be sent when successful then [Ind] */
  1235. // ACK deleting pet
  1236. void intif_parse_DeletePetOk(int fd) {
  1237. if(RFIFOB(fd,2) == 1)
  1238. ShowError("pet data delete failure\n");
  1239. }
  1240. // ACK changing name request, players,pets,homun
  1241. void intif_parse_ChangeNameOk(int fd)
  1242. {
  1243. struct map_session_data *sd = NULL;
  1244. if((sd=map->id2sd(RFIFOL(fd,2)))==NULL ||
  1245. sd->status.char_id != RFIFOL(fd,6))
  1246. return;
  1247. switch (RFIFOB(fd,10)) {
  1248. case 0: //Players [NOT SUPPORTED YET]
  1249. break;
  1250. case 1: //Pets
  1251. pet->change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
  1252. break;
  1253. case 2: //Hom
  1254. homun->change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
  1255. break;
  1256. }
  1257. return;
  1258. }
  1259. //----------------------------------------------------------------
  1260. // Homunculus recv packets [albator]
  1261. void intif_parse_CreateHomunculus(int fd) {
  1262. int len = RFIFOW(fd,2)-9;
  1263. if (sizeof(struct s_homunculus) != len) {
  1264. if (battle_config.etc_log)
  1265. ShowError("intif: create homun data: data size mismatch %d != %"PRIuS"\n", len, sizeof(struct s_homunculus));
  1266. return;
  1267. }
  1268. homun->recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8)) ;
  1269. }
  1270. void intif_parse_RecvHomunculusData(int fd) {
  1271. int len = RFIFOW(fd,2)-9;
  1272. if (sizeof(struct s_homunculus) != len) {
  1273. if (battle_config.etc_log)
  1274. ShowError("intif: homun data: data size mismatch %d != %"PRIuS"\n", len, sizeof(struct s_homunculus));
  1275. return;
  1276. }
  1277. homun->recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8));
  1278. }
  1279. /* Really? Whats the point, shouldn't be sent when successful then [Ind] */
  1280. void intif_parse_SaveHomunculusOk(int fd) {
  1281. if(RFIFOB(fd,6) != 1)
  1282. ShowError("homunculus data save failure for account %d\n", RFIFOL(fd,2));
  1283. }
  1284. /* Really? Whats the point, shouldn't be sent when successful then [Ind] */
  1285. void intif_parse_DeleteHomunculusOk(int fd) {
  1286. if(RFIFOB(fd,2) != 1)
  1287. ShowError("Homunculus data delete failure\n");
  1288. }
  1289. /**************************************
  1290. QUESTLOG SYSTEM FUNCTIONS
  1291. ***************************************/
  1292. /**
  1293. * Requests a character's quest log entries to the inter server.
  1294. *
  1295. * @param sd Character's data
  1296. */
  1297. void intif_request_questlog(struct map_session_data *sd)
  1298. {
  1299. nullpo_retv(sd);
  1300. WFIFOHEAD(inter_fd,6);
  1301. WFIFOW(inter_fd,0) = 0x3060;
  1302. WFIFOL(inter_fd,2) = sd->status.char_id;
  1303. WFIFOSET(inter_fd,6);
  1304. }
  1305. /**
  1306. * Parses the received quest log entries for a character from the inter server.
  1307. *
  1308. * Received in reply to the requests made by intif_request_questlog.
  1309. *
  1310. * @see intif_parse
  1311. */
  1312. void intif_parse_QuestLog(int fd) {
  1313. int char_id = RFIFOL(fd, 4), num_received = (RFIFOW(fd, 2)-8)/sizeof(struct quest);
  1314. struct map_session_data *sd = map->charid2sd(char_id);
  1315. if (!sd) // User not online anymore
  1316. return;
  1317. sd->num_quests = sd->avail_quests = 0;
  1318. if (num_received == 0) {
  1319. if (sd->quest_log) {
  1320. aFree(sd->quest_log);
  1321. sd->quest_log = NULL;
  1322. }
  1323. } else {
  1324. struct quest *received = (struct quest *)RFIFOP(fd, 8);
  1325. int i, k = num_received;
  1326. if (sd->quest_log) {
  1327. RECREATE(sd->quest_log, struct quest, num_received);
  1328. } else {
  1329. CREATE(sd->quest_log, struct quest, num_received);
  1330. }
  1331. for (i = 0; i < num_received; i++) {
  1332. if( quest->db(received[i].quest_id) == &quest->dummy ) {
  1333. ShowError("intif_parse_QuestLog: quest %d not found in DB.\n", received[i].quest_id);
  1334. continue;
  1335. }
  1336. if (received[i].state != Q_COMPLETE) {
  1337. // Insert at the beginning
  1338. memcpy(&sd->quest_log[sd->avail_quests++], &received[i], sizeof(struct quest));
  1339. } else {
  1340. // Insert at the end
  1341. memcpy(&sd->quest_log[--k], &received[i], sizeof(struct quest));
  1342. }
  1343. sd->num_quests++;
  1344. }
  1345. if (sd->avail_quests < k) {
  1346. // sd->avail_quests and k didn't meet in the middle: some entries were skipped
  1347. if (k < num_received) // Move the entries at the end to fill the gap
  1348. memmove(&sd->quest_log[k], &sd->quest_log[sd->avail_quests], sizeof(struct quest)*(num_received - k));
  1349. sd->quest_log = aRealloc(sd->quest_log, sizeof(struct quest)*sd->num_quests);
  1350. }
  1351. }
  1352. quest->pc_login(sd);
  1353. }
  1354. /**
  1355. * Parses the quest log save ack for a character from the inter server.
  1356. *
  1357. * Received in reply to the requests made by intif_quest_save.
  1358. *
  1359. * @see intif_parse
  1360. */
  1361. void intif_parse_QuestSave(int fd) {
  1362. int cid = RFIFOL(fd, 2);
  1363. struct map_session_data *sd = map->id2sd(cid);
  1364. if( !RFIFOB(fd, 6) )
  1365. ShowError("intif_parse_QuestSave: Failed to save quest(s) for character %d!\n", cid);
  1366. else if( sd )
  1367. sd->save_quest = false;
  1368. }
  1369. /**
  1370. * Requests to the inter server to save a character's quest log entries.
  1371. *
  1372. * @param sd Character's data
  1373. * @return 0 in case of success, nonzero otherwise
  1374. */
  1375. int intif_quest_save(struct map_session_data *sd)
  1376. {
  1377. int len = sizeof(struct quest)*sd->num_quests + 8;
  1378. if(intif->CheckForCharServer())
  1379. return 1;
  1380. WFIFOHEAD(inter_fd, len);
  1381. WFIFOW(inter_fd,0) = 0x3061;
  1382. WFIFOW(inter_fd,2) = len;
  1383. WFIFOL(inter_fd,4) = sd->status.char_id;
  1384. if( sd->num_quests )
  1385. memcpy(WFIFOP(inter_fd,8), sd->quest_log, sizeof(struct quest)*sd->num_quests);
  1386. WFIFOSET(inter_fd, len);
  1387. return 0;
  1388. }
  1389. /*==========================================
  1390. * MAIL SYSTEM
  1391. * By Zephyrus
  1392. *==========================================*/
  1393. /*------------------------------------------
  1394. * Inbox Request
  1395. * flag: 0 Update Inbox | 1 OpenMail
  1396. *------------------------------------------*/
  1397. int intif_Mail_requestinbox(int char_id, unsigned char flag)
  1398. {
  1399. if (intif->CheckForCharServer())
  1400. return 0;
  1401. WFIFOHEAD(inter_fd,7);
  1402. WFIFOW(inter_fd,0) = 0x3048;
  1403. WFIFOL(inter_fd,2) = char_id;
  1404. WFIFOB(inter_fd,6) = flag;
  1405. WFIFOSET(inter_fd,7);
  1406. return 0;
  1407. }
  1408. void intif_parse_MailInboxReceived(int fd) {
  1409. struct map_session_data *sd;
  1410. unsigned char flag = RFIFOB(fd,8);
  1411. sd = map->charid2sd(RFIFOL(fd,4));
  1412. if (sd == NULL) /** user is not online anymore and its ok (quest log also does this) **/
  1413. return;
  1414. if (RFIFOW(fd,2) - 9 != sizeof(struct mail_data)) {
  1415. ShowError("intif_parse_MailInboxReceived: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd,2) - 9, sizeof(struct mail_data));
  1416. return;
  1417. }
  1418. //FIXME: this operation is not safe [ultramage]
  1419. memcpy(&sd->mail.inbox, RFIFOP(fd,9), sizeof(struct mail_data));
  1420. sd->mail.changed = false; // cache is now in sync
  1421. if (flag)
  1422. clif->mail_refreshinbox(sd);
  1423. else if( battle_config.mail_show_status && ( battle_config.mail_show_status == 1 || sd->mail.inbox.unread ) ) {
  1424. char output[128];
  1425. sprintf(output, msg_sd(sd,510), sd->mail.inbox.unchecked, sd->mail.inbox.unread + sd->mail.inbox.unchecked);
  1426. clif_disp_onlyself(sd, output, strlen(output));
  1427. }
  1428. }
  1429. /*------------------------------------------
  1430. * Mail Read
  1431. *------------------------------------------*/
  1432. int intif_Mail_read(int mail_id)
  1433. {
  1434. if (intif->CheckForCharServer())
  1435. return 0;
  1436. WFIFOHEAD(inter_fd,6);
  1437. WFIFOW(inter_fd,0) = 0x3049;
  1438. WFIFOL(inter_fd,2) = mail_id;
  1439. WFIFOSET(inter_fd,6);
  1440. return 0;
  1441. }
  1442. /*------------------------------------------
  1443. * Get Attachment
  1444. *------------------------------------------*/
  1445. int intif_Mail_getattach(int char_id, int mail_id)
  1446. {
  1447. if (intif->CheckForCharServer())
  1448. return 0;
  1449. WFIFOHEAD(inter_fd,10);
  1450. WFIFOW(inter_fd,0) = 0x304a;
  1451. WFIFOL(inter_fd,2) = char_id;
  1452. WFIFOL(inter_fd,6) = mail_id;
  1453. WFIFOSET(inter_fd, 10);
  1454. return 0;
  1455. }
  1456. void intif_parse_MailGetAttach(int fd) {
  1457. struct map_session_data *sd;
  1458. struct item item;
  1459. int zeny = RFIFOL(fd,8);
  1460. Assert_retv(zeny >= 0);
  1461. sd = map->charid2sd( RFIFOL(fd,4) );
  1462. if (sd == NULL) {
  1463. ShowError("intif_parse_MailGetAttach: char not found %d\n",RFIFOL(fd,4));
  1464. return;
  1465. }
  1466. if (RFIFOW(fd,2) - 12 != sizeof(struct item)) {
  1467. ShowError("intif_parse_MailGetAttach: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd,2) - 16, sizeof(struct item));
  1468. return;
  1469. }
  1470. memcpy(&item, RFIFOP(fd,12), sizeof(struct item));
  1471. mail->getattachment(sd, zeny, &item);
  1472. }
  1473. /*------------------------------------------
  1474. * Delete Message
  1475. *------------------------------------------*/
  1476. int intif_Mail_delete(int char_id, int mail_id)
  1477. {
  1478. if (intif->CheckForCharServer())
  1479. return 0;
  1480. WFIFOHEAD(inter_fd,10);
  1481. WFIFOW(inter_fd,0) = 0x304b;
  1482. WFIFOL(inter_fd,2) = char_id;
  1483. WFIFOL(inter_fd,6) = mail_id;
  1484. WFIFOSET(inter_fd,10);
  1485. return 0;
  1486. }
  1487. void intif_parse_MailDelete(int fd) {
  1488. struct map_session_data *sd;
  1489. int char_id = RFIFOL(fd,2);
  1490. int mail_id = RFIFOL(fd,6);
  1491. bool failed = RFIFOB(fd,10);
  1492. if ( (sd = map->charid2sd(char_id)) == NULL) {
  1493. ShowError("intif_parse_MailDelete: char not found %d\n", char_id);
  1494. return;
  1495. }
  1496. if (!failed) {
  1497. int i;
  1498. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  1499. if( i < MAIL_MAX_INBOX ) {
  1500. memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message));
  1501. sd->mail.inbox.amount--;
  1502. }
  1503. if( sd->mail.inbox.full )
  1504. intif->Mail_requestinbox(sd->status.char_id, 1); // Free space is available for new mails
  1505. }
  1506. clif->mail_delete(sd->fd, mail_id, failed);
  1507. }
  1508. /*------------------------------------------
  1509. * Return Message
  1510. *------------------------------------------*/
  1511. int intif_Mail_return(int char_id, int mail_id)
  1512. {
  1513. if (intif->CheckForCharServer())
  1514. return 0;
  1515. WFIFOHEAD(inter_fd,10);
  1516. WFIFOW(inter_fd,0) = 0x304c;
  1517. WFIFOL(inter_fd,2) = char_id;
  1518. WFIFOL(inter_fd,6) = mail_id;
  1519. WFIFOSET(inter_fd,10);
  1520. return 0;
  1521. }
  1522. void intif_parse_MailReturn(int fd) {
  1523. struct map_session_data *sd = map->charid2sd(RFIFOL(fd,2));
  1524. int mail_id = RFIFOL(fd,6);
  1525. short fail = RFIFOB(fd,10);
  1526. if( sd == NULL ) {
  1527. ShowError("intif_parse_MailReturn: char not found %d\n",RFIFOL(fd,2));
  1528. return;
  1529. }
  1530. if( !fail ) {
  1531. int i;
  1532. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  1533. if( i < MAIL_MAX_INBOX ) {
  1534. memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message));
  1535. sd->mail.inbox.amount--;
  1536. }
  1537. if( sd->mail.inbox.full )
  1538. intif->Mail_requestinbox(sd->status.char_id, 1); // Free space is available for new mails
  1539. }
  1540. clif->mail_return(sd->fd, mail_id, fail);
  1541. }
  1542. /*---------------------------------------…

Large files files are truncated, but you can click here to view the full file