PageRenderTime 35ms CodeModel.GetById 18ms 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
  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. /*------------------------------------------
  1543. * Send Mail
  1544. *------------------------------------------*/
  1545. int intif_Mail_send(int account_id, struct mail_message *msg)
  1546. {
  1547. int len = sizeof(struct mail_message) + 8;
  1548. if (intif->CheckForCharServer())
  1549. return 0;
  1550. nullpo_ret(msg);
  1551. WFIFOHEAD(inter_fd,len);
  1552. WFIFOW(inter_fd,0) = 0x304d;
  1553. WFIFOW(inter_fd,2) = len;
  1554. WFIFOL(inter_fd,4) = account_id;
  1555. memcpy(WFIFOP(inter_fd,8), msg, sizeof(struct mail_message));
  1556. WFIFOSET(inter_fd,len);
  1557. return 1;
  1558. }
  1559. void intif_parse_MailSend(int fd) {
  1560. struct mail_message msg;
  1561. struct map_session_data *sd;
  1562. bool fail;
  1563. if( RFIFOW(fd,2) - 4 != sizeof(struct mail_message) ) {
  1564. ShowError("intif_parse_MailSend: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd,2) - 4, sizeof(struct mail_message));
  1565. return;
  1566. }
  1567. memcpy(&msg, RFIFOP(fd,4), sizeof(struct mail_message));
  1568. fail = (msg.id == 0);
  1569. // notify sender
  1570. sd = map->charid2sd(msg.send_id);
  1571. if( sd != NULL ) {
  1572. if( fail )
  1573. mail->deliveryfail(sd, &msg);
  1574. else {
  1575. clif->mail_send(sd->fd, false);
  1576. if( map->save_settings&16 )
  1577. chrif->save(sd, 0);
  1578. }
  1579. }
  1580. }
  1581. void intif_parse_MailNew(int fd) {
  1582. struct map_session_data *sd = map->charid2sd(RFIFOL(fd,2));
  1583. int mail_id = RFIFOL(fd,6);
  1584. const char* sender_name = (char*)RFIFOP(fd,10);
  1585. const char* title = (char*)RFIFOP(fd,34);
  1586. if( sd == NULL )
  1587. return;
  1588. sd->mail.changed = true;
  1589. clif->mail_new(sd->fd, mail_id, sender_name, title);
  1590. }
  1591. /*==========================================
  1592. * AUCTION SYSTEM
  1593. * By Zephyrus
  1594. *==========================================*/
  1595. int intif_Auction_requestlist(int char_id, short type, int price, const char* searchtext, short page)
  1596. {
  1597. int len = NAME_LENGTH + 16;
  1598. if( intif->CheckForCharServer() )
  1599. return 0;
  1600. nullpo_ret(searchtext);
  1601. WFIFOHEAD(inter_fd,len);
  1602. WFIFOW(inter_fd,0) = 0x3050;
  1603. WFIFOW(inter_fd,2) = len;
  1604. WFIFOL(inter_fd,4) = char_id;
  1605. WFIFOW(inter_fd,8) = type;
  1606. WFIFOL(inter_fd,10) = price;
  1607. WFIFOW(inter_fd,14) = page;
  1608. memcpy(WFIFOP(inter_fd,16), searchtext, NAME_LENGTH);
  1609. WFIFOSET(inter_fd,len);
  1610. return 0;
  1611. }
  1612. void intif_parse_AuctionResults(int fd) {
  1613. struct map_session_data *sd = map->charid2sd(RFIFOL(fd,4));
  1614. short count = RFIFOW(fd,8);
  1615. short pages = RFIFOW(fd,10);
  1616. uint8* data = RFIFOP(fd,12);
  1617. if( sd == NULL )
  1618. return;
  1619. clif->auction_results(sd, count, pages, data);
  1620. }
  1621. int intif_Auction_register(struct auction_data *auction)
  1622. {
  1623. int len = sizeof(struct auction_data) + 4;
  1624. if( intif->CheckForCharServer() )
  1625. return 0;
  1626. nullpo_ret(auction);
  1627. WFIFOHEAD(inter_fd,len);
  1628. WFIFOW(inter_fd,0) = 0x3051;
  1629. WFIFOW(inter_fd,2) = len;
  1630. memcpy(WFIFOP(inter_fd,4), auction, sizeof(struct auction_data));
  1631. WFIFOSET(inter_fd,len);
  1632. return 1;
  1633. }
  1634. void intif_parse_AuctionRegister(int fd) {
  1635. struct map_session_data *sd;
  1636. struct auction_data auction;
  1637. if (RFIFOW(fd,2) - 4 != sizeof(struct auction_data)) {
  1638. ShowError("intif_parse_AuctionRegister: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd,2) - 4, sizeof(struct auction_data));
  1639. return;
  1640. }
  1641. memcpy(&auction, RFIFOP(fd,4), sizeof(struct auction_data));
  1642. if( (sd = map->charid2sd(auction.seller_id)) == NULL )
  1643. return;
  1644. if( auction.auction_id > 0 ) {
  1645. clif->auction_message(sd->fd, 1); // Confirmation Packet ??
  1646. if( map->save_settings&32 )
  1647. chrif->save(sd,0);
  1648. } else {
  1649. int zeny = auction.hours*battle_config.auction_feeperhour;
  1650. clif->auction_message(sd->fd, 4);
  1651. pc->additem(sd, &auction.item, auction.item.amount, LOG_TYPE_AUCTION);
  1652. pc->getzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  1653. }
  1654. }
  1655. int intif_Auction_cancel(int char_id, unsigned int auction_id)
  1656. {
  1657. if( intif->CheckForCharServer() )
  1658. return 0;
  1659. WFIFOHEAD(inter_fd,10);
  1660. WFIFOW(inter_fd,0) = 0x3052;
  1661. WFIFOL(inter_fd,2) = char_id;
  1662. WFIFOL(inter_fd,6) = auction_id;
  1663. WFIFOSET(inter_fd,10);
  1664. return 0;
  1665. }
  1666. void intif_parse_AuctionCancel(int fd) {
  1667. struct map_session_data *sd = map->charid2sd(RFIFOL(fd,2));
  1668. int result = RFIFOB(fd,6);
  1669. if( sd == NULL )
  1670. return;
  1671. switch( result ) {
  1672. case 0: clif->auction_message(sd->fd, 2); break;
  1673. case 1: clif->auction_close(sd->fd, 2); break;
  1674. case 2: clif->auction_close(sd->fd, 1); break;
  1675. case 3: clif->auction_message(sd->fd, 3); break;
  1676. }
  1677. }
  1678. int intif_Auction_close(int char_id, unsigned int auction_id)
  1679. {
  1680. if( intif->CheckForCharServer() )
  1681. return 0;
  1682. WFIFOHEAD(inter_fd,10);
  1683. WFIFOW(inter_fd,0) = 0x3053;
  1684. WFIFOL(inter_fd,2) = char_id;
  1685. WFIFOL(inter_fd,6) = auction_id;
  1686. WFIFOSET(inter_fd,10);
  1687. return 0;
  1688. }
  1689. void intif_parse_AuctionClose(int fd) {
  1690. struct map_session_data *sd = map->charid2sd(RFIFOL(fd,2));
  1691. unsigned char result = RFIFOB(fd,6);
  1692. if( sd == NULL )
  1693. return;
  1694. clif->auction_close(sd->fd, result);
  1695. if( result == 0 ) {
  1696. // FIXME: Leeching off a parse function
  1697. clif->pAuction_cancelreg(fd, sd);
  1698. intif->Auction_requestlist(sd->status.char_id, 6, 0, "", 1);
  1699. }
  1700. }
  1701. int intif_Auction_bid(int char_id, const char* name, unsigned int auction_id, int bid)
  1702. {
  1703. int len = 16 + NAME_LENGTH;
  1704. if( intif->CheckForCharServer() )
  1705. return 0;
  1706. nullpo_ret(name);
  1707. WFIFOHEAD(inter_fd,len);
  1708. WFIFOW(inter_fd,0) = 0x3055;
  1709. WFIFOW(inter_fd,2) = len;
  1710. WFIFOL(inter_fd,4) = char_id;
  1711. WFIFOL(inter_fd,8) = auction_id;
  1712. WFIFOL(inter_fd,12) = bid;
  1713. memcpy(WFIFOP(inter_fd,16), name, NAME_LENGTH);
  1714. WFIFOSET(inter_fd,len);
  1715. return 0;
  1716. }
  1717. void intif_parse_AuctionBid(int fd) {
  1718. struct map_session_data *sd = map->charid2sd(RFIFOL(fd,2));
  1719. int bid = RFIFOL(fd,6);
  1720. unsigned char result = RFIFOB(fd,10);
  1721. if( sd == NULL )
  1722. return;
  1723. clif->auction_message(sd->fd, result);
  1724. if( bid > 0 ) {
  1725. pc->getzeny(sd, bid, LOG_TYPE_AUCTION,NULL);
  1726. }
  1727. if( result == 1 ) { // To update the list, display your buy list
  1728. clif->pAuction_cancelreg(fd, sd);
  1729. intif->Auction_requestlist(sd->status.char_id, 7, 0, "", 1);
  1730. }
  1731. }
  1732. // Used to send 'You have won the auction' and 'You failed to won the auction' messages
  1733. void intif_parse_AuctionMessage(int fd) {
  1734. struct map_session_data *sd = map->charid2sd(RFIFOL(fd,2));
  1735. unsigned char result = RFIFOB(fd,6);
  1736. if( sd == NULL )
  1737. return;
  1738. clif->auction_message(sd->fd, result);
  1739. }
  1740. /*==========================================
  1741. * Mercenary's System
  1742. *------------------------------------------*/
  1743. int intif_mercenary_create(struct s_mercenary *merc)
  1744. {
  1745. int size = sizeof(struct s_mercenary) + 4;
  1746. if( intif->CheckForCharServer() )
  1747. return 0;
  1748. nullpo_ret(merc);
  1749. WFIFOHEAD(inter_fd,size);
  1750. WFIFOW(inter_fd,0) = 0x3070;
  1751. WFIFOW(inter_fd,2) = size;
  1752. memcpy(WFIFOP(inter_fd,4), merc, sizeof(struct s_mercenary));
  1753. WFIFOSET(inter_fd,size);
  1754. return 0;
  1755. }
  1756. void intif_parse_MercenaryReceived(int fd) {
  1757. int len = RFIFOW(fd,2) - 5;
  1758. if (sizeof(struct s_mercenary) != len) {
  1759. if (battle_config.etc_log)
  1760. ShowError("intif: create mercenary data size mismatch %d != %"PRIuS"\n", len, sizeof(struct s_mercenary));
  1761. return;
  1762. }
  1763. mercenary->data_received((struct s_mercenary*)RFIFOP(fd,5), RFIFOB(fd,4));
  1764. }
  1765. int intif_mercenary_request(int merc_id, int char_id)
  1766. {
  1767. if (intif->CheckForCharServer())
  1768. return 0;
  1769. WFIFOHEAD(inter_fd,10);
  1770. WFIFOW(inter_fd,0) = 0x3071;
  1771. WFIFOL(inter_fd,2) = merc_id;
  1772. WFIFOL(inter_fd,6) = char_id;
  1773. WFIFOSET(inter_fd,10);
  1774. return 0;
  1775. }
  1776. int intif_mercenary_delete(int merc_id)
  1777. {
  1778. if (intif->CheckForCharServer())
  1779. return 0;
  1780. WFIFOHEAD(inter_fd,6);
  1781. WFIFOW(inter_fd,0) = 0x3072;
  1782. WFIFOL(inter_fd,2) = merc_id;
  1783. WFIFOSET(inter_fd,6);
  1784. return 0;
  1785. }
  1786. /* Really? Whats the point, shouldn't be sent when successful then [Ind] */
  1787. void intif_parse_MercenaryDeleted(int fd) {
  1788. if( RFIFOB(fd,2) != 1 )
  1789. ShowError("Mercenary data delete failure\n");
  1790. }
  1791. int intif_mercenary_save(struct s_mercenary *merc)
  1792. {
  1793. int size = sizeof(struct s_mercenary) + 4;
  1794. if( intif->CheckForCharServer() )
  1795. return 0;
  1796. nullpo_ret(merc);
  1797. WFIFOHEAD(inter_fd,size);
  1798. WFIFOW(inter_fd,0) = 0x3073;
  1799. WFIFOW(inter_fd,2) = size;
  1800. memcpy(WFIFOP(inter_fd,4), merc, sizeof(struct s_mercenary));
  1801. WFIFOSET(inter_fd,size);
  1802. return 0;
  1803. }
  1804. /* Really? Whats the point, shouldn't be sent when successful then [Ind] */
  1805. void intif_parse_MercenarySaved(int fd) {
  1806. if( RFIFOB(fd,2) != 1 )
  1807. ShowError("Mercenary data save failure\n");
  1808. }
  1809. /*==========================================
  1810. * Elemental's System
  1811. *------------------------------------------*/
  1812. int intif_elemental_create(struct s_elemental *ele)
  1813. {
  1814. int size = sizeof(struct s_elemental) + 4;
  1815. if( intif->CheckForCharServer() )
  1816. return 0;
  1817. nullpo_ret(ele);
  1818. WFIFOHEAD(inter_fd,size);
  1819. WFIFOW(inter_fd,0) = 0x307c;
  1820. WFIFOW(inter_fd,2) = size;
  1821. memcpy(WFIFOP(inter_fd,4), ele, sizeof(struct s_elemental));
  1822. WFIFOSET(inter_fd,size);
  1823. return 0;
  1824. }
  1825. void intif_parse_ElementalReceived(int fd) {
  1826. int len = RFIFOW(fd,2) - 5;
  1827. if (sizeof(struct s_elemental) != len) {
  1828. if (battle_config.etc_log)
  1829. ShowError("intif: create elemental data size mismatch %d != %"PRIuS"\n", len, sizeof(struct s_elemental));
  1830. return;
  1831. }
  1832. elemental->data_received((struct s_elemental*)RFIFOP(fd,5), RFIFOB(fd,4));
  1833. }
  1834. int intif_elemental_request(int ele_id, int char_id)
  1835. {
  1836. if (intif->CheckForCharServer())
  1837. return 0;
  1838. WFIFOHEAD(inter_fd,10);
  1839. WFIFOW(inter_fd,0) = 0x307d;
  1840. WFIFOL(inter_fd,2) = ele_id;
  1841. WFIFOL(inter_fd,6) = char_id;
  1842. WFIFOSET(inter_fd,10);
  1843. return 0;
  1844. }
  1845. int intif_elemental_delete(int ele_id)
  1846. {
  1847. if (intif->CheckForCharServer())
  1848. return 0;
  1849. WFIFOHEAD(inter_fd,6);
  1850. WFIFOW(inter_fd,0) = 0x307e;
  1851. WFIFOL(inter_fd,2) = ele_id;
  1852. WFIFOSET(inter_fd,6);
  1853. return 0;
  1854. }
  1855. /* Really? Whats the point, shouldn't be sent when successful then [Ind] */
  1856. void intif_parse_ElementalDeleted(int fd) {
  1857. if( RFIFOB(fd,2) != 1 )
  1858. ShowError("Elemental data delete failure\n");
  1859. }
  1860. int intif_elemental_save(struct s_elemental *ele)
  1861. {
  1862. int size = sizeof(struct s_elemental) + 4;
  1863. if( intif->CheckForCharServer() )
  1864. return 0;
  1865. nullpo_ret(ele);
  1866. WFIFOHEAD(inter_fd,size);
  1867. WFIFOW(inter_fd,0) = 0x307f;
  1868. WFIFOW(inter_fd,2) = size;
  1869. memcpy(WFIFOP(inter_fd,4), ele, sizeof(struct s_elemental));
  1870. WFIFOSET(inter_fd,size);
  1871. return 0;
  1872. }
  1873. /* Really? Whats the point, shouldn't be sent when successful then [Ind] */
  1874. void intif_parse_ElementalSaved(int fd) {
  1875. if( RFIFOB(fd,2) != 1 )
  1876. ShowError("Elemental data save failure\n");
  1877. }
  1878. void intif_request_accinfo( int u_fd, int aid, int group_lv, char* query ) {
  1879. nullpo_retv(query);
  1880. WFIFOHEAD(inter_fd,2 + 4 + 4 + 4 + NAME_LENGTH);
  1881. WFIFOW(inter_fd,0) = 0x3007;
  1882. WFIFOL(inter_fd,2) = u_fd;
  1883. WFIFOL(inter_fd,6) = aid;
  1884. WFIFOL(inter_fd,10) = group_lv;
  1885. safestrncpy((char *)WFIFOP(inter_fd,14), query, NAME_LENGTH);
  1886. WFIFOSET(inter_fd,2 + 4 + 4 + 4 + NAME_LENGTH);
  1887. return;
  1888. }
  1889. void intif_parse_MessageToFD(int fd) {
  1890. int u_fd = RFIFOL(fd,4);
  1891. Assert_retv(sockt->session_is_valid(u_fd));
  1892. if( sockt->session[u_fd] && sockt->session[u_fd]->session_data ) {
  1893. int aid = RFIFOL(fd,8);
  1894. struct map_session_data * sd = sockt->session[u_fd]->session_data;
  1895. /* matching e.g. previous fd owner didn't dc during request or is still the same */
  1896. if( sd && sd->bl.id == aid ) {
  1897. char msg[512];
  1898. safestrncpy(msg, (char*)RFIFOP(fd,12), RFIFOW(fd,2) - 12);
  1899. clif->messagecolor_self(u_fd, COLOR_DEFAULT ,msg);
  1900. }
  1901. }
  1902. return;
  1903. }
  1904. /*==========================================
  1905. * Item Bound System [Xantara][Mhalicot]
  1906. *------------------------------------------*/
  1907. void intif_itembound_req(int char_id,int aid,int guild_id) {
  1908. #ifdef GP_BOUND_ITEMS
  1909. struct guild_storage *gstor = idb_get(gstorage->db,guild_id);
  1910. WFIFOHEAD(inter_fd,12);
  1911. WFIFOW(inter_fd,0) = 0x3056;
  1912. WFIFOL(inter_fd,2) = char_id;
  1913. WFIFOL(inter_fd,6) = aid;
  1914. WFIFOW(inter_fd,10) = guild_id;
  1915. WFIFOSET(inter_fd,12);
  1916. if(gstor)
  1917. gstor->lock = 1; //Lock for retrieval process
  1918. #endif
  1919. }
  1920. //3856
  1921. void intif_parse_Itembound_ack(int fd) {
  1922. #ifdef GP_BOUND_ITEMS
  1923. struct guild_storage *gstor;
  1924. int guild_id = RFIFOW(fd,6);
  1925. gstor = idb_get(gstorage->db,guild_id);
  1926. if(gstor)
  1927. gstor->lock = 0; //Unlock now that operation is completed
  1928. #endif
  1929. }
  1930. //-----------------------------------------------------------------
  1931. // Communication from the inter server
  1932. // Return a 0 (false) if there were any errors.
  1933. // 1, 2 if there are not enough to return the length of the packet if the packet processing
  1934. int intif_parse(int fd)
  1935. {
  1936. int packet_len, cmd;
  1937. cmd = RFIFOW(fd,0);
  1938. // Verify ID of the packet
  1939. if (cmd < 0x3800 || cmd >= 0x3800+(sizeof(intif->packet_len_table)/sizeof(intif->packet_len_table[0]))
  1940. || intif->packet_len_table[cmd-0x3800] == 0
  1941. ) {
  1942. return 0;
  1943. }
  1944. // Check the length of the packet
  1945. packet_len = intif->packet_len_table[cmd-0x3800];
  1946. if(packet_len==-1){
  1947. if(RFIFOREST(fd)<4)
  1948. return 2;
  1949. packet_len = RFIFOW(fd,2);
  1950. }
  1951. if((int)RFIFOREST(fd)<packet_len){
  1952. return 2;
  1953. }
  1954. // Processing branch
  1955. switch(cmd){
  1956. case 0x3800:
  1957. if (RFIFOL(fd,4) == 0xFF000000) //Normal announce.
  1958. clif->broadcast(NULL, (char *) RFIFOP(fd,16), packet_len-16, BC_DEFAULT, ALL_CLIENT);
  1959. else //Color announce.
  1960. clif->broadcast2(NULL, (char *) RFIFOP(fd,16), packet_len-16, RFIFOL(fd,4), RFIFOW(fd,8), RFIFOW(fd,10), RFIFOW(fd,12), RFIFOW(fd,14), ALL_CLIENT);
  1961. break;
  1962. case 0x3801: intif->pWisMessage(fd); break;
  1963. case 0x3802: intif->pWisEnd(fd); break;
  1964. case 0x3803: intif->pWisToGM(fd); break;
  1965. case 0x3804: intif->pRegisters(fd); break;
  1966. case 0x3806: intif->pChangeNameOk(fd); break;
  1967. case 0x3807: intif->pMessageToFD(fd); break;
  1968. case 0x3818: intif->pLoadGuildStorage(fd); break;
  1969. case 0x3819: intif->pSaveGuildStorage(fd); break;
  1970. case 0x3820: intif->pPartyCreated(fd); break;
  1971. case 0x3821: intif->pPartyInfo(fd); break;
  1972. case 0x3822: intif->pPartyMemberAdded(fd); break;
  1973. case 0x3823: intif->pPartyOptionChanged(fd); break;
  1974. case 0x3824: intif->pPartyMemberWithdraw(fd); break;
  1975. case 0x3825: intif->pPartyMove(fd); break;
  1976. case 0x3826: intif->pPartyBroken(fd); break;
  1977. case 0x3827: intif->pPartyMessage(fd); break;
  1978. case 0x3830: intif->pGuildCreated(fd); break;
  1979. case 0x3831: intif->pGuildInfo(fd); break;
  1980. case 0x3832: intif->pGuildMemberAdded(fd); break;
  1981. case 0x3834: intif->pGuildMemberWithdraw(fd); break;
  1982. case 0x3835: intif->pGuildMemberInfoShort(fd); break;
  1983. case 0x3836: intif->pGuildBroken(fd); break;
  1984. case 0x3837: intif->pGuildMessage(fd); break;
  1985. case 0x3839: intif->pGuildBasicInfoChanged(fd); break;
  1986. case 0x383a: intif->pGuildMemberInfoChanged(fd); break;
  1987. case 0x383b: intif->pGuildPosition(fd); break;
  1988. case 0x383c: intif->pGuildSkillUp(fd); break;
  1989. case 0x383d: intif->pGuildAlliance(fd); break;
  1990. case 0x383e: intif->pGuildNotice(fd); break;
  1991. case 0x383f: intif->pGuildEmblem(fd); break;
  1992. case 0x3840: intif->pGuildCastleDataLoad(fd); break;
  1993. case 0x3843: intif->pGuildMasterChanged(fd); break;
  1994. //Quest system
  1995. case 0x3860: intif->pQuestLog(fd); break;
  1996. case 0x3861: intif->pQuestSave(fd); break;
  1997. // Mail System
  1998. case 0x3848: intif->pMailInboxReceived(fd); break;
  1999. case 0x3849: intif->pMailNew(fd); break;
  2000. case 0x384a: intif->pMailGetAttach(fd); break;
  2001. case 0x384b: intif->pMailDelete(fd); break;
  2002. case 0x384c: intif->pMailReturn(fd); break;
  2003. case 0x384d: intif->pMailSend(fd); break;
  2004. // Auction System
  2005. case 0x3850: intif->pAuctionResults(fd); break;
  2006. case 0x3851: intif->pAuctionRegister(fd); break;
  2007. case 0x3852: intif->pAuctionCancel(fd); break;
  2008. case 0x3853: intif->pAuctionClose(fd); break;
  2009. case 0x3854: intif->pAuctionMessage(fd); break;
  2010. case 0x3855: intif->pAuctionBid(fd); break;
  2011. //Bound items
  2012. case 0x3856:
  2013. #ifdef GP_BOUND_ITEMS
  2014. intif->pItembound_ack(fd);
  2015. #else
  2016. ShowWarning("intif_parse: Received 0x3856 with GP_BOUND_ITEMS disabled !!!\n");
  2017. #endif
  2018. break;
  2019. // Mercenary System
  2020. case 0x3870: intif->pMercenaryReceived(fd); break;
  2021. case 0x3871: intif->pMercenaryDeleted(fd); break;
  2022. case 0x3872: intif->pMercenarySaved(fd); break;
  2023. // Elemental System
  2024. case 0x387c: intif->pElementalReceived(fd); break;
  2025. case 0x387d: intif->pElementalDeleted(fd); break;
  2026. case 0x387e: intif->pElementalSaved(fd); break;
  2027. case 0x3880: intif->pCreatePet(fd); break;
  2028. case 0x3881: intif->pRecvPetData(fd); break;
  2029. case 0x3882: intif->pSavePetOk(fd); break;
  2030. case 0x3883: intif->pDeletePetOk(fd); break;
  2031. case 0x3890: intif->pCreateHomunculus(fd); break;
  2032. case 0x3891: intif->pRecvHomunculusData(fd); break;
  2033. case 0x3892: intif->pSaveHomunculusOk(fd); break;
  2034. case 0x3893: intif->pDeleteHomunculusOk(fd); break;
  2035. default:
  2036. ShowError("intif_parse : unknown packet %d %x\n",fd,RFIFOW(fd,0));
  2037. return 0;
  2038. }
  2039. // Skip packet
  2040. RFIFOSKIP(fd,packet_len);
  2041. return 1;
  2042. }
  2043. /*=====================================
  2044. * Default Functions : intif.h
  2045. * Generated by HerculesInterfaceMaker
  2046. * created by Susu
  2047. *-------------------------------------*/
  2048. void intif_defaults(void) {
  2049. const int packet_len_table [INTIF_PACKET_LEN_TABLE_SIZE] = {
  2050. -1,-1,27,-1, -1, 0,37,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3800-0x380f
  2051. 0, 0, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810
  2052. 39,-1,15,15, 14,19, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3820
  2053. 10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830
  2054. -1, 0, 0,14, 0, 0, 0, 0, -1,74,-1,11, 11,-1, 0, 0, //0x3840
  2055. -1,-1, 7, 7, 7,11, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus] itembound[Akinari]
  2056. -1, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin] [Inkfish]
  2057. -1, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 3, 3, 0, //0x3870 Mercenaries [Zephyrus] / Elemental [pakpil]
  2058. 12,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3880
  2059. -1,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3890 Homunculus [albator]
  2060. };
  2061. intif = &intif_s;
  2062. /* */
  2063. memcpy(intif->packet_len_table,&packet_len_table,sizeof(intif->packet_len_table));
  2064. /* funcs */
  2065. intif->parse = intif_parse;
  2066. intif->create_pet = intif_create_pet;
  2067. intif->broadcast = intif_broadcast;
  2068. intif->broadcast2 = intif_broadcast2;
  2069. intif->main_message = intif_main_message;
  2070. intif->wis_message = intif_wis_message;
  2071. intif->wis_message_to_gm = intif_wis_message_to_gm;
  2072. intif->saveregistry = intif_saveregistry;
  2073. intif->request_registry = intif_request_registry;
  2074. intif->request_guild_storage = intif_request_guild_storage;
  2075. intif->send_guild_storage = intif_send_guild_storage;
  2076. intif->create_party = intif_create_party;
  2077. intif->request_partyinfo = intif_request_partyinfo;
  2078. intif->party_addmember = intif_party_addmember;
  2079. intif->party_changeoption = intif_party_changeoption;
  2080. intif->party_leave = intif_party_leave;
  2081. intif->party_changemap = intif_party_changemap;
  2082. intif->break_party = intif_break_party;
  2083. intif->party_message = intif_party_message;
  2084. intif->party_leaderchange = intif_party_leaderchange;
  2085. intif->guild_create = intif_guild_create;
  2086. intif->guild_request_info = intif_guild_request_info;
  2087. intif->guild_addmember = intif_guild_addmember;
  2088. intif->guild_leave = intif_guild_leave;
  2089. intif->guild_memberinfoshort = intif_guild_memberinfoshort;
  2090. intif->guild_break = intif_guild_break;
  2091. intif->guild_message = intif_guild_message;
  2092. intif->guild_change_gm = intif_guild_change_gm;
  2093. intif->guild_change_basicinfo = intif_guild_change_basicinfo;
  2094. intif->guild_change_memberinfo = intif_guild_change_memberinfo;
  2095. intif->guild_position = intif_guild_position;
  2096. intif->guild_skillup = intif_guild_skillup;
  2097. intif->guild_alliance = intif_guild_alliance;
  2098. intif->guild_notice = intif_guild_notice;
  2099. intif->guild_emblem = intif_guild_emblem;
  2100. intif->guild_castle_dataload = intif_guild_castle_dataload;
  2101. intif->guild_castle_datasave = intif_guild_castle_datasave;
  2102. intif->request_petdata = intif_request_petdata;
  2103. intif->save_petdata = intif_save_petdata;
  2104. intif->delete_petdata = intif_delete_petdata;
  2105. intif->rename = intif_rename;
  2106. intif->homunculus_create = intif_homunculus_create;
  2107. intif->homunculus_requestload = intif_homunculus_requestload;
  2108. intif->homunculus_requestsave = intif_homunculus_requestsave;
  2109. intif->homunculus_requestdelete = intif_homunculus_requestdelete;
  2110. /******QUEST SYTEM*******/
  2111. intif->request_questlog = intif_request_questlog;
  2112. intif->quest_save = intif_quest_save;
  2113. // MERCENARY SYSTEM
  2114. intif->mercenary_create = intif_mercenary_create;
  2115. intif->mercenary_request = intif_mercenary_request;
  2116. intif->mercenary_delete = intif_mercenary_delete;
  2117. intif->mercenary_save = intif_mercenary_save;
  2118. // MAIL SYSTEM
  2119. intif->Mail_requestinbox = intif_Mail_requestinbox;
  2120. intif->Mail_read = intif_Mail_read;
  2121. intif->Mail_getattach = intif_Mail_getattach;
  2122. intif->Mail_delete = intif_Mail_delete;
  2123. intif->Mail_return = intif_Mail_return;
  2124. intif->Mail_send = intif_Mail_send;
  2125. // AUCTION SYSTEM
  2126. intif->Auction_requestlist = intif_Auction_requestlist;
  2127. intif->Auction_register = intif_Auction_register;
  2128. intif->Auction_cancel = intif_Auction_cancel;
  2129. intif->Auction_close = intif_Auction_close;
  2130. intif->Auction_bid = intif_Auction_bid;
  2131. // ELEMENTAL SYSTEM
  2132. intif->elemental_create = intif_elemental_create;
  2133. intif->elemental_request = intif_elemental_request;
  2134. intif->elemental_delete = intif_elemental_delete;
  2135. intif->elemental_save = intif_elemental_save;
  2136. /* @accinfo */
  2137. intif->request_accinfo = intif_request_accinfo;
  2138. /* */
  2139. intif->CheckForCharServer = CheckForCharServer;
  2140. /* */
  2141. intif->itembound_req = intif_itembound_req;
  2142. /* parse functions */
  2143. intif->pWisMessage = intif_parse_WisMessage;
  2144. intif->pWisEnd = intif_parse_WisEnd;
  2145. intif->pWisToGM_sub = mapif_parse_WisToGM_sub;
  2146. intif->pWisToGM = mapif_parse_WisToGM;
  2147. intif->pRegisters = intif_parse_Registers;
  2148. intif->pChangeNameOk = intif_parse_ChangeNameOk;
  2149. intif->pMessageToFD = intif_parse_MessageToFD;
  2150. intif->pLoadGuildStorage = intif_parse_LoadGuildStorage;
  2151. intif->pSaveGuildStorage = intif_parse_SaveGuildStorage;
  2152. intif->pPartyCreated = intif_parse_PartyCreated;
  2153. intif->pPartyInfo = intif_parse_PartyInfo;
  2154. intif->pPartyMemberAdded = intif_parse_PartyMemberAdded;
  2155. intif->pPartyOptionChanged = intif_parse_PartyOptionChanged;
  2156. intif->pPartyMemberWithdraw = intif_parse_PartyMemberWithdraw;
  2157. intif->pPartyMove = intif_parse_PartyMove;
  2158. intif->pPartyBroken = intif_parse_PartyBroken;
  2159. intif->pPartyMessage = intif_parse_PartyMessage;
  2160. intif->pGuildCreated = intif_parse_GuildCreated;
  2161. intif->pGuildInfo = intif_parse_GuildInfo;
  2162. intif->pGuildMemberAdded = intif_parse_GuildMemberAdded;
  2163. intif->pGuildMemberWithdraw = intif_parse_GuildMemberWithdraw;
  2164. intif->pGuildMemberInfoShort = intif_parse_GuildMemberInfoShort;
  2165. intif->pGuildBroken = intif_parse_GuildBroken;
  2166. intif->pGuildMessage = intif_parse_GuildMessage;
  2167. intif->pGuildBasicInfoChanged = intif_parse_GuildBasicInfoChanged;
  2168. intif->pGuildMemberInfoChanged = intif_parse_GuildMemberInfoChanged;
  2169. intif->pGuildPosition = intif_parse_GuildPosition;
  2170. intif->pGuildSkillUp = intif_parse_GuildSkillUp;
  2171. intif->pGuildAlliance = intif_parse_GuildAlliance;
  2172. intif->pGuildNotice = intif_parse_GuildNotice;
  2173. intif->pGuildEmblem = intif_parse_GuildEmblem;
  2174. intif->pGuildCastleDataLoad = intif_parse_GuildCastleDataLoad;
  2175. intif->pGuildMasterChanged = intif_parse_GuildMasterChanged;
  2176. intif->pQuestLog = intif_parse_QuestLog;
  2177. intif->pQuestSave = intif_parse_QuestSave;
  2178. intif->pMailInboxReceived = intif_parse_MailInboxReceived;
  2179. intif->pMailNew = intif_parse_MailNew;
  2180. intif->pMailGetAttach = intif_parse_MailGetAttach;
  2181. intif->pMailDelete = intif_parse_MailDelete;
  2182. intif->pMailReturn = intif_parse_MailReturn;
  2183. intif->pMailSend = intif_parse_MailSend;
  2184. intif->pAuctionResults = intif_parse_AuctionResults;
  2185. intif->pAuctionRegister = intif_parse_AuctionRegister;
  2186. intif->pAuctionCancel = intif_parse_AuctionCancel;
  2187. intif->pAuctionClose = intif_parse_AuctionClose;
  2188. intif->pAuctionMessage = intif_parse_AuctionMessage;
  2189. intif->pAuctionBid = intif_parse_AuctionBid;
  2190. intif->pItembound_ack = intif_parse_Itembound_ack;
  2191. intif->pMercenaryReceived = intif_parse_MercenaryReceived;
  2192. intif->pMercenaryDeleted = intif_parse_MercenaryDeleted;
  2193. intif->pMercenarySaved = intif_parse_MercenarySaved;
  2194. intif->pElementalReceived = intif_parse_ElementalReceived;
  2195. intif->pElementalDeleted = intif_parse_ElementalDeleted;
  2196. intif->pElementalSaved = intif_parse_ElementalSaved;
  2197. intif->pCreatePet = intif_parse_CreatePet;
  2198. intif->pRecvPetData = intif_parse_RecvPetData;
  2199. intif->pSavePetOk = intif_parse_SavePetOk;
  2200. intif->pDeletePetOk = intif_parse_DeletePetOk;
  2201. intif->pCreateHomunculus = intif_parse_CreateHomunculus;
  2202. intif->pRecvHomunculusData = intif_parse_RecvHomunculusData;
  2203. intif->pSaveHomunculusOk = intif_parse_SaveHomunculusOk;
  2204. intif->pDeleteHomunculusOk = intif_parse_DeleteHomunculusOk;
  2205. }