intif.cpp 100 KB

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