intif.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/showmsg.h"
  4. #include "../common/socket.h"
  5. #include "../common/timer.h"
  6. #include "../common/nullpo.h"
  7. #include "../common/malloc.h"
  8. #include "../common/strlib.h"
  9. #include "map.h"
  10. #include "battle.h"
  11. #include "chrif.h"
  12. #include "clif.h"
  13. #include "pc.h"
  14. #include "intif.h"
  15. #include "storage.h"
  16. #include "party.h"
  17. #include "guild.h"
  18. #include "pet.h"
  19. #include "atcommand.h"
  20. #include "mercenary.h" //albator
  21. #include "mail.h"
  22. #include <sys/types.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <signal.h>
  26. #include <fcntl.h>
  27. #include <string.h>
  28. static const int packet_len_table[]={
  29. -1,-1,27,-1, -1, 0,37, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3800-0x380f
  30. -1, 7, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810
  31. 39,-1,15,15, 14,19, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3820
  32. 10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830
  33. 9, 9,-1,14, 0, 0, 0, 0, -1,74,-1,11, 11,-1, 0, 0, //0x3840
  34. -1,-1, 7, 7, 7,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus]
  35. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  36. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  37. 11,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3880
  38. -1,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3890 Homunculus [albator]
  39. };
  40. extern int char_fd; // inter serverのfdはchar_fdを使う
  41. #define inter_fd char_fd // エイリアス
  42. //-----------------------------------------------------------------
  43. // inter serverへの送信
  44. int CheckForCharServer(void)
  45. {
  46. return ((char_fd <= 0) || session[char_fd] == NULL || session[char_fd]->wdata == NULL);
  47. }
  48. // pet
  49. int intif_create_pet(int account_id,int char_id,short pet_class,short pet_lv,short pet_egg_id,
  50. short pet_equip,short intimate,short hungry,char rename_flag,char incuvate,char *pet_name)
  51. {
  52. if (CheckForCharServer())
  53. return 0;
  54. WFIFOHEAD(inter_fd, 24 + NAME_LENGTH);
  55. WFIFOW(inter_fd,0) = 0x3080;
  56. WFIFOL(inter_fd,2) = account_id;
  57. WFIFOL(inter_fd,6) = char_id;
  58. WFIFOW(inter_fd,10) = pet_class;
  59. WFIFOW(inter_fd,12) = pet_lv;
  60. WFIFOW(inter_fd,14) = pet_egg_id;
  61. WFIFOW(inter_fd,16) = pet_equip;
  62. WFIFOW(inter_fd,18) = intimate;
  63. WFIFOW(inter_fd,20) = hungry;
  64. WFIFOB(inter_fd,22) = rename_flag;
  65. WFIFOB(inter_fd,23) = incuvate;
  66. memcpy(WFIFOP(inter_fd,24),pet_name,NAME_LENGTH);
  67. WFIFOSET(inter_fd,24+NAME_LENGTH);
  68. return 0;
  69. }
  70. int intif_request_petdata(int account_id,int char_id,int pet_id)
  71. {
  72. if (CheckForCharServer())
  73. return 0;
  74. WFIFOHEAD(inter_fd, 14);
  75. WFIFOW(inter_fd,0) = 0x3081;
  76. WFIFOL(inter_fd,2) = account_id;
  77. WFIFOL(inter_fd,6) = char_id;
  78. WFIFOL(inter_fd,10) = pet_id;
  79. WFIFOSET(inter_fd,14);
  80. return 0;
  81. }
  82. int intif_save_petdata(int account_id,struct s_pet *p)
  83. {
  84. if (CheckForCharServer())
  85. return 0;
  86. WFIFOHEAD(inter_fd, sizeof(struct s_pet) + 8);
  87. WFIFOW(inter_fd,0) = 0x3082;
  88. WFIFOW(inter_fd,2) = sizeof(struct s_pet) + 8;
  89. WFIFOL(inter_fd,4) = account_id;
  90. memcpy(WFIFOP(inter_fd,8),p,sizeof(struct s_pet));
  91. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  92. return 0;
  93. }
  94. int intif_delete_petdata(int pet_id)
  95. {
  96. if (CheckForCharServer())
  97. return 0;
  98. WFIFOHEAD(inter_fd,6);
  99. WFIFOW(inter_fd,0) = 0x3083;
  100. WFIFOL(inter_fd,2) = pet_id;
  101. WFIFOSET(inter_fd,6);
  102. return 1;
  103. }
  104. int intif_rename(struct map_session_data *sd, int type, char *name)
  105. {
  106. if (CheckForCharServer())
  107. return 1;
  108. WFIFOHEAD(inter_fd,NAME_LENGTH+12);
  109. WFIFOW(inter_fd,0) = 0x3006;
  110. WFIFOL(inter_fd,2) = sd->status.account_id;
  111. WFIFOL(inter_fd,6) = sd->status.char_id;
  112. WFIFOB(inter_fd,10) = type; //Type: 0 - PC, 1 - PET, 2 - HOM
  113. memcpy(WFIFOP(inter_fd,11),name, NAME_LENGTH);
  114. WFIFOSET(inter_fd,NAME_LENGTH+12);
  115. return 0;
  116. }
  117. // GMメッセージを送信
  118. int intif_GMmessage(const char* mes,int len,int flag)
  119. {
  120. int lp = (flag&0x10) ? 8 : 4;
  121. // Send to the local players
  122. clif_GMmessage(NULL, mes, len, flag);
  123. if (CheckForCharServer())
  124. return 0;
  125. if (other_mapserver_count < 1)
  126. return 0; //No need to send.
  127. WFIFOHEAD(inter_fd,lp + len + 4);
  128. WFIFOW(inter_fd,0) = 0x3000;
  129. WFIFOW(inter_fd,2) = lp + len + 4;
  130. WFIFOL(inter_fd,4) = 0xFF000000; //"invalid" color signals standard broadcast.
  131. WFIFOL(inter_fd,8) = 0x65756c62;
  132. memcpy(WFIFOP(inter_fd,4+lp), mes, len);
  133. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  134. return 0;
  135. }
  136. int intif_announce(const char* mes,int len, unsigned long color, int flag)
  137. {
  138. // Send to the local players
  139. if(color == 0xFE000000) // This is main chat message [LuzZza]
  140. clif_MainChatMessage(mes);
  141. else
  142. clif_announce(NULL, mes, len, color, flag);
  143. if (CheckForCharServer())
  144. return 0;
  145. if (other_mapserver_count < 1)
  146. return 0; //No need to send.
  147. WFIFOHEAD(inter_fd, 8 + len);
  148. WFIFOW(inter_fd,0) = 0x3000;
  149. WFIFOW(inter_fd,2) = 8 + len;
  150. WFIFOL(inter_fd,4) = color;
  151. memcpy(WFIFOP(inter_fd,8), mes, len);
  152. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  153. return 0;
  154. }
  155. // The transmission of Wisp/Page to inter-server (player not found on this server)
  156. int intif_wis_message(struct map_session_data *sd, char *nick, char *mes, int mes_len)
  157. {
  158. nullpo_retr(0, sd);
  159. if (CheckForCharServer())
  160. return 0;
  161. if (other_mapserver_count < 1)
  162. { //Character not found.
  163. clif_wis_end(sd->fd, 1);
  164. return 0;
  165. }
  166. WFIFOHEAD(inter_fd,mes_len + 52);
  167. WFIFOW(inter_fd,0) = 0x3001;
  168. WFIFOW(inter_fd,2) = mes_len + 52;
  169. memcpy(WFIFOP(inter_fd,4), sd->status.name, NAME_LENGTH);
  170. memcpy(WFIFOP(inter_fd,4+NAME_LENGTH), nick, NAME_LENGTH);
  171. memcpy(WFIFOP(inter_fd,4+2*NAME_LENGTH), mes, mes_len);
  172. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  173. if (battle_config.etc_log)
  174. ShowInfo("intif_wis_message from %s to %s (message: '%s')\n", sd->status.name, nick, mes);
  175. return 0;
  176. }
  177. // The reply of Wisp/page
  178. int intif_wis_replay(int id, int flag)
  179. {
  180. if (CheckForCharServer())
  181. return 0;
  182. WFIFOHEAD(inter_fd,7);
  183. WFIFOW(inter_fd,0) = 0x3002;
  184. WFIFOL(inter_fd,2) = id;
  185. WFIFOB(inter_fd,6) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
  186. WFIFOSET(inter_fd,7);
  187. if (battle_config.etc_log)
  188. ShowInfo("intif_wis_replay: id: %d, flag:%d\n", id, flag);
  189. return 0;
  190. }
  191. // The transmission of GM only Wisp/Page from server to inter-server
  192. int intif_wis_message_to_gm(char *Wisp_name, int min_gm_level, char *mes)
  193. {
  194. int mes_len;
  195. if (CheckForCharServer())
  196. return 0;
  197. mes_len = strlen(mes) + 1; // + null
  198. WFIFOHEAD(inter_fd, mes_len + 30);
  199. WFIFOW(inter_fd,0) = 0x3003;
  200. WFIFOW(inter_fd,2) = mes_len + 30;
  201. memcpy(WFIFOP(inter_fd,4), Wisp_name, NAME_LENGTH);
  202. WFIFOW(inter_fd,4+NAME_LENGTH) = (short)min_gm_level;
  203. memcpy(WFIFOP(inter_fd,6+NAME_LENGTH), mes, mes_len);
  204. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  205. if (battle_config.etc_log)
  206. ShowNotice("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n", Wisp_name, min_gm_level, mes);
  207. return 0;
  208. }
  209. int intif_regtostr(char* str, struct global_reg *reg, int qty)
  210. {
  211. int len =0, i;
  212. for (i = 0; i < qty; i++) {
  213. len+= sprintf(str+len, "%s", reg[i].str)+1; //We add 1 to consider the '\0' in place.
  214. len+= sprintf(str+len, "%s", reg[i].value)+1;
  215. }
  216. return len;
  217. }
  218. //Request for saving registry values.
  219. int intif_saveregistry(struct map_session_data *sd, int type)
  220. {
  221. struct global_reg *reg;
  222. int count;
  223. int i, p;
  224. if (CheckForCharServer())
  225. return -1;
  226. switch (type) {
  227. case 3: //Character reg
  228. reg = sd->save_reg.global;
  229. count = sd->save_reg.global_num;
  230. sd->state.reg_dirty &= ~0x4;
  231. break;
  232. case 2: //Account reg
  233. reg = sd->save_reg.account;
  234. count = sd->save_reg.account_num;
  235. sd->state.reg_dirty &= ~0x2;
  236. break;
  237. case 1: //Account2 reg
  238. reg = sd->save_reg.account2;
  239. count = sd->save_reg.account2_num;
  240. sd->state.reg_dirty &= ~0x1;
  241. break;
  242. default: //Broken code?
  243. ShowError("intif_saveregistry: Invalid type %d\n", type);
  244. return -1;
  245. }
  246. WFIFOHEAD(inter_fd, 288 * MAX_REG_NUM+13);
  247. WFIFOW(inter_fd,0)=0x3004;
  248. WFIFOL(inter_fd,4)=sd->status.account_id;
  249. WFIFOL(inter_fd,8)=sd->status.char_id;
  250. WFIFOB(inter_fd,12)=type;
  251. for( p = 13, i = 0; i < count; i++ ) {
  252. if (reg[i].str[0] && reg[i].value != 0) {
  253. p+= sprintf((char*)WFIFOP(inter_fd,p), "%s", reg[i].str)+1; //We add 1 to consider the '\0' in place.
  254. p+= sprintf((char*)WFIFOP(inter_fd,p), "%s", reg[i].value)+1;
  255. }
  256. }
  257. WFIFOW(inter_fd,2)=p;
  258. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  259. return 0;
  260. }
  261. //Request the registries for this player.
  262. int intif_request_registry(struct map_session_data *sd, int flag)
  263. {
  264. nullpo_retr(0, sd);
  265. sd->save_reg.account2_num = -1;
  266. sd->save_reg.account_num = -1;
  267. sd->save_reg.global_num = -1;
  268. if (CheckForCharServer())
  269. return 0;
  270. WFIFOHEAD(inter_fd,6);
  271. WFIFOW(inter_fd,0) = 0x3005;
  272. WFIFOL(inter_fd,2) = sd->status.account_id;
  273. WFIFOL(inter_fd,6) = sd->status.char_id;
  274. WFIFOB(inter_fd,10) = (flag&1?1:0); //Request Acc Reg 2
  275. WFIFOB(inter_fd,11) = (flag&2?1:0); //Request Acc Reg
  276. WFIFOB(inter_fd,12) = (flag&4?1:0); //Request Char Reg
  277. WFIFOSET(inter_fd,13);
  278. return 0;
  279. }
  280. // 倉庫データ要求
  281. int intif_request_storage(int account_id)
  282. {
  283. if (CheckForCharServer())
  284. return 0;
  285. WFIFOHEAD(inter_fd,6);
  286. WFIFOW(inter_fd,0) = 0x3010;
  287. WFIFOL(inter_fd,2) = account_id;
  288. WFIFOSET(inter_fd,6);
  289. return 0;
  290. }
  291. // 倉庫データ送信
  292. int intif_send_storage(struct storage *stor)
  293. {
  294. if (CheckForCharServer())
  295. return 0;
  296. nullpo_retr(0, stor);
  297. WFIFOHEAD(inter_fd,sizeof(struct storage)+8);
  298. WFIFOW(inter_fd,0) = 0x3011;
  299. WFIFOW(inter_fd,2) = sizeof(struct storage)+8;
  300. WFIFOL(inter_fd,4) = stor->account_id;
  301. memcpy( WFIFOP(inter_fd,8),stor, sizeof(struct storage) );
  302. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  303. return 0;
  304. }
  305. int intif_request_guild_storage(int account_id,int guild_id)
  306. {
  307. if (CheckForCharServer())
  308. return 0;
  309. WFIFOHEAD(inter_fd,10);
  310. WFIFOW(inter_fd,0) = 0x3018;
  311. WFIFOL(inter_fd,2) = account_id;
  312. WFIFOL(inter_fd,6) = guild_id;
  313. WFIFOSET(inter_fd,10);
  314. return 0;
  315. }
  316. int intif_send_guild_storage(int account_id,struct guild_storage *gstor)
  317. {
  318. if (CheckForCharServer())
  319. return 0;
  320. WFIFOHEAD(inter_fd,sizeof(struct guild_storage)+12);
  321. WFIFOW(inter_fd,0) = 0x3019;
  322. WFIFOW(inter_fd,2) = (unsigned short)sizeof(struct guild_storage)+12;
  323. WFIFOL(inter_fd,4) = account_id;
  324. WFIFOL(inter_fd,8) = gstor->guild_id;
  325. memcpy( WFIFOP(inter_fd,12),gstor, sizeof(struct guild_storage) );
  326. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  327. return 0;
  328. }
  329. // パーティ作成要求
  330. int intif_create_party(struct party_member *member,char *name,int item,int item2)
  331. {
  332. if (CheckForCharServer())
  333. return 0;
  334. nullpo_retr(0, member);
  335. WFIFOHEAD(inter_fd,64);
  336. WFIFOW(inter_fd,0) = 0x3020;
  337. WFIFOW(inter_fd,2) = 30+sizeof(struct party_member);
  338. memcpy(WFIFOP(inter_fd,4),name, NAME_LENGTH);
  339. WFIFOB(inter_fd,28)= item;
  340. WFIFOB(inter_fd,29)= item2;
  341. memcpy(WFIFOP(inter_fd,30), member, sizeof(struct party_member));
  342. WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
  343. return 0;
  344. }
  345. // パーティ情報要求
  346. int intif_request_partyinfo(int party_id)
  347. {
  348. if (CheckForCharServer())
  349. return 0;
  350. WFIFOHEAD(inter_fd,6);
  351. WFIFOW(inter_fd,0) = 0x3021;
  352. WFIFOL(inter_fd,2) = party_id;
  353. WFIFOSET(inter_fd,6);
  354. return 0;
  355. }
  356. // パーティ追加要求
  357. int intif_party_addmember(int party_id,struct party_member *member)
  358. {
  359. if (CheckForCharServer())
  360. return 0;
  361. WFIFOHEAD(inter_fd,42);
  362. WFIFOW(inter_fd,0)=0x3022;
  363. WFIFOW(inter_fd,2)=8+sizeof(struct party_member);
  364. WFIFOL(inter_fd,4)=party_id;
  365. memcpy(WFIFOP(inter_fd,8),member,sizeof(struct party_member));
  366. WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
  367. return 1;
  368. }
  369. // パーティ設定変更
  370. int intif_party_changeoption(int party_id,int account_id,int exp,int item)
  371. {
  372. if (CheckForCharServer())
  373. return 0;
  374. WFIFOHEAD(inter_fd,14);
  375. WFIFOW(inter_fd,0)=0x3023;
  376. WFIFOL(inter_fd,2)=party_id;
  377. WFIFOL(inter_fd,6)=account_id;
  378. WFIFOW(inter_fd,10)=exp;
  379. WFIFOW(inter_fd,12)=item;
  380. WFIFOSET(inter_fd,14);
  381. return 0;
  382. }
  383. // パーティ脱退要求
  384. int intif_party_leave(int party_id,int account_id, int char_id)
  385. {
  386. if (CheckForCharServer())
  387. return 0;
  388. WFIFOHEAD(inter_fd,14);
  389. WFIFOW(inter_fd,0)=0x3024;
  390. WFIFOL(inter_fd,2)=party_id;
  391. WFIFOL(inter_fd,6)=account_id;
  392. WFIFOL(inter_fd,10)=char_id;
  393. WFIFOSET(inter_fd,14);
  394. return 0;
  395. }
  396. // パーティ移動要求
  397. int intif_party_changemap(struct map_session_data *sd,int online)
  398. {
  399. if (CheckForCharServer())
  400. return 0;
  401. if(!sd)
  402. return 0;
  403. WFIFOHEAD(inter_fd,19);
  404. WFIFOW(inter_fd,0)=0x3025;
  405. WFIFOL(inter_fd,2)=sd->status.party_id;
  406. WFIFOL(inter_fd,6)=sd->status.account_id;
  407. WFIFOL(inter_fd,10)=sd->status.char_id;
  408. WFIFOW(inter_fd,14)=sd->mapindex;
  409. WFIFOB(inter_fd,16)=online;
  410. WFIFOW(inter_fd,17)=sd->status.base_level;
  411. WFIFOSET(inter_fd,19);
  412. return 1;
  413. }
  414. // パーティー解散要求
  415. int intif_break_party(int party_id)
  416. {
  417. if (CheckForCharServer())
  418. return 0;
  419. WFIFOHEAD(inter_fd,6);
  420. WFIFOW(inter_fd,0)=0x3026;
  421. WFIFOL(inter_fd,2)=party_id;
  422. WFIFOSET(inter_fd,6);
  423. return 0;
  424. }
  425. // パーティ会話送信
  426. int intif_party_message(int party_id,int account_id,const char *mes,int len)
  427. {
  428. if (CheckForCharServer())
  429. return 0;
  430. if (other_mapserver_count < 1)
  431. return 0; //No need to send.
  432. WFIFOHEAD(inter_fd,len + 12);
  433. WFIFOW(inter_fd,0)=0x3027;
  434. WFIFOW(inter_fd,2)=len+12;
  435. WFIFOL(inter_fd,4)=party_id;
  436. WFIFOL(inter_fd,8)=account_id;
  437. memcpy(WFIFOP(inter_fd,12),mes,len);
  438. WFIFOSET(inter_fd,len+12);
  439. return 0;
  440. }
  441. // パーティ競合チェック要求
  442. int intif_party_checkconflict(int party_id,int account_id,int char_id)
  443. {
  444. if (CheckForCharServer())
  445. return 0;
  446. WFIFOHEAD(inter_fd,10 + NAME_LENGTH);
  447. WFIFOW(inter_fd,0)=0x3028;
  448. WFIFOL(inter_fd,2)=party_id;
  449. WFIFOL(inter_fd,6)=account_id;
  450. WFIFOL(inter_fd,10)=char_id;
  451. WFIFOSET(inter_fd,14);
  452. return 0;
  453. }
  454. int intif_party_leaderchange(int party_id,int account_id,int char_id)
  455. {
  456. if (CheckForCharServer())
  457. return 0;
  458. WFIFOHEAD(inter_fd,14);
  459. WFIFOW(inter_fd,0)=0x3029;
  460. WFIFOL(inter_fd,2)=party_id;
  461. WFIFOL(inter_fd,6)=account_id;
  462. WFIFOL(inter_fd,10)=char_id;
  463. WFIFOSET(inter_fd,14);
  464. return 0;
  465. }
  466. // ギルド作成要求
  467. int intif_guild_create(const char *name,const struct guild_member *master)
  468. {
  469. if (CheckForCharServer())
  470. return 0;
  471. nullpo_retr(0, master);
  472. WFIFOHEAD(inter_fd,sizeof(struct guild_member)+(8+NAME_LENGTH));
  473. WFIFOW(inter_fd,0)=0x3030;
  474. WFIFOW(inter_fd,2)=sizeof(struct guild_member)+(8+NAME_LENGTH);
  475. WFIFOL(inter_fd,4)=master->account_id;
  476. memcpy(WFIFOP(inter_fd,8),name,NAME_LENGTH);
  477. memcpy(WFIFOP(inter_fd,8+NAME_LENGTH),master,sizeof(struct guild_member));
  478. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  479. return 0;
  480. }
  481. // ギルド情報要求
  482. int intif_guild_request_info(int guild_id)
  483. {
  484. if (CheckForCharServer())
  485. return 0;
  486. WFIFOHEAD(inter_fd,6);
  487. WFIFOW(inter_fd,0) = 0x3031;
  488. WFIFOL(inter_fd,2) = guild_id;
  489. WFIFOSET(inter_fd,6);
  490. return 0;
  491. }
  492. // ギルドメンバ追加要求
  493. int intif_guild_addmember(int guild_id,struct guild_member *m)
  494. {
  495. if (CheckForCharServer())
  496. return 0;
  497. WFIFOHEAD(inter_fd,sizeof(struct guild_member)+8);
  498. WFIFOW(inter_fd,0) = 0x3032;
  499. WFIFOW(inter_fd,2) = sizeof(struct guild_member)+8;
  500. WFIFOL(inter_fd,4) = guild_id;
  501. memcpy(WFIFOP(inter_fd,8),m,sizeof(struct guild_member));
  502. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  503. return 0;
  504. }
  505. int intif_guild_change_gm(int guild_id, const char* name, int len)
  506. {
  507. if (CheckForCharServer())
  508. return 0;
  509. WFIFOHEAD(inter_fd, len + 8);
  510. WFIFOW(inter_fd, 0)=0x3033;
  511. WFIFOW(inter_fd, 2)=len+8;
  512. WFIFOL(inter_fd, 4)=guild_id;
  513. memcpy(WFIFOP(inter_fd,8),name,len);
  514. WFIFOSET(inter_fd,len+8);
  515. return 0;
  516. }
  517. // ギルドメンバ脱退/追放要求
  518. int intif_guild_leave(int guild_id,int account_id,int char_id,int flag,const char *mes)
  519. {
  520. if (CheckForCharServer())
  521. return 0;
  522. WFIFOHEAD(inter_fd, 55);
  523. WFIFOW(inter_fd, 0) = 0x3034;
  524. WFIFOL(inter_fd, 2) = guild_id;
  525. WFIFOL(inter_fd, 6) = account_id;
  526. WFIFOL(inter_fd,10) = char_id;
  527. WFIFOB(inter_fd,14) = flag;
  528. safestrncpy(WFIFOP(inter_fd,15),mes,40);
  529. WFIFOSET(inter_fd,55);
  530. return 0;
  531. }
  532. // ギルドメンバのオンライン状況/Lv更新要求
  533. int intif_guild_memberinfoshort(int guild_id,int account_id,int char_id,int online,int lv,int class_)
  534. {
  535. if (CheckForCharServer())
  536. return 0;
  537. WFIFOHEAD(inter_fd, 19);
  538. WFIFOW(inter_fd, 0) = 0x3035;
  539. WFIFOL(inter_fd, 2) = guild_id;
  540. WFIFOL(inter_fd, 6) = account_id;
  541. WFIFOL(inter_fd,10) = char_id;
  542. WFIFOB(inter_fd,14) = online;
  543. WFIFOW(inter_fd,15) = lv;
  544. WFIFOW(inter_fd,17) = class_;
  545. WFIFOSET(inter_fd,19);
  546. return 0;
  547. }
  548. // ギルド解散通知
  549. int intif_guild_break(int guild_id)
  550. {
  551. if (CheckForCharServer())
  552. return 0;
  553. WFIFOHEAD(inter_fd, 6);
  554. WFIFOW(inter_fd, 0) = 0x3036;
  555. WFIFOL(inter_fd, 2) = guild_id;
  556. WFIFOSET(inter_fd,6);
  557. return 0;
  558. }
  559. // ギルド会話送信
  560. int intif_guild_message(int guild_id,int account_id,const char *mes,int len)
  561. {
  562. if (CheckForCharServer())
  563. return 0;
  564. if (other_mapserver_count < 1)
  565. return 0; //No need to send.
  566. WFIFOHEAD(inter_fd, len + 12);
  567. WFIFOW(inter_fd,0)=0x3037;
  568. WFIFOW(inter_fd,2)=len+12;
  569. WFIFOL(inter_fd,4)=guild_id;
  570. WFIFOL(inter_fd,8)=account_id;
  571. memcpy(WFIFOP(inter_fd,12),mes,len);
  572. WFIFOSET(inter_fd,len+12);
  573. return 0;
  574. }
  575. // ギルド基本情報変更要求
  576. int intif_guild_change_basicinfo(int guild_id,int type,const void *data,int len)
  577. {
  578. if (CheckForCharServer())
  579. return 0;
  580. WFIFOHEAD(inter_fd, len + 10);
  581. WFIFOW(inter_fd,0)=0x3039;
  582. WFIFOW(inter_fd,2)=len+10;
  583. WFIFOL(inter_fd,4)=guild_id;
  584. WFIFOW(inter_fd,8)=type;
  585. memcpy(WFIFOP(inter_fd,10),data,len);
  586. WFIFOSET(inter_fd,len+10);
  587. return 0;
  588. }
  589. // ギルドメンバ情報変更要求
  590. int intif_guild_change_memberinfo(int guild_id,int account_id,int char_id,
  591. int type,const void *data,int len)
  592. {
  593. if (CheckForCharServer())
  594. return 0;
  595. WFIFOHEAD(inter_fd, len + 18);
  596. WFIFOW(inter_fd, 0)=0x303a;
  597. WFIFOW(inter_fd, 2)=len+18;
  598. WFIFOL(inter_fd, 4)=guild_id;
  599. WFIFOL(inter_fd, 8)=account_id;
  600. WFIFOL(inter_fd,12)=char_id;
  601. WFIFOW(inter_fd,16)=type;
  602. memcpy(WFIFOP(inter_fd,18),data,len);
  603. WFIFOSET(inter_fd,len+18);
  604. return 0;
  605. }
  606. // ギルド役職変更要求
  607. int intif_guild_position(int guild_id,int idx,struct guild_position *p)
  608. {
  609. if (CheckForCharServer())
  610. return 0;
  611. WFIFOHEAD(inter_fd, sizeof(struct guild_position)+12);
  612. WFIFOW(inter_fd,0)=0x303b;
  613. WFIFOW(inter_fd,2)=sizeof(struct guild_position)+12;
  614. WFIFOL(inter_fd,4)=guild_id;
  615. WFIFOL(inter_fd,8)=idx;
  616. memcpy(WFIFOP(inter_fd,12),p,sizeof(struct guild_position));
  617. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  618. return 0;
  619. }
  620. // ギルドスキルアップ要求
  621. int intif_guild_skillup(int guild_id, int skill_num, int account_id)
  622. {
  623. if( CheckForCharServer() )
  624. return 0;
  625. WFIFOHEAD(inter_fd, 14);
  626. WFIFOW(inter_fd, 0) = 0x303c;
  627. WFIFOL(inter_fd, 2) = guild_id;
  628. WFIFOL(inter_fd, 6) = skill_num;
  629. WFIFOL(inter_fd, 10) = account_id;
  630. WFIFOSET(inter_fd, 14);
  631. return 0;
  632. }
  633. // ギルド同盟/敵対要求
  634. int intif_guild_alliance(int guild_id1,int guild_id2,int account_id1,int account_id2,int flag)
  635. {
  636. if (CheckForCharServer())
  637. return 0;
  638. WFIFOHEAD(inter_fd,19);
  639. WFIFOW(inter_fd, 0)=0x303d;
  640. WFIFOL(inter_fd, 2)=guild_id1;
  641. WFIFOL(inter_fd, 6)=guild_id2;
  642. WFIFOL(inter_fd,10)=account_id1;
  643. WFIFOL(inter_fd,14)=account_id2;
  644. WFIFOB(inter_fd,18)=flag;
  645. WFIFOSET(inter_fd,19);
  646. return 0;
  647. }
  648. // ギルド告知変更要求
  649. int intif_guild_notice(int guild_id,const char *mes1,const char *mes2)
  650. {
  651. if (CheckForCharServer())
  652. return 0;
  653. WFIFOHEAD(inter_fd,186);
  654. WFIFOW(inter_fd,0)=0x303e;
  655. WFIFOL(inter_fd,2)=guild_id;
  656. memcpy(WFIFOP(inter_fd,6),mes1,60);
  657. memcpy(WFIFOP(inter_fd,66),mes2,120);
  658. WFIFOSET(inter_fd,186);
  659. return 0;
  660. }
  661. // ギルドエンブレム変更要求
  662. int intif_guild_emblem(int guild_id,int len,const char *data)
  663. {
  664. if (CheckForCharServer())
  665. return 0;
  666. if(guild_id<=0 || len<0 || len>2000)
  667. return 0;
  668. WFIFOHEAD(inter_fd,len + 12);
  669. WFIFOW(inter_fd,0)=0x303f;
  670. WFIFOW(inter_fd,2)=len+12;
  671. WFIFOL(inter_fd,4)=guild_id;
  672. WFIFOL(inter_fd,8)=0;
  673. memcpy(WFIFOP(inter_fd,12),data,len);
  674. WFIFOSET(inter_fd,len+12);
  675. return 0;
  676. }
  677. //現在のギルド城占領ギルドを調べる
  678. int intif_guild_castle_dataload(int castle_id,int index)
  679. {
  680. if (CheckForCharServer())
  681. return 0;
  682. WFIFOHEAD(inter_fd,5);
  683. WFIFOW(inter_fd,0)=0x3040;
  684. WFIFOW(inter_fd,2)=castle_id;
  685. WFIFOB(inter_fd,4)=index;
  686. WFIFOSET(inter_fd,5);
  687. return 0;
  688. }
  689. //ギルド城占領ギルド変更要求
  690. int intif_guild_castle_datasave(int castle_id,int index, int value)
  691. {
  692. if (CheckForCharServer())
  693. return 0;
  694. WFIFOHEAD(inter_fd,9);
  695. WFIFOW(inter_fd,0)=0x3041;
  696. WFIFOW(inter_fd,2)=castle_id;
  697. WFIFOB(inter_fd,4)=index;
  698. WFIFOL(inter_fd,5)=value;
  699. WFIFOSET(inter_fd,9);
  700. return 0;
  701. }
  702. //-----------------------------------------------------------------
  703. // Homunculus Packets send to Inter server [albator]
  704. //-----------------------------------------------------------------
  705. int intif_homunculus_create(int account_id, struct s_homunculus *sh)
  706. {
  707. if (CheckForCharServer())
  708. return 0;
  709. WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
  710. WFIFOW(inter_fd,0) = 0x3090;
  711. WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
  712. WFIFOL(inter_fd,4) = account_id;
  713. memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
  714. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  715. return 0;
  716. }
  717. int intif_homunculus_requestload(int account_id, int homun_id)
  718. {
  719. if (CheckForCharServer())
  720. return 0;
  721. WFIFOHEAD(inter_fd, 10);
  722. WFIFOW(inter_fd,0) = 0x3091;
  723. WFIFOL(inter_fd,2) = account_id;
  724. WFIFOL(inter_fd,6) = homun_id;
  725. WFIFOSET(inter_fd, 10);
  726. return 1;
  727. }
  728. int intif_homunculus_requestsave(int account_id, struct s_homunculus* sh)
  729. {
  730. if (CheckForCharServer())
  731. return 0;
  732. WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
  733. WFIFOW(inter_fd,0) = 0x3092;
  734. WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
  735. WFIFOL(inter_fd,4) = account_id;
  736. memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
  737. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  738. return 0;
  739. }
  740. int intif_homunculus_requestdelete(int homun_id)
  741. {
  742. if (CheckForCharServer())
  743. return 0;
  744. WFIFOHEAD(inter_fd, 6);
  745. WFIFOW(inter_fd, 0) = 0x3093;
  746. WFIFOL(inter_fd,2) = homun_id;
  747. WFIFOSET(inter_fd,6);
  748. return 0;
  749. }
  750. //-----------------------------------------------------------------
  751. // Packets receive from inter server
  752. // Wisp/Page reception // rewritten by [Yor]
  753. int intif_parse_WisMessage(int fd)
  754. {
  755. struct map_session_data* sd;
  756. char *wisp_source;
  757. char name[NAME_LENGTH];
  758. int id, i;
  759. id=RFIFOL(fd,4);
  760. safestrncpy(name, (char*)RFIFOP(fd,32), NAME_LENGTH);
  761. sd = map_nick2sd(name);
  762. if(sd == NULL || strcmp(sd->status.name, name) != 0)
  763. { //Not found
  764. intif_wis_replay(id,1);
  765. return 0;
  766. }
  767. if(sd->state.ignoreAll) {
  768. intif_wis_replay(id, 2);
  769. return 0;
  770. }
  771. wisp_source = (char *) RFIFOP(fd,8); // speed up [Yor]
  772. for(i=0; i < MAX_IGNORE_LIST &&
  773. sd->ignore[i].name[0] != '\0' &&
  774. strcmp(sd->ignore[i].name, wisp_source) != 0
  775. ; i++);
  776. if (i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0')
  777. { //Ignored
  778. intif_wis_replay(id, 2);
  779. return 0;
  780. }
  781. //Success to send whisper.
  782. clif_wis_message(sd->fd, wisp_source, (char*)RFIFOP(fd,56),RFIFOW(fd,2)-56);
  783. intif_wis_replay(id,0); // 送信成功
  784. return 0;
  785. }
  786. // Wisp/page transmission result reception
  787. int intif_parse_WisEnd(int fd)
  788. {
  789. struct map_session_data* sd;
  790. if (battle_config.etc_log)
  791. ShowInfo("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP(fd,2), RFIFOB(fd,26)); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
  792. sd = (struct map_session_data *)map_nick2sd((char *) RFIFOP(fd,2));
  793. if (sd != NULL)
  794. clif_wis_end(sd->fd, RFIFOB(fd,26));
  795. return 0;
  796. }
  797. static int mapif_parse_WisToGM_sub(struct map_session_data* sd,va_list va)
  798. {
  799. int min_gm_level = va_arg(va, int);
  800. char *wisp_name;
  801. char *message;
  802. int len;
  803. if (pc_isGM(sd) < min_gm_level) return 0;
  804. wisp_name = va_arg(va, char*);
  805. message = va_arg(va, char*);
  806. len = va_arg(va, int);
  807. clif_wis_message(sd->fd, wisp_name, message, len);
  808. return 1;
  809. }
  810. // Received wisp message from map-server via char-server for ALL gm
  811. // 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B
  812. int mapif_parse_WisToGM(int fd)
  813. {
  814. int min_gm_level, mes_len;
  815. char Wisp_name[NAME_LENGTH];
  816. char mbuf[255];
  817. char *message;
  818. mes_len = RFIFOW(fd,2) - 30;
  819. message = (char *) (mes_len >= 255 ? (char *) aMallocA(mes_len) : mbuf);
  820. min_gm_level = (int)RFIFOW(fd,28);
  821. safestrncpy(Wisp_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  822. safestrncpy(message, (char*)RFIFOP(fd,30), mes_len);
  823. // information is sended to all online GM
  824. clif_foreachclient(mapif_parse_WisToGM_sub, min_gm_level, Wisp_name, message, mes_len);
  825. if (message != mbuf)
  826. aFree(message);
  827. return 0;
  828. }
  829. // アカウント変数通知
  830. int intif_parse_Registers(int fd)
  831. {
  832. int j,p,len,max, flag;
  833. struct map_session_data *sd;
  834. struct global_reg *reg;
  835. int *qty;
  836. int account_id = RFIFOL(fd,4), char_id = RFIFOL(fd,8);
  837. struct auth_node *node = chrif_auth_check(account_id, char_id, ST_LOGIN);
  838. if (node)
  839. sd = node->sd;
  840. else { //Normally registries should arrive for in log-in chars.
  841. sd = map_id2sd(account_id);
  842. if (sd && RFIFOB(fd,12) == 3 && sd->status.char_id != char_id)
  843. sd = NULL; //Character registry from another character.
  844. }
  845. if (!sd) return 1;
  846. flag = (sd->save_reg.global_num == -1 || sd->save_reg.account_num == -1 || sd->save_reg.account2_num == -1);
  847. switch (RFIFOB(fd,12)) {
  848. case 3: //Character Registry
  849. reg = sd->save_reg.global;
  850. qty = &sd->save_reg.global_num;
  851. max = GLOBAL_REG_NUM;
  852. break;
  853. case 2: //Account Registry
  854. reg = sd->save_reg.account;
  855. qty = &sd->save_reg.account_num;
  856. max = ACCOUNT_REG_NUM;
  857. break;
  858. case 1: //Account2 Registry
  859. reg = sd->save_reg.account2;
  860. qty = &sd->save_reg.account2_num;
  861. max = ACCOUNT_REG2_NUM;
  862. break;
  863. default:
  864. ShowError("intif_parse_Registers: Unrecognized type %d\n",RFIFOB(fd,12));
  865. return 0;
  866. }
  867. for(j=0,p=13;j<max && p<RFIFOW(fd,2);j++){
  868. sscanf((char*)RFIFOP(fd,p), "%31c%n", reg[j].str,&len);
  869. reg[j].str[len]='\0';
  870. p += len+1; //+1 to skip the '\0' between strings.
  871. sscanf((char*)RFIFOP(fd,p), "%255c%n", reg[j].value,&len);
  872. reg[j].value[len]='\0';
  873. p += len+1;
  874. }
  875. *qty = j;
  876. if (flag && sd->save_reg.global_num > -1 && sd->save_reg.account_num > -1 && sd->save_reg.account2_num > -1)
  877. pc_reg_received(sd); //Received all registry values, execute init scripts and what-not. [Skotlex]
  878. return 1;
  879. }
  880. // 倉庫データ受信
  881. int intif_parse_LoadStorage(int fd)
  882. {
  883. struct storage *stor;
  884. struct map_session_data *sd;
  885. sd=map_id2sd( RFIFOL(fd,4) );
  886. if(sd==NULL){
  887. ShowError("intif_parse_LoadStorage: user not found %d\n",RFIFOL(fd,4));
  888. return 1;
  889. }
  890. stor = account2storage( RFIFOL(fd,4));
  891. if (stor->storage_status == 1) { // Already open.. lets ignore this update
  892. ShowWarning("intif_parse_LoadStorage: storage received for a client already open (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
  893. return 1;
  894. }
  895. if (stor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex]
  896. ShowWarning("intif_parse_LoadStorage: received storage for an already modified non-saved storage! (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
  897. return 1;
  898. }
  899. if (RFIFOW(fd,2)-8 != sizeof(struct storage)) {
  900. ShowError("intif_parse_LoadStorage: data size error %d %d\n", RFIFOW(fd,2)-8, sizeof(struct storage));
  901. return 1;
  902. }
  903. if(battle_config.save_log)
  904. ShowInfo("intif_openstorage: %d\n",RFIFOL(fd,4) );
  905. memcpy(stor,RFIFOP(fd,8),sizeof(struct storage));
  906. stor->dirty=0;
  907. stor->storage_status=1;
  908. sd->state.storage_flag = 1;
  909. clif_storagelist(sd,stor);
  910. clif_updatestorageamount(sd,stor);
  911. return 0;
  912. }
  913. // 倉庫データ送信成功
  914. int intif_parse_SaveStorage(int fd)
  915. {
  916. if(battle_config.save_log)
  917. ShowInfo("intif_savestorage: done %d %d\n",RFIFOL(fd,2),RFIFOB(fd,6) );
  918. storage_storage_saved(RFIFOL(fd,2));
  919. return 0;
  920. }
  921. int intif_parse_LoadGuildStorage(int fd)
  922. {
  923. struct guild_storage *gstor;
  924. struct map_session_data *sd;
  925. int guild_id;
  926. guild_id = RFIFOL(fd,8);
  927. if(guild_id <= 0)
  928. return 1;
  929. sd=map_id2sd( RFIFOL(fd,4) );
  930. if(sd==NULL){
  931. ShowError("intif_parse_LoadGuildStorage: user not found %d\n",RFIFOL(fd,4));
  932. return 1;
  933. }
  934. gstor=guild2storage(guild_id);
  935. if(!gstor) {
  936. ShowWarning("intif_parse_LoadGuildStorage: error guild_id %d not exist\n",guild_id);
  937. return 1;
  938. }
  939. if (gstor->storage_status == 1) { // Already open.. lets ignore this update
  940. ShowWarning("intif_parse_LoadGuildStorage: storage received for a client already open (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
  941. return 1;
  942. }
  943. if (gstor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex]
  944. ShowWarning("intif_parse_LoadGuildStorage: received storage for an already modified non-saved storage! (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
  945. return 1;
  946. }
  947. if( RFIFOW(fd,2)-12 != sizeof(struct guild_storage) ){
  948. ShowError("intif_parse_LoadGuildStorage: data size error %d %d\n",RFIFOW(fd,2)-12 , sizeof(struct guild_storage));
  949. gstor->storage_status = 0;
  950. return 1;
  951. }
  952. if(battle_config.save_log)
  953. ShowInfo("intif_open_guild_storage: %d\n",RFIFOL(fd,4) );
  954. memcpy(gstor,RFIFOP(fd,12),sizeof(struct guild_storage));
  955. gstor->storage_status = 1;
  956. sd->state.storage_flag = 2;
  957. clif_guildstoragelist(sd,gstor);
  958. clif_updateguildstorageamount(sd,gstor);
  959. return 0;
  960. }
  961. int intif_parse_SaveGuildStorage(int fd)
  962. {
  963. if(battle_config.save_log) {
  964. ShowInfo("intif_save_guild_storage: done %d %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOB(fd,10) );
  965. }
  966. storage_guild_storagesaved(/*RFIFOL(fd,2), */RFIFOL(fd,6));
  967. return 0;
  968. }
  969. // パーティ作成可否
  970. int intif_parse_PartyCreated(int fd)
  971. {
  972. if(battle_config.etc_log)
  973. ShowInfo("intif: party created by account %d\n\n", RFIFOL(fd,2));
  974. party_created(RFIFOL(fd,2), RFIFOL(fd,6),RFIFOB(fd,10),RFIFOL(fd,11), (char *)RFIFOP(fd,15));
  975. return 0;
  976. }
  977. // パーティ情報
  978. int intif_parse_PartyInfo(int fd)
  979. {
  980. if( RFIFOW(fd,2)==8){
  981. ShowWarning("intif: party noinfo %d\n",RFIFOL(fd,4));
  982. party_recv_noinfo(RFIFOL(fd,4));
  983. return 0;
  984. }
  985. if( RFIFOW(fd,2)!=sizeof(struct party)+4 )
  986. ShowError("intif: party info : data size error %d %d %d\n",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct party)+4);
  987. party_recv_info((struct party *)RFIFOP(fd,4));
  988. return 0;
  989. }
  990. // パーティ追加通知
  991. int intif_parse_PartyMemberAdded(int fd)
  992. {
  993. if(battle_config.etc_log)
  994. ShowInfo("intif: party member added Party (%d), Account(%d), Char(%d)\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
  995. party_member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10), RFIFOB(fd, 14));
  996. return 0;
  997. }
  998. // パーティ設定変更通知
  999. int intif_parse_PartyOptionChanged(int fd)
  1000. {
  1001. party_optionchanged(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOW(fd,10),RFIFOW(fd,12),RFIFOB(fd,14));
  1002. return 0;
  1003. }
  1004. // パーティ脱退通知
  1005. int intif_parse_PartyMemberLeaved(int fd)
  1006. {
  1007. if(battle_config.etc_log)
  1008. ShowInfo("intif: party member leaved: Party(%d), Account(%d), Char(%d)\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
  1009. party_member_leaved(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
  1010. return 0;
  1011. }
  1012. // パーティ解散通知
  1013. int intif_parse_PartyBroken(int fd)
  1014. {
  1015. party_broken(RFIFOL(fd,2));
  1016. return 0;
  1017. }
  1018. // パーティ移動通知
  1019. int intif_parse_PartyMove(int fd)
  1020. {
  1021. party_recv_movemap(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOW(fd,14),RFIFOB(fd,16),RFIFOW(fd,17));
  1022. return 0;
  1023. }
  1024. // パーティメッセージ
  1025. int intif_parse_PartyMessage(int fd)
  1026. {
  1027. party_recv_message(RFIFOL(fd,4),RFIFOL(fd,8),(char *) RFIFOP(fd,12),RFIFOW(fd,2)-12);
  1028. return 0;
  1029. }
  1030. // ギルド作成可否
  1031. int intif_parse_GuildCreated(int fd)
  1032. {
  1033. guild_created(RFIFOL(fd,2),RFIFOL(fd,6));
  1034. return 0;
  1035. }
  1036. // ギルド情報
  1037. int intif_parse_GuildInfo(int fd)
  1038. {
  1039. if(RFIFOW(fd,2) == 8) {
  1040. ShowWarning("intif: guild noinfo %d\n",RFIFOL(fd,4));
  1041. guild_recv_noinfo(RFIFOL(fd,4));
  1042. return 0;
  1043. }
  1044. if( RFIFOW(fd,2)!=sizeof(struct guild)+4 )
  1045. ShowError("intif: guild info : data size error Gid: %d recv size: %d Expected size: %d\n",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild)+4);
  1046. guild_recv_info((struct guild *)RFIFOP(fd,4));
  1047. return 0;
  1048. }
  1049. // ギルドメンバ追加通知
  1050. int intif_parse_GuildMemberAdded(int fd)
  1051. {
  1052. if(battle_config.etc_log)
  1053. ShowInfo("intif: guild member added %d %d %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14));
  1054. guild_member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14));
  1055. return 0;
  1056. }
  1057. // ギルドメンバ脱退/追放通知
  1058. int intif_parse_GuildMemberLeaved(int fd)
  1059. {
  1060. guild_member_leaved(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),(char *)RFIFOP(fd,55),(char *)RFIFOP(fd,15));
  1061. return 0;
  1062. }
  1063. // ギルドメンバオンライン状態/Lv変更通知
  1064. int intif_parse_GuildMemberInfoShort(int fd)
  1065. {
  1066. guild_recv_memberinfoshort(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOW(fd,15),RFIFOW(fd,17));
  1067. return 0;
  1068. }
  1069. // ギルド解散通知
  1070. int intif_parse_GuildBroken(int fd)
  1071. {
  1072. guild_broken(RFIFOL(fd,2),RFIFOB(fd,6));
  1073. return 0;
  1074. }
  1075. // basic guild info change notice
  1076. // 0x3839 <packet len>.w <guild id>.l <type>.w <data>.?b
  1077. int intif_parse_GuildBasicInfoChanged(int fd)
  1078. {
  1079. //int len = RFIFOW(fd,2) - 10;
  1080. int guild_id = RFIFOL(fd,4);
  1081. int type = RFIFOW(fd,8);
  1082. //void* data = RFIFOP(fd,10);
  1083. struct guild* g = guild_search(guild_id);
  1084. if( g == NULL )
  1085. return 0;
  1086. switch(type) {
  1087. case GBI_EXP: g->exp = RFIFOL(fd,10); break;
  1088. case GBI_GUILDLV: g->guild_lv = RFIFOW(fd,10); break;
  1089. case GBI_SKILLPOINT: g->skill_point = RFIFOL(fd,10); break;
  1090. }
  1091. return 0;
  1092. }
  1093. // guild member info change notice
  1094. // 0x383a <packet len>.w <guild id>.l <account id>.l <char id>.l <type>.w <data>.?b
  1095. int intif_parse_GuildMemberInfoChanged(int fd)
  1096. {
  1097. //int len = RFIFOW(fd,2) - 18;
  1098. int guild_id = RFIFOL(fd,4);
  1099. int account_id = RFIFOL(fd,8);
  1100. int char_id = RFIFOL(fd,12);
  1101. int type = RFIFOW(fd,16);
  1102. void* data = RFIFOP(fd,18);
  1103. int dd = *((int *)data);
  1104. struct guild* g;
  1105. int idx;
  1106. g = guild_search(guild_id);
  1107. if( g == NULL )
  1108. return 0;
  1109. idx = guild_getindex(g,account_id,char_id);
  1110. if( idx == -1 )
  1111. return 0;
  1112. switch( type ) {
  1113. case GMI_POSITION: g->member[idx].position = dd; guild_memberposition_changed(g,idx,dd); break;
  1114. case GMI_EXP: g->member[idx].exp = dd; break;
  1115. case GMI_HAIR: g->member[idx].hair = dd; break;
  1116. case GMI_HAIR_COLOR: g->member[idx].hair_color = dd; break;
  1117. case GMI_GENDER: g->member[idx].gender = dd; break;
  1118. case GMI_CLASS: g->member[idx].class_ = dd; break;
  1119. case GMI_LEVEL: g->member[idx].lv = dd; break;
  1120. }
  1121. return 0;
  1122. }
  1123. // ギルド役職変更通知
  1124. int intif_parse_GuildPosition(int fd)
  1125. {
  1126. if( RFIFOW(fd,2)!=sizeof(struct guild_position)+12 )
  1127. ShowError("intif: guild info : data size error\n %d %d %d",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild_position)+12);
  1128. guild_position_changed(RFIFOL(fd,4),RFIFOL(fd,8),(struct guild_position *)RFIFOP(fd,12));
  1129. return 0;
  1130. }
  1131. // ギルドスキル割り振り通知
  1132. int intif_parse_GuildSkillUp(int fd)
  1133. {
  1134. guild_skillupack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
  1135. return 0;
  1136. }
  1137. // ギルド同盟/敵対通知
  1138. int intif_parse_GuildAlliance(int fd)
  1139. {
  1140. 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));
  1141. return 0;
  1142. }
  1143. // ギルド告知変更通知
  1144. int intif_parse_GuildNotice(int fd)
  1145. {
  1146. guild_notice_changed(RFIFOL(fd,2),(char *) RFIFOP(fd,6),(char *) RFIFOP(fd,66));
  1147. return 0;
  1148. }
  1149. // ギルドエンブレム変更通知
  1150. int intif_parse_GuildEmblem(int fd)
  1151. {
  1152. guild_emblem_changed(RFIFOW(fd,2)-12,RFIFOL(fd,4),RFIFOL(fd,8), (char *)RFIFOP(fd,12));
  1153. return 0;
  1154. }
  1155. // ギルド会話受信
  1156. int intif_parse_GuildMessage(int fd)
  1157. {
  1158. guild_recv_message(RFIFOL(fd,4),RFIFOL(fd,8),(char *) RFIFOP(fd,12),RFIFOW(fd,2)-12);
  1159. return 0;
  1160. }
  1161. // ギルド城データ要求返信
  1162. int intif_parse_GuildCastleDataLoad(int fd)
  1163. {
  1164. return guild_castledataloadack(RFIFOW(fd,2),RFIFOB(fd,4),RFIFOL(fd,5));
  1165. }
  1166. // ギルド城データ変更通知
  1167. int intif_parse_GuildCastleDataSave(int fd)
  1168. {
  1169. return guild_castledatasaveack(RFIFOW(fd,2),RFIFOB(fd,4),RFIFOL(fd,5));
  1170. }
  1171. // ギルド城データ一括受信(初期化時)
  1172. int intif_parse_GuildCastleAllDataLoad(int fd)
  1173. {
  1174. return guild_castlealldataload(RFIFOW(fd,2),(struct guild_castle *)RFIFOP(fd,4));
  1175. }
  1176. int intif_parse_GuildMasterChanged(int fd)
  1177. {
  1178. return guild_gm_changed(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
  1179. }
  1180. // pet
  1181. int intif_parse_CreatePet(int fd)
  1182. {
  1183. pet_get_egg(RFIFOL(fd,2),RFIFOL(fd,7),RFIFOB(fd,6));
  1184. return 0;
  1185. }
  1186. int intif_parse_RecvPetData(int fd)
  1187. {
  1188. struct s_pet p;
  1189. int len;
  1190. len=RFIFOW(fd,2);
  1191. if(sizeof(struct s_pet)!=len-9) {
  1192. if(battle_config.etc_log)
  1193. ShowError("intif: pet data: data size error %d %d\n",sizeof(struct s_pet),len-9);
  1194. }
  1195. else{
  1196. memcpy(&p,RFIFOP(fd,9),sizeof(struct s_pet));
  1197. pet_recv_petdata(RFIFOL(fd,4),&p,RFIFOB(fd,8));
  1198. }
  1199. return 0;
  1200. }
  1201. int intif_parse_SavePetOk(int fd)
  1202. {
  1203. if(RFIFOB(fd,6) == 1)
  1204. ShowError("pet data save failure\n");
  1205. return 0;
  1206. }
  1207. int intif_parse_DeletePetOk(int fd)
  1208. {
  1209. if(RFIFOB(fd,2) == 1)
  1210. ShowError("pet data delete failure\n");
  1211. return 0;
  1212. }
  1213. int intif_parse_ChangeNameOk(int fd)
  1214. {
  1215. struct map_session_data *sd = NULL;
  1216. if((sd=map_id2sd(RFIFOL(fd,2)))==NULL ||
  1217. sd->status.char_id != RFIFOL(fd,6))
  1218. return 0;
  1219. switch (RFIFOB(fd,10)) {
  1220. case 0: //Players [NOT SUPPORTED YET]
  1221. break;
  1222. case 1: //Pets
  1223. pet_change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
  1224. break;
  1225. case 2: //Hom
  1226. merc_hom_change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
  1227. break;
  1228. }
  1229. return 0;
  1230. }
  1231. //----------------------------------------------------------------
  1232. // Homunculus recv packets [albator]
  1233. int intif_parse_CreateHomunculus(int fd)
  1234. {
  1235. int len;
  1236. len=RFIFOW(fd,2)-9;
  1237. if(sizeof(struct s_homunculus)!=len) {
  1238. if(battle_config.etc_log)
  1239. ShowError("intif: create homun data: data size error %d != %d\n",sizeof(struct s_homunculus),len);
  1240. return 0;
  1241. }
  1242. merc_hom_recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8)) ;
  1243. return 0;
  1244. }
  1245. int intif_parse_RecvHomunculusData(int fd)
  1246. {
  1247. int len;
  1248. len=RFIFOW(fd,2)-9;
  1249. if(sizeof(struct s_homunculus)!=len) {
  1250. if(battle_config.etc_log)
  1251. ShowError("intif: homun data: data size error %d %d\n",sizeof(struct s_homunculus),len);
  1252. return 0;
  1253. }
  1254. merc_hom_recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8));
  1255. return 0;
  1256. }
  1257. int intif_parse_SaveHomunculusOk(int fd)
  1258. {
  1259. if(RFIFOB(fd,6) != 1)
  1260. ShowError("homunculus data save failure for account %d\n", RFIFOL(fd,2));
  1261. return 0;
  1262. }
  1263. int intif_parse_DeleteHomunculusOk(int fd)
  1264. {
  1265. if(RFIFOB(fd,2) != 1)
  1266. ShowError("Homunculus data delete failure\n");
  1267. return 0;
  1268. }
  1269. #ifndef TXT_ONLY
  1270. /*==========================================
  1271. * MAIL SYSTEM
  1272. * By Zephyrus
  1273. *==========================================*/
  1274. /*------------------------------------------
  1275. * Inbox Request
  1276. * flag: 0 Update Inbox | 1 OpenMail
  1277. *------------------------------------------*/
  1278. int intif_Mail_requestinbox(int char_id, unsigned char flag)
  1279. {
  1280. if (CheckForCharServer())
  1281. return 0;
  1282. WFIFOHEAD(inter_fd,7);
  1283. WFIFOW(inter_fd,0) = 0x3048;
  1284. WFIFOL(inter_fd,2) = char_id;
  1285. WFIFOB(inter_fd,6) = flag;
  1286. WFIFOSET(inter_fd,7);
  1287. return 0;
  1288. }
  1289. int intif_parse_Mail_inboxreceived(int fd)
  1290. {
  1291. struct map_session_data *sd;
  1292. unsigned char flag = RFIFOB(fd,8);
  1293. sd = map_charid2sd(RFIFOL(fd,4));
  1294. if (sd == NULL)
  1295. {
  1296. ShowError("intif_parse_Mail_inboxreceived: char not found %d\n",RFIFOL(fd,4));
  1297. return 1;
  1298. }
  1299. if (RFIFOW(fd,2) - 9 != sizeof(struct mail_data))
  1300. {
  1301. ShowError("intif_parse_Mail_inboxreceived: data size error %d %d\n", RFIFOW(fd,2) - 9, sizeof(struct mail_data));
  1302. return 1;
  1303. }
  1304. //FIXME: this operation is not safe [ultramage]
  1305. memcpy(&sd->mail.inbox, RFIFOP(fd,9), sizeof(struct mail_data));
  1306. if (flag)
  1307. clif_Mail_refreshinbox(sd);
  1308. else
  1309. {
  1310. char output[128];
  1311. sprintf(output, "You have %d new emails (%d unread)", sd->mail.inbox.unchecked, sd->mail.inbox.unread + sd->mail.inbox.unchecked);
  1312. clif_disp_onlyself(sd, output, strlen(output));
  1313. }
  1314. return 0;
  1315. }
  1316. /*------------------------------------------
  1317. * Mail Readed
  1318. *------------------------------------------*/
  1319. int intif_Mail_read(int mail_id)
  1320. {
  1321. if (CheckForCharServer())
  1322. return 0;
  1323. WFIFOHEAD(inter_fd,6);
  1324. WFIFOW(inter_fd,0) = 0x3049;
  1325. WFIFOL(inter_fd,2) = mail_id;
  1326. WFIFOSET(inter_fd,6);
  1327. return 0;
  1328. }
  1329. /*------------------------------------------
  1330. * Get Attachment
  1331. *------------------------------------------*/
  1332. int intif_Mail_getattach(int char_id, int mail_id)
  1333. {
  1334. if (CheckForCharServer())
  1335. return 0;
  1336. WFIFOHEAD(inter_fd,10);
  1337. WFIFOW(inter_fd,0) = 0x304a;
  1338. WFIFOL(inter_fd,2) = char_id;
  1339. WFIFOL(inter_fd,6) = mail_id;
  1340. WFIFOSET(inter_fd, 10);
  1341. return 0;
  1342. }
  1343. int intif_parse_Mail_getattach(int fd)
  1344. {
  1345. struct map_session_data *sd;
  1346. struct item item;
  1347. int zeny = RFIFOL(fd,8);
  1348. sd = map_charid2sd( RFIFOL(fd,4) );
  1349. if (sd == NULL)
  1350. {
  1351. ShowError("intif_parse_Mail_getattach: char not found %d\n",RFIFOL(fd,4));
  1352. return 1;
  1353. }
  1354. if (RFIFOW(fd,2) - 12 != sizeof(struct item))
  1355. {
  1356. ShowError("intif_parse_Mail_getattach: data size error %d %d\n", RFIFOW(fd,2) - 16, sizeof(struct item));
  1357. return 1;
  1358. }
  1359. memcpy(&item, RFIFOP(fd,12), sizeof(struct item));
  1360. mail_getattachment(sd, zeny, &item);
  1361. return 0;
  1362. }
  1363. /*------------------------------------------
  1364. * Delete Message
  1365. *------------------------------------------*/
  1366. int intif_Mail_delete(int char_id, int mail_id)
  1367. {
  1368. if (CheckForCharServer())
  1369. return 0;
  1370. WFIFOHEAD(inter_fd,10);
  1371. WFIFOW(inter_fd,0) = 0x304b;
  1372. WFIFOL(inter_fd,2) = char_id;
  1373. WFIFOL(inter_fd,6) = mail_id;
  1374. WFIFOSET(inter_fd,10);
  1375. return 0;
  1376. }
  1377. int intif_parse_Mail_delete(int fd)
  1378. {
  1379. int char_id = RFIFOL(fd,2);
  1380. int mail_id = RFIFOL(fd,6);
  1381. bool failed = RFIFOB(fd,10);
  1382. struct map_session_data *sd = map_charid2sd(char_id);
  1383. if (sd == NULL)
  1384. {
  1385. ShowError("intif_parse_Mail_delete: char not found %d\n", char_id);
  1386. return 1;
  1387. }
  1388. if (!failed)
  1389. {
  1390. int i;
  1391. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  1392. if( i < MAIL_MAX_INBOX )
  1393. {
  1394. memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message));
  1395. sd->mail.inbox.amount--;
  1396. }
  1397. if( sd->mail.inbox.full )
  1398. intif_Mail_requestinbox(sd->status.char_id, 1); // Free space is available for new mails
  1399. }
  1400. clif_Mail_delete(sd->fd, mail_id, failed);
  1401. return 0;
  1402. }
  1403. /*------------------------------------------
  1404. * Return Message
  1405. *------------------------------------------*/
  1406. int intif_Mail_return(int char_id, int mail_id)
  1407. {
  1408. if (CheckForCharServer())
  1409. return 0;
  1410. WFIFOHEAD(inter_fd,10);
  1411. WFIFOW(inter_fd,0) = 0x304c;
  1412. WFIFOL(inter_fd,2) = char_id;
  1413. WFIFOL(inter_fd,6) = mail_id;
  1414. WFIFOSET(inter_fd,10);
  1415. return 0;
  1416. }
  1417. int intif_parse_Mail_return(int fd)
  1418. {
  1419. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  1420. int mail_id = RFIFOL(fd,6);
  1421. short fail = RFIFOB(fd,10);
  1422. if( sd == NULL )
  1423. {
  1424. ShowError("intif_parse_Mail_return: char not found %d\n",RFIFOL(fd,2));
  1425. return 1;
  1426. }
  1427. if( !fail )
  1428. {
  1429. int i;
  1430. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  1431. if( i < MAIL_MAX_INBOX )
  1432. {
  1433. memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message));
  1434. sd->mail.inbox.amount--;
  1435. }
  1436. if( sd->mail.inbox.full )
  1437. intif_Mail_requestinbox(sd->status.char_id, 1); // Free space is available for new mails
  1438. }
  1439. clif_Mail_return(sd->fd, mail_id, fail);
  1440. return 0;
  1441. }
  1442. /*------------------------------------------
  1443. * Send Mail
  1444. *------------------------------------------*/
  1445. int intif_Mail_send(int account_id, struct mail_message *msg)
  1446. {
  1447. int len = sizeof(struct mail_message) + 8;
  1448. if (CheckForCharServer())
  1449. return 0;
  1450. WFIFOHEAD(inter_fd,len);
  1451. WFIFOW(inter_fd,0) = 0x304d;
  1452. WFIFOW(inter_fd,2) = len;
  1453. WFIFOL(inter_fd,4) = account_id;
  1454. memcpy(WFIFOP(inter_fd,8), msg, sizeof(struct mail_message));
  1455. WFIFOSET(inter_fd,len);
  1456. return 1;
  1457. }
  1458. static void intif_parse_Mail_send(int fd)
  1459. {
  1460. struct mail_message msg;
  1461. struct map_session_data *sd;
  1462. bool fail;
  1463. if( RFIFOW(fd,2) - 4 != sizeof(struct mail_message) )
  1464. {
  1465. ShowError("intif_parse_Mail_send: data size error %d %d\n", RFIFOW(fd,2) - 4, sizeof(struct mail_message));
  1466. return;
  1467. }
  1468. memcpy(&msg, RFIFOP(fd,4), sizeof(struct mail_message));
  1469. fail = (msg.id == 0);
  1470. if( (sd = map_charid2sd(msg.send_id)) )
  1471. {
  1472. if( fail )
  1473. mail_deliveryfail(sd, &msg);
  1474. else
  1475. clif_Mail_send(sd->fd, false);
  1476. }
  1477. if( fail )
  1478. return;
  1479. if( (sd = map_charid2sd(msg.dest_id)) )
  1480. {
  1481. sd->mail.inbox.changed = true;
  1482. clif_Mail_new(sd->fd, msg.id, msg.send_name, msg.title);
  1483. }
  1484. }
  1485. static void intif_parse_Mail_new(int fd)
  1486. {
  1487. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  1488. int mail_id = RFIFOL(fd,6);
  1489. const char* sender_name = (char*)RFIFOP(fd,10);
  1490. const char* title = (char*)RFIFOP(fd,34);
  1491. if( sd == NULL )
  1492. return;
  1493. sd->mail.inbox.changed = true;
  1494. clif_Mail_new(sd->fd, mail_id, sender_name, title);
  1495. }
  1496. /*==========================================
  1497. * AUCTION SYSTEM
  1498. * By Zephyrus
  1499. *==========================================*/
  1500. int intif_Auction_requestlist(int char_id, short type, int price, const char* searchtext, short page)
  1501. {
  1502. int len = NAME_LENGTH + 16;
  1503. if( CheckForCharServer() )
  1504. return 0;
  1505. WFIFOHEAD(inter_fd,len);
  1506. WFIFOW(inter_fd,0) = 0x3050;
  1507. WFIFOW(inter_fd,2) = len;
  1508. WFIFOL(inter_fd,4) = char_id;
  1509. WFIFOW(inter_fd,8) = type;
  1510. WFIFOL(inter_fd,10) = price;
  1511. WFIFOW(inter_fd,14) = page;
  1512. memcpy(WFIFOP(inter_fd,16), searchtext, NAME_LENGTH);
  1513. WFIFOSET(inter_fd,len);
  1514. return 0;
  1515. }
  1516. static void intif_parse_Auction_results(int fd)
  1517. {
  1518. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,4));
  1519. short count = RFIFOW(fd,8), pages = RFIFOW(fd,10);
  1520. if( sd == NULL )
  1521. return;
  1522. clif_Auction_results(sd, count, pages, (char *)RFIFOP(fd,12));
  1523. }
  1524. int intif_Auction_register(struct auction_data *auction)
  1525. {
  1526. int len = sizeof(struct auction_data) + 4;
  1527. if( CheckForCharServer() )
  1528. return 0;
  1529. WFIFOHEAD(inter_fd,len);
  1530. WFIFOW(inter_fd,0) = 0x3051;
  1531. WFIFOW(inter_fd,2) = len;
  1532. memcpy(WFIFOP(inter_fd,4), auction, sizeof(struct auction_data));
  1533. WFIFOSET(inter_fd,len);
  1534. return 1;
  1535. }
  1536. static void intif_parse_Auction_register(int fd)
  1537. {
  1538. struct map_session_data *sd;
  1539. struct auction_data auction;
  1540. if( RFIFOW(fd,2) - 4 != sizeof(struct auction_data) )
  1541. {
  1542. ShowError("intif_parse_Auction_register: data size error %d %d\n", RFIFOW(fd,2) - 4, sizeof(struct auction_data));
  1543. return;
  1544. }
  1545. memcpy(&auction, RFIFOP(fd,4), sizeof(struct auction_data));
  1546. if( (sd = map_charid2sd(auction.seller_id)) == NULL )
  1547. return;
  1548. if( auction.auction_id > 0 )
  1549. clif_Auction_message(sd->fd, 1); // Confirmation Packet ??
  1550. else
  1551. {
  1552. clif_Auction_message(sd->fd, 4);
  1553. pc_additem(sd, &auction.item, auction.item.amount);
  1554. pc_getzeny(sd, auction.hours * battle_config.auction_feeperhour);
  1555. }
  1556. }
  1557. int intif_Auction_cancel(int char_id, unsigned int auction_id)
  1558. {
  1559. if( CheckForCharServer() )
  1560. return 0;
  1561. WFIFOHEAD(inter_fd,10);
  1562. WFIFOW(inter_fd,0) = 0x3052;
  1563. WFIFOL(inter_fd,2) = char_id;
  1564. WFIFOL(inter_fd,6) = auction_id;
  1565. WFIFOSET(inter_fd,10);
  1566. return 0;
  1567. }
  1568. static void intif_parse_Auction_cancel(int fd)
  1569. {
  1570. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  1571. int result = RFIFOB(fd,6);
  1572. if( sd == NULL )
  1573. return;
  1574. switch( result )
  1575. {
  1576. case 0: clif_Auction_message(sd->fd, 2); break;
  1577. case 1: clif_Auction_close(sd->fd, 2); break;
  1578. case 2: clif_Auction_close(sd->fd, 1); break;
  1579. case 3: clif_Auction_message(sd->fd, 3); break;
  1580. }
  1581. }
  1582. int intif_Auction_close(int char_id, unsigned int auction_id)
  1583. {
  1584. if( CheckForCharServer() )
  1585. return 0;
  1586. WFIFOHEAD(inter_fd,10);
  1587. WFIFOW(inter_fd,0) = 0x3053;
  1588. WFIFOL(inter_fd,2) = char_id;
  1589. WFIFOL(inter_fd,6) = auction_id;
  1590. WFIFOSET(inter_fd,10);
  1591. return 0;
  1592. }
  1593. static void intif_parse_Auction_close(int fd)
  1594. {
  1595. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  1596. unsigned char result = RFIFOB(fd,6);
  1597. if( sd == NULL )
  1598. return;
  1599. clif_Auction_close(sd->fd, result);
  1600. if( result == 0 )
  1601. {
  1602. clif_parse_Auction_cancelreg(fd, sd);
  1603. intif_Auction_requestlist(sd->status.char_id, 6, 0, "", 1);
  1604. }
  1605. }
  1606. int intif_Auction_bid(int char_id, const char* name, unsigned int auction_id, int bid)
  1607. {
  1608. int len = 16 + NAME_LENGTH;
  1609. if( CheckForCharServer() )
  1610. return 0;
  1611. WFIFOHEAD(inter_fd,len);
  1612. WFIFOW(inter_fd,0) = 0x3055;
  1613. WFIFOW(inter_fd,2) = len;
  1614. WFIFOL(inter_fd,4) = char_id;
  1615. WFIFOL(inter_fd,8) = auction_id;
  1616. WFIFOL(inter_fd,12) = bid;
  1617. memcpy(WFIFOP(inter_fd,16), name, NAME_LENGTH);
  1618. WFIFOSET(inter_fd,len);
  1619. return 0;
  1620. }
  1621. static void intif_parse_Auction_bid(int fd)
  1622. {
  1623. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  1624. int bid = RFIFOL(fd,6);
  1625. unsigned char result = RFIFOB(fd,10);
  1626. if( sd == NULL )
  1627. return;
  1628. clif_Auction_message(sd->fd, result);
  1629. if( bid > 0 )
  1630. pc_getzeny(sd, bid);
  1631. if( result == 1 )
  1632. { // To update the list, display your buy list
  1633. clif_parse_Auction_cancelreg(fd, sd);
  1634. intif_Auction_requestlist(sd->status.char_id, 7, 0, "", 1);
  1635. }
  1636. }
  1637. // Used to send 'You have won the auction' and 'You failed to won the auction' messages
  1638. static void intif_parse_Auction_message(int fd)
  1639. {
  1640. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  1641. unsigned char result = RFIFOB(fd,6);
  1642. if( sd == NULL )
  1643. return;
  1644. clif_Auction_message(sd->fd, result);
  1645. }
  1646. #endif
  1647. //-----------------------------------------------------------------
  1648. // inter serverからの通信
  1649. // エラーがあれば0(false)を返すこと
  1650. // パケットが処理できれば1,パケット長が足りなければ2を返すこと
  1651. int intif_parse(int fd)
  1652. {
  1653. int packet_len, cmd;
  1654. cmd = RFIFOW(fd,0);
  1655. // パケットのID確認
  1656. if(cmd<0x3800 || cmd>=0x3800+(sizeof(packet_len_table)/sizeof(packet_len_table[0])) ||
  1657. packet_len_table[cmd-0x3800]==0){
  1658. return 0;
  1659. }
  1660. // パケットの長さ確認
  1661. packet_len = packet_len_table[cmd-0x3800];
  1662. if(packet_len==-1){
  1663. if(RFIFOREST(fd)<4)
  1664. return 2;
  1665. packet_len = RFIFOW(fd,2);
  1666. }
  1667. if((int)RFIFOREST(fd)<packet_len){
  1668. return 2;
  1669. }
  1670. // 処理分岐
  1671. switch(cmd){
  1672. case 0x3800:
  1673. if (RFIFOL(fd,4) == 0xFF000000) //Normal announce.
  1674. clif_GMmessage(NULL,(char *) RFIFOP(fd,8),packet_len-8,0);
  1675. else if (RFIFOL(fd,4) == 0xFE000000) //Main chat message [LuzZza]
  1676. clif_MainChatMessage((char *)RFIFOP(fd,8));
  1677. else //Color announce.
  1678. clif_announce(NULL,(char *) RFIFOP(fd,8),packet_len-8,RFIFOL(fd,4),0);
  1679. break;
  1680. case 0x3801: intif_parse_WisMessage(fd); break;
  1681. case 0x3802: intif_parse_WisEnd(fd); break;
  1682. case 0x3803: mapif_parse_WisToGM(fd); break;
  1683. case 0x3804: intif_parse_Registers(fd); break;
  1684. case 0x3806: intif_parse_ChangeNameOk(fd); break;
  1685. case 0x3810: intif_parse_LoadStorage(fd); break;
  1686. case 0x3811: intif_parse_SaveStorage(fd); break;
  1687. case 0x3818: intif_parse_LoadGuildStorage(fd); break;
  1688. case 0x3819: intif_parse_SaveGuildStorage(fd); break;
  1689. case 0x3820: intif_parse_PartyCreated(fd); break;
  1690. case 0x3821: intif_parse_PartyInfo(fd); break;
  1691. case 0x3822: intif_parse_PartyMemberAdded(fd); break;
  1692. case 0x3823: intif_parse_PartyOptionChanged(fd); break;
  1693. case 0x3824: intif_parse_PartyMemberLeaved(fd); break;
  1694. case 0x3825: intif_parse_PartyMove(fd); break;
  1695. case 0x3826: intif_parse_PartyBroken(fd); break;
  1696. case 0x3827: intif_parse_PartyMessage(fd); break;
  1697. case 0x3830: intif_parse_GuildCreated(fd); break;
  1698. case 0x3831: intif_parse_GuildInfo(fd); break;
  1699. case 0x3832: intif_parse_GuildMemberAdded(fd); break;
  1700. case 0x3834: intif_parse_GuildMemberLeaved(fd); break;
  1701. case 0x3835: intif_parse_GuildMemberInfoShort(fd); break;
  1702. case 0x3836: intif_parse_GuildBroken(fd); break;
  1703. case 0x3837: intif_parse_GuildMessage(fd); break;
  1704. case 0x3839: intif_parse_GuildBasicInfoChanged(fd); break;
  1705. case 0x383a: intif_parse_GuildMemberInfoChanged(fd); break;
  1706. case 0x383b: intif_parse_GuildPosition(fd); break;
  1707. case 0x383c: intif_parse_GuildSkillUp(fd); break;
  1708. case 0x383d: intif_parse_GuildAlliance(fd); break;
  1709. case 0x383e: intif_parse_GuildNotice(fd); break;
  1710. case 0x383f: intif_parse_GuildEmblem(fd); break;
  1711. case 0x3840: intif_parse_GuildCastleDataLoad(fd); break;
  1712. case 0x3841: intif_parse_GuildCastleDataSave(fd); break;
  1713. case 0x3842: intif_parse_GuildCastleAllDataLoad(fd); break;
  1714. case 0x3843: intif_parse_GuildMasterChanged(fd); break;
  1715. #ifndef TXT_ONLY
  1716. // Mail System
  1717. case 0x3848: intif_parse_Mail_inboxreceived(fd); break;
  1718. case 0x3849: intif_parse_Mail_new(fd); break;
  1719. case 0x384a: intif_parse_Mail_getattach(fd); break;
  1720. case 0x384b: intif_parse_Mail_delete(fd); break;
  1721. case 0x384c: intif_parse_Mail_return(fd); break;
  1722. case 0x384d: intif_parse_Mail_send(fd); break;
  1723. // Auction System
  1724. case 0x3850: intif_parse_Auction_results(fd); break;
  1725. case 0x3851: intif_parse_Auction_register(fd); break;
  1726. case 0x3852: intif_parse_Auction_cancel(fd); break;
  1727. case 0x3853: intif_parse_Auction_close(fd); break;
  1728. case 0x3854: intif_parse_Auction_message(fd); break;
  1729. case 0x3855: intif_parse_Auction_bid(fd); break;
  1730. #endif
  1731. case 0x3880: intif_parse_CreatePet(fd); break;
  1732. case 0x3881: intif_parse_RecvPetData(fd); break;
  1733. case 0x3882: intif_parse_SavePetOk(fd); break;
  1734. case 0x3883: intif_parse_DeletePetOk(fd); break;
  1735. case 0x3890: intif_parse_CreateHomunculus(fd); break;
  1736. case 0x3891: intif_parse_RecvHomunculusData(fd); break;
  1737. case 0x3892: intif_parse_SaveHomunculusOk(fd); break;
  1738. case 0x3893: intif_parse_DeleteHomunculusOk(fd); break;
  1739. default:
  1740. ShowError("intif_parse : unknown packet %d %x\n",fd,RFIFOW(fd,0));
  1741. return 0;
  1742. }
  1743. // パケット読み飛ばし
  1744. RFIFOSKIP(fd,packet_len);
  1745. return 1;
  1746. }