intif.c 87 KB

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