intif.c 54 KB

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