intif.cpp 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "intif.hpp"
  4. #include <stdlib.h>
  5. #include "../common/malloc.hpp"
  6. #include "../common/mmo.hpp"
  7. #include "../common/nullpo.hpp"
  8. #include "../common/showmsg.hpp"
  9. #include "../common/socket.hpp"
  10. #include "../common/strlib.hpp"
  11. #include "../common/timer.hpp"
  12. #include "achievement.hpp"
  13. #include "battle.hpp"
  14. #include "chrif.hpp"
  15. #include "clan.hpp"
  16. #include "clif.hpp"
  17. #include "elemental.hpp"
  18. #include "guild.hpp"
  19. #include "homunculus.hpp"
  20. #include "log.hpp"
  21. #include "mail.hpp"
  22. #include "map.hpp"
  23. #include "mercenary.hpp"
  24. #include "party.hpp"
  25. #include "pc.hpp"
  26. #include "pc_groups.hpp"
  27. #include "pet.hpp"
  28. #include "quest.hpp"
  29. #include "status.hpp"
  30. #include "storage.hpp"
  31. /// Received packet Lengths from inter-server
  32. static const int packet_len_table[] = {
  33. -1,-1,27,-1, -1, 0,37,-1, 10+NAME_LENGTH,-1, 0, 0, 0, 0, 0, 0, //0x3800-0x380f
  34. 0, 0, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810
  35. 39,-1,15,15, 15+NAME_LENGTH,19, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3820
  36. 10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830
  37. -1,10, 0,18, 0, 0, 0, 0, -1,75,-1,11, 11,-1, 38, 0, //0x3840
  38. -1,-1, 7, 7, 7,11, 8,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus] itembound[Akinari]
  39. -1, 7,-1, 7, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin] [Inkfish] / Achievements [Aleos]
  40. -1, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 3, 3, 0, //0x3870 Mercenaries [Zephyrus] / Elemental [pakpil]
  41. 12,-1, 7, 3, 0, 0, 0, 0, 0, 0,-1, 9, -1, 0, 0, 0, //0x3880 Pet System, Storages
  42. -1,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3890 Homunculus [albator]
  43. -1,-1, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x38A0 Clans
  44. };
  45. extern int char_fd; // inter server Fd used for char_fd
  46. #define inter_fd char_fd // alias
  47. //-----------------------------------------------------------------
  48. // Send to inter server
  49. /**
  50. * Verify the char-serv is up and running
  51. * @return 0=no, 1=ok
  52. */
  53. int CheckForCharServer(void)
  54. {
  55. return ((char_fd <= 0) || session[char_fd] == NULL || session[char_fd]->wdata == NULL);
  56. }
  57. /**
  58. * Get sd from pc_db (map_id2db) or auth_db (in case if parsing packet from inter-server when sd not added to pc_db yet)
  59. * @param account_id
  60. * @param char_id
  61. * @return sd Found sd or NULL if not found
  62. */
  63. struct map_session_data *inter_search_sd(uint32 account_id, uint32 char_id)
  64. {
  65. struct map_session_data *sd = NULL;
  66. struct auth_node *node = chrif_auth_check(account_id, char_id, ST_LOGIN);
  67. if (node)
  68. sd = node->sd;
  69. else
  70. sd = map_id2sd(account_id);
  71. return sd;
  72. }
  73. /**
  74. * Request the char-serv to create a pet (to register it actually)
  75. * @param account_id
  76. * @param char_id
  77. * @param pet_class
  78. * @param pet_lv
  79. * @param pet_egg_id
  80. * @param pet_equip
  81. * @param intimate
  82. * @param hungry
  83. * @param rename_flag
  84. * @param incubate
  85. * @param pet_name
  86. * @return
  87. */
  88. int intif_create_pet(uint32 account_id,uint32 char_id,short pet_class,short pet_lv, t_itemid pet_egg_id, t_itemid pet_equip,short intimate,short hungry,char rename_flag,char incubate,const char *pet_name)
  89. {
  90. if (CheckForCharServer())
  91. return 0;
  92. WFIFOHEAD(inter_fd, 28 + NAME_LENGTH);
  93. WFIFOW(inter_fd, 0) = 0x3080;
  94. WFIFOL(inter_fd, 2) = account_id;
  95. WFIFOL(inter_fd, 6) = char_id;
  96. WFIFOW(inter_fd, 10) = pet_class;
  97. WFIFOW(inter_fd, 12) = pet_lv;
  98. WFIFOL(inter_fd, 14) = pet_egg_id;
  99. WFIFOL(inter_fd, 18) = pet_equip;
  100. WFIFOW(inter_fd, 22) = intimate;
  101. WFIFOW(inter_fd, 24) = hungry;
  102. WFIFOB(inter_fd, 26) = rename_flag;
  103. WFIFOB(inter_fd, 27) = incubate;
  104. memcpy(WFIFOP(inter_fd, 28), pet_name, NAME_LENGTH);
  105. WFIFOSET(inter_fd, 28 + NAME_LENGTH);
  106. return 1;
  107. }
  108. /**
  109. * Request char-serv to load a pet from persistence (SQL)
  110. * @param account_id
  111. * @param char_id
  112. * @param pet_id
  113. * @return
  114. */
  115. int intif_request_petdata(uint32 account_id,uint32 char_id,int pet_id)
  116. {
  117. if (CheckForCharServer())
  118. return 0;
  119. WFIFOHEAD(inter_fd, 14);
  120. WFIFOW(inter_fd,0) = 0x3081;
  121. WFIFOL(inter_fd,2) = account_id;
  122. WFIFOL(inter_fd,6) = char_id;
  123. WFIFOL(inter_fd,10) = pet_id;
  124. WFIFOSET(inter_fd,14);
  125. return 1;
  126. }
  127. /**
  128. * Request char-serv to save a pet in persistence (SQL)
  129. * @param account_id
  130. * @param p
  131. * @return
  132. */
  133. int intif_save_petdata(uint32 account_id,struct s_pet *p)
  134. {
  135. if (CheckForCharServer())
  136. return 0;
  137. WFIFOHEAD(inter_fd, sizeof(struct s_pet) + 8);
  138. WFIFOW(inter_fd,0) = 0x3082;
  139. WFIFOW(inter_fd,2) = sizeof(struct s_pet) + 8;
  140. WFIFOL(inter_fd,4) = account_id;
  141. memcpy(WFIFOP(inter_fd,8),p,sizeof(struct s_pet));
  142. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  143. return 1;
  144. }
  145. /**
  146. * Request char-serv to delete the entry for this pet-char association
  147. * @param pet_id
  148. * @return
  149. */
  150. int intif_delete_petdata(int pet_id)
  151. {
  152. if (CheckForCharServer())
  153. return 0;
  154. WFIFOHEAD(inter_fd,6);
  155. WFIFOW(inter_fd,0) = 0x3083;
  156. WFIFOL(inter_fd,2) = pet_id;
  157. WFIFOSET(inter_fd,6);
  158. return 1;
  159. }
  160. /**
  161. * Ask char-serv to rename a CHAR (PC|PET|HOM)
  162. * @param sd
  163. * @param type
  164. * @param name
  165. * @return
  166. */
  167. int intif_rename(struct map_session_data *sd, int type, char *name)
  168. {
  169. if (CheckForCharServer())
  170. return 0;
  171. WFIFOHEAD(inter_fd,NAME_LENGTH+12);
  172. WFIFOW(inter_fd,0) = 0x3006;
  173. WFIFOL(inter_fd,2) = sd->status.account_id;
  174. WFIFOL(inter_fd,6) = sd->status.char_id;
  175. WFIFOB(inter_fd,10) = type; //Type: 0 - PC, 1 - PET, 2 - HOM
  176. memcpy(WFIFOP(inter_fd,11),name, NAME_LENGTH);
  177. WFIFOSET(inter_fd,NAME_LENGTH+12);
  178. return 1;
  179. }
  180. /**
  181. * Request to broadcast a message via char-serv to reach all map-serv connected
  182. * @param mes : Message to send
  183. * @param len ; Size of the message
  184. * @param type : Color of msg
  185. * @return 0=error occured, 1=msg sent
  186. */
  187. int intif_broadcast(const char* mes, int len, int type)
  188. {
  189. nullpo_ret(mes);
  190. if (len < 2)
  191. return 0;
  192. int lp = (type|BC_COLOR_MASK) ? 4 : 0;
  193. // Send to the local players
  194. clif_broadcast(NULL, mes, len, type, ALL_CLIENT);
  195. if (CheckForCharServer())
  196. return 0;
  197. if (other_mapserver_count < 1)
  198. return 0; //No need to send.
  199. WFIFOHEAD(inter_fd, 16 + lp + len);
  200. WFIFOW(inter_fd,0) = 0x3000;
  201. WFIFOW(inter_fd,2) = 16 + lp + len;
  202. WFIFOL(inter_fd,4) = 0xFF000000; // 0xFF000000 color signals standard broadcast
  203. WFIFOW(inter_fd,8) = 0; // fontType not used with standard broadcast
  204. WFIFOW(inter_fd,10) = 0; // fontSize not used with standard broadcast
  205. WFIFOW(inter_fd,12) = 0; // fontAlign not used with standard broadcast
  206. WFIFOW(inter_fd,14) = 0; // fontY not used with standard broadcast
  207. if (type|BC_BLUE)
  208. 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.
  209. else if (type|BC_WOE)
  210. WFIFOL(inter_fd,16) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  211. memcpy(WFIFOP(inter_fd,16 + lp), mes, len);
  212. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  213. return 1;
  214. }
  215. /**
  216. * Request to char-serv to broadcast a message to all map-serv
  217. * @param mes : Message to brodcast
  218. * @param len : Size of message
  219. * @param fontColor : color to display message
  220. * @param fontType :
  221. * @param fontSize :
  222. * @param fontAlign :
  223. * @param fontY :
  224. * @return 0=not send to char-serv, 1=send to char-serv
  225. */
  226. int intif_broadcast2(const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY)
  227. {
  228. nullpo_ret(mes);
  229. if (len < 2)
  230. return 0;
  231. // Send to the local players
  232. clif_broadcast2(NULL, mes, len, fontColor, fontType, fontSize, fontAlign, fontY, ALL_CLIENT);
  233. if (CheckForCharServer())
  234. return 0;
  235. if (other_mapserver_count < 1)
  236. return 0; //No need to send.
  237. WFIFOHEAD(inter_fd, 16 + len);
  238. WFIFOW(inter_fd,0) = 0x3000;
  239. WFIFOW(inter_fd,2) = 16 + len;
  240. WFIFOL(inter_fd,4) = fontColor;
  241. WFIFOW(inter_fd,8) = fontType;
  242. WFIFOW(inter_fd,10) = fontSize;
  243. WFIFOW(inter_fd,12) = fontAlign;
  244. WFIFOW(inter_fd,14) = fontY;
  245. memcpy(WFIFOP(inter_fd,16), mes, len);
  246. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  247. return 1;
  248. }
  249. /**
  250. * send a message using the main chat system
  251. * @param sd : Player source of message
  252. * @param message : the message to sent
  253. * @return
  254. */
  255. int intif_main_message(struct map_session_data* sd, const char* message)
  256. {
  257. char output[256];
  258. nullpo_ret(sd);
  259. // format the message for main broadcasting
  260. snprintf( output, sizeof(output), msg_txt(sd,386), sd->status.name, message );
  261. // send the message using the inter-server broadcast service
  262. intif_broadcast2( output, strlen(output) + 1, 0xFE000000, 0, 0, 0, 0 );
  263. // log the chat message
  264. log_chat( LOG_CHAT_MAINCHAT, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message );
  265. return 1;
  266. }
  267. /**
  268. * Request char-serv to transmit a whisper message. (Private message from one player to another)
  269. * (player not found on this server)
  270. * @param sd : Player ending message
  271. * @param nick : Name of receiver
  272. * @param mes : Message to send
  273. * @param mes_len : Size of message
  274. * @return 0=Message not send, 1=Message send
  275. */
  276. int intif_wis_message(struct map_session_data *sd, char *nick, char *mes, int mes_len)
  277. {
  278. int headersize = 8 + 2 * NAME_LENGTH;
  279. nullpo_ret(sd);
  280. if (CheckForCharServer())
  281. return 0;
  282. if (other_mapserver_count < 1)
  283. { //Character not found.
  284. clif_wis_end(sd->fd, 1);
  285. return 0;
  286. }
  287. WFIFOHEAD(inter_fd,mes_len + headersize);
  288. WFIFOW(inter_fd,0) = 0x3001;
  289. WFIFOW(inter_fd,2) = mes_len + headersize;
  290. WFIFOL(inter_fd,4) = pc_get_group_level(sd);
  291. safestrncpy(WFIFOCP(inter_fd,8), sd->status.name, NAME_LENGTH);
  292. safestrncpy(WFIFOCP(inter_fd,8+NAME_LENGTH), nick, NAME_LENGTH);
  293. safestrncpy(WFIFOCP(inter_fd,8+2*NAME_LENGTH), mes, mes_len);
  294. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  295. if (battle_config.etc_log)
  296. ShowInfo("intif_wis_message from %s to %s (message: '%s')\n", sd->status.name, nick, mes);
  297. return 1;
  298. }
  299. /**
  300. * Inform the char-serv of the result of the whisper
  301. * @param id : Character ID
  302. * @param flag : 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
  303. * @return 0=no char-serv connected, 1=msg sent
  304. */
  305. int intif_wis_reply(int id, int flag)
  306. {
  307. if (CheckForCharServer())
  308. return 0;
  309. WFIFOHEAD(inter_fd,7);
  310. WFIFOW(inter_fd,0) = 0x3002;
  311. WFIFOL(inter_fd,2) = id;
  312. WFIFOB(inter_fd,6) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
  313. WFIFOSET(inter_fd,7);
  314. if (battle_config.etc_log)
  315. ShowInfo("intif_wis_reply: id: %d, flag:%d\n", id, flag);
  316. return 1;
  317. }
  318. /**
  319. * Whisper message from player to all GM from map-server to inter-server (@request)
  320. * @param wisp_name
  321. * @param permission
  322. * @param mes
  323. * @return 0:no char-serv connected, 1:transfered
  324. */
  325. int intif_wis_message_to_gm(char *wisp_name, int permission, char *mes)
  326. {
  327. int mes_len;
  328. if (CheckForCharServer())
  329. return 0;
  330. mes_len = strlen(mes) + 1; // + null
  331. WFIFOHEAD(inter_fd, mes_len + 8 + NAME_LENGTH);
  332. WFIFOW(inter_fd,0) = 0x3003;
  333. WFIFOW(inter_fd,2) = mes_len + 32;
  334. safestrncpy(WFIFOCP(inter_fd,4), wisp_name, NAME_LENGTH);
  335. WFIFOL(inter_fd,4+NAME_LENGTH) = permission;
  336. safestrncpy(WFIFOCP(inter_fd,8+NAME_LENGTH), mes, mes_len);
  337. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  338. if (battle_config.etc_log)
  339. ShowNotice("intif_wis_message_to_gm: from: '%s', required permission: %d, message: '%s'.\n", wisp_name, permission, mes);
  340. return 1;
  341. }
  342. /**
  343. * Request for saving registry values.
  344. * @param sd : Player to save registry
  345. * @return 1=msg sent, -1=error
  346. */
  347. int intif_saveregistry(struct map_session_data *sd)
  348. {
  349. DBIterator *iter;
  350. DBKey key;
  351. DBData *data;
  352. int plen = 0;
  353. size_t len;
  354. if (CheckForCharServer() || !sd->regs.vars)
  355. return -1;
  356. WFIFOHEAD(inter_fd, 60000 + 300);
  357. WFIFOW(inter_fd,0) = 0x3004;
  358. // 0x2 = length (set later)
  359. WFIFOL(inter_fd,4) = sd->status.account_id;
  360. WFIFOL(inter_fd,8) = sd->status.char_id;
  361. WFIFOW(inter_fd,12) = 0; // count
  362. plen = 14;
  363. iter = db_iterator(sd->regs.vars);
  364. for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) {
  365. const char *varname = NULL;
  366. struct script_reg_state *src = NULL;
  367. bool lValid = false;
  368. if( data->type != DB_DATA_PTR ) // it's a @number
  369. continue;
  370. varname = get_str(script_getvarid(key.i64));
  371. if( varname[0] == '@' ) // @string$ can get here, so we skip
  372. continue;
  373. src = (struct script_reg_state *)db_data2ptr(data);
  374. if( !src->update )
  375. continue;
  376. src->update = false;
  377. lValid = script_check_RegistryVariableLength(0,varname,&len);
  378. ++len;
  379. if (!lValid) { //this is sql colum size, must be retrive from config
  380. ShowError("intif_saveregistry: Variable name length is too long (aid: %d, cid: %d): '%s' sz=%" PRIuPTR "\n", sd->status.account_id, sd->status.char_id, varname, len);
  381. continue;
  382. }
  383. WFIFOB(inter_fd, plen) = (unsigned char)len; // won't be higher; the column size is 32
  384. plen += 1;
  385. safestrncpy(WFIFOCP(inter_fd,plen), varname, len); //the key
  386. plen += len;
  387. WFIFOL(inter_fd, plen) = script_getvaridx(key.i64);
  388. plen += 4;
  389. if( src->type ) {
  390. struct script_reg_str *p = (struct script_reg_str *)src;
  391. WFIFOB(inter_fd, plen) = p->value ? 2 : 3; //var type
  392. plen += 1;
  393. if( p->value ) {
  394. lValid = script_check_RegistryVariableLength(1,p->value,&len);
  395. ++len;
  396. if ( !lValid ) { // error can't be higher; the column size is 254. (nb the transmission limit with be fixed with protobuf revamp)
  397. ShowDebug( "intif_saveregistry: Variable value length is too long (aid: %d, cid: %d): '%s' sz=%" PRIuPTR " to be saved with current system and will be truncated\n",sd->status.account_id, sd->status.char_id,p->value,len);
  398. len = 254;
  399. p->value[len - 1] = '\0'; //this is backward for old char-serv but new one doesn't need this
  400. }
  401. WFIFOB(inter_fd, plen) = (uint8)len;
  402. plen += 1;
  403. safestrncpy(WFIFOCP(inter_fd,plen), p->value, len);
  404. plen += len;
  405. } else {
  406. script_reg_destroy_single(sd,key.i64,&p->flag);
  407. }
  408. } else {
  409. struct script_reg_num *p = (struct script_reg_num *)src;
  410. WFIFOB(inter_fd, plen) = p->value ? 0 : 1;
  411. plen += 1;
  412. if( p->value ) {
  413. WFIFOQ(inter_fd, plen) = p->value;
  414. plen += 8;
  415. } else {
  416. script_reg_destroy_single(sd,key.i64,&p->flag);
  417. }
  418. }
  419. WFIFOW(inter_fd,12) += 1;
  420. if( plen > 60000 ) {
  421. WFIFOW(inter_fd, 2) = plen;
  422. WFIFOSET(inter_fd, plen);
  423. // prepare follow up
  424. WFIFOHEAD(inter_fd, 60000 + 300);
  425. WFIFOW(inter_fd,0) = 0x3004;
  426. // 0x2 = length (set later)
  427. WFIFOL(inter_fd,4) = sd->status.account_id;
  428. WFIFOL(inter_fd,8) = sd->status.char_id;
  429. WFIFOW(inter_fd,12) = 0; // count
  430. plen = 14;
  431. }
  432. }
  433. dbi_destroy(iter);
  434. WFIFOW(inter_fd, 2) = plen;
  435. WFIFOSET(inter_fd, plen);
  436. sd->vars_dirty = false;
  437. return 0;
  438. }
  439. /**
  440. * Request the registries for this player.
  441. * @param sd : Player to load registry
  442. * @param flag : Type of registry to load, &1=acc (login-serv), &2=acc (char-serv), &4=char
  443. * @return
  444. */
  445. int intif_request_registry(struct map_session_data *sd, int flag)
  446. {
  447. nullpo_ret(sd);
  448. if (CheckForCharServer())
  449. return 0;
  450. WFIFOHEAD(inter_fd,13);
  451. WFIFOW(inter_fd,0) = 0x3005;
  452. WFIFOL(inter_fd,2) = sd->status.account_id;
  453. WFIFOL(inter_fd,6) = sd->status.char_id;
  454. WFIFOB(inter_fd,10) = (flag&1?1:0); //Request Acc Reg 2 (from login-serv))
  455. WFIFOB(inter_fd,11) = (flag&2?1:0); //Request Acc Reg (from char-serv)
  456. WFIFOB(inter_fd,12) = (flag&4?1:0); //Request Char Reg
  457. WFIFOSET(inter_fd,13);
  458. return 1;
  459. }
  460. /**
  461. * Request to load guild storage from char-serv
  462. * @param account_id: Player account identification
  463. * @param guild_id: Guild of player
  464. * @return false - error, true - message sent
  465. */
  466. bool intif_request_guild_storage(uint32 account_id, int guild_id)
  467. {
  468. if (CheckForCharServer())
  469. return false;
  470. WFIFOHEAD(inter_fd,10);
  471. WFIFOW(inter_fd,0) = 0x3018;
  472. WFIFOL(inter_fd,2) = account_id;
  473. WFIFOL(inter_fd,6) = guild_id;
  474. WFIFOSET(inter_fd,10);
  475. return true;
  476. }
  477. /**
  478. * Request to save guild storage
  479. * @param account_id: account requesting the save
  480. * @param gstor: Guild storage struct to save
  481. * @return false - error, true - message sent
  482. */
  483. bool intif_send_guild_storage(uint32 account_id, struct s_storage *gstor)
  484. {
  485. if (CheckForCharServer())
  486. return false;
  487. WFIFOHEAD(inter_fd,sizeof(struct s_storage)+12);
  488. WFIFOW(inter_fd,0) = 0x3019;
  489. WFIFOW(inter_fd,2) = (unsigned short)sizeof(struct s_storage)+12;
  490. WFIFOL(inter_fd,4) = account_id;
  491. WFIFOL(inter_fd,8) = gstor->id;
  492. memcpy( WFIFOP(inter_fd,12),gstor, sizeof(struct s_storage) );
  493. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  494. return true;
  495. }
  496. /**
  497. * Party creation request
  498. * @param member : Struct of 1 party member
  499. * @param name : Party name
  500. * @param item : item pickup rule
  501. * @param item2 : item share rule
  502. * @return 0=error, 1=msg sent
  503. */
  504. int intif_create_party(struct party_member *member,char *name,int item,int item2)
  505. {
  506. if (CheckForCharServer())
  507. return 0;
  508. nullpo_ret(member);
  509. WFIFOHEAD(inter_fd, 6+NAME_LENGTH+sizeof(struct party_member));
  510. WFIFOW(inter_fd,0) = 0x3020;
  511. WFIFOW(inter_fd,2) = 6+NAME_LENGTH+sizeof(struct party_member);
  512. memcpy(WFIFOP(inter_fd,4),name, NAME_LENGTH);
  513. WFIFOB(inter_fd,28)= item;
  514. WFIFOB(inter_fd,29)= item2;
  515. memcpy(WFIFOP(inter_fd,30), member, sizeof(struct party_member));
  516. WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
  517. return 1;
  518. }
  519. /**
  520. * Party information request
  521. * @param party_id : Party id to request info
  522. * @param char_id : Player id requesting
  523. * @return 0=error, 1=msg sent
  524. */
  525. int intif_request_partyinfo(int party_id, uint32 char_id)
  526. {
  527. if (CheckForCharServer())
  528. return 0;
  529. WFIFOHEAD(inter_fd,10);
  530. WFIFOW(inter_fd,0) = 0x3021;
  531. WFIFOL(inter_fd,2) = party_id;
  532. WFIFOL(inter_fd,6) = char_id;
  533. WFIFOSET(inter_fd,10);
  534. return 1;
  535. }
  536. /**
  537. * Request to add a member to party
  538. * @param party_id : Party to add member to
  539. * @param member : member to add to party
  540. * @return
  541. */
  542. int intif_party_addmember(int party_id,struct party_member *member)
  543. {
  544. if (CheckForCharServer())
  545. return 0;
  546. WFIFOHEAD(inter_fd,8+sizeof(struct party_member));
  547. WFIFOW(inter_fd,0)=0x3022;
  548. WFIFOW(inter_fd,2)=8+sizeof(struct party_member);
  549. WFIFOL(inter_fd,4)=party_id;
  550. memcpy(WFIFOP(inter_fd,8),member,sizeof(struct party_member));
  551. WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
  552. return 1;
  553. }
  554. /**
  555. * Request to change party configuration (exp,item share)
  556. * @param party_id : Party to alter
  557. * @param account_id : account requesting change
  558. * @param exp : sharing exp option
  559. * @param item : sharing item option
  560. * @return 0=error, 1=msg sent
  561. */
  562. int intif_party_changeoption(int party_id,uint32 account_id,int exp,int item)
  563. {
  564. if (CheckForCharServer())
  565. return 0;
  566. WFIFOHEAD(inter_fd,14);
  567. WFIFOW(inter_fd,0)=0x3023;
  568. WFIFOL(inter_fd,2)=party_id;
  569. WFIFOL(inter_fd,6)=account_id;
  570. WFIFOW(inter_fd,10)=exp;
  571. WFIFOW(inter_fd,12)=item;
  572. WFIFOSET(inter_fd,14);
  573. return 1;
  574. }
  575. /**
  576. * Ask the char-serv to make aid,cid quit party
  577. * @param party_id : Party to leave
  578. * @param account_id : aid of player to leave
  579. * @param char_id : cid of player to leave
  580. * @return 0:char-serv disconected, 1=msg sent
  581. */
  582. int intif_party_leave(int party_id, uint32 account_id, uint32 char_id, const char *name, enum e_party_member_withdraw type)
  583. {
  584. if (CheckForCharServer())
  585. return 0;
  586. WFIFOHEAD(inter_fd,15+NAME_LENGTH);
  587. WFIFOW(inter_fd,0) = 0x3024;
  588. WFIFOL(inter_fd,2) = party_id;
  589. WFIFOL(inter_fd,6) = account_id;
  590. WFIFOL(inter_fd,10) = char_id;
  591. memcpy(WFIFOCP(inter_fd,14), name, NAME_LENGTH);
  592. WFIFOB(inter_fd,14+NAME_LENGTH) = type;
  593. WFIFOSET(inter_fd,15+NAME_LENGTH);
  594. return 1;
  595. }
  596. /**
  597. * Inform char-serv that a member as quit/lvlup change map, therefore changing party state
  598. * @param sd : Player that moved
  599. * @param online : If the player will stay online or no
  600. * @return 0=error, 1=msg sent
  601. */
  602. int intif_party_changemap(struct map_session_data *sd,int online)
  603. {
  604. int16 m, mapindex;
  605. if (CheckForCharServer())
  606. return 0;
  607. if(!sd)
  608. return 0;
  609. if ((m = map_mapindex2mapid(sd->mapindex)) >= 0) {
  610. struct map_data *mapdata = map_getmapdata(m);
  611. if (mapdata->instance_id)
  612. mapindex = map_getmapdata(mapdata->instance_src_map)->index;
  613. else
  614. mapindex = sd->mapindex;
  615. } else
  616. mapindex = sd->mapindex;
  617. WFIFOHEAD(inter_fd,19);
  618. WFIFOW(inter_fd,0)=0x3025;
  619. WFIFOL(inter_fd,2)=sd->status.party_id;
  620. WFIFOL(inter_fd,6)=sd->status.account_id;
  621. WFIFOL(inter_fd,10)=sd->status.char_id;
  622. WFIFOW(inter_fd,14)=mapindex;
  623. WFIFOB(inter_fd,16)=online;
  624. WFIFOW(inter_fd,17)=sd->status.base_level;
  625. WFIFOSET(inter_fd,19);
  626. return 1;
  627. }
  628. /**
  629. * Request breaking party
  630. * @param party_id : Party to delete
  631. * @return 0=error, 1=msg sent
  632. */
  633. int intif_break_party(int party_id)
  634. {
  635. if (CheckForCharServer())
  636. return 0;
  637. WFIFOHEAD(inter_fd,6);
  638. WFIFOW(inter_fd,0)=0x3026;
  639. WFIFOL(inter_fd,2)=party_id;
  640. WFIFOSET(inter_fd,6);
  641. return 0;
  642. }
  643. //
  644. /**
  645. * Request sending party chat
  646. * (we using this in case we have multiple map-serv attached
  647. * to be sure all party get the message)
  648. * @param party_id : Party identification
  649. * @param account_id : Player sending the message
  650. * @param mes : Message to send
  651. * @param len : Size of the message
  652. * @return 0=error, 1=msg sent
  653. */
  654. int intif_party_message(int party_id,uint32 account_id,const char *mes,int len)
  655. {
  656. if (CheckForCharServer())
  657. return 0;
  658. if (other_mapserver_count < 1)
  659. return 0; //No need to send.
  660. WFIFOHEAD(inter_fd,len + 12);
  661. WFIFOW(inter_fd,0)=0x3027;
  662. WFIFOW(inter_fd,2)=len+12;
  663. WFIFOL(inter_fd,4)=party_id;
  664. WFIFOL(inter_fd,8)=account_id;
  665. memcpy(WFIFOP(inter_fd,12),mes,len);
  666. WFIFOSET(inter_fd,len+12);
  667. return 1;
  668. }
  669. /**
  670. * Request a new leader for party
  671. * @param party_id : Party to alter
  672. * @param account_id : player to set as new leader
  673. * @param char_id : player to set as new leader
  674. * @return 0=error, 1=msg sent
  675. */
  676. int intif_party_leaderchange(int party_id,uint32 account_id,uint32 char_id)
  677. {
  678. if (CheckForCharServer())
  679. return 0;
  680. WFIFOHEAD(inter_fd,14);
  681. WFIFOW(inter_fd,0)=0x3029;
  682. WFIFOL(inter_fd,2)=party_id;
  683. WFIFOL(inter_fd,6)=account_id;
  684. WFIFOL(inter_fd,10)=char_id;
  685. WFIFOSET(inter_fd,14);
  686. return 1;
  687. }
  688. /**
  689. * Request to update party share level
  690. * @param share_lvl : Max level number of difference to share exp
  691. * @return 0=error, 1=msg sent
  692. */
  693. int intif_party_sharelvlupdate(unsigned int share_lvl)
  694. {
  695. if (CheckForCharServer())
  696. return 0;
  697. WFIFOHEAD(inter_fd,6);
  698. WFIFOW(inter_fd,0)=0x302A;
  699. WFIFOL(inter_fd,2)=share_lvl;
  700. WFIFOSET(inter_fd,6);
  701. return 1;
  702. }
  703. /**
  704. * Request a Guild creation
  705. * @param name : Name of the guild
  706. * @param master : Guild_member info of master
  707. * @return 0=error, 1=msg_sent
  708. */
  709. int intif_guild_create(const char *name,const struct guild_member *master)
  710. {
  711. if (CheckForCharServer())
  712. return 0;
  713. nullpo_ret(master);
  714. WFIFOHEAD(inter_fd,sizeof(struct guild_member)+(8+NAME_LENGTH));
  715. WFIFOW(inter_fd,0)=0x3030;
  716. WFIFOW(inter_fd,2)=sizeof(struct guild_member)+(8+NAME_LENGTH);
  717. WFIFOL(inter_fd,4)=master->account_id;
  718. memcpy(WFIFOP(inter_fd,8),name,NAME_LENGTH);
  719. memcpy(WFIFOP(inter_fd,8+NAME_LENGTH),master,sizeof(struct guild_member));
  720. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  721. return 1;
  722. }
  723. /**
  724. * Request Guild information
  725. * @param guild_id : guild to get info from
  726. * @return 0=error, 1=msg_sent
  727. */
  728. int intif_guild_request_info(int guild_id)
  729. {
  730. if (CheckForCharServer())
  731. return 0;
  732. WFIFOHEAD(inter_fd,6);
  733. WFIFOW(inter_fd,0) = 0x3031;
  734. WFIFOL(inter_fd,2) = guild_id;
  735. WFIFOSET(inter_fd,6);
  736. return 1;
  737. }
  738. /**
  739. * Request to add member to the guild
  740. * @param guild_id : Guild to alter
  741. * @param m : Member to add to the guild
  742. * @return 0=error, 1=msg_sent
  743. */
  744. int intif_guild_addmember(int guild_id,struct guild_member *m)
  745. {
  746. if (CheckForCharServer())
  747. return 0;
  748. WFIFOHEAD(inter_fd,sizeof(struct guild_member)+8);
  749. WFIFOW(inter_fd,0) = 0x3032;
  750. WFIFOW(inter_fd,2) = sizeof(struct guild_member)+8;
  751. WFIFOL(inter_fd,4) = guild_id;
  752. memcpy(WFIFOP(inter_fd,8),m,sizeof(struct guild_member));
  753. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  754. return 1;
  755. }
  756. /**
  757. * Request a new leader for guild
  758. * @param guild_id : guild to alter
  759. * @param name : name of the new master
  760. * @param len : size of the name
  761. * @return 0=error, 1=msg_sent
  762. */
  763. int intif_guild_change_gm(int guild_id, const char* name, int len)
  764. {
  765. if (CheckForCharServer())
  766. return 0;
  767. WFIFOHEAD(inter_fd, len + 8);
  768. WFIFOW(inter_fd, 0)=0x3033;
  769. WFIFOW(inter_fd, 2)=len+8;
  770. WFIFOL(inter_fd, 4)=guild_id;
  771. memcpy(WFIFOP(inter_fd,8),name,len);
  772. WFIFOSET(inter_fd,len+8);
  773. return 1;
  774. }
  775. /**
  776. * Request to make a player leave a guild
  777. * @param guild_id : guild to alter
  778. * @param account_id : player aid to kick
  779. * @param char_id : player cid to kick
  780. * @param flag : 0:normal quit, 1=expulsion
  781. * @param mes : quitting message (max 40)
  782. * @return 0=error, 1=msg_sent
  783. */
  784. int intif_guild_leave(int guild_id,uint32 account_id,uint32 char_id,int flag,const char *mes)
  785. {
  786. if (CheckForCharServer())
  787. return 0;
  788. WFIFOHEAD(inter_fd, 55);
  789. WFIFOW(inter_fd, 0) = 0x3034;
  790. WFIFOL(inter_fd, 2) = guild_id;
  791. WFIFOL(inter_fd, 6) = account_id;
  792. WFIFOL(inter_fd,10) = char_id;
  793. WFIFOB(inter_fd,14) = flag;
  794. safestrncpy(WFIFOCP(inter_fd,15),mes,40);
  795. WFIFOSET(inter_fd,55);
  796. return 1;
  797. }
  798. /**
  799. * Update request / Lv online status of the guild members
  800. * @param guild_id : guild to alter
  801. * @param account_id : player aid to alter
  802. * @param char_id : player cid to alter
  803. * @param online : does the player is online (or will stay online)
  804. * @param lv : player lv
  805. * @param class_ : player class
  806. * @return 0=error, 1=msg_sent
  807. */
  808. int intif_guild_memberinfoshort(int guild_id,uint32 account_id,uint32 char_id,int online,int lv,int class_)
  809. {
  810. if (CheckForCharServer())
  811. return 0;
  812. WFIFOHEAD(inter_fd, 19);
  813. WFIFOW(inter_fd, 0) = 0x3035;
  814. WFIFOL(inter_fd, 2) = guild_id;
  815. WFIFOL(inter_fd, 6) = account_id;
  816. WFIFOL(inter_fd,10) = char_id;
  817. WFIFOB(inter_fd,14) = online;
  818. WFIFOW(inter_fd,15) = lv;
  819. WFIFOW(inter_fd,17) = class_;
  820. WFIFOSET(inter_fd,19);
  821. return 1;
  822. }
  823. /**
  824. * Guild disbanded notification
  825. * @param guild_id : guild to disband
  826. * @return 0=error, 1=msg_sent
  827. */
  828. int intif_guild_break(int guild_id)
  829. {
  830. if (CheckForCharServer())
  831. return 0;
  832. WFIFOHEAD(inter_fd, 6);
  833. WFIFOW(inter_fd, 0) = 0x3036;
  834. WFIFOL(inter_fd, 2) = guild_id;
  835. WFIFOSET(inter_fd,6);
  836. return 1;
  837. }
  838. /**
  839. * Send a guild message
  840. * (This is goign throught char-serv in case of multi-map setup)
  841. * @param guild_id : Guild id to send the message to
  842. * @param account_id : Player sending the msg
  843. * @param mes : Message to send
  844. * @param len : Size of the message
  845. * @return 0=error, 1=msg_sent
  846. */
  847. int intif_guild_message(int guild_id,uint32 account_id,const char *mes,int len)
  848. {
  849. if (CheckForCharServer())
  850. return 0;
  851. if (other_mapserver_count < 1)
  852. return 0; //No need to send.
  853. WFIFOHEAD(inter_fd, len + 12);
  854. WFIFOW(inter_fd,0)=0x3037;
  855. WFIFOW(inter_fd,2)=len+12;
  856. WFIFOL(inter_fd,4)=guild_id;
  857. WFIFOL(inter_fd,8)=account_id;
  858. memcpy(WFIFOP(inter_fd,12),mes,len);
  859. WFIFOSET(inter_fd,len+12);
  860. return 1;
  861. }
  862. /**
  863. * Request a change of Guild basic information
  864. * @param guild_id : Guild to alter
  865. * @param type : type of data to change (currently only guildlv)
  866. * @param data : new value for type
  867. * @param len : size of data
  868. * @return 0=error, 1=msg_sent
  869. */
  870. int intif_guild_change_basicinfo(int guild_id,int type,const void *data,int len)
  871. {
  872. if (CheckForCharServer())
  873. return 0;
  874. WFIFOHEAD(inter_fd, len + 10);
  875. WFIFOW(inter_fd,0)=0x3039;
  876. WFIFOW(inter_fd,2)=len+10;
  877. WFIFOL(inter_fd,4)=guild_id;
  878. WFIFOW(inter_fd,8)=type;
  879. memcpy(WFIFOP(inter_fd,10),data,len);
  880. WFIFOSET(inter_fd,len+10);
  881. return 1;
  882. }
  883. /**
  884. * Request a change of Guild member information
  885. * @param guild_id : Guild to alter
  886. * @param account_id : Player aid to alter
  887. * @param char_id : Player cid to alter
  888. * @param type : Type of modification
  889. * @param data : Value of modification
  890. * @param len : Size of value
  891. * @return 0=error, 1=msg_sent
  892. */
  893. int intif_guild_change_memberinfo(int guild_id,uint32 account_id,uint32 char_id,
  894. int type,const void *data,int len)
  895. {
  896. if (CheckForCharServer())
  897. return 0;
  898. WFIFOHEAD(inter_fd, len + 18);
  899. WFIFOW(inter_fd, 0)=0x303a;
  900. WFIFOW(inter_fd, 2)=len+18;
  901. WFIFOL(inter_fd, 4)=guild_id;
  902. WFIFOL(inter_fd, 8)=account_id;
  903. WFIFOL(inter_fd,12)=char_id;
  904. WFIFOW(inter_fd,16)=type;
  905. memcpy(WFIFOP(inter_fd,18),data,len);
  906. WFIFOSET(inter_fd,len+18);
  907. return 1;
  908. }
  909. /**
  910. * Request a change of Guild title
  911. * @param guild_id : guild to alter
  912. * @param idx : Position Index
  913. * @param p : Position data { <mode>.L <ranking>.L <pay rate>.L <name>.24B }
  914. * @return 0=error, 1=msg_sent
  915. */
  916. int intif_guild_position(int guild_id,int idx,struct guild_position *p)
  917. {
  918. if (CheckForCharServer())
  919. return 0;
  920. WFIFOHEAD(inter_fd, sizeof(struct guild_position)+12);
  921. WFIFOW(inter_fd,0)=0x303b;
  922. WFIFOW(inter_fd,2)=sizeof(struct guild_position)+12;
  923. WFIFOL(inter_fd,4)=guild_id;
  924. WFIFOL(inter_fd,8)=idx;
  925. memcpy(WFIFOP(inter_fd,12),p,sizeof(struct guild_position));
  926. WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
  927. return 1;
  928. }
  929. /**
  930. * Request an update of Guildskill skill_id
  931. * @param guild_id : Guild to alter
  932. * @param skill_id : Skill to lvl up
  933. * @param account_id : aid requesting update
  934. * @param max : skill max level
  935. * @return 0=error, 1=msg_sent
  936. */
  937. int intif_guild_skillup(int guild_id, uint16 skill_id, uint32 account_id, int max)
  938. {
  939. if( CheckForCharServer() )
  940. return 0;
  941. WFIFOHEAD(inter_fd, 18);
  942. WFIFOW(inter_fd, 0) = 0x303c;
  943. WFIFOL(inter_fd, 2) = guild_id;
  944. WFIFOL(inter_fd, 6) = skill_id;
  945. WFIFOL(inter_fd, 10) = account_id;
  946. WFIFOL(inter_fd, 14) = max;
  947. WFIFOSET(inter_fd, 18);
  948. return 1;
  949. }
  950. /**
  951. * Request a new guild relationship
  952. * @param guild_id1 : Guild to associate 1
  953. * @param guild_id2 : Guild to associate 2
  954. * @param account_id1 : aid of player in guild1
  955. * @param account_id2 : aid of player in guild2
  956. * @param flag : (GUILD_ALLIANCE_REMOVE|0|1)
  957. * @return 0=error, 1=msg_sent
  958. */
  959. int intif_guild_alliance(int guild_id1,int guild_id2,uint32 account_id1,uint32 account_id2,int flag)
  960. {
  961. if (CheckForCharServer())
  962. return 0;
  963. WFIFOHEAD(inter_fd,19);
  964. WFIFOW(inter_fd, 0)=0x303d;
  965. WFIFOL(inter_fd, 2)=guild_id1;
  966. WFIFOL(inter_fd, 6)=guild_id2;
  967. WFIFOL(inter_fd,10)=account_id1;
  968. WFIFOL(inter_fd,14)=account_id2;
  969. WFIFOB(inter_fd,18)=flag;
  970. WFIFOSET(inter_fd,19);
  971. return 1;
  972. }
  973. /**
  974. * Request to change guild notice
  975. * @param guild_id : Guild to alter
  976. * @param mes1 : Notice title (max 60)
  977. * @param mes2 : Notice body (max 120)
  978. * @return 0=error, 1=msg_sent
  979. */
  980. int intif_guild_notice(int guild_id,const char *mes1,const char *mes2)
  981. {
  982. if (CheckForCharServer())
  983. return 0;
  984. WFIFOHEAD(inter_fd,186);
  985. WFIFOW(inter_fd,0)=0x303e;
  986. WFIFOL(inter_fd,2)=guild_id;
  987. memcpy(WFIFOP(inter_fd,6),mes1,MAX_GUILDMES1);
  988. memcpy(WFIFOP(inter_fd,66),mes2,MAX_GUILDMES2);
  989. WFIFOSET(inter_fd,186);
  990. return 1;
  991. }
  992. /**
  993. * Request to change guild emblem
  994. * @param guild_id
  995. * @param len
  996. * @param data
  997. * @return
  998. */
  999. int intif_guild_emblem(int guild_id,int len,const char *data)
  1000. {
  1001. if (CheckForCharServer())
  1002. return 0;
  1003. if(guild_id<=0 || len<0 || len>2000)
  1004. return 0;
  1005. WFIFOHEAD(inter_fd,len + 12);
  1006. WFIFOW(inter_fd,0)=0x303f;
  1007. WFIFOW(inter_fd,2)=len+12;
  1008. WFIFOL(inter_fd,4)=guild_id;
  1009. WFIFOL(inter_fd,8)=0;
  1010. memcpy(WFIFOP(inter_fd,12),data,len);
  1011. WFIFOSET(inter_fd,len+12);
  1012. return 1;
  1013. }
  1014. int intif_guild_emblem_version(int guild_id, int emblem_id)
  1015. {
  1016. if (CheckForCharServer())
  1017. return 0;
  1018. if (guild_id <= 0)
  1019. return 0;
  1020. WFIFOHEAD(inter_fd, 10);
  1021. WFIFOW(inter_fd, 0) = 0x3042;
  1022. WFIFOL(inter_fd, 2) = guild_id;
  1023. WFIFOL(inter_fd, 6) = emblem_id;
  1024. WFIFOSET(inter_fd, 10);
  1025. return 1;
  1026. }
  1027. /**
  1028. * Requests guild castles data from char-server.
  1029. * @param num Number of castles, size of castle_ids array.
  1030. * @param castle_ids Pointer to array of castle IDs.
  1031. */
  1032. bool intif_guild_castle_dataload( const std::vector<int32>& castle_ids ){
  1033. if( CheckForCharServer() ){
  1034. return false;
  1035. }
  1036. uint16 size = (uint16)( 4 + castle_ids.size() * sizeof( int32 ) );
  1037. WFIFOHEAD( inter_fd, size );
  1038. WFIFOW(inter_fd, 0) = 0x3040;
  1039. WFIFOW( inter_fd, 2 ) = size;
  1040. for( size_t i = 0; i < castle_ids.size(); i++ ){
  1041. WFIFOL( inter_fd, 4 + i * sizeof( int32 ) ) = castle_ids[i];
  1042. }
  1043. WFIFOSET( inter_fd, size );
  1044. return true;
  1045. }
  1046. /**
  1047. * Request change castle guild owner and save data
  1048. * @param castle_id
  1049. * @param index
  1050. * @param value
  1051. * @return
  1052. */
  1053. int intif_guild_castle_datasave(int castle_id,int index, int value)
  1054. {
  1055. if (CheckForCharServer())
  1056. return 0;
  1057. WFIFOHEAD(inter_fd,9);
  1058. WFIFOW(inter_fd,0)=0x3041;
  1059. WFIFOW(inter_fd,2)=castle_id;
  1060. WFIFOB(inter_fd,4)=index;
  1061. WFIFOL(inter_fd,5)=value;
  1062. WFIFOSET(inter_fd,9);
  1063. return 1;
  1064. }
  1065. //-----------------------------------------------------------------
  1066. // Homunculus Packets send to Inter server [albator]
  1067. //-----------------------------------------------------------------
  1068. /**
  1069. * Request to create/register homonculus
  1070. * @param account_id : player requesting
  1071. * @param sh : TMp homunlus data
  1072. * @return 0=error, 1=msg_sent
  1073. */
  1074. int intif_homunculus_create(uint32 account_id, struct s_homunculus *sh)
  1075. {
  1076. if (CheckForCharServer())
  1077. return 0;
  1078. WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
  1079. WFIFOW(inter_fd,0) = 0x3090;
  1080. WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
  1081. WFIFOL(inter_fd,4) = account_id;
  1082. memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
  1083. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  1084. return 1;
  1085. }
  1086. /**
  1087. * Request to load homunculus from char-serv
  1088. * @param account_id
  1089. * @param homun_id
  1090. * @return 0=error, 1=msg sent
  1091. */
  1092. int intif_homunculus_requestload(uint32 account_id, int homun_id)
  1093. {
  1094. if (CheckForCharServer())
  1095. return 0;
  1096. WFIFOHEAD(inter_fd, 10);
  1097. WFIFOW(inter_fd,0) = 0x3091;
  1098. WFIFOL(inter_fd,2) = account_id;
  1099. WFIFOL(inter_fd,6) = homun_id;
  1100. WFIFOSET(inter_fd, 10);
  1101. return 1;
  1102. }
  1103. /**
  1104. * Request to save homunculus
  1105. * @param account_id : Player asking save
  1106. * @param sh : homunculus struct
  1107. * @return : 0=error, 1=msg sent
  1108. */
  1109. int intif_homunculus_requestsave(uint32 account_id, struct s_homunculus* sh)
  1110. {
  1111. if (CheckForCharServer())
  1112. return 0;
  1113. WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
  1114. WFIFOW(inter_fd,0) = 0x3092;
  1115. WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
  1116. WFIFOL(inter_fd,4) = account_id;
  1117. memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
  1118. WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
  1119. return 1;
  1120. }
  1121. /**
  1122. * request to delete homunculus
  1123. * @param homun_id
  1124. * @return 0=error, 1=msg sent
  1125. */
  1126. int intif_homunculus_requestdelete(int homun_id)
  1127. {
  1128. if (CheckForCharServer())
  1129. return 0;
  1130. WFIFOHEAD(inter_fd, 6);
  1131. WFIFOW(inter_fd, 0) = 0x3093;
  1132. WFIFOL(inter_fd,2) = homun_id;
  1133. WFIFOSET(inter_fd,6);
  1134. return 1;
  1135. }
  1136. //-----------------------------------------------------------------
  1137. // Packets receive from inter server
  1138. /**
  1139. * Receive a whisper request from char-serv transmit it to player
  1140. * @author : rewritten by [Yor]
  1141. * @param fd : char-serv link
  1142. * @return 0=not found or ignored, 1=transmited
  1143. */
  1144. int intif_parse_WisMessage(int fd)
  1145. {
  1146. struct map_session_data* sd;
  1147. char *wisp_source;
  1148. char name[NAME_LENGTH];
  1149. int id, i, gmlvl;
  1150. id=RFIFOL(fd,4);
  1151. gmlvl=RFIFOL(fd,8);
  1152. safestrncpy(name, RFIFOCP(fd,12+NAME_LENGTH), NAME_LENGTH);
  1153. sd = map_nick2sd(name,false);
  1154. if(sd == NULL || strcmp(sd->status.name, name) != 0)
  1155. { //Not found
  1156. intif_wis_reply(id,1);
  1157. return 0;
  1158. }
  1159. if(sd->state.ignoreAll) {
  1160. intif_wis_reply(id, (pc_has_permission(sd, PC_PERM_HIDE_SESSION))?1:2);
  1161. return 0;
  1162. }
  1163. wisp_source = RFIFOCP(fd,12); // speed up [Yor]
  1164. for(i=0; i < MAX_IGNORE_LIST &&
  1165. sd->ignore[i].name[0] != '\0' &&
  1166. strcmp(sd->ignore[i].name, wisp_source) != 0
  1167. ; i++);
  1168. if (i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0')
  1169. { //Ignored
  1170. intif_wis_reply(id, (pc_has_permission(sd, PC_PERM_HIDE_SESSION))?1:2);
  1171. return 0;
  1172. }
  1173. //Success to send whisper.
  1174. clif_wis_message(sd, wisp_source, RFIFOCP(fd,12+2*NAME_LENGTH),RFIFOW(fd,2)-12+2*NAME_LENGTH, gmlvl);
  1175. intif_wis_reply(id,0); // success
  1176. return 1;
  1177. }
  1178. /**
  1179. * Wisp/page transmission result reception
  1180. * @param fd : char-serv link
  1181. * @return 1
  1182. */
  1183. int intif_parse_WisEnd(int fd)
  1184. {
  1185. struct map_session_data* sd;
  1186. if (battle_config.etc_log)
  1187. 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
  1188. sd = (struct map_session_data *)map_nick2sd(RFIFOCP(fd,2),false);
  1189. if (sd != NULL)
  1190. clif_wis_end(sd->fd, RFIFOB(fd,26));
  1191. return 1;
  1192. }
  1193. /**
  1194. * Transmit a whisper message to sd
  1195. * @param sd : Player to transmit the message to
  1196. * @param va : list of arguments ( wisp_name, message, len)
  1197. * @return 0=error, 1=msg sent
  1198. */
  1199. static int mapif_parse_WisToGM_sub(struct map_session_data* sd,va_list va)
  1200. {
  1201. int permission = va_arg(va, int);
  1202. char *wisp_name;
  1203. char *message;
  1204. int len;
  1205. if (!pc_has_permission(sd, permission))
  1206. return 0;
  1207. wisp_name = va_arg(va, char*);
  1208. message = va_arg(va, char*);
  1209. len = va_arg(va, int);
  1210. clif_wis_message(sd, wisp_name, message, len,0);
  1211. return 1;
  1212. }
  1213. /**
  1214. * Received wisp message from map-server via char-server for ALL gm
  1215. * 0x3003/0x3803 <packet_len>.w <wispname>.24B <permission>.l <message>.?B
  1216. * @see mapif_parse_WisToGM_sub, for 1 transmission
  1217. * @param fd : char-serv link
  1218. * @return 1
  1219. */
  1220. int mapif_parse_WisToGM(int fd)
  1221. {
  1222. int permission, mes_len;
  1223. char Wisp_name[NAME_LENGTH];
  1224. char *message;
  1225. mes_len = RFIFOW(fd,2) - 8+NAME_LENGTH;
  1226. message = (char *) aMalloc(mes_len+1);
  1227. safestrncpy(Wisp_name, RFIFOCP(fd,4), NAME_LENGTH);
  1228. permission = RFIFOL(fd, 4 + NAME_LENGTH);
  1229. safestrncpy(message, RFIFOCP(fd,8+NAME_LENGTH), mes_len+1);
  1230. // information is sent to all online GM
  1231. map_foreachpc(mapif_parse_WisToGM_sub, permission, Wisp_name, message, mes_len);
  1232. aFree(message);
  1233. return 1;
  1234. }
  1235. /**
  1236. * Request player registry
  1237. * @param fd : char-serv link
  1238. * @return 0=error, 1=sucess
  1239. */
  1240. void intif_parse_Registers(int fd)
  1241. {
  1242. int flag;
  1243. struct map_session_data *sd;
  1244. uint32 account_id = RFIFOL(fd,4), char_id = RFIFOL(fd,8);
  1245. struct auth_node *node = chrif_auth_check(account_id, char_id, ST_LOGIN);
  1246. char type = RFIFOB(fd, 13);
  1247. if (node)
  1248. sd = node->sd;
  1249. else { //Normally registries should arrive for in log-in chars.
  1250. sd = map_id2sd(account_id);
  1251. }
  1252. if (!sd || sd->status.char_id != char_id) {
  1253. return; //Character registry from another character.
  1254. }
  1255. flag = ( sd->vars_received&PRL_ACCG && sd->vars_received&PRL_ACCL && sd->vars_received&PRL_CHAR ) ? 0 : 1;
  1256. switch (RFIFOB(fd,12)) {
  1257. case 3: //Character Registry
  1258. sd->vars_received |= PRL_CHAR;
  1259. break;
  1260. case 2: //Account Registry
  1261. sd->vars_received |= PRL_ACCL;
  1262. break;
  1263. case 1: //Account2 Registry
  1264. sd->vars_received |= PRL_ACCG;
  1265. break;
  1266. case 0:
  1267. break;
  1268. default:
  1269. ShowError("intif_parse_Registers: Unrecognized type %d\n",RFIFOB(fd,12));
  1270. return;
  1271. }
  1272. // have it not complain about insertion of vars before loading, and not set those vars as new or modified
  1273. pc_set_reg_load(true);
  1274. if( RFIFOW(fd, 14) ) {
  1275. char key[32];
  1276. uint32 index;
  1277. int max = RFIFOW(fd, 14), cursor = 16, i;
  1278. /**
  1279. * Vessel!char_reg_num_db
  1280. *
  1281. * str type
  1282. * { keyLength(B), key(<keyLength>), index(L), valLength(B), val(<valLength>) }
  1283. **/
  1284. if (type) {
  1285. for(i = 0; i < max; i++) {
  1286. char sval[254];
  1287. safestrncpy(key, RFIFOCP(fd, cursor + 1), RFIFOB(fd, cursor));
  1288. cursor += RFIFOB(fd, cursor) + 1;
  1289. index = RFIFOL(fd, cursor);
  1290. cursor += 4;
  1291. safestrncpy(sval, RFIFOCP(fd, cursor + 1), RFIFOB(fd, cursor));
  1292. cursor += RFIFOB(fd, cursor) + 1;
  1293. set_reg_str( NULL, sd, reference_uid( add_str( key ), index ), key, sval, NULL );
  1294. }
  1295. /**
  1296. * Vessel!
  1297. *
  1298. * int type
  1299. * { keyLength(B), key(<keyLength>), index(L), value(L) }
  1300. **/
  1301. } else {
  1302. for(i = 0; i < max; i++) {
  1303. int64 ival;
  1304. safestrncpy(key, RFIFOCP(fd, cursor + 1), RFIFOB(fd, cursor));
  1305. cursor += RFIFOB(fd, cursor) + 1;
  1306. index = RFIFOL(fd, cursor);
  1307. cursor += 4;
  1308. ival = RFIFOQ(fd, cursor);
  1309. cursor += 8;
  1310. set_reg_num( NULL, sd, reference_uid( add_str( key ), index ), key, ival, NULL );
  1311. }
  1312. }
  1313. }
  1314. pc_set_reg_load(false);
  1315. if (flag && sd->vars_received&PRL_ACCG && sd->vars_received&PRL_ACCL && sd->vars_received&PRL_CHAR)
  1316. pc_reg_received(sd); //Received all registry values, execute init scripts and what-not. [Skotlex]
  1317. }
  1318. /**
  1319. * Received a guild storage
  1320. * @param fd : char-serv link
  1321. * @return 0=error, 1=sucess
  1322. */
  1323. int intif_parse_LoadGuildStorage(int fd)
  1324. {
  1325. struct s_storage *gstor;
  1326. struct map_session_data *sd;
  1327. int guild_id, flag;
  1328. guild_id = RFIFOL(fd,8);
  1329. flag = RFIFOL(fd,12);
  1330. if (guild_id <= 0)
  1331. return 0;
  1332. sd = map_id2sd( RFIFOL(fd,4) );
  1333. if (flag){ //If flag != 0, we attach a player and open the storage
  1334. if(sd == NULL){
  1335. ShowError("intif_parse_LoadGuildStorage: user not found (AID: %d)\n",RFIFOL(fd,4));
  1336. return 0;
  1337. }
  1338. }
  1339. gstor = guild2storage(guild_id);
  1340. if (!gstor) {
  1341. ShowWarning("intif_parse_LoadGuildStorage: error guild_id %d not exist\n",guild_id);
  1342. return 0;
  1343. }
  1344. if (gstor->status) { // Already open.. lets ignore this update
  1345. ShowWarning("intif_parse_LoadGuildStorage: storage received for a client already open (User %d:%d)\n", flag?sd->status.account_id:1, flag?sd->status.char_id:1);
  1346. return 0;
  1347. }
  1348. if (gstor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex]
  1349. ShowWarning("intif_parse_LoadGuildStorage: received storage for an already modified non-saved storage! (User %d:%d)\n", flag?sd->status.account_id:1, flag?sd->status.char_id:1);
  1350. return 0;
  1351. }
  1352. if (RFIFOW(fd,2)-13 != sizeof(struct s_storage)) {
  1353. ShowError("intif_parse_LoadGuildStorage: data size error %d %" PRIuPTR "\n",RFIFOW(fd,2)-13 , sizeof(struct s_storage));
  1354. gstor->status = false;
  1355. return 0;
  1356. }
  1357. memcpy(gstor,RFIFOP(fd,13),sizeof(struct s_storage));
  1358. if( flag )
  1359. storage_guild_storageopen(sd);
  1360. return 1;
  1361. }
  1362. /**
  1363. * ACK guild_storage saved
  1364. * @param fd : char-serv link
  1365. * @return 1
  1366. */
  1367. int intif_parse_SaveGuildStorage(int fd)
  1368. {
  1369. storage_guild_storagesaved(/*RFIFOL(fd,2), */RFIFOL(fd,6));
  1370. return 1;
  1371. }
  1372. /**
  1373. * ACK party creation
  1374. * @param fd : char-serv link
  1375. * @return 1
  1376. */
  1377. int intif_parse_PartyCreated(int fd)
  1378. {
  1379. if(battle_config.etc_log)
  1380. ShowInfo("intif: party created by account %d\n\n", RFIFOL(fd,2));
  1381. party_created(RFIFOL(fd,2), RFIFOL(fd,6),RFIFOB(fd,10),RFIFOL(fd,11), RFIFOCP(fd,15));
  1382. return 1;
  1383. }
  1384. /**
  1385. * Receive party info
  1386. * @param fd : char-serv link
  1387. * @return 0=error, 1=sucess
  1388. */
  1389. int intif_parse_PartyInfo(int fd)
  1390. {
  1391. if( RFIFOW(fd,2) == 12 ){
  1392. ShowWarning("intif: party noinfo (char_id=%d party_id=%d)\n", RFIFOL(fd,4), RFIFOL(fd,8));
  1393. party_recv_noinfo(RFIFOL(fd,8), RFIFOL(fd,4));
  1394. return 0;
  1395. }
  1396. if( RFIFOW(fd,2) != 8+sizeof(struct party) )
  1397. ShowError("intif: party info : data size error (char_id=%d party_id=%d packet_len=%d expected_len=%" PRIuPTR ")\n", RFIFOL(fd,4), RFIFOL(fd,8), RFIFOW(fd,2), 8+sizeof(struct party));
  1398. party_recv_info((struct party *)RFIFOP(fd,8), RFIFOL(fd,4));
  1399. return 1;
  1400. }
  1401. /**
  1402. * ACK adding party member
  1403. * @param fd : char-serv link
  1404. * @return 1
  1405. */
  1406. int intif_parse_PartyMemberAdded(int fd)
  1407. {
  1408. if(battle_config.etc_log)
  1409. ShowInfo("intif: party member added Party (%d), Account(%d), Char(%d)\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
  1410. party_member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10), RFIFOB(fd, 14));
  1411. return 1;
  1412. }
  1413. /**
  1414. * ACK changing party option
  1415. * @param fd : char-serv link
  1416. * @return 1
  1417. */
  1418. int intif_parse_PartyOptionChanged(int fd)
  1419. {
  1420. party_optionchanged(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOW(fd,10),RFIFOW(fd,12),RFIFOB(fd,14));
  1421. return 1;
  1422. }
  1423. /**
  1424. * ACK member leaving party
  1425. * @param fd : char-serv link
  1426. * @return 1
  1427. */
  1428. int intif_parse_PartyMemberWithdraw(int fd)
  1429. {
  1430. if(battle_config.etc_log)
  1431. ShowInfo("intif: party member withdraw: Type(%d) Party(%d), Account(%d), Char(%d), Name(%s)\n",RFIFOB(fd,14+NAME_LENGTH),RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOCP(fd,14));
  1432. party_member_withdraw(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOCP(fd,14),(enum e_party_member_withdraw)RFIFOB(fd,14+NAME_LENGTH));
  1433. return 1;
  1434. }
  1435. /**
  1436. * ACK party break
  1437. * @param fd : char-serv link
  1438. * @return 1
  1439. */
  1440. int intif_parse_PartyBroken(int fd)
  1441. {
  1442. party_broken(RFIFOL(fd,2));
  1443. return 1;
  1444. }
  1445. /**
  1446. * ACK party on new map
  1447. * @param fd : char-serv link
  1448. * @return 1
  1449. */
  1450. int intif_parse_PartyMove(int fd)
  1451. {
  1452. party_recv_movemap(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOW(fd,14),RFIFOB(fd,16),RFIFOW(fd,17));
  1453. return 1;
  1454. }
  1455. /**
  1456. * ACK party messages
  1457. * @param fd : char-serv link
  1458. * @return 1
  1459. */
  1460. int intif_parse_PartyMessage(int fd)
  1461. {
  1462. party_recv_message(RFIFOL(fd,4),RFIFOL(fd,8),RFIFOCP(fd,12),RFIFOW(fd,2)-12);
  1463. return 1;
  1464. }
  1465. /**
  1466. * ACK guild creation
  1467. * @param fd : char-serv link
  1468. * @return 1
  1469. */
  1470. int intif_parse_GuildCreated(int fd)
  1471. {
  1472. guild_created(RFIFOL(fd,2),RFIFOL(fd,6));
  1473. return 1;
  1474. }
  1475. /**
  1476. * ACK guild infos
  1477. * @param fd : char-serv link
  1478. * @return 0=error, 1=sucess
  1479. */
  1480. int intif_parse_GuildInfo(int fd)
  1481. {
  1482. if(RFIFOW(fd,2) == 8) {
  1483. ShowWarning("intif: guild noinfo %d\n",RFIFOL(fd,4));
  1484. guild_recv_noinfo(RFIFOL(fd,4));
  1485. return 0;
  1486. }
  1487. if( RFIFOW(fd,2)!=sizeof(struct guild)+4 )
  1488. ShowError("intif: guild info : data size error Gid: %d recv size: %d Expected size: %" PRIuPTR "\n",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild)+4);
  1489. guild_recv_info((struct guild *)RFIFOP(fd,4));
  1490. return 1;
  1491. }
  1492. /**
  1493. * ACK adding guild member
  1494. * @param fd : char-serv link
  1495. * @return 1
  1496. */
  1497. int intif_parse_GuildMemberAdded(int fd)
  1498. {
  1499. if(battle_config.etc_log)
  1500. ShowInfo("intif: guild member added %d %d %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14));
  1501. guild_member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14));
  1502. return 1;
  1503. }
  1504. /**
  1505. * ACK member leaving guild
  1506. * @param fd : char-serv link
  1507. * @return 1
  1508. */
  1509. int intif_parse_GuildMemberWithdraw(int fd)
  1510. {
  1511. guild_member_withdraw(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOCP(fd,55),RFIFOCP(fd,15));
  1512. return 1;
  1513. }
  1514. /**
  1515. * ACK guild member basic info
  1516. * @param fd : char-serv link
  1517. * @return 1
  1518. */
  1519. int intif_parse_GuildMemberInfoShort(int fd)
  1520. {
  1521. guild_recv_memberinfoshort(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOW(fd,15),RFIFOW(fd,17));
  1522. return 1;
  1523. }
  1524. /**
  1525. * ACK guild break
  1526. * @param fd : char-serv link
  1527. * @return 1
  1528. */
  1529. int intif_parse_GuildBroken(int fd)
  1530. {
  1531. guild_broken(RFIFOL(fd,2),RFIFOB(fd,6));
  1532. return 1;
  1533. }
  1534. /**
  1535. * basic guild info change notice
  1536. * 0x3839 <packet len>.w <guild id>.l <type>.w <data>.?b
  1537. * @param fd : char-serv link
  1538. * @return 0=error, 1=sucess
  1539. */
  1540. int intif_parse_GuildBasicInfoChanged(int fd)
  1541. {
  1542. //int len = RFIFOW(fd,2) - 10;
  1543. int guild_id = RFIFOL(fd,4);
  1544. int type = RFIFOW(fd,8);
  1545. //void* data = RFIFOP(fd,10);
  1546. struct guild* g = guild_search(guild_id);
  1547. if( g == NULL )
  1548. return 0;
  1549. switch(type) {
  1550. case GBI_EXP: g->exp = RFIFOQ(fd,10); break;
  1551. case GBI_GUILDLV: g->guild_lv = RFIFOW(fd,10); break;
  1552. case GBI_SKILLPOINT: g->skill_point = RFIFOL(fd,10); break;
  1553. }
  1554. return 1;
  1555. }
  1556. /**
  1557. * guild member info change notice
  1558. * 0x383a <packet len>.w <guild id>.l <account id>.l <char id>.l <type>.w <data>.?b
  1559. * @param fd : char-serv link
  1560. * @return 0=error, 1=sucess
  1561. */
  1562. int intif_parse_GuildMemberInfoChanged(int fd)
  1563. {
  1564. //int len = RFIFOW(fd,2) - 18;
  1565. int guild_id = RFIFOL(fd,4);
  1566. uint32 account_id = RFIFOL(fd,8);
  1567. uint32 char_id = RFIFOL(fd,12);
  1568. int type = RFIFOW(fd,16);
  1569. //void* data = RFIFOP(fd,18);
  1570. struct guild* g;
  1571. int idx;
  1572. g = guild_search(guild_id);
  1573. if( g == NULL )
  1574. return 0;
  1575. idx = guild_getindex(g,account_id,char_id);
  1576. if( idx == -1 )
  1577. return 0;
  1578. switch( type ) {
  1579. case GMI_POSITION: g->member[idx].position = RFIFOW(fd,18); guild_memberposition_changed(g,idx,RFIFOW(fd,18)); break;
  1580. case GMI_EXP: g->member[idx].exp = RFIFOQ(fd,18); break;
  1581. case GMI_HAIR: g->member[idx].hair = RFIFOW(fd,18); break;
  1582. case GMI_HAIR_COLOR: g->member[idx].hair_color = RFIFOW(fd,18); break;
  1583. case GMI_GENDER: g->member[idx].gender = RFIFOW(fd,18); break;
  1584. case GMI_CLASS: g->member[idx].class_ = RFIFOW(fd,18); break;
  1585. case GMI_LEVEL: g->member[idx].lv = RFIFOW(fd,18); break;
  1586. }
  1587. return 1;
  1588. }
  1589. /**
  1590. * ACK change of guild title
  1591. * @param fd : char-serv link
  1592. * @return 1
  1593. */
  1594. int intif_parse_GuildPosition(int fd)
  1595. {
  1596. if( RFIFOW(fd,2)!=sizeof(struct guild_position)+12 )
  1597. ShowError("intif: guild info : data size error %d %d %" PRIuPTR "\n",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild_position)+12);
  1598. guild_position_changed(RFIFOL(fd,4),RFIFOL(fd,8),(struct guild_position *)RFIFOP(fd,12));
  1599. return 1;
  1600. }
  1601. /**
  1602. * ACK change of guild skill update
  1603. * @param fd : char-serv link
  1604. * @return 1
  1605. */
  1606. int intif_parse_GuildSkillUp(int fd)
  1607. {
  1608. guild_skillupack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
  1609. return 1;
  1610. }
  1611. /**
  1612. * ACK change of guild relationship
  1613. * @param fd : char-serv link
  1614. * @return 1
  1615. */
  1616. int intif_parse_GuildAlliance(int fd)
  1617. {
  1618. guild_allianceack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOL(fd,14),RFIFOB(fd,18),RFIFOCP(fd,19),RFIFOCP(fd,43));
  1619. return 1;
  1620. }
  1621. /**
  1622. * ACK change of guild notice
  1623. * @param fd : char-serv link
  1624. * @return 1
  1625. */
  1626. int intif_parse_GuildNotice(int fd)
  1627. {
  1628. guild_notice_changed(RFIFOL(fd,2),RFIFOCP(fd,6),RFIFOCP(fd,66));
  1629. return 1;
  1630. }
  1631. /**
  1632. * ACK change of guild emblem
  1633. * @param fd : char-serv link
  1634. * @return 1
  1635. */
  1636. int intif_parse_GuildEmblem(int fd)
  1637. {
  1638. guild_emblem_changed(RFIFOW(fd,2)-12,RFIFOL(fd,4),RFIFOL(fd,8), RFIFOCP(fd,12));
  1639. return 1;
  1640. }
  1641. int intif_parse_GuildEmblemVersionChanged(int fd)
  1642. {
  1643. guild_emblem_changed(0, RFIFOL(fd, 2), RFIFOL(fd, 6), nullptr); // Doesn't need emblem length and data
  1644. return 1;
  1645. }
  1646. /**
  1647. * ACK guild message
  1648. * @param fd : char-serv link
  1649. * @return 1
  1650. */
  1651. int intif_parse_GuildMessage(int fd)
  1652. {
  1653. guild_recv_message(RFIFOL(fd,4),RFIFOL(fd,8),RFIFOCP(fd,12),RFIFOW(fd,2)-12);
  1654. return 1;
  1655. }
  1656. /**
  1657. * Reply guild castle data request
  1658. * @param fd : char-serv link
  1659. * @return ?
  1660. */
  1661. int intif_parse_GuildCastleDataLoad(int fd)
  1662. {
  1663. return guild_castledataloadack(RFIFOW(fd,2), (struct guild_castle *)RFIFOP(fd,4));
  1664. }
  1665. /**
  1666. * ACK change of guildmaster
  1667. * @param fd : char-serv link
  1668. * @return ?
  1669. */
  1670. int intif_parse_GuildMasterChanged(int fd)
  1671. {
  1672. return guild_gm_changed(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOL(fd,14));
  1673. }
  1674. /**
  1675. * Request pet creation
  1676. * @param fd : char-serv link
  1677. * @return 1
  1678. */
  1679. int intif_parse_CreatePet(int fd)
  1680. {
  1681. pet_get_egg(RFIFOL(fd,2),RFIFOW(fd,6),RFIFOL(fd,8));
  1682. return 1;
  1683. }
  1684. /**
  1685. * ACK pet data
  1686. * @param fd : char-serv link
  1687. * @return 1
  1688. */
  1689. int intif_parse_RecvPetData(int fd)
  1690. {
  1691. struct s_pet p;
  1692. int len;
  1693. len=RFIFOW(fd,2);
  1694. if(sizeof(struct s_pet)!=len-9) {
  1695. if(battle_config.etc_log)
  1696. ShowError("intif: pet data: data size error %" PRIuPTR " %d\n",sizeof(struct s_pet),len-9);
  1697. }
  1698. else{
  1699. memcpy(&p,RFIFOP(fd,9),sizeof(struct s_pet));
  1700. pet_recv_petdata(RFIFOL(fd,4),&p,RFIFOB(fd,8));
  1701. }
  1702. return 1;
  1703. }
  1704. /**
  1705. * ACK pet save data
  1706. * @param fd : char-serv link
  1707. * @return 1
  1708. */
  1709. int intif_parse_SavePetOk(int fd)
  1710. {
  1711. if(RFIFOB(fd,6) == 1)
  1712. ShowError("pet data save failure\n");
  1713. return 1;
  1714. }
  1715. /**
  1716. * ACK deleting pet
  1717. * @param fd : char-serv link
  1718. * @return 1
  1719. */
  1720. int intif_parse_DeletePetOk(int fd)
  1721. {
  1722. if(RFIFOB(fd,2) == 1)
  1723. ShowError("pet data delete failure\n");
  1724. return 1;
  1725. }
  1726. /**
  1727. * ACK changing name resquest, players,pets,hommon
  1728. * @param fd : char-serv link
  1729. * @return 0=error, 1=sucess
  1730. */
  1731. int intif_parse_ChangeNameOk(int fd)
  1732. {
  1733. struct map_session_data *sd = NULL;
  1734. if((sd=map_id2sd(RFIFOL(fd,2)))==NULL ||
  1735. sd->status.char_id != RFIFOL(fd,6))
  1736. return 0;
  1737. switch (RFIFOB(fd,10)) {
  1738. case 0: //Players [NOT SUPPORTED YET]
  1739. break;
  1740. case 1: //Pets
  1741. pet_change_name_ack(sd, RFIFOCP(fd,12), RFIFOB(fd,11));
  1742. break;
  1743. case 2: //Hom
  1744. hom_change_name_ack(sd, RFIFOCP(fd,12), RFIFOB(fd,11));
  1745. break;
  1746. }
  1747. return 1;
  1748. }
  1749. //----------------------------------------------------------------
  1750. // Homunculus recv packets [albator]
  1751. /**
  1752. * ACK Homunculus creation
  1753. * @param fd : char-serv link
  1754. * @return 0=error, 1=sucess
  1755. */
  1756. int intif_parse_CreateHomunculus(int fd)
  1757. {
  1758. int len;
  1759. len=RFIFOW(fd,2)-9;
  1760. if(sizeof(struct s_homunculus)!=len) {
  1761. if(battle_config.etc_log)
  1762. ShowError("intif: create homun data: data size error %" PRIuPTR " != %d\n",sizeof(struct s_homunculus),len);
  1763. return 0;
  1764. }
  1765. hom_recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8)) ;
  1766. return 1;
  1767. }
  1768. /**
  1769. * ACK homunculus get data (load homun from char)
  1770. * @param fd : char-serv link
  1771. * @return 0=error, 1=sucess
  1772. */
  1773. int intif_parse_RecvHomunculusData(int fd)
  1774. {
  1775. int len;
  1776. len=RFIFOW(fd,2)-9;
  1777. if(sizeof(struct s_homunculus)!=len) {
  1778. if(battle_config.etc_log)
  1779. ShowError("intif: homun data: data size error %" PRIuPTR " %d\n",sizeof(struct s_homunculus),len);
  1780. return 0;
  1781. }
  1782. hom_recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8));
  1783. return 1;
  1784. }
  1785. /**
  1786. * ACK save Homun
  1787. * @param fd : char-serv link
  1788. * @return 1
  1789. */
  1790. int intif_parse_SaveHomunculusOk(int fd)
  1791. {
  1792. if(RFIFOB(fd,6) != 1)
  1793. ShowError("homunculus data save failure for account %d\n", RFIFOL(fd,2));
  1794. return 1;
  1795. }
  1796. /**
  1797. * ACK delete Homun
  1798. * @param fd : char-serv link
  1799. * @return 1
  1800. */
  1801. int intif_parse_DeleteHomunculusOk(int fd)
  1802. {
  1803. if(RFIFOB(fd,2) != 1)
  1804. ShowError("Homunculus data delete failure\n");
  1805. return 1;
  1806. }
  1807. /**************************************
  1808. QUESTLOG SYSTEM FUNCTIONS
  1809. ***************************************/
  1810. /**
  1811. * Requests a character's quest log entries to the inter server.
  1812. * @param sd Character's data
  1813. */
  1814. void intif_request_questlog(struct map_session_data *sd)
  1815. {
  1816. if (CheckForCharServer())
  1817. return;
  1818. WFIFOHEAD(inter_fd,6);
  1819. WFIFOW(inter_fd,0) = 0x3060;
  1820. WFIFOL(inter_fd,2) = sd->status.char_id;
  1821. WFIFOSET(inter_fd,6);
  1822. }
  1823. /**
  1824. * Receive a char quest log
  1825. * @param fd : char-serv link
  1826. */
  1827. void intif_parse_questlog(int fd)
  1828. {
  1829. uint32 char_id = RFIFOL(fd,4), num_received = (RFIFOW(fd,2) - 8) / sizeof(struct quest);
  1830. TBL_PC *sd = map_charid2sd(char_id);
  1831. if(!sd) // User not online anymore
  1832. return;
  1833. sd->num_quests = sd->avail_quests = 0;
  1834. if(num_received == 0) {
  1835. if(sd->quest_log) {
  1836. aFree(sd->quest_log);
  1837. sd->quest_log = NULL;
  1838. }
  1839. } else {
  1840. struct quest *received = (struct quest *)RFIFOP(fd,8);
  1841. int k = num_received;
  1842. if(sd->quest_log)
  1843. RECREATE(sd->quest_log, struct quest, num_received);
  1844. else
  1845. CREATE(sd->quest_log, struct quest, num_received);
  1846. for(int i = 0; i < num_received; i++) {
  1847. if(!quest_search(received[i].quest_id)) {
  1848. ShowError("intif_parse_QuestLog: quest %d not found in DB.\n", received[i].quest_id);
  1849. continue;
  1850. }
  1851. if(received[i].state != Q_COMPLETE) // Insert at the beginning
  1852. memcpy(&sd->quest_log[sd->avail_quests++], &received[i], sizeof(struct quest));
  1853. else // Insert at the end
  1854. memcpy(&sd->quest_log[--k], &received[i], sizeof(struct quest));
  1855. sd->num_quests++;
  1856. }
  1857. if(sd->avail_quests < k) {
  1858. // sd->avail_quests and k didn't meet in the middle: some entries were skipped
  1859. if(k < num_received) // Move the entries at the end to fill the gap
  1860. memmove(&sd->quest_log[k], &sd->quest_log[sd->avail_quests], sizeof(struct quest) * (num_received - k));
  1861. sd->quest_log = (struct quest *)aRealloc(sd->quest_log, sizeof(struct quest) * sd->num_quests);
  1862. }
  1863. }
  1864. quest_pc_login(sd);
  1865. }
  1866. /**
  1867. * Parses the quest log save ack for a character from the inter server.
  1868. * Received in reply to the requests made by intif_quest_save.
  1869. * @see intif_parse
  1870. * @param fd : char-serv link
  1871. */
  1872. void intif_parse_questsave(int fd)
  1873. {
  1874. int cid = RFIFOL(fd, 2);
  1875. TBL_PC *sd = map_id2sd(cid);
  1876. if( !RFIFOB(fd, 6) )
  1877. ShowError("intif_parse_questsave: Failed to save quest(s) for character %d!\n", cid);
  1878. else if( sd )
  1879. sd->save_quest = false;
  1880. }
  1881. /**
  1882. * Requests to the inter server to save a character's quest log entries.
  1883. * @param sd Character's data
  1884. * @return 0 in case of success, nonzero otherwise
  1885. */
  1886. int intif_quest_save(struct map_session_data *sd)
  1887. {
  1888. int len = sizeof(struct quest) * sd->num_quests + 8;
  1889. if(CheckForCharServer())
  1890. return 0;
  1891. WFIFOHEAD(inter_fd, len);
  1892. WFIFOW(inter_fd,0) = 0x3061;
  1893. WFIFOW(inter_fd,2) = len;
  1894. WFIFOL(inter_fd,4) = sd->status.char_id;
  1895. if( sd->num_quests )
  1896. memcpy(WFIFOP(inter_fd,8), sd->quest_log, sizeof(struct quest)*sd->num_quests);
  1897. WFIFOSET(inter_fd, len);
  1898. return 1;
  1899. }
  1900. /*==========================================
  1901. * Achievement System
  1902. *------------------------------------------*/
  1903. /**
  1904. * Requests a character's achievement log entries to the inter server.
  1905. * @param char_id: Character ID
  1906. */
  1907. void intif_request_achievements(uint32 char_id)
  1908. {
  1909. if (CheckForCharServer())
  1910. return;
  1911. WFIFOHEAD(inter_fd, 6);
  1912. WFIFOW(inter_fd, 0) = 0x3062;
  1913. WFIFOL(inter_fd, 2) = char_id;
  1914. WFIFOSET(inter_fd, 6);
  1915. }
  1916. /**
  1917. * Receive a character's achievements
  1918. * @param fd: char-serv link
  1919. */
  1920. void intif_parse_achievements(int fd)
  1921. {
  1922. uint32 char_id = RFIFOL(fd, 4), num_received = (RFIFOW(fd, 2) - 8) / sizeof(struct achievement);
  1923. struct map_session_data *sd = map_charid2sd(char_id);
  1924. if (!sd) // User not online anymore
  1925. return;
  1926. if (num_received == 0) {
  1927. if (sd->achievement_data.achievements) {
  1928. aFree(sd->achievement_data.achievements);
  1929. sd->achievement_data.achievements = NULL;
  1930. sd->achievement_data.incompleteCount = 0;
  1931. sd->achievement_data.count = 0;
  1932. }
  1933. } else {
  1934. struct achievement *received = (struct achievement *)RFIFOP(fd, 8);
  1935. int i, k = num_received;
  1936. if (sd->achievement_data.achievements)
  1937. RECREATE(sd->achievement_data.achievements, struct achievement, num_received);
  1938. else
  1939. CREATE(sd->achievement_data.achievements, struct achievement, num_received);
  1940. for (i = 0; i < num_received; i++) {
  1941. std::shared_ptr<s_achievement_db> adb = achievement_db.find( received[i].achievement_id );
  1942. if (!adb) {
  1943. ShowError("intif_parse_achievements: Achievement %d not found in achievement_db.\n", received[i].achievement_id);
  1944. continue;
  1945. }
  1946. received[i].score = adb->score;
  1947. if (received[i].completed == 0) // Insert at the beginning
  1948. memcpy(&sd->achievement_data.achievements[sd->achievement_data.incompleteCount++], &received[i], sizeof(struct achievement));
  1949. else // Insert at the end
  1950. memcpy(&sd->achievement_data.achievements[--k], &received[i], sizeof(struct achievement));
  1951. sd->achievement_data.count++;
  1952. }
  1953. if (sd->achievement_data.incompleteCount < k) {
  1954. // sd->achievement_data.incompleteCount and k didn't meet in the middle: some entries were skipped
  1955. if (k < num_received) // Move the entries at the end to fill the gap
  1956. memmove(&sd->achievement_data.achievements[k], &sd->achievement_data.achievements[sd->achievement_data.incompleteCount], sizeof(struct achievement) * (num_received - k));
  1957. sd->achievement_data.achievements = (struct achievement *)aRealloc(sd->achievement_data.achievements, sizeof(struct achievement) * sd->achievement_data.count);
  1958. }
  1959. }
  1960. // Check all conditions and counters on login
  1961. for( int group = AG_NONE + 1; group < AG_MAX; group++ ){
  1962. achievement_update_objective( sd, static_cast<e_achievement_group>( group ), 0 );
  1963. }
  1964. achievement_level(sd, false); // Calculate level info but don't give any AG_GOAL_ACHIEVE achievements
  1965. achievement_get_titles(sd->status.char_id); // Populate the title list for completed achievements
  1966. clif_achievement_update(sd, NULL, 0);
  1967. clif_achievement_list_all(sd);
  1968. }
  1969. /**
  1970. * Parses the achievement log save ack for a character from the inter server.
  1971. * Received in reply to the requests made by intif_achievement_save.
  1972. * @see intif_parse
  1973. * @param fd : char-serv link
  1974. */
  1975. void intif_parse_achievementsave(int fd)
  1976. {
  1977. int cid = RFIFOL(fd, 2);
  1978. struct map_session_data *sd = map_charid2sd(cid);
  1979. if (!sd) // User not online anymore
  1980. return;
  1981. if (!RFIFOB(fd, 6))
  1982. ShowError("intif_parse_achievementsave: Failed to save achievement(s) for character %s (%d)!\n", sd->status.name, cid);
  1983. }
  1984. /**
  1985. * Requests to the inter server to save a character's achievement log entries.
  1986. * @param sd: Character's data
  1987. * @return 0 in case of success, nonzero otherwise
  1988. */
  1989. int intif_achievement_save(struct map_session_data *sd)
  1990. {
  1991. int len = sizeof(struct achievement) * sd->achievement_data.count + 8;
  1992. if (CheckForCharServer())
  1993. return 0;
  1994. WFIFOHEAD(inter_fd, len);
  1995. WFIFOW(inter_fd, 0) = 0x3063;
  1996. WFIFOW(inter_fd, 2) = len;
  1997. WFIFOL(inter_fd, 4) = sd->status.char_id;
  1998. if (sd->achievement_data.count)
  1999. memcpy(WFIFOP(inter_fd, 8), sd->achievement_data.achievements, sizeof(struct achievement) * sd->achievement_data.count);
  2000. WFIFOSET(inter_fd, len);
  2001. sd->achievement_data.save = false;
  2002. return 1;
  2003. }
  2004. /**
  2005. * Parses the reply of the reward claiming for a achievement from the inter server.
  2006. * @see intif_parse
  2007. * @param fd : char-serv link
  2008. */
  2009. void intif_parse_achievementreward(int fd){
  2010. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  2011. // User not online anymore
  2012. if( !sd ){
  2013. return;
  2014. }
  2015. achievement_get_reward(sd, RFIFOL(fd, 6), RFIFOL(fd, 10));
  2016. }
  2017. /**
  2018. * Request the achievement rewards from the inter server.
  2019. */
  2020. int intif_achievement_reward(struct map_session_data *sd, struct s_achievement_db *adb){
  2021. if( CheckForCharServer() ){
  2022. return 0;
  2023. }
  2024. WFIFOHEAD(inter_fd, 16+NAME_LENGTH+ACHIEVEMENT_NAME_LENGTH);
  2025. WFIFOW(inter_fd, 0) = 0x3064;
  2026. WFIFOL(inter_fd, 2) = sd->status.char_id;
  2027. WFIFOL(inter_fd, 6) = adb->achievement_id;
  2028. WFIFOL(inter_fd, 10) = adb->rewards.nameid;
  2029. WFIFOW(inter_fd, 14) = adb->rewards.amount;
  2030. safestrncpy(WFIFOCP(inter_fd, 16), sd->status.name, NAME_LENGTH);
  2031. safestrncpy(WFIFOCP(inter_fd, 16+NAME_LENGTH), adb->name.c_str(), ACHIEVEMENT_NAME_LENGTH);
  2032. WFIFOSET(inter_fd, 16+NAME_LENGTH+ACHIEVEMENT_NAME_LENGTH);
  2033. return 1;
  2034. }
  2035. /*==========================================
  2036. * MAIL SYSTEM
  2037. * By Zephyrus
  2038. *==========================================*/
  2039. /**
  2040. * Request to update inbox
  2041. * @param char_id : Player ID linked with box
  2042. * @param flag 0 Update Inbox | 1 OpenMail
  2043. * @return 0=error, 1=msg_sent
  2044. */
  2045. int intif_Mail_requestinbox(uint32 char_id, unsigned char flag, enum mail_inbox_type type)
  2046. {
  2047. if (CheckForCharServer())
  2048. return 0;
  2049. WFIFOHEAD(inter_fd,8);
  2050. WFIFOW(inter_fd,0) = 0x3048;
  2051. WFIFOL(inter_fd,2) = char_id;
  2052. WFIFOB(inter_fd,6) = flag;
  2053. WFIFOB(inter_fd,7) = type;
  2054. WFIFOSET(inter_fd,8);
  2055. return 1;
  2056. }
  2057. /**
  2058. * Map-serv received a mail from char-serv
  2059. * (inform user of new mail)
  2060. * @param fd : char-serv link
  2061. * @return 0=msg fail, 1=msg received
  2062. */
  2063. int intif_parse_Mail_inboxreceived(int fd)
  2064. {
  2065. struct map_session_data *sd;
  2066. unsigned char flag = RFIFOB(fd,8);
  2067. sd = map_charid2sd(RFIFOL(fd,4));
  2068. if (sd == NULL)
  2069. {
  2070. ShowError("intif_parse_Mail_inboxreceived: char not found %d\n",RFIFOL(fd,4));
  2071. return 0;
  2072. }
  2073. if (RFIFOW(fd,2) - 10 != sizeof(struct mail_data))
  2074. {
  2075. ShowError("intif_parse_Mail_inboxreceived: data size error %d %" PRIuPTR "\n", RFIFOW(fd,2) - 10, sizeof(struct mail_data));
  2076. return 0;
  2077. }
  2078. //FIXME: this operation is not safe [ultramage]
  2079. memcpy(&sd->mail.inbox, RFIFOP(fd,10), sizeof(struct mail_data));
  2080. sd->mail.changed = false; // cache is now in sync
  2081. #if PACKETVER >= 20150513
  2082. // Refresh top right icon
  2083. clif_Mail_new(sd, 0, NULL, NULL);
  2084. #endif
  2085. if (flag){
  2086. clif_Mail_refreshinbox(sd,static_cast<mail_inbox_type>(RFIFOB(fd,9)),0);
  2087. }else if( battle_config.mail_show_status && ( battle_config.mail_show_status == 1 || sd->mail.inbox.unread ) )
  2088. {
  2089. char output[128];
  2090. sprintf(output, msg_txt(sd,510), sd->mail.inbox.unchecked, sd->mail.inbox.unread + sd->mail.inbox.unchecked);
  2091. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  2092. }
  2093. return 1;
  2094. }
  2095. /**
  2096. * Notify char-serv that the mail was read
  2097. * @param mail_id : mail reed
  2098. * @return 0=error, 1=msg sent
  2099. */
  2100. int intif_Mail_read(int mail_id)
  2101. {
  2102. if (CheckForCharServer())
  2103. return 0;
  2104. WFIFOHEAD(inter_fd,6);
  2105. WFIFOW(inter_fd,0) = 0x3049;
  2106. WFIFOL(inter_fd,2) = mail_id;
  2107. WFIFOSET(inter_fd,6);
  2108. return 1;
  2109. }
  2110. /**
  2111. * Request the mail attachment for mail
  2112. * @param char_id : Player requesting
  2113. * @param mail_id : Mail identification
  2114. * @return 0=error, 1=msg sent
  2115. */
  2116. bool intif_mail_getattach( struct map_session_data* sd, struct mail_message *msg, enum mail_attachment_type type){
  2117. if (CheckForCharServer())
  2118. return false;
  2119. WFIFOHEAD(inter_fd,11);
  2120. WFIFOW(inter_fd,0) = 0x304a;
  2121. WFIFOL(inter_fd,2) = sd->status.char_id;
  2122. WFIFOL(inter_fd,6) = msg->id;
  2123. WFIFOB(inter_fd,10) = (uint8)type;
  2124. WFIFOSET(inter_fd, 11);
  2125. return true;
  2126. }
  2127. /**
  2128. * Receive the attachment from char-serv of a mail
  2129. * @param fd : char-serv link
  2130. * @return 0=error, 1=sucess
  2131. */
  2132. int intif_parse_Mail_getattach(int fd)
  2133. {
  2134. struct map_session_data *sd;
  2135. struct item item[MAIL_MAX_ITEM];
  2136. int i, mail_id, zeny;
  2137. if (RFIFOW(fd, 2) - 16 != sizeof(struct item)*MAIL_MAX_ITEM)
  2138. {
  2139. ShowError("intif_parse_Mail_getattach: data size error %d %" PRIuPTR "\n", RFIFOW(fd, 2) - 16, sizeof(struct item));
  2140. return 0;
  2141. }
  2142. sd = map_charid2sd( RFIFOL(fd,4) );
  2143. if (sd == NULL)
  2144. {
  2145. ShowError("intif_parse_Mail_getattach: char not found %d\n",RFIFOL(fd,4));
  2146. return 0;
  2147. }
  2148. mail_id = RFIFOL(fd, 8);
  2149. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  2150. if (i == MAIL_MAX_INBOX)
  2151. return 0;
  2152. zeny = RFIFOL(fd, 12);
  2153. memcpy(item, RFIFOP(fd,16), sizeof(struct item)*MAIL_MAX_ITEM);
  2154. mail_getattachment(sd, &sd->mail.inbox.msg[i], zeny, item);
  2155. return 1;
  2156. }
  2157. /**
  2158. * request to delete a mail
  2159. * @param char_id : player requesting
  2160. * @param mail_id : mail to delete
  2161. * @return 0=error, 1=msg sent
  2162. */
  2163. int intif_Mail_delete(uint32 char_id, int mail_id)
  2164. {
  2165. if (CheckForCharServer())
  2166. return 0;
  2167. WFIFOHEAD(inter_fd,10);
  2168. WFIFOW(inter_fd,0) = 0x304b;
  2169. WFIFOL(inter_fd,2) = char_id;
  2170. WFIFOL(inter_fd,6) = mail_id;
  2171. WFIFOSET(inter_fd,10);
  2172. return 1;
  2173. }
  2174. /**
  2175. * Ack of a mail deletion
  2176. * @param fd : char-serv link
  2177. * @return 0=error, 1=success
  2178. */
  2179. int intif_parse_Mail_delete(int fd)
  2180. {
  2181. uint32 char_id = RFIFOL(fd,2);
  2182. int mail_id = RFIFOL(fd,6);
  2183. bool failed = RFIFOB(fd,10) > 0;
  2184. struct map_session_data *sd = map_charid2sd(char_id);
  2185. if (sd == NULL)
  2186. {
  2187. ShowError("intif_parse_Mail_delete: char not found %d\n", char_id);
  2188. return 0;
  2189. }
  2190. if (!failed)
  2191. {
  2192. int i;
  2193. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  2194. if( i < MAIL_MAX_INBOX )
  2195. {
  2196. enum mail_inbox_type type = sd->mail.inbox.msg[i].type;
  2197. clif_mail_delete(sd, &sd->mail.inbox.msg[i], !failed);
  2198. memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message));
  2199. sd->mail.inbox.amount--;
  2200. if( sd->mail.inbox.full || sd->mail.inbox.unchecked > 0 )
  2201. intif_Mail_requestinbox(sd->status.char_id, 1, type); // Free space is available for new mails
  2202. }
  2203. }
  2204. return 1;
  2205. }
  2206. /*------------------------------------------
  2207. * Return Message
  2208. *------------------------------------------*/
  2209. /**
  2210. * Request to return a mail to his sender
  2211. * @param char_id : player asking to return
  2212. * @param mail_id : mail to return
  2213. * @return 0=error, 1=msg sent
  2214. */
  2215. int intif_Mail_return(uint32 char_id, int mail_id)
  2216. {
  2217. if (CheckForCharServer())
  2218. return 0;
  2219. WFIFOHEAD(inter_fd,10);
  2220. WFIFOW(inter_fd,0) = 0x304c;
  2221. WFIFOL(inter_fd,2) = char_id;
  2222. WFIFOL(inter_fd,6) = mail_id;
  2223. WFIFOSET(inter_fd,10);
  2224. return 1;
  2225. }
  2226. /**
  2227. * Received a returned mail
  2228. * @param fd
  2229. * @return
  2230. */
  2231. int intif_parse_Mail_return(int fd)
  2232. {
  2233. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  2234. int mail_id = RFIFOL(fd,6);
  2235. short fail = RFIFOB(fd,10);
  2236. if( sd == NULL )
  2237. {
  2238. ShowError("intif_parse_Mail_return: char not found %d\n",RFIFOL(fd,2));
  2239. return 1;
  2240. }
  2241. if( !fail )
  2242. {
  2243. int i;
  2244. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  2245. if( i < MAIL_MAX_INBOX )
  2246. {
  2247. enum mail_inbox_type type = sd->mail.inbox.msg[i].type;
  2248. memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message));
  2249. sd->mail.inbox.amount--;
  2250. if( sd->mail.inbox.full )
  2251. intif_Mail_requestinbox(sd->status.char_id, 1, type); // Free space is available for new mails
  2252. }
  2253. }
  2254. clif_Mail_return(sd->fd, mail_id, fail);
  2255. return 1;
  2256. }
  2257. /*------------------------------------------
  2258. * Send Mail
  2259. *------------------------------------------*/
  2260. /**
  2261. * Request to send a mail
  2262. * @param account_id
  2263. * @param msg : mail struct
  2264. * @return 0=error, 1=msg sent
  2265. */
  2266. int intif_Mail_send(uint32 account_id, struct mail_message *msg)
  2267. {
  2268. int len = sizeof(struct mail_message) + 8;
  2269. if (CheckForCharServer())
  2270. return 0;
  2271. WFIFOHEAD(inter_fd,len);
  2272. WFIFOW(inter_fd,0) = 0x304d;
  2273. WFIFOW(inter_fd,2) = len;
  2274. WFIFOL(inter_fd,4) = account_id;
  2275. memcpy(WFIFOP(inter_fd,8), msg, sizeof(struct mail_message));
  2276. WFIFOSET(inter_fd,len);
  2277. return 1;
  2278. }
  2279. /**
  2280. * Received the ack of a mail send request
  2281. * @param fd L char-serv link
  2282. */
  2283. static void intif_parse_Mail_send(int fd)
  2284. {
  2285. struct mail_message msg;
  2286. struct map_session_data *sd;
  2287. bool fail;
  2288. if( RFIFOW(fd,2) - 4 != sizeof(struct mail_message) )
  2289. {
  2290. ShowError("intif_parse_Mail_send: data size error %d %" PRIuPTR "\n", RFIFOW(fd,2) - 4, sizeof(struct mail_message));
  2291. return;
  2292. }
  2293. memcpy(&msg, RFIFOP(fd,4), sizeof(struct mail_message));
  2294. fail = (msg.id == 0);
  2295. // notify sender
  2296. sd = map_charid2sd(msg.send_id);
  2297. if( sd != NULL )
  2298. {
  2299. if( fail )
  2300. mail_deliveryfail(sd, &msg);
  2301. else
  2302. {
  2303. clif_Mail_send(sd, WRITE_MAIL_SUCCESS);
  2304. if( save_settings&CHARSAVE_MAIL )
  2305. chrif_save(sd, CSAVE_INVENTORY);
  2306. }
  2307. }
  2308. }
  2309. /**
  2310. * Received a new mail notification
  2311. * @param fd : char-link serv
  2312. */
  2313. static void intif_parse_Mail_new(int fd)
  2314. {
  2315. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  2316. int mail_id = RFIFOL(fd,6);
  2317. const char* sender_name = RFIFOCP(fd,10);
  2318. const char* title = RFIFOCP(fd,34);
  2319. if( sd == NULL )
  2320. return;
  2321. sd->mail.changed = true;
  2322. sd->mail.inbox.unread++;
  2323. clif_Mail_new(sd, mail_id, sender_name, title);
  2324. #if PACKETVER >= 20150513
  2325. // Make sure the window gets refreshed when its open
  2326. intif_Mail_requestinbox(sd->status.char_id, 1, static_cast<mail_inbox_type>(RFIFOB(fd,74)));
  2327. #endif
  2328. }
  2329. static void intif_parse_Mail_receiver( int fd ){
  2330. struct map_session_data *sd;
  2331. sd = map_charid2sd( RFIFOL( fd, 2 ) );
  2332. // Only f the player is online
  2333. if( sd ){
  2334. clif_Mail_Receiver_Ack( sd, RFIFOL( fd, 6 ), RFIFOW( fd, 10 ), RFIFOW( fd, 12 ), RFIFOCP( fd, 14 ) );
  2335. }
  2336. }
  2337. bool intif_mail_checkreceiver( struct map_session_data* sd, char* name ){
  2338. struct map_session_data *tsd;
  2339. tsd = map_nick2sd( name, false );
  2340. // If the target player is online on this map-server
  2341. if( tsd != NULL ){
  2342. clif_Mail_Receiver_Ack( sd, tsd->status.char_id, tsd->status.class_, tsd->status.base_level, name );
  2343. return true;
  2344. }
  2345. if( CheckForCharServer() )
  2346. return false;
  2347. WFIFOHEAD(inter_fd, 6 + NAME_LENGTH);
  2348. WFIFOW(inter_fd, 0) = 0x304e;
  2349. WFIFOL(inter_fd, 2) = sd->status.char_id;
  2350. safestrncpy(WFIFOCP(inter_fd, 6), name, NAME_LENGTH);
  2351. WFIFOSET(inter_fd, 6 + NAME_LENGTH);
  2352. return true;
  2353. }
  2354. /*==========================================
  2355. * AUCTION SYSTEM
  2356. * By Zephyrus
  2357. *==========================================*/
  2358. /**
  2359. * Request a list of auction matching criteria
  2360. * @param char_id : player searching auction
  2361. * @param type : see clif_parse_Auction_search type
  2362. * @param price : min price for search
  2363. * @param searchtext : contain item name
  2364. * @param page : in case of huge result list display 5 entry per page, (kinda suck that we redo the request atm)
  2365. * @return 0=error, 1=msg sent
  2366. */
  2367. int intif_Auction_requestlist(uint32 char_id, short type, int price, const char* searchtext, short page)
  2368. {
  2369. int len = NAME_LENGTH + 16;
  2370. if( CheckForCharServer() )
  2371. return 0;
  2372. WFIFOHEAD(inter_fd,len);
  2373. WFIFOW(inter_fd,0) = 0x3050;
  2374. WFIFOW(inter_fd,2) = len;
  2375. WFIFOL(inter_fd,4) = char_id;
  2376. WFIFOW(inter_fd,8) = type;
  2377. WFIFOL(inter_fd,10) = price; //min price for search
  2378. WFIFOW(inter_fd,14) = page;
  2379. memcpy(WFIFOP(inter_fd,16), searchtext, NAME_LENGTH);
  2380. WFIFOSET(inter_fd,len);
  2381. return 1;
  2382. }
  2383. /**
  2384. * Received a list of auction, display them
  2385. * @param fd : Char-serv link
  2386. */
  2387. static void intif_parse_Auction_results(int fd)
  2388. {
  2389. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,4));
  2390. short count = RFIFOW(fd,8);
  2391. short pages = RFIFOW(fd,10);
  2392. uint8* data = RFIFOP(fd,12);
  2393. if( sd == NULL )
  2394. return;
  2395. clif_Auction_results(sd, count, pages, data);
  2396. }
  2397. /**
  2398. * Register an auction to char-serv
  2399. * @param auction : tmp auction to register
  2400. * @return 0=error, 1=msg sent
  2401. */
  2402. int intif_Auction_register(struct auction_data *auction)
  2403. {
  2404. int len = sizeof(struct auction_data) + 4;
  2405. if( CheckForCharServer() )
  2406. return 0;
  2407. WFIFOHEAD(inter_fd,len);
  2408. WFIFOW(inter_fd,0) = 0x3051;
  2409. WFIFOW(inter_fd,2) = len;
  2410. memcpy(WFIFOP(inter_fd,4), auction, sizeof(struct auction_data));
  2411. WFIFOSET(inter_fd,len);
  2412. return 1;
  2413. }
  2414. /**
  2415. * Receive a auction available from char-serv
  2416. * @param fd : char-serv link
  2417. */
  2418. static void intif_parse_Auction_register(int fd)
  2419. {
  2420. struct map_session_data *sd;
  2421. struct auction_data auction;
  2422. if( RFIFOW(fd,2) - 4 != sizeof(struct auction_data) )
  2423. {
  2424. ShowError("intif_parse_Auction_register: data size error %d %" PRIuPTR "\n", RFIFOW(fd,2) - 4, sizeof(struct auction_data));
  2425. return;
  2426. }
  2427. memcpy(&auction, RFIFOP(fd,4), sizeof(struct auction_data));
  2428. if( (sd = map_charid2sd(auction.seller_id)) == NULL )
  2429. return;
  2430. if( auction.auction_id > 0 )
  2431. {
  2432. clif_Auction_message(sd->fd, 1); // Confirmation Packet ??
  2433. if( save_settings&CHARSAVE_AUCTION )
  2434. chrif_save(sd, CSAVE_INVENTORY);
  2435. }
  2436. else
  2437. {
  2438. int zeny = auction.hours*battle_config.auction_feeperhour;
  2439. clif_Auction_message(sd->fd, 4);
  2440. pc_additem(sd, &auction.item, auction.item.amount, LOG_TYPE_AUCTION);
  2441. pc_getzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  2442. }
  2443. }
  2444. /**
  2445. * Inform char-serv that the auction is cancelled
  2446. * @param char_id : player that has cancel the auction
  2447. * @param auction_id : auction to cancel
  2448. * @return 0=error, 1=msg sent
  2449. */
  2450. int intif_Auction_cancel(uint32 char_id, unsigned int auction_id)
  2451. {
  2452. if( CheckForCharServer() )
  2453. return 0;
  2454. WFIFOHEAD(inter_fd,10);
  2455. WFIFOW(inter_fd,0) = 0x3052;
  2456. WFIFOL(inter_fd,2) = char_id;
  2457. WFIFOL(inter_fd,6) = auction_id;
  2458. WFIFOSET(inter_fd,10);
  2459. return 1;
  2460. }
  2461. /**
  2462. * Receive a notification that the auction was cancelled
  2463. * @param fd : char-serv link
  2464. */
  2465. static void intif_parse_Auction_cancel(int fd)
  2466. {
  2467. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  2468. int result = RFIFOB(fd,6);
  2469. if( sd == NULL )
  2470. return;
  2471. switch( result )
  2472. {
  2473. case 0: clif_Auction_message(sd->fd, 2); break;
  2474. case 1: clif_Auction_close(sd->fd, 2); break;
  2475. case 2: clif_Auction_close(sd->fd, 1); break;
  2476. case 3: clif_Auction_message(sd->fd, 3); break;
  2477. }
  2478. }
  2479. /**
  2480. * Inform the char-serv that the auction has ended
  2481. * @param char_id : player that stop the auction
  2482. * @param auction_id : auction to stop
  2483. * @return 0=error, 1=msg sent
  2484. */
  2485. int intif_Auction_close(uint32 char_id, unsigned int auction_id)
  2486. {
  2487. if( CheckForCharServer() )
  2488. return 0;
  2489. WFIFOHEAD(inter_fd,10);
  2490. WFIFOW(inter_fd,0) = 0x3053;
  2491. WFIFOL(inter_fd,2) = char_id;
  2492. WFIFOL(inter_fd,6) = auction_id;
  2493. WFIFOSET(inter_fd,10);
  2494. return 1;
  2495. }
  2496. /**
  2497. * Receive a notification that the auction has ended
  2498. * @param fd : char-serv link
  2499. */
  2500. static void intif_parse_Auction_close(int fd)
  2501. {
  2502. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  2503. unsigned char result = RFIFOB(fd,6);
  2504. if( sd == NULL )
  2505. return;
  2506. clif_Auction_close(sd->fd, result);
  2507. if( result == 0 )
  2508. {
  2509. // FIXME: Leeching off a parse function
  2510. clif_parse_Auction_cancelreg(fd, sd);
  2511. intif_Auction_requestlist(sd->status.char_id, 6, 0, "", 1);
  2512. }
  2513. }
  2514. /**
  2515. * Bid for an auction
  2516. * @param char_id
  2517. * @param name
  2518. * @param auction_id
  2519. * @param bid
  2520. * @return 0=error, 1=msg sent
  2521. */
  2522. int intif_Auction_bid(uint32 char_id, const char* name, unsigned int auction_id, int bid)
  2523. {
  2524. int len = 16 + NAME_LENGTH;
  2525. if( CheckForCharServer() )
  2526. return 0;
  2527. WFIFOHEAD(inter_fd,len);
  2528. WFIFOW(inter_fd,0) = 0x3055;
  2529. WFIFOW(inter_fd,2) = len;
  2530. WFIFOL(inter_fd,4) = char_id;
  2531. WFIFOL(inter_fd,8) = auction_id;
  2532. WFIFOL(inter_fd,12) = bid;
  2533. memcpy(WFIFOP(inter_fd,16), name, NAME_LENGTH);
  2534. WFIFOSET(inter_fd,len);
  2535. return 1;
  2536. }
  2537. /**
  2538. * Get back the money from biding auction,
  2539. * (someone else have bid it over)
  2540. * @param fd : char-serv link
  2541. */
  2542. static void intif_parse_Auction_bid(int fd)
  2543. {
  2544. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  2545. int bid = RFIFOL(fd,6);
  2546. unsigned char result = RFIFOB(fd,10);
  2547. if( sd == NULL )
  2548. return;
  2549. clif_Auction_message(sd->fd, result);
  2550. if( bid > 0 )
  2551. {
  2552. pc_getzeny(sd, bid, LOG_TYPE_AUCTION,NULL);
  2553. }
  2554. if( result == 1 )
  2555. { // To update the list, display your buy list
  2556. clif_parse_Auction_cancelreg(fd, sd);
  2557. intif_Auction_requestlist(sd->status.char_id, 7, 0, "", 1);
  2558. }
  2559. }
  2560. /**
  2561. * Used to send 'You have won the auction' and 'You failed to won the auction' messages
  2562. * @param fd : char-serv link
  2563. */
  2564. static void intif_parse_Auction_message(int fd)
  2565. {
  2566. struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
  2567. unsigned char result = RFIFOB(fd,6);
  2568. if( sd == NULL )
  2569. return;
  2570. clif_Auction_message(sd->fd, result);
  2571. }
  2572. /*==========================================
  2573. * Mercenary's System
  2574. *------------------------------------------*/
  2575. /**
  2576. * Request to create/register a mercenary on char-serv
  2577. * @param merc : Tmp mercenary data
  2578. * @return 0=error, 1=msg sent
  2579. */
  2580. int intif_mercenary_create(struct s_mercenary *merc)
  2581. {
  2582. int size = sizeof(struct s_mercenary) + 4;
  2583. if( CheckForCharServer() )
  2584. return 0;
  2585. WFIFOHEAD(inter_fd,size);
  2586. WFIFOW(inter_fd,0) = 0x3070;
  2587. WFIFOW(inter_fd,2) = size;
  2588. memcpy(WFIFOP(inter_fd,4), merc, sizeof(struct s_mercenary));
  2589. WFIFOSET(inter_fd,size);
  2590. return 1;
  2591. }
  2592. /**
  2593. * Ack of a load or create request
  2594. * @param fd : char-serv link
  2595. * @return 0=error, 1=success
  2596. */
  2597. int intif_parse_mercenary_received(int fd)
  2598. {
  2599. int len = RFIFOW(fd,2) - 5;
  2600. if( sizeof(struct s_mercenary) != len )
  2601. {
  2602. if( battle_config.etc_log )
  2603. ShowError("intif: create mercenary data size error %" PRIuPTR " != %d\n", sizeof(struct s_mercenary), len);
  2604. return 0;
  2605. }
  2606. mercenary_recv_data((struct s_mercenary*)RFIFOP(fd,5), RFIFOB(fd,4) > 0);
  2607. return 1;
  2608. }
  2609. /**
  2610. * Request mercenary data from char-serv
  2611. * @param merc_id : mercenary id to load
  2612. * @param char_id : player cid requesting data
  2613. * @return 0=error, 1=msg sent
  2614. */
  2615. int intif_mercenary_request(int merc_id, uint32 char_id)
  2616. {
  2617. if (CheckForCharServer())
  2618. return 0;
  2619. WFIFOHEAD(inter_fd,10);
  2620. WFIFOW(inter_fd,0) = 0x3071;
  2621. WFIFOL(inter_fd,2) = merc_id;
  2622. WFIFOL(inter_fd,6) = char_id;
  2623. WFIFOSET(inter_fd,10);
  2624. return 1;
  2625. }
  2626. /**
  2627. * Request to delete a mercenary
  2628. * @param merc_id
  2629. * @return 0=error, 1=msg sent
  2630. */
  2631. int intif_mercenary_delete(int merc_id)
  2632. {
  2633. if (CheckForCharServer())
  2634. return 0;
  2635. WFIFOHEAD(inter_fd,6);
  2636. WFIFOW(inter_fd,0) = 0x3072;
  2637. WFIFOL(inter_fd,2) = merc_id;
  2638. WFIFOSET(inter_fd,6);
  2639. return 1;
  2640. }
  2641. /**
  2642. * Ack of a mercenary deletion request
  2643. * @param fd : char-serv link
  2644. * @return 1
  2645. */
  2646. int intif_parse_mercenary_deleted(int fd)
  2647. {
  2648. if( RFIFOB(fd,2) != 1 )
  2649. ShowError("Mercenary data delete failure\n");
  2650. return 1;
  2651. }
  2652. /**
  2653. * Request to save a mercenary
  2654. * @param merc : Mercenary struct to save
  2655. * @return 0=error, 1=msg sent
  2656. */
  2657. int intif_mercenary_save(struct s_mercenary *merc)
  2658. {
  2659. int size = sizeof(struct s_mercenary) + 4;
  2660. if( CheckForCharServer() )
  2661. return 0;
  2662. WFIFOHEAD(inter_fd,size);
  2663. WFIFOW(inter_fd,0) = 0x3073;
  2664. WFIFOW(inter_fd,2) = size;
  2665. memcpy(WFIFOP(inter_fd,4), merc, sizeof(struct s_mercenary));
  2666. WFIFOSET(inter_fd,size);
  2667. return 1;
  2668. }
  2669. /**
  2670. * Ack of a mercenary save request
  2671. * @param fd : char-serv link
  2672. * @return 1
  2673. */
  2674. int intif_parse_mercenary_saved(int fd)
  2675. {
  2676. if( RFIFOB(fd,2) != 1 )
  2677. ShowError("Mercenary data save failure\n");
  2678. return 1;
  2679. }
  2680. /*==========================================
  2681. * Elemental's System
  2682. *------------------------------------------*/
  2683. /**
  2684. * Request to create elemental, (verify and save on char-serv)
  2685. * @param ele : Tmp Elemental data
  2686. * @return 0=error, 1=msg sent
  2687. */
  2688. int intif_elemental_create(struct s_elemental *ele)
  2689. {
  2690. int size = sizeof(struct s_elemental) + 4;
  2691. if( CheckForCharServer() )
  2692. return 0;
  2693. WFIFOHEAD(inter_fd,size);
  2694. WFIFOW(inter_fd,0) = 0x307c;
  2695. WFIFOW(inter_fd,2) = size;
  2696. memcpy(WFIFOP(inter_fd,4), ele, sizeof(struct s_elemental));
  2697. WFIFOSET(inter_fd,size);
  2698. return 1;
  2699. }
  2700. /**
  2701. * Receive an elemental data from char-serv
  2702. * @param fd : char-serv link
  2703. * @return 0=error, 1=success
  2704. */
  2705. int intif_parse_elemental_received(int fd)
  2706. {
  2707. int len = RFIFOW(fd,2) - 5;
  2708. if( sizeof(struct s_elemental) != len )
  2709. {
  2710. if( battle_config.etc_log )
  2711. ShowError("intif: create elemental data size error %" PRIuPTR " != %d\n", sizeof(struct s_elemental), len);
  2712. return 0;
  2713. }
  2714. elemental_data_received((struct s_elemental*)RFIFOP(fd,5), RFIFOB(fd,4) > 0);
  2715. return 1;
  2716. }
  2717. /**
  2718. * Request to load elemental from char-serv
  2719. * @param ele_id : elemental identification
  2720. * @param char_id : player identification
  2721. * @return 0=error, 1=msg sent
  2722. */
  2723. int intif_elemental_request(int ele_id, uint32 char_id)
  2724. {
  2725. if (CheckForCharServer())
  2726. return 0;
  2727. WFIFOHEAD(inter_fd,10);
  2728. WFIFOW(inter_fd,0) = 0x307d;
  2729. WFIFOL(inter_fd,2) = ele_id;
  2730. WFIFOL(inter_fd,6) = char_id;
  2731. WFIFOSET(inter_fd,10);
  2732. return 1;
  2733. }
  2734. /**
  2735. * Request to delete an elemental
  2736. * @param ele_id : Elemental to delete
  2737. * @return 0=error, 1=msg sent
  2738. */
  2739. int intif_elemental_delete(int ele_id)
  2740. {
  2741. if (CheckForCharServer())
  2742. return 0;
  2743. WFIFOHEAD(inter_fd,6);
  2744. WFIFOW(inter_fd,0) = 0x307e;
  2745. WFIFOL(inter_fd,2) = ele_id;
  2746. WFIFOSET(inter_fd,6);
  2747. return 1;
  2748. }
  2749. /**
  2750. * Ack of a delete elemental request
  2751. * @param fd : char-serv link
  2752. * @return 1
  2753. */
  2754. int intif_parse_elemental_deleted(int fd)
  2755. {
  2756. if( RFIFOB(fd,2) != 1 )
  2757. ShowError("Elemental data delete failure\n");
  2758. return 1;
  2759. }
  2760. /**
  2761. * Request to save elemental data
  2762. * @param ele : elemental struct to save
  2763. * @return 0=error, 1=msg sent
  2764. */
  2765. int intif_elemental_save(struct s_elemental *ele)
  2766. {
  2767. int size = sizeof(struct s_elemental) + 4;
  2768. if( CheckForCharServer() )
  2769. return 0;
  2770. WFIFOHEAD(inter_fd,size);
  2771. WFIFOW(inter_fd,0) = 0x307f;
  2772. WFIFOW(inter_fd,2) = size;
  2773. memcpy(WFIFOP(inter_fd,4), ele, sizeof(struct s_elemental));
  2774. WFIFOSET(inter_fd,size);
  2775. return 1;
  2776. }
  2777. /**
  2778. * Ack of a save elemental request
  2779. * @param fd : char-serv link
  2780. * @return 1
  2781. */
  2782. int intif_parse_elemental_saved(int fd)
  2783. {
  2784. if( RFIFOB(fd,2) != 1 )
  2785. ShowError("Elemental data save failure\n");
  2786. return 1;
  2787. }
  2788. /**
  2789. * Request account information to char-serv
  2790. * @param u_fd : Player fd (for message back)
  2791. * @param aid : requesting player aid
  2792. * @param group_lv : requesting player lv
  2793. * @param query : name or aid of player we want info
  2794. * @param type : 1 - Only return account id & userid, 0 - Full info
  2795. * @return : 0=error, 1=msg sent
  2796. */
  2797. int intif_request_accinfo(int u_fd, int aid, int group_lv, char* query, char type) {
  2798. if( CheckForCharServer() )
  2799. return 0;
  2800. WFIFOHEAD(inter_fd,2 + 4 + 4 + 4 + 1 + NAME_LENGTH);
  2801. WFIFOW(inter_fd,0) = 0x3007;
  2802. WFIFOL(inter_fd,2) = u_fd;
  2803. WFIFOL(inter_fd,6) = aid;
  2804. WFIFOL(inter_fd,10) = group_lv;
  2805. WFIFOB(inter_fd,14) = type;
  2806. safestrncpy(WFIFOCP(inter_fd,15), query, NAME_LENGTH);
  2807. WFIFOSET(inter_fd,2 + 4 + 4 + 4 + 1 + NAME_LENGTH);
  2808. return 1;
  2809. }
  2810. /**
  2811. * Receive the reply of a request_accinfo with type 1
  2812. * @param fd : char-serv link
  2813. */
  2814. void intif_parse_accinfo_ack( int fd ) {
  2815. char acc_name[NAME_LENGTH];
  2816. int u_fd = RFIFOL(fd,2);
  2817. int acc_id = RFIFOL(fd,6);
  2818. safestrncpy(acc_name, RFIFOCP(fd,10), NAME_LENGTH);
  2819. clif_account_name(u_fd, acc_id, acc_name);
  2820. }
  2821. /**
  2822. * Display a message from char-serv to a player
  2823. * @param fd : Char-serv link
  2824. */
  2825. void intif_parse_MessageToFD(int fd) {
  2826. int u_fd = RFIFOL(fd,4);
  2827. if( session[u_fd] && session[u_fd]->session_data ) { //check if the player still online
  2828. int aid = RFIFOL(fd,8);
  2829. struct map_session_data * sd = (struct map_session_data *)session[u_fd]->session_data;
  2830. /* matching e.g. previous fd owner didn't dc during request or is still the same */
  2831. if( sd->bl.id == aid ) {
  2832. char msg[512];
  2833. safestrncpy(msg, RFIFOCP(fd,12), RFIFOW(fd,2) - 12);
  2834. clif_displaymessage(u_fd,msg);
  2835. }
  2836. }
  2837. return;
  2838. }
  2839. /// BROADCAST OBTAIN SPECIAL ITEM
  2840. /**
  2841. * Request to send broadcast item to all servers
  2842. * ZI 3009 <cmd>.W <len>.W <nameid>.N <source>.W <type>.B <name>.?B
  2843. * @param sd Player who obtain the item
  2844. * @param nameid Obtained item
  2845. * @param sourceid Source of item, another item ID or monster ID
  2846. * @param type Obtain type @see enum BROADCASTING_SPECIAL_ITEM_OBTAIN
  2847. * @return
  2848. **/
  2849. int intif_broadcast_obtain_special_item(struct map_session_data *sd, t_itemid nameid, t_itemid sourceid, unsigned char type) {
  2850. nullpo_retr(0, sd);
  2851. // Should not be here!
  2852. if (type == ITEMOBTAIN_TYPE_NPC) {
  2853. intif_broadcast_obtain_special_item_npc(sd, nameid);
  2854. return 0;
  2855. }
  2856. // Send local
  2857. clif_broadcast_obtain_special_item(sd->status.name, nameid, sourceid, (enum BROADCASTING_SPECIAL_ITEM_OBTAIN)type);
  2858. if (CheckForCharServer())
  2859. return 0;
  2860. if (other_mapserver_count < 1)
  2861. return 0;
  2862. WFIFOHEAD(inter_fd, 11 + NAME_LENGTH);
  2863. WFIFOW(inter_fd, 0) = 0x3009;
  2864. WFIFOW(inter_fd, 2) = 11 + NAME_LENGTH;
  2865. WFIFOL(inter_fd, 4) = nameid;
  2866. WFIFOW(inter_fd, 8) = sourceid;
  2867. WFIFOB(inter_fd, 10) = type;
  2868. safestrncpy(WFIFOCP(inter_fd, 11), sd->status.name, NAME_LENGTH);
  2869. WFIFOSET(inter_fd, WFIFOW(inter_fd, 2));
  2870. return 1;
  2871. }
  2872. /**
  2873. * Request to send broadcast item to all servers.
  2874. * TODO: Confirm the usage. Maybe on getitem-like command?
  2875. * ZI 3009 <cmd>.W <len>.W <nameid>.N <source>.W <type>.B <name>.24B <npcname>.24B
  2876. * @param sd Player who obtain the item
  2877. * @param nameid Obtained item
  2878. * @param srcname Source name
  2879. * @return
  2880. **/
  2881. int intif_broadcast_obtain_special_item_npc(struct map_session_data *sd, t_itemid nameid) {
  2882. nullpo_retr(0, sd);
  2883. // Send local
  2884. clif_broadcast_obtain_special_item(sd->status.name, nameid, 0, ITEMOBTAIN_TYPE_NPC);
  2885. if (CheckForCharServer())
  2886. return 0;
  2887. if (other_mapserver_count < 1)
  2888. return 0;
  2889. WFIFOHEAD(inter_fd, 11 + NAME_LENGTH*2);
  2890. WFIFOW(inter_fd, 0) = 0x3009;
  2891. WFIFOW(inter_fd, 2) = 11 + NAME_LENGTH*2;
  2892. WFIFOL(inter_fd, 4) = nameid;
  2893. WFIFOW(inter_fd, 8) = 0;
  2894. WFIFOB(inter_fd, 10) = ITEMOBTAIN_TYPE_NPC;
  2895. safestrncpy(WFIFOCP(inter_fd, 11), sd->status.name, NAME_LENGTH);
  2896. WFIFOSET(inter_fd, WFIFOW(inter_fd, 2));
  2897. return 1;
  2898. }
  2899. /**
  2900. * Received broadcast item and broadcast on local map.
  2901. * IZ 3809 <cmd>.W <len>.W <nameid>.L <source>.W <type>.B <name>.24B <srcname>.24B
  2902. * @param fd
  2903. **/
  2904. void intif_parse_broadcast_obtain_special_item(int fd) {
  2905. int type = RFIFOB(fd, 10);
  2906. char name[NAME_LENGTH];
  2907. safestrncpy(name, RFIFOCP(fd, 11), NAME_LENGTH);
  2908. if (type == ITEMOBTAIN_TYPE_NPC)
  2909. safestrncpy(name, RFIFOCP(fd, 11 + NAME_LENGTH), NAME_LENGTH);
  2910. clif_broadcast_obtain_special_item(name, RFIFOL(fd, 4), RFIFOW(fd, 8), (enum BROADCASTING_SPECIAL_ITEM_OBTAIN)type);
  2911. }
  2912. /*==========================================
  2913. * Item Bound System
  2914. *------------------------------------------*/
  2915. #ifdef BOUND_ITEMS
  2916. /**
  2917. * ZI 0x3056 <char_id>.L <account_id>.L <guild_id>.W
  2918. * Request inter-serv to delete some bound item, for non connected cid
  2919. * @param char_id : Char to delete item ID
  2920. * @param aid : Account to delete item ID
  2921. * @param guild_id : Guild of char
  2922. */
  2923. void intif_itembound_guild_retrieve(uint32 char_id,uint32 account_id,int guild_id) {
  2924. struct s_storage *gstor = guild2storage2(guild_id);
  2925. if( CheckForCharServer() )
  2926. return;
  2927. WFIFOHEAD(inter_fd,12);
  2928. WFIFOW(inter_fd,0) = 0x3056;
  2929. WFIFOL(inter_fd,2) = char_id;
  2930. WFIFOL(inter_fd,6) = account_id;
  2931. WFIFOW(inter_fd,10) = guild_id;
  2932. WFIFOSET(inter_fd,12);
  2933. if (gstor)
  2934. gstor->lock = true; //Lock for retrieval process
  2935. ShowInfo("Request guild bound item(s) retrieval for CID = " CL_WHITE "%d" CL_RESET ", AID = %d, Guild ID = " CL_WHITE "%d" CL_RESET ".\n", char_id, account_id, guild_id);
  2936. }
  2937. /**
  2938. * Acknowledge the good deletion of the bound item
  2939. * (unlock the guild storage)
  2940. * @struct : 0x3856 <aid>.L <gid>.W
  2941. * @param fd : Char-serv link
  2942. */
  2943. void intif_parse_itembound_ack(int fd) {
  2944. int guild_id = RFIFOW(fd,6);
  2945. struct s_storage *gstor = guild2storage2(guild_id);
  2946. if (gstor)
  2947. gstor->lock = false; //Unlock now that operation is completed
  2948. }
  2949. /**
  2950. * IZ 0x3857 <size>.W <count>.W <guild_id>.W { <item>.?B }.*MAX_INVENTORY
  2951. * Received the retrieved guild bound items from inter-server, store them to guild storage.
  2952. * @param fd
  2953. * @author [Cydh]
  2954. */
  2955. void intif_parse_itembound_store2gstorage(int fd) {
  2956. unsigned short i, failed = 0;
  2957. short count = RFIFOW(fd, 4), guild_id = RFIFOW(fd, 6);
  2958. struct s_storage *gstor = guild2storage(guild_id);
  2959. if (!gstor) {
  2960. ShowError("intif_parse_itembound_store2gstorage: Guild '%d' not found.\n", guild_id);
  2961. return;
  2962. }
  2963. //@TODO: Gives some actions for item(s) that cannot be stored because storage is full or reach the limit of stack amount
  2964. for (i = 0; i < count; i++) {
  2965. struct item *item = (struct item*)RFIFOP(fd, 8 + i*sizeof(struct item));
  2966. if (!item)
  2967. continue;
  2968. if (!storage_guild_additem2(gstor, item, item->amount))
  2969. failed++;
  2970. }
  2971. ShowInfo("Retrieved '" CL_WHITE "%d" CL_RESET "' (failed: %d) guild bound item(s) for Guild ID = " CL_WHITE "%d" CL_RESET ".\n", count, failed, guild_id);
  2972. gstor->lock = false;
  2973. gstor->status = false;
  2974. }
  2975. #endif
  2976. /**
  2977. * Receive inventory/cart/storage data for player
  2978. * IZ 0x388a <size>.W <type>.B <account_id>.L <result>.B <storage>.?B
  2979. * @param fd
  2980. */
  2981. static bool intif_parse_StorageReceived(int fd)
  2982. {
  2983. char type = RFIFOB(fd,4);
  2984. uint32 account_id = RFIFOL(fd, 5);
  2985. struct map_session_data *sd = map_id2sd(account_id);
  2986. struct s_storage *stor, *p; //storage
  2987. size_t sz_stor = sizeof(struct s_storage);
  2988. if (!sd) {
  2989. ShowError("intif_parse_StorageReceived: No player online for receiving inventory/cart/storage data (AID: %d)\n", account_id);
  2990. return false;
  2991. }
  2992. if (!RFIFOB(fd, 9)) {
  2993. ShowError("intif_parse_StorageReceived: Failed to load! (AID: %d, type: %d)\n", account_id, type);
  2994. return false;
  2995. }
  2996. p = (struct s_storage *)RFIFOP(fd,10);
  2997. switch (type) {
  2998. case TABLE_INVENTORY:
  2999. stor = &sd->inventory;
  3000. break;
  3001. case TABLE_STORAGE:
  3002. if (p->stor_id == 0)
  3003. stor = &sd->storage;
  3004. else
  3005. stor = &sd->premiumStorage;
  3006. break;
  3007. case TABLE_CART:
  3008. stor = &sd->cart;
  3009. break;
  3010. default:
  3011. return false;
  3012. }
  3013. if (stor->stor_id == p->stor_id) {
  3014. if (stor->status) { // Already open.. lets ignore this update
  3015. ShowWarning("intif_parse_StorageReceived: storage received for a client already open (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
  3016. return false;
  3017. }
  3018. if (stor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit!
  3019. ShowWarning("intif_parse_StorageReceived: received storage for an already modified non-saved storage! (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
  3020. return false;
  3021. }
  3022. }
  3023. if (RFIFOW(fd,2)-10 != sz_stor) {
  3024. ShowError("intif_parse_StorageReceived: data size error %d %" PRIuPTR "\n",RFIFOW(fd,2)-10 , sz_stor);
  3025. stor->status = false;
  3026. return false;
  3027. }
  3028. memcpy(stor, p, sz_stor); //copy the items data to correct destination
  3029. switch (type) {
  3030. case TABLE_INVENTORY: {
  3031. #ifdef BOUND_ITEMS
  3032. int j, idxlist[MAX_INVENTORY];
  3033. #endif
  3034. pc_setinventorydata(sd);
  3035. pc_setequipindex(sd);
  3036. pc_check_expiration(sd);
  3037. pc_check_available_item(sd, ITMCHK_INVENTORY);
  3038. pc_itemcd_do(sd, true);
  3039. #ifdef BOUND_ITEMS
  3040. // Party bound item check
  3041. if (sd->status.party_id == 0 && (j = pc_bound_chk(sd, BOUND_PARTY, idxlist))) { // Party was deleted while character offline
  3042. int i;
  3043. for (i = 0; i < j; i++)
  3044. pc_delitem(sd, idxlist[i], sd->inventory.u.items_inventory[idxlist[i]].amount, 4, 1, LOG_TYPE_OTHER);
  3045. }
  3046. #endif
  3047. //Set here because we need the inventory data for weapon sprite parsing.
  3048. status_set_viewdata(&sd->bl, sd->status.class_);
  3049. // Set headgear data here, otherwise this is done in loadEndAck
  3050. if( sd->state.autotrade ){
  3051. pc_set_costume_view(sd);
  3052. }
  3053. pc_load_combo(sd);
  3054. status_calc_pc(sd, (enum e_status_calc_opt)(SCO_FIRST|SCO_FORCE));
  3055. status_calc_weight(sd, (e_status_calc_weight_opt)(CALCWT_ITEM|CALCWT_MAXBONUS)); // Refresh weight data
  3056. chrif_scdata_request(sd->status.account_id, sd->status.char_id);
  3057. break;
  3058. }
  3059. case TABLE_CART:
  3060. pc_check_available_item(sd, ITMCHK_CART);
  3061. if (sd->state.autotrade) {
  3062. clif_parse_LoadEndAck(sd->fd, sd);
  3063. sd->autotrade_tid = add_timer(gettick() + battle_config.feature_autotrade_open_delay, pc_autotrade_timer, sd->bl.id, 0);
  3064. }else if( sd->state.prevend ){
  3065. clif_clearcart(sd->fd);
  3066. clif_cartlist(sd);
  3067. clif_openvendingreq(sd, sd->vend_skill_lv+2);
  3068. }
  3069. break;
  3070. case TABLE_STORAGE:
  3071. if (stor->stor_id)
  3072. storage_premiumStorage_open(sd);
  3073. else {
  3074. #ifdef VIP_ENABLE
  3075. if (!pc_isvip(sd))
  3076. stor->max_amount = MIN_STORAGE;
  3077. #endif
  3078. pc_check_available_item(sd, ITMCHK_STORAGE);
  3079. }
  3080. break;
  3081. }
  3082. return true;
  3083. }
  3084. /**
  3085. * Save inventory/cart/storage data for a player
  3086. * IZ 0x388b <account_id>.L <result>.B <type>.B <storage_id>.B
  3087. * @param fd
  3088. */
  3089. static void intif_parse_StorageSaved(int fd)
  3090. {
  3091. if (RFIFOB(fd, 6)) {
  3092. switch (RFIFOB(fd, 7)) {
  3093. case TABLE_INVENTORY: //inventory
  3094. //ShowInfo("Inventory has been saved (AID: %d).\n", RFIFOL(fd, 2));
  3095. break;
  3096. case TABLE_STORAGE: //storage
  3097. {
  3098. struct map_session_data *sd = map_id2sd( RFIFOL( fd, 2 ) );
  3099. struct s_storage* stor = nullptr;
  3100. if( RFIFOB( fd, 8 ) ){
  3101. // ShowInfo("Storage %d has been saved (AID: %d).\n", RFIFOL(fd, 2), RFIFOB(fd, 8) );
  3102. if( sd ){
  3103. stor = &sd->premiumStorage;
  3104. }
  3105. }else{
  3106. // ShowInfo("Storage has been saved (AID: %d).\n", RFIFOL(fd, 2));
  3107. if( sd ){
  3108. stor = &sd->storage;
  3109. }
  3110. }
  3111. if( stor ){
  3112. stor->dirty = false;
  3113. }
  3114. }
  3115. break;
  3116. case TABLE_CART: // cart
  3117. //ShowInfo("Cart has been saved (AID: %d).\n", RFIFOL(fd, 2));
  3118. {
  3119. struct map_session_data *sd = map_id2sd(RFIFOL(fd, 2));
  3120. if( sd && sd->state.prevend ){
  3121. intif_storage_request(sd,TABLE_CART,0,STOR_MODE_ALL);
  3122. }
  3123. }
  3124. break;
  3125. default:
  3126. break;
  3127. }
  3128. } else
  3129. ShowError("Failed to save inventory/cart/storage data (AID: %d, type: %d).\n", RFIFOL(fd, 2), RFIFOB(fd, 7));
  3130. }
  3131. /**
  3132. * IZ 0x388c <len>.W { <storage_table>.? }*?
  3133. * Receive storage information
  3134. **/
  3135. void intif_parse_StorageInfo_recv(int fd) {
  3136. int size = sizeof(struct s_storage_table), count = (RFIFOW(fd, 2) - 4) / size;
  3137. storage_db.clear();
  3138. for( int i = 0; i < count; i++ ){
  3139. struct s_storage_table* ptr = (struct s_storage_table*)RFIFOP( fd, 4 + size * i );
  3140. std::shared_ptr<struct s_storage_table> storage = std::make_shared<struct s_storage_table>();
  3141. safestrncpy( storage->name, ptr->name, sizeof( storage->name ) );
  3142. safestrncpy( storage->table, ptr->table, sizeof( storage->table ) );
  3143. storage->max_num = ptr->max_num;
  3144. storage->id = ptr->id;
  3145. storage_db[storage->id] = storage;
  3146. }
  3147. if (battle_config.etc_log)
  3148. ShowInfo("Received '" CL_WHITE PRIdPTR CL_RESET "' storage info from inter-server.\n", storage_db.size());
  3149. }
  3150. /**
  3151. * Request inventory/cart/storage data for a player
  3152. * ZI 0x308a <type>.B <account_id>.L <char_id>.L <storage_id>.B
  3153. * @param sd: Player data
  3154. * @param type: Storage type
  3155. * @param stor_id: Storage ID
  3156. * @param mode: Storage mode
  3157. * @return false - error, true - message sent
  3158. */
  3159. bool intif_storage_request(struct map_session_data *sd, enum storage_type type, uint8 stor_id, uint8 mode)
  3160. {
  3161. if (CheckForCharServer())
  3162. return false;
  3163. WFIFOHEAD(inter_fd, 13);
  3164. WFIFOW(inter_fd, 0) = 0x308a;
  3165. WFIFOB(inter_fd, 2) = type;
  3166. WFIFOL(inter_fd, 3) = sd->status.account_id;
  3167. WFIFOL(inter_fd, 7) = sd->status.char_id;
  3168. WFIFOB(inter_fd, 11) = stor_id;
  3169. WFIFOB(inter_fd, 12) = mode;
  3170. WFIFOSET(inter_fd, 13);
  3171. return true;
  3172. }
  3173. /**
  3174. * Request to save inventory/cart/storage data from player
  3175. * ZI 0x308b <size>.W <type>.B <account_id>.L <char_id>.L <entries>.?B
  3176. * @param sd: Player data
  3177. * @param stor: Storage data
  3178. * @ return false - error, true - message sent
  3179. */
  3180. bool intif_storage_save(struct map_session_data *sd, struct s_storage *stor)
  3181. {
  3182. int stor_size = sizeof(struct s_storage);
  3183. nullpo_retr(false, sd);
  3184. nullpo_retr(false, stor);
  3185. if (CheckForCharServer())
  3186. return false;
  3187. WFIFOHEAD(inter_fd, stor_size+13);
  3188. WFIFOW(inter_fd, 0) = 0x308b;
  3189. WFIFOW(inter_fd, 2) = stor_size+13;
  3190. WFIFOB(inter_fd, 4) = stor->type;
  3191. WFIFOL(inter_fd, 5) = sd->status.account_id;
  3192. WFIFOL(inter_fd, 9) = sd->status.char_id;
  3193. memcpy(WFIFOP(inter_fd, 13), stor, stor_size);
  3194. WFIFOSET(inter_fd, stor_size+13);
  3195. return true;
  3196. }
  3197. int intif_clan_requestclans(){
  3198. if (CheckForCharServer())
  3199. return 0;
  3200. WFIFOHEAD(inter_fd, 2);
  3201. WFIFOW(inter_fd, 0) = 0x30A0;
  3202. WFIFOSET(inter_fd, 2);
  3203. return 1;
  3204. }
  3205. void intif_parse_clans( int fd ){
  3206. clan_load_clandata( ( RFIFOW(fd, 2) - 4 ) / sizeof( struct clan ), (struct clan*)RFIFOP(fd,4) );
  3207. }
  3208. int intif_clan_message(int clan_id,uint32 account_id,const char *mes,int len){
  3209. if (CheckForCharServer())
  3210. return 0;
  3211. if (other_mapserver_count < 1)
  3212. return 0; //No need to send.
  3213. WFIFOHEAD(inter_fd, len + 12);
  3214. WFIFOW(inter_fd,0)=0x30A1;
  3215. WFIFOW(inter_fd,2)=len+12;
  3216. WFIFOL(inter_fd,4)=clan_id;
  3217. WFIFOL(inter_fd,8)=account_id;
  3218. memcpy(WFIFOP(inter_fd,12),mes,len);
  3219. WFIFOSET(inter_fd,len+12);
  3220. return 1;
  3221. }
  3222. int intif_parse_clan_message( int fd ){
  3223. clan_recv_message(RFIFOL(fd,4),RFIFOL(fd,8),(char *) RFIFOP(fd,12),RFIFOW(fd,2)-12);
  3224. return 1;
  3225. }
  3226. int intif_clan_member_left( int clan_id ){
  3227. if (CheckForCharServer())
  3228. return 0;
  3229. if (other_mapserver_count < 1)
  3230. return 0; //No need to send.
  3231. WFIFOHEAD(inter_fd,6);
  3232. WFIFOW(inter_fd,0) = 0x30A2;
  3233. WFIFOL(inter_fd,2) = clan_id;
  3234. WFIFOSET(inter_fd,6);
  3235. return 1;
  3236. }
  3237. int intif_clan_member_joined( int clan_id ){
  3238. if (CheckForCharServer())
  3239. return 0;
  3240. if (other_mapserver_count < 1)
  3241. return 0; //No need to send.
  3242. WFIFOHEAD(inter_fd,6);
  3243. WFIFOW(inter_fd,0) = 0x30A3;
  3244. WFIFOL(inter_fd,2) = clan_id;
  3245. WFIFOSET(inter_fd,6);
  3246. return 1;
  3247. }
  3248. int intif_parse_clan_onlinecount( int fd ){
  3249. struct clan* clan = clan_search(RFIFOL(fd,2));
  3250. if( clan == NULL ){
  3251. return 0;
  3252. }
  3253. clan->connect_member = RFIFOW(fd,6);
  3254. clif_clan_onlinecount(clan);
  3255. return 1;
  3256. }
  3257. //-----------------------------------------------------------------
  3258. /**
  3259. * Communication from the inter server, Main entry point interface (inter<=>map)
  3260. * @param fd : inter-serv link
  3261. * @return
  3262. * 0 (unknow packet).
  3263. * 1 sucess (no error)
  3264. * 2 invalid length of packet (not enough data yet)
  3265. */
  3266. int intif_parse(int fd)
  3267. {
  3268. int packet_len, cmd;
  3269. cmd = RFIFOW(fd,0);
  3270. // Verify ID of the packet
  3271. if(cmd<0x3800 || cmd>=0x3800+ARRAYLENGTH(packet_len_table) ||
  3272. packet_len_table[cmd-0x3800]==0){
  3273. return 0;
  3274. }
  3275. // Check the length of the packet
  3276. packet_len = packet_len_table[cmd-0x3800];
  3277. if(packet_len==-1){
  3278. if(RFIFOREST(fd)<4)
  3279. return 2;
  3280. packet_len = RFIFOW(fd,2);
  3281. }
  3282. if((int)RFIFOREST(fd)<packet_len){
  3283. return 2;
  3284. }
  3285. // Processing branch
  3286. switch(cmd){
  3287. case 0x3800:
  3288. if (RFIFOL(fd,4) == 0xFF000000) //Normal announce.
  3289. clif_broadcast(NULL, RFIFOCP(fd,16), packet_len-16, BC_DEFAULT, ALL_CLIENT);
  3290. else //Color announce.
  3291. clif_broadcast2(NULL, RFIFOCP(fd,16), packet_len-16, RFIFOL(fd,4), RFIFOW(fd,8), RFIFOW(fd,10), RFIFOW(fd,12), RFIFOW(fd,14), ALL_CLIENT);
  3292. break;
  3293. case 0x3801: intif_parse_WisMessage(fd); break;
  3294. case 0x3802: intif_parse_WisEnd(fd); break;
  3295. case 0x3803: mapif_parse_WisToGM(fd); break;
  3296. case 0x3804: intif_parse_Registers(fd); break;
  3297. case 0x3806: intif_parse_ChangeNameOk(fd); break;
  3298. case 0x3807: intif_parse_MessageToFD(fd); break;
  3299. case 0x3808: intif_parse_accinfo_ack(fd); break;
  3300. case 0x3809: intif_parse_broadcast_obtain_special_item(fd); break;
  3301. case 0x3818: intif_parse_LoadGuildStorage(fd); break;
  3302. case 0x3819: intif_parse_SaveGuildStorage(fd); break;
  3303. case 0x3820: intif_parse_PartyCreated(fd); break;
  3304. case 0x3821: intif_parse_PartyInfo(fd); break;
  3305. case 0x3822: intif_parse_PartyMemberAdded(fd); break;
  3306. case 0x3823: intif_parse_PartyOptionChanged(fd); break;
  3307. case 0x3824: intif_parse_PartyMemberWithdraw(fd); break;
  3308. case 0x3825: intif_parse_PartyMove(fd); break;
  3309. case 0x3826: intif_parse_PartyBroken(fd); break;
  3310. case 0x3827: intif_parse_PartyMessage(fd); break;
  3311. case 0x3830: intif_parse_GuildCreated(fd); break;
  3312. case 0x3831: intif_parse_GuildInfo(fd); break;
  3313. case 0x3832: intif_parse_GuildMemberAdded(fd); break;
  3314. case 0x3834: intif_parse_GuildMemberWithdraw(fd); break;
  3315. case 0x3835: intif_parse_GuildMemberInfoShort(fd); break;
  3316. case 0x3836: intif_parse_GuildBroken(fd); break;
  3317. case 0x3837: intif_parse_GuildMessage(fd); break;
  3318. case 0x3839: intif_parse_GuildBasicInfoChanged(fd); break;
  3319. case 0x383a: intif_parse_GuildMemberInfoChanged(fd); break;
  3320. case 0x383b: intif_parse_GuildPosition(fd); break;
  3321. case 0x383c: intif_parse_GuildSkillUp(fd); break;
  3322. case 0x383d: intif_parse_GuildAlliance(fd); break;
  3323. case 0x383e: intif_parse_GuildNotice(fd); break;
  3324. case 0x383f: intif_parse_GuildEmblem(fd); break;
  3325. case 0x3840: intif_parse_GuildCastleDataLoad(fd); break;
  3326. case 0x3841: intif_parse_GuildEmblemVersionChanged(fd); break;
  3327. case 0x3843: intif_parse_GuildMasterChanged(fd); break;
  3328. // Mail System
  3329. case 0x3848: intif_parse_Mail_inboxreceived(fd); break;
  3330. case 0x3849: intif_parse_Mail_new(fd); break;
  3331. case 0x384a: intif_parse_Mail_getattach(fd); break;
  3332. case 0x384b: intif_parse_Mail_delete(fd); break;
  3333. case 0x384c: intif_parse_Mail_return(fd); break;
  3334. case 0x384d: intif_parse_Mail_send(fd); break;
  3335. case 0x384e: intif_parse_Mail_receiver(fd); break;
  3336. // Auction System
  3337. case 0x3850: intif_parse_Auction_results(fd); break;
  3338. case 0x3851: intif_parse_Auction_register(fd); break;
  3339. case 0x3852: intif_parse_Auction_cancel(fd); break;
  3340. case 0x3853: intif_parse_Auction_close(fd); break;
  3341. case 0x3854: intif_parse_Auction_message(fd); break;
  3342. case 0x3855: intif_parse_Auction_bid(fd); break;
  3343. //Bound items
  3344. #ifdef BOUND_ITEMS
  3345. case 0x3856: intif_parse_itembound_ack(fd); break;
  3346. case 0x3857: intif_parse_itembound_store2gstorage(fd); break;
  3347. #endif
  3348. //Quest system
  3349. case 0x3860: intif_parse_questlog(fd); break;
  3350. case 0x3861: intif_parse_questsave(fd); break;
  3351. //Achievement system
  3352. case 0x3862: intif_parse_achievements(fd); break;
  3353. case 0x3863: intif_parse_achievementsave(fd); break;
  3354. case 0x3864: intif_parse_achievementreward(fd); break;
  3355. // Mercenary System
  3356. case 0x3870: intif_parse_mercenary_received(fd); break;
  3357. case 0x3871: intif_parse_mercenary_deleted(fd); break;
  3358. case 0x3872: intif_parse_mercenary_saved(fd); break;
  3359. // Elemental System
  3360. case 0x387c: intif_parse_elemental_received(fd); break;
  3361. case 0x387d: intif_parse_elemental_deleted(fd); break;
  3362. case 0x387e: intif_parse_elemental_saved(fd); break;
  3363. // Pet System
  3364. case 0x3880: intif_parse_CreatePet(fd); break;
  3365. case 0x3881: intif_parse_RecvPetData(fd); break;
  3366. case 0x3882: intif_parse_SavePetOk(fd); break;
  3367. case 0x3883: intif_parse_DeletePetOk(fd); break;
  3368. // Storage
  3369. case 0x388a: intif_parse_StorageReceived(fd); break;
  3370. case 0x388b: intif_parse_StorageSaved(fd); break;
  3371. case 0x388c: intif_parse_StorageInfo_recv(fd); break;
  3372. // Homunculus System
  3373. case 0x3890: intif_parse_CreateHomunculus(fd); break;
  3374. case 0x3891: intif_parse_RecvHomunculusData(fd); break;
  3375. case 0x3892: intif_parse_SaveHomunculusOk(fd); break;
  3376. case 0x3893: intif_parse_DeleteHomunculusOk(fd); break;
  3377. // Clan system
  3378. case 0x38A0: intif_parse_clans(fd); break;
  3379. case 0x38A1: intif_parse_clan_message(fd); break;
  3380. case 0x38A2: intif_parse_clan_onlinecount(fd); break;
  3381. default:
  3382. ShowError("intif_parse : unknown packet %d %x\n",fd,RFIFOW(fd,0));
  3383. return 0;
  3384. }
  3385. // Skip packet
  3386. RFIFOSKIP(fd,packet_len);
  3387. return 1;
  3388. }