1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862 |
- // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
- // For more information, see LICENCE in the main folder
- #include "intif.hpp"
- #include <stdlib.h>
- #include "../common/malloc.hpp"
- #include "../common/mmo.hpp"
- #include "../common/nullpo.hpp"
- #include "../common/showmsg.hpp"
- #include "../common/socket.hpp"
- #include "../common/strlib.hpp"
- #include "../common/timer.hpp"
- #include "achievement.hpp"
- #include "battle.hpp"
- #include "chrif.hpp"
- #include "clan.hpp"
- #include "clif.hpp"
- #include "elemental.hpp"
- #include "guild.hpp"
- #include "homunculus.hpp"
- #include "log.hpp"
- #include "mail.hpp"
- #include "map.hpp"
- #include "mercenary.hpp"
- #include "party.hpp"
- #include "pc.hpp"
- #include "pc_groups.hpp"
- #include "pet.hpp"
- #include "quest.hpp"
- #include "status.hpp"
- #include "storage.hpp"
- /// Received packet Lengths from inter-server
- static const int packet_len_table[] = {
- -1,-1,27,-1, -1, 0,37,-1, 10+NAME_LENGTH,-1, 0, 0, 0, 0, 0, 0, //0x3800-0x380f
- 0, 0, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810
- 39,-1,15,15, 15+NAME_LENGTH,19, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3820
- 10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830
- -1,10, 0,18, 0, 0, 0, 0, -1,75,-1,11, 11,-1, 38, 0, //0x3840
- -1,-1, 7, 7, 7,11, 8,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus] itembound[Akinari]
- -1, 7,-1, 7, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin] [Inkfish] / Achievements [Aleos]
- -1, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 3, 3, 0, //0x3870 Mercenaries [Zephyrus] / Elemental [pakpil]
- 12,-1, 7, 3, 0, 0, 0, 0, 0, 0,-1, 9, -1, 0, 0, 0, //0x3880 Pet System, Storages
- -1,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3890 Homunculus [albator]
- -1,-1, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x38A0 Clans
- };
- extern int char_fd; // inter server Fd used for char_fd
- #define inter_fd char_fd // alias
- //-----------------------------------------------------------------
- // Send to inter server
- /**
- * Verify the char-serv is up and running
- * @return 0=no, 1=ok
- */
- int CheckForCharServer(void)
- {
- return ((char_fd <= 0) || session[char_fd] == NULL || session[char_fd]->wdata == NULL);
- }
- /**
- * Get sd from pc_db (map_id2db) or auth_db (in case if parsing packet from inter-server when sd not added to pc_db yet)
- * @param account_id
- * @param char_id
- * @return sd Found sd or NULL if not found
- */
- struct map_session_data *inter_search_sd(uint32 account_id, uint32 char_id)
- {
- struct map_session_data *sd = NULL;
- struct auth_node *node = chrif_auth_check(account_id, char_id, ST_LOGIN);
- if (node)
- sd = node->sd;
- else
- sd = map_id2sd(account_id);
- return sd;
- }
- /**
- * Request the char-serv to create a pet (to register it actually)
- * @param account_id
- * @param char_id
- * @param pet_class
- * @param pet_lv
- * @param pet_egg_id
- * @param pet_equip
- * @param intimate
- * @param hungry
- * @param rename_flag
- * @param incubate
- * @param pet_name
- * @return
- */
- int intif_create_pet(uint32 account_id,uint32 char_id,short pet_class,short pet_lv, t_itemid pet_egg_id, t_itemid pet_equip,short intimate,short hungry,char rename_flag,char incubate,char *pet_name)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 28 + NAME_LENGTH);
- WFIFOW(inter_fd, 0) = 0x3080;
- WFIFOL(inter_fd, 2) = account_id;
- WFIFOL(inter_fd, 6) = char_id;
- WFIFOW(inter_fd, 10) = pet_class;
- WFIFOW(inter_fd, 12) = pet_lv;
- WFIFOL(inter_fd, 14) = pet_egg_id;
- WFIFOL(inter_fd, 18) = pet_equip;
- WFIFOW(inter_fd, 22) = intimate;
- WFIFOW(inter_fd, 24) = hungry;
- WFIFOB(inter_fd, 26) = rename_flag;
- WFIFOB(inter_fd, 27) = incubate;
- memcpy(WFIFOP(inter_fd, 28), pet_name, NAME_LENGTH);
- WFIFOSET(inter_fd, 28 + NAME_LENGTH);
- return 1;
- }
- /**
- * Request char-serv to load a pet from persistence (SQL)
- * @param account_id
- * @param char_id
- * @param pet_id
- * @return
- */
- int intif_request_petdata(uint32 account_id,uint32 char_id,int pet_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 14);
- WFIFOW(inter_fd,0) = 0x3081;
- WFIFOL(inter_fd,2) = account_id;
- WFIFOL(inter_fd,6) = char_id;
- WFIFOL(inter_fd,10) = pet_id;
- WFIFOSET(inter_fd,14);
- return 1;
- }
- /**
- * Request char-serv to save a pet in persistence (SQL)
- * @param account_id
- * @param p
- * @return
- */
- int intif_save_petdata(uint32 account_id,struct s_pet *p)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, sizeof(struct s_pet) + 8);
- WFIFOW(inter_fd,0) = 0x3082;
- WFIFOW(inter_fd,2) = sizeof(struct s_pet) + 8;
- WFIFOL(inter_fd,4) = account_id;
- memcpy(WFIFOP(inter_fd,8),p,sizeof(struct s_pet));
- WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
- return 1;
- }
- /**
- * Request char-serv to delete the entry for this pet-char association
- * @param pet_id
- * @return
- */
- int intif_delete_petdata(int pet_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x3083;
- WFIFOL(inter_fd,2) = pet_id;
- WFIFOSET(inter_fd,6);
- return 1;
- }
- /**
- * Ask char-serv to rename a CHAR (PC|PET|HOM)
- * @param sd
- * @param type
- * @param name
- * @return
- */
- int intif_rename(struct map_session_data *sd, int type, char *name)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,NAME_LENGTH+12);
- WFIFOW(inter_fd,0) = 0x3006;
- WFIFOL(inter_fd,2) = sd->status.account_id;
- WFIFOL(inter_fd,6) = sd->status.char_id;
- WFIFOB(inter_fd,10) = type; //Type: 0 - PC, 1 - PET, 2 - HOM
- memcpy(WFIFOP(inter_fd,11),name, NAME_LENGTH);
- WFIFOSET(inter_fd,NAME_LENGTH+12);
- return 1;
- }
- /**
- * Request to broadcast a message via char-serv to reach all map-serv connected
- * @param mes : Message to send
- * @param len ; Size of the message
- * @param type : Color of msg
- * @return 0=error occured, 1=msg sent
- */
- int intif_broadcast(const char* mes, int len, int type)
- {
- nullpo_ret(mes);
- if (len < 2)
- return 0;
- int lp = (type|BC_COLOR_MASK) ? 4 : 0;
- // Send to the local players
- clif_broadcast(NULL, mes, len, type, ALL_CLIENT);
- if (CheckForCharServer())
- return 0;
- if (other_mapserver_count < 1)
- return 0; //No need to send.
- WFIFOHEAD(inter_fd, 16 + lp + len);
- WFIFOW(inter_fd,0) = 0x3000;
- WFIFOW(inter_fd,2) = 16 + lp + len;
- WFIFOL(inter_fd,4) = 0xFF000000; // 0xFF000000 color signals standard broadcast
- WFIFOW(inter_fd,8) = 0; // fontType not used with standard broadcast
- WFIFOW(inter_fd,10) = 0; // fontSize not used with standard broadcast
- WFIFOW(inter_fd,12) = 0; // fontAlign not used with standard broadcast
- WFIFOW(inter_fd,14) = 0; // fontY not used with standard broadcast
- if (type|BC_BLUE)
- 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.
- else if (type|BC_WOE)
- WFIFOL(inter_fd,16) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
- memcpy(WFIFOP(inter_fd,16 + lp), mes, len);
- WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
- return 1;
- }
- /**
- * Request to char-serv to broadcast a message to all map-serv
- * @param mes : Message to brodcast
- * @param len : Size of message
- * @param fontColor : color to display message
- * @param fontType :
- * @param fontSize :
- * @param fontAlign :
- * @param fontY :
- * @return 0=not send to char-serv, 1=send to char-serv
- */
- int intif_broadcast2(const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY)
- {
- nullpo_ret(mes);
- if (len < 2)
- return 0;
- // Send to the local players
- clif_broadcast2(NULL, mes, len, fontColor, fontType, fontSize, fontAlign, fontY, ALL_CLIENT);
- if (CheckForCharServer())
- return 0;
- if (other_mapserver_count < 1)
- return 0; //No need to send.
- WFIFOHEAD(inter_fd, 16 + len);
- WFIFOW(inter_fd,0) = 0x3000;
- WFIFOW(inter_fd,2) = 16 + len;
- WFIFOL(inter_fd,4) = fontColor;
- WFIFOW(inter_fd,8) = fontType;
- WFIFOW(inter_fd,10) = fontSize;
- WFIFOW(inter_fd,12) = fontAlign;
- WFIFOW(inter_fd,14) = fontY;
- memcpy(WFIFOP(inter_fd,16), mes, len);
- WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
- return 1;
- }
- /**
- * send a message using the main chat system
- * @param sd : Player source of message
- * @param message : the message to sent
- * @return
- */
- int intif_main_message(struct map_session_data* sd, const char* message)
- {
- char output[256];
- nullpo_ret(sd);
- // format the message for main broadcasting
- snprintf( output, sizeof(output), msg_txt(sd,386), sd->status.name, message );
- // send the message using the inter-server broadcast service
- intif_broadcast2( output, strlen(output) + 1, 0xFE000000, 0, 0, 0, 0 );
- // log the chat message
- 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 );
- return 1;
- }
- /**
- * Request char-serv to transmit a whisper message. (Private message from one player to another)
- * (player not found on this server)
- * @param sd : Player ending message
- * @param nick : Name of receiver
- * @param mes : Message to send
- * @param mes_len : Size of message
- * @return 0=Message not send, 1=Message send
- */
- int intif_wis_message(struct map_session_data *sd, char *nick, char *mes, int mes_len)
- {
- int headersize = 8 + 2 * NAME_LENGTH;
- nullpo_ret(sd);
- if (CheckForCharServer())
- return 0;
- if (other_mapserver_count < 1)
- { //Character not found.
- clif_wis_end(sd->fd, 1);
- return 0;
- }
- WFIFOHEAD(inter_fd,mes_len + headersize);
- WFIFOW(inter_fd,0) = 0x3001;
- WFIFOW(inter_fd,2) = mes_len + headersize;
- WFIFOL(inter_fd,4) = pc_get_group_level(sd);
- safestrncpy(WFIFOCP(inter_fd,8), sd->status.name, NAME_LENGTH);
- safestrncpy(WFIFOCP(inter_fd,8+NAME_LENGTH), nick, NAME_LENGTH);
- safestrncpy(WFIFOCP(inter_fd,8+2*NAME_LENGTH), mes, mes_len);
- WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
- if (battle_config.etc_log)
- ShowInfo("intif_wis_message from %s to %s (message: '%s')\n", sd->status.name, nick, mes);
- return 1;
- }
- /**
- * Inform the char-serv of the result of the whisper
- * @param id : Character ID
- * @param flag : 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
- * @return 0=no char-serv connected, 1=msg sent
- */
- int intif_wis_reply(int id, int flag)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,7);
- WFIFOW(inter_fd,0) = 0x3002;
- WFIFOL(inter_fd,2) = id;
- WFIFOB(inter_fd,6) = flag; // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
- WFIFOSET(inter_fd,7);
- if (battle_config.etc_log)
- ShowInfo("intif_wis_reply: id: %d, flag:%d\n", id, flag);
- return 1;
- }
- /**
- * Whisper message from player to all GM from map-server to inter-server (@request)
- * @param wisp_name
- * @param permission
- * @param mes
- * @return 0:no char-serv connected, 1:transfered
- */
- int intif_wis_message_to_gm(char *wisp_name, int permission, char *mes)
- {
- int mes_len;
- if (CheckForCharServer())
- return 0;
- mes_len = strlen(mes) + 1; // + null
- WFIFOHEAD(inter_fd, mes_len + 8 + NAME_LENGTH);
- WFIFOW(inter_fd,0) = 0x3003;
- WFIFOW(inter_fd,2) = mes_len + 32;
- safestrncpy(WFIFOCP(inter_fd,4), wisp_name, NAME_LENGTH);
- WFIFOL(inter_fd,4+NAME_LENGTH) = permission;
- safestrncpy(WFIFOCP(inter_fd,8+NAME_LENGTH), mes, mes_len);
- WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
- if (battle_config.etc_log)
- ShowNotice("intif_wis_message_to_gm: from: '%s', required permission: %d, message: '%s'.\n", wisp_name, permission, mes);
- return 1;
- }
- /**
- * Request for saving registry values.
- * @param sd : Player to save registry
- * @return 1=msg sent, -1=error
- */
- int intif_saveregistry(struct map_session_data *sd)
- {
- DBIterator *iter;
- DBKey key;
- DBData *data;
- int plen = 0;
- size_t len;
- if (CheckForCharServer() || !sd->regs.vars)
- return -1;
- WFIFOHEAD(inter_fd, 60000 + 300);
- WFIFOW(inter_fd,0) = 0x3004;
- // 0x2 = length (set later)
- WFIFOL(inter_fd,4) = sd->status.account_id;
- WFIFOL(inter_fd,8) = sd->status.char_id;
- WFIFOW(inter_fd,12) = 0; // count
- plen = 14;
- iter = db_iterator(sd->regs.vars);
- for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) {
- const char *varname = NULL;
- struct script_reg_state *src = NULL;
- bool lValid = false;
- if( data->type != DB_DATA_PTR ) // it's a @number
- continue;
- varname = get_str(script_getvarid(key.i64));
- if( varname[0] == '@' ) // @string$ can get here, so we skip
- continue;
- src = (struct script_reg_state *)db_data2ptr(data);
- if( !src->update )
- continue;
- src->update = false;
- lValid = script_check_RegistryVariableLength(0,varname,&len);
- ++len;
- if (!lValid) { //this is sql colum size, must be retrive from config
- ShowError("intif_saveregistry: Variable name length is too long (aid: %d, cid: %d): '%s' sz=%" PRIuPTR "\n", sd->status.account_id, sd->status.char_id, varname, len);
- continue;
- }
- WFIFOB(inter_fd, plen) = (unsigned char)len; // won't be higher; the column size is 32
- plen += 1;
- safestrncpy(WFIFOCP(inter_fd,plen), varname, len); //the key
- plen += len;
- WFIFOL(inter_fd, plen) = script_getvaridx(key.i64);
- plen += 4;
- if( src->type ) {
- struct script_reg_str *p = (struct script_reg_str *)src;
- WFIFOB(inter_fd, plen) = p->value ? 2 : 3; //var type
- plen += 1;
- if( p->value ) {
- lValid = script_check_RegistryVariableLength(1,p->value,&len);
- ++len;
- if ( !lValid ) { // error can't be higher; the column size is 254. (nb the transmission limit with be fixed with protobuf revamp)
- ShowDebug( "intif_saveregistry: Variable value length is too long (aid: %d, cid: %d): '%s' sz=%" PRIuPTR " to be saved with current system and will be truncated\n",sd->status.account_id, sd->status.char_id,p->value,len);
- len = 254;
- p->value[len - 1] = '\0'; //this is backward for old char-serv but new one doesn't need this
- }
- WFIFOB(inter_fd, plen) = (uint8)len;
- plen += 1;
- safestrncpy(WFIFOCP(inter_fd,plen), p->value, len);
- plen += len;
- } else {
- script_reg_destroy_single(sd,key.i64,&p->flag);
- }
- } else {
- struct script_reg_num *p = (struct script_reg_num *)src;
- WFIFOB(inter_fd, plen) = p->value ? 0 : 1;
- plen += 1;
- if( p->value ) {
- WFIFOQ(inter_fd, plen) = p->value;
- plen += 8;
- } else {
- script_reg_destroy_single(sd,key.i64,&p->flag);
- }
- }
- WFIFOW(inter_fd,12) += 1;
- if( plen > 60000 ) {
- WFIFOW(inter_fd, 2) = plen;
- WFIFOSET(inter_fd, plen);
- // prepare follow up
- WFIFOHEAD(inter_fd, 60000 + 300);
- WFIFOW(inter_fd,0) = 0x3004;
- // 0x2 = length (set later)
- WFIFOL(inter_fd,4) = sd->status.account_id;
- WFIFOL(inter_fd,8) = sd->status.char_id;
- WFIFOW(inter_fd,12) = 0; // count
- plen = 14;
- }
- }
- dbi_destroy(iter);
- WFIFOW(inter_fd, 2) = plen;
- WFIFOSET(inter_fd, plen);
- sd->vars_dirty = false;
- return 0;
- }
- /**
- * Request the registries for this player.
- * @param sd : Player to load registry
- * @param flag : Type of registry to load, &1=acc (login-serv), &2=acc (char-serv), &4=char
- * @return
- */
- int intif_request_registry(struct map_session_data *sd, int flag)
- {
- nullpo_ret(sd);
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,13);
- WFIFOW(inter_fd,0) = 0x3005;
- WFIFOL(inter_fd,2) = sd->status.account_id;
- WFIFOL(inter_fd,6) = sd->status.char_id;
- WFIFOB(inter_fd,10) = (flag&1?1:0); //Request Acc Reg 2 (from login-serv))
- WFIFOB(inter_fd,11) = (flag&2?1:0); //Request Acc Reg (from char-serv)
- WFIFOB(inter_fd,12) = (flag&4?1:0); //Request Char Reg
- WFIFOSET(inter_fd,13);
- return 1;
- }
- /**
- * Request to load guild storage from char-serv
- * @param account_id: Player account identification
- * @param guild_id: Guild of player
- * @return false - error, true - message sent
- */
- bool intif_request_guild_storage(uint32 account_id, int guild_id)
- {
- if (CheckForCharServer())
- return false;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x3018;
- WFIFOL(inter_fd,2) = account_id;
- WFIFOL(inter_fd,6) = guild_id;
- WFIFOSET(inter_fd,10);
- return true;
- }
- /**
- * Request to save guild storage
- * @param account_id: account requesting the save
- * @param gstor: Guild storage struct to save
- * @return false - error, true - message sent
- */
- bool intif_send_guild_storage(uint32 account_id, struct s_storage *gstor)
- {
- if (CheckForCharServer())
- return false;
- WFIFOHEAD(inter_fd,sizeof(struct s_storage)+12);
- WFIFOW(inter_fd,0) = 0x3019;
- WFIFOW(inter_fd,2) = (unsigned short)sizeof(struct s_storage)+12;
- WFIFOL(inter_fd,4) = account_id;
- WFIFOL(inter_fd,8) = gstor->id;
- memcpy( WFIFOP(inter_fd,12),gstor, sizeof(struct s_storage) );
- WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
- return true;
- }
- /**
- * Party creation request
- * @param member : Struct of 1 party member
- * @param name : Party name
- * @param item : item pickup rule
- * @param item2 : item share rule
- * @return 0=error, 1=msg sent
- */
- int intif_create_party(struct party_member *member,char *name,int item,int item2)
- {
- if (CheckForCharServer())
- return 0;
- nullpo_ret(member);
- WFIFOHEAD(inter_fd, 6+NAME_LENGTH+sizeof(struct party_member));
- WFIFOW(inter_fd,0) = 0x3020;
- WFIFOW(inter_fd,2) = 6+NAME_LENGTH+sizeof(struct party_member);
- memcpy(WFIFOP(inter_fd,4),name, NAME_LENGTH);
- WFIFOB(inter_fd,28)= item;
- WFIFOB(inter_fd,29)= item2;
- memcpy(WFIFOP(inter_fd,30), member, sizeof(struct party_member));
- WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
- return 1;
- }
- /**
- * Party information request
- * @param party_id : Party id to request info
- * @param char_id : Player id requesting
- * @return 0=error, 1=msg sent
- */
- int intif_request_partyinfo(int party_id, uint32 char_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x3021;
- WFIFOL(inter_fd,2) = party_id;
- WFIFOL(inter_fd,6) = char_id;
- WFIFOSET(inter_fd,10);
- return 1;
- }
- /**
- * Request to add a member to party
- * @param party_id : Party to add member to
- * @param member : member to add to party
- * @return
- */
- int intif_party_addmember(int party_id,struct party_member *member)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,8+sizeof(struct party_member));
- WFIFOW(inter_fd,0)=0x3022;
- WFIFOW(inter_fd,2)=8+sizeof(struct party_member);
- WFIFOL(inter_fd,4)=party_id;
- memcpy(WFIFOP(inter_fd,8),member,sizeof(struct party_member));
- WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
- return 1;
- }
- /**
- * Request to change party configuration (exp,item share)
- * @param party_id : Party to alter
- * @param account_id : account requesting change
- * @param exp : sharing exp option
- * @param item : sharing item option
- * @return 0=error, 1=msg sent
- */
- int intif_party_changeoption(int party_id,uint32 account_id,int exp,int item)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,14);
- WFIFOW(inter_fd,0)=0x3023;
- WFIFOL(inter_fd,2)=party_id;
- WFIFOL(inter_fd,6)=account_id;
- WFIFOW(inter_fd,10)=exp;
- WFIFOW(inter_fd,12)=item;
- WFIFOSET(inter_fd,14);
- return 1;
- }
- /**
- * Ask the char-serv to make aid,cid quit party
- * @param party_id : Party to leave
- * @param account_id : aid of player to leave
- * @param char_id : cid of player to leave
- * @return 0:char-serv disconected, 1=msg sent
- */
- int intif_party_leave(int party_id, uint32 account_id, uint32 char_id, const char *name, enum e_party_member_withdraw type)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,15+NAME_LENGTH);
- WFIFOW(inter_fd,0) = 0x3024;
- WFIFOL(inter_fd,2) = party_id;
- WFIFOL(inter_fd,6) = account_id;
- WFIFOL(inter_fd,10) = char_id;
- memcpy(WFIFOCP(inter_fd,14), name, NAME_LENGTH);
- WFIFOB(inter_fd,14+NAME_LENGTH) = type;
- WFIFOSET(inter_fd,15+NAME_LENGTH);
- return 1;
- }
- /**
- * Inform char-serv that a member as quit/lvlup change map, therefore changing party state
- * @param sd : Player that moved
- * @param online : If the player will stay online or no
- * @return 0=error, 1=msg sent
- */
- int intif_party_changemap(struct map_session_data *sd,int online)
- {
- int16 m, mapindex;
- if (CheckForCharServer())
- return 0;
- if(!sd)
- return 0;
- if ((m = map_mapindex2mapid(sd->mapindex)) >= 0) {
- struct map_data *mapdata = map_getmapdata(m);
- if (mapdata->instance_id)
- mapindex = map_getmapdata(mapdata->instance_src_map)->index;
- else
- mapindex = sd->mapindex;
- } else
- mapindex = sd->mapindex;
- WFIFOHEAD(inter_fd,19);
- WFIFOW(inter_fd,0)=0x3025;
- WFIFOL(inter_fd,2)=sd->status.party_id;
- WFIFOL(inter_fd,6)=sd->status.account_id;
- WFIFOL(inter_fd,10)=sd->status.char_id;
- WFIFOW(inter_fd,14)=mapindex;
- WFIFOB(inter_fd,16)=online;
- WFIFOW(inter_fd,17)=sd->status.base_level;
- WFIFOSET(inter_fd,19);
- return 1;
- }
- /**
- * Request breaking party
- * @param party_id : Party to delete
- * @return 0=error, 1=msg sent
- */
- int intif_break_party(int party_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0)=0x3026;
- WFIFOL(inter_fd,2)=party_id;
- WFIFOSET(inter_fd,6);
- return 0;
- }
- //
- /**
- * Request sending party chat
- * (we using this in case we have multiple map-serv attached
- * to be sure all party get the message)
- * @param party_id : Party identification
- * @param account_id : Player sending the message
- * @param mes : Message to send
- * @param len : Size of the message
- * @return 0=error, 1=msg sent
- */
- int intif_party_message(int party_id,uint32 account_id,const char *mes,int len)
- {
- if (CheckForCharServer())
- return 0;
- if (other_mapserver_count < 1)
- return 0; //No need to send.
- WFIFOHEAD(inter_fd,len + 12);
- WFIFOW(inter_fd,0)=0x3027;
- WFIFOW(inter_fd,2)=len+12;
- WFIFOL(inter_fd,4)=party_id;
- WFIFOL(inter_fd,8)=account_id;
- memcpy(WFIFOP(inter_fd,12),mes,len);
- WFIFOSET(inter_fd,len+12);
- return 1;
- }
- /**
- * Request a new leader for party
- * @param party_id : Party to alter
- * @param account_id : player to set as new leader
- * @param char_id : player to set as new leader
- * @return 0=error, 1=msg sent
- */
- int intif_party_leaderchange(int party_id,uint32 account_id,uint32 char_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,14);
- WFIFOW(inter_fd,0)=0x3029;
- WFIFOL(inter_fd,2)=party_id;
- WFIFOL(inter_fd,6)=account_id;
- WFIFOL(inter_fd,10)=char_id;
- WFIFOSET(inter_fd,14);
- return 1;
- }
- /**
- * Request to update party share level
- * @param share_lvl : Max level number of difference to share exp
- * @return 0=error, 1=msg sent
- */
- int intif_party_sharelvlupdate(unsigned int share_lvl)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0)=0x302A;
- WFIFOL(inter_fd,2)=share_lvl;
- WFIFOSET(inter_fd,6);
- return 1;
- }
- /**
- * Request a Guild creation
- * @param name : Name of the guild
- * @param master : Guild_member info of master
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_create(const char *name,const struct guild_member *master)
- {
- if (CheckForCharServer())
- return 0;
- nullpo_ret(master);
- WFIFOHEAD(inter_fd,sizeof(struct guild_member)+(8+NAME_LENGTH));
- WFIFOW(inter_fd,0)=0x3030;
- WFIFOW(inter_fd,2)=sizeof(struct guild_member)+(8+NAME_LENGTH);
- WFIFOL(inter_fd,4)=master->account_id;
- memcpy(WFIFOP(inter_fd,8),name,NAME_LENGTH);
- memcpy(WFIFOP(inter_fd,8+NAME_LENGTH),master,sizeof(struct guild_member));
- WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
- return 1;
- }
- /**
- * Request Guild information
- * @param guild_id : guild to get info from
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_request_info(int guild_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x3031;
- WFIFOL(inter_fd,2) = guild_id;
- WFIFOSET(inter_fd,6);
- return 1;
- }
- /**
- * Request to add member to the guild
- * @param guild_id : Guild to alter
- * @param m : Member to add to the guild
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_addmember(int guild_id,struct guild_member *m)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,sizeof(struct guild_member)+8);
- WFIFOW(inter_fd,0) = 0x3032;
- WFIFOW(inter_fd,2) = sizeof(struct guild_member)+8;
- WFIFOL(inter_fd,4) = guild_id;
- memcpy(WFIFOP(inter_fd,8),m,sizeof(struct guild_member));
- WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
- return 1;
- }
- /**
- * Request a new leader for guild
- * @param guild_id : guild to alter
- * @param name : name of the new master
- * @param len : size of the name
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_change_gm(int guild_id, const char* name, int len)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, len + 8);
- WFIFOW(inter_fd, 0)=0x3033;
- WFIFOW(inter_fd, 2)=len+8;
- WFIFOL(inter_fd, 4)=guild_id;
- memcpy(WFIFOP(inter_fd,8),name,len);
- WFIFOSET(inter_fd,len+8);
- return 1;
- }
- /**
- * Request to make a player leave a guild
- * @param guild_id : guild to alter
- * @param account_id : player aid to kick
- * @param char_id : player cid to kick
- * @param flag : 0:normal quit, 1=expulsion
- * @param mes : quitting message (max 40)
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_leave(int guild_id,uint32 account_id,uint32 char_id,int flag,const char *mes)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 55);
- WFIFOW(inter_fd, 0) = 0x3034;
- WFIFOL(inter_fd, 2) = guild_id;
- WFIFOL(inter_fd, 6) = account_id;
- WFIFOL(inter_fd,10) = char_id;
- WFIFOB(inter_fd,14) = flag;
- safestrncpy(WFIFOCP(inter_fd,15),mes,40);
- WFIFOSET(inter_fd,55);
- return 1;
- }
- /**
- * Update request / Lv online status of the guild members
- * @param guild_id : guild to alter
- * @param account_id : player aid to alter
- * @param char_id : player cid to alter
- * @param online : does the player is online (or will stay online)
- * @param lv : player lv
- * @param class_ : player class
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_memberinfoshort(int guild_id,uint32 account_id,uint32 char_id,int online,int lv,int class_)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 19);
- WFIFOW(inter_fd, 0) = 0x3035;
- WFIFOL(inter_fd, 2) = guild_id;
- WFIFOL(inter_fd, 6) = account_id;
- WFIFOL(inter_fd,10) = char_id;
- WFIFOB(inter_fd,14) = online;
- WFIFOW(inter_fd,15) = lv;
- WFIFOW(inter_fd,17) = class_;
- WFIFOSET(inter_fd,19);
- return 1;
- }
- /**
- * Guild disbanded notification
- * @param guild_id : guild to disband
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_break(int guild_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 6);
- WFIFOW(inter_fd, 0) = 0x3036;
- WFIFOL(inter_fd, 2) = guild_id;
- WFIFOSET(inter_fd,6);
- return 1;
- }
- /**
- * Send a guild message
- * (This is goign throught char-serv in case of multi-map setup)
- * @param guild_id : Guild id to send the message to
- * @param account_id : Player sending the msg
- * @param mes : Message to send
- * @param len : Size of the message
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_message(int guild_id,uint32 account_id,const char *mes,int len)
- {
- if (CheckForCharServer())
- return 0;
- if (other_mapserver_count < 1)
- return 0; //No need to send.
- WFIFOHEAD(inter_fd, len + 12);
- WFIFOW(inter_fd,0)=0x3037;
- WFIFOW(inter_fd,2)=len+12;
- WFIFOL(inter_fd,4)=guild_id;
- WFIFOL(inter_fd,8)=account_id;
- memcpy(WFIFOP(inter_fd,12),mes,len);
- WFIFOSET(inter_fd,len+12);
- return 1;
- }
- /**
- * Request a change of Guild basic information
- * @param guild_id : Guild to alter
- * @param type : type of data to change (currently only guildlv)
- * @param data : new value for type
- * @param len : size of data
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_change_basicinfo(int guild_id,int type,const void *data,int len)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, len + 10);
- WFIFOW(inter_fd,0)=0x3039;
- WFIFOW(inter_fd,2)=len+10;
- WFIFOL(inter_fd,4)=guild_id;
- WFIFOW(inter_fd,8)=type;
- memcpy(WFIFOP(inter_fd,10),data,len);
- WFIFOSET(inter_fd,len+10);
- return 1;
- }
- /**
- * Request a change of Guild member information
- * @param guild_id : Guild to alter
- * @param account_id : Player aid to alter
- * @param char_id : Player cid to alter
- * @param type : Type of modification
- * @param data : Value of modification
- * @param len : Size of value
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_change_memberinfo(int guild_id,uint32 account_id,uint32 char_id,
- int type,const void *data,int len)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, len + 18);
- WFIFOW(inter_fd, 0)=0x303a;
- WFIFOW(inter_fd, 2)=len+18;
- WFIFOL(inter_fd, 4)=guild_id;
- WFIFOL(inter_fd, 8)=account_id;
- WFIFOL(inter_fd,12)=char_id;
- WFIFOW(inter_fd,16)=type;
- memcpy(WFIFOP(inter_fd,18),data,len);
- WFIFOSET(inter_fd,len+18);
- return 1;
- }
- /**
- * Request a change of Guild title
- * @param guild_id : guild to alter
- * @param idx : Position Index
- * @param p : Position data { <mode>.L <ranking>.L <pay rate>.L <name>.24B }
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_position(int guild_id,int idx,struct guild_position *p)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, sizeof(struct guild_position)+12);
- WFIFOW(inter_fd,0)=0x303b;
- WFIFOW(inter_fd,2)=sizeof(struct guild_position)+12;
- WFIFOL(inter_fd,4)=guild_id;
- WFIFOL(inter_fd,8)=idx;
- memcpy(WFIFOP(inter_fd,12),p,sizeof(struct guild_position));
- WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
- return 1;
- }
- /**
- * Request an update of Guildskill skill_id
- * @param guild_id : Guild to alter
- * @param skill_id : Skill to lvl up
- * @param account_id : aid requesting update
- * @param max : skill max level
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_skillup(int guild_id, uint16 skill_id, uint32 account_id, int max)
- {
- if( CheckForCharServer() )
- return 0;
- WFIFOHEAD(inter_fd, 18);
- WFIFOW(inter_fd, 0) = 0x303c;
- WFIFOL(inter_fd, 2) = guild_id;
- WFIFOL(inter_fd, 6) = skill_id;
- WFIFOL(inter_fd, 10) = account_id;
- WFIFOL(inter_fd, 14) = max;
- WFIFOSET(inter_fd, 18);
- return 1;
- }
- /**
- * Request a new guild relationship
- * @param guild_id1 : Guild to associate 1
- * @param guild_id2 : Guild to associate 2
- * @param account_id1 : aid of player in guild1
- * @param account_id2 : aid of player in guild2
- * @param flag : (GUILD_ALLIANCE_REMOVE|0|1)
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_alliance(int guild_id1,int guild_id2,uint32 account_id1,uint32 account_id2,int flag)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,19);
- WFIFOW(inter_fd, 0)=0x303d;
- WFIFOL(inter_fd, 2)=guild_id1;
- WFIFOL(inter_fd, 6)=guild_id2;
- WFIFOL(inter_fd,10)=account_id1;
- WFIFOL(inter_fd,14)=account_id2;
- WFIFOB(inter_fd,18)=flag;
- WFIFOSET(inter_fd,19);
- return 1;
- }
- /**
- * Request to change guild notice
- * @param guild_id : Guild to alter
- * @param mes1 : Notice title (max 60)
- * @param mes2 : Notice body (max 120)
- * @return 0=error, 1=msg_sent
- */
- int intif_guild_notice(int guild_id,const char *mes1,const char *mes2)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,186);
- WFIFOW(inter_fd,0)=0x303e;
- WFIFOL(inter_fd,2)=guild_id;
- memcpy(WFIFOP(inter_fd,6),mes1,MAX_GUILDMES1);
- memcpy(WFIFOP(inter_fd,66),mes2,MAX_GUILDMES2);
- WFIFOSET(inter_fd,186);
- return 1;
- }
- /**
- * Request to change guild emblem
- * @param guild_id
- * @param len
- * @param data
- * @return
- */
- int intif_guild_emblem(int guild_id,int len,const char *data)
- {
- if (CheckForCharServer())
- return 0;
- if(guild_id<=0 || len<0 || len>2000)
- return 0;
- WFIFOHEAD(inter_fd,len + 12);
- WFIFOW(inter_fd,0)=0x303f;
- WFIFOW(inter_fd,2)=len+12;
- WFIFOL(inter_fd,4)=guild_id;
- WFIFOL(inter_fd,8)=0;
- memcpy(WFIFOP(inter_fd,12),data,len);
- WFIFOSET(inter_fd,len+12);
- return 1;
- }
- int intif_guild_emblem_version(int guild_id, int emblem_id)
- {
- if (CheckForCharServer())
- return 0;
- if (guild_id <= 0)
- return 0;
- WFIFOHEAD(inter_fd, 10);
- WFIFOW(inter_fd, 0) = 0x3042;
- WFIFOL(inter_fd, 2) = guild_id;
- WFIFOL(inter_fd, 6) = emblem_id;
- WFIFOSET(inter_fd, 10);
- return 1;
- }
- /**
- * Requests guild castles data from char-server.
- * @param num Number of castles, size of castle_ids array.
- * @param castle_ids Pointer to array of castle IDs.
- */
- int intif_guild_castle_dataload(int num, int *castle_ids)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 4 + num * sizeof(int));
- WFIFOW(inter_fd, 0) = 0x3040;
- WFIFOW(inter_fd, 2) = 4 + num * sizeof(int);
- memcpy(WFIFOP(inter_fd, 4), castle_ids, num * sizeof(int));
- WFIFOSET(inter_fd, WFIFOW(inter_fd, 2));
- return 1;
- }
- /**
- * Request change castle guild owner and save data
- * @param castle_id
- * @param index
- * @param value
- * @return
- */
- int intif_guild_castle_datasave(int castle_id,int index, int value)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,9);
- WFIFOW(inter_fd,0)=0x3041;
- WFIFOW(inter_fd,2)=castle_id;
- WFIFOB(inter_fd,4)=index;
- WFIFOL(inter_fd,5)=value;
- WFIFOSET(inter_fd,9);
- return 1;
- }
- //-----------------------------------------------------------------
- // Homunculus Packets send to Inter server [albator]
- //-----------------------------------------------------------------
- /**
- * Request to create/register homonculus
- * @param account_id : player requesting
- * @param sh : TMp homunlus data
- * @return 0=error, 1=msg_sent
- */
- int intif_homunculus_create(uint32 account_id, struct s_homunculus *sh)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
- WFIFOW(inter_fd,0) = 0x3090;
- WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
- WFIFOL(inter_fd,4) = account_id;
- memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
- WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
- return 1;
- }
- /**
- * Request to load homunculus from char-serv
- * @param account_id
- * @param homun_id
- * @return 0=error, 1=msg sent
- */
- int intif_homunculus_requestload(uint32 account_id, int homun_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 10);
- WFIFOW(inter_fd,0) = 0x3091;
- WFIFOL(inter_fd,2) = account_id;
- WFIFOL(inter_fd,6) = homun_id;
- WFIFOSET(inter_fd, 10);
- return 1;
- }
- /**
- * Request to save homunculus
- * @param account_id : Player asking save
- * @param sh : homunculus struct
- * @return : 0=error, 1=msg sent
- */
- int intif_homunculus_requestsave(uint32 account_id, struct s_homunculus* sh)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
- WFIFOW(inter_fd,0) = 0x3092;
- WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
- WFIFOL(inter_fd,4) = account_id;
- memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
- WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
- return 1;
- }
- /**
- * request to delete homunculus
- * @param homun_id
- * @return 0=error, 1=msg sent
- */
- int intif_homunculus_requestdelete(int homun_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 6);
- WFIFOW(inter_fd, 0) = 0x3093;
- WFIFOL(inter_fd,2) = homun_id;
- WFIFOSET(inter_fd,6);
- return 1;
- }
- //-----------------------------------------------------------------
- // Packets receive from inter server
- /**
- * Receive a whisper request from char-serv transmit it to player
- * @author : rewritten by [Yor]
- * @param fd : char-serv link
- * @return 0=not found or ignored, 1=transmited
- */
- int intif_parse_WisMessage(int fd)
- {
- struct map_session_data* sd;
- char *wisp_source;
- char name[NAME_LENGTH];
- int id, i, gmlvl;
- id=RFIFOL(fd,4);
- gmlvl=RFIFOL(fd,8);
- safestrncpy(name, RFIFOCP(fd,12+NAME_LENGTH), NAME_LENGTH);
- sd = map_nick2sd(name,false);
- if(sd == NULL || strcmp(sd->status.name, name) != 0)
- { //Not found
- intif_wis_reply(id,1);
- return 0;
- }
- if(sd->state.ignoreAll) {
- intif_wis_reply(id, (pc_has_permission(sd, PC_PERM_HIDE_SESSION))?1:2);
- return 0;
- }
- wisp_source = RFIFOCP(fd,12); // speed up [Yor]
- for(i=0; i < MAX_IGNORE_LIST &&
- sd->ignore[i].name[0] != '\0' &&
- strcmp(sd->ignore[i].name, wisp_source) != 0
- ; i++);
- if (i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0')
- { //Ignored
- intif_wis_reply(id, (pc_has_permission(sd, PC_PERM_HIDE_SESSION))?1:2);
- return 0;
- }
- //Success to send whisper.
- clif_wis_message(sd, wisp_source, RFIFOCP(fd,12+2*NAME_LENGTH),RFIFOW(fd,2)-12+2*NAME_LENGTH, gmlvl);
- intif_wis_reply(id,0); // success
- return 1;
- }
- /**
- * Wisp/page transmission result reception
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_WisEnd(int fd)
- {
- struct map_session_data* sd;
- if (battle_config.etc_log)
- 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
- sd = (struct map_session_data *)map_nick2sd(RFIFOCP(fd,2),false);
- if (sd != NULL)
- clif_wis_end(sd->fd, RFIFOB(fd,26));
- return 1;
- }
- /**
- * Transmit a whisper message to sd
- * @param sd : Player to transmit the message to
- * @param va : list of arguments ( wisp_name, message, len)
- * @return 0=error, 1=msg sent
- */
- static int mapif_parse_WisToGM_sub(struct map_session_data* sd,va_list va)
- {
- int permission = va_arg(va, int);
- char *wisp_name;
- char *message;
- int len;
- if (!pc_has_permission(sd, permission))
- return 0;
- wisp_name = va_arg(va, char*);
- message = va_arg(va, char*);
- len = va_arg(va, int);
- clif_wis_message(sd, wisp_name, message, len,0);
- return 1;
- }
- /**
- * Received wisp message from map-server via char-server for ALL gm
- * 0x3003/0x3803 <packet_len>.w <wispname>.24B <permission>.l <message>.?B
- * @see mapif_parse_WisToGM_sub, for 1 transmission
- * @param fd : char-serv link
- * @return 1
- */
- int mapif_parse_WisToGM(int fd)
- {
- int permission, mes_len;
- char Wisp_name[NAME_LENGTH];
- char *message;
- mes_len = RFIFOW(fd,2) - 8+NAME_LENGTH;
- message = (char *) aMalloc(mes_len+1);
- safestrncpy(Wisp_name, RFIFOCP(fd,4), NAME_LENGTH);
- permission = RFIFOL(fd, 4 + NAME_LENGTH);
- safestrncpy(message, RFIFOCP(fd,8+NAME_LENGTH), mes_len+1);
- // information is sent to all online GM
- map_foreachpc(mapif_parse_WisToGM_sub, permission, Wisp_name, message, mes_len);
- aFree(message);
- return 1;
- }
- /**
- * Request player registry
- * @param fd : char-serv link
- * @return 0=error, 1=sucess
- */
- void intif_parse_Registers(int fd)
- {
- int flag;
- struct map_session_data *sd;
- uint32 account_id = RFIFOL(fd,4), char_id = RFIFOL(fd,8);
- struct auth_node *node = chrif_auth_check(account_id, char_id, ST_LOGIN);
- char type = RFIFOB(fd, 13);
- if (node)
- sd = node->sd;
- else { //Normally registries should arrive for in log-in chars.
- sd = map_id2sd(account_id);
- }
- if (!sd || sd->status.char_id != char_id) {
- return; //Character registry from another character.
- }
- flag = ( sd->vars_received&PRL_ACCG && sd->vars_received&PRL_ACCL && sd->vars_received&PRL_CHAR ) ? 0 : 1;
- switch (RFIFOB(fd,12)) {
- case 3: //Character Registry
- sd->vars_received |= PRL_CHAR;
- break;
- case 2: //Account Registry
- sd->vars_received |= PRL_ACCL;
- break;
- case 1: //Account2 Registry
- sd->vars_received |= PRL_ACCG;
- break;
- case 0:
- break;
- default:
- ShowError("intif_parse_Registers: Unrecognized type %d\n",RFIFOB(fd,12));
- return;
- }
- // have it not complain about insertion of vars before loading, and not set those vars as new or modified
- pc_set_reg_load(true);
-
- if( RFIFOW(fd, 14) ) {
- char key[32];
- uint32 index;
- int max = RFIFOW(fd, 14), cursor = 16, i;
- /**
- * Vessel!char_reg_num_db
- *
- * str type
- * { keyLength(B), key(<keyLength>), index(L), valLength(B), val(<valLength>) }
- **/
- if (type) {
- for(i = 0; i < max; i++) {
- char sval[254];
- safestrncpy(key, RFIFOCP(fd, cursor + 1), RFIFOB(fd, cursor));
- cursor += RFIFOB(fd, cursor) + 1;
- index = RFIFOL(fd, cursor);
- cursor += 4;
- safestrncpy(sval, RFIFOCP(fd, cursor + 1), RFIFOB(fd, cursor));
- cursor += RFIFOB(fd, cursor) + 1;
- set_reg_str( NULL, sd, reference_uid( add_str( key ), index ), key, sval, NULL );
- }
- /**
- * Vessel!
- *
- * int type
- * { keyLength(B), key(<keyLength>), index(L), value(L) }
- **/
- } else {
- for(i = 0; i < max; i++) {
- int64 ival;
- safestrncpy(key, RFIFOCP(fd, cursor + 1), RFIFOB(fd, cursor));
- cursor += RFIFOB(fd, cursor) + 1;
- index = RFIFOL(fd, cursor);
- cursor += 4;
- ival = RFIFOQ(fd, cursor);
- cursor += 8;
- set_reg_num( NULL, sd, reference_uid( add_str( key ), index ), key, ival, NULL );
- }
- }
- }
- pc_set_reg_load(false);
- if (flag && sd->vars_received&PRL_ACCG && sd->vars_received&PRL_ACCL && sd->vars_received&PRL_CHAR)
- pc_reg_received(sd); //Received all registry values, execute init scripts and what-not. [Skotlex]
- }
- /**
- * Received a guild storage
- * @param fd : char-serv link
- * @return 0=error, 1=sucess
- */
- int intif_parse_LoadGuildStorage(int fd)
- {
- struct s_storage *gstor;
- struct map_session_data *sd;
- int guild_id, flag;
- guild_id = RFIFOL(fd,8);
- flag = RFIFOL(fd,12);
- if (guild_id <= 0)
- return 0;
- sd = map_id2sd( RFIFOL(fd,4) );
- if (flag){ //If flag != 0, we attach a player and open the storage
- if(sd == NULL){
- ShowError("intif_parse_LoadGuildStorage: user not found (AID: %d)\n",RFIFOL(fd,4));
- return 0;
- }
- }
- gstor = guild2storage(guild_id);
- if (!gstor) {
- ShowWarning("intif_parse_LoadGuildStorage: error guild_id %d not exist\n",guild_id);
- return 0;
- }
- if (gstor->status) { // Already open.. lets ignore this update
- 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);
- return 0;
- }
- if (gstor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex]
- 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);
- return 0;
- }
- if (RFIFOW(fd,2)-13 != sizeof(struct s_storage)) {
- ShowError("intif_parse_LoadGuildStorage: data size error %d %" PRIuPTR "\n",RFIFOW(fd,2)-13 , sizeof(struct s_storage));
- gstor->status = false;
- return 0;
- }
- memcpy(gstor,RFIFOP(fd,13),sizeof(struct s_storage));
- if( flag )
- storage_guild_storageopen(sd);
- return 1;
- }
- /**
- * ACK guild_storage saved
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_SaveGuildStorage(int fd)
- {
- storage_guild_storagesaved(/*RFIFOL(fd,2), */RFIFOL(fd,6));
- return 1;
- }
- /**
- * ACK party creation
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_PartyCreated(int fd)
- {
- if(battle_config.etc_log)
- ShowInfo("intif: party created by account %d\n\n", RFIFOL(fd,2));
- party_created(RFIFOL(fd,2), RFIFOL(fd,6),RFIFOB(fd,10),RFIFOL(fd,11), RFIFOCP(fd,15));
- return 1;
- }
- /**
- * Receive party info
- * @param fd : char-serv link
- * @return 0=error, 1=sucess
- */
- int intif_parse_PartyInfo(int fd)
- {
- if( RFIFOW(fd,2) == 12 ){
- ShowWarning("intif: party noinfo (char_id=%d party_id=%d)\n", RFIFOL(fd,4), RFIFOL(fd,8));
- party_recv_noinfo(RFIFOL(fd,8), RFIFOL(fd,4));
- return 0;
- }
- if( RFIFOW(fd,2) != 8+sizeof(struct party) )
- ShowError("intif: party info : data size error (char_id=%d party_id=%d packet_len=%d expected_len=%" PRIuPTR ")\n", RFIFOL(fd,4), RFIFOL(fd,8), RFIFOW(fd,2), 8+sizeof(struct party));
- party_recv_info((struct party *)RFIFOP(fd,8), RFIFOL(fd,4));
- return 1;
- }
- /**
- * ACK adding party member
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_PartyMemberAdded(int fd)
- {
- if(battle_config.etc_log)
- ShowInfo("intif: party member added Party (%d), Account(%d), Char(%d)\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
- party_member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10), RFIFOB(fd, 14));
- return 1;
- }
- /**
- * ACK changing party option
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_PartyOptionChanged(int fd)
- {
- party_optionchanged(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOW(fd,10),RFIFOW(fd,12),RFIFOB(fd,14));
- return 1;
- }
- /**
- * ACK member leaving party
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_PartyMemberWithdraw(int fd)
- {
- if(battle_config.etc_log)
- ShowInfo("intif: party member withdraw: Type(%d) Party(%d), Account(%d), Char(%d), Name(%s)\n",RFIFOB(fd,14+NAME_LENGTH),RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOCP(fd,14));
- party_member_withdraw(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOCP(fd,14),(enum e_party_member_withdraw)RFIFOB(fd,14+NAME_LENGTH));
- return 1;
- }
- /**
- * ACK party break
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_PartyBroken(int fd)
- {
- party_broken(RFIFOL(fd,2));
- return 1;
- }
- /**
- * ACK party on new map
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_PartyMove(int fd)
- {
- party_recv_movemap(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOW(fd,14),RFIFOB(fd,16),RFIFOW(fd,17));
- return 1;
- }
- /**
- * ACK party messages
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_PartyMessage(int fd)
- {
- party_recv_message(RFIFOL(fd,4),RFIFOL(fd,8),RFIFOCP(fd,12),RFIFOW(fd,2)-12);
- return 1;
- }
- /**
- * ACK guild creation
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_GuildCreated(int fd)
- {
- guild_created(RFIFOL(fd,2),RFIFOL(fd,6));
- return 1;
- }
- /**
- * ACK guild infos
- * @param fd : char-serv link
- * @return 0=error, 1=sucess
- */
- int intif_parse_GuildInfo(int fd)
- {
- if(RFIFOW(fd,2) == 8) {
- ShowWarning("intif: guild noinfo %d\n",RFIFOL(fd,4));
- guild_recv_noinfo(RFIFOL(fd,4));
- return 0;
- }
- if( RFIFOW(fd,2)!=sizeof(struct guild)+4 )
- ShowError("intif: guild info : data size error Gid: %d recv size: %d Expected size: %" PRIuPTR "\n",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild)+4);
- guild_recv_info((struct guild *)RFIFOP(fd,4));
- return 1;
- }
- /**
- * ACK adding guild member
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_GuildMemberAdded(int fd)
- {
- if(battle_config.etc_log)
- ShowInfo("intif: guild member added %d %d %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14));
- guild_member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14));
- return 1;
- }
- /**
- * ACK member leaving guild
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_GuildMemberWithdraw(int fd)
- {
- guild_member_withdraw(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOCP(fd,55),RFIFOCP(fd,15));
- return 1;
- }
- /**
- * ACK guild member basic info
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_GuildMemberInfoShort(int fd)
- {
- guild_recv_memberinfoshort(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOW(fd,15),RFIFOW(fd,17));
- return 1;
- }
- /**
- * ACK guild break
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_GuildBroken(int fd)
- {
- guild_broken(RFIFOL(fd,2),RFIFOB(fd,6));
- return 1;
- }
- /**
- * basic guild info change notice
- * 0x3839 <packet len>.w <guild id>.l <type>.w <data>.?b
- * @param fd : char-serv link
- * @return 0=error, 1=sucess
- */
- int intif_parse_GuildBasicInfoChanged(int fd)
- {
- //int len = RFIFOW(fd,2) - 10;
- int guild_id = RFIFOL(fd,4);
- int type = RFIFOW(fd,8);
- //void* data = RFIFOP(fd,10);
- struct guild* g = guild_search(guild_id);
- if( g == NULL )
- return 0;
- switch(type) {
- case GBI_EXP: g->exp = RFIFOQ(fd,10); break;
- case GBI_GUILDLV: g->guild_lv = RFIFOW(fd,10); break;
- case GBI_SKILLPOINT: g->skill_point = RFIFOL(fd,10); break;
- }
- return 1;
- }
- /**
- * guild member info change notice
- * 0x383a <packet len>.w <guild id>.l <account id>.l <char id>.l <type>.w <data>.?b
- * @param fd : char-serv link
- * @return 0=error, 1=sucess
- */
- int intif_parse_GuildMemberInfoChanged(int fd)
- {
- //int len = RFIFOW(fd,2) - 18;
- int guild_id = RFIFOL(fd,4);
- uint32 account_id = RFIFOL(fd,8);
- uint32 char_id = RFIFOL(fd,12);
- int type = RFIFOW(fd,16);
- //void* data = RFIFOP(fd,18);
- struct guild* g;
- int idx;
- g = guild_search(guild_id);
- if( g == NULL )
- return 0;
- idx = guild_getindex(g,account_id,char_id);
- if( idx == -1 )
- return 0;
- switch( type ) {
- case GMI_POSITION: g->member[idx].position = RFIFOW(fd,18); guild_memberposition_changed(g,idx,RFIFOW(fd,18)); break;
- case GMI_EXP: g->member[idx].exp = RFIFOQ(fd,18); break;
- case GMI_HAIR: g->member[idx].hair = RFIFOW(fd,18); break;
- case GMI_HAIR_COLOR: g->member[idx].hair_color = RFIFOW(fd,18); break;
- case GMI_GENDER: g->member[idx].gender = RFIFOW(fd,18); break;
- case GMI_CLASS: g->member[idx].class_ = RFIFOW(fd,18); break;
- case GMI_LEVEL: g->member[idx].lv = RFIFOW(fd,18); break;
- }
- return 1;
- }
- /**
- * ACK change of guild title
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_GuildPosition(int fd)
- {
- if( RFIFOW(fd,2)!=sizeof(struct guild_position)+12 )
- ShowError("intif: guild info : data size error %d %d %" PRIuPTR "\n",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild_position)+12);
- guild_position_changed(RFIFOL(fd,4),RFIFOL(fd,8),(struct guild_position *)RFIFOP(fd,12));
- return 1;
- }
- /**
- * ACK change of guild skill update
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_GuildSkillUp(int fd)
- {
- guild_skillupack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
- return 1;
- }
- /**
- * ACK change of guild relationship
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_GuildAlliance(int fd)
- {
- guild_allianceack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOL(fd,14),RFIFOB(fd,18),RFIFOCP(fd,19),RFIFOCP(fd,43));
- return 1;
- }
- /**
- * ACK change of guild notice
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_GuildNotice(int fd)
- {
- guild_notice_changed(RFIFOL(fd,2),RFIFOCP(fd,6),RFIFOCP(fd,66));
- return 1;
- }
- /**
- * ACK change of guild emblem
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_GuildEmblem(int fd)
- {
- guild_emblem_changed(RFIFOW(fd,2)-12,RFIFOL(fd,4),RFIFOL(fd,8), RFIFOCP(fd,12));
- return 1;
- }
- int intif_parse_GuildEmblemVersionChanged(int fd)
- {
- guild_emblem_changed(0, RFIFOL(fd, 2), RFIFOL(fd, 6), nullptr); // Doesn't need emblem length and data
- return 1;
- }
- /**
- * ACK guild message
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_GuildMessage(int fd)
- {
- guild_recv_message(RFIFOL(fd,4),RFIFOL(fd,8),RFIFOCP(fd,12),RFIFOW(fd,2)-12);
- return 1;
- }
- /**
- * Reply guild castle data request
- * @param fd : char-serv link
- * @return ?
- */
- int intif_parse_GuildCastleDataLoad(int fd)
- {
- return guild_castledataloadack(RFIFOW(fd,2), (struct guild_castle *)RFIFOP(fd,4));
- }
- /**
- * ACK change of guildmaster
- * @param fd : char-serv link
- * @return ?
- */
- int intif_parse_GuildMasterChanged(int fd)
- {
- return guild_gm_changed(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOL(fd,14));
- }
- /**
- * Request pet creation
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_CreatePet(int fd)
- {
- pet_get_egg(RFIFOL(fd,2),RFIFOW(fd,6),RFIFOL(fd,8));
- return 1;
- }
- /**
- * ACK pet data
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_RecvPetData(int fd)
- {
- struct s_pet p;
- int len;
- len=RFIFOW(fd,2);
- if(sizeof(struct s_pet)!=len-9) {
- if(battle_config.etc_log)
- ShowError("intif: pet data: data size error %" PRIuPTR " %d\n",sizeof(struct s_pet),len-9);
- }
- else{
- memcpy(&p,RFIFOP(fd,9),sizeof(struct s_pet));
- pet_recv_petdata(RFIFOL(fd,4),&p,RFIFOB(fd,8));
- }
- return 1;
- }
- /**
- * ACK pet save data
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_SavePetOk(int fd)
- {
- if(RFIFOB(fd,6) == 1)
- ShowError("pet data save failure\n");
- return 1;
- }
- /**
- * ACK deleting pet
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_DeletePetOk(int fd)
- {
- if(RFIFOB(fd,2) == 1)
- ShowError("pet data delete failure\n");
- return 1;
- }
- /**
- * ACK changing name resquest, players,pets,hommon
- * @param fd : char-serv link
- * @return 0=error, 1=sucess
- */
- int intif_parse_ChangeNameOk(int fd)
- {
- struct map_session_data *sd = NULL;
- if((sd=map_id2sd(RFIFOL(fd,2)))==NULL ||
- sd->status.char_id != RFIFOL(fd,6))
- return 0;
- switch (RFIFOB(fd,10)) {
- case 0: //Players [NOT SUPPORTED YET]
- break;
- case 1: //Pets
- pet_change_name_ack(sd, RFIFOCP(fd,12), RFIFOB(fd,11));
- break;
- case 2: //Hom
- hom_change_name_ack(sd, RFIFOCP(fd,12), RFIFOB(fd,11));
- break;
- }
- return 1;
- }
- //----------------------------------------------------------------
- // Homunculus recv packets [albator]
- /**
- * ACK Homunculus creation
- * @param fd : char-serv link
- * @return 0=error, 1=sucess
- */
- int intif_parse_CreateHomunculus(int fd)
- {
- int len;
- len=RFIFOW(fd,2)-9;
- if(sizeof(struct s_homunculus)!=len) {
- if(battle_config.etc_log)
- ShowError("intif: create homun data: data size error %" PRIuPTR " != %d\n",sizeof(struct s_homunculus),len);
- return 0;
- }
- hom_recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8)) ;
- return 1;
- }
- /**
- * ACK homunculus get data (load homun from char)
- * @param fd : char-serv link
- * @return 0=error, 1=sucess
- */
- int intif_parse_RecvHomunculusData(int fd)
- {
- int len;
- len=RFIFOW(fd,2)-9;
- if(sizeof(struct s_homunculus)!=len) {
- if(battle_config.etc_log)
- ShowError("intif: homun data: data size error %" PRIuPTR " %d\n",sizeof(struct s_homunculus),len);
- return 0;
- }
- hom_recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8));
- return 1;
- }
- /**
- * ACK save Homun
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_SaveHomunculusOk(int fd)
- {
- if(RFIFOB(fd,6) != 1)
- ShowError("homunculus data save failure for account %d\n", RFIFOL(fd,2));
- return 1;
- }
- /**
- * ACK delete Homun
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_DeleteHomunculusOk(int fd)
- {
- if(RFIFOB(fd,2) != 1)
- ShowError("Homunculus data delete failure\n");
- return 1;
- }
- /**************************************
- QUESTLOG SYSTEM FUNCTIONS
- ***************************************/
- /**
- * Requests a character's quest log entries to the inter server.
- * @param sd Character's data
- */
- void intif_request_questlog(struct map_session_data *sd)
- {
- if (CheckForCharServer())
- return;
-
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x3060;
- WFIFOL(inter_fd,2) = sd->status.char_id;
- WFIFOSET(inter_fd,6);
- }
- /**
- * Receive a char quest log
- * @param fd : char-serv link
- */
- void intif_parse_questlog(int fd)
- {
- uint32 char_id = RFIFOL(fd,4), num_received = (RFIFOW(fd,2) - 8) / sizeof(struct quest);
- TBL_PC *sd = map_charid2sd(char_id);
- if(!sd) // User not online anymore
- return;
- sd->num_quests = sd->avail_quests = 0;
- if(num_received == 0) {
- if(sd->quest_log) {
- aFree(sd->quest_log);
- sd->quest_log = NULL;
- }
- } else {
- struct quest *received = (struct quest *)RFIFOP(fd,8);
- int k = num_received;
- if(sd->quest_log)
- RECREATE(sd->quest_log, struct quest, num_received);
- else
- CREATE(sd->quest_log, struct quest, num_received);
- for(int i = 0; i < num_received; i++) {
- if(!quest_search(received[i].quest_id)) {
- ShowError("intif_parse_QuestLog: quest %d not found in DB.\n", received[i].quest_id);
- continue;
- }
- if(received[i].state != Q_COMPLETE) // Insert at the beginning
- memcpy(&sd->quest_log[sd->avail_quests++], &received[i], sizeof(struct quest));
- else // Insert at the end
- memcpy(&sd->quest_log[--k], &received[i], sizeof(struct quest));
- sd->num_quests++;
- }
- if(sd->avail_quests < k) {
- // sd->avail_quests and k didn't meet in the middle: some entries were skipped
- if(k < num_received) // Move the entries at the end to fill the gap
- memmove(&sd->quest_log[k], &sd->quest_log[sd->avail_quests], sizeof(struct quest) * (num_received - k));
- sd->quest_log = (struct quest *)aRealloc(sd->quest_log, sizeof(struct quest) * sd->num_quests);
- }
- }
- quest_pc_login(sd);
- }
- /**
- * Parses the quest log save ack for a character from the inter server.
- * Received in reply to the requests made by intif_quest_save.
- * @see intif_parse
- * @param fd : char-serv link
- */
- void intif_parse_questsave(int fd)
- {
- int cid = RFIFOL(fd, 2);
- TBL_PC *sd = map_id2sd(cid);
- if( !RFIFOB(fd, 6) )
- ShowError("intif_parse_questsave: Failed to save quest(s) for character %d!\n", cid);
- else if( sd )
- sd->save_quest = false;
- }
- /**
- * Requests to the inter server to save a character's quest log entries.
- * @param sd Character's data
- * @return 0 in case of success, nonzero otherwise
- */
- int intif_quest_save(struct map_session_data *sd)
- {
- int len = sizeof(struct quest) * sd->num_quests + 8;
- if(CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, len);
- WFIFOW(inter_fd,0) = 0x3061;
- WFIFOW(inter_fd,2) = len;
- WFIFOL(inter_fd,4) = sd->status.char_id;
- if( sd->num_quests )
- memcpy(WFIFOP(inter_fd,8), sd->quest_log, sizeof(struct quest)*sd->num_quests);
- WFIFOSET(inter_fd, len);
- return 1;
- }
- /*==========================================
- * Achievement System
- *------------------------------------------*/
- /**
- * Requests a character's achievement log entries to the inter server.
- * @param char_id: Character ID
- */
- void intif_request_achievements(uint32 char_id)
- {
- if (CheckForCharServer())
- return;
- WFIFOHEAD(inter_fd, 6);
- WFIFOW(inter_fd, 0) = 0x3062;
- WFIFOL(inter_fd, 2) = char_id;
- WFIFOSET(inter_fd, 6);
- }
- /**
- * Receive a character's achievements
- * @param fd: char-serv link
- */
- void intif_parse_achievements(int fd)
- {
- uint32 char_id = RFIFOL(fd, 4), num_received = (RFIFOW(fd, 2) - 8) / sizeof(struct achievement);
- struct map_session_data *sd = map_charid2sd(char_id);
- if (!sd) // User not online anymore
- return;
- if (num_received == 0) {
- if (sd->achievement_data.achievements) {
- aFree(sd->achievement_data.achievements);
- sd->achievement_data.achievements = NULL;
- sd->achievement_data.incompleteCount = 0;
- sd->achievement_data.count = 0;
- }
- } else {
- struct achievement *received = (struct achievement *)RFIFOP(fd, 8);
- int i, k = num_received;
- if (sd->achievement_data.achievements)
- RECREATE(sd->achievement_data.achievements, struct achievement, num_received);
- else
- CREATE(sd->achievement_data.achievements, struct achievement, num_received);
- for (i = 0; i < num_received; i++) {
- std::shared_ptr<s_achievement_db> adb = achievement_db.find( received[i].achievement_id );
- if (!adb) {
- ShowError("intif_parse_achievements: Achievement %d not found in achievement_db.\n", received[i].achievement_id);
- continue;
- }
- received[i].score = adb->score;
- if (received[i].completed == 0) // Insert at the beginning
- memcpy(&sd->achievement_data.achievements[sd->achievement_data.incompleteCount++], &received[i], sizeof(struct achievement));
- else // Insert at the end
- memcpy(&sd->achievement_data.achievements[--k], &received[i], sizeof(struct achievement));
- sd->achievement_data.count++;
- }
- if (sd->achievement_data.incompleteCount < k) {
- // sd->achievement_data.incompleteCount and k didn't meet in the middle: some entries were skipped
- if (k < num_received) // Move the entries at the end to fill the gap
- memmove(&sd->achievement_data.achievements[k], &sd->achievement_data.achievements[sd->achievement_data.incompleteCount], sizeof(struct achievement) * (num_received - k));
- sd->achievement_data.achievements = (struct achievement *)aRealloc(sd->achievement_data.achievements, sizeof(struct achievement) * sd->achievement_data.count);
- }
- }
- // Check all conditions and counters on login
- for( int group = AG_NONE + 1; group < AG_MAX; group++ ){
- achievement_update_objective( sd, static_cast<e_achievement_group>( group ), 0 );
- }
- achievement_level(sd, false); // Calculate level info but don't give any AG_GOAL_ACHIEVE achievements
- achievement_get_titles(sd->status.char_id); // Populate the title list for completed achievements
- clif_achievement_update(sd, NULL, 0);
- clif_achievement_list_all(sd);
- }
- /**
- * Parses the achievement log save ack for a character from the inter server.
- * Received in reply to the requests made by intif_achievement_save.
- * @see intif_parse
- * @param fd : char-serv link
- */
- void intif_parse_achievementsave(int fd)
- {
- int cid = RFIFOL(fd, 2);
- struct map_session_data *sd = map_charid2sd(cid);
- if (!sd) // User not online anymore
- return;
- if (!RFIFOB(fd, 6))
- ShowError("intif_parse_achievementsave: Failed to save achievement(s) for character %s (%d)!\n", sd->status.name, cid);
- }
- /**
- * Requests to the inter server to save a character's achievement log entries.
- * @param sd: Character's data
- * @return 0 in case of success, nonzero otherwise
- */
- int intif_achievement_save(struct map_session_data *sd)
- {
- int len = sizeof(struct achievement) * sd->achievement_data.count + 8;
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, len);
- WFIFOW(inter_fd, 0) = 0x3063;
- WFIFOW(inter_fd, 2) = len;
- WFIFOL(inter_fd, 4) = sd->status.char_id;
- if (sd->achievement_data.count)
- memcpy(WFIFOP(inter_fd, 8), sd->achievement_data.achievements, sizeof(struct achievement) * sd->achievement_data.count);
- WFIFOSET(inter_fd, len);
- sd->achievement_data.save = false;
- return 1;
- }
- /**
- * Parses the reply of the reward claiming for a achievement from the inter server.
- * @see intif_parse
- * @param fd : char-serv link
- */
- void intif_parse_achievementreward(int fd){
- struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
- // User not online anymore
- if( !sd ){
- return;
- }
- achievement_get_reward(sd, RFIFOL(fd, 6), RFIFOL(fd, 10));
- }
- /**
- * Request the achievement rewards from the inter server.
- */
- int intif_achievement_reward(struct map_session_data *sd, struct s_achievement_db *adb){
- if( CheckForCharServer() ){
- return 0;
- }
- WFIFOHEAD(inter_fd, 16+NAME_LENGTH+ACHIEVEMENT_NAME_LENGTH);
- WFIFOW(inter_fd, 0) = 0x3064;
- WFIFOL(inter_fd, 2) = sd->status.char_id;
- WFIFOL(inter_fd, 6) = adb->achievement_id;
- WFIFOL(inter_fd, 10) = adb->rewards.nameid;
- WFIFOW(inter_fd, 14) = adb->rewards.amount;
- safestrncpy(WFIFOCP(inter_fd, 16), sd->status.name, NAME_LENGTH);
- safestrncpy(WFIFOCP(inter_fd, 16+NAME_LENGTH), adb->name.c_str(), ACHIEVEMENT_NAME_LENGTH);
- WFIFOSET(inter_fd, 16+NAME_LENGTH+ACHIEVEMENT_NAME_LENGTH);
- return 1;
- }
- /*==========================================
- * MAIL SYSTEM
- * By Zephyrus
- *==========================================*/
- /**
- * Request to update inbox
- * @param char_id : Player ID linked with box
- * @param flag 0 Update Inbox | 1 OpenMail
- * @return 0=error, 1=msg_sent
- */
- int intif_Mail_requestinbox(uint32 char_id, unsigned char flag, enum mail_inbox_type type)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,8);
- WFIFOW(inter_fd,0) = 0x3048;
- WFIFOL(inter_fd,2) = char_id;
- WFIFOB(inter_fd,6) = flag;
- WFIFOB(inter_fd,7) = type;
- WFIFOSET(inter_fd,8);
- return 1;
- }
- /**
- * Map-serv received a mail from char-serv
- * (inform user of new mail)
- * @param fd : char-serv link
- * @return 0=msg fail, 1=msg received
- */
- int intif_parse_Mail_inboxreceived(int fd)
- {
- struct map_session_data *sd;
- unsigned char flag = RFIFOB(fd,8);
- sd = map_charid2sd(RFIFOL(fd,4));
- if (sd == NULL)
- {
- ShowError("intif_parse_Mail_inboxreceived: char not found %d\n",RFIFOL(fd,4));
- return 0;
- }
- if (RFIFOW(fd,2) - 10 != sizeof(struct mail_data))
- {
- ShowError("intif_parse_Mail_inboxreceived: data size error %d %" PRIuPTR "\n", RFIFOW(fd,2) - 10, sizeof(struct mail_data));
- return 0;
- }
- //FIXME: this operation is not safe [ultramage]
- memcpy(&sd->mail.inbox, RFIFOP(fd,10), sizeof(struct mail_data));
- sd->mail.changed = false; // cache is now in sync
- #if PACKETVER >= 20150513
- // Refresh top right icon
- clif_Mail_new(sd, 0, NULL, NULL);
- #endif
- if (flag){
- clif_Mail_refreshinbox(sd,static_cast<mail_inbox_type>(RFIFOB(fd,9)),0);
- }else if( battle_config.mail_show_status && ( battle_config.mail_show_status == 1 || sd->mail.inbox.unread ) )
- {
- char output[128];
- sprintf(output, msg_txt(sd,510), sd->mail.inbox.unchecked, sd->mail.inbox.unread + sd->mail.inbox.unchecked);
- clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
- }
- return 1;
- }
- /**
- * Notify char-serv that the mail was read
- * @param mail_id : mail reed
- * @return 0=error, 1=msg sent
- */
- int intif_Mail_read(int mail_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x3049;
- WFIFOL(inter_fd,2) = mail_id;
- WFIFOSET(inter_fd,6);
- return 1;
- }
- /**
- * Request the mail attachment for mail
- * @param char_id : Player requesting
- * @param mail_id : Mail identification
- * @return 0=error, 1=msg sent
- */
- bool intif_mail_getattach( struct map_session_data* sd, struct mail_message *msg, enum mail_attachment_type type){
- if (CheckForCharServer())
- return false;
- WFIFOHEAD(inter_fd,11);
- WFIFOW(inter_fd,0) = 0x304a;
- WFIFOL(inter_fd,2) = sd->status.char_id;
- WFIFOL(inter_fd,6) = msg->id;
- WFIFOB(inter_fd,10) = (uint8)type;
- WFIFOSET(inter_fd, 11);
- return true;
- }
- /**
- * Receive the attachment from char-serv of a mail
- * @param fd : char-serv link
- * @return 0=error, 1=sucess
- */
- int intif_parse_Mail_getattach(int fd)
- {
- struct map_session_data *sd;
- struct item item[MAIL_MAX_ITEM];
- int i, mail_id, zeny;
- if (RFIFOW(fd, 2) - 16 != sizeof(struct item)*MAIL_MAX_ITEM)
- {
- ShowError("intif_parse_Mail_getattach: data size error %d %" PRIuPTR "\n", RFIFOW(fd, 2) - 16, sizeof(struct item));
- return 0;
- }
- sd = map_charid2sd( RFIFOL(fd,4) );
- if (sd == NULL)
- {
- ShowError("intif_parse_Mail_getattach: char not found %d\n",RFIFOL(fd,4));
- return 0;
- }
- mail_id = RFIFOL(fd, 8);
- ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
- if (i == MAIL_MAX_INBOX)
- return 0;
- zeny = RFIFOL(fd, 12);
- memcpy(item, RFIFOP(fd,16), sizeof(struct item)*MAIL_MAX_ITEM);
- mail_getattachment(sd, &sd->mail.inbox.msg[i], zeny, item);
- return 1;
- }
- /**
- * request to delete a mail
- * @param char_id : player requesting
- * @param mail_id : mail to delete
- * @return 0=error, 1=msg sent
- */
- int intif_Mail_delete(uint32 char_id, int mail_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x304b;
- WFIFOL(inter_fd,2) = char_id;
- WFIFOL(inter_fd,6) = mail_id;
- WFIFOSET(inter_fd,10);
- return 1;
- }
- /**
- * Ack of a mail deletion
- * @param fd : char-serv link
- * @return 0=error, 1=success
- */
- int intif_parse_Mail_delete(int fd)
- {
- uint32 char_id = RFIFOL(fd,2);
- int mail_id = RFIFOL(fd,6);
- bool failed = RFIFOB(fd,10) > 0;
- struct map_session_data *sd = map_charid2sd(char_id);
- if (sd == NULL)
- {
- ShowError("intif_parse_Mail_delete: char not found %d\n", char_id);
- return 0;
- }
- if (!failed)
- {
- int i;
- ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
- if( i < MAIL_MAX_INBOX )
- {
- enum mail_inbox_type type = sd->mail.inbox.msg[i].type;
- clif_mail_delete(sd, &sd->mail.inbox.msg[i], !failed);
- memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message));
- sd->mail.inbox.amount--;
- if( sd->mail.inbox.full || sd->mail.inbox.unchecked > 0 )
- intif_Mail_requestinbox(sd->status.char_id, 1, type); // Free space is available for new mails
- }
- }
- return 1;
- }
- /*------------------------------------------
- * Return Message
- *------------------------------------------*/
- /**
- * Request to return a mail to his sender
- * @param char_id : player asking to return
- * @param mail_id : mail to return
- * @return 0=error, 1=msg sent
- */
- int intif_Mail_return(uint32 char_id, int mail_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x304c;
- WFIFOL(inter_fd,2) = char_id;
- WFIFOL(inter_fd,6) = mail_id;
- WFIFOSET(inter_fd,10);
- return 1;
- }
- /**
- * Received a returned mail
- * @param fd
- * @return
- */
- int intif_parse_Mail_return(int fd)
- {
- struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
- int mail_id = RFIFOL(fd,6);
- short fail = RFIFOB(fd,10);
- if( sd == NULL )
- {
- ShowError("intif_parse_Mail_return: char not found %d\n",RFIFOL(fd,2));
- return 1;
- }
- if( !fail )
- {
- int i;
- ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
- if( i < MAIL_MAX_INBOX )
- {
- enum mail_inbox_type type = sd->mail.inbox.msg[i].type;
- memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message));
- sd->mail.inbox.amount--;
- if( sd->mail.inbox.full )
- intif_Mail_requestinbox(sd->status.char_id, 1, type); // Free space is available for new mails
- }
- }
- clif_Mail_return(sd->fd, mail_id, fail);
- return 1;
- }
- /*------------------------------------------
- * Send Mail
- *------------------------------------------*/
- /**
- * Request to send a mail
- * @param account_id
- * @param msg : mail struct
- * @return 0=error, 1=msg sent
- */
- int intif_Mail_send(uint32 account_id, struct mail_message *msg)
- {
- int len = sizeof(struct mail_message) + 8;
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,len);
- WFIFOW(inter_fd,0) = 0x304d;
- WFIFOW(inter_fd,2) = len;
- WFIFOL(inter_fd,4) = account_id;
- memcpy(WFIFOP(inter_fd,8), msg, sizeof(struct mail_message));
- WFIFOSET(inter_fd,len);
- return 1;
- }
- /**
- * Received the ack of a mail send request
- * @param fd L char-serv link
- */
- static void intif_parse_Mail_send(int fd)
- {
- struct mail_message msg;
- struct map_session_data *sd;
- bool fail;
- if( RFIFOW(fd,2) - 4 != sizeof(struct mail_message) )
- {
- ShowError("intif_parse_Mail_send: data size error %d %" PRIuPTR "\n", RFIFOW(fd,2) - 4, sizeof(struct mail_message));
- return;
- }
- memcpy(&msg, RFIFOP(fd,4), sizeof(struct mail_message));
- fail = (msg.id == 0);
- // notify sender
- sd = map_charid2sd(msg.send_id);
- if( sd != NULL )
- {
- if( fail )
- mail_deliveryfail(sd, &msg);
- else
- {
- clif_Mail_send(sd, WRITE_MAIL_SUCCESS);
- if( save_settings&CHARSAVE_MAIL )
- chrif_save(sd, CSAVE_INVENTORY);
- }
- }
- }
- /**
- * Received a new mail notification
- * @param fd : char-link serv
- */
- static void intif_parse_Mail_new(int fd)
- {
- struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
- int mail_id = RFIFOL(fd,6);
- const char* sender_name = RFIFOCP(fd,10);
- const char* title = RFIFOCP(fd,34);
- if( sd == NULL )
- return;
- sd->mail.changed = true;
- sd->mail.inbox.unread++;
- clif_Mail_new(sd, mail_id, sender_name, title);
- #if PACKETVER >= 20150513
- // Make sure the window gets refreshed when its open
- intif_Mail_requestinbox(sd->status.char_id, 1, static_cast<mail_inbox_type>(RFIFOB(fd,74)));
- #endif
- }
- static void intif_parse_Mail_receiver( int fd ){
- struct map_session_data *sd;
- sd = map_charid2sd( RFIFOL( fd, 2 ) );
- // Only f the player is online
- if( sd ){
- clif_Mail_Receiver_Ack( sd, RFIFOL( fd, 6 ), RFIFOW( fd, 10 ), RFIFOW( fd, 12 ), RFIFOCP( fd, 14 ) );
- }
- }
- bool intif_mail_checkreceiver( struct map_session_data* sd, char* name ){
- struct map_session_data *tsd;
- tsd = map_nick2sd( name, false );
- // If the target player is online on this map-server
- if( tsd != NULL ){
- clif_Mail_Receiver_Ack( sd, tsd->status.char_id, tsd->status.class_, tsd->status.base_level, name );
- return true;
- }
- if( CheckForCharServer() )
- return false;
- WFIFOHEAD(inter_fd, 6 + NAME_LENGTH);
- WFIFOW(inter_fd, 0) = 0x304e;
- WFIFOL(inter_fd, 2) = sd->status.char_id;
- safestrncpy(WFIFOCP(inter_fd, 6), name, NAME_LENGTH);
- WFIFOSET(inter_fd, 6 + NAME_LENGTH);
- return true;
- }
- /*==========================================
- * AUCTION SYSTEM
- * By Zephyrus
- *==========================================*/
- /**
- * Request a list of auction matching criteria
- * @param char_id : player searching auction
- * @param type : see clif_parse_Auction_search type
- * @param price : min price for search
- * @param searchtext : contain item name
- * @param page : in case of huge result list display 5 entry per page, (kinda suck that we redo the request atm)
- * @return 0=error, 1=msg sent
- */
- int intif_Auction_requestlist(uint32 char_id, short type, int price, const char* searchtext, short page)
- {
- int len = NAME_LENGTH + 16;
- if( CheckForCharServer() )
- return 0;
- WFIFOHEAD(inter_fd,len);
- WFIFOW(inter_fd,0) = 0x3050;
- WFIFOW(inter_fd,2) = len;
- WFIFOL(inter_fd,4) = char_id;
- WFIFOW(inter_fd,8) = type;
- WFIFOL(inter_fd,10) = price; //min price for search
- WFIFOW(inter_fd,14) = page;
- memcpy(WFIFOP(inter_fd,16), searchtext, NAME_LENGTH);
- WFIFOSET(inter_fd,len);
- return 1;
- }
- /**
- * Received a list of auction, display them
- * @param fd : Char-serv link
- */
- static void intif_parse_Auction_results(int fd)
- {
- struct map_session_data *sd = map_charid2sd(RFIFOL(fd,4));
- short count = RFIFOW(fd,8);
- short pages = RFIFOW(fd,10);
- uint8* data = RFIFOP(fd,12);
- if( sd == NULL )
- return;
- clif_Auction_results(sd, count, pages, data);
- }
- /**
- * Register an auction to char-serv
- * @param auction : tmp auction to register
- * @return 0=error, 1=msg sent
- */
- int intif_Auction_register(struct auction_data *auction)
- {
- int len = sizeof(struct auction_data) + 4;
- if( CheckForCharServer() )
- return 0;
- WFIFOHEAD(inter_fd,len);
- WFIFOW(inter_fd,0) = 0x3051;
- WFIFOW(inter_fd,2) = len;
- memcpy(WFIFOP(inter_fd,4), auction, sizeof(struct auction_data));
- WFIFOSET(inter_fd,len);
- return 1;
- }
- /**
- * Receive a auction available from char-serv
- * @param fd : char-serv link
- */
- static void intif_parse_Auction_register(int fd)
- {
- struct map_session_data *sd;
- struct auction_data auction;
- if( RFIFOW(fd,2) - 4 != sizeof(struct auction_data) )
- {
- ShowError("intif_parse_Auction_register: data size error %d %" PRIuPTR "\n", RFIFOW(fd,2) - 4, sizeof(struct auction_data));
- return;
- }
- memcpy(&auction, RFIFOP(fd,4), sizeof(struct auction_data));
- if( (sd = map_charid2sd(auction.seller_id)) == NULL )
- return;
- if( auction.auction_id > 0 )
- {
- clif_Auction_message(sd->fd, 1); // Confirmation Packet ??
- if( save_settings&CHARSAVE_AUCTION )
- chrif_save(sd, CSAVE_INVENTORY);
- }
- else
- {
- int zeny = auction.hours*battle_config.auction_feeperhour;
- clif_Auction_message(sd->fd, 4);
- pc_additem(sd, &auction.item, auction.item.amount, LOG_TYPE_AUCTION);
- pc_getzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
- }
- }
- /**
- * Inform char-serv that the auction is cancelled
- * @param char_id : player that has cancel the auction
- * @param auction_id : auction to cancel
- * @return 0=error, 1=msg sent
- */
- int intif_Auction_cancel(uint32 char_id, unsigned int auction_id)
- {
- if( CheckForCharServer() )
- return 0;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x3052;
- WFIFOL(inter_fd,2) = char_id;
- WFIFOL(inter_fd,6) = auction_id;
- WFIFOSET(inter_fd,10);
- return 1;
- }
- /**
- * Receive a notification that the auction was cancelled
- * @param fd : char-serv link
- */
- static void intif_parse_Auction_cancel(int fd)
- {
- struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
- int result = RFIFOB(fd,6);
- if( sd == NULL )
- return;
- switch( result )
- {
- case 0: clif_Auction_message(sd->fd, 2); break;
- case 1: clif_Auction_close(sd->fd, 2); break;
- case 2: clif_Auction_close(sd->fd, 1); break;
- case 3: clif_Auction_message(sd->fd, 3); break;
- }
- }
- /**
- * Inform the char-serv that the auction has ended
- * @param char_id : player that stop the auction
- * @param auction_id : auction to stop
- * @return 0=error, 1=msg sent
- */
- int intif_Auction_close(uint32 char_id, unsigned int auction_id)
- {
- if( CheckForCharServer() )
- return 0;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x3053;
- WFIFOL(inter_fd,2) = char_id;
- WFIFOL(inter_fd,6) = auction_id;
- WFIFOSET(inter_fd,10);
- return 1;
- }
- /**
- * Receive a notification that the auction has ended
- * @param fd : char-serv link
- */
- static void intif_parse_Auction_close(int fd)
- {
- struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
- unsigned char result = RFIFOB(fd,6);
- if( sd == NULL )
- return;
- clif_Auction_close(sd->fd, result);
- if( result == 0 )
- {
- // FIXME: Leeching off a parse function
- clif_parse_Auction_cancelreg(fd, sd);
- intif_Auction_requestlist(sd->status.char_id, 6, 0, "", 1);
- }
- }
- /**
- * Bid for an auction
- * @param char_id
- * @param name
- * @param auction_id
- * @param bid
- * @return 0=error, 1=msg sent
- */
- int intif_Auction_bid(uint32 char_id, const char* name, unsigned int auction_id, int bid)
- {
- int len = 16 + NAME_LENGTH;
- if( CheckForCharServer() )
- return 0;
- WFIFOHEAD(inter_fd,len);
- WFIFOW(inter_fd,0) = 0x3055;
- WFIFOW(inter_fd,2) = len;
- WFIFOL(inter_fd,4) = char_id;
- WFIFOL(inter_fd,8) = auction_id;
- WFIFOL(inter_fd,12) = bid;
- memcpy(WFIFOP(inter_fd,16), name, NAME_LENGTH);
- WFIFOSET(inter_fd,len);
- return 1;
- }
- /**
- * Get back the money from biding auction,
- * (someone else have bid it over)
- * @param fd : char-serv link
- */
- static void intif_parse_Auction_bid(int fd)
- {
- struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
- int bid = RFIFOL(fd,6);
- unsigned char result = RFIFOB(fd,10);
- if( sd == NULL )
- return;
- clif_Auction_message(sd->fd, result);
- if( bid > 0 )
- {
- pc_getzeny(sd, bid, LOG_TYPE_AUCTION,NULL);
- }
- if( result == 1 )
- { // To update the list, display your buy list
- clif_parse_Auction_cancelreg(fd, sd);
- intif_Auction_requestlist(sd->status.char_id, 7, 0, "", 1);
- }
- }
- /**
- * Used to send 'You have won the auction' and 'You failed to won the auction' messages
- * @param fd : char-serv link
- */
- static void intif_parse_Auction_message(int fd)
- {
- struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2));
- unsigned char result = RFIFOB(fd,6);
- if( sd == NULL )
- return;
- clif_Auction_message(sd->fd, result);
- }
- /*==========================================
- * Mercenary's System
- *------------------------------------------*/
- /**
- * Request to create/register a mercenary on char-serv
- * @param merc : Tmp mercenary data
- * @return 0=error, 1=msg sent
- */
- int intif_mercenary_create(struct s_mercenary *merc)
- {
- int size = sizeof(struct s_mercenary) + 4;
- if( CheckForCharServer() )
- return 0;
- WFIFOHEAD(inter_fd,size);
- WFIFOW(inter_fd,0) = 0x3070;
- WFIFOW(inter_fd,2) = size;
- memcpy(WFIFOP(inter_fd,4), merc, sizeof(struct s_mercenary));
- WFIFOSET(inter_fd,size);
- return 1;
- }
- /**
- * Ack of a load or create request
- * @param fd : char-serv link
- * @return 0=error, 1=success
- */
- int intif_parse_mercenary_received(int fd)
- {
- int len = RFIFOW(fd,2) - 5;
- if( sizeof(struct s_mercenary) != len )
- {
- if( battle_config.etc_log )
- ShowError("intif: create mercenary data size error %" PRIuPTR " != %d\n", sizeof(struct s_mercenary), len);
- return 0;
- }
- mercenary_recv_data((struct s_mercenary*)RFIFOP(fd,5), RFIFOB(fd,4) > 0);
- return 1;
- }
- /**
- * Request mercenary data from char-serv
- * @param merc_id : mercenary id to load
- * @param char_id : player cid requesting data
- * @return 0=error, 1=msg sent
- */
- int intif_mercenary_request(int merc_id, uint32 char_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x3071;
- WFIFOL(inter_fd,2) = merc_id;
- WFIFOL(inter_fd,6) = char_id;
- WFIFOSET(inter_fd,10);
- return 1;
- }
- /**
- * Request to delete a mercenary
- * @param merc_id
- * @return 0=error, 1=msg sent
- */
- int intif_mercenary_delete(int merc_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x3072;
- WFIFOL(inter_fd,2) = merc_id;
- WFIFOSET(inter_fd,6);
- return 1;
- }
- /**
- * Ack of a mercenary deletion request
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_mercenary_deleted(int fd)
- {
- if( RFIFOB(fd,2) != 1 )
- ShowError("Mercenary data delete failure\n");
- return 1;
- }
- /**
- * Request to save a mercenary
- * @param merc : Mercenary struct to save
- * @return 0=error, 1=msg sent
- */
- int intif_mercenary_save(struct s_mercenary *merc)
- {
- int size = sizeof(struct s_mercenary) + 4;
- if( CheckForCharServer() )
- return 0;
- WFIFOHEAD(inter_fd,size);
- WFIFOW(inter_fd,0) = 0x3073;
- WFIFOW(inter_fd,2) = size;
- memcpy(WFIFOP(inter_fd,4), merc, sizeof(struct s_mercenary));
- WFIFOSET(inter_fd,size);
- return 1;
- }
- /**
- * Ack of a mercenary save request
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_mercenary_saved(int fd)
- {
- if( RFIFOB(fd,2) != 1 )
- ShowError("Mercenary data save failure\n");
- return 1;
- }
- /*==========================================
- * Elemental's System
- *------------------------------------------*/
- /**
- * Request to create elemental, (verify and save on char-serv)
- * @param ele : Tmp Elemental data
- * @return 0=error, 1=msg sent
- */
- int intif_elemental_create(struct s_elemental *ele)
- {
- int size = sizeof(struct s_elemental) + 4;
- if( CheckForCharServer() )
- return 0;
- WFIFOHEAD(inter_fd,size);
- WFIFOW(inter_fd,0) = 0x307c;
- WFIFOW(inter_fd,2) = size;
- memcpy(WFIFOP(inter_fd,4), ele, sizeof(struct s_elemental));
- WFIFOSET(inter_fd,size);
- return 1;
- }
- /**
- * Receive an elemental data from char-serv
- * @param fd : char-serv link
- * @return 0=error, 1=success
- */
- int intif_parse_elemental_received(int fd)
- {
- int len = RFIFOW(fd,2) - 5;
- if( sizeof(struct s_elemental) != len )
- {
- if( battle_config.etc_log )
- ShowError("intif: create elemental data size error %" PRIuPTR " != %d\n", sizeof(struct s_elemental), len);
- return 0;
- }
- elemental_data_received((struct s_elemental*)RFIFOP(fd,5), RFIFOB(fd,4) > 0);
- return 1;
- }
- /**
- * Request to load elemental from char-serv
- * @param ele_id : elemental identification
- * @param char_id : player identification
- * @return 0=error, 1=msg sent
- */
- int intif_elemental_request(int ele_id, uint32 char_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x307d;
- WFIFOL(inter_fd,2) = ele_id;
- WFIFOL(inter_fd,6) = char_id;
- WFIFOSET(inter_fd,10);
- return 1;
- }
- /**
- * Request to delete an elemental
- * @param ele_id : Elemental to delete
- * @return 0=error, 1=msg sent
- */
- int intif_elemental_delete(int ele_id)
- {
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x307e;
- WFIFOL(inter_fd,2) = ele_id;
- WFIFOSET(inter_fd,6);
- return 1;
- }
- /**
- * Ack of a delete elemental request
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_elemental_deleted(int fd)
- {
- if( RFIFOB(fd,2) != 1 )
- ShowError("Elemental data delete failure\n");
- return 1;
- }
- /**
- * Request to save elemental data
- * @param ele : elemental struct to save
- * @return 0=error, 1=msg sent
- */
- int intif_elemental_save(struct s_elemental *ele)
- {
- int size = sizeof(struct s_elemental) + 4;
- if( CheckForCharServer() )
- return 0;
- WFIFOHEAD(inter_fd,size);
- WFIFOW(inter_fd,0) = 0x307f;
- WFIFOW(inter_fd,2) = size;
- memcpy(WFIFOP(inter_fd,4), ele, sizeof(struct s_elemental));
- WFIFOSET(inter_fd,size);
- return 1;
- }
- /**
- * Ack of a save elemental request
- * @param fd : char-serv link
- * @return 1
- */
- int intif_parse_elemental_saved(int fd)
- {
- if( RFIFOB(fd,2) != 1 )
- ShowError("Elemental data save failure\n");
- return 1;
- }
- /**
- * Request account information to char-serv
- * @param u_fd : Player fd (for message back)
- * @param aid : requesting player aid
- * @param group_lv : requesting player lv
- * @param query : name or aid of player we want info
- * @param type : 1 - Only return account id & userid, 0 - Full info
- * @return : 0=error, 1=msg sent
- */
- int intif_request_accinfo(int u_fd, int aid, int group_lv, char* query, char type) {
- if( CheckForCharServer() )
- return 0;
-
- WFIFOHEAD(inter_fd,2 + 4 + 4 + 4 + 1 + NAME_LENGTH);
- WFIFOW(inter_fd,0) = 0x3007;
- WFIFOL(inter_fd,2) = u_fd;
- WFIFOL(inter_fd,6) = aid;
- WFIFOL(inter_fd,10) = group_lv;
- WFIFOB(inter_fd,14) = type;
- safestrncpy(WFIFOCP(inter_fd,15), query, NAME_LENGTH);
- WFIFOSET(inter_fd,2 + 4 + 4 + 4 + 1 + NAME_LENGTH);
- return 1;
- }
- /**
- * Receive the reply of a request_accinfo with type 1
- * @param fd : char-serv link
- */
- void intif_parse_accinfo_ack( int fd ) {
- char acc_name[NAME_LENGTH];
- int u_fd = RFIFOL(fd,2);
- int acc_id = RFIFOL(fd,6);
- safestrncpy(acc_name, RFIFOCP(fd,10), NAME_LENGTH);
- clif_account_name(u_fd, acc_id, acc_name);
- }
- /**
- * Display a message from char-serv to a player
- * @param fd : Char-serv link
- */
- void intif_parse_MessageToFD(int fd) {
- int u_fd = RFIFOL(fd,4);
- if( session[u_fd] && session[u_fd]->session_data ) { //check if the player still online
- int aid = RFIFOL(fd,8);
- struct map_session_data * sd = (struct map_session_data *)session[u_fd]->session_data;
- /* matching e.g. previous fd owner didn't dc during request or is still the same */
- if( sd->bl.id == aid ) {
- char msg[512];
- safestrncpy(msg, RFIFOCP(fd,12), RFIFOW(fd,2) - 12);
- clif_displaymessage(u_fd,msg);
- }
- }
- return;
- }
- /// BROADCAST OBTAIN SPECIAL ITEM
- /**
- * Request to send broadcast item to all servers
- * ZI 3009 <cmd>.W <len>.W <nameid>.N <source>.W <type>.B <name>.?B
- * @param sd Player who obtain the item
- * @param nameid Obtained item
- * @param sourceid Source of item, another item ID or monster ID
- * @param type Obtain type @see enum BROADCASTING_SPECIAL_ITEM_OBTAIN
- * @return
- **/
- int intif_broadcast_obtain_special_item(struct map_session_data *sd, t_itemid nameid, t_itemid sourceid, unsigned char type) {
- nullpo_retr(0, sd);
- // Should not be here!
- if (type == ITEMOBTAIN_TYPE_NPC) {
- intif_broadcast_obtain_special_item_npc(sd, nameid);
- return 0;
- }
- // Send local
- clif_broadcast_obtain_special_item(sd->status.name, nameid, sourceid, (enum BROADCASTING_SPECIAL_ITEM_OBTAIN)type);
- if (CheckForCharServer())
- return 0;
- if (other_mapserver_count < 1)
- return 0;
- WFIFOHEAD(inter_fd, 11 + NAME_LENGTH);
- WFIFOW(inter_fd, 0) = 0x3009;
- WFIFOW(inter_fd, 2) = 11 + NAME_LENGTH;
- WFIFOL(inter_fd, 4) = nameid;
- WFIFOW(inter_fd, 8) = sourceid;
- WFIFOB(inter_fd, 10) = type;
- safestrncpy(WFIFOCP(inter_fd, 11), sd->status.name, NAME_LENGTH);
- WFIFOSET(inter_fd, WFIFOW(inter_fd, 2));
- return 1;
- }
- /**
- * Request to send broadcast item to all servers.
- * TODO: Confirm the usage. Maybe on getitem-like command?
- * ZI 3009 <cmd>.W <len>.W <nameid>.N <source>.W <type>.B <name>.24B <npcname>.24B
- * @param sd Player who obtain the item
- * @param nameid Obtained item
- * @param srcname Source name
- * @return
- **/
- int intif_broadcast_obtain_special_item_npc(struct map_session_data *sd, t_itemid nameid) {
- nullpo_retr(0, sd);
- // Send local
- clif_broadcast_obtain_special_item(sd->status.name, nameid, 0, ITEMOBTAIN_TYPE_NPC);
- if (CheckForCharServer())
- return 0;
- if (other_mapserver_count < 1)
- return 0;
- WFIFOHEAD(inter_fd, 11 + NAME_LENGTH*2);
- WFIFOW(inter_fd, 0) = 0x3009;
- WFIFOW(inter_fd, 2) = 11 + NAME_LENGTH*2;
- WFIFOL(inter_fd, 4) = nameid;
- WFIFOW(inter_fd, 8) = 0;
- WFIFOB(inter_fd, 10) = ITEMOBTAIN_TYPE_NPC;
- safestrncpy(WFIFOCP(inter_fd, 11), sd->status.name, NAME_LENGTH);
- WFIFOSET(inter_fd, WFIFOW(inter_fd, 2));
- return 1;
- }
- /**
- * Received broadcast item and broadcast on local map.
- * IZ 3809 <cmd>.W <len>.W <nameid>.L <source>.W <type>.B <name>.24B <srcname>.24B
- * @param fd
- **/
- void intif_parse_broadcast_obtain_special_item(int fd) {
- int type = RFIFOB(fd, 10);
- char name[NAME_LENGTH];
- safestrncpy(name, RFIFOCP(fd, 11), NAME_LENGTH);
- if (type == ITEMOBTAIN_TYPE_NPC)
- safestrncpy(name, RFIFOCP(fd, 11 + NAME_LENGTH), NAME_LENGTH);
- clif_broadcast_obtain_special_item(name, RFIFOL(fd, 4), RFIFOW(fd, 8), (enum BROADCASTING_SPECIAL_ITEM_OBTAIN)type);
- }
- /*==========================================
- * Item Bound System
- *------------------------------------------*/
- #ifdef BOUND_ITEMS
- /**
- * ZI 0x3056 <char_id>.L <account_id>.L <guild_id>.W
- * Request inter-serv to delete some bound item, for non connected cid
- * @param char_id : Char to delete item ID
- * @param aid : Account to delete item ID
- * @param guild_id : Guild of char
- */
- void intif_itembound_guild_retrieve(uint32 char_id,uint32 account_id,int guild_id) {
- struct s_storage *gstor = guild2storage2(guild_id);
-
- if( CheckForCharServer() )
- return;
-
- WFIFOHEAD(inter_fd,12);
- WFIFOW(inter_fd,0) = 0x3056;
- WFIFOL(inter_fd,2) = char_id;
- WFIFOL(inter_fd,6) = account_id;
- WFIFOW(inter_fd,10) = guild_id;
- WFIFOSET(inter_fd,12);
- if (gstor)
- gstor->lock = true; //Lock for retrieval process
- 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);
- }
- /**
- * Acknowledge the good deletion of the bound item
- * (unlock the guild storage)
- * @struct : 0x3856 <aid>.L <gid>.W
- * @param fd : Char-serv link
- */
- void intif_parse_itembound_ack(int fd) {
- int guild_id = RFIFOW(fd,6);
- struct s_storage *gstor = guild2storage2(guild_id);
- if (gstor)
- gstor->lock = false; //Unlock now that operation is completed
- }
- /**
- * IZ 0x3857 <size>.W <count>.W <guild_id>.W { <item>.?B }.*MAX_INVENTORY
- * Received the retrieved guild bound items from inter-server, store them to guild storage.
- * @param fd
- * @author [Cydh]
- */
- void intif_parse_itembound_store2gstorage(int fd) {
- unsigned short i, failed = 0;
- short count = RFIFOW(fd, 4), guild_id = RFIFOW(fd, 6);
- struct s_storage *gstor = guild2storage(guild_id);
- if (!gstor) {
- ShowError("intif_parse_itembound_store2gstorage: Guild '%d' not found.\n", guild_id);
- return;
- }
- //@TODO: Gives some actions for item(s) that cannot be stored because storage is full or reach the limit of stack amount
- for (i = 0; i < count; i++) {
- struct item *item = (struct item*)RFIFOP(fd, 8 + i*sizeof(struct item));
- if (!item)
- continue;
- if (!storage_guild_additem2(gstor, item, item->amount))
- failed++;
- }
- 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);
- gstor->lock = false;
- gstor->status = false;
- }
- #endif
- /**
- * Receive inventory/cart/storage data for player
- * IZ 0x388a <size>.W <type>.B <account_id>.L <result>.B <storage>.?B
- * @param fd
- */
- static bool intif_parse_StorageReceived(int fd)
- {
- char type = RFIFOB(fd,4);
- uint32 account_id = RFIFOL(fd, 5);
- struct map_session_data *sd = map_id2sd(account_id);
- struct s_storage *stor, *p; //storage
- size_t sz_stor = sizeof(struct s_storage);
- if (!sd) {
- ShowError("intif_parse_StorageReceived: No player online for receiving inventory/cart/storage data (AID: %d)\n", account_id);
- return false;
- }
- if (!RFIFOB(fd, 9)) {
- ShowError("intif_parse_StorageReceived: Failed to load! (AID: %d, type: %d)\n", account_id, type);
- return false;
- }
- p = (struct s_storage *)RFIFOP(fd,10);
- switch (type) {
- case TABLE_INVENTORY:
- stor = &sd->inventory;
- break;
- case TABLE_STORAGE:
- if (p->stor_id == 0)
- stor = &sd->storage;
- else
- stor = &sd->premiumStorage;
- break;
- case TABLE_CART:
- stor = &sd->cart;
- break;
- default:
- return false;
- }
- if (stor->stor_id == p->stor_id) {
- if (stor->status) { // Already open.. lets ignore this update
- ShowWarning("intif_parse_StorageReceived: storage received for a client already open (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
- return false;
- }
- if (stor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit!
- ShowWarning("intif_parse_StorageReceived: received storage for an already modified non-saved storage! (User %d:%d)\n", sd->status.account_id, sd->status.char_id);
- return false;
- }
- }
- if (RFIFOW(fd,2)-10 != sz_stor) {
- ShowError("intif_parse_StorageReceived: data size error %d %" PRIuPTR "\n",RFIFOW(fd,2)-10 , sz_stor);
- stor->status = false;
- return false;
- }
- memcpy(stor, p, sz_stor); //copy the items data to correct destination
- switch (type) {
- case TABLE_INVENTORY: {
- #ifdef BOUND_ITEMS
- int j, idxlist[MAX_INVENTORY];
- #endif
- pc_setinventorydata(sd);
- pc_setequipindex(sd);
- pc_check_expiration(sd);
- pc_check_available_item(sd, ITMCHK_INVENTORY);
- pc_itemcd_do(sd, true);
- #ifdef BOUND_ITEMS
- // Party bound item check
- if (sd->status.party_id == 0 && (j = pc_bound_chk(sd, BOUND_PARTY, idxlist))) { // Party was deleted while character offline
- int i;
- for (i = 0; i < j; i++)
- pc_delitem(sd, idxlist[i], sd->inventory.u.items_inventory[idxlist[i]].amount, 4, 1, LOG_TYPE_OTHER);
- }
- #endif
- //Set here because we need the inventory data for weapon sprite parsing.
- status_set_viewdata(&sd->bl, sd->status.class_);
- pc_load_combo(sd);
- status_calc_pc(sd, (enum e_status_calc_opt)(SCO_FIRST|SCO_FORCE));
- status_calc_weight(sd, (e_status_calc_weight_opt)(CALCWT_ITEM|CALCWT_MAXBONUS)); // Refresh weight data
- chrif_scdata_request(sd->status.account_id, sd->status.char_id);
- break;
- }
- case TABLE_CART:
- pc_check_available_item(sd, ITMCHK_CART);
- if (sd->state.autotrade) {
- clif_parse_LoadEndAck(sd->fd, sd);
- sd->autotrade_tid = add_timer(gettick() + battle_config.feature_autotrade_open_delay, pc_autotrade_timer, sd->bl.id, 0);
- }else if( sd->state.prevend ){
- clif_clearcart(sd->fd);
- clif_cartlist(sd);
- clif_openvendingreq(sd, sd->vend_skill_lv+2);
- }
- break;
- case TABLE_STORAGE:
- if (stor->stor_id)
- storage_premiumStorage_open(sd);
- else {
- #ifdef VIP_ENABLE
- if (!pc_isvip(sd))
- stor->max_amount = MIN_STORAGE;
- #endif
- pc_check_available_item(sd, ITMCHK_STORAGE);
- }
- break;
- }
- return true;
- }
- /**
- * Save inventory/cart/storage data for a player
- * IZ 0x388b <account_id>.L <result>.B <type>.B <storage_id>.B
- * @param fd
- */
- static void intif_parse_StorageSaved(int fd)
- {
- if (RFIFOB(fd, 6)) {
- switch (RFIFOB(fd, 7)) {
- case TABLE_INVENTORY: //inventory
- //ShowInfo("Inventory has been saved (AID: %d).\n", RFIFOL(fd, 2));
- break;
- case TABLE_STORAGE: //storage
- //ShowInfo("Storage has been saved (AID: %d).\n", RFIFOL(fd, 2));
- if (RFIFOB(fd, 8))
- storage_premiumStorage_saved(map_id2sd(RFIFOL(fd, 2)));
- break;
- case TABLE_CART: // cart
- //ShowInfo("Cart has been saved (AID: %d).\n", RFIFOL(fd, 2));
- {
- struct map_session_data *sd = map_id2sd(RFIFOL(fd, 2));
- if( sd && sd->state.prevend ){
- intif_storage_request(sd,TABLE_CART,0,STOR_MODE_ALL);
- }
- }
- break;
- default:
- break;
- }
- } else
- ShowError("Failed to save inventory/cart/storage data (AID: %d, type: %d).\n", RFIFOL(fd, 2), RFIFOB(fd, 7));
- }
- /**
- * IZ 0x388c <len>.W { <storage_table>.? }*?
- * Receive storage information
- **/
- void intif_parse_StorageInfo_recv(int fd) {
- int i, size = sizeof(struct s_storage_table), count = (RFIFOW(fd, 2) - 4) / size;
- storage_count = 0;
- if (storage_db)
- aFree(storage_db);
- storage_db = NULL;
- for (i = 0; i < count; i++) {
- RECREATE(storage_db, struct s_storage_table, storage_count+1);
- memcpy(&storage_db[storage_count], RFIFOP(fd, 4 + size * i), size);
- storage_count++;
- }
- if (battle_config.etc_log)
- ShowInfo("Received '" CL_WHITE "%d" CL_RESET "' storage info from inter-server.\n", storage_count);
- }
- /**
- * Request inventory/cart/storage data for a player
- * ZI 0x308a <type>.B <account_id>.L <char_id>.L <storage_id>.B
- * @param sd: Player data
- * @param type: Storage type
- * @param stor_id: Storage ID
- * @param mode: Storage mode
- * @return false - error, true - message sent
- */
- bool intif_storage_request(struct map_session_data *sd, enum storage_type type, uint8 stor_id, uint8 mode)
- {
- if (CheckForCharServer())
- return false;
- WFIFOHEAD(inter_fd, 13);
- WFIFOW(inter_fd, 0) = 0x308a;
- WFIFOB(inter_fd, 2) = type;
- WFIFOL(inter_fd, 3) = sd->status.account_id;
- WFIFOL(inter_fd, 7) = sd->status.char_id;
- WFIFOB(inter_fd, 11) = stor_id;
- WFIFOB(inter_fd, 12) = mode;
- WFIFOSET(inter_fd, 13);
- return true;
- }
- /**
- * Request to save inventory/cart/storage data from player
- * ZI 0x308b <size>.W <type>.B <account_id>.L <char_id>.L <entries>.?B
- * @param sd: Player data
- * @param stor: Storage data
- * @ return false - error, true - message sent
- */
- bool intif_storage_save(struct map_session_data *sd, struct s_storage *stor)
- {
- int stor_size = sizeof(struct s_storage);
- nullpo_retr(false, sd);
- nullpo_retr(false, stor);
- if (CheckForCharServer())
- return false;
- WFIFOHEAD(inter_fd, stor_size+13);
- WFIFOW(inter_fd, 0) = 0x308b;
- WFIFOW(inter_fd, 2) = stor_size+13;
- WFIFOB(inter_fd, 4) = stor->type;
- WFIFOL(inter_fd, 5) = sd->status.account_id;
- WFIFOL(inter_fd, 9) = sd->status.char_id;
- memcpy(WFIFOP(inter_fd, 13), stor, stor_size);
- WFIFOSET(inter_fd, stor_size+13);
- return true;
- }
- int intif_clan_requestclans(){
- if (CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 2);
- WFIFOW(inter_fd, 0) = 0x30A0;
- WFIFOSET(inter_fd, 2);
- return 1;
- }
- void intif_parse_clans( int fd ){
- clan_load_clandata( ( RFIFOW(fd, 2) - 4 ) / sizeof( struct clan ), (struct clan*)RFIFOP(fd,4) );
- }
- int intif_clan_message(int clan_id,uint32 account_id,const char *mes,int len){
- if (CheckForCharServer())
- return 0;
- if (other_mapserver_count < 1)
- return 0; //No need to send.
- WFIFOHEAD(inter_fd, len + 12);
- WFIFOW(inter_fd,0)=0x30A1;
- WFIFOW(inter_fd,2)=len+12;
- WFIFOL(inter_fd,4)=clan_id;
- WFIFOL(inter_fd,8)=account_id;
- memcpy(WFIFOP(inter_fd,12),mes,len);
- WFIFOSET(inter_fd,len+12);
- return 1;
- }
- int intif_parse_clan_message( int fd ){
- clan_recv_message(RFIFOL(fd,4),RFIFOL(fd,8),(char *) RFIFOP(fd,12),RFIFOW(fd,2)-12);
- return 1;
- }
- int intif_clan_member_left( int clan_id ){
- if (CheckForCharServer())
- return 0;
- if (other_mapserver_count < 1)
- return 0; //No need to send.
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x30A2;
- WFIFOL(inter_fd,2) = clan_id;
- WFIFOSET(inter_fd,6);
-
- return 1;
- }
- int intif_clan_member_joined( int clan_id ){
- if (CheckForCharServer())
- return 0;
- if (other_mapserver_count < 1)
- return 0; //No need to send.
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x30A3;
- WFIFOL(inter_fd,2) = clan_id;
- WFIFOSET(inter_fd,6);
-
- return 1;
- }
- int intif_parse_clan_onlinecount( int fd ){
- struct clan* clan = clan_search(RFIFOL(fd,2));
- if( clan == NULL ){
- return 0;
- }
- clan->connect_member = RFIFOW(fd,6);
- clif_clan_onlinecount(clan);
- return 1;
- }
- //-----------------------------------------------------------------
- /**
- * Communication from the inter server, Main entry point interface (inter<=>map)
- * @param fd : inter-serv link
- * @return
- * 0 (unknow packet).
- * 1 sucess (no error)
- * 2 invalid length of packet (not enough data yet)
- */
- int intif_parse(int fd)
- {
- int packet_len, cmd;
- cmd = RFIFOW(fd,0);
- // Verify ID of the packet
- if(cmd<0x3800 || cmd>=0x3800+ARRAYLENGTH(packet_len_table) ||
- packet_len_table[cmd-0x3800]==0){
- return 0;
- }
- // Check the length of the packet
- packet_len = packet_len_table[cmd-0x3800];
- if(packet_len==-1){
- if(RFIFOREST(fd)<4)
- return 2;
- packet_len = RFIFOW(fd,2);
- }
- if((int)RFIFOREST(fd)<packet_len){
- return 2;
- }
- // Processing branch
- switch(cmd){
- case 0x3800:
- if (RFIFOL(fd,4) == 0xFF000000) //Normal announce.
- clif_broadcast(NULL, RFIFOCP(fd,16), packet_len-16, BC_DEFAULT, ALL_CLIENT);
- else //Color announce.
- clif_broadcast2(NULL, RFIFOCP(fd,16), packet_len-16, RFIFOL(fd,4), RFIFOW(fd,8), RFIFOW(fd,10), RFIFOW(fd,12), RFIFOW(fd,14), ALL_CLIENT);
- break;
- case 0x3801: intif_parse_WisMessage(fd); break;
- case 0x3802: intif_parse_WisEnd(fd); break;
- case 0x3803: mapif_parse_WisToGM(fd); break;
- case 0x3804: intif_parse_Registers(fd); break;
- case 0x3806: intif_parse_ChangeNameOk(fd); break;
- case 0x3807: intif_parse_MessageToFD(fd); break;
- case 0x3808: intif_parse_accinfo_ack(fd); break;
- case 0x3809: intif_parse_broadcast_obtain_special_item(fd); break;
- case 0x3818: intif_parse_LoadGuildStorage(fd); break;
- case 0x3819: intif_parse_SaveGuildStorage(fd); break;
- case 0x3820: intif_parse_PartyCreated(fd); break;
- case 0x3821: intif_parse_PartyInfo(fd); break;
- case 0x3822: intif_parse_PartyMemberAdded(fd); break;
- case 0x3823: intif_parse_PartyOptionChanged(fd); break;
- case 0x3824: intif_parse_PartyMemberWithdraw(fd); break;
- case 0x3825: intif_parse_PartyMove(fd); break;
- case 0x3826: intif_parse_PartyBroken(fd); break;
- case 0x3827: intif_parse_PartyMessage(fd); break;
- case 0x3830: intif_parse_GuildCreated(fd); break;
- case 0x3831: intif_parse_GuildInfo(fd); break;
- case 0x3832: intif_parse_GuildMemberAdded(fd); break;
- case 0x3834: intif_parse_GuildMemberWithdraw(fd); break;
- case 0x3835: intif_parse_GuildMemberInfoShort(fd); break;
- case 0x3836: intif_parse_GuildBroken(fd); break;
- case 0x3837: intif_parse_GuildMessage(fd); break;
- case 0x3839: intif_parse_GuildBasicInfoChanged(fd); break;
- case 0x383a: intif_parse_GuildMemberInfoChanged(fd); break;
- case 0x383b: intif_parse_GuildPosition(fd); break;
- case 0x383c: intif_parse_GuildSkillUp(fd); break;
- case 0x383d: intif_parse_GuildAlliance(fd); break;
- case 0x383e: intif_parse_GuildNotice(fd); break;
- case 0x383f: intif_parse_GuildEmblem(fd); break;
- case 0x3840: intif_parse_GuildCastleDataLoad(fd); break;
- case 0x3841: intif_parse_GuildEmblemVersionChanged(fd); break;
- case 0x3843: intif_parse_GuildMasterChanged(fd); break;
- // Mail System
- case 0x3848: intif_parse_Mail_inboxreceived(fd); break;
- case 0x3849: intif_parse_Mail_new(fd); break;
- case 0x384a: intif_parse_Mail_getattach(fd); break;
- case 0x384b: intif_parse_Mail_delete(fd); break;
- case 0x384c: intif_parse_Mail_return(fd); break;
- case 0x384d: intif_parse_Mail_send(fd); break;
- case 0x384e: intif_parse_Mail_receiver(fd); break;
- // Auction System
- case 0x3850: intif_parse_Auction_results(fd); break;
- case 0x3851: intif_parse_Auction_register(fd); break;
- case 0x3852: intif_parse_Auction_cancel(fd); break;
- case 0x3853: intif_parse_Auction_close(fd); break;
- case 0x3854: intif_parse_Auction_message(fd); break;
- case 0x3855: intif_parse_Auction_bid(fd); break;
- //Bound items
- #ifdef BOUND_ITEMS
- case 0x3856: intif_parse_itembound_ack(fd); break;
- case 0x3857: intif_parse_itembound_store2gstorage(fd); break;
- #endif
- //Quest system
- case 0x3860: intif_parse_questlog(fd); break;
- case 0x3861: intif_parse_questsave(fd); break;
- //Achievement system
- case 0x3862: intif_parse_achievements(fd); break;
- case 0x3863: intif_parse_achievementsave(fd); break;
- case 0x3864: intif_parse_achievementreward(fd); break;
- // Mercenary System
- case 0x3870: intif_parse_mercenary_received(fd); break;
- case 0x3871: intif_parse_mercenary_deleted(fd); break;
- case 0x3872: intif_parse_mercenary_saved(fd); break;
- // Elemental System
- case 0x387c: intif_parse_elemental_received(fd); break;
- case 0x387d: intif_parse_elemental_deleted(fd); break;
- case 0x387e: intif_parse_elemental_saved(fd); break;
- // Pet System
- case 0x3880: intif_parse_CreatePet(fd); break;
- case 0x3881: intif_parse_RecvPetData(fd); break;
- case 0x3882: intif_parse_SavePetOk(fd); break;
- case 0x3883: intif_parse_DeletePetOk(fd); break;
- // Storage
- case 0x388a: intif_parse_StorageReceived(fd); break;
- case 0x388b: intif_parse_StorageSaved(fd); break;
- case 0x388c: intif_parse_StorageInfo_recv(fd); break;
- // Homunculus System
- case 0x3890: intif_parse_CreateHomunculus(fd); break;
- case 0x3891: intif_parse_RecvHomunculusData(fd); break;
- case 0x3892: intif_parse_SaveHomunculusOk(fd); break;
- case 0x3893: intif_parse_DeleteHomunculusOk(fd); break;
- // Clan system
- case 0x38A0: intif_parse_clans(fd); break;
- case 0x38A1: intif_parse_clan_message(fd); break;
- case 0x38A2: intif_parse_clan_onlinecount(fd); break;
- default:
- ShowError("intif_parse : unknown packet %d %x\n",fd,RFIFOW(fd,0));
- return 0;
- }
- // Skip packet
- RFIFOSKIP(fd,packet_len);
- return 1;
- }
|