intif.c 89 KB

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