intif.c 53 KB

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