intif.c 81 KB

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