clif.cpp 730 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // Copyright (c) Hercules Dev Team - Licensed under GNU GPL
  3. // For more information, see LICENCE in the main folder
  4. #include "clif.hpp"
  5. #include <unordered_set>
  6. #include <cstdarg>
  7. #include <cstdio>
  8. #include <cstdlib>
  9. #include <cstring>
  10. #include <ctime>
  11. #include <common/cbasetypes.hpp>
  12. #include <common/conf.hpp>
  13. #include <common/ers.hpp>
  14. #include <common/grfio.hpp>
  15. #include <common/malloc.hpp>
  16. #include <common/nullpo.hpp>
  17. #include <common/random.hpp>
  18. #include <common/showmsg.hpp>
  19. #include <common/socket.hpp>
  20. #include <common/strlib.hpp>
  21. #include <common/timer.hpp>
  22. #include <common/utilities.hpp>
  23. #include <common/utils.hpp>
  24. #include "achievement.hpp"
  25. #include "atcommand.hpp"
  26. #include "battle.hpp"
  27. #include "battleground.hpp"
  28. #include "cashshop.hpp"
  29. #include "channel.hpp"
  30. #include "chat.hpp"
  31. #include "chrif.hpp"
  32. #include "clan.hpp"
  33. #include "clif.hpp"
  34. #include "elemental.hpp"
  35. #include "guild.hpp"
  36. #include "homunculus.hpp"
  37. #include "instance.hpp"
  38. #include "intif.hpp"
  39. #include "itemdb.hpp"
  40. #include "log.hpp"
  41. #include "mail.hpp"
  42. #include "map.hpp"
  43. #include "mercenary.hpp"
  44. #include "mob.hpp"
  45. #include "npc.hpp"
  46. #include "party.hpp"
  47. #include "pc.hpp"
  48. #include "pc_groups.hpp"
  49. #include "pet.hpp"
  50. #include "quest.hpp"
  51. #include "script.hpp"
  52. #include "skill.hpp"
  53. #include "status.hpp"
  54. #include "storage.hpp"
  55. #include "trade.hpp"
  56. #include "unit.hpp"
  57. #include "vending.hpp"
  58. using namespace rathena;
  59. static inline uint32 client_tick( t_tick tick ){
  60. return (uint32)tick;
  61. }
  62. #if PACKETVER >= 20170830
  63. static inline int64 client_exp(t_exp exp) {
  64. return (int64)u64min(exp, MAX_EXP);
  65. }
  66. #else
  67. static inline int32 client_exp(t_exp exp) {
  68. return (int32)u64min(exp, MAX_EXP);
  69. }
  70. #endif
  71. /* for clif_clearunit_delayed */
  72. static struct eri *delay_clearunit_ers;
  73. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  74. unsigned long color_table[COLOR_MAX];
  75. #include "clif_obfuscation.hpp"
  76. static bool clif_session_isValid(map_session_data *sd);
  77. static void clif_loadConfirm( map_session_data *sd );
  78. #if PACKETVER >= 20150513
  79. enum mail_type {
  80. MAIL_TYPE_TEXT = 0x0,
  81. MAIL_TYPE_ZENY = 0x2,
  82. MAIL_TYPE_ITEM = 0x4,
  83. MAIL_TYPE_NPC = 0x8
  84. };
  85. #endif
  86. enum e_inventory_type{
  87. INVTYPE_INVENTORY = 0,
  88. INVTYPE_CART = 1,
  89. INVTYPE_STORAGE = 2,
  90. INVTYPE_GUILD_STORAGE = 3,
  91. };
  92. /** Converts item type to display it on client if necessary.
  93. * @param nameid: Item ID
  94. * @return item type. For IT_PETEGG will be displayed as IT_ARMOR. If Shadow Weapon of IT_SHADOWGEAR as IT_WEAPON and else as IT_ARMOR
  95. */
  96. static inline int itemtype(t_itemid nameid) {
  97. struct item_data* id = itemdb_search(nameid); //Use itemdb_search, so non-existance item will use dummy data and won't crash the server. bugreport:8468
  98. int type = id->type;
  99. if( type == IT_SHADOWGEAR ) {
  100. if( id->equip&EQP_SHADOW_WEAPON )
  101. return IT_WEAPON;
  102. else
  103. return IT_ARMOR;
  104. }
  105. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  106. }
  107. // TODO: doc
  108. static inline uint16 client_index( uint16 server_index ){
  109. return server_index + 2;
  110. }
  111. static inline uint16 server_index( uint16 client_index ){
  112. return client_index - 2;
  113. }
  114. static inline uint16 client_storage_index( uint16 server_index ){
  115. return server_index + 1;
  116. }
  117. static inline uint16 server_storage_index( uint16 client_index ){
  118. return client_index - 1;
  119. }
  120. static inline uint32 disguised_bl_id( uint32 bl_id ){
  121. // Casting to prevent a compiler warning
  122. return -((int32)bl_id);
  123. }
  124. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  125. static inline uint32 client_nameid( t_itemid server_nameid ){
  126. t_itemid view = itemdb_viewid( server_nameid );
  127. if( view > 0 ){
  128. return view;
  129. }else{
  130. return server_nameid;
  131. }
  132. }
  133. #else
  134. static inline uint16 client_nameid( t_itemid server_nameid ){
  135. t_itemid view = itemdb_viewid( server_nameid );
  136. if( view > 0 ){
  137. if( view > UINT16_MAX ){
  138. return (uint16)UNKNOWN_ITEM_ID;
  139. }
  140. return (uint16)view;
  141. }else{
  142. if( server_nameid > UINT16_MAX ){
  143. return (uint16)UNKNOWN_ITEM_ID;
  144. }
  145. return (uint16)server_nameid;
  146. }
  147. }
  148. #endif
  149. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  150. p += pos;
  151. p[0] = (uint8)(x>>2);
  152. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  153. p[2] = (uint8)((y<<4) | (dir&0xf));
  154. }
  155. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  156. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  157. p += pos;
  158. p[0] = (uint8)(x0>>2);
  159. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  160. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  161. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  162. p[4] = (uint8)y1;
  163. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  164. }
  165. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  166. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  167. }
  168. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  169. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  170. }
  171. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  172. p += pos;
  173. if( x ) {
  174. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  175. }
  176. if( y ) {
  177. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  178. }
  179. if( dir ) {
  180. dir[0] = ( p[2] & 0x0f );
  181. }
  182. }
  183. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  184. p += pos;
  185. if( x0 ) {
  186. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  187. }
  188. if( y0 ) {
  189. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  190. }
  191. if( x1 ) {
  192. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  193. }
  194. if( y1 ) {
  195. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  196. }
  197. if( sx0 ) {
  198. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  199. }
  200. if( sy0 ) {
  201. sy0[0] = ( p[5] & 0x0f ) >> 0;
  202. }
  203. }
  204. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  205. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  206. }
  207. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  208. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  209. }
  210. //To idenfity disguised characters.
  211. static inline bool disguised(struct block_list* bl) {
  212. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  213. }
  214. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  215. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  216. if( len > max )
  217. len = max;
  218. mes[len-1] = '\0';
  219. return len;
  220. }
  221. static char map_ip_str[128];
  222. static uint32 map_ip;
  223. static uint32 bind_ip = INADDR_ANY;
  224. static uint16 map_port = 5121;
  225. static bool clif_ally_only = false;
  226. int map_fd;
  227. static int clif_parse (int fd);
  228. /*==========================================
  229. * Ip setting of map-server
  230. *------------------------------------------*/
  231. int clif_setip(const char* ip) {
  232. char ip_str[16];
  233. map_ip = host2ip(ip);
  234. if (!map_ip) {
  235. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  236. return 0;
  237. }
  238. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  239. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  240. return 1;
  241. }
  242. void clif_setbindip(const char* ip)
  243. {
  244. bind_ip = host2ip(ip);
  245. if (bind_ip) {
  246. char ip_str[16];
  247. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  248. } else {
  249. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  250. }
  251. }
  252. /*==========================================
  253. * Sets map port to 'port'
  254. * is run from map.cpp upon loading map server configuration
  255. *------------------------------------------*/
  256. void clif_setport(uint16 port)
  257. {
  258. map_port = port;
  259. }
  260. /*==========================================
  261. * Returns map server IP
  262. *------------------------------------------*/
  263. uint32 clif_getip(void)
  264. {
  265. return map_ip;
  266. }
  267. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  268. uint32 clif_refresh_ip(void)
  269. {
  270. uint32 new_ip;
  271. new_ip = host2ip(map_ip_str);
  272. if (new_ip && new_ip != map_ip) {
  273. map_ip = new_ip;
  274. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  275. return map_ip;
  276. }
  277. return 0;
  278. }
  279. /*==========================================
  280. * Returns map port which is set by clif_setport()
  281. *------------------------------------------*/
  282. uint16 clif_getport(void)
  283. {
  284. return map_port;
  285. }
  286. #if PACKETVER >= 20071106
  287. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  288. switch (bl->type) {
  289. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  290. case BL_ITEM: return 0x2; //ITEM_TYPE
  291. case BL_SKILL: return 0x3; //SKILL_TYPE
  292. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  293. case BL_MOB:
  294. if( pcdb_checkid( status_get_viewdata( bl )->class_ ) ){
  295. return 0x0; //PC_TYPE
  296. }else{
  297. switch( ( (mob_data*)bl )->special_state.ai ){
  298. case AI_ABR:
  299. return 0xd; //NPC_ABR_TYPE
  300. case AI_BIONIC:
  301. return 0xe; //NPC_BIONIC_TYPE
  302. default:
  303. return 0x5; //NPC_MOB_TYPE
  304. }
  305. }
  306. case BL_NPC:
  307. // From 2017-07-26 on NPC type units can also use player sprites.
  308. // There is one exception and this is if they are walking.
  309. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  310. #if PACKETVER >= 20170726
  311. if (pcdb_checkid( status_get_viewdata( bl )->class_ ) && walking)
  312. return 0x0;
  313. else if (mobdb_checkid( status_get_viewdata( bl )->class_ )) // FIXME: categorize NPCs able to walk
  314. return 0xC;
  315. else
  316. return 0x6;
  317. #else
  318. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  319. #endif
  320. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  321. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  322. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  323. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  324. default: return 0x1; //NPC_TYPE
  325. }
  326. }
  327. #endif
  328. static bool clif_session_isValid(map_session_data *sd) {
  329. return ( sd != nullptr && session_isActive(sd->fd) );
  330. }
  331. /*==========================================
  332. * sub process of clif_send
  333. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  334. * In order to send area-wise packets, such as:
  335. * - AREA : everyone nearby your area
  336. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  337. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  338. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  339. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  340. *------------------------------------------*/
  341. static int clif_send_sub(struct block_list *bl, va_list ap)
  342. {
  343. struct block_list *src_bl;
  344. map_session_data *sd;
  345. unsigned char *buf;
  346. int len, type, fd;
  347. nullpo_ret(bl);
  348. nullpo_ret(sd = (map_session_data *)bl);
  349. // Don't send to disconnected clients.
  350. if( !session_isActive( fd = sd->fd ) ){
  351. return 0;
  352. }
  353. buf = va_arg(ap,unsigned char*);
  354. len = va_arg(ap,int);
  355. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  356. type = va_arg(ap,int);
  357. switch(type) {
  358. case AREA_WOS:
  359. if (bl == src_bl)
  360. return 0;
  361. break;
  362. case AREA_WOC:
  363. if (sd->chatID || bl == src_bl)
  364. return 0;
  365. break;
  366. case AREA_WOSC:
  367. {
  368. if(src_bl->type == BL_PC) {
  369. map_session_data *ssd = (map_session_data *)src_bl;
  370. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  371. return 0;
  372. }
  373. else if(src_bl->type == BL_NPC) {
  374. struct npc_data *nd = (struct npc_data *)src_bl;
  375. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  376. return 0;
  377. }
  378. }
  379. break;
  380. }
  381. if( src_bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)src_bl ), *sd ) ){
  382. // Do not send anything
  383. return 0;
  384. }
  385. /* unless visible, hold it here */
  386. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  387. !sd->sc.getSCE(SC_INTRAVISION) && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  388. return 0;
  389. WFIFOHEAD(fd, len);
  390. if (WFIFOP(fd,0) == buf) {
  391. ShowError("WARNING: Invalid use of clif_send function\n");
  392. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  393. ShowError(" Please correct your code.\n");
  394. // don't send to not move the pointer of the packet for next sessions in the loop
  395. //WFIFOSET(fd,0);//## TODO is this ok?
  396. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  397. return 0;
  398. }
  399. memcpy(WFIFOP(fd,0), buf, len);
  400. WFIFOSET(fd,len);
  401. return 0;
  402. }
  403. /*==========================================
  404. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  405. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  406. *------------------------------------------*/
  407. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  408. {
  409. int i;
  410. map_session_data *sd, *tsd;
  411. struct party_data *p = NULL;
  412. std::shared_ptr<s_battleground_data> bg;
  413. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  414. struct s_mapiterator* iter;
  415. if( type != ALL_CLIENT )
  416. nullpo_ret(bl);
  417. sd = BL_CAST(BL_PC, bl);
  418. switch(type) {
  419. case ALL_CLIENT: //All player clients.
  420. iter = mapit_getallusers();
  421. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  422. if( session_isActive( fd = tsd->fd ) ){
  423. WFIFOHEAD( fd, len );
  424. memcpy( WFIFOP( fd, 0 ), buf, len );
  425. WFIFOSET( fd, len );
  426. }
  427. }
  428. mapit_free(iter);
  429. break;
  430. case ALL_SAMEMAP: //All players on the same map
  431. iter = mapit_getallusers();
  432. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  433. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  434. WFIFOHEAD( fd, len );
  435. memcpy( WFIFOP( fd, 0 ), buf, len );
  436. WFIFOSET( fd, len );
  437. }
  438. }
  439. mapit_free(iter);
  440. break;
  441. case AREA:
  442. case AREA_WOSC:
  443. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  444. clif_send (buf, len, bl, SELF);
  445. [[fallthrough]];
  446. case AREA_WOC:
  447. case AREA_WOS:
  448. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  449. BL_PC, buf, len, bl, type);
  450. break;
  451. case AREA_CHAT_WOC:
  452. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  453. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  454. break;
  455. case CHAT:
  456. case CHAT_WOS:
  457. {
  458. struct chat_data *cd;
  459. if (sd) {
  460. cd = (struct chat_data*)map_id2bl(sd->chatID);
  461. } else if (bl->type == BL_CHAT) {
  462. cd = (struct chat_data*)bl;
  463. } else break;
  464. if (cd == NULL)
  465. break;
  466. for(i = 0; i < cd->users; i++) {
  467. if (type == CHAT_WOS && cd->usersd[i] == sd)
  468. continue;
  469. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  470. WFIFOHEAD(fd,len);
  471. memcpy(WFIFOP(fd,0), buf, len);
  472. WFIFOSET(fd,len);
  473. }
  474. }
  475. }
  476. break;
  477. case PARTY_AREA:
  478. case PARTY_AREA_WOS:
  479. x0 = bl->x - AREA_SIZE;
  480. y0 = bl->y - AREA_SIZE;
  481. x1 = bl->x + AREA_SIZE;
  482. y1 = bl->y + AREA_SIZE;
  483. [[fallthrough]];
  484. case PARTY:
  485. case PARTY_WOS:
  486. case PARTY_SAMEMAP:
  487. case PARTY_SAMEMAP_WOS:
  488. if (sd && sd->status.party_id)
  489. p = party_search(sd->status.party_id);
  490. if (p) {
  491. for(i=0;i<MAX_PARTY;i++){
  492. if( (sd = p->data[i].sd) == NULL )
  493. continue;
  494. if( !session_isActive( fd = sd->fd ) )
  495. continue;
  496. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  497. continue;
  498. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  499. continue;
  500. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  501. continue;
  502. WFIFOHEAD(fd, len);
  503. memcpy(WFIFOP(fd, 0), buf, len);
  504. WFIFOSET(fd, len);
  505. }
  506. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  507. break;
  508. iter = mapit_getallusers();
  509. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  510. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  511. WFIFOHEAD( fd, len );
  512. memcpy( WFIFOP( fd, 0 ), buf, len );
  513. WFIFOSET( tsd->fd, len );
  514. }
  515. }
  516. mapit_free(iter);
  517. }
  518. break;
  519. case DUEL:
  520. case DUEL_WOS:
  521. if (!sd || !sd->duel_group) break; //Invalid usage.
  522. iter = mapit_getallusers();
  523. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  524. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  525. continue;
  526. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  527. WFIFOHEAD( fd, len );
  528. memcpy( WFIFOP( fd, 0 ), buf, len );
  529. WFIFOSET( fd, len );
  530. }
  531. }
  532. mapit_free(iter);
  533. break;
  534. case SELF:
  535. if( clif_session_isValid(sd) ){
  536. fd = sd->fd;
  537. WFIFOHEAD(fd,len);
  538. memcpy(WFIFOP(fd,0), buf, len);
  539. WFIFOSET(fd,len);
  540. }
  541. break;
  542. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  543. case GUILD_AREA:
  544. case GUILD_AREA_WOS:
  545. x0 = bl->x - AREA_SIZE;
  546. y0 = bl->y - AREA_SIZE;
  547. x1 = bl->x + AREA_SIZE;
  548. y1 = bl->y + AREA_SIZE;
  549. [[fallthrough]];
  550. case GUILD_SAMEMAP:
  551. case GUILD_SAMEMAP_WOS:
  552. case GUILD:
  553. case GUILD_WOS:
  554. case GUILD_NOBG: {
  555. if (!sd || !sd->status.guild_id || !sd->guild)
  556. break;
  557. const auto &g = sd->guild->guild;
  558. for(i = 0; i < g.max_member; i++) {
  559. if( (sd = g.member[i].sd) != nullptr ){
  560. if( !session_isActive( fd = sd->fd ) )
  561. continue;
  562. if( type == GUILD_NOBG && sd->bg_id )
  563. continue;
  564. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  565. continue;
  566. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  567. continue;
  568. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  569. continue;
  570. WFIFOHEAD(fd,len);
  571. memcpy(WFIFOP(fd,0), buf, len);
  572. WFIFOSET(fd,len);
  573. }
  574. }
  575. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  576. break;
  577. iter = mapit_getallusers();
  578. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  579. if( tsd->guildspy == g.guild_id && session_isActive( fd = tsd->fd ) ){
  580. WFIFOHEAD( fd, len );
  581. memcpy( WFIFOP( fd, 0 ), buf, len );
  582. WFIFOSET( fd, len );
  583. }
  584. }
  585. mapit_free(iter);
  586. break;
  587. }
  588. case BG_AREA:
  589. case BG_AREA_WOS:
  590. x0 = bl->x - AREA_SIZE;
  591. y0 = bl->y - AREA_SIZE;
  592. x1 = bl->x + AREA_SIZE;
  593. y1 = bl->y + AREA_SIZE;
  594. [[fallthrough]];
  595. case BG_SAMEMAP:
  596. case BG_SAMEMAP_WOS:
  597. case BG:
  598. case BG_WOS:
  599. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  600. {
  601. for (const auto &member : bg->members) {
  602. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  603. continue;
  604. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  605. continue;
  606. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  607. continue;
  608. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  609. continue;
  610. WFIFOHEAD(fd,len);
  611. memcpy(WFIFOP(fd,0), buf, len);
  612. WFIFOSET(fd,len);
  613. }
  614. }
  615. break;
  616. case CLAN:
  617. if( sd && sd->clan ){
  618. struct clan* clan = sd->clan;
  619. for( i = 0; i < clan->max_member; i++ ){
  620. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  621. continue;
  622. }
  623. WFIFOHEAD(fd,len);
  624. memcpy(WFIFOP(fd,0), buf, len);
  625. WFIFOSET(fd,len);
  626. }
  627. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  628. break;
  629. iter = mapit_getallusers();
  630. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  631. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  632. WFIFOHEAD(fd, len);
  633. memcpy(WFIFOP(fd, 0), buf, len);
  634. WFIFOSET(fd, len);
  635. }
  636. }
  637. mapit_free(iter);
  638. }
  639. break;
  640. default:
  641. ShowError("clif_send: Unrecognized type %d\n",type);
  642. return -1;
  643. }
  644. return 0;
  645. }
  646. /// Notifies the client, that it's connection attempt was accepted.
  647. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  648. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  649. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  650. void clif_authok(map_session_data *sd)
  651. {
  652. #if PACKETVER < 20080102
  653. const int cmd = 0x73;
  654. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  655. const int cmd = 0x2eb;
  656. #else
  657. const int cmd = 0xa18;
  658. #endif
  659. int fd = sd->fd;
  660. WFIFOHEAD(fd,packet_len(cmd));
  661. WFIFOW(fd, 0) = cmd;
  662. WFIFOL(fd, 2) = client_tick(gettick());
  663. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  664. WFIFOB(fd, 9) = 5; // ignored
  665. WFIFOB(fd,10) = 5; // ignored
  666. #if PACKETVER >= 20080102
  667. WFIFOW(fd,11) = sd->status.font;
  668. #endif
  669. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  670. WFIFOB(fd,13) = sd->status.sex;
  671. #endif
  672. WFIFOSET(fd,packet_len(cmd));
  673. }
  674. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  675. /// 0074 <error code>.B
  676. /// error code:
  677. /// 0 = client type mismatch
  678. /// 1 = ID mismatch
  679. /// 2 = mobile - out of available time
  680. /// 3 = mobile - already logged in
  681. /// 4 = mobile - waiting state
  682. void clif_authrefuse(int fd, uint8 error_code)
  683. {
  684. WFIFOHEAD(fd,packet_len(0x74));
  685. WFIFOW(fd,0) = 0x74;
  686. WFIFOB(fd,2) = error_code;
  687. WFIFOSET(fd,packet_len(0x74));
  688. }
  689. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  690. /// 0081 <error code>.B
  691. /// error code:
  692. /// 0 = BAN_UNFAIR
  693. /// 1 = server closed -> MsgStringTable[4]
  694. /// 2 = ID already logged in -> MsgStringTable[5]
  695. /// 3 = timeout/too much lag -> MsgStringTable[241]
  696. /// 4 = server full -> MsgStringTable[264]
  697. /// 5 = underaged -> MsgStringTable[305]
  698. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  699. /// 9 = too many connections from this ip -> MsgStringTable[529]
  700. /// 10 = out of available time paid for -> MsgStringTable[530]
  701. /// 11 = BAN_PAY_SUSPEND
  702. /// 12 = BAN_PAY_CHANGE
  703. /// 13 = BAN_PAY_WRONGIP
  704. /// 14 = BAN_PAY_PNGAMEROOM
  705. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  706. /// 16 = BAN_JAPAN_REFUSE1
  707. /// 17 = BAN_JAPAN_REFUSE2
  708. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  709. /// 100 = BAN_PC_IP_UNFAIR
  710. /// 101 = BAN_PC_IP_COUNT_ALL
  711. /// 102 = BAN_PC_IP_COUNT
  712. /// 103 = BAN_GRAVITY_MEM_AGREE
  713. /// 104 = BAN_GAME_MEM_AGREE
  714. /// 105 = BAN_HAN_VALID
  715. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  716. /// 107 = BAN_OVER_CHARACTER_LIST
  717. /// 108 = BAN_IP_BLOCK
  718. /// 109 = BAN_INVALID_PWD_CNT
  719. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  720. /// ? = disconnected -> MsgStringTable[3]
  721. void clif_authfail_fd(int fd, int type)
  722. {
  723. if (!session_isValid(fd) || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  724. return;
  725. WFIFOHEAD(fd, packet_len(0x81));
  726. WFIFOW(fd,0) = 0x81;
  727. WFIFOB(fd,2) = type;
  728. WFIFOSET(fd,packet_len(0x81));
  729. set_eof(fd);
  730. }
  731. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  732. /// 00b3 <type>.B
  733. /// type:
  734. /// 1 = disconnect, char-select
  735. /// ? = nothing
  736. void clif_charselectok(int id, uint8 ok)
  737. {
  738. map_session_data* sd;
  739. int fd;
  740. if ((sd = map_id2sd(id)) == NULL || !session_isValid(sd->fd))
  741. return;
  742. fd = sd->fd;
  743. WFIFOHEAD(fd,packet_len(0xb3));
  744. WFIFOW(fd,0) = 0xb3;
  745. WFIFOB(fd,2) = ok;
  746. WFIFOSET(fd,packet_len(0xb3));
  747. }
  748. /// Makes an item appear on the ground.
  749. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  750. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  751. /// 0ADD <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W <show drop effect>.B <drop effect mode>.W (ZC_ITEM_FALL_ENTRY5)
  752. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  753. nullpo_retv(fitem);
  754. if( fitem->item.nameid == 0 ){
  755. return;
  756. }
  757. struct packet_dropflooritem p;
  758. p.PacketType = dropflooritemType;
  759. p.ITAID = fitem->bl.id;
  760. p.ITID = client_nameid( fitem->item.nameid );
  761. #if PACKETVER >= 20130000 /* not sure date */
  762. p.type = itemtype( fitem->item.nameid );
  763. #endif
  764. p.IsIdentified = fitem->item.identify ? 1 : 0;
  765. p.xPos = fitem->bl.x;
  766. p.yPos = fitem->bl.y;
  767. p.subX = fitem->subx;
  768. p.subY = fitem->suby;
  769. p.count = fitem->item.amount;
  770. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  771. if( canShowEffect ){
  772. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  773. if( dropEffect > 0 ){
  774. p.showdropeffect = 1;
  775. p.dropeffectmode = dropEffect - 1;
  776. }else if (battle_config.rndopt_drop_pillar != 0){
  777. uint8 optionCount = 0;
  778. for (uint8 i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  779. if (fitem->item.option[i].id != 0) {
  780. optionCount++;
  781. }
  782. }
  783. if (optionCount > 0) {
  784. p.showdropeffect = 1;
  785. if (optionCount == 1)
  786. p.dropeffectmode = DROPEFFECT_BLUE_PILLAR - 1;
  787. else if (optionCount == 2)
  788. p.dropeffectmode = DROPEFFECT_YELLOW_PILLAR - 1;
  789. else
  790. p.dropeffectmode = DROPEFFECT_PURPLE_PILLAR - 1;
  791. } else {
  792. p.showdropeffect = 0;
  793. p.dropeffectmode = DROPEFFECT_NONE;
  794. }
  795. } else {
  796. p.showdropeffect = 0;
  797. p.dropeffectmode = DROPEFFECT_NONE;
  798. }
  799. }else{
  800. p.showdropeffect = 0;
  801. p.dropeffectmode = DROPEFFECT_NONE;
  802. }
  803. #endif
  804. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  805. }
  806. /// Makes an item disappear from the ground.
  807. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  808. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  809. {
  810. unsigned char buf[16];
  811. nullpo_retv(fitem);
  812. WBUFW(buf,0) = 0xa1;
  813. WBUFL(buf,2) = fitem->bl.id;
  814. if ( !session_isActive( fd ) ){
  815. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  816. } else {
  817. WFIFOHEAD(fd,packet_len(0xa1));
  818. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  819. WFIFOSET(fd,packet_len(0xa1));
  820. }
  821. }
  822. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  823. /// 0080 <id>.L <type>.B
  824. /// type:
  825. /// 0 = out of sight
  826. /// 1 = died
  827. /// 2 = logged out
  828. /// 3 = teleport
  829. /// 4 = trickdead
  830. void clif_clearunit_single(int id, clr_type type, int fd)
  831. {
  832. WFIFOHEAD(fd, packet_len(0x80));
  833. WFIFOW(fd,0) = 0x80;
  834. WFIFOL(fd,2) = id;
  835. WFIFOB(fd,6) = type;
  836. WFIFOSET(fd, packet_len(0x80));
  837. }
  838. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  839. /// 0080 <id>.L <type>.B
  840. /// type:
  841. /// 0 = out of sight
  842. /// 1 = died
  843. /// 2 = logged out
  844. /// 3 = teleport
  845. /// 4 = trickdead
  846. void clif_clearunit_area(struct block_list* bl, clr_type type)
  847. {
  848. unsigned char buf[8];
  849. nullpo_retv(bl);
  850. WBUFW(buf,0) = 0x80;
  851. WBUFL(buf,2) = bl->id;
  852. WBUFB(buf,6) = type;
  853. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  854. if(disguised(bl)) {
  855. WBUFL(buf,2) = disguised_bl_id( bl->id );
  856. clif_send(buf, packet_len(0x80), bl, SELF);
  857. }
  858. }
  859. /// Used to make monsters with player-sprites disappear after dying
  860. /// like normal monsters, because the client does not remove those
  861. /// automatically.
  862. static TIMER_FUNC(clif_clearunit_delayed_sub){
  863. struct block_list *bl = (struct block_list *)data;
  864. clif_clearunit_area(bl, (clr_type) id);
  865. ers_free(delay_clearunit_ers,bl);
  866. return 0;
  867. }
  868. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  869. {
  870. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  871. tbl->next = nullptr;
  872. tbl->prev = nullptr;
  873. tbl->id = bl->id;
  874. tbl->m = bl->m;
  875. tbl->x = bl->x;
  876. tbl->y = bl->y;
  877. tbl->type = BL_NUL;
  878. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  879. }
  880. void clif_get_weapon_view(map_session_data* sd, t_itemid *rhand, t_itemid *lhand)
  881. {
  882. if(sd->sc.option&OPTION_COSTUME)
  883. {
  884. *rhand = *lhand = 0;
  885. return;
  886. }
  887. #if PACKETVER < 4
  888. *rhand = sd->status.weapon;
  889. *lhand = sd->status.shield;
  890. #else
  891. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  892. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  893. {
  894. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  895. if (id->view_id > 0)
  896. *rhand = id->view_id;
  897. else
  898. *rhand = id->nameid;
  899. } else
  900. *rhand = 0;
  901. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  902. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  903. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  904. {
  905. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  906. if (id->view_id > 0)
  907. *lhand = id->view_id;
  908. else
  909. *lhand = id->nameid;
  910. } else
  911. *lhand = 0;
  912. #endif
  913. }
  914. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  915. static int clif_setlevel_sub(int lv) {
  916. if( lv < battle_config.max_lv ) {
  917. ;
  918. } else if( lv < battle_config.aura_lv ) {
  919. lv = battle_config.max_lv - 1;
  920. } else {
  921. lv = battle_config.max_lv;
  922. }
  923. return lv;
  924. }
  925. static int clif_setlevel(struct block_list* bl) {
  926. int lv = status_get_lv(bl);
  927. if( battle_config.client_limit_unit_lv&bl->type )
  928. return clif_setlevel_sub(lv);
  929. switch( bl->type ) {
  930. case BL_NPC:
  931. case BL_PET:
  932. // npcs and pets do not have level
  933. return 0;
  934. }
  935. return lv;
  936. }
  937. /*==========================================
  938. * Prepares 'unit standing/spawning' packet
  939. *------------------------------------------*/
  940. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  941. nullpo_retv( bl );
  942. map_session_data* sd = BL_CAST( BL_PC, bl );
  943. status_change* sc = status_get_sc( bl );
  944. struct view_data* vd = status_get_viewdata( bl );
  945. int g_id = status_get_guild_id( bl );
  946. #if PACKETVER < 20091103
  947. if( !pcdb_checkid( vd->class_ ) ){
  948. struct packet_idle_unit2 p;
  949. p.PacketType = idle_unit2Type;
  950. #if PACKETVER >= 20071106
  951. p.objecttype = clif_bl_type( bl, walking );
  952. #endif
  953. p.GID = bl->id;
  954. p.speed = status_get_speed( bl );
  955. p.bodyState = ( sc ) ? sc->opt1 : 0;
  956. p.healthState = ( sc ) ? sc->opt2 : 0;
  957. p.effectState = ( sc ) ? sc->option : 0;
  958. p.job = vd->class_;
  959. p.head = vd->hair_style;
  960. p.weapon = vd->weapon;
  961. p.accessory = vd->head_bottom;
  962. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  963. // The hell, why flags work like this?
  964. p.shield = status_get_emblem_id( bl );
  965. p.accessory2 = GetWord( g_id, 1 );
  966. p.accessory3 = GetWord( g_id, 0 );
  967. }else{
  968. p.shield = vd->shield;
  969. p.accessory2 = vd->head_top;
  970. p.accessory3 = vd->head_mid;
  971. }
  972. p.headpalette = vd->hair_color;
  973. p.bodypalette = vd->cloth_color;
  974. p.headDir = ( sd )? sd->head_dir : 0;
  975. p.GUID = g_id;
  976. p.GEmblemVer = status_get_emblem_id( bl );
  977. p.honor = ( sd ) ? sd->status.manner : 0;
  978. p.virtue = ( sc ) ? sc->opt3 : 0;
  979. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  980. p.sex = vd->sex;
  981. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  982. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  983. p.state = vd->dead_sit;
  984. p.clevel = clif_setlevel( bl );
  985. clif_send( &p, sizeof( p ), tbl, target );
  986. return;
  987. }
  988. #endif
  989. struct packet_idle_unit p;
  990. p.PacketType = idle_unitType;
  991. #if PACKETVER >= 20091103
  992. p.PacketLength = sizeof(p);
  993. p.objecttype = clif_bl_type( bl, walking );
  994. #endif
  995. #if PACKETVER >= 20131223
  996. p.AID = bl->id;
  997. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  998. #else
  999. p.GID = bl->id;
  1000. #endif
  1001. p.speed = status_get_speed(bl);
  1002. p.bodyState = (sc) ? sc->opt1 : 0;
  1003. p.healthState = (sc) ? sc->opt2 : 0;
  1004. // npc option changed?
  1005. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  1006. map_session_data* sd = (map_session_data*)tbl;
  1007. struct npc_data* nd = (struct npc_data*)bl;
  1008. int option = (sc) ? sc->option : 0;
  1009. if( !nd->vd.dead_sit ){
  1010. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  1011. option ^= OPTION_CLOAK;
  1012. }
  1013. }
  1014. p.effectState = option;
  1015. }else{
  1016. p.effectState = (sc) ? sc->option : 0;
  1017. }
  1018. p.job = vd->class_;
  1019. p.head = vd->hair_style;
  1020. p.weapon = vd->weapon;
  1021. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1022. p.shield = vd->shield;
  1023. #endif
  1024. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1025. // The hell, why flags work like this?
  1026. p.accessory = status_get_emblem_id( bl );
  1027. p.accessory2 = GetWord( g_id, 1 );
  1028. p.accessory3 = GetWord( g_id, 0 );
  1029. }else{
  1030. p.accessory = vd->head_bottom;
  1031. p.accessory2 = vd->head_top;
  1032. p.accessory3 = vd->head_mid;
  1033. }
  1034. p.headpalette = vd->hair_color;
  1035. p.bodypalette = vd->cloth_color;
  1036. p.headDir = (sd)? sd->head_dir : 0;
  1037. #if PACKETVER >= 20101124
  1038. p.robe = vd->robe;
  1039. #endif
  1040. p.GUID = g_id;
  1041. p.GEmblemVer = status_get_emblem_id( bl );
  1042. p.honor = (sd) ? sd->status.manner : 0;
  1043. p.virtue = (sc) ? sc->opt3 : 0;
  1044. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1045. p.sex = vd->sex;
  1046. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1047. p.xSize = p.ySize = (sd) ? 5 : 0;
  1048. p.state = vd->dead_sit;
  1049. p.clevel = clif_setlevel( bl );
  1050. #if PACKETVER >= 20080102
  1051. p.font = (sd) ? sd->status.font : 0;
  1052. #endif
  1053. #if PACKETVER >= 20120221
  1054. if( battle_config.monster_hp_bars_info && !map_getmapflag( bl->m, MF_HIDEMOBHPBAR ) && bl->type == BL_MOB && ( status_get_hp( bl ) < status_get_max_hp( bl ) ) ){
  1055. p.maxHP = status_get_max_hp(bl);
  1056. p.HP = status_get_hp(bl);
  1057. }else{
  1058. p.maxHP = -1;
  1059. p.HP = -1;
  1060. }
  1061. if( bl->type == BL_MOB ){
  1062. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1063. }else if( bl->type == BL_PET ){
  1064. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1065. }else{
  1066. p.isBoss = BOSSTYPE_NONE;
  1067. }
  1068. #endif
  1069. #if PACKETVER >= 20150513
  1070. p.body = vd->body_style;
  1071. #endif
  1072. /* Might be earlier, this is when the named item bug began */
  1073. #if PACKETVER >= 20131223
  1074. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1075. #endif
  1076. clif_send( &p, sizeof( p ), tbl, target );
  1077. // if disguised, send to self
  1078. if( disguised( bl ) ){
  1079. #if PACKETVER >= 20091103
  1080. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1081. #if PACKETVER >= 20131223
  1082. p.AID = disguised_bl_id( bl->id );
  1083. #else
  1084. p.GID = disguised_bl_id( bl->id );
  1085. #endif
  1086. #else
  1087. p.GID = disguised_bl_id( bl->id );
  1088. #endif
  1089. clif_send(&p, sizeof(p), bl, SELF);
  1090. }
  1091. }
  1092. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1093. nullpo_retv( bl );
  1094. map_session_data* sd = BL_CAST( BL_PC, bl );
  1095. status_change* sc = status_get_sc( bl );
  1096. struct view_data* vd = status_get_viewdata( bl );
  1097. int g_id = status_get_guild_id( bl );
  1098. #if PACKETVER < 20091103
  1099. if( !pcdb_checkid( vd->class_ ) ){
  1100. struct packet_spawn_unit2 p;
  1101. p.PacketType = spawn_unit2Type;
  1102. #if PACKETVER >= 20071106
  1103. p.objecttype = clif_bl_type( bl, false );
  1104. #endif
  1105. p.GID = bl->id;
  1106. p.speed = status_get_speed( bl );
  1107. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1108. p.healthState = ( sc ) ? sc->opt2 : 0;
  1109. p.effectState = ( sc ) ? sc->option : 0;
  1110. p.head = vd->hair_style;
  1111. p.weapon = vd->weapon;
  1112. p.accessory = vd->head_bottom;
  1113. p.job = vd->class_;
  1114. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1115. // The hell, why flags work like this?
  1116. p.shield = status_get_emblem_id( bl );
  1117. p.accessory2 = GetWord( g_id, 1 );
  1118. p.accessory3 = GetWord( g_id, 0 );
  1119. }else{
  1120. p.shield = vd->shield;
  1121. p.accessory2 = vd->head_top;
  1122. p.accessory3 = vd->head_mid;
  1123. }
  1124. p.headpalette = vd->hair_color;
  1125. p.bodypalette = vd->cloth_color;
  1126. p.headDir = ( sd ) ? sd->head_dir : 0;
  1127. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1128. p.sex = vd->sex;
  1129. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1130. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1131. clif_send( &p, sizeof( p ), bl, target );
  1132. return;
  1133. }
  1134. #endif
  1135. struct packet_spawn_unit p;
  1136. p.PacketType = spawn_unitType;
  1137. #if PACKETVER >= 20091103
  1138. p.PacketLength = sizeof(p);
  1139. p.objecttype = clif_bl_type( bl, false );
  1140. #endif
  1141. #if PACKETVER >= 20131223
  1142. p.AID = bl->id;
  1143. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1144. #else
  1145. p.GID = bl->id;
  1146. #endif
  1147. p.speed = status_get_speed( bl );
  1148. p.bodyState = (sc) ? sc->opt1 : 0;
  1149. p.healthState = (sc) ? sc->opt2 : 0;
  1150. p.effectState = (sc) ? sc->option : 0;
  1151. p.job = vd->class_;
  1152. p.head = vd->hair_style;
  1153. p.weapon = vd->weapon;
  1154. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1155. p.shield = vd->shield;
  1156. #endif
  1157. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1158. // The hell, why flags work like this?
  1159. p.accessory = status_get_emblem_id( bl );
  1160. p.accessory2 = GetWord( g_id, 1 );
  1161. p.accessory3 = GetWord( g_id, 0 );
  1162. }else{
  1163. p.accessory = vd->head_bottom;
  1164. p.accessory2 = vd->head_top;
  1165. p.accessory3 = vd->head_mid;
  1166. }
  1167. p.headpalette = vd->hair_color;
  1168. p.bodypalette = vd->cloth_color;
  1169. p.headDir = (sd)? sd->head_dir : 0;
  1170. #if PACKETVER >= 20101124
  1171. p.robe = vd->robe;
  1172. #endif
  1173. p.GUID = g_id;
  1174. p.GEmblemVer = status_get_emblem_id( bl );
  1175. p.honor = (sd) ? sd->status.manner : 0;
  1176. p.virtue = (sc) ? sc->opt3 : 0;
  1177. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1178. p.sex = vd->sex;
  1179. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1180. p.xSize = p.ySize = (sd) ? 5 : 0;
  1181. p.clevel = clif_setlevel( bl );
  1182. #if PACKETVER >= 20080102
  1183. p.font = (sd) ? sd->status.font : 0;
  1184. #endif
  1185. #if PACKETVER >= 20120221
  1186. if( battle_config.monster_hp_bars_info && bl->type == BL_MOB && !map_getmapflag( bl->m, MF_HIDEMOBHPBAR ) && ( status_get_hp( bl ) < status_get_max_hp( bl ) ) ){
  1187. p.maxHP = status_get_max_hp( bl );
  1188. p.HP = status_get_hp( bl );
  1189. }else{
  1190. p.maxHP = -1;
  1191. p.HP = -1;
  1192. }
  1193. if( bl->type == BL_MOB ){
  1194. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1195. }else if( bl->type == BL_PET ){
  1196. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1197. }else{
  1198. p.isBoss = BOSSTYPE_NONE;
  1199. }
  1200. #endif
  1201. #if PACKETVER >= 20150513
  1202. p.body = vd->body_style;
  1203. #endif
  1204. /* Might be earlier, this is when the named item bug began */
  1205. #if PACKETVER >= 20131223
  1206. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1207. #endif
  1208. if( disguised( bl ) ){
  1209. nullpo_retv( sd );
  1210. if( sd->status.class_ != sd->disguise ){
  1211. clif_send( &p, sizeof( p ), bl, target );
  1212. }
  1213. #if PACKETVER >= 20091103
  1214. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1215. #if PACKETVER >= 20131223
  1216. p.AID = disguised_bl_id( bl->id );
  1217. #else
  1218. p.GID = disguised_bl_id( bl->id );
  1219. #endif
  1220. #else
  1221. p.GID = disguised_bl_id( bl->id );
  1222. #endif
  1223. clif_send( &p, sizeof( p ), bl, SELF );
  1224. }else{
  1225. clif_send( &p, sizeof( p ), bl, target );
  1226. }
  1227. }
  1228. /*==========================================
  1229. * Prepares 'unit walking' packet
  1230. *------------------------------------------*/
  1231. static void clif_set_unit_walking( struct block_list *bl, map_session_data *tsd, struct unit_data *ud, enum send_target target ){
  1232. nullpo_retv( bl );
  1233. nullpo_retv( ud );
  1234. map_session_data* sd;
  1235. status_change* sc = status_get_sc( bl );
  1236. struct view_data* vd = status_get_viewdata( bl );
  1237. struct packet_unit_walking p;
  1238. int g_id = status_get_guild_id(bl);
  1239. sd = BL_CAST(BL_PC, bl);
  1240. p.PacketType = unit_walkingType;
  1241. #if PACKETVER >= 20091103
  1242. p.PacketLength = sizeof(p);
  1243. #endif
  1244. #if PACKETVER >= 20071106
  1245. p.objecttype = clif_bl_type( bl, true );
  1246. #endif
  1247. #if PACKETVER >= 20131223
  1248. p.AID = bl->id;
  1249. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1250. #else
  1251. p.GID = bl->id;
  1252. #endif
  1253. p.speed = status_get_speed(bl);
  1254. p.bodyState = (sc) ? sc->opt1 : 0;
  1255. p.healthState = (sc) ? sc->opt2 : 0;
  1256. p.effectState = (sc) ? sc->option : 0;
  1257. p.job = vd->class_;
  1258. p.head = vd->hair_style;
  1259. p.weapon = vd->weapon;
  1260. p.accessory = vd->head_bottom;
  1261. p.moveStartTime = client_tick(gettick());
  1262. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1263. p.shield = vd->shield;
  1264. #endif
  1265. p.accessory2 = vd->head_top;
  1266. p.accessory3 = vd->head_mid;
  1267. p.headpalette = vd->hair_color;
  1268. p.bodypalette = vd->cloth_color;
  1269. p.headDir = (sd) ? sd->head_dir : 0;
  1270. #if PACKETVER >= 20101124
  1271. p.robe = vd->robe;
  1272. #endif
  1273. p.GUID = g_id;
  1274. p.GEmblemVer = status_get_emblem_id(bl);
  1275. p.honor = (sd) ? sd->status.manner : 0;
  1276. p.virtue = (sc) ? sc->opt3 : 0;
  1277. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1278. p.sex = vd->sex;
  1279. WBUFPOS2( &p.MoveData[0], 0, bl->x, bl->y, ud->to_x, ud->to_y, 8, 8 );
  1280. p.xSize = p.ySize = (sd) ? 5 : 0;
  1281. p.clevel = clif_setlevel(bl);
  1282. #if PACKETVER >= 20080102
  1283. p.font = (sd) ? sd->status.font : 0;
  1284. #endif
  1285. #if PACKETVER >= 20120221
  1286. if( battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR) && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp( bl ) ) ){
  1287. p.maxHP = status_get_max_hp(bl);
  1288. p.HP = status_get_hp(bl);
  1289. } else {
  1290. p.maxHP = -1;
  1291. p.HP = -1;
  1292. }
  1293. if( bl->type == BL_MOB ){
  1294. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1295. }else if( bl->type == BL_PET ){
  1296. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1297. }else{
  1298. p.isBoss = BOSSTYPE_NONE;
  1299. }
  1300. #endif
  1301. #if PACKETVER >= 20150513
  1302. p.body = vd->body_style;
  1303. #endif
  1304. /* Might be earlier, this is when the named item bug began */
  1305. #if PACKETVER >= 20131223
  1306. safestrncpy(p.name, status_get_name(bl), NAME_LENGTH);
  1307. #endif
  1308. clif_send( &p, sizeof(p), tsd ? &tsd->bl : bl, target );
  1309. // if disguised, send the info to self
  1310. if( disguised( bl ) ){
  1311. #if PACKETVER >= 20091103
  1312. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1313. #if PACKETVER >= 20131223
  1314. p.AID = disguised_bl_id( bl->id );
  1315. #else
  1316. p.GID = disguised_bl_id( bl->id );
  1317. #endif
  1318. #else
  1319. p.GID = disguised_bl_id( bl->id );
  1320. #endif
  1321. clif_send(&p,sizeof(p),bl,SELF);
  1322. }
  1323. }
  1324. //Modifies the buffer for disguise characters and sends it to self.
  1325. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1326. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1327. {
  1328. #if PACKETVER >= 20091103
  1329. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1330. WBUFL(buf,5)=-bl->id;
  1331. #elif PACKETVER >= 20071106
  1332. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1333. WBUFL(buf,3)=-bl->id;
  1334. #else
  1335. WBUFL(buf,2)=-bl->id;
  1336. #endif
  1337. clif_send(buf, len, bl, SELF);
  1338. }
  1339. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1340. /// 01b0 <id>.L <type>.B <value>.L
  1341. /// type:
  1342. /// unused
  1343. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, map_session_data *sd)
  1344. {
  1345. nullpo_retv(bl);
  1346. if(!pcdb_checkid(class_))
  1347. {// player classes yield missing sprites
  1348. unsigned char buf[16];
  1349. WBUFW(buf,0)=0x1b0;
  1350. WBUFL(buf,2)=bl->id;
  1351. WBUFB(buf,6)=type;
  1352. WBUFL(buf,7)=class_;
  1353. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1354. }
  1355. }
  1356. void clif_servantball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1357. struct PACKET_ZC_SPIRITS p = {};
  1358. p.PacketType = HEADER_ZC_SPIRITS;
  1359. p.AID = sd.bl.id;
  1360. p.num = sd.servantball;
  1361. if( target == nullptr ){
  1362. target = &sd.bl;
  1363. }
  1364. clif_send( &p, sizeof( p ), target, send_target );
  1365. }
  1366. void clif_abyssball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1367. struct PACKET_ZC_SPIRITS p = {};
  1368. p.PacketType = HEADER_ZC_SPIRITS;
  1369. p.AID = sd.bl.id;
  1370. p.num = sd.abyssball;
  1371. if( target == nullptr ){
  1372. target = &sd.bl;
  1373. }
  1374. clif_send( &p, sizeof( p ), target, send_target );
  1375. }
  1376. /// Notifies the client of an object's Millenium Shields.
  1377. static void clif_millenniumshield_single(int fd, map_session_data *sd)
  1378. {
  1379. nullpo_retv(sd);
  1380. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD) == nullptr)
  1381. return;
  1382. WFIFOHEAD(fd, packet_len(0x440));
  1383. WFIFOW(fd, 0) = 0x440;
  1384. WFIFOL(fd, 2) = sd->bl.id;
  1385. WFIFOW(fd, 6) = sd->sc.getSCE(SC_MILLENNIUMSHIELD)->val2;
  1386. WFIFOW(fd, 8) = 0;
  1387. WFIFOSET(fd, packet_len(0x440));
  1388. }
  1389. /*==========================================
  1390. * Kagerou/Oboro amulet spirit
  1391. *------------------------------------------*/
  1392. static void clif_spiritcharm_single(int fd, map_session_data *sd)
  1393. {
  1394. WFIFOHEAD(fd, packet_len(0x08cf));
  1395. WFIFOW(fd,0)=0x08cf;
  1396. WFIFOL(fd,2)=sd->bl.id;
  1397. WFIFOW(fd,6)=sd->spiritcharm_type;
  1398. WFIFOW(fd,8)=sd->spiritcharm;
  1399. WFIFOSET(fd, packet_len(0x08cf));
  1400. }
  1401. /*==========================================
  1402. * Enchanting Shadow / Shadow Scar Spirit
  1403. *------------------------------------------*/
  1404. void clif_enchantingshadow_spirit(unit_data &ud) {
  1405. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191120 || PACKETVER_ZERO_NUM >= 20191127
  1406. PACKET_ZC_TARGET_SPIRITS p = {};
  1407. p.packetType = HEADER_ZC_TARGET_SPIRITS;
  1408. p.GID = ud.bl->id;
  1409. p.unknown_val = 0;
  1410. p.amount = static_cast<uint16>(ud.shadow_scar_timer.size());
  1411. clif_send(&p, sizeof(p), ud.bl, AREA);
  1412. #endif
  1413. }
  1414. /*==========================================
  1415. * Run when player changes map / refreshes
  1416. * Tells its client to display all weather settings being used by this map
  1417. *------------------------------------------*/
  1418. static void clif_weather_check(map_session_data *sd)
  1419. {
  1420. int16 m = sd->bl.m;
  1421. int fd = sd->fd;
  1422. if (map_getmapflag(m, MF_SNOW)
  1423. || map_getmapflag(m, MF_CLOUDS)
  1424. || map_getmapflag(m, MF_FOG)
  1425. || map_getmapflag(m, MF_FIREWORKS)
  1426. || map_getmapflag(m, MF_SAKURA)
  1427. || map_getmapflag(m, MF_LEAVES)
  1428. || map_getmapflag(m, MF_CLOUDS2))
  1429. {
  1430. if (map_getmapflag(m, MF_SNOW))
  1431. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1432. if (map_getmapflag(m, MF_CLOUDS))
  1433. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1434. if (map_getmapflag(m, MF_CLOUDS2))
  1435. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1436. if (map_getmapflag(m, MF_FOG))
  1437. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1438. if (map_getmapflag(m, MF_FIREWORKS)) {
  1439. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1440. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1441. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1442. }
  1443. if (map_getmapflag(m, MF_SAKURA))
  1444. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1445. if (map_getmapflag(m, MF_LEAVES))
  1446. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1447. }
  1448. }
  1449. /**
  1450. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1451. **/
  1452. void clif_weather(int16 m)
  1453. {
  1454. struct s_mapiterator* iter;
  1455. map_session_data *sd=NULL;
  1456. iter = mapit_getallusers();
  1457. for( sd = (map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (map_session_data*)mapit_next(iter) )
  1458. {
  1459. if( sd->bl.m == m )
  1460. clif_weather_check(sd);
  1461. }
  1462. mapit_free(iter);
  1463. }
  1464. /**
  1465. * Hide a NPC from the effects of Maya Purple card.
  1466. * @param bl: Block data
  1467. * @return True if NPC is disabled or false otherwise
  1468. */
  1469. static inline bool clif_npc_mayapurple(block_list *bl) {
  1470. nullpo_retr(false, bl);
  1471. if (bl->type == BL_NPC) {
  1472. npc_data *nd = map_id2nd(bl->id);
  1473. // TODO: Confirm if waitingroom cause any special cases
  1474. if (/* nd->chat_id == 0 && */ nd->is_invisible)
  1475. return true;
  1476. }
  1477. return false;
  1478. }
  1479. /**
  1480. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1481. **/
  1482. int clif_spawn( struct block_list *bl, bool walking ){
  1483. struct view_data *vd;
  1484. vd = status_get_viewdata(bl);
  1485. if( !vd || vd->class_ == JT_INVISIBLE )
  1486. return 0;
  1487. // Hide NPC from Maya Purple card
  1488. if (clif_npc_mayapurple(bl))
  1489. return 0;
  1490. if( bl->type == BL_NPC && !vd->dead_sit ){
  1491. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1492. }else{
  1493. clif_spawn_unit( bl, AREA_WOS );
  1494. }
  1495. if (vd->cloth_color)
  1496. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1497. if (vd->body_style)
  1498. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1499. switch (bl->type)
  1500. {
  1501. case BL_PC:
  1502. {
  1503. TBL_PC *sd = ((TBL_PC*)bl);
  1504. if (sd->spiritball > 0)
  1505. clif_spiritball(&sd->bl);
  1506. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD))
  1507. clif_millenniumshield(&sd->bl, sd->sc.getSCE(SC_MILLENNIUMSHIELD)->val2);
  1508. if (sd->soulball > 0)
  1509. clif_soulball(sd);
  1510. if (sd->servantball > 0)
  1511. clif_servantball( *sd );
  1512. if (sd->abyssball > 0)
  1513. clif_abyssball( *sd );
  1514. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1515. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1516. else if(sd->state.size==SZ_MEDIUM)
  1517. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1518. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1519. clif_sendbgemblem_area(sd);
  1520. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1521. clif_spiritcharm(sd);
  1522. if (sd->status.robe)
  1523. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1524. clif_efst_status_change_sub(bl, bl, AREA);
  1525. clif_hat_effects(sd,bl,AREA);
  1526. }
  1527. break;
  1528. case BL_MOB:
  1529. {
  1530. TBL_MOB *md = ((TBL_MOB*)bl);
  1531. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1532. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1533. else if(md->special_state.size==SZ_MEDIUM)
  1534. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1535. if ( md->special_state.ai == AI_ABR || md->special_state.ai == AI_BIONIC )
  1536. clif_summon_init(*md);
  1537. }
  1538. break;
  1539. case BL_NPC:
  1540. {
  1541. TBL_NPC *nd = ((TBL_NPC*)bl);
  1542. if( nd->size == SZ_BIG )
  1543. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1544. else if( nd->size == SZ_MEDIUM )
  1545. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1546. clif_efst_status_change_sub(bl, bl, AREA);
  1547. clif_progressbar_npc_area(nd);
  1548. }
  1549. break;
  1550. case BL_PET:
  1551. if (vd->head_bottom)
  1552. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1553. break;
  1554. }
  1555. return 0;
  1556. }
  1557. /// Sends information about owned homunculus to the client . [orn]
  1558. /// 022e <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.W <max hp>.W <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W (ZC_PROPERTY_HOMUN)
  1559. /// 09f7 <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.L <max hp>.L <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W (ZC_PROPERTY_HOMUN_2)
  1560. void clif_hominfo( map_session_data *sd, struct homun_data *hd, int flag ){
  1561. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1562. nullpo_retv( sd );
  1563. nullpo_retv( hd );
  1564. struct status_data *status = &hd->battle_status;
  1565. struct PACKET_ZC_PROPERTY_HOMUN p;
  1566. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1567. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1568. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1569. p.flags = ( !battle_config.hom_rename && hd->homunculus.rename_flag ? 0x1 : 0x0 ) | ( hd->homunculus.vaporize == HOM_ST_REST ? 0x2 : 0 ) | ( hd->homunculus.hp > 0 ? 0x4 : 0 );
  1570. p.level = hd->homunculus.level;
  1571. p.hunger = hd->homunculus.hunger;
  1572. p.intimacy = hd->homunculus.intimacy / 100;
  1573. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1574. p.itemId = 0; // equip id
  1575. #endif
  1576. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1577. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1578. p.hit = status->hit;
  1579. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1580. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1581. }else{
  1582. p.crit = status->cri / 10;
  1583. }
  1584. #ifdef RENEWAL
  1585. p.def = status->def + status->def2;
  1586. p.mdef = status->mdef + status->mdef2;
  1587. #else
  1588. p.def = status->def + status->vit;
  1589. p.mdef = status->mdef;
  1590. #endif
  1591. p.flee = status->flee;
  1592. p.amotion = (flag) ? 0 : status->amotion;
  1593. #if PACKETVER >= 20141016
  1594. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1595. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1596. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1597. p.hp = status->hp / ( status->max_hp / 100 );
  1598. p.maxHp = 100;
  1599. }else{
  1600. p.hp = status->hp;
  1601. p.maxHp = status->max_hp;
  1602. }
  1603. #else
  1604. if( status->max_hp > INT16_MAX ){
  1605. p.hp = status->hp / ( status->max_hp / 100 );
  1606. p.maxHp = 100;
  1607. }else{
  1608. p.hp = status->hp;
  1609. p.maxHp = status->max_hp;
  1610. }
  1611. #endif
  1612. if( status->max_sp > INT16_MAX ){
  1613. p.sp = status->sp / ( status->max_sp / 100 );
  1614. p.maxSp = 100;
  1615. }else{
  1616. p.sp = status->sp;
  1617. p.maxSp = status->max_sp;
  1618. }
  1619. #if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103
  1620. p.exp = hd->homunculus.exp;
  1621. p.expNext = hd->exp_next;
  1622. #else
  1623. p.exp = (uint32)hd->homunculus.exp;
  1624. p.expNext = (uint32)hd->exp_next;
  1625. #endif
  1626. switch( hom_class2type( hd->homunculus.class_ ) ){
  1627. case HT_REG:
  1628. case HT_EVO:
  1629. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1630. p.expNext = 0;
  1631. }
  1632. break;
  1633. case HT_S:
  1634. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1635. p.expNext = 0;
  1636. }
  1637. break;
  1638. }
  1639. p.skillPoints = hd->homunculus.skillpts;
  1640. p.range = status_get_range( &hd->bl );
  1641. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1642. #endif
  1643. }
  1644. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1645. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1646. /// type:
  1647. /// unused
  1648. /// state:
  1649. /// 0 = pre-init
  1650. /// 1 = intimacy
  1651. /// 2 = hunger
  1652. /// 3 = accessory?
  1653. /// ? = ignored
  1654. void clif_send_homdata(map_session_data *sd, int state, int param)
  1655. { //[orn]
  1656. int fd = sd->fd;
  1657. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1658. hom_calc_skilltree(sd->hd);
  1659. WFIFOHEAD(fd, packet_len(0x230));
  1660. WFIFOW(fd,0)=0x230;
  1661. WFIFOB(fd,2)=0;
  1662. WFIFOB(fd,3)=state;
  1663. WFIFOL(fd,4)=sd->hd->bl.id;
  1664. WFIFOL(fd,8)=param;
  1665. WFIFOSET(fd,packet_len(0x230));
  1666. }
  1667. int clif_homskillinfoblock(map_session_data *sd)
  1668. { //[orn]
  1669. struct homun_data *hd;
  1670. int fd = sd->fd;
  1671. int i, len=4;
  1672. nullpo_ret(sd);
  1673. hd = sd->hd;
  1674. if ( !hd )
  1675. return 0 ;
  1676. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1677. WFIFOW(fd,0)=0x235;
  1678. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1679. int id = hd->homunculus.hskill[i].id;
  1680. if( id != 0 ){
  1681. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1682. short idx = hom_skill_get_index(id);
  1683. if (idx == -1)
  1684. continue;
  1685. WFIFOW(fd,len ) = id;
  1686. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1687. WFIFOW(fd,len+4) = 0;
  1688. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1689. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1690. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1691. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1692. WFIFOB(fd,len+36) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(id, hd->homunculus.class_)) ? 0 : 1;
  1693. len+=37;
  1694. }
  1695. }
  1696. WFIFOW(fd,2)=len;
  1697. WFIFOSET(fd,len);
  1698. return 0;
  1699. }
  1700. void clif_homskillup(map_session_data *sd, uint16 skill_id)
  1701. { //[orn]
  1702. struct homun_data *hd;
  1703. int fd;
  1704. short idx = -1;
  1705. nullpo_retv(sd);
  1706. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1707. return;
  1708. fd = sd->fd;
  1709. hd = sd->hd;
  1710. WFIFOHEAD(fd, packet_len(0x239));
  1711. WFIFOW(fd,0) = 0x239;
  1712. WFIFOW(fd,2) = skill_id;
  1713. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1714. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1715. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1716. WFIFOB(fd,10) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, skill_id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(hd->homunculus.hskill[idx].id, hd->homunculus.class_)) ? 0 : 1;
  1717. WFIFOSET(fd,packet_len(0x239));
  1718. }
  1719. /// Result of request to feed a homun/merc.
  1720. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1721. /// result:
  1722. /// 0 = failure
  1723. /// 1 = success
  1724. void clif_hom_food( map_session_data *sd, int foodid, int fail ){
  1725. nullpo_retv( sd );
  1726. struct PACKET_ZC_FEED_MER p;
  1727. p.packetType = 0x22f;
  1728. p.result = fail;
  1729. p.itemId = client_nameid( foodid );
  1730. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1731. }
  1732. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1733. /// 0087 <walk start time>.L <walk data>.6B
  1734. void clif_walkok(map_session_data *sd)
  1735. {
  1736. int fd=sd->fd;
  1737. WFIFOHEAD(fd, packet_len(0x87));
  1738. WFIFOW(fd,0)=0x87;
  1739. WFIFOL(fd,2)=client_tick(gettick());
  1740. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1741. WFIFOSET(fd,packet_len(0x87));
  1742. }
  1743. static void clif_move2( struct block_list *bl, struct view_data *vd, struct unit_data *ud ){
  1744. status_change *sc = NULL;
  1745. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1746. clif_ally_only = true;
  1747. clif_set_unit_walking( bl, nullptr, ud, AREA_WOS );
  1748. if(vd->cloth_color)
  1749. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1750. if(vd->body_style)
  1751. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1752. switch(bl->type) {
  1753. case BL_PC:
  1754. {
  1755. TBL_PC *sd = ((TBL_PC*)bl);
  1756. // clif_movepc(sd);
  1757. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1758. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1759. else if(sd->state.size==SZ_MEDIUM)
  1760. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1761. if (sd->status.robe)
  1762. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1763. }
  1764. break;
  1765. case BL_MOB:
  1766. {
  1767. TBL_MOB *md = ((TBL_MOB*)bl);
  1768. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1769. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1770. else if(md->special_state.size==SZ_MEDIUM)
  1771. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1772. }
  1773. break;
  1774. case BL_PET:
  1775. if(vd->head_bottom) // needed to display pet equip properly
  1776. clif_pet_equip_area((TBL_PET*)bl);
  1777. break;
  1778. }
  1779. clif_ally_only = false;
  1780. }
  1781. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1782. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1783. /// Note: unit must not be self
  1784. void clif_move(struct unit_data *ud)
  1785. {
  1786. unsigned char buf[16];
  1787. struct view_data* vd;
  1788. struct block_list* bl = ud->bl;
  1789. status_change *sc = NULL;
  1790. vd = status_get_viewdata(bl);
  1791. if (!vd )
  1792. return;
  1793. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1794. else if( vd->class_ == JT_INVISIBLE ){
  1795. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1796. if(disguised(bl)) {
  1797. WBUFW(buf,0)=0x86;
  1798. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1799. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1800. WBUFL(buf,12)=client_tick(gettick());
  1801. clif_send(buf, packet_len(0x86), bl, SELF);
  1802. }
  1803. return;
  1804. }
  1805. // Hide NPC from Maya Purple card
  1806. if (clif_npc_mayapurple(bl))
  1807. return;
  1808. if (ud->state.speed_changed) {
  1809. // Since we don't know how to update the speed of other objects,
  1810. // use the old walk packet to update the data.
  1811. ud->state.speed_changed = 0;
  1812. clif_move2(bl, vd, ud);
  1813. return;
  1814. }
  1815. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1816. clif_ally_only = true;
  1817. WBUFW(buf,0)=0x86;
  1818. WBUFL(buf,2)=bl->id;
  1819. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1820. WBUFL(buf,12)=client_tick(gettick());
  1821. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1822. if (disguised(bl)) {
  1823. WBUFL(buf,2)=disguised_bl_id(bl->id);
  1824. clif_send(buf, packet_len(0x86), bl, SELF);
  1825. }
  1826. clif_ally_only = false;
  1827. }
  1828. /*==========================================
  1829. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1830. *------------------------------------------*/
  1831. static TIMER_FUNC(clif_delayquit){
  1832. map_session_data *sd = NULL;
  1833. //Remove player from map server
  1834. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1835. map_quit(sd);
  1836. return 0;
  1837. }
  1838. /*==========================================
  1839. *
  1840. *------------------------------------------*/
  1841. void clif_quitsave(int fd,map_session_data *sd) {
  1842. if (!battle_config.prevent_logout ||
  1843. sd->canlog_tick == 0 ||
  1844. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1845. map_quit(sd);
  1846. else if (session_isValid(sd->fd)) {
  1847. //Disassociate session from player (session is deleted after this function was called)
  1848. //And set a timer to make him quit later.
  1849. session[sd->fd]->session_data = NULL;
  1850. sd->fd = 0;
  1851. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1852. }
  1853. }
  1854. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1855. /// 0091 <map name>.16B <x>.W <y>.W
  1856. void clif_changemap(map_session_data *sd, short m, int x, int y)
  1857. {
  1858. nullpo_retv(sd);
  1859. int fd = sd->fd;
  1860. WFIFOHEAD(fd,packet_len(0x91));
  1861. WFIFOW(fd,0) = 0x91;
  1862. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1863. WFIFOW(fd,18) = x;
  1864. WFIFOW(fd,20) = y;
  1865. WFIFOSET(fd,packet_len(0x91));
  1866. }
  1867. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1868. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1869. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1870. void clif_changemapserver(map_session_data* sd, const char* map, int x, int y, uint32 ip, uint16 port)
  1871. {
  1872. int fd;
  1873. #if PACKETVER >= 20170315
  1874. int cmd = 0xac7;
  1875. #else
  1876. int cmd = 0x92;
  1877. #endif
  1878. nullpo_retv(sd);
  1879. fd = sd->fd;
  1880. WFIFOHEAD(fd,packet_len(cmd));
  1881. WFIFOW(fd,0) = cmd;
  1882. mapindex_getmapname_ext( map, WFIFOCP( fd, 2 ) );
  1883. WFIFOW(fd,18) = x;
  1884. WFIFOW(fd,20) = y;
  1885. WFIFOL(fd,22) = htonl(ip);
  1886. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1887. #if PACKETVER >= 20170315
  1888. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1889. #endif
  1890. #ifdef DEBUG
  1891. ShowDebug(
  1892. "Sending the client (%d %d.%d.%d.%d) to map-server with ip %d.%d.%d.%d and port %hu\n",
  1893. sd->status.account_id, CONVIP(session[fd]->client_addr), CONVIP(ip), port);
  1894. #endif
  1895. WFIFOSET(fd,packet_len(cmd));
  1896. }
  1897. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1898. /// This function combines both calls and allows to simplify the calling code
  1899. void clif_blown(struct block_list *bl)
  1900. {
  1901. clif_slide(bl, bl->x, bl->y);
  1902. clif_fixpos(bl);
  1903. }
  1904. /// Visually moves(slides) a character to x,y. If the target cell
  1905. /// isn't walkable, the char doesn't move at all. If the char is
  1906. /// sitting it will stand up (ZC_STOPMOVE).
  1907. /// 0088 <id>.L <x>.W <y>.W
  1908. void clif_fixpos(struct block_list *bl)
  1909. {
  1910. unsigned char buf[10];
  1911. nullpo_retv(bl);
  1912. WBUFW(buf,0) = 0x88;
  1913. WBUFL(buf,2) = bl->id;
  1914. WBUFW(buf,6) = bl->x;
  1915. WBUFW(buf,8) = bl->y;
  1916. clif_send(buf, packet_len(0x88), bl, AREA);
  1917. if( disguised(bl) ) {
  1918. WBUFL(buf,2) = disguised_bl_id(bl->id);
  1919. clif_send(buf, packet_len(0x88), bl, SELF);
  1920. }
  1921. }
  1922. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1923. /// 00c4 <shop id>.L
  1924. void clif_npcbuysell(map_session_data* sd, int id)
  1925. {
  1926. int fd;
  1927. nullpo_retv(sd);
  1928. fd=sd->fd;
  1929. WFIFOHEAD(fd, packet_len(0xc4));
  1930. WFIFOW(fd,0)=0xc4;
  1931. WFIFOL(fd,2)=id;
  1932. WFIFOSET(fd,packet_len(0xc4));
  1933. }
  1934. /// Presents list of items, that can be bought in an NPC shop.
  1935. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1936. void clif_buylist( map_session_data *sd, struct npc_data *nd ){
  1937. nullpo_retv( sd );
  1938. nullpo_retv( nd );
  1939. int fd = sd->fd;
  1940. if( !session_isActive( fd ) ){
  1941. return;
  1942. }
  1943. uint16 len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + nd->u.shop.count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1944. WFIFOHEAD( fd, len );
  1945. struct PACKET_ZC_PC_PURCHASE_ITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST *)WFIFOP( fd, 0 );
  1946. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST;
  1947. int count = 0;
  1948. for( int i = 0, discount = npc_shop_discount( nd ); i < nd->u.shop.count; i++ ){
  1949. int val = nd->u.shop.shop_item[i].value;
  1950. p->items[count].price = val;
  1951. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( sd, val ) : val;
  1952. p->items[count].itemType = itemtype( nd->u.shop.shop_item[i].nameid );
  1953. p->items[count].itemId = client_nameid( nd->u.shop.shop_item[i].nameid );
  1954. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1955. std::shared_ptr<item_data> id = item_db.find(nd->u.shop.shop_item[i].nameid);
  1956. p->items[count].viewSprite = id->look;
  1957. p->items[count].location = pc_equippoint_sub( sd, id.get() );
  1958. #endif
  1959. count++;
  1960. }
  1961. p->packetLength = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST ) + count * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_sub );
  1962. WFIFOSET( fd, p->packetLength );
  1963. }
  1964. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1965. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1966. void clif_selllist(map_session_data *sd)
  1967. {
  1968. int fd,i,c=0,val;
  1969. struct npc_data *nd;
  1970. nullpo_retv(sd);
  1971. if (!sd->npc_shopid || (nd = map_id2nd(sd->npc_shopid)) == NULL)
  1972. return;
  1973. fd=sd->fd;
  1974. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1975. WFIFOW(fd,0)=0xc7;
  1976. for( i = 0; i < MAX_INVENTORY; i++ )
  1977. {
  1978. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1979. {
  1980. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i], nd->subtype))
  1981. continue;
  1982. if (battle_config.rental_item_novalue && sd->inventory.u.items_inventory[i].expire_time)
  1983. val = 0;
  1984. else {
  1985. val = sd->inventory_data[i]->value_sell;
  1986. if( val < 0 )
  1987. continue;
  1988. }
  1989. WFIFOW(fd,4+c*10)=i+2;
  1990. WFIFOL(fd,6+c*10)=val;
  1991. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1992. c++;
  1993. }
  1994. }
  1995. WFIFOW(fd,2)=c*10+4;
  1996. WFIFOSET(fd,WFIFOW(fd,2));
  1997. }
  1998. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1999. /// 09d4
  2000. void clif_parse_NPCShopClosed(int fd, map_session_data *sd) {
  2001. // TODO: State tracking?
  2002. sd->npc_shopid = 0;
  2003. }
  2004. /**
  2005. * Presents list of items, that can be sold to a Market shop.
  2006. * @author: Ind and Yommy
  2007. **/
  2008. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  2009. void clif_npc_market_open(map_session_data *sd, struct npc_data *nd) {
  2010. #if PACKETVER >= 20131223
  2011. nullpo_retv( sd );
  2012. nullpo_retv( nd );
  2013. if( sd->state.trading ){
  2014. return;
  2015. }
  2016. int fd = sd->fd;
  2017. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  2018. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  2019. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  2020. int count = 0;
  2021. for( int i = 0; i < nd->u.shop.count; i++ ){
  2022. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  2023. if( !item->nameid ){
  2024. continue;
  2025. }
  2026. std::shared_ptr<item_data> id = item_db.find(item->nameid);
  2027. if( !id ){
  2028. continue;
  2029. }
  2030. p->list[count].nameid = client_nameid( item->nameid );
  2031. p->list[count].type = itemtype( item->nameid );
  2032. p->list[count].price = item->value;
  2033. p->list[count].qty = item->qty;
  2034. p->list[count].weight = id->weight;
  2035. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  2036. p->list[count].location = pc_equippoint_sub( sd, id.get() );
  2037. #endif
  2038. count++;
  2039. }
  2040. p->packetLength = sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub );
  2041. WFIFOSET( fd, p->packetLength );
  2042. sd->state.trading = 1;
  2043. #endif
  2044. }
  2045. /// Closes the Market shop window.
  2046. void clif_parse_NPCMarketClosed(int fd, map_session_data *sd) {
  2047. nullpo_retv(sd);
  2048. sd->npc_shopid = 0;
  2049. sd->state.trading = 0;
  2050. }
  2051. /// Purchase item from Market shop.
  2052. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  2053. void clif_npc_market_purchase_ack( map_session_data *sd, e_purchase_result res, std::vector<s_npc_buy_list>& list ){
  2054. #if PACKETVER >= 20131223
  2055. nullpo_retv( sd );
  2056. struct npc_data *nd = map_id2nd( sd->npc_shopid );
  2057. nullpo_retv( nd );
  2058. struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *p = (struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT *)packet_buffer;
  2059. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  2060. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT );
  2061. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  2062. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 0 : -1 );
  2063. #else
  2064. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 1 : 0 );
  2065. #endif
  2066. if( res == e_purchase_result::PURCHASE_SUCCEED ){
  2067. for( int i = 0, j, count = 0; i < list.size(); i++ ){
  2068. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  2069. // Not found
  2070. if( j == nd->u.shop.count ){
  2071. continue;
  2072. }
  2073. p->list[count].ITID = client_nameid( list[i].nameid );
  2074. p->list[count].qty = list[i].qty;
  2075. p->list[count].price = nd->u.shop.shop_item[j].value;
  2076. p->PacketLength += sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT_sub );
  2077. count++;
  2078. }
  2079. }
  2080. clif_send( p, p->PacketLength, &sd->bl, SELF );
  2081. #endif
  2082. }
  2083. /// Purchase item from Market shop.
  2084. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2085. void clif_parse_NPCMarketPurchase(int fd, map_session_data *sd) {
  2086. #if PACKETVER >= 20131223
  2087. nullpo_retv( sd );
  2088. if( !sd->npc_shopid ){
  2089. return;
  2090. }
  2091. const struct PACKET_CZ_NPC_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  2092. int count = ( p->PacketLength - sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE_sub );
  2093. std::vector<s_npc_buy_list> items;
  2094. items.reserve( count );
  2095. for( int i = 0; i < count; i++ ){
  2096. s_npc_buy_list item = {};
  2097. item.nameid = p->list[i].ITID;
  2098. item.qty = p->list[i].qty;
  2099. items.push_back( item );
  2100. }
  2101. e_purchase_result res = npc_buylist( sd, items );
  2102. clif_npc_market_purchase_ack( sd, res, items );
  2103. #endif
  2104. }
  2105. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  2106. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  2107. /// Client behavior (dialog window):
  2108. /// - disable mouse targeting
  2109. /// - open the dialog window
  2110. /// - set npcid of dialog window (0 by default)
  2111. /// - if set to clear on next mes, clear contents
  2112. /// - append this text
  2113. void clif_scriptmes( map_session_data& sd, uint32 npcid, const char *mes ){
  2114. struct PACKET_ZC_SAY_DIALOG* p = (struct PACKET_ZC_SAY_DIALOG*)packet_buffer;
  2115. int16 length = (int16)( strlen( mes ) + 1 );
  2116. p->PacketType = HEADER_ZC_SAY_DIALOG;
  2117. p->PacketLength = sizeof( *p ) + length;
  2118. p->NpcID = npcid;
  2119. safestrncpy( p->message, mes, length );
  2120. clif_send( p, p->PacketLength, &sd.bl, SELF );
  2121. }
  2122. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  2123. /// 00b5 <npc id>.L
  2124. /// Client behavior (dialog window):
  2125. /// - disable mouse targeting
  2126. /// - open the dialog window
  2127. /// - add 'next' button
  2128. /// When 'next' is pressed:
  2129. /// - 00B9 <npcid of dialog window>.L
  2130. /// - set to clear on next mes
  2131. /// - remove 'next' button
  2132. void clif_scriptnext( map_session_data& sd, uint32 npcid ){
  2133. struct PACKET_ZC_WAIT_DIALOG p = {};
  2134. p.PacketType = HEADER_ZC_WAIT_DIALOG;
  2135. p.NpcID = npcid;
  2136. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2137. }
  2138. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  2139. /// 00b6 <npc id>.L
  2140. /// Client behavior:
  2141. /// - if dialog window is open:
  2142. /// - remove 'next' button
  2143. /// - add 'close' button
  2144. /// - else:
  2145. /// - enable mouse targeting
  2146. /// - close the dialog window
  2147. /// - close the menu window
  2148. /// When 'close' is pressed:
  2149. /// - enable mouse targeting
  2150. /// - close the dialog window
  2151. /// - close the menu window
  2152. /// - 0146 <npcid of dialog window>.L
  2153. void clif_scriptclose(map_session_data *sd, int npcid)
  2154. {
  2155. int fd;
  2156. nullpo_retv(sd);
  2157. fd=sd->fd;
  2158. WFIFOHEAD(fd, packet_len(0xb6));
  2159. WFIFOW(fd,0)=0xb6;
  2160. WFIFOL(fd,2)=npcid;
  2161. WFIFOSET(fd,packet_len(0xb6));
  2162. }
  2163. /**
  2164. * Close script when player is idle
  2165. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2166. * @author [Ind/Hercules]
  2167. * @param sd : player pointer
  2168. * @param npcid : npc gid to close
  2169. */
  2170. void clif_scriptclear( map_session_data& sd, int npcid ){
  2171. struct PACKET_ZC_CLEAR_DIALOG p = {};
  2172. p.packetType = HEADER_ZC_CLEAR_DIALOG;
  2173. p.GID = npcid;
  2174. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2175. }
  2176. /*==========================================
  2177. *
  2178. *------------------------------------------*/
  2179. void clif_sendfakenpc(map_session_data *sd, int npcid) {
  2180. unsigned char *buf;
  2181. int fd = sd->fd;
  2182. sd->state.using_fake_npc = 1;
  2183. WFIFOHEAD(fd, packet_len(0x78));
  2184. buf = WFIFOP(fd,0);
  2185. memset(WBUFP(buf,0), 0, packet_len(0x78));
  2186. WBUFW(buf,0)=0x78;
  2187. #if PACKETVER >= 20071106
  2188. WBUFB(buf,2) = 0; // object type
  2189. buf = WFIFOP(fd,1);
  2190. #endif
  2191. WBUFL(buf,2)=npcid;
  2192. WBUFW(buf,14)=111;
  2193. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  2194. WBUFB(buf,49)=5;
  2195. WBUFB(buf,50)=5;
  2196. WFIFOSET(fd, packet_len(0x78));
  2197. }
  2198. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  2199. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  2200. /// Client behavior:
  2201. /// - disable mouse targeting
  2202. /// - close the menu window
  2203. /// - open the menu window
  2204. /// - add options to the menu (separated in the text by ":")
  2205. /// - set npcid of menu window
  2206. /// - if dialog window is open:
  2207. /// - remove 'next' button
  2208. /// When 'ok' is pressed:
  2209. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2210. /// - close the menu window
  2211. /// When 'cancel' is pressed:
  2212. /// - 00B8 <npcid of menu window>.L <-1>.B
  2213. /// - enable mouse targeting
  2214. /// - close a bunch of windows...
  2215. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2216. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2217. /// TODO investigate behavior of other windows [FlavioJS]
  2218. void clif_scriptmenu(map_session_data* sd, int npcid, const char* mes)
  2219. {
  2220. int fd = sd->fd;
  2221. int slen = strlen(mes) + 9;
  2222. struct block_list *bl = NULL;
  2223. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2224. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2225. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2226. clif_sendfakenpc(sd, npcid);
  2227. WFIFOHEAD(fd, slen);
  2228. WFIFOW(fd,0)=0xb7;
  2229. WFIFOW(fd,2)=slen;
  2230. WFIFOL(fd,4)=npcid;
  2231. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2232. WFIFOSET(fd,WFIFOW(fd,2));
  2233. }
  2234. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2235. /// 0142 <npc id>.L
  2236. /// Client behavior (inputnum window):
  2237. /// - if npcid exists in the client:
  2238. /// - open the inputnum window
  2239. /// - set npcid of inputnum window
  2240. /// When 'ok' is pressed:
  2241. /// - if inputnum window has text:
  2242. /// - if npcid exists in the client:
  2243. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2244. /// - close inputnum window
  2245. void clif_scriptinput(map_session_data *sd, int npcid)
  2246. {
  2247. int fd;
  2248. struct block_list *bl = NULL;
  2249. nullpo_retv(sd);
  2250. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2251. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2252. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2253. clif_sendfakenpc(sd, npcid);
  2254. fd=sd->fd;
  2255. WFIFOHEAD(fd, packet_len(0x142));
  2256. WFIFOW(fd,0)=0x142;
  2257. WFIFOL(fd,2)=npcid;
  2258. WFIFOSET(fd,packet_len(0x142));
  2259. }
  2260. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2261. /// 01d4 <npc id>.L
  2262. /// Client behavior (inputstr window):
  2263. /// - if npcid is 0 or npcid exists in the client:
  2264. /// - open the inputstr window
  2265. /// - set npcid of inputstr window
  2266. /// When 'ok' is pressed:
  2267. /// - if inputstr window has text and isn't an insult(manner.txt):
  2268. /// - if npcid is 0 or npcid exists in the client:
  2269. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2270. /// - close inputstr window
  2271. void clif_scriptinputstr(map_session_data *sd, int npcid)
  2272. {
  2273. int fd;
  2274. struct block_list *bl = NULL;
  2275. nullpo_retv(sd);
  2276. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2277. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2278. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2279. clif_sendfakenpc(sd, npcid);
  2280. fd=sd->fd;
  2281. WFIFOHEAD(fd, packet_len(0x1d4));
  2282. WFIFOW(fd,0)=0x1d4;
  2283. WFIFOL(fd,2)=npcid;
  2284. WFIFOSET(fd,packet_len(0x1d4));
  2285. }
  2286. /// Marks a position on client's minimap (ZC_COMPASS).
  2287. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2288. /// npc id:
  2289. /// is ignored in the client
  2290. /// type:
  2291. /// 0 = display mark for 15 seconds
  2292. /// 1 = display mark until dead or teleported
  2293. /// 2 = remove mark
  2294. /// color:
  2295. /// 0x00RRGGBB
  2296. void clif_viewpoint(map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2297. {
  2298. int fd;
  2299. nullpo_retv(sd);
  2300. fd=sd->fd;
  2301. WFIFOHEAD(fd, packet_len(0x144));
  2302. WFIFOW(fd,0)=0x144;
  2303. WFIFOL(fd,2)=npc_id;
  2304. WFIFOL(fd,6)=type;
  2305. WFIFOL(fd,10)=x;
  2306. WFIFOL(fd,14)=y;
  2307. WFIFOB(fd,18)=id;
  2308. WFIFOL(fd,19)=color;
  2309. WFIFOSET(fd,packet_len(0x144));
  2310. }
  2311. /// Displays an illustration image.
  2312. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2313. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2314. /// type:
  2315. /// 0 = bottom left corner
  2316. /// 1 = bottom middle
  2317. /// 2 = bottom right corner
  2318. /// 3 = middle of screen, inside a movable window
  2319. /// 4 = middle of screen, movable with a close button, chrome-less
  2320. /// 255 = clear all displayed cutins
  2321. void clif_cutin(map_session_data* sd, const char* image, int type)
  2322. {
  2323. int fd;
  2324. nullpo_retv(sd);
  2325. fd=sd->fd;
  2326. WFIFOHEAD(fd, packet_len(0x1b3));
  2327. WFIFOW(fd,0)=0x1b3;
  2328. strncpy(WFIFOCP(fd,2),image,64);
  2329. WFIFOB(fd,66)=type;
  2330. WFIFOSET(fd,packet_len(0x1b3));
  2331. }
  2332. /*==========================================
  2333. * Fills in card data from the given item and into the buffer. [Skotlex]
  2334. *------------------------------------------*/
  2335. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2336. nullpo_retv( buf );
  2337. // Blank data
  2338. if( item == nullptr ){
  2339. buf->card[0] = 0;
  2340. buf->card[1] = 0;
  2341. buf->card[2] = 0;
  2342. buf->card[3] = 0;
  2343. return;
  2344. }
  2345. // Pet eggs
  2346. if( item->card[0] == CARD0_PET ){
  2347. buf->card[0] = 0;
  2348. buf->card[1] = 0;
  2349. // Pet intimacy
  2350. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2351. buf->card[2] = item->card[3] >> 1;
  2352. // Pet renamed flag
  2353. buf->card[3] = item->card[3] & 1;
  2354. return;
  2355. }
  2356. // Forged/created items
  2357. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2358. buf->card[0] = item->card[0];
  2359. buf->card[1] = item->card[1];
  2360. buf->card[2] = item->card[2];
  2361. buf->card[3] = item->card[3];
  2362. return;
  2363. }
  2364. int i = 0, j;
  2365. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2366. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2367. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2368. }
  2369. // Normal items.
  2370. for( int k = 0; k < 4; k++, i++ ){
  2371. if( item->card[i] > 0 ){
  2372. buf->card[k] = client_nameid( item->card[i] );
  2373. }else{
  2374. buf->card[k] = 0;
  2375. }
  2376. }
  2377. }
  2378. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2379. /// A maximum of 5 random options can be supported.
  2380. static void clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item& it ){
  2381. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2382. if( it.option[i].id ){
  2383. buf[i].index = it.option[i].id; // OptIndex
  2384. buf[i].value = it.option[i].value; // Value
  2385. buf[i].param = it.option[i].param; // Param1
  2386. }else{
  2387. buf[i].index = 0;
  2388. buf[i].value = 0;
  2389. buf[i].param = 0;
  2390. }
  2391. }
  2392. #if MAX_ITEM_RDM_OPT < 5
  2393. for( ; i < 5; i++ ){
  2394. buf[i].index = 0; // OptIndex
  2395. buf[i].value = 0; // Value
  2396. buf[i].param = 0; // Param1
  2397. }
  2398. #endif
  2399. }
  2400. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2401. /// 00a0 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B (ZC_ITEM_PICKUP_ACK)
  2402. /// 029a <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B <expire time>.L (ZC_ITEM_PICKUP_ACK2)
  2403. /// 02d4 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK3)
  2404. /// 0990 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK_V5)
  2405. /// 0a0c <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ITEM_PICKUP_ACK_V6)
  2406. /// 0a37 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W { <option id>.W <option value>.W <option param>.B }*5 <favorite>.B <view id>.W (ZC_ITEM_PICKUP_ACK_V7)
  2407. void clif_additem( map_session_data *sd, int n, int amount, unsigned char fail ){
  2408. nullpo_retv( sd );
  2409. int fd = sd->fd;
  2410. if( !session_isActive( fd ) ){
  2411. return;
  2412. }
  2413. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2414. if( fail ){
  2415. p = {};
  2416. }else{
  2417. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2418. return;
  2419. }
  2420. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2421. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2422. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2423. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2424. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2425. p.location = pc_equippoint(sd,n);
  2426. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2427. #if PACKETVER >= 20061218
  2428. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2429. #if PACKETVER >= 20071002
  2430. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2431. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2432. */
  2433. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2434. #if PACKETVER >= 20150226
  2435. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[n] );
  2436. #if PACKETVER >= 20160921
  2437. p.favorite = sd->inventory.u.items_inventory[n].favorite;
  2438. p.look = sd->inventory_data[n]->look;
  2439. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2440. p.grade = sd->inventory.u.items_inventory[n].enchantgrade;
  2441. #endif
  2442. #endif
  2443. #endif
  2444. #endif
  2445. #endif
  2446. }
  2447. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2448. p.Index = client_index( n );
  2449. p.count = amount;
  2450. p.result = fail;
  2451. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2452. }
  2453. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2454. /// 00af <index>.W <amount>.W
  2455. void clif_dropitem(map_session_data *sd,int n,int amount)
  2456. {
  2457. int fd;
  2458. nullpo_retv(sd);
  2459. fd=sd->fd;
  2460. WFIFOHEAD(fd, packet_len(0xaf));
  2461. WFIFOW(fd,0)=0xaf;
  2462. WFIFOW(fd,2)=n+2;
  2463. WFIFOW(fd,4)=amount;
  2464. WFIFOSET(fd,packet_len(0xaf));
  2465. }
  2466. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2467. /// 07fa <delete type>.W <index>.W <amount>.W
  2468. /// delete type:
  2469. /// 0 = Normal
  2470. /// 1 = Item used for a skill
  2471. /// 2 = Refine failed
  2472. /// 3 = Material changed
  2473. /// 4 = Moved to storage
  2474. /// 5 = Moved to cart
  2475. /// 6 = Item sold
  2476. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2477. void clif_delitem(map_session_data *sd,int n,int amount, short reason)
  2478. {
  2479. #if PACKETVER < 20091117
  2480. clif_dropitem(sd,n,amount);
  2481. #else
  2482. int fd;
  2483. nullpo_retv(sd);
  2484. fd=sd->fd;
  2485. WFIFOHEAD(fd, packet_len(0x7fa));
  2486. WFIFOW(fd,0)=0x7fa;
  2487. WFIFOW(fd,2)=reason;
  2488. WFIFOW(fd,4)=n+2;
  2489. WFIFOW(fd,6)=amount;
  2490. WFIFOSET(fd,packet_len(0x7fa));
  2491. #endif
  2492. }
  2493. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2494. nullpo_retv( p );
  2495. nullpo_retv( it );
  2496. nullpo_retv( id );
  2497. p->index = idx;
  2498. p->ITID = client_nameid( it->nameid );
  2499. p->type = itemtype( it->nameid );
  2500. #if PACKETVER < 20120925
  2501. p->IsIdentified = it->identify ? 1 : 0;
  2502. #endif
  2503. p->location = eqp_pos;
  2504. p->WearState = it->equip;
  2505. #if PACKETVER < 20120925
  2506. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2507. #endif
  2508. p->RefiningLevel = it->refine;
  2509. clif_addcards( &p->slot, it );
  2510. #if PACKETVER >= 20071002
  2511. p->HireExpireDate = it->expire_time;
  2512. #endif
  2513. #if PACKETVER >= 20080102
  2514. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2515. #endif
  2516. #if PACKETVER >= 20100629
  2517. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2518. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2519. #endif
  2520. #if PACKETVER >= 20120925
  2521. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2522. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2523. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2524. p->Flag.SpareBits = 0;
  2525. #endif
  2526. #if PACKETVER >= 20150226
  2527. clif_add_random_options( p->option_data, *it );
  2528. // Client ingores the value anyway and recalculates it
  2529. p->option_count = 0;
  2530. #endif
  2531. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2532. p->grade = it->enchantgrade;
  2533. #endif
  2534. }
  2535. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2536. nullpo_retv(p);
  2537. nullpo_retv(i);
  2538. nullpo_retv(id);
  2539. p->index = idx;
  2540. p->ITID = client_nameid( i->nameid );
  2541. p->type = itemtype( i->nameid );
  2542. #if PACKETVER < 20120925
  2543. p->IsIdentified = i->identify ? 1 : 0;
  2544. #endif
  2545. p->count = i->amount;
  2546. p->WearState = id->equip;
  2547. #if PACKETVER >= 5
  2548. clif_addcards( &p->slot, i );
  2549. #endif
  2550. #if PACKETVER >= 20080102
  2551. p->HireExpireDate = i->expire_time;
  2552. #endif
  2553. #if PACKETVER >= 20120925
  2554. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2555. p->Flag.PlaceETCTab = i->favorite ? 1 : 0;
  2556. p->Flag.SpareBits = 0;
  2557. #endif
  2558. }
  2559. static void clif_inventoryStart( map_session_data *sd, e_inventory_type type, const char *name ){
  2560. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2561. nullpo_retv(sd);
  2562. nullpo_retv(name);
  2563. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2564. memset(buf, 0, sizeof(buf));
  2565. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2566. p->packetType = HEADER_ZC_INVENTORY_START;
  2567. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2568. p->invType = type;
  2569. #endif
  2570. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2571. int strLen = (int)safestrnlen(name, 24) + 1;
  2572. if (strLen > 24)
  2573. strLen = 24;
  2574. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2575. p->packetLength = len;
  2576. safestrncpy(p->name, name, strLen);
  2577. #else
  2578. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2579. safestrncpy(p->name, name, NAME_LENGTH);
  2580. #endif
  2581. clif_send( p, len, &sd->bl, SELF );
  2582. #endif
  2583. }
  2584. static void clif_inventoryEnd( map_session_data *sd, e_inventory_type type ){
  2585. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2586. nullpo_retv(sd);
  2587. struct PACKET_ZC_INVENTORY_END p;
  2588. p.packetType = HEADER_ZC_INVENTORY_END;
  2589. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2590. p.invType = type;
  2591. #endif
  2592. p.flag = 0;
  2593. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2594. #endif
  2595. }
  2596. void clif_favorite_item(map_session_data* sd, unsigned short index);
  2597. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2598. void clif_inventorylist( map_session_data *sd ){
  2599. nullpo_retv( sd );
  2600. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2601. e_inventory_type type = INVTYPE_INVENTORY;
  2602. clif_inventoryStart( sd, type, "" );
  2603. #endif
  2604. static struct packet_itemlist_normal itemlist_normal;
  2605. static struct packet_itemlist_equip itemlist_equip;
  2606. int equip = 0;
  2607. int normal = 0;
  2608. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2609. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2610. continue;
  2611. }
  2612. // Non-stackable (Equippable)
  2613. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2614. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2615. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2616. itemlist_equip.PacketType = inventorylistequipType;
  2617. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2618. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2619. itemlist_equip.invType = type;
  2620. #endif
  2621. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2622. equip = 0;
  2623. }
  2624. // Stackable (Normal)
  2625. }else{
  2626. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2627. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2628. itemlist_normal.PacketType = inventorylistnormalType;
  2629. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2630. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2631. itemlist_normal.invType = type;
  2632. #endif
  2633. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2634. normal = 0;
  2635. }
  2636. }
  2637. }
  2638. if( normal ){
  2639. itemlist_normal.PacketType = inventorylistnormalType;
  2640. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2641. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2642. itemlist_normal.invType = type;
  2643. #endif
  2644. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2645. }
  2646. if( sd->equip_index[EQI_AMMO] >= 0 )
  2647. clif_arrowequip( sd, sd->equip_index[EQI_AMMO] );
  2648. if( equip ) {
  2649. itemlist_equip.PacketType = inventorylistequipType;
  2650. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2651. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2652. itemlist_equip.invType = type;
  2653. #endif
  2654. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2655. }
  2656. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2657. clif_inventoryEnd( sd, type );
  2658. #endif
  2659. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2660. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2661. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2662. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL )
  2663. continue;
  2664. if ( sd->inventory.u.items_inventory[i].favorite )
  2665. clif_favorite_item(sd, i);
  2666. }
  2667. #endif
  2668. }
  2669. //Required when items break/get-repaired. Only sends equippable item list.
  2670. void clif_equiplist( map_session_data *sd ){
  2671. // TODO: implement again => only send equip part
  2672. clif_inventorylist( sd );
  2673. }
  2674. void clif_storagelist(map_session_data* sd, struct item* items, int items_length, const char *storename){
  2675. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2676. e_inventory_type type = INVTYPE_STORAGE;
  2677. clif_inventoryStart( sd, type, storename );
  2678. #endif
  2679. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2680. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2681. int equip = 0;
  2682. int normal = 0;
  2683. for( int i = 0; i < items_length; i++ ){
  2684. if( items[i].nameid == 0 ){
  2685. continue;
  2686. }
  2687. struct item_data* id = itemdb_search( items[i].nameid );
  2688. // Non-stackable (Equippable)
  2689. if( !itemdb_isstackable2( id ) ){
  2690. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2691. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2692. storage_itemlist_equip.PacketType = storageListEquipType;
  2693. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2694. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2695. storage_itemlist_equip.invType = type;
  2696. #elif PACKETVER >= 20120925
  2697. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2698. #endif
  2699. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2700. equip = 0;
  2701. }
  2702. // Stackable (Normal)
  2703. }else{
  2704. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2705. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2706. storage_itemlist_normal.PacketType = storageListNormalType;
  2707. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2708. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2709. storage_itemlist_normal.invType = type;
  2710. #elif PACKETVER >= 20120925
  2711. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2712. #endif
  2713. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2714. normal = 0;
  2715. }
  2716. }
  2717. }
  2718. if( normal ){
  2719. storage_itemlist_normal.PacketType = storageListNormalType;
  2720. storage_itemlist_normal.PacketLength = ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2721. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2722. storage_itemlist_normal.invType = type;
  2723. #elif PACKETVER >= 20120925
  2724. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2725. #endif
  2726. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2727. }
  2728. if( equip ) {
  2729. storage_itemlist_equip.PacketType = storageListEquipType;
  2730. storage_itemlist_equip.PacketLength = ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2731. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2732. storage_itemlist_equip.invType = type;
  2733. #elif PACKETVER >= 20120925
  2734. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2735. #endif
  2736. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2737. }
  2738. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2739. clif_inventoryEnd( sd, type );
  2740. #endif
  2741. }
  2742. void clif_cartlist( map_session_data *sd ){
  2743. nullpo_retv( sd );
  2744. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2745. e_inventory_type type = INVTYPE_CART;
  2746. clif_inventoryStart( sd, type, "" );
  2747. #endif
  2748. static struct packet_itemlist_normal itemlist_normal;
  2749. static struct packet_itemlist_equip itemlist_equip;
  2750. int normal = 0;
  2751. int equip = 0;
  2752. for( int i = 0; i < MAX_CART; i++ ){
  2753. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2754. continue;
  2755. }
  2756. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2757. // Non-stackable (Equippable)
  2758. if( !itemdb_isstackable2(id) ){
  2759. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2760. // Stackable (Normal)
  2761. }else{
  2762. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2763. }
  2764. }
  2765. if( normal ){
  2766. itemlist_normal.PacketType = cartlistnormalType;
  2767. itemlist_normal.PacketLength = ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal );
  2768. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2769. itemlist_normal.invType = type;
  2770. #endif
  2771. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2772. }
  2773. if( equip ){
  2774. itemlist_equip.PacketType = cartlistequipType;
  2775. itemlist_equip.PacketLength = ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip );
  2776. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2777. itemlist_equip.invType = type;
  2778. #endif
  2779. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2780. }
  2781. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2782. clif_inventoryEnd( sd, type );
  2783. #endif
  2784. }
  2785. /// Removes cart (ZC_CARTOFF).
  2786. /// 012b
  2787. /// Client behaviour:
  2788. /// Closes the cart storage and removes all it's items from memory.
  2789. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2790. void clif_clearcart(int fd)
  2791. {
  2792. WFIFOHEAD(fd, packet_len(0x12b));
  2793. WFIFOW(fd,0) = 0x12b;
  2794. WFIFOSET(fd, packet_len(0x12b));
  2795. }
  2796. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2797. /// 01eb <account id>.L <x>.W <y>.W
  2798. void clif_guild_xy(map_session_data *sd)
  2799. {
  2800. unsigned char buf[10];
  2801. nullpo_retv(sd);
  2802. WBUFW(buf,0)=0x1eb;
  2803. WBUFL(buf,2)=sd->status.account_id;
  2804. WBUFW(buf,6)=sd->bl.x;
  2805. WBUFW(buf,8)=sd->bl.y;
  2806. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2807. }
  2808. /*==========================================
  2809. * Sends x/y dot to a single fd. [Skotlex]
  2810. *------------------------------------------*/
  2811. void clif_guild_xy_single(int fd, map_session_data *sd)
  2812. {
  2813. if( sd->bg_id )
  2814. return;
  2815. WFIFOHEAD(fd,packet_len(0x1eb));
  2816. WFIFOW(fd,0)=0x1eb;
  2817. WFIFOL(fd,2)=sd->status.account_id;
  2818. WFIFOW(fd,6)=sd->bl.x;
  2819. WFIFOW(fd,8)=sd->bl.y;
  2820. WFIFOSET(fd,packet_len(0x1eb));
  2821. }
  2822. // Guild XY locators [Valaris]
  2823. void clif_guild_xy_remove(map_session_data *sd)
  2824. {
  2825. unsigned char buf[10];
  2826. nullpo_retv(sd);
  2827. WBUFW(buf,0)=0x1eb;
  2828. WBUFL(buf,2)=sd->status.account_id;
  2829. WBUFW(buf,6)=-1;
  2830. WBUFW(buf,8)=-1;
  2831. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2832. }
  2833. /*==========================================
  2834. * Load castle list for guild UI. [Asheraf] / [Balfear]
  2835. *------------------------------------------*/
  2836. void clif_guild_castle_list(map_session_data& sd){
  2837. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2838. auto &g = sd.guild;
  2839. if (g == nullptr)
  2840. return;
  2841. int castle_count = guild_checkcastles(g->guild);
  2842. if (castle_count > 0) {
  2843. struct PACKET_ZC_GUILD_AGIT_INFO* p = (struct PACKET_ZC_GUILD_AGIT_INFO*)packet_buffer;
  2844. p->packetType = HEADER_ZC_GUILD_AGIT_INFO;
  2845. p->packetLength = static_cast<int16>( sizeof( struct PACKET_ZC_GUILD_AGIT_INFO ) );
  2846. int i = 0;
  2847. for (const auto& gc : castle_db) {
  2848. if (gc.second->guild_id == g->guild.guild_id && gc.second->client_id) {
  2849. p->castle_list[i] = static_cast<int8>( gc.second->client_id );
  2850. p->packetLength += static_cast<int16>( sizeof( p->castle_list[0] ) );
  2851. ++i;
  2852. }
  2853. }
  2854. clif_send(p, p->packetLength, &sd.bl, SELF);
  2855. }
  2856. #endif
  2857. }
  2858. /*==========================================
  2859. * Send castle info Economy/Defence. [Asheraf] / [Balfear]
  2860. *------------------------------------------*/
  2861. void clif_guild_castleinfo(map_session_data& sd, std::shared_ptr<guild_castle> castle ){
  2862. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2863. if( castle->client_id == 0 ){
  2864. return;
  2865. }
  2866. struct PACKET_ZC_REQ_ACK_AGIT_INVESTMENT p = {};
  2867. p.packetType = HEADER_ZC_REQ_ACK_AGIT_INVESTMENT;
  2868. p.castle_id = static_cast<int8>( castle->client_id );
  2869. p.economy = castle->economy;
  2870. p.defense = castle->defense;
  2871. clif_send(&p, sizeof(p), &sd.bl, SELF);
  2872. #endif
  2873. }
  2874. /*==========================================
  2875. * Show teleport request result. [Asheraf] / [Balfear]
  2876. *------------------------------------------*/
  2877. void clif_guild_castle_teleport_res(map_session_data& sd, enum e_siege_teleport_result result){
  2878. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2879. struct PACKET_ZC_REQ_ACK_MOVE_GUILD_AGIT p = {};
  2880. p.packetType = HEADER_ZC_REQ_ACK_MOVE_GUILD_AGIT;
  2881. p.result = static_cast<int16>( result );
  2882. clif_send(&p, sizeof(p), &sd.bl, SELF);
  2883. #endif
  2884. }
  2885. /*==========================================
  2886. * Request castle info. [Asheraf] / [Balfear]
  2887. *------------------------------------------*/
  2888. void clif_parse_guild_castle_info_request(int fd, map_session_data* sd){
  2889. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515
  2890. const struct PACKET_CZ_REQ_AGIT_INVESTMENT* p = (struct PACKET_CZ_REQ_AGIT_INVESTMENT*)RFIFOP(fd, 0);
  2891. auto &g = sd->guild;
  2892. if (g == nullptr)
  2893. return;
  2894. std::shared_ptr<guild_castle> gc = castle_db.find_by_clientid( p->castle_id );
  2895. if (gc == nullptr)
  2896. return;
  2897. if (gc->guild_id != g->guild.guild_id)
  2898. return;
  2899. clif_guild_castleinfo(*sd, gc);
  2900. #endif
  2901. }
  2902. /*==========================================
  2903. * Teleport to castle. [Asheraf] / [Balfear]
  2904. *------------------------------------------*/
  2905. void clif_parse_guild_castle_teleport_request(int fd, map_session_data* sd){
  2906. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515
  2907. const struct PACKET_CZ_REQ_MOVE_GUILD_AGIT* p = (struct PACKET_CZ_REQ_MOVE_GUILD_AGIT*)RFIFOP(fd, 0);
  2908. auto &g = sd->guild;
  2909. if (g == nullptr)
  2910. return;
  2911. std::shared_ptr<guild_castle> gc = castle_db.find_by_clientid( p->castle_id );
  2912. if (gc == nullptr)
  2913. return;
  2914. if (!gc->warp_enabled)
  2915. return;
  2916. if (gc->guild_id != g->guild.guild_id)
  2917. return;
  2918. if (map_getmapflag(sd->bl.m, MF_GVG_CASTLE)
  2919. || map_getmapflag(sd->bl.m, MF_NOTELEPORT)
  2920. || map_getmapflag(sd->bl.m, MF_NOWARP))
  2921. return;
  2922. uint32 zeny = gc->zeny;
  2923. switch( gc->type ){
  2924. case WOE_FIRST_EDITION:
  2925. if( agit_flag ){
  2926. zeny = gc->zeny_siege;
  2927. }
  2928. break;
  2929. case WOE_SECOND_EDITION:
  2930. if( agit2_flag ){
  2931. zeny = gc->zeny_siege;
  2932. }
  2933. break;
  2934. case WOE_THIRD_EDITION:
  2935. if( agit3_flag ){
  2936. zeny = gc->zeny_siege;
  2937. }
  2938. break;
  2939. }
  2940. if (zeny && pc_payzeny(sd, zeny, LOG_TYPE_OTHER)) {
  2941. clif_guild_castle_teleport_res(*sd, SIEGE_TP_NOT_ENOUGH_ZENY);
  2942. return;
  2943. }
  2944. pc_setpos(sd, gc->mapindex, gc->warp_x, gc->warp_y, CLR_OUTSIGHT);
  2945. #endif
  2946. }
  2947. /*==========================================
  2948. *
  2949. *------------------------------------------*/
  2950. static int clif_hpmeter_sub( struct block_list *bl, va_list ap ){
  2951. map_session_data* sd = va_arg( ap, map_session_data* );
  2952. map_session_data* tsd = BL_CAST( BL_PC, bl );
  2953. nullpo_ret(sd);
  2954. nullpo_ret(tsd);
  2955. if( pc_has_permission( tsd, PC_PERM_VIEW_HPMETER ) ){
  2956. clif_hpmeter_single( *tsd, sd->status.account_id, sd->battle_status.hp, sd->battle_status.max_hp );
  2957. }
  2958. return 0;
  2959. }
  2960. /*==========================================
  2961. * Server tells all players that are allowed to view HP bars
  2962. * and are nearby 'sd' that 'sd' hp bar was updated.
  2963. *------------------------------------------*/
  2964. static int clif_hpmeter(map_session_data *sd)
  2965. {
  2966. nullpo_ret(sd);
  2967. map_foreachinallarea(clif_hpmeter_sub, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd);
  2968. return 0;
  2969. }
  2970. /**
  2971. * Send HP bar update to others.
  2972. * @param sd: Player invoking update
  2973. */
  2974. void clif_update_hp(map_session_data &sd) {
  2975. if (map_getmapdata(sd.bl.m)->hpmeter_visible)
  2976. clif_hpmeter(&sd);
  2977. if (!battle_config.party_hp_mode && sd.status.party_id)
  2978. clif_party_hp( sd );
  2979. if (sd.bg_id)
  2980. clif_bg_hp(&sd);
  2981. }
  2982. /// Notifies client of a character parameter change.
  2983. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2984. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2985. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2986. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2987. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2988. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2989. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2990. /// TODO: Extract individual packets.
  2991. /// FIXME: Packet lengths from packet_len(cmd)
  2992. void clif_updatestatus(map_session_data *sd,int type)
  2993. {
  2994. int fd,len=8;
  2995. nullpo_retv(sd);
  2996. fd=sd->fd;
  2997. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2998. return;
  2999. WFIFOHEAD(fd, 14);
  3000. WFIFOW(fd,0)=0xb0;
  3001. WFIFOW(fd,2)=type;
  3002. switch(type){
  3003. // 00b0
  3004. case SP_WEIGHT:
  3005. pc_updateweightstatus(sd);
  3006. WFIFOHEAD(fd,14);
  3007. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  3008. WFIFOW(fd,2)=type;
  3009. WFIFOL(fd,4)=sd->weight;
  3010. break;
  3011. case SP_MAXWEIGHT:
  3012. WFIFOL(fd,4)=sd->max_weight;
  3013. break;
  3014. case SP_SPEED:
  3015. WFIFOL(fd,4)=sd->battle_status.speed;
  3016. break;
  3017. case SP_BASELEVEL:
  3018. WFIFOL(fd,4)=sd->status.base_level;
  3019. break;
  3020. case SP_JOBLEVEL:
  3021. WFIFOL(fd,4)=sd->status.job_level;
  3022. break;
  3023. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  3024. WFIFOL(fd,4)=sd->status.karma;
  3025. break;
  3026. case SP_MANNER:
  3027. WFIFOL(fd,4)=sd->status.manner;
  3028. break;
  3029. case SP_STATUSPOINT:
  3030. WFIFOL(fd,4)=sd->status.status_point;
  3031. break;
  3032. case SP_SKILLPOINT:
  3033. WFIFOL(fd,4)=sd->status.skill_point;
  3034. break;
  3035. case SP_HIT:
  3036. WFIFOL(fd,4)=sd->battle_status.hit;
  3037. break;
  3038. case SP_FLEE1:
  3039. WFIFOL(fd,4)=sd->battle_status.flee;
  3040. break;
  3041. case SP_FLEE2:
  3042. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  3043. break;
  3044. case SP_MAXHP:
  3045. WFIFOL(fd,4)=sd->battle_status.max_hp;
  3046. break;
  3047. case SP_MAXSP:
  3048. WFIFOL(fd,4)=sd->battle_status.max_sp;
  3049. break;
  3050. case SP_HP:
  3051. // On officials the HP never go below 1, even if you die [Lemongrass]
  3052. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  3053. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  3054. break;
  3055. case SP_SP:
  3056. WFIFOL(fd,4)=sd->battle_status.sp;
  3057. break;
  3058. case SP_ASPD:
  3059. WFIFOL(fd,4)=sd->battle_status.amotion;
  3060. break;
  3061. case SP_ATK1:
  3062. WFIFOL(fd,4)=pc_leftside_atk(sd);
  3063. break;
  3064. case SP_DEF1:
  3065. WFIFOL(fd,4)=pc_leftside_def(sd);
  3066. break;
  3067. case SP_MDEF1:
  3068. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  3069. break;
  3070. case SP_ATK2:
  3071. WFIFOL(fd,4)=pc_rightside_atk(sd);
  3072. break;
  3073. case SP_DEF2:
  3074. WFIFOL(fd,4)=pc_rightside_def(sd);
  3075. break;
  3076. case SP_MDEF2: {
  3077. //negative check (in case you have something like Berserk active)
  3078. int mdef2 = pc_rightside_mdef(sd);
  3079. WFIFOL(fd,4)=
  3080. #ifndef RENEWAL
  3081. ( mdef2 < 0 ) ? 0 :
  3082. #endif
  3083. mdef2;
  3084. }
  3085. break;
  3086. case SP_CRITICAL:
  3087. WFIFOL(fd,4)=sd->battle_status.cri/10;
  3088. break;
  3089. case SP_MATK1:
  3090. WFIFOL(fd,4)=pc_rightside_matk(sd);
  3091. break;
  3092. case SP_MATK2:
  3093. WFIFOL(fd,4)=pc_leftside_matk(sd);
  3094. break;
  3095. case SP_ZENY:
  3096. WFIFOW(fd,0)=0xb1;
  3097. WFIFOL(fd,4)=sd->status.zeny;
  3098. break;
  3099. #if PACKETVER >= 20170830
  3100. case SP_BASEEXP:
  3101. WFIFOW(fd,0)=0xacb;
  3102. WFIFOQ(fd,4)=client_exp(sd->status.base_exp);
  3103. len = packet_len(0xacb);
  3104. break;
  3105. case SP_JOBEXP:
  3106. WFIFOW(fd,0)=0xacb;
  3107. WFIFOQ(fd,4)=client_exp(sd->status.job_exp);
  3108. len = packet_len(0xacb);
  3109. break;
  3110. case SP_NEXTBASEEXP:
  3111. WFIFOW(fd,0)=0xacb;
  3112. WFIFOQ(fd,4)=client_exp(pc_nextbaseexp(sd));
  3113. len = packet_len(0xacb);
  3114. break;
  3115. case SP_NEXTJOBEXP:
  3116. WFIFOW(fd,0)=0xacb;
  3117. WFIFOQ(fd,4)=client_exp(pc_nextjobexp(sd));
  3118. len = packet_len(0xacb);
  3119. break;
  3120. #else
  3121. case SP_BASEEXP:
  3122. WFIFOW(fd,0)=0xb1;
  3123. WFIFOL(fd,4)=client_exp(sd->status.base_exp);
  3124. break;
  3125. case SP_JOBEXP:
  3126. WFIFOW(fd,0)=0xb1;
  3127. WFIFOL(fd,4)=client_exp(sd->status.job_exp);
  3128. break;
  3129. case SP_NEXTBASEEXP:
  3130. WFIFOW(fd,0)=0xb1;
  3131. WFIFOL(fd,4)= client_exp(pc_nextbaseexp(sd));
  3132. break;
  3133. case SP_NEXTJOBEXP:
  3134. WFIFOW(fd,0)=0xb1;
  3135. WFIFOL(fd,4)= client_exp(pc_nextjobexp(sd));
  3136. break;
  3137. #endif
  3138. /**
  3139. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3140. **/
  3141. case SP_USTR:
  3142. case SP_UAGI:
  3143. case SP_UVIT:
  3144. case SP_UINT:
  3145. case SP_UDEX:
  3146. case SP_ULUK:
  3147. WFIFOW(fd,0)=0xbe;
  3148. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  3149. len=5;
  3150. break;
  3151. /**
  3152. * Tells the client how far it is allowed to attack (weapon range)
  3153. **/
  3154. case SP_ATTACKRANGE:
  3155. WFIFOW(fd,0)=0x13a;
  3156. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  3157. len=4;
  3158. break;
  3159. case SP_STR:
  3160. WFIFOW(fd,0)=0x141;
  3161. WFIFOL(fd,2)=type;
  3162. WFIFOL(fd,6)=sd->status.str;
  3163. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  3164. len=14;
  3165. break;
  3166. case SP_AGI:
  3167. WFIFOW(fd,0)=0x141;
  3168. WFIFOL(fd,2)=type;
  3169. WFIFOL(fd,6)=sd->status.agi;
  3170. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  3171. len=14;
  3172. break;
  3173. case SP_VIT:
  3174. WFIFOW(fd,0)=0x141;
  3175. WFIFOL(fd,2)=type;
  3176. WFIFOL(fd,6)=sd->status.vit;
  3177. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  3178. len=14;
  3179. break;
  3180. case SP_INT:
  3181. WFIFOW(fd,0)=0x141;
  3182. WFIFOL(fd,2)=type;
  3183. WFIFOL(fd,6)=sd->status.int_;
  3184. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  3185. len=14;
  3186. break;
  3187. case SP_DEX:
  3188. WFIFOW(fd,0)=0x141;
  3189. WFIFOL(fd,2)=type;
  3190. WFIFOL(fd,6)=sd->status.dex;
  3191. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  3192. len=14;
  3193. break;
  3194. case SP_LUK:
  3195. WFIFOW(fd,0)=0x141;
  3196. WFIFOL(fd,2)=type;
  3197. WFIFOL(fd,6)=sd->status.luk;
  3198. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  3199. len=14;
  3200. break;
  3201. case SP_CARTINFO:
  3202. WFIFOW(fd,0)=0x121;
  3203. WFIFOW(fd,2)=sd->cart_num;
  3204. WFIFOW(fd,4)=MAX_CART;
  3205. WFIFOL(fd,6)=sd->cart_weight;
  3206. WFIFOL(fd,10)=sd->cart_weight_max;
  3207. len=14;
  3208. break;
  3209. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3210. case SP_AP:
  3211. WFIFOL(fd, 4) = sd->battle_status.ap;
  3212. break;
  3213. case SP_TRAITPOINT:
  3214. WFIFOL(fd, 4) = sd->status.trait_point;
  3215. break;
  3216. case SP_MAXAP:
  3217. WFIFOL(fd, 4) = sd->battle_status.max_ap;
  3218. break;
  3219. case SP_POW:
  3220. WFIFOW(fd, 0) = 0x141;
  3221. WFIFOL(fd, 2) = type;
  3222. WFIFOL(fd, 6) = sd->status.pow;
  3223. WFIFOL(fd, 10) = sd->battle_status.pow - sd->status.pow;
  3224. len = 14;
  3225. break;
  3226. case SP_STA:
  3227. WFIFOW(fd, 0) = 0x141;
  3228. WFIFOL(fd, 2) = type;
  3229. WFIFOL(fd, 6) = sd->status.sta;
  3230. WFIFOL(fd, 10) = sd->battle_status.sta - sd->status.sta;
  3231. len = 14;
  3232. break;
  3233. case SP_WIS:
  3234. WFIFOW(fd, 0) = 0x141;
  3235. WFIFOL(fd, 2) = type;
  3236. WFIFOL(fd, 6) = sd->status.wis;
  3237. WFIFOL(fd, 10) = sd->battle_status.wis - sd->status.wis;
  3238. len = 14;
  3239. break;
  3240. case SP_SPL:
  3241. WFIFOW(fd, 0) = 0x141;
  3242. WFIFOL(fd, 2) = type;
  3243. WFIFOL(fd, 6) = sd->status.spl;
  3244. WFIFOL(fd, 10) = sd->battle_status.spl - sd->status.spl;
  3245. len = 14;
  3246. break;
  3247. case SP_CON:
  3248. WFIFOW(fd, 0) = 0x141;
  3249. WFIFOL(fd, 2) = type;
  3250. WFIFOL(fd, 6) = sd->status.con;
  3251. WFIFOL(fd, 10) = sd->battle_status.con - sd->status.con;
  3252. len = 14;
  3253. break;
  3254. case SP_CRT:
  3255. WFIFOW(fd, 0) = 0x141;
  3256. WFIFOL(fd, 2) = type;
  3257. WFIFOL(fd, 6) = sd->status.crt;
  3258. WFIFOL(fd, 10) = sd->battle_status.crt - sd->status.crt;
  3259. len = 14;
  3260. break;
  3261. case SP_UPOW:
  3262. case SP_USTA:
  3263. case SP_UWIS:
  3264. case SP_USPL:
  3265. case SP_UCON:
  3266. case SP_UCRT:
  3267. WFIFOW(fd, 0) = 0xbe;
  3268. WFIFOB(fd, 4) = pc_need_trait_point(sd,type-SP_UPOW+SP_POW, 1);
  3269. len = 5;
  3270. break;
  3271. case SP_PATK:
  3272. WFIFOL(fd, 4) = sd->battle_status.patk;
  3273. break;
  3274. case SP_SMATK:
  3275. WFIFOL(fd, 4) = sd->battle_status.smatk;
  3276. break;
  3277. case SP_RES:
  3278. WFIFOL(fd, 4) = sd->battle_status.res;
  3279. break;
  3280. case SP_MRES:
  3281. WFIFOL(fd, 4) = sd->battle_status.mres;
  3282. break;
  3283. case SP_HPLUS:
  3284. WFIFOL(fd, 4) = sd->battle_status.hplus;
  3285. break;
  3286. case SP_CRATE:
  3287. WFIFOL(fd, 4) = sd->battle_status.crate;
  3288. break;
  3289. #else
  3290. case SP_AP:
  3291. case SP_TRAITPOINT:
  3292. case SP_MAXAP:
  3293. case SP_POW:
  3294. case SP_STA:
  3295. case SP_WIS:
  3296. case SP_SPL:
  3297. case SP_CON:
  3298. case SP_CRT:
  3299. case SP_UPOW:
  3300. case SP_USTA:
  3301. case SP_UWIS:
  3302. case SP_USPL:
  3303. case SP_UCON:
  3304. case SP_UCRT:
  3305. case SP_PATK:
  3306. case SP_SMATK:
  3307. case SP_RES:
  3308. case SP_MRES:
  3309. case SP_HPLUS:
  3310. case SP_CRATE:
  3311. // 4th job status are not supported by older clients
  3312. return;
  3313. #endif
  3314. default:
  3315. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3316. return;
  3317. }
  3318. WFIFOSET(fd,len);
  3319. // Additional update packets that should be sent right after
  3320. switch( type ){
  3321. case SP_BASELEVEL:
  3322. if( sd->status.party_id ){
  3323. struct party_data* p;
  3324. int i;
  3325. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3326. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3327. if( i < MAX_PARTY ){
  3328. p->party.member[i].lv = sd->status.base_level;
  3329. clif_party_job_and_level( *sd );
  3330. }
  3331. }
  3332. }
  3333. break;
  3334. case SP_HP:
  3335. clif_update_hp(*sd);
  3336. break;
  3337. }
  3338. }
  3339. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3340. /// 01ab <account id>.L <var id>.W <value>.L
  3341. void clif_changestatus(map_session_data* sd,int type,int val)
  3342. {
  3343. unsigned char buf[12];
  3344. nullpo_retv(sd);
  3345. WBUFW(buf,0)=0x1ab;
  3346. WBUFL(buf,2)=sd->bl.id;
  3347. WBUFW(buf,6)=type;
  3348. switch(type)
  3349. {
  3350. case SP_MANNER:
  3351. WBUFL(buf,8)=val;
  3352. break;
  3353. default:
  3354. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3355. return;
  3356. }
  3357. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3358. }
  3359. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3360. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3361. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3362. struct PACKET_ZC_SPRITE_CHANGE p;
  3363. p.packetType = sendLookType;
  3364. p.AID = id;
  3365. p.type = type;
  3366. p.val = val;
  3367. #if PACKETVER >= 4
  3368. p.val2 = val2;
  3369. #endif
  3370. clif_send( &p, sizeof( p ), bl, target );
  3371. }
  3372. /// Updates sprite/style properties of an object.
  3373. void clif_changelook(struct block_list *bl, int type, int val) {
  3374. map_session_data* sd;
  3375. status_change* sc;
  3376. struct view_data* vd;
  3377. enum send_target target = AREA;
  3378. int val2 = 0;
  3379. nullpo_retv(bl);
  3380. sd = BL_CAST(BL_PC, bl);
  3381. sc = status_get_sc(bl);
  3382. vd = status_get_viewdata(bl);
  3383. if( vd ) //temp hack to let Warp Portal change appearance
  3384. switch(type) {
  3385. case LOOK_WEAPON:
  3386. if (sd) {
  3387. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3388. val = vd->weapon;
  3389. }
  3390. else
  3391. vd->weapon = val;
  3392. break;
  3393. case LOOK_SHIELD:
  3394. if (sd) {
  3395. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3396. val = vd->shield;
  3397. }
  3398. else
  3399. vd->shield = val;
  3400. break;
  3401. case LOOK_BASE:
  3402. if (!sd)
  3403. break;
  3404. if ( val == JT_INVISIBLE )
  3405. return;
  3406. if (sd->sc.option&OPTION_COSTUME)
  3407. vd->weapon = vd->shield = 0;
  3408. if (!vd->cloth_color)
  3409. break;
  3410. if (sd) {
  3411. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3412. vd->cloth_color = 0;
  3413. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3414. vd->cloth_color = 0;
  3415. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3416. vd->cloth_color = 0;
  3417. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3418. vd->cloth_color = 0;
  3419. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3420. vd->cloth_color = 0;
  3421. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3422. vd->body_style = 0;
  3423. }
  3424. break;
  3425. case LOOK_HAIR:
  3426. vd->hair_style = val;
  3427. break;
  3428. case LOOK_HEAD_BOTTOM:
  3429. vd->head_bottom = val;
  3430. break;
  3431. case LOOK_HEAD_TOP:
  3432. vd->head_top = val;
  3433. break;
  3434. case LOOK_HEAD_MID:
  3435. vd->head_mid = val;
  3436. break;
  3437. case LOOK_HAIR_COLOR:
  3438. vd->hair_color = val;
  3439. break;
  3440. case LOOK_CLOTHES_COLOR:
  3441. if (val && sd) {
  3442. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3443. val = 0;
  3444. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3445. val = 0;
  3446. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3447. val = 0;
  3448. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3449. val = 0;
  3450. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3451. val = 0;
  3452. }
  3453. vd->cloth_color = val;
  3454. break;
  3455. case LOOK_SHOES:
  3456. #if PACKETVER > 3
  3457. if (sd) {
  3458. int n;
  3459. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3460. if(sd->inventory_data[n]->view_id > 0)
  3461. val = sd->inventory_data[n]->view_id;
  3462. else
  3463. val = sd->inventory.u.items_inventory[n].nameid;
  3464. } else
  3465. val = 0;
  3466. }
  3467. #endif
  3468. //Shoes? No packet uses this....
  3469. break;
  3470. case LOOK_BODY:
  3471. // unknown purpose
  3472. break;
  3473. case LOOK_ROBE:
  3474. #if PACKETVER < 20110111
  3475. return;
  3476. #else
  3477. vd->robe = val;
  3478. #endif
  3479. break;
  3480. case LOOK_BODY2:
  3481. #if PACKETVER < 20150513
  3482. return;
  3483. #else
  3484. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3485. val = 0;
  3486. vd->body_style = val;
  3487. #endif
  3488. break;
  3489. }
  3490. // prevent leaking the presence of GM-hidden objects
  3491. if( sc && sc->option&OPTION_INVISIBLE )
  3492. target = SELF;
  3493. #if PACKETVER < 4
  3494. if (target != SELF && bl->type == BL_NPC && (((TBL_NPC*)bl)->is_invisible))
  3495. target = SELF;
  3496. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3497. #else
  3498. if (bl->type != BL_NPC) {
  3499. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3500. type = LOOK_WEAPON;
  3501. val = (vd ? vd->weapon : 0);
  3502. val2 = (vd ? vd->shield : 0);
  3503. }
  3504. if (disguised(bl)) {
  3505. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3506. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3507. } else
  3508. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3509. } else
  3510. unit_refresh(bl);
  3511. #endif
  3512. }
  3513. //Sends a change-base-look packet required for traps as they are triggered.
  3514. void clif_changetraplook(struct block_list *bl,int val) {
  3515. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3516. }
  3517. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3518. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3519. clif_sprite_change(bl, id, type, val, 0, target);
  3520. }
  3521. /// Character status (ZC_STATUS).
  3522. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3523. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3524. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3525. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3526. void clif_initialstatus(map_session_data *sd) {
  3527. int fd, mdef2;
  3528. unsigned char *buf;
  3529. nullpo_retv(sd);
  3530. fd=sd->fd;
  3531. WFIFOHEAD(fd, packet_len(0xbd));
  3532. buf = WFIFOP(fd,0);
  3533. WBUFW(buf,0) = 0xbd;
  3534. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3535. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3536. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3537. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3538. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3539. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3540. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3541. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3542. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3543. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3544. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3545. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3546. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3547. WBUFW(buf,16) = pc_leftside_atk(sd);
  3548. WBUFW(buf,18) = pc_rightside_atk(sd);
  3549. WBUFW(buf,20) = pc_rightside_matk(sd);
  3550. WBUFW(buf,22) = pc_leftside_matk(sd);
  3551. WBUFW(buf,24) = pc_leftside_def(sd);
  3552. WBUFW(buf,26) = pc_rightside_def(sd);
  3553. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3554. mdef2 = pc_rightside_mdef(sd);
  3555. WBUFW(buf,30) =
  3556. #ifndef RENEWAL
  3557. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3558. #endif
  3559. mdef2;
  3560. WBUFW(buf,32) = sd->battle_status.hit;
  3561. WBUFW(buf,34) = sd->battle_status.flee;
  3562. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3563. WBUFW(buf,38) = sd->battle_status.cri/10;
  3564. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3565. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3566. WFIFOSET(fd, packet_len(0xbd));
  3567. clif_updatestatus(sd, SP_STR);
  3568. clif_updatestatus(sd, SP_AGI);
  3569. clif_updatestatus(sd, SP_VIT);
  3570. clif_updatestatus(sd, SP_INT);
  3571. clif_updatestatus(sd, SP_DEX);
  3572. clif_updatestatus(sd, SP_LUK);
  3573. clif_updatestatus(sd, SP_ATTACKRANGE);
  3574. clif_updatestatus(sd, SP_ASPD);
  3575. #ifdef RENEWAL
  3576. clif_updatestatus(sd, SP_POW);
  3577. clif_updatestatus(sd, SP_STA);
  3578. clif_updatestatus(sd, SP_WIS);
  3579. clif_updatestatus(sd, SP_SPL);
  3580. clif_updatestatus(sd, SP_CON);
  3581. clif_updatestatus(sd, SP_CRT);
  3582. clif_updatestatus(sd, SP_PATK);
  3583. clif_updatestatus(sd, SP_SMATK);
  3584. clif_updatestatus(sd, SP_RES);
  3585. clif_updatestatus(sd, SP_MRES);
  3586. clif_updatestatus(sd, SP_HPLUS);
  3587. clif_updatestatus(sd, SP_CRATE);
  3588. clif_updatestatus(sd, SP_TRAITPOINT);
  3589. clif_updatestatus(sd, SP_AP);
  3590. clif_updatestatus(sd, SP_MAXAP);
  3591. clif_updatestatus(sd, SP_UPOW);
  3592. clif_updatestatus(sd, SP_USTA);
  3593. clif_updatestatus(sd, SP_UWIS);
  3594. clif_updatestatus(sd, SP_USPL);
  3595. clif_updatestatus(sd, SP_UCON);
  3596. clif_updatestatus(sd, SP_UCRT);
  3597. #endif
  3598. }
  3599. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3600. /// 013c <index>.W
  3601. void clif_arrowequip(map_session_data *sd,int val) {
  3602. int fd;
  3603. nullpo_retv(sd);
  3604. #if PACKETVER >= 20121128
  3605. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3606. #endif
  3607. fd=sd->fd;
  3608. WFIFOHEAD(fd, packet_len(0x013c));
  3609. WFIFOW(fd,0) = 0x013c;
  3610. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3611. WFIFOSET(fd, packet_len(0x013c));
  3612. }
  3613. /// Ammunition action message (ZC_ACTION_FAILURE).
  3614. /// 013b <type>.W
  3615. /// type:
  3616. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3617. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3618. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3619. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3620. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3621. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3622. void clif_arrow_fail(map_session_data *sd,int type) {
  3623. int fd;
  3624. nullpo_retv(sd);
  3625. fd=sd->fd;
  3626. WFIFOHEAD(fd, packet_len(0x013b));
  3627. WFIFOW(fd,0) = 0x013b;
  3628. WFIFOW(fd,2) = type;
  3629. WFIFOSET(fd, packet_len(0x013b));
  3630. }
  3631. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3632. /// 01ad <packet len>.W { <name id>.W }*
  3633. void clif_arrow_create_list( map_session_data *sd ){
  3634. nullpo_retv( sd );
  3635. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  3636. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3637. int count = 0;
  3638. for (const auto &it : skill_arrow_db) {
  3639. t_itemid nameid = it.second->nameid;
  3640. if( !item_db.exists( nameid ) ){
  3641. continue;
  3642. }
  3643. int index = pc_search_inventory( sd, nameid );
  3644. if( index < 0 ){
  3645. continue;
  3646. }
  3647. if( sd->inventory.u.items_inventory[index].equip ){
  3648. continue;
  3649. }
  3650. if( !sd->inventory.u.items_inventory[index].identify ){
  3651. continue;
  3652. }
  3653. p->items[count].itemId = client_nameid( nameid );
  3654. count++;
  3655. }
  3656. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  3657. clif_send( p, p->packetLength, &sd->bl, SELF );
  3658. if( count > 0 ){
  3659. sd->menuskill_id = AC_MAKINGARROW;
  3660. sd->menuskill_val = count;
  3661. }
  3662. }
  3663. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3664. /// 00bc <status id>.W <result>.B <value>.B
  3665. /// status id:
  3666. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3667. /// result:
  3668. /// 0 = failure
  3669. /// 1 = success
  3670. void clif_statusupack(map_session_data *sd,int type,int ok,int val) {
  3671. int fd;
  3672. nullpo_retv(sd);
  3673. fd=sd->fd;
  3674. WFIFOHEAD(fd, packet_len(0xbc));
  3675. WFIFOW(fd,0) = 0xbc;
  3676. WFIFOW(fd,2) = type;
  3677. WFIFOB(fd,4) = ok;
  3678. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3679. WFIFOSET(fd, packet_len(0xbc));
  3680. }
  3681. /// Notifies the client about the result of a request to equip an item.
  3682. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3683. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3684. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3685. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3686. /// @ok: //inversed forv2 v5
  3687. /// 0 = failure
  3688. /// 1 = success
  3689. /// 2 = failure due to low level
  3690. void clif_equipitemack( map_session_data& sd, uint8 flag, int index, int pos ){
  3691. struct PACKET_ZC_REQ_WEAR_EQUIP_ACK p = {};
  3692. p.PacketType = HEADER_ZC_REQ_WEAR_EQUIP_ACK;
  3693. p.index = client_index( index );
  3694. p.wearLocation = pos;
  3695. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20100629
  3696. if( flag == ITEM_EQUIP_ACK_OK && sd.inventory_data[index]->equip&EQP_VISIBLE ){
  3697. p.wItemSpriteNumber = sd.inventory_data[index]->look;
  3698. }else{
  3699. p.wItemSpriteNumber = 0;
  3700. }
  3701. #endif
  3702. p.result = flag;
  3703. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  3704. }
  3705. /// Notifies the client about the result of a request to take off an item.
  3706. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3707. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3708. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3709. /// @ok : //inversed for v2 v5
  3710. /// 0 = failure
  3711. /// 1 = success
  3712. void clif_unequipitemack(map_session_data *sd,int n,int pos,int ok)
  3713. {
  3714. int fd, header, offs = 0;
  3715. #if PACKETVER >= 20130000
  3716. header = 0x99a;
  3717. ok = ok ? 0 : 1;
  3718. #elif PACKETVER >= 20110824
  3719. header = 0x8d1;
  3720. ok = ok ? 0 : 1;
  3721. #else
  3722. header = 0xac;
  3723. #endif
  3724. nullpo_retv(sd);
  3725. fd=sd->fd;
  3726. WFIFOHEAD(fd, packet_len(header));
  3727. WFIFOW(fd,offs+0) = header;
  3728. WFIFOW(fd,offs+2) = n+2;
  3729. #if PACKETVER >= 20130000
  3730. WFIFOL(fd,offs+4) = pos;
  3731. offs += 2;
  3732. #else
  3733. WFIFOW(fd,offs+4) = pos;
  3734. #endif
  3735. WFIFOB(fd,offs+6) = ok;
  3736. WFIFOSET(fd, packet_len(header));
  3737. }
  3738. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3739. /// 019b <id>.L <effect id>.L
  3740. /// effect id:
  3741. /// 0 = base level up
  3742. /// 1 = job level up
  3743. /// 2 = refine failure
  3744. /// 3 = refine success
  3745. /// 4 = game over
  3746. /// 5 = pharmacy success
  3747. /// 6 = pharmacy failure
  3748. /// 7 = base level up (super novice)
  3749. /// 8 = job level up (super novice)
  3750. /// 9 = base level up (taekwon)
  3751. void clif_misceffect(struct block_list* bl,int type)
  3752. {
  3753. unsigned char buf[32];
  3754. nullpo_retv(bl);
  3755. WBUFW(buf,0) = 0x19b;
  3756. WBUFL(buf,2) = bl->id;
  3757. WBUFL(buf,6) = type;
  3758. clif_send(buf,packet_len(0x19b),bl,AREA);
  3759. }
  3760. /// Notifies clients in the area of a state change.
  3761. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3762. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3763. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3764. nullpo_retv( bl );
  3765. status_change* sc = status_get_sc( bl );
  3766. //How can an option change if there's no sc?
  3767. if( sc == nullptr ){
  3768. return;
  3769. }
  3770. map_session_data* sd = BL_CAST( BL_PC, bl );
  3771. struct PACKET_ZC_STATE_CHANGE p;
  3772. p.packetType = HEADER_ZC_STATE_CHANGE;
  3773. p.AID = bl->id;
  3774. p.bodyState = sc->opt1;
  3775. p.healthState = sc->opt2;
  3776. p.effectState = sc->option;
  3777. p.isPKModeON = sd ? sd->status.karma : false;
  3778. if( target == nullptr ){
  3779. if( disguised( bl ) ){
  3780. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3781. p.AID = disguised_bl_id( p.AID );
  3782. clif_send( &p, sizeof( p ), bl, SELF );
  3783. p.AID = disguised_bl_id( p.AID );
  3784. p.effectState = OPTION_INVISIBLE;
  3785. clif_send( &p, sizeof( p ), bl, SELF );
  3786. }else{
  3787. clif_send( &p, sizeof( p ), bl, AREA );
  3788. }
  3789. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3790. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3791. if( sc->getSCE(SC_PROVOKE) ){
  3792. const struct TimerData *td = get_timer( sc->getSCE(SC_PROVOKE)->timer );
  3793. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3794. }
  3795. }else{
  3796. if( disguised( bl ) ){
  3797. p.AID = disguised_bl_id( p.AID );
  3798. clif_send( &p, sizeof( p ), target, SELF );
  3799. p.AID = disguised_bl_id( p.AID );
  3800. p.effectState = OPTION_INVISIBLE;
  3801. clif_send( &p, sizeof( p ), target, SELF );
  3802. }else{
  3803. clif_send( &p, sizeof( p ), target, SELF );
  3804. }
  3805. }
  3806. }
  3807. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3808. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3809. void clif_changeoption2(struct block_list* bl)
  3810. {
  3811. unsigned char buf[20];
  3812. status_change *sc;
  3813. sc = status_get_sc(bl);
  3814. if (!sc) return; //How can an option change if there's no sc?
  3815. WBUFW(buf,0) = 0x28a;
  3816. WBUFL(buf,2) = bl->id;
  3817. WBUFL(buf,6) = sc->option;
  3818. WBUFL(buf,10) = clif_setlevel(bl);
  3819. WBUFL(buf,14) = sc->opt3;
  3820. if(disguised(bl)) {
  3821. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3822. WBUFL(buf,2) = disguised_bl_id( bl->id );
  3823. clif_send(buf,packet_len(0x28a),bl,SELF);
  3824. WBUFL(buf,2) = bl->id;
  3825. WBUFL(buf,6) = OPTION_INVISIBLE;
  3826. clif_send(buf,packet_len(0x28a),bl,SELF);
  3827. } else
  3828. clif_send(buf,packet_len(0x28a),bl,AREA);
  3829. }
  3830. /// Notifies the client about the result of an item use request.
  3831. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3832. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3833. void clif_useitemack( map_session_data *sd, int index, int amount, bool ok ){
  3834. nullpo_retv( sd );
  3835. int fd = sd->fd;
  3836. if( !session_isActive( fd ) ){
  3837. return;
  3838. }
  3839. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3840. return;
  3841. }
  3842. struct PACKET_ZC_USE_ITEM_ACK p;
  3843. p.packetType = useItemAckType;
  3844. p.index = index + 2;
  3845. #if PACKETVER > 3
  3846. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3847. p.AID = sd->bl.id;
  3848. #endif
  3849. p.amount = amount;
  3850. p.result = ok;
  3851. if( !ok ){
  3852. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3853. }else{
  3854. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3855. }
  3856. }
  3857. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3858. /// 00d6 <flag>.B
  3859. /// flag:
  3860. /// 0 = Room has been successfully created (opens chat room)
  3861. /// 1 = Room limit exceeded
  3862. /// 2 = Same room already exists
  3863. void clif_createchat(map_session_data* sd, int flag)
  3864. {
  3865. int fd;
  3866. nullpo_retv(sd);
  3867. fd = sd->fd;
  3868. WFIFOHEAD(fd,packet_len(0xd6));
  3869. WFIFOW(fd,0) = 0xd6;
  3870. WFIFOB(fd,2) = flag;
  3871. WFIFOSET(fd,packet_len(0xd6));
  3872. }
  3873. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3874. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3875. /// type:
  3876. /// 0 = private (password protected)
  3877. /// 1 = public
  3878. /// 2 = arena (npc waiting room)
  3879. /// 3 = PK zone (non-clickable)
  3880. void clif_dispchat(struct chat_data* cd, int fd)
  3881. {
  3882. unsigned char buf[128];
  3883. uint8 type;
  3884. if( cd == NULL || cd->owner == NULL )
  3885. return;
  3886. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3887. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3888. : 1;
  3889. WBUFW(buf, 0) = 0xd7;
  3890. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3891. WBUFL(buf, 4) = cd->owner->id;
  3892. WBUFL(buf, 8) = cd->bl.id;
  3893. WBUFW(buf,12) = cd->limit;
  3894. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3895. WBUFB(buf,16) = type;
  3896. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3897. if( session_isActive(fd) ) {
  3898. WFIFOHEAD(fd,WBUFW(buf,2));
  3899. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3900. WFIFOSET(fd,WBUFW(buf,2));
  3901. } else {
  3902. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3903. }
  3904. }
  3905. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3906. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3907. /// type:
  3908. /// 0 = private (password protected)
  3909. /// 1 = public
  3910. /// 2 = arena (npc waiting room)
  3911. /// 3 = PK zone (non-clickable)
  3912. void clif_changechatstatus(struct chat_data* cd)
  3913. {
  3914. unsigned char buf[128];
  3915. uint8 type;
  3916. if( cd == NULL || cd->usersd[0] == NULL )
  3917. return;
  3918. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3919. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3920. : 1;
  3921. WBUFW(buf, 0) = 0xdf;
  3922. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3923. WBUFL(buf, 4) = cd->owner->id;
  3924. WBUFL(buf, 8) = cd->bl.id;
  3925. WBUFW(buf,12) = cd->limit;
  3926. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3927. WBUFB(buf,16) = type;
  3928. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3929. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3930. }
  3931. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3932. /// 00d8 <chat id>.L
  3933. void clif_clearchat(struct chat_data *cd,int fd)
  3934. {
  3935. unsigned char buf[32];
  3936. nullpo_retv(cd);
  3937. WBUFW(buf,0) = 0xd8;
  3938. WBUFL(buf,2) = cd->bl.id;
  3939. if( session_isActive(fd) ) {
  3940. WFIFOHEAD(fd,packet_len(0xd8));
  3941. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3942. WFIFOSET(fd,packet_len(0xd8));
  3943. } else {
  3944. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3945. }
  3946. }
  3947. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3948. /// 00da <result>.B
  3949. /// result:
  3950. /// 0 = room full
  3951. /// 1 = wrong password
  3952. /// 2 = kicked
  3953. /// 3 = success (no message)
  3954. /// 4 = no enough zeny
  3955. /// 5 = too low level
  3956. /// 6 = too high level
  3957. /// 7 = unsuitable job class
  3958. void clif_joinchatfail(map_session_data *sd,int flag)
  3959. {
  3960. int fd;
  3961. nullpo_retv(sd);
  3962. fd = sd->fd;
  3963. WFIFOHEAD(fd,packet_len(0xda));
  3964. WFIFOW(fd,0) = 0xda;
  3965. WFIFOB(fd,2) = flag;
  3966. WFIFOSET(fd,packet_len(0xda));
  3967. }
  3968. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3969. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3970. /// role:
  3971. /// 0 = owner (menu)
  3972. /// 1 = normal
  3973. void clif_joinchatok(map_session_data *sd,struct chat_data* cd)
  3974. {
  3975. int fd;
  3976. int i,t;
  3977. nullpo_retv(sd);
  3978. nullpo_retv(cd);
  3979. fd = sd->fd;
  3980. if (!session_isActive(fd))
  3981. return;
  3982. t = (int)(cd->owner->type == BL_NPC);
  3983. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3984. WFIFOW(fd, 0) = 0xdb;
  3985. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3986. WFIFOL(fd, 4) = cd->bl.id;
  3987. if(cd->owner->type == BL_NPC){
  3988. WFIFOL(fd, 30) = 1;
  3989. WFIFOL(fd, 8) = 0;
  3990. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3991. for (i = 0; i < cd->users; i++) {
  3992. WFIFOL(fd, 8+(i+1)*28) = 1;
  3993. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3994. }
  3995. }else{
  3996. for (i = 0; i < cd->users; i++) {
  3997. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3998. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3999. }
  4000. }
  4001. WFIFOSET(fd, WFIFOW(fd, 2));
  4002. }
  4003. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  4004. /// 00dc <users>.W <name>.24B
  4005. void clif_addchat(struct chat_data* cd,map_session_data *sd)
  4006. {
  4007. unsigned char buf[29];
  4008. nullpo_retv(sd);
  4009. nullpo_retv(cd);
  4010. WBUFW(buf, 0) = 0xdc;
  4011. WBUFW(buf, 2) = cd->users;
  4012. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  4013. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  4014. }
  4015. /// Announce the new owner (ZC_ROLE_CHANGE).
  4016. /// 00e1 <role>.L <nick>.24B
  4017. /// role:
  4018. /// 0 = owner (menu)
  4019. /// 1 = normal
  4020. void clif_changechatowner(struct chat_data* cd, map_session_data* sd)
  4021. {
  4022. unsigned char buf[64];
  4023. nullpo_retv(sd);
  4024. nullpo_retv(cd);
  4025. WBUFW(buf, 0) = 0xe1;
  4026. WBUFL(buf, 2) = 1;
  4027. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  4028. WBUFW(buf,30) = 0xe1;
  4029. WBUFL(buf,32) = 0;
  4030. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  4031. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  4032. }
  4033. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  4034. /// 00dd <users>.W <nick>.24B <flag>.B
  4035. /// flag:
  4036. /// 0 = left
  4037. /// 1 = kicked
  4038. void clif_leavechat(struct chat_data* cd, map_session_data* sd, bool flag)
  4039. {
  4040. unsigned char buf[32];
  4041. nullpo_retv(sd);
  4042. nullpo_retv(cd);
  4043. WBUFW(buf, 0) = 0xdd;
  4044. WBUFW(buf, 2) = cd->users-1;
  4045. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  4046. WBUFB(buf,28) = flag;
  4047. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  4048. }
  4049. /// Opens a trade request window from char 'name'.
  4050. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  4051. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  4052. void clif_traderequest(map_session_data* sd, const char* name)
  4053. {
  4054. int fd = sd->fd;
  4055. #if PACKETVER < 6
  4056. WFIFOHEAD(fd,packet_len(0xe5));
  4057. WFIFOW(fd,0) = 0xe5;
  4058. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  4059. WFIFOSET(fd,packet_len(0xe5));
  4060. #else
  4061. map_session_data* tsd = map_id2sd(sd->trade_partner);
  4062. if( !tsd ) return;
  4063. WFIFOHEAD(fd,packet_len(0x1f4));
  4064. WFIFOW(fd,0) = 0x1f4;
  4065. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  4066. WFIFOL(fd,26) = tsd->status.char_id;
  4067. WFIFOW(fd,30) = tsd->status.base_level;
  4068. WFIFOSET(fd,packet_len(0x1f4));
  4069. #endif
  4070. }
  4071. /// Reply to a trade-request.
  4072. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  4073. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  4074. /// result:
  4075. /// 0 = Char is too far
  4076. /// 1 = Character does not exist
  4077. /// 2 = Trade failed
  4078. /// 3 = Accept
  4079. /// 4 = Cancel
  4080. /// 5 = Busy
  4081. void clif_tradestart(map_session_data* sd, uint8 type)
  4082. {
  4083. int fd = sd->fd;
  4084. map_session_data* tsd = map_id2sd(sd->trade_partner);
  4085. if( PACKETVER < 6 || !tsd ) {
  4086. WFIFOHEAD(fd,packet_len(0xe7));
  4087. WFIFOW(fd,0) = 0xe7;
  4088. WFIFOB(fd,2) = type;
  4089. WFIFOSET(fd,packet_len(0xe7));
  4090. } else {
  4091. WFIFOHEAD(fd,packet_len(0x1f5));
  4092. WFIFOW(fd,0) = 0x1f5;
  4093. WFIFOB(fd,2) = type;
  4094. WFIFOL(fd,3) = tsd->status.char_id;
  4095. WFIFOW(fd,7) = tsd->status.base_level;
  4096. WFIFOSET(fd,packet_len(0x1f5));
  4097. }
  4098. }
  4099. /// Notifies the client about an item from other player in current trade.
  4100. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  4101. /// 080f <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM2)
  4102. /// 0a09 <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ADD_EXCHANGE_ITEM3)
  4103. void clif_tradeadditem( map_session_data* sd, map_session_data* tsd, int index, int amount ){
  4104. nullpo_retv( sd );
  4105. nullpo_retv( tsd );
  4106. int fd = tsd->fd;
  4107. if( !session_isActive( fd ) ){
  4108. return;
  4109. }
  4110. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  4111. if( index ){
  4112. index = server_index( index );
  4113. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  4114. return;
  4115. }
  4116. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  4117. #if PACKETVER >= 20100223
  4118. p.itemType = sd->inventory_data[index]->type;
  4119. #endif
  4120. p.identified = sd->inventory.u.items_inventory[index].identify;
  4121. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  4122. p.refine = sd->inventory.u.items_inventory[index].refine;
  4123. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  4124. #if PACKETVER >= 20150226
  4125. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[index] );
  4126. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4127. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4128. p.look = sd->inventory_data[index]->look;
  4129. p.grade = sd->inventory.u.items_inventory[index].enchantgrade;
  4130. #endif
  4131. #endif
  4132. }else{
  4133. p = {};
  4134. }
  4135. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4136. p.amount = amount;
  4137. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4138. }
  4139. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4140. /// 00ea <index>.W <result>.B
  4141. /// result:
  4142. /// 0 = success
  4143. /// 1 = overweight
  4144. /// 2 = trade canceled
  4145. void clif_tradeitemok(map_session_data& sd, int index, e_exitem_add_result result)
  4146. {
  4147. PACKET_ZC_ACK_ADD_EXCHANGE_ITEM p = {};
  4148. p.packetType = HEADER_ZC_ACK_ADD_EXCHANGE_ITEM;
  4149. p.index = client_index(index);
  4150. p.result = static_cast<uint8>(result);
  4151. clif_send(&p, sizeof(p), &sd.bl, SELF);
  4152. }
  4153. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  4154. /// 00ec <who>.B
  4155. /// who:
  4156. /// 0 = self
  4157. /// 1 = other player
  4158. void clif_tradedeal_lock(map_session_data* sd, int fail)
  4159. {
  4160. int fd;
  4161. nullpo_retv(sd);
  4162. fd = sd->fd;
  4163. WFIFOHEAD(fd,packet_len(0xec));
  4164. WFIFOW(fd,0) = 0xec;
  4165. WFIFOB(fd,2) = fail;
  4166. WFIFOSET(fd,packet_len(0xec));
  4167. }
  4168. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  4169. /// 00ee
  4170. void clif_tradecancelled(map_session_data* sd)
  4171. {
  4172. int fd;
  4173. nullpo_retv(sd);
  4174. fd = sd->fd;
  4175. WFIFOHEAD(fd,packet_len(0xee));
  4176. WFIFOW(fd,0) = 0xee;
  4177. WFIFOSET(fd,packet_len(0xee));
  4178. }
  4179. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  4180. /// 00f0 <result>.B
  4181. /// result:
  4182. /// 0 = success
  4183. /// 1 = failure
  4184. void clif_tradecompleted(map_session_data* sd, int fail)
  4185. {
  4186. int fd;
  4187. nullpo_retv(sd);
  4188. fd = sd->fd;
  4189. WFIFOHEAD(fd,packet_len(0xf0));
  4190. WFIFOW(fd,0) = 0xf0;
  4191. WFIFOB(fd,2) = fail;
  4192. WFIFOSET(fd,packet_len(0xf0));
  4193. }
  4194. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  4195. /// 00f1
  4196. /// NOTE: Unknown purpose. Items are not removed until the window is
  4197. /// refreshed (ex. by putting another item in there).
  4198. void clif_tradeundo(map_session_data* sd)
  4199. {
  4200. int fd = sd->fd;
  4201. WFIFOHEAD(fd,packet_len(0xf1));
  4202. WFIFOW(fd,0) = 0xf1;
  4203. WFIFOSET(fd,packet_len(0xf1));
  4204. }
  4205. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  4206. /// 00f2 <current count>.W <max count>.W
  4207. void clif_updatestorageamount(map_session_data* sd, int amount, int max_amount)
  4208. {
  4209. int fd;
  4210. nullpo_retv(sd);
  4211. fd=sd->fd;
  4212. WFIFOHEAD(fd,packet_len(0xf2));
  4213. WFIFOW(fd,0) = 0xf2;
  4214. WFIFOW(fd,2) = amount;
  4215. WFIFOW(fd,4) = max_amount;
  4216. WFIFOSET(fd,packet_len(0xf2));
  4217. }
  4218. /// Notifies the client of an item being added to the storage.
  4219. /// 00f4 <index>.W <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE)
  4220. /// 01c4 <index>.W <amount>.L <nameid>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE2)
  4221. /// 0a0a <index>.W <amount>.L <nameid>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ADD_ITEM_TO_STORE3)
  4222. void clif_storageitemadded( map_session_data* sd, struct item* i, int index, int amount ){
  4223. nullpo_retv( sd );
  4224. nullpo_retv( i );
  4225. int fd = sd->fd;
  4226. if( !session_isActive( fd ) ){
  4227. return;
  4228. }
  4229. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4230. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4231. p.index = client_storage_index( index ); // index
  4232. p.amount = amount; // amount
  4233. p.itemId = client_nameid( i->nameid ); // id
  4234. #if PACKETVER >= 5
  4235. p.itemType = itemtype( i->nameid ); //type
  4236. #endif
  4237. p.identified = i->identify; //identify flag
  4238. p.damaged = i->attribute; // attribute
  4239. p.refine = i->refine; //refine
  4240. clif_addcards( &p.slot, i );
  4241. #if PACKETVER_MAIN_NUM >= 20140813 || PACKETVER_RE_NUM >= 20140402 || defined(PACKETVER_ZERO)
  4242. clif_add_random_options( p.option_data, *i );
  4243. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20221024
  4244. p.grade = i->enchantgrade;
  4245. #endif
  4246. #endif
  4247. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4248. }
  4249. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4250. /// 00f6 <index>.W <amount>.L
  4251. void clif_storageitemremoved(map_session_data* sd, int index, int amount)
  4252. {
  4253. int fd;
  4254. nullpo_retv(sd);
  4255. fd=sd->fd;
  4256. WFIFOHEAD(fd,packet_len(0xf6));
  4257. WFIFOW(fd,0)=0xf6; // Storage item removed
  4258. WFIFOW(fd,2)=client_storage_index(index);
  4259. WFIFOL(fd,4)=amount;
  4260. WFIFOSET(fd,packet_len(0xf6));
  4261. }
  4262. /// Closes storage (ZC_CLOSE_STORE).
  4263. /// 00f8
  4264. void clif_storageclose(map_session_data* sd)
  4265. {
  4266. int fd;
  4267. nullpo_retv(sd);
  4268. fd=sd->fd;
  4269. WFIFOHEAD(fd,packet_len(0xf8));
  4270. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4271. WFIFOSET(fd,packet_len(0xf8));
  4272. }
  4273. /// Notifies clients in an area of a player's souls.
  4274. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4275. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4276. /// 0b73 <id>.L <amount>.W
  4277. void clif_soulball( map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4278. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4279. struct PACKET_ZC_SOULENERGY p = {};
  4280. p.PacketType = HEADER_ZC_SOULENERGY;
  4281. #else
  4282. struct PACKET_ZC_SPIRITS p = {};
  4283. p.PacketType = HEADER_ZC_SPIRITS;
  4284. #endif
  4285. p.AID = sd->bl.id;
  4286. p.num = sd->soulball;
  4287. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4288. }
  4289. /*==========================================
  4290. * Server tells 'sd' player client the abouts of 'dstsd' player
  4291. *------------------------------------------*/
  4292. static void clif_getareachar_pc(map_session_data* sd,map_session_data* dstsd)
  4293. {
  4294. struct block_list *d_bl;
  4295. int i;
  4296. if( dstsd->chatID ) {
  4297. struct chat_data *cd = NULL;
  4298. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4299. clif_dispchat(cd,sd->fd);
  4300. } else if( dstsd->state.vending )
  4301. clif_showvendingboard( *dstsd, SELF, &sd->bl );
  4302. else if( dstsd->state.buyingstore )
  4303. clif_buyingstore_entry( *dstsd, &sd->bl );
  4304. if(dstsd->spiritball > 0)
  4305. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4306. if (dstsd->sc.getSCE(SC_MILLENNIUMSHIELD))
  4307. clif_millenniumshield_single(sd->fd, dstsd);
  4308. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4309. clif_spiritcharm_single(sd->fd, dstsd);
  4310. if (dstsd->soulball > 0)
  4311. clif_soulball( dstsd, &sd->bl, SELF );
  4312. if (dstsd->servantball > 0)
  4313. clif_servantball( *dstsd, &sd->bl, SELF );
  4314. if (dstsd->abyssball > 0)
  4315. clif_abyssball( *dstsd, &sd->bl, SELF );
  4316. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4317. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4318. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4319. )
  4320. clif_hpmeter_single( *sd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp );
  4321. // display link (sd - dstsd) to sd
  4322. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4323. if( i < MAX_DEVOTION )
  4324. clif_devotion(&sd->bl, sd);
  4325. // display links (dstsd - devotees) to sd
  4326. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4327. if( i < MAX_DEVOTION )
  4328. clif_devotion(&dstsd->bl, sd);
  4329. // display link (dstsd - crusader) to sd
  4330. if( dstsd->sc.getSCE(SC_DEVOTION) && (d_bl = map_id2bl(dstsd->sc.getSCE(SC_DEVOTION)->val1)) != NULL )
  4331. clif_devotion(d_bl, sd);
  4332. }
  4333. void clif_getareachar_unit( map_session_data* sd,struct block_list *bl ){
  4334. struct unit_data *ud;
  4335. struct view_data *vd;
  4336. bool option = false;
  4337. unsigned int option_val = 0;
  4338. vd = status_get_viewdata(bl);
  4339. if (!vd || vd->class_ == JT_INVISIBLE)
  4340. return;
  4341. // Hide NPC from Maya Purple card
  4342. if (clif_npc_mayapurple(bl))
  4343. return;
  4344. if( bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)bl ), *sd ) ){
  4345. // Do not send anything
  4346. return;
  4347. }
  4348. ud = unit_bl2ud(bl);
  4349. if( ud && ud->walktimer != INVALID_TIMER ){
  4350. clif_set_unit_walking( bl, sd, ud, SELF );
  4351. }else{
  4352. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4353. }
  4354. if (vd->cloth_color)
  4355. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4356. if (vd->body_style)
  4357. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4358. switch (bl->type)
  4359. {
  4360. case BL_PC:
  4361. {
  4362. TBL_PC* tsd = (TBL_PC*)bl;
  4363. clif_getareachar_pc(sd, tsd);
  4364. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4365. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4366. else if(tsd->state.size==SZ_MEDIUM)
  4367. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4368. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4369. clif_sendbgemblem_single(sd->fd,tsd);
  4370. if ( tsd->status.robe )
  4371. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4372. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4373. clif_hat_effects(sd,bl,SELF);
  4374. }
  4375. break;
  4376. case BL_MER: // Devotion Effects
  4377. if( ((TBL_MER*)bl)->devotion_flag )
  4378. clif_devotion(bl, sd);
  4379. break;
  4380. case BL_NPC:
  4381. {
  4382. TBL_NPC* nd = (TBL_NPC*)bl;
  4383. if( nd->chat_id )
  4384. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4385. if( nd->size == SZ_BIG )
  4386. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4387. else if( nd->size == SZ_MEDIUM )
  4388. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4389. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4390. clif_progressbar_npc(nd, sd);
  4391. }
  4392. break;
  4393. case BL_MOB:
  4394. {
  4395. TBL_MOB* md = (TBL_MOB*)bl;
  4396. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4397. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4398. else if(md->special_state.size==SZ_MEDIUM)
  4399. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4400. #if PACKETVER >= 20120404
  4401. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4402. int i;
  4403. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4404. if( md->dmglog[i].id == sd->status.char_id )
  4405. clif_monster_hp_bar(md, sd->fd);
  4406. }
  4407. #endif
  4408. }
  4409. break;
  4410. case BL_PET:
  4411. if (vd->head_bottom)
  4412. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4413. break;
  4414. }
  4415. }
  4416. //Modifies the type of damage according to status changes [Skotlex]
  4417. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4418. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4419. {
  4420. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4421. }
  4422. /*==========================================
  4423. * Estimates walk delay based on the damage criteria. [Skotlex]
  4424. *------------------------------------------*/
  4425. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4426. {
  4427. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4428. return 0;
  4429. if (bl->type == BL_PC) {
  4430. if (battle_config.pc_walk_delay_rate != 100)
  4431. delay = delay*battle_config.pc_walk_delay_rate/100;
  4432. } else
  4433. if (battle_config.walk_delay_rate != 100)
  4434. delay = delay*battle_config.walk_delay_rate/100;
  4435. if (div_ > 1) //Multi-hit skills mean higher delays.
  4436. delay += battle_config.multihit_delay*(div_-1);
  4437. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4438. }
  4439. /*========================================== [Playtester]
  4440. * Returns hallucination damage the client displays
  4441. *------------------------------------------*/
  4442. static int clif_hallucination_damage()
  4443. {
  4444. int digit = rnd() % 5 + 1;
  4445. switch (digit)
  4446. {
  4447. case 1:
  4448. return (rnd() % 10);
  4449. case 2:
  4450. return (rnd() % 100);
  4451. case 3:
  4452. return (rnd() % 1000);
  4453. case 4:
  4454. return (rnd() % 10000);
  4455. }
  4456. return (rnd() % 32767);
  4457. }
  4458. /// Sends a 'damage' packet (src performs action on dst)
  4459. /// 008a <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.W <div>.W <type>.B <damage2>.W (ZC_NOTIFY_ACT)
  4460. /// 02e1 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT2)
  4461. /// 08c8 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <IsSPDamage>.B <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT3)
  4462. /// type:
  4463. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4464. /// 1 = pick up item
  4465. /// 2 = sit down
  4466. /// 3 = stand up
  4467. /// 4 = damage (endure)
  4468. /// 5 = (splash?)
  4469. /// 6 = (skill?)
  4470. /// 7 = (repeat damage?)
  4471. /// 8 = multi-hit damage
  4472. /// 9 = multi-hit damage (endure)
  4473. /// 10 = critical hit
  4474. /// 11 = lucky dodge
  4475. /// 12 = (touch skill?)
  4476. /// 13 = multi-hit critical
  4477. int clif_damage(struct block_list* src, struct block_list* dst, t_tick tick, int sdelay, int ddelay, int64 sdamage, int div, enum e_damage_type type, int64 sdamage2, bool spdamage)
  4478. {
  4479. unsigned char buf[34];
  4480. status_change *sc;
  4481. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4482. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4483. #if PACKETVER < 20071113
  4484. const int cmd = 0x8a;
  4485. int offset = 0;
  4486. #elif PACKETVER < 20131223
  4487. const int cmd = 0x2e1;
  4488. int offset = 2;
  4489. #else
  4490. const int cmd = 0x8c8;
  4491. int offset = 3;
  4492. #endif
  4493. nullpo_ret(src);
  4494. nullpo_ret(dst);
  4495. if (type != DMG_MULTI_HIT_CRITICAL)
  4496. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4497. sc = status_get_sc(dst);
  4498. if(sc && sc->count) {
  4499. if(sc->getSCE(SC_HALLUCINATION)) {
  4500. damage = clif_hallucination_damage();
  4501. if(damage2) damage2 = clif_hallucination_damage();
  4502. }
  4503. }
  4504. WBUFW(buf,0) = cmd;
  4505. WBUFL(buf,2) = src->id;
  4506. WBUFL(buf,6) = dst->id;
  4507. WBUFL(buf,10) = client_tick(tick);
  4508. WBUFL(buf,14) = sdelay;
  4509. WBUFL(buf,18) = ddelay;
  4510. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4511. #if PACKETVER < 20071113
  4512. WBUFW(buf,22) = damage ? div : 0;
  4513. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4514. #else
  4515. WBUFL(buf, 22) = damage ? div : 0;
  4516. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4517. #endif
  4518. } else {
  4519. #if PACKETVER < 20071113
  4520. WBUFW(buf,22) = min(damage, INT16_MAX);
  4521. WBUFW(buf,27+offset) = damage2;
  4522. #else
  4523. WBUFL(buf,22) = damage;
  4524. WBUFL(buf,27+offset) = damage2;
  4525. #endif
  4526. }
  4527. #if PACKETVER >= 20131223
  4528. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4529. #endif
  4530. WBUFW(buf,24+offset) = div;
  4531. WBUFB(buf,26+offset) = type;
  4532. if(disguised(dst)) {
  4533. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4534. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4535. clif_send(buf, packet_len(cmd), dst, SELF);
  4536. } else
  4537. clif_send(buf, packet_len(cmd), dst, AREA);
  4538. if(disguised(src)) {
  4539. WBUFL(buf,2) = disguised_bl_id( src->id );
  4540. if (disguised(dst))
  4541. WBUFL(buf,6) = dst->id;
  4542. #if PACKETVER < 20071113
  4543. if(damage > 0) WBUFW(buf,22) = -1;
  4544. if(damage2 > 0) WBUFW(buf,27) = -1;
  4545. #else
  4546. if(damage > 0) WBUFL(buf,22) = -1;
  4547. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4548. #endif
  4549. clif_send(buf,packet_len(cmd),src,SELF);
  4550. }
  4551. if(src == dst) {
  4552. unit_setdir(src, unit_getdir(src));
  4553. }
  4554. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4555. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4556. //Return adjusted can't walk delay for further processing.
  4557. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4558. }
  4559. /*==========================================
  4560. * src picks up dst
  4561. *------------------------------------------*/
  4562. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4563. {
  4564. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4565. unsigned char buf[32];
  4566. nullpo_retv(src);
  4567. nullpo_retv(dst);
  4568. WBUFW(buf, 0) = 0x8a;
  4569. WBUFL(buf, 2) = src->id;
  4570. WBUFL(buf, 6) = dst->id;
  4571. WBUFB(buf,26) = 1;
  4572. clif_send(buf, packet_len(0x8a), src, AREA);
  4573. }
  4574. /*==========================================
  4575. * inform clients in area that `bl` is sitting
  4576. *------------------------------------------*/
  4577. void clif_sitting(struct block_list* bl)
  4578. {
  4579. unsigned char buf[32];
  4580. nullpo_retv(bl);
  4581. WBUFW(buf, 0) = 0x8a;
  4582. WBUFL(buf, 2) = bl->id;
  4583. WBUFB(buf,26) = 2;
  4584. clif_send(buf, packet_len(0x8a), bl, AREA);
  4585. if(disguised(bl)) {
  4586. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4587. clif_send(buf, packet_len(0x8a), bl, SELF);
  4588. }
  4589. }
  4590. /*==========================================
  4591. * inform clients in area that `bl` is standing
  4592. *------------------------------------------*/
  4593. void clif_standing(struct block_list* bl)
  4594. {
  4595. unsigned char buf[32];
  4596. nullpo_retv(bl);
  4597. WBUFW(buf, 0) = 0x8a;
  4598. WBUFL(buf, 2) = bl->id;
  4599. WBUFB(buf,26) = 3;
  4600. clif_send(buf, packet_len(0x8a), bl, AREA);
  4601. if(disguised(bl)) {
  4602. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4603. clif_send(buf, packet_len(0x8a), bl, SELF);
  4604. }
  4605. }
  4606. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4607. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4608. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4609. {
  4610. unsigned char buf[32];
  4611. WBUFW(buf,0) = 0x192;
  4612. WBUFW(buf,2) = x;
  4613. WBUFW(buf,4) = y;
  4614. WBUFW(buf,6) = type;
  4615. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4616. if( session_isActive(fd) )
  4617. {
  4618. WFIFOHEAD(fd,packet_len(0x192));
  4619. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4620. WFIFOSET(fd,packet_len(0x192));
  4621. }
  4622. else
  4623. {
  4624. struct block_list dummy_bl;
  4625. dummy_bl.type = BL_NUL;
  4626. dummy_bl.x = x;
  4627. dummy_bl.y = y;
  4628. dummy_bl.m = m;
  4629. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4630. }
  4631. }
  4632. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4633. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4634. void clif_getareachar_item( map_session_data* sd,struct flooritem_data* fitem ){
  4635. nullpo_retv( sd );
  4636. nullpo_retv( fitem );
  4637. struct PACKET_ZC_ITEM_ENTRY p;
  4638. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4639. p.AID = fitem->bl.id;
  4640. p.itemId = client_nameid( fitem->item.nameid );
  4641. p.identify = fitem->item.identify;
  4642. p.x = fitem->bl.x;
  4643. p.y = fitem->bl.y;
  4644. p.amount = fitem->item.amount;
  4645. p.subX = fitem->subx;
  4646. p.subY = fitem->suby;
  4647. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4648. }
  4649. /// Notifes client about Graffiti
  4650. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4651. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4652. unsigned char buf[128];
  4653. nullpo_retv(bl);
  4654. nullpo_retv(unit);
  4655. WBUFW(buf, 0) = 0x1c9;
  4656. WBUFL(buf, 2) = unit->bl.id;
  4657. WBUFL(buf, 6) = unit->group->src_id;
  4658. WBUFW(buf,10) = unit->bl.x;
  4659. WBUFW(buf,12) = unit->bl.y;
  4660. WBUFB(buf,14) = unit->group->unit_id;
  4661. WBUFB(buf,15) = 1;
  4662. WBUFB(buf,16) = 1;
  4663. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4664. clif_send(buf,packet_len(0x1c9),bl,target);
  4665. }
  4666. /// Notifies the client of a skill unit.
  4667. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4668. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4669. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4670. /// 09ca <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.B <visible>.B <skill level>.B (ZC_SKILL_ENTRY5)
  4671. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4672. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4673. unsigned char buf[128];
  4674. nullpo_retv(bl);
  4675. nullpo_retv(unit);
  4676. if (bl->type == BL_PC)
  4677. fd = ((TBL_PC*)bl)->fd;
  4678. if (unit->group->state.guildaura)
  4679. return;
  4680. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4681. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4682. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4683. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4684. else
  4685. unit_id = unit->group->unit_id;
  4686. if (!visible)
  4687. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4688. #if PACKETVER >= 3
  4689. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4690. clif_graffiti(bl, unit, target);
  4691. return;
  4692. }
  4693. #endif
  4694. #if PACKETVER <= 20120702
  4695. header = 0x011f;
  4696. //#if PACKETVER < 20110718
  4697. // header = 0x011f;
  4698. //#elif PACKETVER < 20121212
  4699. // header = 0x08c7;
  4700. #elif PACKETVER < 20130731
  4701. header = 0x099f;
  4702. #else
  4703. header = 0x09ca;
  4704. #endif
  4705. len = packet_len(header);
  4706. WBUFW(buf,pos) = header;
  4707. if (header != 0x011f) {
  4708. WBUFW(buf, pos+2) = len;
  4709. pos += 2;
  4710. }
  4711. WBUFL(buf,pos+2) = unit->bl.id;
  4712. WBUFL(buf,pos+6) = unit->group->src_id;
  4713. WBUFW(buf,pos+10) = unit->bl.x;
  4714. WBUFW(buf,pos+12) = unit->bl.y;
  4715. switch (header) {
  4716. case 0x011f:
  4717. WBUFB(buf,pos+14) = unit_id;
  4718. WBUFB(buf,pos+15) = visible;
  4719. break;
  4720. case 0x08c7:
  4721. WBUFB(buf,pos+14) = unit_id;
  4722. WBUFW(buf,pos+15) = unit->range;
  4723. WBUFB(buf,pos+17) = visible;
  4724. break;
  4725. case 0x099f:
  4726. WBUFL(buf,pos+14) = unit_id;
  4727. WBUFW(buf,pos+18) = unit->range;
  4728. WBUFB(buf,pos+20) = visible;
  4729. break;
  4730. case 0x09ca:
  4731. WBUFL(buf,pos+14) = unit_id;
  4732. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4733. WBUFB(buf,pos+19) = visible;
  4734. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4735. break;
  4736. }
  4737. clif_send(buf, len, bl, target);
  4738. if (unit->group->skill_id == WZ_ICEWALL)
  4739. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4740. }
  4741. /// 09ca <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.B <visible>.B <skill level>.B (ZC_SKILL_ENTRY5)
  4742. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4743. unsigned char buf[128];
  4744. nullpo_retv(bl);
  4745. WBUFW(buf, 0) = 0x09ca;
  4746. WBUFW(buf, 2) = packet_len(0x09ca);
  4747. WBUFL(buf, 4) = 1000;
  4748. WBUFL(buf, 8) = 2000;
  4749. WBUFW(buf, 12) = x;
  4750. WBUFW(buf, 14) = y;
  4751. WBUFL(buf, 16) = unit_id;
  4752. WBUFB(buf, 20) = (unsigned char)range;
  4753. WBUFB(buf, 21) = 1;
  4754. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4755. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4756. }
  4757. /*==========================================
  4758. * Server tells client to remove unit of id 'unit->bl.id'
  4759. *------------------------------------------*/
  4760. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4761. {
  4762. nullpo_retv(unit);
  4763. WFIFOHEAD(fd,packet_len(0x120));
  4764. WFIFOW(fd, 0)=0x120;
  4765. WFIFOL(fd, 2)=unit->bl.id;
  4766. WFIFOSET(fd,packet_len(0x120));
  4767. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4768. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4769. }
  4770. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4771. /// 0120 <id>.L
  4772. void clif_skill_delunit(struct skill_unit *unit)
  4773. {
  4774. unsigned char buf[16];
  4775. nullpo_retv(unit);
  4776. WBUFW(buf, 0)=0x120;
  4777. WBUFL(buf, 2)=unit->bl.id;
  4778. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4779. }
  4780. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4781. /// 01ac <id>.L
  4782. /// Only affects units with class [139,153] client-side.
  4783. void clif_skillunit_update(struct block_list* bl)
  4784. {
  4785. unsigned char buf[6];
  4786. nullpo_retv(bl);
  4787. WBUFW(buf,0) = 0x1ac;
  4788. WBUFL(buf,2) = bl->id;
  4789. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4790. }
  4791. /*==========================================
  4792. *
  4793. *------------------------------------------*/
  4794. static int clif_getareachar(struct block_list* bl,va_list ap)
  4795. {
  4796. map_session_data *sd;
  4797. nullpo_ret(bl);
  4798. sd=va_arg(ap,map_session_data*);
  4799. if (!clif_session_isValid(sd))
  4800. return 0;
  4801. switch(bl->type){
  4802. case BL_ITEM:
  4803. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4804. break;
  4805. case BL_SKILL:
  4806. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4807. break;
  4808. default:
  4809. if(&sd->bl == bl)
  4810. break;
  4811. clif_getareachar_unit(sd,bl);
  4812. break;
  4813. }
  4814. return 0;
  4815. }
  4816. /*==========================================
  4817. * tbl has gone out of view-size of bl
  4818. *------------------------------------------*/
  4819. int clif_outsight(struct block_list *bl,va_list ap)
  4820. {
  4821. struct block_list *tbl;
  4822. struct view_data *vd;
  4823. TBL_PC *sd, *tsd;
  4824. tbl=va_arg(ap,struct block_list*);
  4825. if(bl == tbl) return 0;
  4826. sd = BL_CAST(BL_PC, bl);
  4827. tsd = BL_CAST(BL_PC, tbl);
  4828. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4829. nullpo_ret(bl);
  4830. switch(bl->type){
  4831. case BL_PC:
  4832. if(sd->vd.class_ != JT_INVISIBLE)
  4833. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4834. if(sd->chatID){
  4835. struct chat_data *cd;
  4836. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4837. if(cd->usersd[0]==sd)
  4838. clif_dispchat(cd,tsd->fd);
  4839. }
  4840. if(sd->state.vending)
  4841. clif_closevendingboard(bl,tsd->fd);
  4842. if(sd->state.buyingstore)
  4843. clif_buyingstore_disappear_entry( *sd, &tsd->bl );
  4844. break;
  4845. case BL_ITEM:
  4846. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4847. break;
  4848. case BL_SKILL:
  4849. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4850. break;
  4851. case BL_NPC:
  4852. if(!(((TBL_NPC*)bl)->is_invisible))
  4853. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4854. break;
  4855. default:
  4856. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4857. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4858. break;
  4859. }
  4860. }
  4861. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4862. nullpo_ret(tbl);
  4863. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4864. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4865. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4866. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->is_invisible)))
  4867. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4868. }
  4869. return 0;
  4870. }
  4871. /*==========================================
  4872. * tbl has come into view of bl
  4873. *------------------------------------------*/
  4874. int clif_insight(struct block_list *bl,va_list ap)
  4875. {
  4876. struct block_list *tbl;
  4877. TBL_PC *sd, *tsd;
  4878. tbl=va_arg(ap,struct block_list*);
  4879. if (bl == tbl) return 0;
  4880. sd = BL_CAST(BL_PC, bl);
  4881. tsd = BL_CAST(BL_PC, tbl);
  4882. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4883. switch(bl->type){
  4884. case BL_ITEM:
  4885. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4886. break;
  4887. case BL_SKILL:
  4888. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4889. break;
  4890. default:
  4891. clif_getareachar_unit(tsd,bl);
  4892. break;
  4893. }
  4894. }
  4895. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4896. clif_getareachar_unit(sd,tbl);
  4897. }
  4898. return 0;
  4899. }
  4900. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4901. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4902. void clif_skillinfoblock(map_session_data *sd)
  4903. {
  4904. int fd;
  4905. int i,len,id;
  4906. nullpo_retv(sd);
  4907. fd = sd->fd;
  4908. if (!session_isActive(fd))
  4909. return;
  4910. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4911. WFIFOW(fd,0) = 0x10f;
  4912. bool haveCallPartnerSkill = false;
  4913. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4914. {
  4915. if( (id = sd->status.skill[i].id) != 0 )
  4916. {
  4917. // workaround for bugreport:5348
  4918. if (len + 37 > 8192)
  4919. break;
  4920. // skip WE_CALLPARTNER and send it in special way
  4921. if (id == WE_CALLPARTNER) {
  4922. haveCallPartnerSkill = true;
  4923. continue;
  4924. }
  4925. WFIFOW(fd,len) = id;
  4926. WFIFOL(fd,len+2) = skill_get_inf(id);
  4927. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4928. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4929. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4930. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4931. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4932. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4933. else
  4934. WFIFOB(fd,len+36) = 0;
  4935. len += 37;
  4936. }
  4937. }
  4938. WFIFOW(fd,2)=len;
  4939. WFIFOSET(fd,len);
  4940. // adoption fix
  4941. if (haveCallPartnerSkill) {
  4942. clif_addskill(sd, WE_CALLPARTNER);
  4943. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4944. }
  4945. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4946. for ( ; i < MAX_SKILL; i++)
  4947. {
  4948. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4949. {
  4950. clif_addskill(sd, id);
  4951. clif_skillinfo(sd, id, 0);
  4952. }
  4953. }
  4954. }
  4955. /**
  4956. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4957. **/
  4958. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4959. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4960. void clif_addskill(map_session_data *sd, int skill_id)
  4961. {
  4962. nullpo_retv(sd);
  4963. int fd = sd->fd;
  4964. uint16 idx = skill_get_index(skill_id);
  4965. if (!session_isActive(fd) || !idx)
  4966. return;
  4967. if( sd->status.skill[idx].id <= 0 )
  4968. return;
  4969. WFIFOHEAD(fd, packet_len(0x111));
  4970. WFIFOW(fd,0) = 0x111;
  4971. WFIFOW(fd,2) = skill_id;
  4972. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4973. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4974. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4975. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4976. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4977. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4978. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4979. else
  4980. WFIFOB(fd,38) = 0;
  4981. WFIFOSET(fd,packet_len(0x111));
  4982. }
  4983. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4984. /// 0441 <skill id>.W
  4985. void clif_deleteskill(map_session_data *sd, int skill_id, bool skip_infoblock)
  4986. {
  4987. #if PACKETVER >= 20081217
  4988. nullpo_retv(sd);
  4989. int fd = sd->fd;
  4990. uint16 idx = skill_get_index(skill_id);
  4991. if (!session_isActive(fd) || !idx)
  4992. return;
  4993. WFIFOHEAD(fd,packet_len(0x441));
  4994. WFIFOW(fd,0) = 0x441;
  4995. WFIFOW(fd,2) = skill_id;
  4996. WFIFOSET(fd,packet_len(0x441));
  4997. #endif
  4998. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190918
  4999. if (!skip_infoblock)
  5000. #endif
  5001. clif_skillinfoblock(sd);
  5002. }
  5003. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  5004. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  5005. void clif_skillup(map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  5006. nullpo_retv(sd);
  5007. int fd = sd->fd;
  5008. uint16 idx = skill_get_index(skill_id);
  5009. if (!session_isActive(fd) || !idx)
  5010. return;
  5011. WFIFOHEAD(fd, packet_len(0x10e));
  5012. WFIFOW(fd, 0) = 0x10e;
  5013. WFIFOW(fd, 2) = skill_id;
  5014. WFIFOW(fd, 4) = lv;
  5015. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  5016. WFIFOW(fd, 8) = range;
  5017. WFIFOB(fd, 10) = upgradable;
  5018. WFIFOSET(fd, packet_len(0x10e));
  5019. }
  5020. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  5021. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  5022. void clif_skillinfo(map_session_data *sd,int skill_id, int inf)
  5023. {
  5024. nullpo_retv(sd);
  5025. const int fd = sd->fd;
  5026. uint16 idx = skill_get_index(skill_id);
  5027. if (!session_isActive(fd) || !idx)
  5028. return;
  5029. WFIFOHEAD(fd,packet_len(0x7e1));
  5030. WFIFOW(fd,0) = 0x7e1;
  5031. WFIFOW(fd,2) = skill_id;
  5032. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  5033. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  5034. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  5035. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  5036. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  5037. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  5038. else
  5039. WFIFOB(fd,14) = 0;
  5040. WFIFOSET(fd,packet_len(0x7e1));
  5041. }
  5042. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  5043. #if PACKETVER >= 20151223
  5044. if( !battle_config.show_skill_scale ){
  5045. return;
  5046. }
  5047. struct PACKET_ZC_SKILL_SCALE p;
  5048. p.PacketType = skillscale;
  5049. p.AID = src_id;
  5050. p.skill_id = skill_id;
  5051. p.skill_lv = skill_lv;
  5052. p.x = x;
  5053. p.y = y;
  5054. p.casttime = casttime;
  5055. if( disguised( bl ) ){
  5056. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  5057. p.AID = disguised_bl_id( bl->id );
  5058. clif_send( &p, sizeof( p ), bl, SELF );
  5059. }else{
  5060. clif_send( &p, sizeof( p ), bl, AREA );
  5061. }
  5062. #endif
  5063. }
  5064. /// Notifies clients in area, that an object is about to use a skill.
  5065. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  5066. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  5067. /// property:
  5068. /// 0 = Yellow cast aura
  5069. /// 1 = Water elemental cast aura
  5070. /// 2 = Earth elemental cast aura
  5071. /// 3 = Fire elemental cast aura
  5072. /// 4 = Wind elemental cast aura
  5073. /// 5 = Poison elemental cast aura
  5074. /// 6 = Holy elemental cast aura
  5075. /// ? = like 0
  5076. /// is disposable:
  5077. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  5078. /// 1 = no text
  5079. void clif_skillcasting(struct block_list* bl, int src_id, int dst_id, int dst_x, int dst_y, uint16 skill_id, uint16 skill_lv, int property, int casttime)
  5080. {
  5081. #if PACKETVER < 20091124
  5082. const int cmd = 0x13e;
  5083. #else
  5084. const int cmd = 0x7fb;
  5085. #endif
  5086. unsigned char buf[32];
  5087. WBUFW(buf,0) = cmd;
  5088. WBUFL(buf,2) = src_id;
  5089. WBUFL(buf,6) = dst_id;
  5090. WBUFW(buf,10) = dst_x;
  5091. WBUFW(buf,12) = dst_y;
  5092. WBUFW(buf,14) = skill_id;
  5093. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  5094. WBUFL(buf,20) = casttime;
  5095. #if PACKETVER >= 20091124
  5096. WBUFB(buf,24) = 0; // isDisposable
  5097. #endif
  5098. if (disguised(bl)) {
  5099. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  5100. WBUFL(buf,2) = disguised_bl_id( src_id );
  5101. clif_send(buf,packet_len(cmd), bl, SELF);
  5102. } else
  5103. clif_send(buf,packet_len(cmd), bl, AREA);
  5104. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  5105. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  5106. }
  5107. }
  5108. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  5109. /// 01b9 <id>.L
  5110. void clif_skillcastcancel(struct block_list* bl)
  5111. {
  5112. unsigned char buf[16];
  5113. nullpo_retv(bl);
  5114. WBUFW(buf,0) = 0x1b9;
  5115. WBUFL(buf,2) = bl->id;
  5116. clif_send(buf,packet_len(0x1b9), bl, AREA);
  5117. }
  5118. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  5119. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  5120. /// num (only used when skill id = NV_BASIC and cause = 0):
  5121. /// 0 = "skill failed" MsgStringTable[159]
  5122. /// 1 = "no emotions" MsgStringTable[160]
  5123. /// 2 = "no sit" MsgStringTable[161]
  5124. /// 3 = "no chat" MsgStringTable[162]
  5125. /// 4 = "no party" MsgStringTable[163]
  5126. /// 5 = "no shout" MsgStringTable[164]
  5127. /// 6 = "no PKing" MsgStringTable[165]
  5128. /// 7 = "no alligning" MsgStringTable[383]
  5129. /// ? = ignored
  5130. /// cause:
  5131. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5132. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5133. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5134. /// "skill failed" MsgStringTable[204] (otherwise)
  5135. /// ... = @see enum useskill_fail_cause
  5136. /// ? = ignored
  5137. ///
  5138. /// if(result!=0) doesn't display any of the previous messages
  5139. /// Note: when this packet is received an unknown flag is always set to 0,
  5140. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5141. void clif_skill_fail( map_session_data *sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5142. nullpo_retv( sd );
  5143. int fd = sd->fd;
  5144. if( !session_isActive( fd ) ){
  5145. return;
  5146. }
  5147. if(battle_config.display_skill_fail&1)
  5148. return; //Disable all skill failed messages
  5149. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  5150. return; //Disable delay failed messages
  5151. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5152. return;
  5153. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5154. return;
  5155. struct PACKET_ZC_ACK_TOUSESKILL p;
  5156. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5157. p.skillId = skill_id;
  5158. p.btype = btype;
  5159. p.itemId = itemId;
  5160. p.flag = 0; // 0 - failed
  5161. p.cause = cause;
  5162. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5163. }
  5164. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  5165. /// 043d <skill ID>.W <tick>.L
  5166. void clif_skill_cooldown(map_session_data *sd, uint16 skill_id, t_tick tick)
  5167. {
  5168. #if PACKETVER>=20081112
  5169. int fd;
  5170. nullpo_retv(sd);
  5171. fd=sd->fd;
  5172. WFIFOHEAD(fd,packet_len(0x43d));
  5173. WFIFOW(fd,0) = 0x43d;
  5174. WFIFOW(fd,2) = skill_id;
  5175. WFIFOL(fd,4) = client_tick(tick);
  5176. WFIFOSET(fd,packet_len(0x43d));
  5177. #endif
  5178. }
  5179. /// Skill attack effect and damage.
  5180. /// 0114 <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <damage>.W <level>.W <div>.W <type>.B (ZC_NOTIFY_SKILL)
  5181. /// 01de <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <damage>.L <level>.W <div>.W <type>.B (ZC_NOTIFY_SKILL2)
  5182. int clif_skill_damage(struct block_list *src,struct block_list *dst,t_tick tick,int sdelay,int ddelay,int64 sdamage,int div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  5183. {
  5184. unsigned char buf[64];
  5185. status_change *sc;
  5186. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5187. nullpo_ret(src);
  5188. nullpo_ret(dst);
  5189. type = clif_calc_delay(type,div,damage,ddelay);
  5190. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5191. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5192. damage = clif_hallucination_damage();
  5193. }
  5194. #if PACKETVER < 3
  5195. WBUFW(buf,0)=0x114;
  5196. WBUFW(buf,2)=skill_id;
  5197. WBUFL(buf,4)=src->id;
  5198. WBUFL(buf,8)=dst->id;
  5199. WBUFL(buf,12)=client_tick(tick);
  5200. WBUFL(buf,16)=sdelay;
  5201. WBUFL(buf,20)=ddelay;
  5202. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5203. WBUFW(buf,24)=damage?div:0;
  5204. } else {
  5205. WBUFW(buf,24)=damage;
  5206. }
  5207. WBUFW(buf,26)=skill_lv;
  5208. WBUFW(buf,28)=div;
  5209. WBUFB(buf,30)=type;
  5210. if (disguised(dst)) {
  5211. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5212. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5213. clif_send(buf,packet_len(0x114),dst,SELF);
  5214. } else
  5215. clif_send(buf,packet_len(0x114),dst,AREA);
  5216. if(disguised(src)) {
  5217. WBUFL(buf,4)=disguised_bl_id(src->id);
  5218. if (disguised(dst))
  5219. WBUFL(buf,8)=dst->id;
  5220. if(damage > 0)
  5221. WBUFW(buf,24)=-1;
  5222. clif_send(buf,packet_len(0x114),src,SELF);
  5223. }
  5224. #else
  5225. WBUFW(buf,0)=0x1de;
  5226. WBUFW(buf,2)=skill_id;
  5227. WBUFL(buf,4)=src->id;
  5228. WBUFL(buf,8)=dst->id;
  5229. WBUFL(buf,12)=client_tick(tick);
  5230. WBUFL(buf,16)=sdelay;
  5231. WBUFL(buf,20)=ddelay;
  5232. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5233. WBUFL(buf,24)=damage?div:0;
  5234. } else {
  5235. WBUFL(buf,24)=damage;
  5236. }
  5237. WBUFW(buf,28)=skill_lv;
  5238. WBUFW(buf,30)=div;
  5239. // For some reason, late 2013 and newer clients have
  5240. // a issue that causes players and monsters to endure
  5241. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5242. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5243. #if PACKETVER < 20131223
  5244. WBUFB(buf,32)=type;
  5245. #else
  5246. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5247. #endif
  5248. if (disguised(dst)) {
  5249. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5250. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5251. clif_send(buf,packet_len(0x1de),dst,SELF);
  5252. } else
  5253. clif_send(buf,packet_len(0x1de),dst,AREA);
  5254. if(disguised(src)) {
  5255. WBUFL(buf,4)=disguised_bl_id(src->id);
  5256. if (disguised(dst))
  5257. WBUFL(buf,8)=dst->id;
  5258. if(damage > 0)
  5259. WBUFL(buf,24)=-1;
  5260. clif_send(buf,packet_len(0x1de),src,SELF);
  5261. }
  5262. #endif
  5263. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5264. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5265. }
  5266. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5267. /// 0115 <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <x>.W <y>.W <damage>.W <level>.W <div>.W <type>.B
  5268. /*
  5269. int clif_skill_damage2(struct block_list *src,struct block_list *dst,t_tick tick,int sdelay,int ddelay,int damage,int div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  5270. {
  5271. unsigned char buf[64];
  5272. status_change *sc;
  5273. nullpo_ret(src);
  5274. nullpo_ret(dst);
  5275. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5276. type = clif_calc_delay(type,div,damage,ddelay);
  5277. sc = status_get_sc(dst);
  5278. if(sc && sc->count) {
  5279. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5280. damage = clif_hallucination_damage();
  5281. }
  5282. WBUFW(buf,0)=0x115;
  5283. WBUFW(buf,2)=skill_id;
  5284. WBUFL(buf,4)=src->id;
  5285. WBUFL(buf,8)=dst->id;
  5286. WBUFL(buf,12)=client_tick(tick);
  5287. WBUFL(buf,16)=sdelay;
  5288. WBUFL(buf,20)=ddelay;
  5289. WBUFW(buf,24)=dst->x;
  5290. WBUFW(buf,26)=dst->y;
  5291. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5292. WBUFW(buf,28)=damage?div:0;
  5293. } else {
  5294. WBUFW(buf,28)=damage;
  5295. }
  5296. WBUFW(buf,30)=skill_lv;
  5297. WBUFW(buf,32)=div;
  5298. WBUFB(buf,34)=type;
  5299. clif_send(buf,packet_len(0x115),src,AREA);
  5300. if(disguised(src)) {
  5301. WBUFL(buf,4)=disguised_bl_id(src->id);
  5302. if(damage > 0)
  5303. WBUFW(buf,28)=-1;
  5304. clif_send(buf,packet_len(0x115),src,SELF);
  5305. }
  5306. if (disguised(dst)) {
  5307. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5308. if (disguised(src))
  5309. WBUFL(buf,4)=src->id;
  5310. else if(damage > 0)
  5311. WBUFW(buf,28)=-1;
  5312. clif_send(buf,packet_len(0x115),dst,SELF);
  5313. }
  5314. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5315. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5316. }
  5317. */
  5318. /// Non-damaging skill effect
  5319. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5320. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5321. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5322. {
  5323. unsigned char buf[17];
  5324. #if PACKETVER < 20130731
  5325. const int cmd = 0x11a;
  5326. #else
  5327. const int cmd = 0x9cb;
  5328. #endif
  5329. int offset = 0;
  5330. bool success = ( tick != 0 );
  5331. nullpo_ret(dst);
  5332. WBUFW(buf,0) = cmd;
  5333. WBUFW(buf,2) = skill_id;
  5334. #if PACKETVER < 20130731
  5335. WBUFW(buf,4) = min(heal, INT16_MAX);
  5336. #else
  5337. WBUFL(buf,4) = min(heal, INT32_MAX);
  5338. offset += 2;
  5339. #endif
  5340. WBUFL(buf,6+offset) = dst->id;
  5341. WBUFL(buf,10+offset) = src ? src->id : 0;
  5342. WBUFB(buf,14+offset) = success;
  5343. if (disguised(dst)) {
  5344. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5345. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5346. clif_send(buf, packet_len(cmd), dst, SELF);
  5347. } else
  5348. clif_send(buf, packet_len(cmd), dst, AREA);
  5349. if(src && disguised(src)) {
  5350. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5351. if (disguised(dst))
  5352. WBUFL(buf,6+offset) = dst->id;
  5353. clif_send(buf, packet_len(cmd), src, SELF);
  5354. }
  5355. return success;
  5356. }
  5357. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5358. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5359. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5360. {
  5361. unsigned char buf[32];
  5362. nullpo_retv(src);
  5363. WBUFW(buf,0)=0x117;
  5364. WBUFW(buf,2)=skill_id;
  5365. WBUFL(buf,4)=src->id;
  5366. WBUFW(buf,8)=val;
  5367. WBUFW(buf,10)=x;
  5368. WBUFW(buf,12)=y;
  5369. WBUFL(buf,14)=client_tick(tick);
  5370. if(disguised(src)) {
  5371. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5372. WBUFL(buf,4)=disguised_bl_id(src->id);
  5373. clif_send(buf,packet_len(0x117),src,SELF);
  5374. } else
  5375. clif_send(buf,packet_len(0x117),src,AREA);
  5376. }
  5377. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5378. /// 011c <skill id>.W { <map name>.16B }*4
  5379. void clif_skill_warppoint( map_session_data* sd, uint16 skill_id, uint16 skill_lv, const char* map1, const char* map2, const char* map3, const char* map4 ){
  5380. int fd;
  5381. nullpo_retv(sd);
  5382. fd = sd->fd;
  5383. WFIFOHEAD(fd,packet_len(0x11c));
  5384. WFIFOW(fd,0) = 0x11c;
  5385. WFIFOW(fd,2) = skill_id;
  5386. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5387. if( strcmp( "", map1 ) != 0 ){
  5388. mapindex_getmapname_ext( map1, WFIFOCP( fd, 4 ) );
  5389. }
  5390. if( strcmp( "", map2 ) != 0 ){
  5391. mapindex_getmapname_ext( map2, WFIFOCP( fd, 20 ) );
  5392. }
  5393. if( strcmp( "", map3 ) != 0 ){
  5394. mapindex_getmapname_ext( map3, WFIFOCP( fd, 36 ) );
  5395. }
  5396. if( strcmp( "", map4 ) != 0 ){
  5397. mapindex_getmapname_ext( map4, WFIFOCP( fd, 52 ) );
  5398. }
  5399. WFIFOSET(fd,packet_len(0x11c));
  5400. sd->menuskill_id = skill_id;
  5401. if (skill_id == AL_WARP) {
  5402. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5403. sd->state.workinprogress = WIP_DISABLE_ALL;
  5404. } else
  5405. sd->menuskill_val = skill_lv;
  5406. }
  5407. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5408. /// 011e <type>.B
  5409. /// type:
  5410. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5411. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5412. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5413. ///
  5414. /// @param sd Who receives the message
  5415. /// @param type What message
  5416. void clif_skill_memomessage(map_session_data* sd, int type)
  5417. {
  5418. int fd;
  5419. nullpo_retv(sd);
  5420. fd=sd->fd;
  5421. WFIFOHEAD(fd,packet_len(0x11e));
  5422. WFIFOW(fd,0)=0x11e;
  5423. WFIFOB(fd,2)=type;
  5424. WFIFOSET(fd,packet_len(0x11e));
  5425. }
  5426. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5427. /// 0189 <type>.W
  5428. /// type:
  5429. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5430. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5431. ///
  5432. /// @param sd Who receives the message
  5433. /// @param type What message
  5434. void clif_skill_teleportmessage(map_session_data *sd, int type)
  5435. {
  5436. int fd;
  5437. nullpo_retv(sd);
  5438. fd=sd->fd;
  5439. WFIFOHEAD(fd,packet_len(0x189));
  5440. WFIFOW(fd,0)=0x189;
  5441. WFIFOW(fd,2)=type;
  5442. WFIFOSET(fd,packet_len(0x189));
  5443. }
  5444. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5445. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5446. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5447. void clif_skill_estimation(map_session_data *sd,struct block_list *dst)
  5448. {
  5449. struct status_data *status;
  5450. unsigned char buf[64];
  5451. int i, fix;
  5452. nullpo_retv(sd);
  5453. nullpo_retv(dst);
  5454. if( dst->type != BL_MOB )
  5455. return;
  5456. status = status_get_status_data(dst);
  5457. WBUFW(buf, 0)=0x18c;
  5458. WBUFW(buf, 2)=status_get_class(dst);
  5459. WBUFW(buf, 4)=status_get_lv(dst);
  5460. WBUFW(buf, 6)=status->size;
  5461. WBUFL(buf, 8)=status->hp;
  5462. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5463. +(battle_config.estimation_type&2?status->def2:0);
  5464. WBUFW(buf,14)=status->race;
  5465. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5466. +(battle_config.estimation_type&2?status->mdef2:0);
  5467. WBUFW(buf,18)= status->def_ele;
  5468. for(i=0;i<9;i++)
  5469. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5470. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5471. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5472. }
  5473. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5474. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5475. /// material id:
  5476. /// unused by the client
  5477. void clif_skill_produce_mix_list( map_session_data *sd, int skill_id, int trigger ){
  5478. nullpo_retv(sd);
  5479. int fd = sd->fd;
  5480. if( !session_isActive( fd ) ){
  5481. return;
  5482. }
  5483. if (sd->menuskill_id == skill_id)
  5484. return; //Avoid resending the menu twice or more times...
  5485. if (skill_id == GC_CREATENEWPOISON)
  5486. skill_id = GC_RESEARCHNEWPOISON;
  5487. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5488. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5489. p->packetType = 0x18d;
  5490. int count = 0;
  5491. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5492. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5493. (skill_id <= 0 || skill_produce_db[i].req_skill == skill_id)
  5494. )
  5495. {
  5496. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5497. p->items[count].material[0] = 0;
  5498. p->items[count].material[1] = 0;
  5499. p->items[count].material[2] = 0;
  5500. count++;
  5501. }
  5502. }
  5503. p->packetLength = sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub );
  5504. WFIFOSET( fd, p->packetLength );
  5505. if( count > 0 ){
  5506. sd->menuskill_id = skill_id;
  5507. sd->menuskill_val = trigger;
  5508. return;
  5509. }
  5510. }
  5511. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5512. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5513. /// mk type:
  5514. /// 1 = cooking
  5515. /// 2 = arrow
  5516. /// 3 = elemental
  5517. /// 4 = GN_MIX_COOKING
  5518. /// 5 = GN_MAKEBOMB
  5519. /// 6 = GN_S_PHARMACY
  5520. /// 7 = MT_M_MACHINE - Unconfirmed
  5521. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5522. void clif_cooking_list( map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5523. nullpo_retv( sd );
  5524. // Avoid resending the menu twice or more times...
  5525. if( sd->menuskill_id == skill_id ){
  5526. return;
  5527. }
  5528. int fd = sd->fd;
  5529. if( !session_isActive( fd ) ){
  5530. return;
  5531. }
  5532. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5533. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5534. p->packetType = 0x25a;
  5535. p->makeItem = list_type; // list type
  5536. int count = 0;
  5537. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5538. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5539. continue;
  5540. }
  5541. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5542. count++;
  5543. }
  5544. if( count > 0 || skill_id == AM_PHARMACY ){
  5545. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5546. WFIFOSET( fd, p->packetLength );
  5547. sd->menuskill_id = skill_id;
  5548. sd->menuskill_val = trigger;
  5549. sd->menuskill_val2 = qty; // amount.
  5550. }else{
  5551. clif_menuskill_clear(sd);
  5552. #if PACKETVER >= 20090922
  5553. clif_msg_skill( sd, skill_id, INVENTORY_SPACE_FULL );
  5554. #else
  5555. p->packetLength = sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub );
  5556. WFIFOSET( fd, p->packetLength );
  5557. #endif
  5558. }
  5559. }
  5560. /// Notifies clients of a status change.
  5561. /// 0196 <index>.W <id>.L <state>.B (ZC_MSG_STATE_CHANGE) [used for ending status changes and starting them on non-pc units (when needed)]
  5562. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5563. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5564. /// @param bl Sends packet to clients around this object
  5565. /// @param id ID of object that has this effect
  5566. /// @param type Status icon see enum efst_type
  5567. /// @param flag 1:Active, 0:Deactive
  5568. /// @param tick Duration in ms
  5569. /// @param val1
  5570. /// @param val2
  5571. /// @param val3
  5572. void clif_status_change_sub(struct block_list *bl, int id, int type, int flag, t_tick tick, int val1, int val2, int val3, enum send_target target_type)
  5573. {
  5574. unsigned char buf[32];
  5575. if (type == EFST_BLANK) //It shows nothing on the client...
  5576. return;
  5577. if (type == EFST_POSTDELAY && tick == 0)
  5578. return;
  5579. nullpo_retv(bl);
  5580. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5581. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5582. tick = 200;
  5583. #if PACKETVER >= 20120618
  5584. if (flag && battle_config.display_status_timers)
  5585. WBUFW(buf,0) = 0x983;
  5586. else
  5587. #elif PACKETVER >= 20090121
  5588. if (flag && battle_config.display_status_timers)
  5589. WBUFW(buf,0) = 0x43f;
  5590. else
  5591. #endif
  5592. WBUFW(buf,0) = 0x196;
  5593. WBUFW(buf,2) = type;
  5594. WBUFL(buf,4) = id;
  5595. WBUFB(buf,8) = flag;
  5596. #if PACKETVER >= 20120618
  5597. if (flag && battle_config.display_status_timers) {
  5598. if (tick <= 0)
  5599. tick = 9999; // this is indeed what official servers do
  5600. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5601. WBUFL(buf,13) = client_tick(tick);
  5602. WBUFL(buf,17) = val1;
  5603. WBUFL(buf,21) = val2;
  5604. WBUFL(buf,25) = val3;
  5605. }
  5606. #elif PACKETVER >= 20090121
  5607. if (flag && battle_config.display_status_timers) {
  5608. if (tick <= 0)
  5609. tick = 9999; // this is indeed what official servers do
  5610. WBUFL(buf,9) = client_tick(tick);
  5611. WBUFL(buf,13) = val1;
  5612. WBUFL(buf,17) = val2;
  5613. WBUFL(buf,21) = val3;
  5614. }
  5615. #endif
  5616. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5617. }
  5618. /* Sends status effect to clients around the bl
  5619. * @param bl Object that has the effect
  5620. * @param type Status icon see enum efst_type
  5621. * @param flag 1:Active, 0:Deactive
  5622. * @param tick Duration in ms
  5623. * @param val1
  5624. * @param val2
  5625. * @param val3
  5626. */
  5627. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5628. map_session_data *sd = NULL;
  5629. if (type == EFST_BLANK) //It shows nothing on the client...
  5630. return;
  5631. if (type == EFST_POSTDELAY && tick == 0)
  5632. return;
  5633. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5634. return;
  5635. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5636. // Older clients display normal riding icon.
  5637. if (type == EFST_MADOGEAR)
  5638. type = EFST_RIDING;
  5639. #endif
  5640. nullpo_retv(bl);
  5641. sd = BL_CAST(BL_PC, bl);
  5642. // Check if current bl type is in the returned bitmask and only send status changes that actually matter to the client
  5643. if (!(status_efst_get_bl_type(static_cast<efst_type>(type)) & bl->type))
  5644. return;
  5645. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5646. }
  5647. /**
  5648. * Send any active EFST to those around.
  5649. * @param tbl: Unit to send the packet to
  5650. * @param bl: Objects walking into view
  5651. * @param target: Client send type
  5652. */
  5653. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5654. unsigned char i;
  5655. struct sc_display_entry **sc_display;
  5656. unsigned char sc_display_count;
  5657. bool spheres_sent;
  5658. nullpo_retv(bl);
  5659. switch( bl->type ){
  5660. case BL_PC: {
  5661. map_session_data* sd = (map_session_data*)bl;
  5662. sc_display = sd->sc_display;
  5663. sc_display_count = sd->sc_display_count;
  5664. spheres_sent = !sd->state.connect_new;
  5665. }
  5666. break;
  5667. case BL_NPC: {
  5668. struct npc_data* nd = (struct npc_data*)bl;
  5669. sc_display = nd->sc_display;
  5670. sc_display_count = nd->sc_display_count;
  5671. spheres_sent = true;
  5672. }
  5673. break;
  5674. default:
  5675. return;
  5676. }
  5677. for (i = 0; i < sc_display_count; i++) {
  5678. enum sc_type type = sc_display[i]->type;
  5679. status_change *sc = status_get_sc(bl);
  5680. const struct TimerData *td = (sc && sc->getSCE(type) ? get_timer(sc->getSCE(type)->timer) : NULL);
  5681. t_tick tick = 0;
  5682. if (td)
  5683. tick = DIFF_TICK(td->tick, gettick());
  5684. // Status changes that need special handling
  5685. switch( type ){
  5686. case SC_SPHERE_1:
  5687. case SC_SPHERE_2:
  5688. case SC_SPHERE_3:
  5689. case SC_SPHERE_4:
  5690. case SC_SPHERE_5:
  5691. if( spheres_sent ){
  5692. target = AREA_WOS;
  5693. }
  5694. break;
  5695. case SC_HELLS_PLANT:
  5696. if( sc && sc->getSCE(type) ){
  5697. tick = sc->getSCE(type)->val4;
  5698. }
  5699. break;
  5700. }
  5701. #if PACKETVER > 20120418
  5702. clif_efst_status_change(tbl, bl->id, target, status_db.getIcon(type), tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5703. #else
  5704. clif_status_change_sub(tbl, bl->id, status_db.getIcon(type), 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5705. #endif
  5706. }
  5707. }
  5708. /// Notifies the client when a player enters the screen with an active EFST.
  5709. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5710. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5711. void clif_efst_status_change(struct block_list *bl, int tid, enum send_target target, int type, t_tick tick, int val1, int val2, int val3) {
  5712. #if PACKETVER >= 20111108
  5713. unsigned char buf[32];
  5714. #if PACKETVER >= 20120618
  5715. const int cmd = 0x984;
  5716. #elif PACKETVER >= 20111108
  5717. const int cmd = 0x8ff;
  5718. #endif
  5719. int offset = 0;
  5720. if (type == EFST_BLANK)
  5721. return;
  5722. nullpo_retv(bl);
  5723. if (tick <= 0)
  5724. tick = 9999;
  5725. WBUFW(buf,offset + 0) = cmd;
  5726. WBUFL(buf,offset + 2) = tid;
  5727. WBUFW(buf,offset + 6) = type;
  5728. #if PACKETVER >= 20111108
  5729. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5730. #if PACKETVER >= 20120618
  5731. WBUFL(buf,offset + 12) = client_tick(tick);
  5732. offset += 4;
  5733. #endif
  5734. WBUFL(buf,offset + 12) = val1;
  5735. WBUFL(buf,offset + 16) = val2;
  5736. WBUFL(buf,offset + 20) = val3;
  5737. #endif
  5738. clif_send(buf,packet_len(cmd),bl,target);
  5739. #endif
  5740. }
  5741. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5742. /// 008e <packet len>.W <message>.?B
  5743. void clif_displaymessage(const int fd, const char* mes)
  5744. {
  5745. nullpo_retv(mes);
  5746. if( session_isActive( fd ) ){
  5747. char *message, *line;
  5748. message = aStrdup(mes);
  5749. line = strtok(message, "\n");
  5750. while(line != NULL) {
  5751. #if PACKETVER == 20141022
  5752. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5753. /** so we redirect to ZC_NPC_CHAT **/
  5754. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5755. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5756. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5757. if (len > 0) {
  5758. WFIFOHEAD(fd, 13 + len);
  5759. WFIFOW(fd, 0) = 0x2C1;
  5760. WFIFOW(fd, 2) = 13 + len;
  5761. WFIFOL(fd, 4) = 0;
  5762. WFIFOL(fd, 8) = color;
  5763. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5764. WFIFOSET(fd, WFIFOW(fd, 2));
  5765. }
  5766. #else
  5767. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5768. int len = strnlen(line, CHAT_SIZE_MAX);
  5769. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5770. WFIFOHEAD(fd, 5 + len);
  5771. WFIFOW(fd,0) = 0x8e;
  5772. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5773. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5774. WFIFOSET(fd, 5 + len);
  5775. }
  5776. #endif
  5777. line = strtok(NULL, "\n");
  5778. }
  5779. aFree(message);
  5780. }
  5781. }
  5782. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5783. /// 009a <packet len>.W <message>.?B
  5784. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5785. {
  5786. nullpo_retv(mes);
  5787. if (len < 2)
  5788. return;
  5789. struct PACKET_ZC_BROADCAST* p = (struct PACKET_ZC_BROADCAST*)packet_buffer;
  5790. p->packetType = HEADER_ZC_BROADCAST;
  5791. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST ) + len );
  5792. if( ( type&BC_BLUE ) != 0 ){
  5793. const char* color = "blue";
  5794. int16 length = (int16)strlen( color );
  5795. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5796. strcpy( p->message, color );
  5797. strncpy( &p->message[length], mes, len );
  5798. p->PacketLength += length;
  5799. }else if( ( type&BC_WOE ) != 0 ){
  5800. const char* color = "ssss";
  5801. int16 length = (int16)strlen( color );
  5802. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5803. strcpy( p->message, color );
  5804. strncpy( &p->message[length], mes, len );
  5805. p->PacketLength += length;
  5806. }else{
  5807. strncpy( p->message, mes, len );
  5808. }
  5809. clif_send( p, p->PacketLength, bl, target );
  5810. }
  5811. /*==========================================
  5812. * Displays a message on a 'bl' to all it's nearby clients
  5813. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5814. *------------------------------------------*/
  5815. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5816. nullpo_retv(bl);
  5817. nullpo_retv(message);
  5818. int16 len = (int16)( strlen( message ) + 1 );
  5819. if( len > CHAT_SIZE_MAX ) {
  5820. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5821. len = CHAT_SIZE_MAX;
  5822. }
  5823. struct PACKET_ZC_NOTIFY_CHAT* p = (struct PACKET_ZC_NOTIFY_CHAT*)packet_buffer;
  5824. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5825. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_NOTIFY_CHAT ) + len );
  5826. p->GID = bl->id;
  5827. safestrncpy( p->Message, message, len );
  5828. clif_send( p, p->PacketLength, bl, target );
  5829. }
  5830. /// Send broadcast message with font formatting.
  5831. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5832. void clif_broadcast2(struct block_list* bl, const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target)
  5833. {
  5834. nullpo_retv(mes);
  5835. if (len < 2)
  5836. return;
  5837. struct PACKET_ZC_BROADCAST2* p = (struct PACKET_ZC_BROADCAST2*)packet_buffer;
  5838. p->packetType = HEADER_ZC_BROADCAST2;
  5839. p->PacketLength = (int16)( sizeof( struct PACKET_ZC_BROADCAST2 ) + len );
  5840. p->fontColor = fontColor;
  5841. p->fontType = fontType;
  5842. p->fontSize = fontSize;
  5843. p->fontAlign = fontAlign;
  5844. p->fontY = fontY;
  5845. strncpy( p->message, mes, len );
  5846. clif_send( p, p->PacketLength, bl, target );
  5847. }
  5848. /*
  5849. * Display *msg to all *users in channel
  5850. */
  5851. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5852. DBIterator *iter;
  5853. map_session_data *user;
  5854. unsigned short msg_len = 0, len = 0;
  5855. unsigned char buf[CHAT_SIZE_MAX];
  5856. if (!channel || !msg)
  5857. return;
  5858. msg_len = (unsigned short)(strlen(msg) + 1);
  5859. if( msg_len > sizeof(buf)-12 ) {
  5860. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5861. msg_len = sizeof(buf)-12;
  5862. }
  5863. WBUFW(buf,0) = 0x2C1;
  5864. WBUFW(buf,2) = (len = msg_len + 12);
  5865. WBUFL(buf,4) = 0;
  5866. WBUFL(buf,8) = color;
  5867. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5868. iter = db_iterator(channel->users);
  5869. for( user = (map_session_data *)dbi_first(iter); dbi_exists(iter); user = (map_session_data *)dbi_next(iter) ) {
  5870. clif_send(buf, len, &user->bl, SELF);
  5871. }
  5872. dbi_destroy(iter);
  5873. }
  5874. /// Displays heal effect.
  5875. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5876. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5877. /// var id:
  5878. /// 5 = HP (SP_HP)
  5879. /// 7 = SP (SP_SP)
  5880. /// ? = ignored
  5881. void clif_heal(int fd,int type,int val) {
  5882. #if PACKETVER < 20141022
  5883. const int cmd = 0x13d;
  5884. #else
  5885. const int cmd = 0xa27;
  5886. #endif
  5887. WFIFOHEAD(fd, packet_len(cmd));
  5888. WFIFOW(fd,0) = cmd;
  5889. WFIFOW(fd,2) = type;
  5890. #if PACKETVER < 20141022
  5891. WFIFOW(fd,4) = min(val, INT16_MAX);
  5892. #else
  5893. WFIFOL(fd,4) = min(val, INT32_MAX);
  5894. #endif
  5895. WFIFOSET(fd, packet_len(cmd));
  5896. }
  5897. /// Displays resurrection effect (ZC_RESURRECTION).
  5898. /// 0148 <id>.L <type>.W
  5899. /// type:
  5900. /// ignored
  5901. void clif_resurrection(struct block_list *bl,int type)
  5902. {
  5903. unsigned char buf[16];
  5904. nullpo_retv(bl);
  5905. WBUFW(buf,0)=0x148;
  5906. WBUFL(buf,2)=bl->id;
  5907. WBUFW(buf,6)=0;
  5908. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5909. if (disguised(bl))
  5910. clif_spawn(bl);
  5911. }
  5912. /// Sets the map property
  5913. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5914. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5915. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5916. {
  5917. #if PACKETVER >= 20121010
  5918. short cmd = 0x99b;
  5919. unsigned char buf[8];
  5920. #else
  5921. short cmd = 0x199;
  5922. unsigned char buf[4];
  5923. #endif
  5924. WBUFW(buf,0)=cmd;
  5925. WBUFW(buf,2)=property;
  5926. #if PACKETVER >= 20121010
  5927. struct map_data *mapdata = map_getmapdata(bl->m);
  5928. map_session_data *sd = BL_CAST(BL_PC, bl);
  5929. WBUFL(buf,4) = ((mapdata->getMapFlag(MF_PVP) || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5930. ((mapdata->getMapFlag(MF_BATTLEGROUND) || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5931. ((mapdata->getMapFlag(MF_BATTLEGROUND) || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5932. ((mapdata->getMapFlag(MF_FORCEMINEFFECT) || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5933. ((mapdata->getMapFlag(MF_NOLOCKON) || mapdata_flag_vs(mapdata) || (sd && sd->duel_group > 0))<<4)| // DISABLE_LOCKON - Only allow attacks on other players with shift key or /ns active
  5934. ((mapdata->getMapFlag(MF_PVP))<<5)| // COUNT_PK - Show the PvP counter
  5935. ((mapdata->getMapFlag(MF_PARTYLOCK))<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5936. ((mapdata->getMapFlag(MF_BATTLEGROUND))<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5937. ((mapdata->getMapFlag(MF_NOCOSTUME))<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5938. ((!mapdata->getMapFlag(MF_NOUSECART))<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5939. ((!mapdata->getMapFlag(MF_NOSUNMOONSTARMIRACLE))<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5940. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5941. #endif
  5942. clif_send(buf,packet_len(cmd),bl,t);
  5943. }
  5944. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5945. /// 01d6 <type>.W
  5946. void clif_map_type(map_session_data* sd, enum map_type type)
  5947. {
  5948. int fd;
  5949. nullpo_retv(sd);
  5950. fd=sd->fd;
  5951. WFIFOHEAD(fd,packet_len(0x1D6));
  5952. WFIFOW(fd,0)=0x1D6;
  5953. WFIFOW(fd,2)=type;
  5954. WFIFOSET(fd,packet_len(0x1D6));
  5955. }
  5956. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5957. /// 019a <id>.L <ranking>.L <total>.L
  5958. void clif_pvpset(map_session_data *sd,int pvprank,int pvpnum,int type)
  5959. {
  5960. if(type == 2) {
  5961. int fd = sd->fd;
  5962. WFIFOHEAD(fd,packet_len(0x19a));
  5963. WFIFOW(fd,0) = 0x19a;
  5964. WFIFOL(fd,2) = sd->bl.id;
  5965. WFIFOL(fd,6) = pvprank;
  5966. WFIFOL(fd,10) = pvpnum;
  5967. WFIFOSET(fd,packet_len(0x19a));
  5968. } else {
  5969. unsigned char buf[32];
  5970. WBUFW(buf,0) = 0x19a;
  5971. WBUFL(buf,2) = sd->bl.id;
  5972. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5973. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5974. else
  5975. WBUFL(buf,6) = pvprank;
  5976. WBUFL(buf,10) = pvpnum;
  5977. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5978. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5979. else if(!type)
  5980. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5981. else
  5982. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5983. }
  5984. }
  5985. /*==========================================
  5986. *
  5987. *------------------------------------------*/
  5988. void clif_map_property_mapall(int map_idx, enum map_property property)
  5989. {
  5990. struct block_list bl;
  5991. bl.id = 0;
  5992. bl.type = BL_NUL;
  5993. bl.m = map_idx;
  5994. clif_map_property( &bl, property, ALL_SAMEMAP );
  5995. }
  5996. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5997. /// 0188 <result>.W <index>.W <refine>.W
  5998. /// result:
  5999. /// 0 = success
  6000. /// 1 = failure
  6001. /// 2 = downgrade
  6002. void clif_refine(int fd, int fail, int index, int val)
  6003. {
  6004. WFIFOHEAD(fd,packet_len(0x188));
  6005. WFIFOW(fd,0)=0x188;
  6006. WFIFOW(fd,2)=fail;
  6007. WFIFOW(fd,4)=index+2;
  6008. WFIFOW(fd,6)=val;
  6009. WFIFOSET(fd,packet_len(0x188));
  6010. }
  6011. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  6012. /// 0223 <result>.L <nameid>.W
  6013. /// result:
  6014. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  6015. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  6016. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  6017. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  6018. void clif_upgrademessage( map_session_data* sd, int result, t_itemid item_id ){
  6019. struct PACKET_ZC_ACK_WEAPONREFINE p;
  6020. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  6021. p.result = result;
  6022. p.itemId = client_nameid( item_id );
  6023. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6024. }
  6025. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  6026. /// 0097 <packet len>.W <nick>.24B <message>.?B
  6027. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  6028. void clif_wis_message(map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  6029. int fd;
  6030. nullpo_retv(sd);
  6031. fd = sd->fd;
  6032. #if PACKETVER < 20091104
  6033. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  6034. WFIFOW(fd,0) = 0x97;
  6035. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  6036. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  6037. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  6038. WFIFOSET(fd,WFIFOW(fd,2));
  6039. #else
  6040. map_session_data *ssd = map_nick2sd(nick,false);
  6041. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  6042. WFIFOW(fd,0) = 0x97;
  6043. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  6044. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  6045. // If it is not a message from the server or a player from another map-server
  6046. if( ssd ){
  6047. gmlvl = pc_get_group_level(ssd);
  6048. }
  6049. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  6050. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  6051. WFIFOSET(fd,WFIFOW(fd,2));
  6052. #endif
  6053. }
  6054. /// Inform the player about the result of his whisper action
  6055. /// 0098 <result>.B (ZC_ACK_WHISPER).
  6056. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  6057. /// result:
  6058. /// 0 = success to send wisper
  6059. /// 1 = target character is not loged in
  6060. /// 2 = ignored by target
  6061. /// 3 = everyone ignored by target
  6062. void clif_wis_end(int fd, int result)
  6063. {
  6064. map_session_data *sd = (session_isActive(fd) ? (map_session_data *)session[fd]->session_data : NULL);
  6065. #if PACKETVER < 20131223
  6066. const int cmd = 0x98;
  6067. #else
  6068. const int cmd = 0x9df;
  6069. #endif
  6070. if (!sd)
  6071. return;
  6072. WFIFOHEAD(fd,packet_len(cmd));
  6073. WFIFOW(fd,0) = cmd;
  6074. WFIFOB(fd,2) = (char)result;
  6075. #if PACKETVER >= 20131223
  6076. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  6077. #endif
  6078. WFIFOSET(fd,packet_len(cmd));
  6079. }
  6080. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  6081. /// 0194 <char id>.L <name>.24B
  6082. /// 0af7 <flag>.W <char id>.L <name>.24B
  6083. void clif_solved_charname(int fd, int charid, const char* name)
  6084. {
  6085. #if PACKETVER >= 20180221
  6086. WFIFOHEAD(fd,packet_len(0xaf7));
  6087. WFIFOW(fd,0) = 0xaf7;
  6088. WFIFOW(fd,2) = name[0] ? 3 : 2;
  6089. WFIFOL(fd,4) = charid;
  6090. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  6091. WFIFOSET(fd,packet_len(0x0af7));
  6092. #else
  6093. WFIFOHEAD(fd,packet_len(0x194));
  6094. WFIFOW(fd,0)=0x194;
  6095. WFIFOL(fd,2)=charid;
  6096. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  6097. WFIFOSET(fd,packet_len(0x194));
  6098. #endif
  6099. }
  6100. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  6101. /// 017b <packet len>.W { <name id>.W }*
  6102. void clif_use_card(map_session_data *sd,int idx)
  6103. {
  6104. int i,c,ep;
  6105. int fd=sd->fd;
  6106. nullpo_retv(sd);
  6107. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  6108. return;
  6109. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  6110. return; //Avoid parsing invalid item indexes (no card/no item)
  6111. ep=sd->inventory_data[idx]->equip;
  6112. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6113. WFIFOW(fd,0)=0x17b;
  6114. for(i=c=0;i<MAX_INVENTORY;i++){
  6115. int j;
  6116. if(sd->inventory_data[i] == NULL)
  6117. continue;
  6118. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  6119. continue;
  6120. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  6121. continue;
  6122. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  6123. continue;
  6124. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  6125. continue;
  6126. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  6127. continue;
  6128. if(sd->inventory_data[i]->type == IT_ARMOR && (ep & EQP_ACC) && ((ep & EQP_ACC) != EQP_ACC) && ((sd->inventory_data[i]->equip & EQP_ACC) != (ep & EQP_ACC)) ) // specific accessory-card can only be inserted to specific accessory.
  6129. continue;
  6130. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  6131. if( j == sd->inventory_data[i]->slots ) // No room
  6132. continue;
  6133. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  6134. continue;
  6135. WFIFOW(fd,4+c*2)=i+2;
  6136. c++;
  6137. }
  6138. if( !c ) return; // no item is available for card insertion
  6139. WFIFOW(fd,2)=4+c*2;
  6140. WFIFOSET(fd,WFIFOW(fd,2));
  6141. }
  6142. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  6143. /// 017d <equip index>.W <card index>.W <result>.B
  6144. /// result:
  6145. /// 0 = success
  6146. /// 1 = failure
  6147. void clif_insert_card(map_session_data *sd,int idx_equip,int idx_card,int flag)
  6148. {
  6149. int fd;
  6150. nullpo_retv(sd);
  6151. fd=sd->fd;
  6152. WFIFOHEAD(fd,packet_len(0x17d));
  6153. WFIFOW(fd,0)=0x17d;
  6154. WFIFOW(fd,2)=idx_equip+2;
  6155. WFIFOW(fd,4)=idx_card+2;
  6156. WFIFOB(fd,6)=flag;
  6157. WFIFOSET(fd,packet_len(0x17d));
  6158. }
  6159. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  6160. /// 0177 <packet len>.W { <index>.W }*
  6161. void clif_item_identify_list(map_session_data *sd)
  6162. {
  6163. int i,c;
  6164. int fd;
  6165. nullpo_retv(sd);
  6166. fd=sd->fd;
  6167. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  6168. WFIFOW(fd,0)=0x177;
  6169. for(i=c=0;i<MAX_INVENTORY;i++){
  6170. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  6171. WFIFOW(fd,c*2+4)=client_index(i);
  6172. c++;
  6173. }
  6174. }
  6175. if(c > 0) {
  6176. WFIFOW(fd,2)=c*2+4;
  6177. WFIFOSET(fd,WFIFOW(fd,2));
  6178. sd->menuskill_id = MC_IDENTIFY;
  6179. sd->menuskill_val = c;
  6180. sd->state.workinprogress = WIP_DISABLE_ALL;
  6181. }
  6182. }
  6183. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  6184. /// 0179 <index>.W <result>.B
  6185. void clif_item_identified(map_session_data *sd,int idx,int flag)
  6186. {
  6187. int fd;
  6188. nullpo_retv(sd);
  6189. fd=sd->fd;
  6190. WFIFOHEAD(fd,packet_len(0x179));
  6191. WFIFOW(fd, 0)=0x179;
  6192. WFIFOW(fd, 2)=idx+2;
  6193. WFIFOB(fd, 4)=flag;
  6194. WFIFOSET(fd,packet_len(0x179));
  6195. }
  6196. /// Presents a list of items that can be repaired.
  6197. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6198. void clif_item_repair_list( map_session_data *sd,map_session_data *dstsd, int lv ){
  6199. nullpo_retv( sd );
  6200. nullpo_retv( dstsd );
  6201. int fd = sd->fd;
  6202. if( !session_isActive( fd ) ){
  6203. return;
  6204. }
  6205. int len = MAX_INVENTORY * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6206. // Preallocate the maximum size
  6207. WFIFOHEAD( fd, len );
  6208. struct PACKET_ZC_REPAIRITEMLIST *p = (struct PACKET_ZC_REPAIRITEMLIST *)WFIFOP( fd, 0 );
  6209. int c = 0;
  6210. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6211. if( dstsd->inventory.u.items_inventory[i].nameid > 0 && dstsd->inventory.u.items_inventory[i].attribute != 0 && !itemdb_ishatched_egg( &dstsd->inventory.u.items_inventory[i] ) ){ // && skill_can_repair(sd,nameid)){
  6212. p->items[c].index = i;
  6213. p->items[c].itemId = client_nameid( dstsd->inventory.u.items_inventory[i].nameid );
  6214. p->items[c].refine = dstsd->inventory.u.items_inventory[i].refine;
  6215. clif_addcards( &p->items[c].slot, &dstsd->inventory.u.items_inventory[i] );
  6216. c++;
  6217. }
  6218. }
  6219. if( c > 0 ){
  6220. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6221. // Recalculate real length
  6222. len = c * sizeof( struct REPAIRITEM_INFO ) + sizeof( struct PACKET_ZC_REPAIRITEMLIST );
  6223. p->packetLength = len;
  6224. WFIFOSET( fd, len );
  6225. sd->menuskill_id = BS_REPAIRWEAPON;
  6226. sd->menuskill_val = dstsd->bl.id;
  6227. sd->menuskill_val2 = lv;
  6228. }else{
  6229. clif_skill_fail( sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0 );
  6230. }
  6231. }
  6232. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  6233. /// 01fe <index>.W <result>.B
  6234. /// index:
  6235. /// ignored (inventory index)
  6236. /// result:
  6237. /// 0 = Item repair success.
  6238. /// 1 = Item repair failure.
  6239. void clif_item_repaireffect(map_session_data *sd,int idx,int flag)
  6240. {
  6241. int fd;
  6242. nullpo_retv(sd);
  6243. fd = sd->fd;
  6244. WFIFOHEAD(fd,packet_len(0x1fe));
  6245. WFIFOW(fd, 0)=0x1fe;
  6246. WFIFOW(fd, 2)=idx+2;
  6247. WFIFOB(fd, 4)=flag;
  6248. WFIFOSET(fd,packet_len(0x1fe));
  6249. }
  6250. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  6251. /// 02bb <equip location>.W <account id>.L
  6252. void clif_item_damaged(map_session_data* sd, unsigned short position)
  6253. {
  6254. int fd = sd->fd;
  6255. WFIFOHEAD(fd,packet_len(0x2bb));
  6256. WFIFOW(fd,0) = 0x2bb;
  6257. WFIFOW(fd,2) = position;
  6258. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6259. WFIFOSET(fd,packet_len(0x2bb));
  6260. }
  6261. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6262. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6263. void clif_item_refine_list( map_session_data *sd ){
  6264. nullpo_retv( sd );
  6265. struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *p = (struct PACKET_ZC_NOTIFY_WEAPONITEMLIST *)packet_buffer;
  6266. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6267. uint16 skill_lv = pc_checkskill( sd, WS_WEAPONREFINE );
  6268. int refine_item[MAX_WEAPON_LEVEL];
  6269. refine_item[0] = pc_search_inventory( sd, ITEMID_PHRACON );
  6270. refine_item[1] = pc_search_inventory( sd, ITEMID_EMVERETARCON );
  6271. refine_item[2] = refine_item[3] = pc_search_inventory( sd, ITEMID_ORIDECON );
  6272. #ifdef RENEWAL
  6273. refine_item[4] = -1;
  6274. #endif
  6275. int count = 0;
  6276. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6277. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  6278. sd->inventory_data[i] != nullptr && sd->inventory_data[i]->type == IT_WEAPON &&
  6279. sd->inventory.u.items_inventory[i].identify && sd->inventory_data[i]->weapon_level >= 1 &&
  6280. refine_item[sd->inventory_data[i]->weapon_level - 1] != -1 && !( sd->inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6281. p->items[count].index = client_index( i );
  6282. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  6283. p->items[count].refine = sd->inventory.u.items_inventory[i].refine;
  6284. clif_addcards( &p->items[count].slot, &sd->inventory.u.items_inventory[i] );
  6285. count++;
  6286. }
  6287. }
  6288. p->packetLength = sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST ) + sizeof( struct PACKET_ZC_NOTIFY_WEAPONITEMLIST_sub ) * count;
  6289. clif_send( p, p->packetLength, &sd->bl, SELF );
  6290. if( count > 0 ){
  6291. sd->menuskill_id = WS_WEAPONREFINE;
  6292. sd->menuskill_val = skill_lv;
  6293. }
  6294. }
  6295. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6296. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6297. void clif_item_skill( map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6298. nullpo_retv( sd );
  6299. struct PACKET_ZC_AUTORUN_SKILL p;
  6300. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6301. p.skill_id = skill_id;
  6302. p.skill_type = skill_get_inf( skill_id );
  6303. p.skill_lv = skill_lv;
  6304. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6305. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6306. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6307. p.up_flag = false;
  6308. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6309. }
  6310. /// Adds an item to character's cart.
  6311. /// 0124 <index>.W <amount>.L <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_CART)
  6312. /// 01c5 <index>.W <amount>.L <name id>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_CART2)
  6313. /// 0a0b <index>.W <amount>.L <name id>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ADD_ITEM_TO_CART3)
  6314. void clif_cart_additem( map_session_data *sd, int n, int amount ){
  6315. nullpo_retv( sd );
  6316. int fd = sd->fd;
  6317. if( !session_isActive( fd ) ){
  6318. return;
  6319. }
  6320. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6321. return;
  6322. }
  6323. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6324. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6325. p.index = client_index( n );
  6326. p.amount = amount;
  6327. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6328. #if PACKETVER >= 5
  6329. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6330. #endif
  6331. p.identified = sd->cart.u.items_cart[n].identify;
  6332. p.damaged = sd->cart.u.items_cart[n].attribute;
  6333. p.refine = sd->cart.u.items_cart[n].refine;
  6334. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6335. #if PACKETVER >= 20150226
  6336. clif_add_random_options( p.option_data, sd->cart.u.items_cart[n] );
  6337. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6338. p.grade = sd->cart.u.items_cart[n].enchantgrade;
  6339. #endif
  6340. #endif
  6341. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6342. }
  6343. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  6344. /* Acknowledge an item have been added to cart
  6345. * 012c <result>B
  6346. * result :
  6347. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6348. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6349. */
  6350. void clif_cart_additem_ack(map_session_data *sd, uint8 flag)
  6351. {
  6352. int fd;
  6353. unsigned char *buf;
  6354. nullpo_retv(sd);
  6355. fd = sd->fd;
  6356. buf = WFIFOP(fd,0);
  6357. WBUFW(buf,0) = 0x12c;
  6358. WBUFB(buf,2) = flag;
  6359. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6360. }
  6361. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6362. void clif_bank_open( map_session_data& sd ){
  6363. #if PACKETVER >= 20130717
  6364. struct PACKET_ZC_ACK_OPEN_BANKING p = {};
  6365. p.packetType = HEADER_ZC_ACK_OPEN_BANKING;
  6366. p.unknown = 0;
  6367. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6368. #endif
  6369. }
  6370. /*
  6371. * Request to Open the banking system
  6372. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6373. */
  6374. void clif_parse_BankOpen(int fd, map_session_data* sd) {
  6375. //TODO check if preventing trade or stuff like that
  6376. //also mark something in case char ain't available for saving, should we check now ?
  6377. nullpo_retv(sd);
  6378. if( !battle_config.feature_banking ) {
  6379. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6380. return;
  6381. }
  6382. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6383. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6384. return;
  6385. }
  6386. else {
  6387. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6388. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6389. if(sd->status.account_id == aid){
  6390. sd->state.banking = 1;
  6391. //request save ?
  6392. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6393. //on succes open bank ?
  6394. clif_bank_open( *sd );
  6395. }
  6396. }
  6397. }
  6398. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6399. void clif_bank_close( map_session_data& sd ){
  6400. #if PACKETVER >= 20130717
  6401. struct PACKET_ZC_ACK_CLOSE_BANKING p = {};
  6402. p.packetType = HEADER_ZC_ACK_CLOSE_BANKING;
  6403. p.unknown = 0;
  6404. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6405. #endif
  6406. }
  6407. /*
  6408. * Request to close the banking system
  6409. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6410. */
  6411. void clif_parse_BankClose(int fd, map_session_data* sd) {
  6412. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6413. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6414. nullpo_retv(sd);
  6415. if( !battle_config.feature_banking ) {
  6416. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6417. //still allow to go trough to not stuck player if we have disable it while they was in
  6418. }
  6419. if(sd->status.account_id == aid){
  6420. sd->state.banking = 0;
  6421. clif_bank_close( *sd );
  6422. }
  6423. }
  6424. /*
  6425. * Display how much we got in bank (I suppose)
  6426. * 09A6 <Bank_Vault>Q <Reason>W (ZC_BANKING_CHECK)
  6427. */
  6428. void clif_Bank_Check( map_session_data& sd ){
  6429. #if PACKETVER >= 20130717
  6430. struct PACKET_ZC_BANKING_CHECK p = {};
  6431. p.packetType = HEADER_ZC_BANKING_CHECK;
  6432. p.money = sd.bank_vault;
  6433. p.reason = 0;
  6434. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6435. #endif
  6436. }
  6437. /*
  6438. * Requesting the data in bank
  6439. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6440. */
  6441. void clif_parse_BankCheck(int fd, map_session_data* sd) {
  6442. nullpo_retv(sd);
  6443. if( !battle_config.feature_banking ) {
  6444. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6445. return;
  6446. }
  6447. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6448. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6449. return;
  6450. }
  6451. else {
  6452. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6453. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6454. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6455. clif_Bank_Check( *sd );
  6456. }
  6457. }
  6458. /*
  6459. * Acknowledge of deposit some money in bank
  6460. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6461. */
  6462. void clif_bank_deposit( map_session_data& sd, enum e_BANKING_DEPOSIT_ACK reason ){
  6463. #if PACKETVER >= 20130717
  6464. struct PACKET_ZC_ACK_BANKING_DEPOSIT p = {};
  6465. p.packetType = HEADER_ZC_ACK_BANKING_DEPOSIT;
  6466. p.money = sd.bank_vault;
  6467. p.zeny = sd.status.zeny;
  6468. p.reason = reason;
  6469. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6470. #endif
  6471. }
  6472. /*
  6473. * Request saving some money in bank
  6474. * @author : original [Yommy/Hercules]
  6475. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6476. */
  6477. void clif_parse_BankDeposit(int fd, map_session_data* sd) {
  6478. nullpo_retv(sd);
  6479. if( !battle_config.feature_banking ) {
  6480. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6481. return;
  6482. }
  6483. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6484. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6485. return;
  6486. }
  6487. else {
  6488. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6489. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6490. int money = RFIFOL(fd,info->pos[1]);
  6491. if(sd->status.account_id == aid){
  6492. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6493. clif_bank_deposit( *sd, reason );
  6494. }
  6495. }
  6496. }
  6497. /*
  6498. * Acknowledge of withdrawing some money from bank
  6499. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6500. */
  6501. void clif_bank_withdraw( map_session_data& sd, enum e_BANKING_WITHDRAW_ACK reason ){
  6502. #if PACKETVER >= 20130717
  6503. struct PACKET_ZC_ACK_BANKING_WITHDRAW p = {};
  6504. p.packetType = HEADER_ZC_ACK_BANKING_WITHDRAW;
  6505. p.reason = reason;
  6506. p.money = sd.bank_vault;
  6507. p.zeny = sd.status.zeny;
  6508. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6509. #endif
  6510. }
  6511. /*
  6512. * Request Withdrawing some money from bank
  6513. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6514. */
  6515. void clif_parse_BankWithdraw(int fd, map_session_data* sd) {
  6516. nullpo_retv(sd);
  6517. if( !battle_config.feature_banking ) {
  6518. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6519. return;
  6520. }
  6521. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6522. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6523. return;
  6524. }
  6525. else {
  6526. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6527. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6528. int money = RFIFOL(fd,info->pos[1]);
  6529. if(sd->status.account_id == aid){
  6530. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6531. clif_bank_withdraw( *sd, reason );
  6532. }
  6533. }
  6534. }
  6535. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6536. /// 0125 <index>.W <amount>.L
  6537. void clif_cart_delitem(map_session_data *sd,int n,int amount)
  6538. {
  6539. int fd;
  6540. nullpo_retv(sd);
  6541. fd=sd->fd;
  6542. WFIFOHEAD(fd,packet_len(0x125));
  6543. WFIFOW(fd,0)=0x125;
  6544. WFIFOW(fd,2)=n+2;
  6545. WFIFOL(fd,4)=amount;
  6546. WFIFOSET(fd,packet_len(0x125));
  6547. }
  6548. /// Opens the shop creation menu (ZC_OPENSTORE).
  6549. /// 012d <num>.W
  6550. /// num:
  6551. /// number of allowed item slots
  6552. void clif_openvendingreq(map_session_data* sd, int num)
  6553. {
  6554. int fd;
  6555. nullpo_retv(sd);
  6556. fd = sd->fd;
  6557. WFIFOHEAD(fd,packet_len(0x12d));
  6558. WFIFOW(fd,0) = 0x12d;
  6559. WFIFOW(fd,2) = num;
  6560. WFIFOSET(fd,packet_len(0x12d));
  6561. }
  6562. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6563. /// 0131 <owner id>.L <message>.80B
  6564. void clif_showvendingboard( map_session_data& sd, enum send_target target, struct block_list* tbl ){
  6565. if( tbl == nullptr ){
  6566. tbl = &sd.bl;
  6567. target = AREA_WOS;
  6568. }
  6569. struct PACKET_ZC_STORE_ENTRY p = {};
  6570. p.packetType = HEADER_ZC_STORE_ENTRY;
  6571. p.makerAID = sd.status.account_id;
  6572. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  6573. clif_send( &p, sizeof( p ), tbl, target );
  6574. }
  6575. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6576. /// 0132 <owner id>.L
  6577. void clif_closevendingboard(struct block_list* bl, int fd)
  6578. {
  6579. unsigned char buf[16];
  6580. nullpo_retv(bl);
  6581. WBUFW(buf,0) = 0x132;
  6582. WBUFL(buf,2) = bl->id;
  6583. if( session_isActive(fd) ) {
  6584. WFIFOHEAD(fd,packet_len(0x132));
  6585. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6586. WFIFOSET(fd,packet_len(0x132));
  6587. } else {
  6588. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6589. }
  6590. }
  6591. /// Sends a list of items in a shop.
  6592. /// R 0133 <packet len>.W <owner id>.L { <price>.L <amount>.W <index>.W <type>.B <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_PC_PURCHASE_ITEMLIST_FROMMC)
  6593. /// R 0800 <packet len>.W <owner id>.L <unique id>.L { <price>.L <amount>.W <index>.W <type>.B <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_PC_PURCHASE_ITEMLIST_FROMMC2)
  6594. void clif_vendinglist( map_session_data* sd, map_session_data* vsd ){
  6595. nullpo_retv( sd );
  6596. nullpo_retv( vsd );
  6597. nullpo_retv( vsd->vending );
  6598. int fd = sd->fd;
  6599. if( !session_isActive( fd ) ){
  6600. return;
  6601. }
  6602. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6603. WFIFOHEAD( fd, len );
  6604. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6605. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6606. p->packetLength = len;
  6607. p->AID = vsd->status.account_id;
  6608. #if PACKETVER >= 20100105
  6609. p->venderId = vsd->vender_id;
  6610. #endif
  6611. for( int i = 0; i < vsd->vend_num; i++ ){
  6612. int index = vsd->vending[i].index;
  6613. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6614. p->items[i].price = vsd->vending[i].value;
  6615. p->items[i].amount = vsd->vending[i].amount;
  6616. p->items[i].index = client_index( index );
  6617. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6618. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6619. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6620. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6621. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6622. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6623. #if PACKETVER >= 20150226
  6624. clif_add_random_options( p->items[i].option_data, vsd->cart.u.items_cart[index] );
  6625. #if PACKETVER >= 20160921
  6626. p->items[i].location = pc_equippoint_sub( sd, data );
  6627. p->items[i].viewSprite = data->look;
  6628. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6629. p->items[i].grade = vsd->cart.u.items_cart[index].enchantgrade;
  6630. #endif
  6631. #endif
  6632. #endif
  6633. }
  6634. WFIFOSET( fd, len );
  6635. }
  6636. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6637. /// 0135 <index>.W <amount>.W <result>.B
  6638. /// result:
  6639. /// 0 = success
  6640. /// 1 = not enough zeny
  6641. /// 2 = overweight
  6642. /// 4 = out of stock
  6643. /// 5 = "cannot use an npc shop while in a trade"
  6644. /// 6 = Because the store information was incorrect the item was not purchased.
  6645. /// 7 = No sales information.
  6646. void clif_buyvending(map_session_data* sd, int index, int amount, int fail)
  6647. {
  6648. int fd;
  6649. nullpo_retv(sd);
  6650. fd = sd->fd;
  6651. WFIFOHEAD(fd,packet_len(0x135));
  6652. WFIFOW(fd,0) = 0x135;
  6653. WFIFOW(fd,2) = index+2;
  6654. WFIFOW(fd,4) = amount;
  6655. WFIFOB(fd,6) = fail;
  6656. WFIFOSET(fd,packet_len(0x135));
  6657. }
  6658. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6659. /// 0a28 <Result>.B
  6660. /// result:
  6661. /// 0 = Successed
  6662. /// 1 = Failed
  6663. void clif_openvending_ack(map_session_data* sd, int result)
  6664. {
  6665. int fd;
  6666. nullpo_retv(sd);
  6667. fd = sd->fd;
  6668. WFIFOHEAD(fd, 3);
  6669. WFIFOW(fd,0) = 0xa28;
  6670. WFIFOB(fd,2) = result;
  6671. WFIFOSET(fd, 3);
  6672. }
  6673. /// Shop creation success.
  6674. /// 0136 <packet len>.W <owner id>.L { <price>.L <index>.W <amount>.W <type>.B <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_PC_PURCHASE_MYITEMLIST)
  6675. void clif_openvending( map_session_data* sd, int id, struct s_vending* vending ){
  6676. nullpo_retv( sd );
  6677. nullpo_retv( vending );
  6678. int fd = sd->fd;
  6679. if( !session_isActive( fd ) ){
  6680. return;
  6681. }
  6682. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6683. WFIFOHEAD( fd, len );
  6684. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6685. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6686. p->packetLength = len;
  6687. p->AID = id;
  6688. for( int i = 0; i < sd->vend_num; i++ ) {
  6689. int index = vending[i].index;
  6690. p->items[i].price = vending[i].value;
  6691. p->items[i].index = client_index( index );
  6692. p->items[i].amount = vending[i].amount;
  6693. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6694. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6695. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6696. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6697. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6698. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6699. #if PACKETVER >= 20150226
  6700. clif_add_random_options( p->items[i].option_data, sd->cart.u.items_cart[index] );
  6701. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6702. p->items[i].grade = sd->cart.u.items_cart[index].enchantgrade;
  6703. #endif
  6704. #endif
  6705. }
  6706. WFIFOSET( fd, len );
  6707. #if PACKETVER >= 20141022
  6708. /// 0 = Successed
  6709. /// 1 = Failed
  6710. clif_openvending_ack( sd, 0 );
  6711. #endif
  6712. }
  6713. /// Inform merchant that someone has bought an item.
  6714. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6715. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6716. void clif_vendingreport(map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6717. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6718. const int cmd = 0x137;
  6719. #else
  6720. const int cmd = 0x9e5;
  6721. #endif
  6722. int fd = sd->fd;
  6723. nullpo_retv(sd);
  6724. WFIFOHEAD(fd,packet_len(cmd));
  6725. WFIFOW(fd,0) = cmd;
  6726. WFIFOW(fd,2) = index+2;
  6727. WFIFOW(fd,4) = amount;
  6728. #if PACKETVER >= 20141016
  6729. WFIFOL(fd,6) = char_id; // GID
  6730. WFIFOL(fd,10) = (int)time(NULL); // Date
  6731. WFIFOL(fd,14) = zeny; // zeny
  6732. #endif
  6733. WFIFOSET(fd,packet_len(cmd));
  6734. }
  6735. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6736. /// 00fa <result>.B
  6737. /// result:
  6738. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6739. /// 1 = MsgStringTable[78]="party name already exists"
  6740. /// 2 = MsgStringTable[79]="already in a party"
  6741. /// 3 = cannot organize parties on this map
  6742. /// ? = nothing
  6743. void clif_party_created( map_session_data& sd, int result ){
  6744. struct PACKET_ZC_ACK_MAKE_GROUP p = {};
  6745. p.PacketType = HEADER_ZC_ACK_MAKE_GROUP;
  6746. p.result = result;
  6747. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6748. }
  6749. /// Adds new member to a party.
  6750. /// 0104 <account id>.L <role>.L <x>.W <y>.W <state>.B <party name>.24B <char name>.24B <map name>.16B (ZC_ADD_MEMBER_TO_GROUP)
  6751. /// 01e9 <account id>.L <role>.L <x>.W <y>.W <state>.B <party name>.24B <char name>.24B <map name>.16B <item pickup rule>.B <item share rule>.B (ZC_ADD_MEMBER_TO_GROUP2)
  6752. /// 0a43 <account id>.L <role>.L <class>.W <base level>.W <x>.W <y>.W <state>.B <party name>.24B <char name>.24B <map name>.16B <item pickup rule>.B <item share rule>.B (ZC_ADD_MEMBER_TO_GROUP3)
  6753. /// role:
  6754. /// 0 = leader
  6755. /// 1 = normal
  6756. /// state:
  6757. /// 0 = connected
  6758. /// 1 = disconnected
  6759. void clif_party_member_info( struct party_data& party, map_session_data& sd ){
  6760. int id = party_getmemberid( &party, &sd );
  6761. if( id < 0 ){
  6762. return;
  6763. }
  6764. struct PACKET_ZC_ADD_MEMBER_TO_GROUP p = {};
  6765. p.packetType = partymemberinfo;
  6766. p.AID = sd.status.account_id;
  6767. #if PACKETVER >= 20171207
  6768. p.GID = sd.status.char_id;
  6769. #endif
  6770. p.leader = ( party.party.member[id].leader != 0 ) ? 0 : 1;
  6771. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6772. p.class_ = sd.status.class_;
  6773. p.baseLevel = sd.status.base_level;
  6774. #endif
  6775. p.x = sd.bl.x;
  6776. p.y = sd.bl.y;
  6777. p.offline = ( party.party.member[id].online != 0 ) ? 0 : 1;
  6778. safestrncpy( p.partyName, party.party.name, sizeof( p.partyName ) );
  6779. safestrncpy( p.playerName, sd.status.name, sizeof( p.playerName ) );
  6780. mapindex_getmapname_ext( map_mapid2mapname( sd.bl.m ), p.mapName );
  6781. p.sharePickup = ( party.party.item&1 ) ? 1 : 0;
  6782. p.shareLoot = ( party.party.item&2 )? 1 : 0;
  6783. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6784. }
  6785. /// Sends party information (ZC_GROUP_LIST).
  6786. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6787. /// role:
  6788. /// 0 = leader
  6789. /// 1 = normal
  6790. /// state:
  6791. /// 0 = connected
  6792. /// 1 = disconnected
  6793. /// 0a44 <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B <class>.W <base level>.W }* <item pickup rule>.B <item share rule>.B <unknown>.L
  6794. void clif_party_info( struct party_data& party, map_session_data* sd ){
  6795. send_target target;
  6796. if( sd == nullptr ){
  6797. sd = party_getavailablesd( &party );
  6798. if( sd == nullptr ){
  6799. // Nobody is online to notify
  6800. return;
  6801. }
  6802. // Send to whole party
  6803. target = PARTY;
  6804. }else{
  6805. // Send only to self
  6806. target = SELF;
  6807. }
  6808. struct PACKET_ZC_GROUP_LIST* p = (struct PACKET_ZC_GROUP_LIST*)packet_buffer;
  6809. p->packetType = partyinfo;
  6810. p->packetLen = sizeof( *p );
  6811. safestrncpy( p->partyName, party.party.name, sizeof( p->partyName ) );
  6812. for( int i = 0, c = 0; i < MAX_PARTY; i++ ){
  6813. struct party_member& m = party.party.member[i];
  6814. if( m.account_id == 0 ){
  6815. continue;
  6816. }
  6817. struct PACKET_ZC_GROUP_LIST_SUB& member = p->members[c];
  6818. member.AID = m.account_id;
  6819. #if PACKETVER >= 20171207
  6820. member.GID = m.char_id;
  6821. #endif
  6822. safestrncpy( member.playerName, m.name, sizeof( member.playerName ) );
  6823. mapindex_getmapname_ext( m.map, member.mapName );
  6824. member.leader = ( m.leader ) ? 0 : 1;
  6825. member.offline = ( m.online ) ? 0 : 1;
  6826. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6827. member.class_ = m.class_;
  6828. member.baseLevel = m.lv;
  6829. #endif
  6830. c++;
  6831. p->packetLen += sizeof( member );
  6832. }
  6833. clif_send( p, p->packetLen, &sd->bl, target );
  6834. }
  6835. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6836. /// 02c9 <flag>.B
  6837. /// flag:
  6838. /// 0 = allow party invites
  6839. /// 1 = auto-deny party invites
  6840. void clif_partyinvitationstate( map_session_data& sd ){
  6841. #if PACKETVER_MAIN_NUM >= 20070911 || defined(PACKETVER_RE) || PACKETVER_AD_NUM >= 20070911 || PACKETVER_SAK_NUM >= 20070904 || defined(PACKETVER_ZERO)
  6842. struct PACKET_ZC_PARTY_CONFIG p = {};
  6843. p.packetType = HEADER_ZC_PARTY_CONFIG;
  6844. p.denyPartyInvites = 0; // TODO: not implemented
  6845. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6846. #endif
  6847. }
  6848. /// Party invitation request.
  6849. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6850. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6851. void clif_party_invite( map_session_data& sd, map_session_data& tsd ){
  6852. struct party_data* party = party_search( sd.status.party_id );
  6853. if( party == nullptr ){
  6854. return;
  6855. }
  6856. struct PACKET_ZC_PARTY_JOIN_REQ p = {};
  6857. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ;
  6858. p.GRID = party->party.party_id;
  6859. safestrncpy( p.groupName, party->party.name, sizeof( p.groupName ) );
  6860. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6861. }
  6862. /// Party invite result.
  6863. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6864. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6865. /// result=0 : char is already in a party -> MsgStringTable[80]
  6866. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6867. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6868. /// result=3 : party is full -> MsgStringTable[83]
  6869. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6870. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6871. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6872. /// result=8 : (%s) are currently in restricted map to join a party. -> MsgStringTable[1388] (since 20080527)
  6873. /// result=9 : Cannot join a party in this map. -> MsgStringTable[1871] (since 20110215)
  6874. /// result=10 : You cannot invite or withdraw while in memorial dungeon -> message: MSG_ID_BD3 (since 20161130)
  6875. /// result=11 : The character is a level that can not join the party -> message: MSG_ID_C9A (since 20170412)
  6876. void clif_party_invite_reply( map_session_data& sd, const char* nick, enum e_party_invite_reply reply ){
  6877. #if PACKETVER < 20070904
  6878. if( reply == PARTY_REPLY_OFFLINE ){
  6879. clif_displaymessage( sd.fd, msg_txt( &sd, 3 ) ); // Character not found.
  6880. return;
  6881. }
  6882. #endif
  6883. struct PACKET_ZC_PARTY_JOIN_REQ_ACK p = {};
  6884. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ_ACK;
  6885. safestrncpy( p.characterName, nick, sizeof( p.characterName ) );
  6886. p.result = reply;
  6887. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6888. }
  6889. /// Updates party settings.
  6890. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6891. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6892. /// exp option:
  6893. /// 0 = exp sharing disabled
  6894. /// 1 = exp sharing enabled
  6895. /// 2 = cannot change exp sharing
  6896. ///
  6897. /// flag:
  6898. /// 0 = send to party
  6899. /// 1 = send to sd
  6900. void clif_party_option(struct party_data *p,map_session_data *sd,int flag)
  6901. {
  6902. unsigned char buf[16];
  6903. #if PACKETVER < 20090603
  6904. const int cmd = 0x101;
  6905. #else
  6906. const int cmd = 0x7d8;
  6907. #endif
  6908. nullpo_retv(p);
  6909. if(!sd && flag==0){
  6910. int i;
  6911. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6912. if (i < MAX_PARTY)
  6913. sd = p->data[i].sd;
  6914. }
  6915. if(!sd) return;
  6916. WBUFW(buf,0)=cmd;
  6917. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6918. #if PACKETVER >= 20090603
  6919. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6920. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6921. #endif
  6922. if(flag==0)
  6923. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6924. else
  6925. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6926. }
  6927. /**
  6928. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6929. * @param sd Send the notification for this player
  6930. * @param account_id Account ID of kicked member
  6931. * @param name Name of kicked member
  6932. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6933. * @param target Send target
  6934. **/
  6935. void clif_party_withdraw( map_session_data& sd, uint32 account_id, const char* name, enum e_party_member_withdraw result, enum send_target target ){
  6936. struct PACKET_ZC_DELETE_MEMBER_FROM_GROUP p = {};
  6937. p.PacketType = HEADER_ZC_DELETE_MEMBER_FROM_GROUP;
  6938. p.AID = account_id;
  6939. safestrncpy( p.characterName, name, sizeof( p.characterName ) );
  6940. p.result = result;
  6941. clif_send( &p, sizeof( p ), &sd.bl, target );
  6942. }
  6943. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6944. /// 0109 <packet len>.W <account id>.L <message>.?B
  6945. void clif_party_message( struct party_data& party, uint32 account_id, const char* mes, int len ){
  6946. map_session_data* sd = party_getavailablesd( &party );
  6947. if( sd == nullptr ){
  6948. return;
  6949. }
  6950. if (len > CHAT_SIZE_MAX) {
  6951. ShowWarning( "clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, CHAT_SIZE_MAX, party.party.party_id );
  6952. len = CHAT_SIZE_MAX;
  6953. }
  6954. struct PACKET_ZC_NOTIFY_CHAT_PARTY* p = (struct PACKET_ZC_NOTIFY_CHAT_PARTY*)packet_buffer;
  6955. p->PacketType = HEADER_ZC_NOTIFY_CHAT_PARTY;
  6956. p->PacketLength = sizeof( *p ) + len;
  6957. p->AID = account_id;
  6958. safestrncpy( p->chatMsg, mes, len );
  6959. clif_send( p, p->PacketLength, &sd->bl, PARTY );
  6960. }
  6961. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6962. /// 0107 <account id>.L <x>.W <y>.W
  6963. void clif_party_xy( map_session_data& sd ){
  6964. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6965. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6966. p.AID = sd.status.account_id;
  6967. p.xPos = sd.bl.x;
  6968. p.yPos = sd.bl.y;
  6969. clif_send( &p, sizeof( p ), &sd.bl, PARTY_SAMEMAP_WOS );
  6970. }
  6971. /*==========================================
  6972. * Sends x/y dot to a single fd. [Skotlex]
  6973. *------------------------------------------*/
  6974. void clif_party_xy_single( map_session_data& sd, map_session_data& tsd ){
  6975. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6976. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6977. p.AID = sd.status.account_id;
  6978. p.xPos = sd.bl.x;
  6979. p.yPos = sd.bl.y;
  6980. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6981. }
  6982. /// Updates HP bar of a party member.
  6983. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6984. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6985. void clif_party_hp( map_session_data& sd ){
  6986. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6987. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6988. p.AID = sd.status.account_id;
  6989. #if PACKETVER < 20100119
  6990. // To correctly display the %hp bar. [Skotlex]
  6991. if( sd.battle_status.max_hp > INT16_MAX ){
  6992. p.hp = sd.battle_status.hp / ( sd.battle_status.max_hp / 100 );
  6993. p.maxhp = 100;
  6994. }else{
  6995. p.hp = sd.battle_status.hp;
  6996. p.maxhp = sd.battle_status.max_hp;
  6997. }
  6998. #else
  6999. p.hp = sd.battle_status.hp;
  7000. p.maxhp = sd.battle_status.max_hp;
  7001. #endif
  7002. clif_send( &p, sizeof( p ), &sd.bl, PARTY_AREA_WOS );
  7003. }
  7004. /// Notifies the party members of a character's death or revival.
  7005. /// 0AB2 <GID>.L <dead>.B
  7006. void clif_party_dead( map_session_data& sd ){
  7007. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  7008. struct PACKET_ZC_GROUP_ISALIVE p = {};
  7009. p.packetType = HEADER_ZC_GROUP_ISALIVE;
  7010. p.AID = sd.status.account_id;
  7011. p.isDead = pc_isdead( &sd );
  7012. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  7013. #endif
  7014. }
  7015. /// Updates the job and level of a party member
  7016. /// 0abd <account id>.L <job>.W <level>.W
  7017. void clif_party_job_and_level( map_session_data& sd ){
  7018. #if PACKETVER_MAIN_NUM >= 20170502 || PACKETVER_RE_NUM >= 20170419 || defined(PACKETVER_ZERO)
  7019. struct PACKET_ZC_NOTIFY_MEMBERINFO_TO_GROUPM p = {};
  7020. p.PacketType = HEADER_ZC_NOTIFY_MEMBERINFO_TO_GROUPM;
  7021. p.AID = sd.status.account_id;
  7022. p.job = sd.status.class_;
  7023. p.level = sd.status.base_level;
  7024. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  7025. #endif
  7026. }
  7027. /*==========================================
  7028. * Sends HP bar to a single fd. [Skotlex]
  7029. *------------------------------------------*/
  7030. void clif_hpmeter_single( map_session_data& sd, uint32 id, uint32 hp, uint32 maxhp ){
  7031. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  7032. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  7033. p.AID = id;
  7034. #if PACKETVER < 20100119
  7035. // To correctly display the %hp bar. [Skotlex]
  7036. if( maxhp > INT16_MAX ){
  7037. p.hp = hp / ( maxhp / 100 );
  7038. p.maxhp = 100;
  7039. }else{
  7040. p.hp = hp;
  7041. p.maxhp = maxhp;
  7042. }
  7043. #else
  7044. p.hp = hp;
  7045. p.maxhp = maxhp;
  7046. #endif
  7047. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7048. }
  7049. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  7050. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  7051. void clif_movetoattack(map_session_data *sd,struct block_list *bl)
  7052. {
  7053. int fd;
  7054. nullpo_retv(sd);
  7055. nullpo_retv(bl);
  7056. fd=sd->fd;
  7057. WFIFOHEAD(fd,packet_len(0x139));
  7058. WFIFOW(fd, 0)=0x139;
  7059. WFIFOL(fd, 2)=bl->id;
  7060. WFIFOW(fd, 6)=bl->x;
  7061. WFIFOW(fd, 8)=bl->y;
  7062. WFIFOW(fd,10)=sd->bl.x;
  7063. WFIFOW(fd,12)=sd->bl.y;
  7064. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  7065. WFIFOSET(fd,packet_len(0x139));
  7066. }
  7067. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  7068. /// 018f <result>.W <name id>.W
  7069. /// result:
  7070. /// 0 = success
  7071. /// 1 = failure
  7072. /// 2 = success (alchemist)
  7073. /// 3 = failure (alchemist)
  7074. void clif_produceeffect(map_session_data* sd,int flag, t_itemid nameid){
  7075. nullpo_retv( sd );
  7076. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  7077. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  7078. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  7079. p.result = flag;
  7080. p.itemId = client_nameid( nameid );
  7081. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7082. }
  7083. /// Initiates the pet taming process (ZC_START_CAPTURE).
  7084. /// 019e
  7085. void clif_catch_process(map_session_data *sd)
  7086. {
  7087. int fd;
  7088. nullpo_retv(sd);
  7089. fd=sd->fd;
  7090. WFIFOHEAD(fd,packet_len(0x19e));
  7091. WFIFOW(fd,0)=0x19e;
  7092. WFIFOSET(fd,packet_len(0x19e));
  7093. }
  7094. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  7095. /// 01a0 <result>.B
  7096. /// 0 = failure
  7097. /// 1 = success
  7098. void clif_pet_roulette(map_session_data *sd,int data)
  7099. {
  7100. int fd;
  7101. nullpo_retv(sd);
  7102. fd=sd->fd;
  7103. WFIFOHEAD(fd,packet_len(0x1a0));
  7104. WFIFOW(fd,0)=0x1a0;
  7105. WFIFOB(fd,2)=data;
  7106. WFIFOSET(fd,packet_len(0x1a0));
  7107. }
  7108. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  7109. /// 01a6 <packet len>.W { <index>.W }*
  7110. void clif_sendegg(map_session_data *sd)
  7111. {
  7112. int i,n=0,fd;
  7113. nullpo_retv(sd);
  7114. fd=sd->fd;
  7115. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  7116. clif_displaymessage(fd, msg_txt(sd,666));
  7117. return;
  7118. }
  7119. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  7120. WFIFOW(fd,0)=0x1a6;
  7121. for(i=0,n=0;i<MAX_INVENTORY;i++){
  7122. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == NULL ||
  7123. sd->inventory_data[i]->type != IT_PETEGG ||
  7124. sd->inventory.u.items_inventory[i].amount <= 0)
  7125. continue;
  7126. WFIFOW(fd,n*2+4)=client_index(i);
  7127. n++;
  7128. }
  7129. WFIFOW(fd,2)=4+n*2;
  7130. WFIFOSET(fd,WFIFOW(fd,2));
  7131. sd->menuskill_id = SA_TAMINGMONSTER;
  7132. sd->menuskill_val = -1;
  7133. }
  7134. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  7135. /// 01a4 <type>.B <id>.L <data>.L
  7136. /// type:
  7137. /// 0 = pre-init (data = 0)
  7138. /// 1 = intimacy (data = 0~4)
  7139. /// 2 = hunger (data = 0~4)
  7140. /// 3 = accessory
  7141. /// 4 = performance (data = 1~3: normal, 4: special)
  7142. /// 5 = hairstyle
  7143. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  7144. ///
  7145. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  7146. void clif_send_petdata(map_session_data* sd, struct pet_data* pd, int type, int param)
  7147. {
  7148. uint8 buf[16];
  7149. nullpo_retv(pd);
  7150. WBUFW(buf,0) = 0x1a4;
  7151. WBUFB(buf,2) = type;
  7152. WBUFL(buf,3) = pd->bl.id;
  7153. WBUFL(buf,7) = param;
  7154. if (sd)
  7155. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  7156. else
  7157. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  7158. }
  7159. /// Pet's base data (ZC_PROPERTY_PET).
  7160. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  7161. void clif_send_petstatus(map_session_data *sd)
  7162. {
  7163. int fd;
  7164. struct s_pet *pet;
  7165. nullpo_retv(sd);
  7166. nullpo_retv(sd->pd);
  7167. fd=sd->fd;
  7168. pet = &sd->pd->pet;
  7169. WFIFOHEAD(fd,packet_len(0x1a2));
  7170. WFIFOW(fd,0)=0x1a2;
  7171. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  7172. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  7173. WFIFOW(fd,27)=pet->level;
  7174. WFIFOW(fd,29)=pet->hungry;
  7175. WFIFOW(fd,31)=pet->intimate;
  7176. WFIFOW(fd,33)=pet->equip;
  7177. #if PACKETVER >= 20081126
  7178. WFIFOW(fd,35)=pet->class_;
  7179. #endif
  7180. WFIFOSET(fd,packet_len(0x1a2));
  7181. }
  7182. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  7183. /// 01aa <id>.L <data>.L
  7184. /// data:
  7185. /// @see CZ_PET_ACT.
  7186. void clif_pet_emotion(struct pet_data *pd,int param)
  7187. {
  7188. unsigned char buf[16];
  7189. nullpo_retv(pd);
  7190. memset(buf,0,packet_len(0x1aa));
  7191. WBUFW(buf,0)=0x1aa;
  7192. WBUFL(buf,2)=pd->bl.id;
  7193. WBUFL(buf,6)=param;
  7194. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  7195. }
  7196. /// Result of request to feed a pet (ZC_FEED_PET).
  7197. /// 01a3 <result>.B <name id>.W
  7198. /// result:
  7199. /// 0 = failure
  7200. /// 1 = success
  7201. void clif_pet_food( map_session_data *sd, int foodid,int fail ){
  7202. nullpo_retv( sd );
  7203. struct PACKET_ZC_FEED_PET p;
  7204. p.packetType = 0x1a3;
  7205. p.result = fail;
  7206. p.itemId = client_nameid( foodid );
  7207. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7208. }
  7209. /// Send pet auto feed info.
  7210. void clif_pet_autofeed_status(map_session_data* sd, bool force) {
  7211. #if PACKETVER >= 20141008
  7212. nullpo_retv(sd);
  7213. if (force || battle_config.pet_autofeed_always) {
  7214. // Always send ON or OFF
  7215. if (sd->pd && battle_config.feature_pet_autofeed) {
  7216. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  7217. }
  7218. else {
  7219. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  7220. }
  7221. }
  7222. else {
  7223. // Only send when enabled
  7224. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  7225. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  7226. }
  7227. }
  7228. #endif
  7229. }
  7230. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  7231. /// 01cd { <skill id>.L }*7
  7232. void clif_autospell(map_session_data *sd,uint16 skill_lv)
  7233. {
  7234. nullpo_retv(sd);
  7235. int fd = sd->fd;
  7236. #ifdef RENEWAL
  7237. uint16 autospell_skill[][2] = {
  7238. { MG_FIREBOLT, 0 }, { MG_COLDBOLT, 0 }, { MG_LIGHTNINGBOLT, 0 },
  7239. { MG_SOULSTRIKE, 3 }, { MG_FIREBALL, 3 },
  7240. { WZ_EARTHSPIKE, 6 }, { MG_FROSTDIVER, 6 },
  7241. { MG_THUNDERSTORM, 9 }, { WZ_HEAVENDRIVE, 9 }
  7242. };
  7243. int count = 0;
  7244. WFIFOHEAD(fd, 2 * 6 + 4);
  7245. WFIFOW(fd, 0) = 0x442;
  7246. for (int i = 0; i < ARRAYLENGTH(autospell_skill); i++) {
  7247. if (skill_lv > autospell_skill[i][1] && pc_checkskill(sd, autospell_skill[i][0])) {
  7248. WFIFOW(fd, 8 + count * 2) = autospell_skill[i][0];
  7249. count++;
  7250. }
  7251. }
  7252. WFIFOW(fd, 2) = 8 + count * 2;
  7253. WFIFOL(fd, 4) = count;
  7254. WFIFOSET(fd, WFIFOW(fd, 2));
  7255. #else
  7256. WFIFOHEAD(fd,packet_len(0x1cd));
  7257. WFIFOW(fd, 0)=0x1cd;
  7258. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  7259. WFIFOL(fd,2)= MG_NAPALMBEAT;
  7260. else
  7261. WFIFOL(fd,2)= 0x00000000;
  7262. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  7263. WFIFOL(fd,6)= MG_COLDBOLT;
  7264. else
  7265. WFIFOL(fd,6)= 0x00000000;
  7266. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  7267. WFIFOL(fd,10)= MG_FIREBOLT;
  7268. else
  7269. WFIFOL(fd,10)= 0x00000000;
  7270. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  7271. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  7272. else
  7273. WFIFOL(fd,14)= 0x00000000;
  7274. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  7275. WFIFOL(fd,18)= MG_SOULSTRIKE;
  7276. else
  7277. WFIFOL(fd,18)= 0x00000000;
  7278. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  7279. WFIFOL(fd,22)= MG_FIREBALL;
  7280. else
  7281. WFIFOL(fd,22)= 0x00000000;
  7282. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  7283. WFIFOL(fd,26)= MG_FROSTDIVER;
  7284. else
  7285. WFIFOL(fd,26)= 0x00000000;
  7286. WFIFOSET(fd,packet_len(0x1cd));
  7287. #endif
  7288. sd->menuskill_id = SA_AUTOSPELL;
  7289. sd->menuskill_val = skill_lv;
  7290. }
  7291. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7292. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7293. void clif_devotion(struct block_list *src, map_session_data *tsd)
  7294. {
  7295. unsigned char buf[56];
  7296. nullpo_retv(src);
  7297. memset(buf,0,packet_len(0x1cf));
  7298. WBUFW(buf,0) = 0x1cf;
  7299. WBUFL(buf,2) = src->id;
  7300. if( src->type == BL_MER )
  7301. {
  7302. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7303. if( md && md->master && md->devotion_flag )
  7304. WBUFL(buf,6) = md->master->bl.id;
  7305. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7306. }
  7307. else
  7308. {
  7309. int i;
  7310. map_session_data *sd = BL_CAST(BL_PC,src);
  7311. if( sd == NULL )
  7312. return;
  7313. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7314. WBUFL(buf,6+4*i) = sd->devotion[i];
  7315. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7316. }
  7317. if( tsd )
  7318. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7319. else
  7320. clif_send(buf, packet_len(0x1cf), src, AREA);
  7321. }
  7322. /// Notifies the client of an object's spirits.
  7323. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7324. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7325. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7326. nullpo_retv( bl );
  7327. struct PACKET_ZC_SPIRITS p = {};
  7328. p.PacketType = HEADER_ZC_SPIRITS;
  7329. p.AID = bl->id;
  7330. switch( bl->type ){
  7331. case BL_PC:
  7332. p.num = ( (map_session_data*)bl )->spiritball;
  7333. break;
  7334. case BL_HOM:
  7335. p.num = ( (struct homun_data*)bl )->homunculus.spiritball;
  7336. break;
  7337. }
  7338. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7339. }
  7340. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7341. /// 01d2 <account id>.L <delay>.L
  7342. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7343. {
  7344. unsigned char buf[32];
  7345. nullpo_retv(bl);
  7346. WBUFW(buf,0)=0x1d2;
  7347. WBUFL(buf,2)=bl->id;
  7348. WBUFL(buf,6)=client_tick(wait);
  7349. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7350. }
  7351. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7352. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7353. /// flag:
  7354. /// 0 = inactive
  7355. /// 1 = active
  7356. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7357. {
  7358. unsigned char buf[32];
  7359. nullpo_retv(src);
  7360. WBUFW(buf,0)=0x1d1;
  7361. WBUFL(buf,2)=src->id;
  7362. WBUFL(buf,6)=dst_id;
  7363. WBUFL(buf,10)=active;
  7364. clif_send(buf,packet_len(0x1d1),src,AREA);
  7365. }
  7366. /// MVP effect (ZC_MVP).
  7367. /// 010c <account id>.L
  7368. void clif_mvp_effect(map_session_data *sd)
  7369. {
  7370. unsigned char buf[16];
  7371. nullpo_retv(sd);
  7372. WBUFW(buf,0)=0x10c;
  7373. WBUFL(buf,2)=sd->bl.id;
  7374. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7375. }
  7376. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7377. /// 010a <name id>.W
  7378. void clif_mvp_item( map_session_data *sd, t_itemid nameid ){
  7379. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7380. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7381. p.itemId = client_nameid( nameid );
  7382. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7383. }
  7384. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7385. /// 010b <exp>.L
  7386. void clif_mvp_exp(map_session_data *sd, t_exp exp) {
  7387. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7388. if (battle_config.mvp_exp_reward_message) {
  7389. char e_msg[CHAT_SIZE_MAX];
  7390. sprintf(e_msg, msg_txt(sd, 717), exp);
  7391. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7392. }
  7393. #else
  7394. int fd;
  7395. nullpo_retv(sd);
  7396. fd = sd->fd;
  7397. WFIFOHEAD(fd, packet_len(0x10b));
  7398. WFIFOW(fd,0) = 0x10b;
  7399. WFIFOL(fd,2) = (uint32)u64min( exp, MAX_EXP );
  7400. WFIFOSET(fd, packet_len(0x10b));
  7401. #endif
  7402. }
  7403. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7404. /// 010d
  7405. ///
  7406. /// "You are the MVP, but cannot obtain the reward because
  7407. /// you are overweight."
  7408. void clif_mvp_noitem(map_session_data* sd)
  7409. {
  7410. int fd = sd->fd;
  7411. WFIFOHEAD(fd,packet_len(0x10d));
  7412. WFIFOW(fd,0) = 0x10d;
  7413. WFIFOSET(fd,packet_len(0x10d));
  7414. }
  7415. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7416. /// 0167 <result>.B
  7417. /// result:
  7418. /// 0 = "Guild has been created."
  7419. /// 1 = "You are already in a Guild."
  7420. /// 2 = "That Guild Name already exists."
  7421. /// 3 = "You need the neccessary item to create a Guild."
  7422. void clif_guild_created(map_session_data *sd,int flag)
  7423. {
  7424. int fd;
  7425. nullpo_retv(sd);
  7426. fd=sd->fd;
  7427. WFIFOHEAD(fd,packet_len(0x167));
  7428. WFIFOW(fd,0)=0x167;
  7429. WFIFOB(fd,2)=flag;
  7430. WFIFOSET(fd,packet_len(0x167));
  7431. }
  7432. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7433. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7434. /// mode:
  7435. /// &0x01 = allow invite
  7436. /// &0x10 = allow expel
  7437. void clif_guild_belonginfo( map_session_data& sd ){
  7438. if( sd.guild == nullptr ){
  7439. return;
  7440. }
  7441. const auto &guild = sd.guild->guild;
  7442. int position = guild_getposition(sd);
  7443. if( position < 0 ){
  7444. return;
  7445. }
  7446. struct PACKET_ZC_UPDATE_GDID p = {};
  7447. p.PacketType = HEADER_ZC_UPDATE_GDID;
  7448. p.guildId = guild.guild_id;
  7449. p.emblemVersion = guild.emblem_id;
  7450. p.mode = guild.position[position].mode;
  7451. p.isMaster = ( sd.state.gmaster_flag == 1 );
  7452. p.interSid = 0; // InterSID (unknown purpose)
  7453. safestrncpy( p.guildName, guild.name, sizeof( p.guildName ) );
  7454. #if PACKETVER_MAIN_NUM >= 20220216
  7455. p.masterGID = guild.member[0].char_id;
  7456. #endif
  7457. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7458. }
  7459. /// Guild member login notice.
  7460. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7461. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7462. /// status:
  7463. /// 0 = offline
  7464. /// 1 = online
  7465. void clif_guild_memberlogin_notice(const struct mmo_guild &g,int idx,int flag)
  7466. {
  7467. unsigned char buf[64];
  7468. map_session_data* sd;
  7469. WBUFW(buf, 0)=0x1f2;
  7470. WBUFL(buf, 2)=g.member[idx].account_id;
  7471. WBUFL(buf, 6)=g.member[idx].char_id;
  7472. WBUFL(buf,10)=flag;
  7473. if( ( sd = g.member[idx].sd ) != NULL )
  7474. {
  7475. WBUFW(buf,14) = sd->status.sex;
  7476. WBUFW(buf,16) = sd->status.hair;
  7477. WBUFW(buf,18) = sd->status.hair_color;
  7478. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7479. }
  7480. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7481. {
  7482. WBUFW(buf,14) = 0;
  7483. WBUFW(buf,16) = 0;
  7484. WBUFW(buf,18) = 0;
  7485. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7486. }
  7487. }
  7488. // Function `clif_guild_memberlogin_notice` sends info about
  7489. // logins and logouts of a guild member to the rest members.
  7490. // But at the 1st time (after a player login or map changing)
  7491. // the client won't show the message.
  7492. // So I suggest use this function for sending "first-time-info"
  7493. // to some player on entering the game or changing location.
  7494. // At next time the client would always show the message.
  7495. // The function sends all the statuses in the single packet
  7496. // to economize traffic. [LuzZza]
  7497. void clif_guild_send_onlineinfo(map_session_data *sd)
  7498. {
  7499. unsigned char buf[14*128];
  7500. int i, count=0, p_len;
  7501. nullpo_retv(sd);
  7502. p_len = packet_len(0x16d);
  7503. auto &g = sd->guild;
  7504. if (!g)
  7505. return;
  7506. for(i=0; i<g->guild.max_member; i++) {
  7507. if(g->guild.member[i].account_id > 0 &&
  7508. g->guild.member[i].account_id != sd->status.account_id) {
  7509. WBUFW(buf,count*p_len) = 0x16d;
  7510. WBUFL(buf,count*p_len+2) = g->guild.member[i].account_id;
  7511. WBUFL(buf,count*p_len+6) = g->guild.member[i].char_id;
  7512. WBUFL(buf,count*p_len+10) = g->guild.member[i].online;
  7513. count++;
  7514. }
  7515. }
  7516. clif_send(buf, p_len*count, &sd->bl, SELF);
  7517. }
  7518. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7519. /// 014e <menu flag>.L
  7520. /// menu flag:
  7521. /// 0x00 = Basic Info (always on)
  7522. /// &0x01 = Member manager
  7523. /// &0x02 = Positions
  7524. /// &0x04 = Skills
  7525. /// &0x10 = Expulsion list
  7526. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7527. /// &0x80 = Notice
  7528. void clif_guild_masterormember(map_session_data *sd)
  7529. {
  7530. int fd;
  7531. nullpo_retv(sd);
  7532. fd=sd->fd;
  7533. WFIFOHEAD(fd,packet_len(0x14e));
  7534. WFIFOW(fd,0) = 0x14e;
  7535. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7536. WFIFOSET(fd,packet_len(0x14e));
  7537. }
  7538. /// Guild basic information (Territories [Valaris])
  7539. /// 0150 <guild id>.L <level>.L <member num>.L <member max>.L <exp>.L <max exp>.L <points>.L <honor>.L <virtue>.L <emblem id>.L <name>.24B <master name>.24B <manage land>.16B (ZC_GUILD_INFO)
  7540. /// 01b6 <guild id>.L <level>.L <member num>.L <member max>.L <exp>.L <max exp>.L <points>.L <honor>.L <virtue>.L <emblem id>.L <name>.24B <master name>.24B <manage land>.16B <zeny>.L (ZC_GUILD_INFO2)
  7541. /// 0a84 <guild id>.L <level>.L <member num>.L <member max>.L <exp>.L <max exp>.L <points>.L <honor>.L <virtue>.L <emblem id>.L <name>.24B <manage land>.16B <zeny>.L <master char id>.L (ZC_GUILD_INFO3)
  7542. void clif_guild_basicinfo( map_session_data& sd ){
  7543. if( sd.guild == nullptr ){
  7544. return;
  7545. }
  7546. const auto &guild = sd.guild->guild;
  7547. struct PACKET_ZC_GUILD_INFO p = {};
  7548. p.PacketType = HEADER_ZC_GUILD_INFO;
  7549. p.GDID = guild.guild_id;
  7550. p.level = guild.guild_lv;
  7551. p.userNum = guild.connect_member;
  7552. p.maxUserNum = guild.max_member;
  7553. p.userAverageLevel = guild.average_lv;
  7554. p.exp = (uint32)cap_value( guild.exp, 0, MAX_GUILD_EXP );
  7555. p.maxExp = (uint32)cap_value( guild.next_exp, 0, MAX_GUILD_EXP );
  7556. p.point = 0; // Tax Points
  7557. p.honor = 0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7558. p.virtue = 0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7559. p.emblemVersion = guild.emblem_id;
  7560. safestrncpy( p.guildname, guild.name, sizeof( p.guildname ) );
  7561. safestrncpy( p.manageLand, msg_txt( &sd, 300 + guild_checkcastles( guild ) ), sizeof( p.manageLand ) );
  7562. p.zeny = 0;
  7563. #if PACKETVER >= 20200902
  7564. p.masterGID = guild.member[0].char_id; // leader
  7565. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7566. #elif PACKETVER_MAIN_NUM >= 20161019 || PACKETVER_RE_NUM >= 20160921 || defined(PACKETVER_ZERO)
  7567. p.masterGID = guild.member[0].char_id; // leader
  7568. #else
  7569. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7570. #endif
  7571. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7572. }
  7573. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7574. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7575. void clif_guild_allianceinfo(map_session_data *sd)
  7576. {
  7577. int fd,i,c;
  7578. nullpo_retv(sd);
  7579. auto &g = sd->guild;
  7580. if (!g)
  7581. return;
  7582. fd = sd->fd;
  7583. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7584. WFIFOW(fd, 0)=0x14c;
  7585. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7586. struct guild_alliance *a=&g->guild.alliance[i];
  7587. if(a->guild_id>0){
  7588. WFIFOL(fd,c*32+4)=a->opposition;
  7589. WFIFOL(fd,c*32+8)=a->guild_id;
  7590. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7591. c++;
  7592. }
  7593. }
  7594. WFIFOW(fd, 2)=c*32+4;
  7595. WFIFOSET(fd,WFIFOW(fd,2));
  7596. }
  7597. /// Guild member manager information
  7598. /// 0154 <packet len>.W { <account>.L <char id>.L <hair style>.W <hair color>.W <gender>.W <class>.W <level>.W <contrib exp>.L <state>.L <position>.L <memo>.50B <name>.24B }* (ZC_MEMBERMGR_INFO)
  7599. /// state:
  7600. /// 0 = offline
  7601. /// 1 = online
  7602. /// memo:
  7603. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7604. /// 0aa5 <packet len>.W { <account>.L <char id>.L <hair style>.W <hair color>.W <gender>.W <class>.W <level>.W <contrib exp>.L <state>.L <position>.L <lastlogin>.L }* (ZC_MEMBERMGR_INFO2)
  7605. void clif_guild_memberlist( map_session_data& sd ){
  7606. if( sd.guild == nullptr ){
  7607. return;
  7608. }
  7609. const auto &guild = sd.guild->guild;
  7610. struct PACKET_ZC_MEMBERMGR_INFO* p = (struct PACKET_ZC_MEMBERMGR_INFO*)packet_buffer;
  7611. p->PacketType = HEADER_ZC_MEMBERMGR_INFO;
  7612. p->packetLength = sizeof( *p );
  7613. for( int i = 0, c = 0; i < guild.max_member; i++ ){
  7614. const auto &member = guild.member[i];
  7615. if( member.account_id == 0 ){
  7616. continue;
  7617. }
  7618. struct GUILD_MEMBER_INFO& member_info = p->guildMemberInfo[c];
  7619. member_info.AID = member.account_id;
  7620. member_info.GID = member.char_id;
  7621. member_info.head = member.hair;
  7622. member_info.headPalette = member.hair_color;
  7623. member_info.sex = member.gender;
  7624. member_info.job = member.class_;
  7625. member_info.level = member.lv;
  7626. member_info.contributionExp = (uint32)cap_value( member.exp, 0, MAX_GUILD_EXP );
  7627. member_info.currentState = member.online;
  7628. member_info.positionID = member.position;
  7629. #if PACKETVER >= 20200902
  7630. member_info.lastLoginTime = member.last_login;
  7631. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7632. #elif PACKETVER_MAIN_NUM >= 20161214 || PACKETVER_RE_NUM >= 20161130 || defined(PACKETVER_ZERO)
  7633. member_info.lastLoginTime = member.last_login;
  7634. #else
  7635. memset( member_info.intro, 0, sizeof( member_info.intro ) ); //[Ind] - This is displayed in the 'note' column but being you can't edit it it's sent empty.
  7636. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7637. #endif
  7638. c++;
  7639. p->packetLength += sizeof( member_info );
  7640. }
  7641. clif_send( p, p->packetLength, &sd.bl, SELF );
  7642. }
  7643. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7644. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7645. void clif_guild_positionnamelist(map_session_data *sd)
  7646. {
  7647. int i,fd;
  7648. nullpo_retv(sd);
  7649. auto &g = sd->guild;
  7650. if (!g)
  7651. return;
  7652. fd = sd->fd;
  7653. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7654. WFIFOW(fd, 0)=0x166;
  7655. for(i=0;i<MAX_GUILDPOSITION;i++){
  7656. WFIFOL(fd,i*28+4)=i;
  7657. safestrncpy(WFIFOCP(fd,i*28+8),g->guild.position[i].name,NAME_LENGTH);
  7658. }
  7659. WFIFOW(fd,2)=i*28+4;
  7660. WFIFOSET(fd,WFIFOW(fd,2));
  7661. }
  7662. /// Guild position information (ZC_POSITION_INFO).
  7663. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7664. /// mode:
  7665. /// &0x01 = allow invite
  7666. /// &0x10 = allow expel
  7667. /// ranking:
  7668. /// TODO
  7669. void clif_guild_positioninfolist(map_session_data *sd)
  7670. {
  7671. int i,fd;
  7672. nullpo_retv(sd);
  7673. auto &g = sd->guild;
  7674. if (!g)
  7675. return;
  7676. fd = sd->fd;
  7677. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7678. WFIFOW(fd, 0)=0x160;
  7679. for(i=0;i<MAX_GUILDPOSITION;i++){
  7680. struct guild_position *p=&g->guild.position[i];
  7681. WFIFOL(fd,i*16+ 4)=i;
  7682. WFIFOL(fd,i*16+ 8)=p->mode;
  7683. WFIFOL(fd,i*16+12)=i;
  7684. WFIFOL(fd,i*16+16)=p->exp_mode;
  7685. }
  7686. WFIFOW(fd, 2)=i*16+4;
  7687. WFIFOSET(fd,WFIFOW(fd,2));
  7688. }
  7689. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7690. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7691. /// mode:
  7692. /// &0x01 = allow invite
  7693. /// &0x10 = allow expel
  7694. /// ranking:
  7695. /// TODO
  7696. void clif_guild_positionchanged(const struct mmo_guild &g,int idx)
  7697. {
  7698. // FIXME: This packet is intended to update the clients after a
  7699. // commit of position info changes, not sending one packet per
  7700. // position.
  7701. map_session_data *sd;
  7702. unsigned char buf[128];
  7703. WBUFW(buf, 0)=0x174;
  7704. WBUFW(buf, 2)=44; // packet len
  7705. // GUILD_REG_POSITION_INFO{
  7706. WBUFL(buf, 4)=idx;
  7707. WBUFL(buf, 8)=g.position[idx].mode;
  7708. WBUFL(buf,12)=idx;
  7709. WBUFL(buf,16)=g.position[idx].exp_mode;
  7710. safestrncpy(WBUFCP(buf,20),g.position[idx].name,NAME_LENGTH);
  7711. // }*
  7712. if( (sd=guild_getavailablesd(g))!=NULL )
  7713. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7714. }
  7715. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7716. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7717. void clif_guild_memberpositionchanged(const struct mmo_guild &g, int idx)
  7718. {
  7719. // FIXME: This packet is intended to update the clients after a
  7720. // commit of member position assignment changes, not sending one
  7721. // packet per position.
  7722. map_session_data *sd;
  7723. unsigned char buf[64];
  7724. WBUFW(buf, 0)=0x156;
  7725. WBUFW(buf, 2)=16; // packet len
  7726. // MEMBER_POSITION_INFO{
  7727. WBUFL(buf, 4)=g.member[idx].account_id;
  7728. WBUFL(buf, 8)=g.member[idx].char_id;
  7729. WBUFL(buf,12)=g.member[idx].position;
  7730. // }*
  7731. if( (sd=guild_getavailablesd(g))!=NULL )
  7732. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7733. }
  7734. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7735. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7736. void clif_guild_emblem(const map_session_data &sd, const struct mmo_guild &g)
  7737. {
  7738. int fd = sd.fd;
  7739. if( g.emblem_len <= 0 )
  7740. return;
  7741. WFIFOHEAD(fd,g.emblem_len+12);
  7742. WFIFOW(fd,0)=0x152;
  7743. WFIFOW(fd,2)=g.emblem_len+12;
  7744. WFIFOL(fd,4)=g.guild_id;
  7745. WFIFOL(fd,8)=g.emblem_id;
  7746. memcpy(WFIFOP(fd,12),g.emblem_data,g.emblem_len);
  7747. WFIFOSET(fd,WFIFOW(fd,2));
  7748. }
  7749. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7750. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7751. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7752. void clif_guild_emblem_area(struct block_list* bl)
  7753. {
  7754. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7755. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7756. PACKET_ZC_CHANGE_GUILD p{};
  7757. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7758. p.guild_id = status_get_guild_id(bl);
  7759. p.emblem_id = status_get_emblem_id(bl);
  7760. p.AID = bl->id;
  7761. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7762. }
  7763. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7764. /// 0162 <packet len>.W <skill points>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B }*
  7765. void clif_guild_skillinfo(map_session_data* sd)
  7766. {
  7767. int fd;
  7768. int i,c;
  7769. nullpo_retv(sd);
  7770. auto &g = sd->guild;
  7771. if (!g)
  7772. return;
  7773. fd = sd->fd;
  7774. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7775. WFIFOW(fd,0) = 0x0162;
  7776. WFIFOW(fd,4) = g->guild.skill_point;
  7777. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7778. {
  7779. if(g->guild.skill[i].id > 0 && guild_check_skill_require(g->guild, g->guild.skill[i].id))
  7780. {
  7781. int id = g->guild.skill[i].id;
  7782. int p = 6 + c*37;
  7783. WFIFOW(fd,p+0) = id;
  7784. WFIFOL(fd,p+2) = skill_get_inf(id);
  7785. WFIFOW(fd,p+6) = g->guild.skill[i].lv;
  7786. WFIFOW(fd,p+8) = skill_get_sp(id, g->guild.skill[i].lv);
  7787. WFIFOW(fd,p+10) = skill_get_range(id, g->guild.skill[i].lv);
  7788. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7789. WFIFOB(fd,p+36)= (g->guild.skill[i].lv < guild_skill_get_max(id) && sd == g->guild.member[0].sd) ? 1 : 0;
  7790. c++;
  7791. }
  7792. }
  7793. WFIFOW(fd,2) = 6 + c*37;
  7794. WFIFOSET(fd,WFIFOW(fd,2));
  7795. }
  7796. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7797. /// 016f <subject>.60B <notice>.120B
  7798. void clif_guild_notice(map_session_data* sd)
  7799. {
  7800. nullpo_retv(sd);
  7801. auto &g = sd->guild;
  7802. int fd = sd->fd;
  7803. if ( !session_isActive(fd) )
  7804. return;
  7805. if(g->guild.mes1[0] == '\0' && g->guild.mes2[0] == '\0')
  7806. return;
  7807. WFIFOHEAD(fd,packet_len(0x16f));
  7808. WFIFOW(fd,0) = 0x16f;
  7809. memcpy(WFIFOP(fd,2), g->guild.mes1, MAX_GUILDMES1);
  7810. memcpy(WFIFOP(fd,62), g->guild.mes2, MAX_GUILDMES2);
  7811. WFIFOSET(fd,packet_len(0x16f));
  7812. }
  7813. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7814. /// 016a <guild id>.L <guild name>.24B
  7815. void clif_guild_invite(const map_session_data &sd, const struct mmo_guild &g)
  7816. {
  7817. int fd = sd.fd;
  7818. WFIFOHEAD(fd,packet_len(0x16a));
  7819. WFIFOW(fd,0)=0x16a;
  7820. WFIFOL(fd,2)=g.guild_id;
  7821. safestrncpy(WFIFOCP(fd,6),g.name,NAME_LENGTH);
  7822. WFIFOSET(fd,packet_len(0x16a));
  7823. }
  7824. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7825. /// 0169 <answer>.B
  7826. /// answer:
  7827. /// 0 = Already in guild.
  7828. /// 1 = Offer rejected.
  7829. /// 2 = Offer accepted.
  7830. /// 3 = Guild full.
  7831. void clif_guild_inviteack(map_session_data *sd,int flag)
  7832. {
  7833. int fd;
  7834. nullpo_retv(sd);
  7835. fd=sd->fd;
  7836. WFIFOHEAD(fd,packet_len(0x169));
  7837. WFIFOW(fd,0)=0x169;
  7838. WFIFOB(fd,2)=flag;
  7839. WFIFOSET(fd,packet_len(0x169));
  7840. }
  7841. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7842. /// 015a <char name>.24B <reason>.40B
  7843. void clif_guild_leave(map_session_data *sd,const char *name,const char *mes)
  7844. {
  7845. unsigned char buf[128];
  7846. nullpo_retv(sd);
  7847. WBUFW(buf, 0)=0x15a;
  7848. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7849. memcpy(WBUFP(buf,26),mes,40);
  7850. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7851. }
  7852. /// Notifies clients of a guild of an expelled member.
  7853. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7854. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7855. void clif_guild_expulsion(map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7856. {
  7857. unsigned char buf[128];
  7858. #if PACKETVER < 20100803
  7859. const unsigned short cmd = 0x15c;
  7860. #else
  7861. const unsigned short cmd = 0x839;
  7862. #endif
  7863. nullpo_retv(sd);
  7864. WBUFW(buf,0) = cmd;
  7865. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7866. safestrncpy(WBUFCP(buf,26), mes, 40);
  7867. #if PACKETVER < 20100803
  7868. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7869. #endif
  7870. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7871. }
  7872. /// Guild expulsion list (ZC_BAN_LIST).
  7873. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7874. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7875. void clif_guild_expulsionlist(map_session_data* sd)
  7876. {
  7877. #if PACKETVER < 20100803
  7878. const int offset = NAME_LENGTH*2+40;
  7879. #else
  7880. const int offset = NAME_LENGTH+40;
  7881. #endif
  7882. int fd, i, c = 0;
  7883. nullpo_retv(sd);
  7884. auto &g = sd->guild;
  7885. if (!g)
  7886. return;
  7887. fd = sd->fd;
  7888. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7889. WFIFOW(fd,0) = 0x163;
  7890. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7891. {
  7892. struct guild_expulsion* e = &g->guild.expulsion[i];
  7893. if( e->account_id > 0 )
  7894. {
  7895. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7896. #if PACKETVER < 20100803
  7897. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7898. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7899. #else
  7900. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7901. #endif
  7902. c++;
  7903. }
  7904. }
  7905. WFIFOW(fd,2) = 4 + c*offset;
  7906. WFIFOSET(fd,WFIFOW(fd,2));
  7907. }
  7908. /// Guild chat message (ZC_GUILD_CHAT).
  7909. /// 017f <packet len>.W <message>.?B
  7910. void clif_guild_message(const struct mmo_guild &g,uint32 account_id,const char *mes,int len)
  7911. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7912. map_session_data *sd;
  7913. uint8 buf[256];
  7914. if( len == 0 )
  7915. {
  7916. return;
  7917. }
  7918. else if( len > sizeof(buf)-5 )
  7919. {
  7920. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g.guild_id);
  7921. len = sizeof(buf)-5;
  7922. }
  7923. WBUFW(buf, 0) = 0x17f;
  7924. WBUFW(buf, 2) = len + 5;
  7925. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7926. if ((sd = guild_getavailablesd(g)) != NULL)
  7927. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7928. }
  7929. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7930. /// 0171 <inviter account id>.L <guild name>.24B
  7931. void clif_guild_reqalliance(map_session_data *sd,uint32 account_id,const char *name)
  7932. {
  7933. int fd;
  7934. nullpo_retv(sd);
  7935. fd=sd->fd;
  7936. WFIFOHEAD(fd,packet_len(0x171));
  7937. WFIFOW(fd,0)=0x171;
  7938. WFIFOL(fd,2)=account_id;
  7939. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7940. WFIFOSET(fd,packet_len(0x171));
  7941. }
  7942. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7943. /// 0173 <answer>.B
  7944. /// answer:
  7945. /// 0 = Already allied.
  7946. /// 1 = You rejected the offer.
  7947. /// 2 = You accepted the offer.
  7948. /// 3 = They have too any alliances.
  7949. /// 4 = You have too many alliances.
  7950. /// 5 = Alliances are disabled.
  7951. void clif_guild_allianceack(map_session_data *sd,int flag)
  7952. {
  7953. int fd;
  7954. nullpo_retv(sd);
  7955. fd=sd->fd;
  7956. WFIFOHEAD(fd,packet_len(0x173));
  7957. WFIFOW(fd,0)=0x173;
  7958. WFIFOL(fd,2)=flag;
  7959. WFIFOSET(fd,packet_len(0x173));
  7960. }
  7961. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7962. /// 0184 <other guild id>.L <relation>.L
  7963. /// relation:
  7964. /// 0 = Ally
  7965. /// 1 = Enemy
  7966. void clif_guild_delalliance(map_session_data *sd,int guild_id,int flag)
  7967. {
  7968. nullpo_retv(sd);
  7969. int fd = sd->fd;
  7970. if ( !session_isActive(fd) )
  7971. return;
  7972. WFIFOHEAD(fd,packet_len(0x184));
  7973. WFIFOW(fd,0)=0x184;
  7974. WFIFOL(fd,2)=guild_id;
  7975. WFIFOL(fd,6)=flag;
  7976. WFIFOSET(fd,packet_len(0x184));
  7977. }
  7978. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7979. /// 0181 <result>.B
  7980. /// result:
  7981. /// 0 = Antagonist has been set.
  7982. /// 1 = Guild has too many Antagonists.
  7983. /// 2 = Already set as an Antagonist.
  7984. /// 3 = Antagonists are disabled.
  7985. void clif_guild_oppositionack(map_session_data *sd,int flag)
  7986. {
  7987. int fd;
  7988. nullpo_retv(sd);
  7989. fd=sd->fd;
  7990. WFIFOHEAD(fd,packet_len(0x181));
  7991. WFIFOW(fd,0)=0x181;
  7992. WFIFOB(fd,2)=flag;
  7993. WFIFOSET(fd,packet_len(0x181));
  7994. }
  7995. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7996. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7997. /*
  7998. void clif_guild_allianceadded(struct guild *g,int idx)
  7999. {
  8000. unsigned char buf[64];
  8001. WBUFW(buf,0)=0x185;
  8002. WBUFL(buf,2)=g->alliance[idx].opposition;
  8003. WBUFL(buf,6)=g->alliance[idx].guild_id;
  8004. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  8005. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  8006. }
  8007. */
  8008. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  8009. /// 015e <reason>.L
  8010. /// 0 = success
  8011. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  8012. /// 2 = there are still members in the guild
  8013. void clif_guild_broken(map_session_data *sd,int flag)
  8014. {
  8015. int fd;
  8016. nullpo_retv(sd);
  8017. fd=sd->fd;
  8018. WFIFOHEAD(fd,packet_len(0x15e));
  8019. WFIFOW(fd,0)=0x15e;
  8020. WFIFOL(fd,2)=flag;
  8021. WFIFOSET(fd,packet_len(0x15e));
  8022. }
  8023. /// Displays emotion on an object (ZC_EMOTION).
  8024. /// 00c0 <id>.L <type>.B
  8025. /// type:
  8026. /// enum emotion_type
  8027. void clif_emotion(struct block_list *bl,int type)
  8028. {
  8029. unsigned char buf[8];
  8030. nullpo_retv(bl);
  8031. WBUFW(buf,0)=0xc0;
  8032. WBUFL(buf,2)=bl->id;
  8033. WBUFB(buf,6)=type;
  8034. clif_send(buf,packet_len(0xc0),bl,AREA);
  8035. }
  8036. /// Displays the contents of a talkiebox trap.
  8037. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  8038. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  8039. nullpo_retv( bl );
  8040. nullpo_retv( talkie );
  8041. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  8042. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  8043. p.aid = bl->id;
  8044. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  8045. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  8046. }
  8047. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  8048. /// 01ea <id>.L
  8049. void clif_wedding_effect(struct block_list *bl)
  8050. {
  8051. unsigned char buf[6];
  8052. nullpo_retv(bl);
  8053. WBUFW(buf,0) = 0x1ea;
  8054. WBUFL(buf,2) = bl->id;
  8055. clif_send(buf, packet_len(0x1ea), bl, AREA);
  8056. }
  8057. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  8058. /// 01e6 <partner name>.24B
  8059. void clif_callpartner(map_session_data& sd)
  8060. {
  8061. PACKET_ZC_COUPLENAME p = { 0 };
  8062. p.packetType = HEADER_ZC_COUPLENAME;
  8063. if( sd.status.partner_id ) {
  8064. map_session_data *p_sd = pc_get_partner(&sd);
  8065. if (p_sd != nullptr && !p_sd->state.autotrade)
  8066. safestrncpy(p.name, p_sd->status.name, NAME_LENGTH);
  8067. else
  8068. p.name[0] = 0;
  8069. } else {// Send zero-length name if no partner, to initialize the client buffer.
  8070. p.name[0] = 0;
  8071. }
  8072. clif_send(&p, sizeof(p), &sd.bl, AREA);
  8073. }
  8074. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  8075. /// 01e4
  8076. /// This packet while still implemented by the client is no longer being officially used.
  8077. /*
  8078. void clif_marriage_process(map_session_data *sd)
  8079. {
  8080. int fd;
  8081. nullpo_retv(sd);
  8082. fd=sd->fd;
  8083. WFIFOHEAD(fd,packet_len(0x1e4));
  8084. WFIFOW(fd,0)=0x1e4;
  8085. WFIFOSET(fd,packet_len(0x1e4));
  8086. }
  8087. */
  8088. /// Notice of divorce (ZC_DIVORCE).
  8089. /// 0205 <partner name>.24B
  8090. void clif_divorced(map_session_data* sd, const char* name)
  8091. {
  8092. int fd;
  8093. nullpo_retv(sd);
  8094. fd=sd->fd;
  8095. WFIFOHEAD(fd,packet_len(0x205));
  8096. WFIFOW(fd,0)=0x205;
  8097. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8098. WFIFOSET(fd, packet_len(0x205));
  8099. }
  8100. /// Marriage proposal (ZC_REQ_COUPLE).
  8101. /// 01e2 <account id>.L <char id>.L <char name>.24B
  8102. /// This packet while still implemented by the client is no longer being officially used.
  8103. /*
  8104. void clif_marriage_proposal(int fd, map_session_data *sd, map_session_data* ssd)
  8105. {
  8106. nullpo_retv(sd);
  8107. WFIFOHEAD(fd,packet_len(0x1e2));
  8108. WFIFOW(fd,0) = 0x1e2;
  8109. WFIFOL(fd,2) = ssd->status.account_id;
  8110. WFIFOL(fd,6) = ssd->status.char_id;
  8111. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  8112. WFIFOSET(fd, packet_len(0x1e2));
  8113. }
  8114. */
  8115. /*==========================================
  8116. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  8117. *------------------------------------------*/
  8118. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  8119. {
  8120. unsigned char buf[256];
  8121. if( len == 0 ) {
  8122. return;
  8123. } else if( len > sizeof(buf)-5 ) {
  8124. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  8125. len = sizeof(buf)-5;
  8126. }
  8127. WBUFW(buf, 0) = 0x17f;
  8128. WBUFW(buf, 2) = len + 5;
  8129. safestrncpy(WBUFCP(buf,4), mes, len+1);
  8130. clif_send(buf, WBUFW(buf,2), src, target);
  8131. }
  8132. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  8133. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  8134. /// 00cd <result>.B
  8135. /// result:
  8136. /// 0 = failure
  8137. /// 1 = success
  8138. void clif_GM_kickack(map_session_data *sd, int id)
  8139. {
  8140. int fd;
  8141. nullpo_retv(sd);
  8142. fd = sd->fd;
  8143. WFIFOHEAD(fd,packet_len(0xcd));
  8144. WFIFOW(fd,0) = 0xcd;
  8145. WFIFOB(fd,2) = id; // FIXME: this is not account id
  8146. WFIFOSET(fd, packet_len(0xcd));
  8147. }
  8148. void clif_GM_kick(map_session_data *sd, map_session_data *tsd)
  8149. {
  8150. nullpo_retv(tsd);
  8151. if (sd == NULL)
  8152. tsd->state.keepshop = true;
  8153. if (session_isActive(tsd->fd))
  8154. clif_authfail_fd(tsd->fd, 15);
  8155. else
  8156. map_quit(tsd);
  8157. if (sd)
  8158. clif_GM_kickack(sd, tsd->status.account_id);
  8159. }
  8160. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  8161. /// 014a <result>.L
  8162. /// result:
  8163. /// 0 = "A manner point has been successfully aligned."
  8164. /// 1 = MP_FAILURE_EXHAUST
  8165. /// 2 = MP_FAILURE_ALREADY_GIVING
  8166. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  8167. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  8168. /// 5 = "You got a good point from %s."
  8169. void clif_manner_message(map_session_data* sd, uint32 type)
  8170. {
  8171. int fd;
  8172. nullpo_retv(sd);
  8173. fd = sd->fd;
  8174. WFIFOHEAD(fd,packet_len(0x14a));
  8175. WFIFOW(fd,0) = 0x14a;
  8176. WFIFOL(fd,2) = type;
  8177. WFIFOSET(fd, packet_len(0x14a));
  8178. }
  8179. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  8180. /// 014b <type>.B <GM name>.24B
  8181. /// type:
  8182. /// 0 = positive (unmute)
  8183. /// 1 = negative (mute)
  8184. void clif_GM_silence(map_session_data* sd, map_session_data* tsd, uint8 type)
  8185. {
  8186. int fd;
  8187. nullpo_retv(sd);
  8188. nullpo_retv(tsd);
  8189. fd = tsd->fd;
  8190. WFIFOHEAD(fd,packet_len(0x14b));
  8191. WFIFOW(fd,0) = 0x14b;
  8192. WFIFOB(fd,2) = type;
  8193. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  8194. WFIFOSET(fd, packet_len(0x14b));
  8195. }
  8196. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  8197. /// 00d1 <type>.B <result>.B
  8198. /// type:
  8199. /// 0 = /ex (deny)
  8200. /// 1 = /in (allow)
  8201. /// result:
  8202. /// 0 = success
  8203. /// 1 = failure
  8204. /// 2 = too many blocks
  8205. void clif_wisexin(map_session_data *sd,int type,int flag)
  8206. {
  8207. int fd;
  8208. nullpo_retv(sd);
  8209. fd=sd->fd;
  8210. WFIFOHEAD(fd,packet_len(0xd1));
  8211. WFIFOW(fd,0)=0xd1;
  8212. WFIFOB(fd,2)=type;
  8213. WFIFOB(fd,3)=flag;
  8214. WFIFOSET(fd,packet_len(0xd1));
  8215. }
  8216. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  8217. /// 00d2 <type>.B <result>.B
  8218. /// type:
  8219. /// 0 = /exall (deny)
  8220. /// 1 = /inall (allow)
  8221. /// result:
  8222. /// 0 = success
  8223. /// 1 = failure
  8224. void clif_wisall(map_session_data *sd,int type,int flag)
  8225. {
  8226. int fd;
  8227. nullpo_retv(sd);
  8228. fd=sd->fd;
  8229. WFIFOHEAD(fd,packet_len(0xd2));
  8230. WFIFOW(fd,0)=0xd2;
  8231. WFIFOB(fd,2)=type;
  8232. WFIFOB(fd,3)=flag;
  8233. WFIFOSET(fd,packet_len(0xd2));
  8234. }
  8235. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8236. /// 07fe <bgm>.24B
  8237. void clif_playBGM( map_session_data& sd, const char* name ){
  8238. #if PACKETVER_MAIN_NUM >= 20220504
  8239. struct PACKET_ZC_PLAY_NPC_BGM* p = (struct PACKET_ZC_PLAY_NPC_BGM*)packet_buffer;
  8240. int16 length = (int16)( strlen( name ) + 1 );
  8241. p->PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8242. p->PacketLength = sizeof( *p ) + length;
  8243. p->playType = 0; // TODO: implement, send loop for the time being
  8244. safestrncpy( p->bgm, name, length );
  8245. clif_send( p, p->PacketLength, &sd.bl, SELF );
  8246. #elif PACKETVER >= 20091201
  8247. struct PACKET_ZC_PLAY_NPC_BGM p = {};
  8248. p.PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8249. safestrncpy( p.bgm, name, sizeof( p.bgm ) );
  8250. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  8251. #endif
  8252. }
  8253. /// Plays/stops a wave sound (ZC_SOUND).
  8254. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8255. /// file name:
  8256. /// relative to data\wav
  8257. /// act:
  8258. /// 0 = play (once)
  8259. /// 1 = play (repeat, does not work)
  8260. /// 2 = stops all sound instances of file name (does not work)
  8261. /// term:
  8262. /// unknown purpose, only relevant to act = 1
  8263. /// npc id:
  8264. /// The accustic direction of the sound is determined by the
  8265. /// relative position of the NPC to the player (3D sound).
  8266. void clif_soundeffect( struct block_list& bl, const char* name, int type, enum send_target target ){
  8267. struct PACKET_ZC_SOUND p = {};
  8268. p.PacketType = HEADER_ZC_SOUND;
  8269. safestrncpy( p.name, name, sizeof( p.name ) );
  8270. p.act = type;
  8271. p.term = 0; // TODO: implement
  8272. p.AID = bl.id;
  8273. clif_send( &p, sizeof( p ), &bl, target );
  8274. }
  8275. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8276. /// 01f3 <id>.L <effect id>.L
  8277. /// effect id:
  8278. /// @see doc/effect_list.txt
  8279. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8280. {
  8281. unsigned char buf[24];
  8282. nullpo_retv(bl);
  8283. memset(buf, 0, packet_len(0x1f3));
  8284. WBUFW(buf,0) = 0x1f3;
  8285. WBUFL(buf,2) = bl->id;
  8286. WBUFL(buf,6) = type;
  8287. clif_send(buf, packet_len(0x1f3), bl, target);
  8288. if (disguised(bl)) {
  8289. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8290. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8291. }
  8292. }
  8293. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8294. {
  8295. WFIFOHEAD(fd,10);
  8296. WFIFOW(fd,0) = 0x1f3;
  8297. WFIFOL(fd,2) = bl->id;
  8298. WFIFOL(fd,6) = type;
  8299. WFIFOSET(fd,10);
  8300. }
  8301. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8302. /// 0284 <id>.L <effect id>.L <num data>.L
  8303. /// effect id:
  8304. /// @see doc/effect_list.txt
  8305. /// num data:
  8306. /// effect-dependent value
  8307. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8308. {
  8309. uint8 buf[14];
  8310. WBUFW(buf,0) = 0x284;
  8311. WBUFL(buf,2) = bl->id;
  8312. WBUFL(buf,6) = effect_id;
  8313. WBUFL(buf,10) = num;
  8314. clif_send(buf, packet_len(0x284), bl, target);
  8315. if( disguised(bl) )
  8316. {
  8317. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8318. clif_send(buf, packet_len(0x284), bl, SELF);
  8319. }
  8320. }
  8321. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8322. {
  8323. #if PACKETVER >= 20181002
  8324. nullpo_retv( bl_src );
  8325. nullpo_retv( bl_target );
  8326. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8327. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8328. p.aid = bl_src->id;
  8329. p.effectId = effect;
  8330. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8331. if( disguised(bl_src) )
  8332. {
  8333. p.aid = disguised_bl_id( bl_src->id );
  8334. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8335. }
  8336. #endif
  8337. }
  8338. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8339. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8340. void clif_messagecolor_target(struct block_list *bl, unsigned long color, const char *msg, bool rgb2bgr, enum send_target type, map_session_data *sd) {
  8341. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8342. uint8 buf[CHAT_SIZE_MAX];
  8343. nullpo_retv(bl);
  8344. if (msg_len > sizeof(buf) - 12) {
  8345. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8346. msg_len = sizeof(buf) - 12;
  8347. }
  8348. if (rgb2bgr)
  8349. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8350. WBUFW(buf,0) = 0x2C1;
  8351. WBUFW(buf,2) = msg_len + 12;
  8352. WBUFL(buf,4) = bl->id;
  8353. WBUFL(buf,8) = color;
  8354. memcpy(WBUFCP(buf,12), msg, msg_len);
  8355. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8356. }
  8357. /**
  8358. * Notifies the client that the storage window is still open
  8359. *
  8360. * Should only be used in cases where the client closed the
  8361. * storage window without server's consent
  8362. */
  8363. void clif_refresh_storagewindow(map_session_data *sd) {
  8364. // Notify the client that the storage is open
  8365. if( sd->state.storage_flag == 1 ) {
  8366. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8367. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8368. clif_updatestorageamount(sd, sd->storage.amount, sd->storage.max_amount);
  8369. }
  8370. // Notify the client that the gstorage is open otherwise it will
  8371. // remain locked forever and nobody will be able to access it
  8372. if( sd->state.storage_flag == 2 ) {
  8373. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8374. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8375. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8376. else {
  8377. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8378. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8379. clif_updatestorageamount(sd, gstor->amount, gstor->max_amount);
  8380. }
  8381. }
  8382. // Notify the client that the premium storage is open
  8383. if (sd->state.storage_flag == 3) {
  8384. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8385. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8386. clif_updatestorageamount(sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8387. }
  8388. }
  8389. // refresh the client's screen, getting rid of any effects
  8390. void clif_refresh(map_session_data *sd)
  8391. {
  8392. nullpo_retv(sd);
  8393. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8394. clif_inventorylist(sd);
  8395. clif_equipswitch_list(sd);
  8396. if(pc_iscarton(sd)) {
  8397. clif_cartlist(sd);
  8398. clif_updatestatus(sd,SP_CARTINFO);
  8399. }
  8400. clif_updatestatus(sd,SP_WEIGHT);
  8401. clif_updatestatus(sd,SP_MAXWEIGHT);
  8402. clif_updatestatus(sd,SP_STR);
  8403. clif_updatestatus(sd,SP_AGI);
  8404. clif_updatestatus(sd,SP_VIT);
  8405. clif_updatestatus(sd,SP_INT);
  8406. clif_updatestatus(sd,SP_DEX);
  8407. clif_updatestatus(sd,SP_LUK);
  8408. #ifdef RENEWAL
  8409. clif_updatestatus(sd,SP_POW);
  8410. clif_updatestatus(sd,SP_STA);
  8411. clif_updatestatus(sd,SP_WIS);
  8412. clif_updatestatus(sd,SP_SPL);
  8413. clif_updatestatus(sd,SP_CON);
  8414. clif_updatestatus(sd,SP_CRT);
  8415. #endif
  8416. if (sd->spiritball)
  8417. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8418. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD))
  8419. clif_millenniumshield_single(sd->fd, sd);
  8420. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8421. clif_spiritcharm_single(sd->fd, sd);
  8422. if (sd->soulball)
  8423. clif_soulball( sd, &sd->bl, SELF );
  8424. if (sd->servantball)
  8425. clif_servantball( *sd, &sd->bl, SELF );
  8426. if (sd->abyssball)
  8427. clif_abyssball( *sd, &sd->bl, SELF );
  8428. if (sd->vd.cloth_color)
  8429. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8430. if (sd->vd.body_style)
  8431. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8432. if(hom_is_active(sd->hd))
  8433. clif_send_homdata(sd,SP_ACK,0);
  8434. if( sd->md ) {
  8435. clif_mercenary_info(sd);
  8436. clif_mercenary_skillblock(sd);
  8437. }
  8438. if( sd->ed )
  8439. clif_elemental_info(sd);
  8440. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8441. clif_weather_check(sd);
  8442. if( sd->chatID )
  8443. chat_leavechat(sd,0);
  8444. if( sd->state.vending )
  8445. clif_openvending(sd, sd->bl.id, sd->vending);
  8446. if( pc_issit(sd) )
  8447. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8448. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8449. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8450. else
  8451. clif_changed_dir(&sd->bl, SELF);
  8452. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8453. //Issue #2143
  8454. //Cancel Trading State
  8455. if (sd->state.trading)
  8456. trade_tradecancel(sd);
  8457. //Cancel Buying/Selling State
  8458. if (sd->state.buyingstore)
  8459. buyingstore_close(sd);
  8460. mail_clear(sd);
  8461. clif_loadConfirm( sd );
  8462. if( disguised(&sd->bl) ) {/* refresh-da */
  8463. short disguise = sd->disguise;
  8464. pc_disguise(sd, 0);
  8465. pc_disguise(sd, disguise);
  8466. }
  8467. clif_refresh_storagewindow(sd);
  8468. }
  8469. /// Updates the object's (bl) name on client.
  8470. /// Used to update when a char leaves a party/guild. [Skotlex]
  8471. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8472. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8473. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8474. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8475. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8476. nullpo_retv( src );
  8477. nullpo_retv( bl );
  8478. switch( bl->type ){
  8479. case BL_PC: {
  8480. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8481. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8482. packet.gid = bl->id;
  8483. map_session_data *sd = (map_session_data *)bl;
  8484. //Requesting your own "shadow" name. [Skotlex]
  8485. if( src == bl && target == SELF && sd->disguise ){
  8486. packet.gid = -bl->id;
  8487. }
  8488. if( sd->fakename[0] ) {
  8489. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8490. clif_send( &packet, sizeof(packet), src, target );
  8491. return;
  8492. }
  8493. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8494. party_data *p = nullptr;
  8495. if( sd->status.party_id ){
  8496. p = party_search( sd->status.party_id );
  8497. }
  8498. // do not display party unless the player is also in a guild
  8499. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8500. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8501. }
  8502. if( sd->guild ){
  8503. int position;
  8504. // Will get the position of the guild the player is in
  8505. position = guild_getposition(*sd);
  8506. safestrncpy( packet.guild_name, sd->guild->guild.name, NAME_LENGTH );
  8507. safestrncpy( packet.position_name, sd->guild->guild.position[position].name, NAME_LENGTH );
  8508. }else if( sd->clan ){
  8509. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8510. }
  8511. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8512. packet.title_id = sd->status.title_id; // Title ID
  8513. #endif
  8514. clif_send(&packet, sizeof(packet), src, target);
  8515. }
  8516. break;
  8517. //[blackhole89]
  8518. case BL_HOM:
  8519. case BL_MER:
  8520. case BL_PET:
  8521. case BL_NPC:
  8522. case BL_ELEM: {
  8523. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8524. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8525. packet.gid = bl->id;
  8526. switch (bl->type) {
  8527. case BL_HOM:
  8528. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8529. break;
  8530. case BL_MER:
  8531. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8532. break;
  8533. case BL_PET:
  8534. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8535. break;
  8536. case BL_NPC:
  8537. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8538. break;
  8539. case BL_ELEM:
  8540. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8541. break;
  8542. }
  8543. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8544. unit_data *ud = unit_bl2ud(bl);
  8545. if (ud != nullptr) {
  8546. memcpy(packet.title, ud->title, NAME_LENGTH);
  8547. packet.groupId = ud->group_id;
  8548. }
  8549. #endif
  8550. clif_send(&packet, sizeof(packet), src, target);
  8551. }
  8552. break;
  8553. case BL_MOB: {
  8554. mob_data *md = (mob_data *)bl;
  8555. if( md->guardian_data && md->guardian_data->guild_id ){
  8556. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8557. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8558. packet.gid = bl->id;
  8559. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8560. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8561. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8562. clif_send(&packet, sizeof(packet), src, target);
  8563. }else if( battle_config.show_mob_info ){
  8564. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8565. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8566. packet.gid = bl->id;
  8567. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8568. char mobhp[50], *str_p = mobhp;
  8569. if( battle_config.show_mob_info&4 ){
  8570. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8571. }
  8572. if( battle_config.show_mob_info&1 ){
  8573. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8574. }
  8575. if( battle_config.show_mob_info&2 ){
  8576. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8577. }
  8578. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8579. if( str_p != mobhp ){
  8580. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8581. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8582. }
  8583. clif_send(&packet, sizeof(packet), src, target);
  8584. } else {
  8585. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8586. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8587. packet.gid = bl->id;
  8588. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8589. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8590. unit_data *ud = unit_bl2ud(bl);
  8591. if (ud != nullptr) {
  8592. memcpy(packet.title, ud->title, NAME_LENGTH);
  8593. packet.groupId = ud->group_id;
  8594. }
  8595. #endif
  8596. clif_send(&packet, sizeof(packet), src, target);
  8597. }
  8598. }
  8599. break;
  8600. case BL_CHAT:
  8601. case BL_SKILL:
  8602. // Newer clients request this, but do not need an answer
  8603. return;
  8604. default:
  8605. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8606. return;
  8607. }
  8608. }
  8609. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8610. /// 01ff <id>.L <x>.W <y>.W
  8611. ///
  8612. /// Visually moves(instant) a character to x,y. The char moves even
  8613. /// when the target cell isn't walkable. If the char is sitting it
  8614. /// stays that way.
  8615. void clif_slide(struct block_list *bl, int x, int y)
  8616. {
  8617. unsigned char buf[10];
  8618. nullpo_retv(bl);
  8619. WBUFW(buf, 0) = 0x01ff;
  8620. WBUFL(buf, 2) = bl->id;
  8621. WBUFW(buf, 6) = x;
  8622. WBUFW(buf, 8) = y;
  8623. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8624. if( disguised(bl) )
  8625. {
  8626. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8627. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8628. }
  8629. }
  8630. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8631. /// 008d <packet len>.W <id>.L <message>.?B
  8632. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8633. {
  8634. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8635. int len_mes = strlen(mes)+1; //Account for \0
  8636. if (len_mes > sizeof(buf)-8) {
  8637. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8638. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8639. }
  8640. // send message to others
  8641. if (flag == AREA) {
  8642. WBUFW(buf,0) = 0x8d;
  8643. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8644. WBUFL(buf,4) = bl->id;
  8645. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8646. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8647. }
  8648. // send back message to the speaker
  8649. if( bl->type == BL_PC ) {
  8650. WBUFW(buf,0) = 0x8e;
  8651. WBUFW(buf, 2) = len_mes + 4;
  8652. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8653. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8654. }
  8655. }
  8656. /*==========================
  8657. * Minimap fix [Kevin]
  8658. * Remove dot from minimap
  8659. *--------------------------*/
  8660. void clif_party_xy_remove(map_session_data* sd)
  8661. {
  8662. nullpo_retv(sd);
  8663. PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p{};
  8664. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  8665. p.AID = sd->status.account_id;
  8666. p.xPos = -1;
  8667. p.yPos = -1;
  8668. clif_send(&p, sizeof(p), &sd->bl, PARTY_SAMEMAP_WOS);
  8669. }
  8670. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8671. /// 0215 <msg id>.L
  8672. /// msg id:
  8673. /// 0x15 = End all negative status (PA_GOSPEL)
  8674. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8675. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8676. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8677. /// 0x19 = All stats +20 (PA_GOSPEL)
  8678. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8679. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8680. /// 0x1e = DEF +25% (PA_GOSPEL)
  8681. /// 0x1f = ATK +100% (PA_GOSPEL)
  8682. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8683. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8684. /// ? = nothing
  8685. void clif_gospel_info(map_session_data *sd, int type)
  8686. {
  8687. int fd=sd->fd;
  8688. WFIFOHEAD(fd,packet_len(0x215));
  8689. WFIFOW(fd,0)=0x215;
  8690. WFIFOL(fd,2)=type;
  8691. WFIFOSET(fd, packet_len(0x215));
  8692. }
  8693. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8694. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8695. /// result:
  8696. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8697. /// star:
  8698. /// 0 = Place of the Sun
  8699. /// 1 = Place of the Moon
  8700. /// 2 = Place of the Stars
  8701. /// 1 = Star Gladiator %s's %s: <mapname>
  8702. /// star:
  8703. /// 0 = Place of the Sun
  8704. /// 1 = Place of the Moon
  8705. /// 2 = Place of the Stars
  8706. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8707. /// star:
  8708. /// 0 = Target of the Sun
  8709. /// 1 = Target of the Moon
  8710. /// 2 = Target of the Stars
  8711. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8712. /// star:
  8713. /// 0 = Monster of the Sun
  8714. /// 1 = Monster of the Moon
  8715. /// 2 = Monster of the Stars
  8716. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8717. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8718. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8719. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8720. /// 40 = Target HP : <monster_id used as HP>
  8721. void clif_starskill(map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8722. {
  8723. int fd = sd->fd;
  8724. WFIFOHEAD(fd,packet_len(0x20e));
  8725. WFIFOW(fd,0) = 0x20e;
  8726. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8727. WFIFOL(fd,26) = monster_id;
  8728. WFIFOB(fd,30) = star;
  8729. WFIFOB(fd,31) = result;
  8730. WFIFOSET(fd,packet_len(0x20e));
  8731. }
  8732. /*==========================================
  8733. * Info about Star Glaldiator save map [Komurka]
  8734. * type: 1: Information, 0: Map registered
  8735. *------------------------------------------*/
  8736. void clif_feel_info(map_session_data* sd, unsigned char feel_level, unsigned char type)
  8737. {
  8738. char mapname[MAP_NAME_LENGTH_EXT];
  8739. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8740. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8741. }
  8742. /*==========================================
  8743. * Info about Star Glaldiator hate mob [Komurka]
  8744. * type: 1: Register mob, 0: Information.
  8745. *------------------------------------------*/
  8746. void clif_hate_info(map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8747. {
  8748. if( pcdb_checkid(class_) ) {
  8749. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8750. } else if( mobdb_checkid(class_) ) {
  8751. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8752. } else {
  8753. ShowWarning("clif_hate_info: Received invalid class %d for this packet (char_id=%d, hate_level=%u, type=%u).\n", class_, sd->status.char_id, (unsigned int)hate_level, (unsigned int)type);
  8754. }
  8755. }
  8756. /*==========================================
  8757. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8758. *------------------------------------------*/
  8759. void clif_mission_info(map_session_data *sd, int mob_id, unsigned char progress)
  8760. {
  8761. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8762. }
  8763. /*==========================================
  8764. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8765. *------------------------------------------*/
  8766. void clif_feel_hate_reset(map_session_data *sd)
  8767. {
  8768. clif_starskill(sd, "", 0, 0, 30);
  8769. }
  8770. /// Send out reply to configuration change
  8771. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8772. /// type: see enum e_config_type
  8773. /// value:
  8774. /// false = disabled
  8775. /// true = enabled
  8776. void clif_configuration( map_session_data* sd, enum e_config_type type, bool enabled ){
  8777. int fd;
  8778. nullpo_retv(sd);
  8779. fd = sd->fd;
  8780. WFIFOHEAD(fd, packet_len(0x2d9));
  8781. WFIFOW(fd, 0) = 0x2d9;
  8782. WFIFOL(fd, 2) = type;
  8783. WFIFOL(fd, 6) = enabled;
  8784. WFIFOSET(fd, packet_len(0x2d9));
  8785. }
  8786. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8787. /// 02da <open equip window>.B
  8788. /// open equip window:
  8789. /// 0 = disabled
  8790. /// 1 = enabled
  8791. void clif_equipcheckbox(map_session_data* sd)
  8792. {
  8793. int fd;
  8794. nullpo_retv(sd);
  8795. fd = sd->fd;
  8796. WFIFOHEAD(fd, packet_len(0x2da));
  8797. WFIFOW(fd, 0) = 0x2da;
  8798. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8799. WFIFOSET(fd, packet_len(0x2da));
  8800. }
  8801. /// Sends info about a player's equipped items.
  8802. /// 02d7 <packet len>.W <name>.24B <class>.W <hairstyle>.W <up-viewid>.W <mid-viewid>.W <low-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.26B* (ZC_EQUIPWIN_MICROSCOPE)
  8803. /// 02d7 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE, PACKETVER >= 20100629)
  8804. /// 0859 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE2, PACKETVER >= 20101124)
  8805. /// 0859 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE2, PACKETVER >= 20110111)
  8806. /// 0997 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.31B* (ZC_EQUIPWIN_MICROSCOPE_V5, PACKETVER >= 20120925)
  8807. /// 0a2d <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.57B* (ZC_EQUIPWIN_MICROSCOPE_V6, PACKETVER >= 20150225)
  8808. void clif_viewequip_ack( map_session_data* sd, map_session_data* tsd ){
  8809. #if PACKETVER_AD_NUM >= 20071211 || PACKETVER_SAK_NUM >= 20071127 || PACKETVER_MAIN_NUM >= 20071211 || defined(PACKETVER_RE)
  8810. nullpo_retv( sd );
  8811. nullpo_retv( tsd );
  8812. struct PACKET_ZC_EQUIPWIN_MICROSCOPE* p = (struct PACKET_ZC_EQUIPWIN_MICROSCOPE*)packet_buffer;
  8813. int equip = 0;
  8814. for( int i = 0; i < EQI_MAX; i++ ){
  8815. int k = tsd->equip_index[i];
  8816. if( k >= 0 ){
  8817. if( tsd->inventory.u.items_inventory[k].nameid == 0 || tsd->inventory_data[k] == NULL ){ // Item doesn't exist
  8818. continue;
  8819. }
  8820. if( !tsd->inventory.u.items_inventory[k].equip ){
  8821. continue;
  8822. }
  8823. if( !itemdb_isequip2( tsd->inventory_data[k] ) ){ // Is not equippable
  8824. continue;
  8825. }
  8826. clif_item_equip( client_index( k ), &p->list[equip++], &tsd->inventory.u.items_inventory[k], tsd->inventory_data[k], pc_equippoint( tsd, k ) );
  8827. }
  8828. }
  8829. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8830. p->PacketLength = sizeof( *p ) + sizeof( struct EQUIPITEM_INFO ) * equip;
  8831. safestrncpy( p->characterName, tsd->status.name, NAME_LENGTH );
  8832. p->job = tsd->status.class_;
  8833. p->head = tsd->vd.hair_style;
  8834. p->accessory = tsd->vd.head_bottom;
  8835. p->accessory2 = tsd->vd.head_mid;
  8836. p->accessory3 = tsd->vd.head_top;
  8837. #if PACKETVER >= 20110111
  8838. p->robe = tsd->vd.robe;
  8839. #endif
  8840. p->headpalette = tsd->vd.hair_color;
  8841. p->bodypalette = tsd->vd.cloth_color;
  8842. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8843. p->body2 = tsd->vd.body_style;
  8844. #endif
  8845. p->sex = tsd->vd.sex;
  8846. clif_send( p, p->PacketLength, &sd->bl, SELF );
  8847. #endif
  8848. }
  8849. /// Display msgstringtable.txt string (ZC_MSG).
  8850. /// 0291 <message>.W
  8851. void clif_msg(map_session_data* sd, unsigned short id)
  8852. {
  8853. int fd;
  8854. nullpo_retv(sd);
  8855. fd = sd->fd;
  8856. WFIFOHEAD(fd, packet_len(0x291));
  8857. WFIFOW(fd, 0) = 0x291;
  8858. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8859. WFIFOSET(fd, packet_len(0x291));
  8860. }
  8861. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8862. /// 0x7e2 <message>.W <value>.L
  8863. void clif_msg_value(map_session_data* sd, unsigned short id, int value)
  8864. {
  8865. int fd = sd->fd;
  8866. WFIFOHEAD(fd, packet_len(0x7e2));
  8867. WFIFOW(fd,0) = 0x7e2;
  8868. WFIFOW(fd,2) = id;
  8869. WFIFOL(fd,4) = value;
  8870. WFIFOSET(fd, packet_len(0x7e2));
  8871. }
  8872. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8873. /// 07e6 <skill id>.W <msg id>.L
  8874. ///
  8875. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8876. /// "[SkillName] Message"
  8877. void clif_msg_skill(map_session_data* sd, uint16 skill_id, int msg_id)
  8878. {
  8879. int fd = sd->fd;
  8880. WFIFOHEAD(fd, packet_len(0x7e6));
  8881. WFIFOW(fd,0) = 0x7e6;
  8882. WFIFOW(fd,2) = skill_id;
  8883. WFIFOL(fd,4) = msg_id;
  8884. WFIFOSET(fd, packet_len(0x7e6));
  8885. }
  8886. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8887. /// 09cd <msg id>.W <color>.L
  8888. void clif_msg_color( map_session_data *sd, uint16 msg_id, uint32 color ){
  8889. nullpo_retv(sd);
  8890. int fd = sd->fd;
  8891. WFIFOHEAD(fd, packet_len(0x9cd));
  8892. WFIFOW(fd, 0) = 0x9cd;
  8893. WFIFOW(fd, 2) = msg_id;
  8894. WFIFOL(fd, 4) = color;
  8895. WFIFOSET(fd, packet_len(0x9cd));
  8896. }
  8897. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8898. /// Returns true if the packet was parsed successfully.
  8899. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8900. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8901. static bool clif_process_message(map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8902. const char* seperator = " : ";
  8903. int fd;
  8904. struct s_packet_db* info;
  8905. uint16 packetLength, inputLength;
  8906. const char *input, *name, *message;
  8907. size_t nameLength, messageLength;
  8908. fd = sd->fd;
  8909. info = &packet_db[RFIFOW(fd,0)];
  8910. packetLength = RFIFOW(fd,info->pos[0]);
  8911. input = RFIFOCP(fd,info->pos[1]);
  8912. // basic structure check for the 4-byte header
  8913. if( packetLength < 4 ){
  8914. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8915. return false;
  8916. }else{
  8917. inputLength = packetLength - 4;
  8918. }
  8919. // process <name> part of the packet
  8920. if( whisperFormat ) {
  8921. // name has fixed width
  8922. if( inputLength < NAME_LENGTH + 1 ) {
  8923. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8924. return false;
  8925. }
  8926. name = input;
  8927. // validate name
  8928. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8929. // only restriction is that the name must be zero-terminated
  8930. if( name[nameLength] != '\0' ) {
  8931. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8932. return false;
  8933. }
  8934. message = input + NAME_LENGTH;
  8935. messageLength = inputLength - NAME_LENGTH;
  8936. }else{
  8937. // name and message are separated by ' : '
  8938. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8939. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8940. // check if there's enough data provided
  8941. if( inputLength < nameLength + seperatorLength + 1 ){
  8942. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8943. return false;
  8944. }
  8945. name = input;
  8946. // validate name
  8947. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8948. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8949. {
  8950. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8951. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8952. set_eof(sd->fd); // Just kick them out to correct it.
  8953. return false;
  8954. }
  8955. message = input + nameLength + seperatorLength;
  8956. messageLength = inputLength - nameLength - seperatorLength;
  8957. }
  8958. #if PACKETVER < 20151001
  8959. // the declared length must match real length
  8960. if( messageLength != strnlen(message, messageLength)+1 ) {
  8961. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8962. return false;
  8963. }
  8964. // verify <message> part of the packet
  8965. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8966. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8967. return false;
  8968. }
  8969. #else
  8970. // No zero termination anymore
  8971. messageLength += 1;
  8972. #endif
  8973. // messages mustn't be too long
  8974. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8975. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8976. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8977. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8978. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8979. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8980. return false;
  8981. }
  8982. // If it is not a whisper message, set the name to the fakename of the player
  8983. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8984. strcpy( out_name, sd->fakename );
  8985. }else{
  8986. safestrncpy( out_name, name, nameLength + 1 );
  8987. }
  8988. safestrncpy( out_message, message, messageLength );
  8989. if( whisperFormat ){
  8990. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8991. out_full_message[nameLength] = '\0';
  8992. }else{
  8993. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8994. }
  8995. if( is_atcommand( fd, sd, out_message, 1 ) )
  8996. return false;
  8997. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8998. return false; //no "chatting" while muted.
  8999. if( battle_config.min_chat_delay ) { //[Skotlex]
  9000. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9001. return false;
  9002. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9003. }
  9004. if (battle_config.idletime_option&IDLE_CHAT)
  9005. sd->idletime = last_tick;
  9006. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  9007. sd->idletime_hom = last_tick;
  9008. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  9009. sd->idletime_mer = last_tick;
  9010. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  9011. return true;
  9012. }
  9013. /**
  9014. * Displays a message if the player enters a PK Zone (during pk_mode)
  9015. * @param sd: Player data
  9016. */
  9017. inline void clif_pk_mode_message(map_session_data * sd)
  9018. {
  9019. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  9020. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  9021. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  9022. char output[CHAT_SIZE_MAX];
  9023. // 1504: You've entered a PK Zone (safe until level %d).
  9024. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  9025. battle_config.pk_min_level);
  9026. clif_showscript(&sd->bl, output, SELF);
  9027. } else {
  9028. // 1503: You've entered a PK Zone.
  9029. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  9030. }
  9031. }
  9032. return;
  9033. }
  9034. // ---------------------
  9035. // clif_parse_wanttoconnect
  9036. // ---------------------
  9037. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  9038. // error codes:
  9039. // 0 - Success
  9040. // 1 - Unknown packet_ver
  9041. // 2 - Invalid account_id
  9042. // 3 - Invalid char_id
  9043. // 4 - Invalid login_id1 (reserved)
  9044. // 5 - Invalid client_tick (reserved)
  9045. // 6 - Invalid sex
  9046. // Only the first 'invalid' error that appears is used.
  9047. static int clif_parse_WantToConnection_sub(int fd)
  9048. {
  9049. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  9050. unsigned short cmd;
  9051. //By default, start searching on the default one.
  9052. cmd = RFIFOW(fd, 0);
  9053. packet_len = RFIFOREST(fd);
  9054. // FIXME: If the packet is not received at once, this will FAIL.
  9055. // Figure out, when it happens, that only part of the packet is
  9056. // received, or fix the function to be able to deal with that
  9057. // case.
  9058. if( packet_len != packet_db[cmd].len )
  9059. return 1; /* wrong length */
  9060. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  9061. return 2; /* invalid account_id */
  9062. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  9063. return 3; /* invalid char_id */
  9064. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  9065. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  9066. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  9067. return 6; /* invalid sex */
  9068. else
  9069. return 0;
  9070. }
  9071. /// Request to connect to map-server.
  9072. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  9073. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  9074. /// There are various variants of this packet, some of them have padding between fields.
  9075. void clif_parse_WantToConnection(int fd, map_session_data* sd)
  9076. {
  9077. struct block_list* bl;
  9078. struct auth_node* node;
  9079. int cmd, account_id, char_id, login_id1, sex, err;
  9080. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  9081. if (sd) {
  9082. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  9083. return;
  9084. }
  9085. cmd = RFIFOW(fd, 0);
  9086. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  9087. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  9088. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  9089. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  9090. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  9091. err = clif_parse_WantToConnection_sub(fd);
  9092. if( err ){ // connection rejected
  9093. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  9094. err == 1 ? "." :
  9095. err == 2 ? ", possibly for having an invalid account_id." :
  9096. err == 3 ? ", possibly for having an invalid char_id." :
  9097. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  9098. err == 4 ? ", possibly for having an invalid login_id1." :
  9099. err == 5 ? ", possibly for having an invalid client_tick." :
  9100. */
  9101. err == 6 ? ", possibly for having an invalid sex." :
  9102. ". ERROR invalid error code"));
  9103. WFIFOHEAD(fd,packet_len(0x6a));
  9104. WFIFOW(fd,0) = 0x6a;
  9105. WFIFOB(fd,2) = err;
  9106. WFIFOSET(fd,packet_len(0x6a));
  9107. #ifdef DUMP_INVALID_PACKET
  9108. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  9109. #endif
  9110. RFIFOSKIP(fd, RFIFOREST(fd));
  9111. set_eof(fd);
  9112. return;
  9113. }
  9114. if( !global_core->is_running() ){ // not allowed
  9115. clif_authfail_fd(fd,1);// server closed
  9116. return;
  9117. }
  9118. //Check for double login.
  9119. bl = map_id2bl(account_id);
  9120. if(bl && bl->type != BL_PC) {
  9121. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  9122. WFIFOHEAD(fd,packet_len(0x6a));
  9123. WFIFOW(fd,0) = 0x6a;
  9124. WFIFOB(fd,2) = 3; // Rejected by server
  9125. WFIFOSET(fd,packet_len(0x6a));
  9126. set_eof(fd);
  9127. return;
  9128. }
  9129. if (bl ||
  9130. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  9131. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  9132. {
  9133. clif_authfail_fd(fd, 8); //Still recognizes last connection
  9134. return;
  9135. }
  9136. CREATE(sd, TBL_PC, 1);
  9137. new(sd) map_session_data();
  9138. sd->fd = fd;
  9139. #ifdef PACKET_OBFUSCATION
  9140. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  9141. #endif
  9142. session[fd]->session_data = sd;
  9143. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  9144. #if PACKETVER < 20070521
  9145. WFIFOHEAD(fd,4);
  9146. WFIFOL(fd,0) = sd->bl.id;
  9147. WFIFOSET(fd,4);
  9148. #else
  9149. WFIFOHEAD(fd,packet_len(0x283));
  9150. WFIFOW(fd,0) = 0x283;
  9151. WFIFOL(fd,2) = sd->bl.id;
  9152. WFIFOSET(fd,packet_len(0x283));
  9153. #endif
  9154. chrif_authreq(sd,false);
  9155. }
  9156. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  9157. /// 007d
  9158. void clif_parse_LoadEndAck(int fd,map_session_data *sd)
  9159. {
  9160. bool guild_notice = false;
  9161. if(sd->bl.prev != NULL)
  9162. return;
  9163. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  9164. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  9165. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  9166. sd->state.connect_new = 0;
  9167. return;
  9168. }
  9169. if (sd->state.rewarp) { //Rewarp player.
  9170. sd->state.rewarp = 0;
  9171. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  9172. return;
  9173. }
  9174. sd->state.warping = 0;
  9175. // look
  9176. #if PACKETVER < 4
  9177. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  9178. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  9179. #else
  9180. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  9181. #endif
  9182. pc_set_costume_view(sd);
  9183. if(sd->vd.cloth_color)
  9184. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  9185. if(sd->vd.body_style)
  9186. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  9187. // item
  9188. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  9189. pc_checkitem(sd);
  9190. clif_equipswitch_list(sd);
  9191. // cart
  9192. if(pc_iscarton(sd)) {
  9193. clif_cartlist(sd);
  9194. clif_updatestatus(sd,SP_CARTINFO);
  9195. }
  9196. // weight
  9197. clif_updatestatus(sd,SP_WEIGHT);
  9198. clif_updatestatus(sd,SP_MAXWEIGHT);
  9199. // guild
  9200. // (needs to go before clif_spawn() to show guild emblems correctly)
  9201. if(sd->status.guild_id)
  9202. guild_send_memberinfoshort(sd,1);
  9203. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  9204. if(battle_config.pc_invincible_time > 0) {
  9205. if(mapdata_flag_gvg(mapdata))
  9206. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  9207. else
  9208. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  9209. }
  9210. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  9211. map_spawnmobs(sd->bl.m);
  9212. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  9213. mapdata->users_pvp++;
  9214. }
  9215. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  9216. // reset the callshop flag if the player changes map
  9217. sd->state.callshop = 0;
  9218. if(map_addblock(&sd->bl))
  9219. return;
  9220. clif_spawn(&sd->bl);
  9221. // Party
  9222. // (needs to go after clif_spawn() to show hp bars correctly)
  9223. if(sd->status.party_id) {
  9224. party_send_movemap(sd);
  9225. clif_party_hp( *sd ); // Show hp after displacement [LuzZza]
  9226. }
  9227. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  9228. if(!pc_isinvisible(sd) && mapdata->getMapFlag(MF_PVP)) {
  9229. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9230. if (!mapdata->getMapFlag(MF_PVP_NOCALCRANK))
  9231. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9232. sd->pvp_rank = 0;
  9233. sd->pvp_lastusers = 0;
  9234. sd->pvp_point = 5;
  9235. sd->pvp_won = 0;
  9236. sd->pvp_lost = 0;
  9237. }
  9238. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9239. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9240. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9241. else if (mapdata->getMapFlag(MF_GVG_DUNGEON))
  9242. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9243. else if( mapdata_flag_gvg(mapdata) )
  9244. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9245. else
  9246. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9247. // info about nearby objects
  9248. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9249. map_foreachinallarea(clif_getareachar, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_ALL, sd);
  9250. // pet
  9251. if( sd->pd ) {
  9252. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9253. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9254. pet_return_egg( sd, sd->pd );
  9255. } else {
  9256. if(map_addblock(&sd->pd->bl))
  9257. return;
  9258. clif_spawn(&sd->pd->bl);
  9259. clif_send_petdata(sd,sd->pd,0,0);
  9260. clif_send_petstatus(sd);
  9261. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9262. }
  9263. }
  9264. //homunculus [blackhole89]
  9265. if( hom_is_active(sd->hd) ) {
  9266. if(map_addblock(&sd->hd->bl))
  9267. return;
  9268. clif_spawn(&sd->hd->bl);
  9269. clif_send_homdata(sd,SP_ACK,0);
  9270. clif_hominfo(sd,sd->hd,1);
  9271. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9272. clif_homskillinfoblock(sd);
  9273. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9274. status_calc_bl(&sd->hd->bl, { SCB_SPEED }); //Homunc mimic their master's speed on each map change
  9275. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9276. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9277. }
  9278. if( sd->md ) {
  9279. if(map_addblock(&sd->md->bl))
  9280. return;
  9281. clif_spawn(&sd->md->bl);
  9282. clif_mercenary_info(sd);
  9283. clif_mercenary_skillblock(sd);
  9284. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9285. }
  9286. if( sd->ed ) {
  9287. if (map_addblock(&sd->ed->bl))
  9288. return;
  9289. clif_spawn(&sd->ed->bl);
  9290. clif_elemental_info(sd);
  9291. clif_elemental_updatestatus(sd,SP_HP);
  9292. clif_hpmeter_single( *sd, sd->ed->bl.id, sd->ed->battle_status.hp, sd->ed->battle_status.max_hp );
  9293. clif_elemental_updatestatus(sd,SP_SP);
  9294. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9295. }
  9296. if(sd->state.connect_new) {
  9297. int lv;
  9298. guild_notice = true;
  9299. clif_skillinfoblock(sd);
  9300. clif_hotkeys_send(sd,0);
  9301. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9302. clif_hotkeys_send(sd,1);
  9303. #endif
  9304. clif_updatestatus(sd,SP_BASEEXP);
  9305. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9306. clif_updatestatus(sd,SP_JOBEXP);
  9307. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9308. clif_updatestatus(sd,SP_SKILLPOINT);
  9309. clif_initialstatus(sd);
  9310. if (sd->sc.option&OPTION_FALCON)
  9311. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9312. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9313. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9314. else if (sd->sc.option&OPTION_WUGRIDER)
  9315. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9316. else if (sd->sc.getSCE(SC_ALL_RIDING))
  9317. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9318. if(sd->status.manner < 0)
  9319. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9320. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9321. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9322. if(sd->bl.m == sd->feel_map[0].m
  9323. || sd->bl.m == sd->feel_map[1].m
  9324. || sd->bl.m == sd->feel_map[2].m)
  9325. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9326. }
  9327. if(sd->pd && sd->pd->pet.intimate > 900)
  9328. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9329. if(hom_is_active(sd->hd))
  9330. hom_init_timers(sd->hd);
  9331. if (night_flag && mapdata->getMapFlag(MF_NIGHTENABLED)) {
  9332. sd->state.night = 1;
  9333. clif_status_load(&sd->bl, EFST_SKE, 1);
  9334. }
  9335. // Notify everyone that this char logged in [Skotlex].
  9336. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9337. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9338. //Login Event
  9339. npc_script_event(sd, NPCE_LOGIN);
  9340. }
  9341. // Set facing direction before check below to update client
  9342. if (battle_config.spawn_direction)
  9343. unit_setdir(&sd->bl, sd->status.body_direction, false);
  9344. } else {
  9345. //For some reason the client "loses" these on warp/map-change.
  9346. clif_updatestatus(sd,SP_STR);
  9347. clif_updatestatus(sd,SP_AGI);
  9348. clif_updatestatus(sd,SP_VIT);
  9349. clif_updatestatus(sd,SP_INT);
  9350. clif_updatestatus(sd,SP_DEX);
  9351. clif_updatestatus(sd,SP_LUK);
  9352. #ifdef RENEWAL
  9353. clif_updatestatus(sd,SP_POW);
  9354. clif_updatestatus(sd,SP_STA);
  9355. clif_updatestatus(sd,SP_WIS);
  9356. clif_updatestatus(sd,SP_SPL);
  9357. clif_updatestatus(sd,SP_CON);
  9358. clif_updatestatus(sd,SP_CRT);
  9359. #endif
  9360. // abort currently running script
  9361. sd->state.using_fake_npc = 0;
  9362. sd->state.menu_or_input = 0;
  9363. sd->npc_menu = 0;
  9364. if(sd->npc_id)
  9365. npc_event_dequeue(sd);
  9366. }
  9367. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9368. clif_partyinvitationstate( *sd );
  9369. #if PACKETVER >= 20070918
  9370. clif_equipcheckbox(sd);
  9371. #endif
  9372. clif_pet_autofeed_status(sd,false);
  9373. clif_configuration( sd, CONFIG_CALL, sd->status.disable_call );
  9374. #if PACKETVER >= 20170920
  9375. if( battle_config.homunculus_autofeed_always ){
  9376. // Always send ON or OFF
  9377. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9378. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9379. }else{
  9380. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9381. }
  9382. }else{
  9383. // Only send when enabled
  9384. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9385. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9386. }
  9387. }
  9388. #endif
  9389. clif_reputation_list( *sd );
  9390. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9391. clif_guild_notice(sd); // Displays after VIP
  9392. guild_notice = false; // Do not display it twice
  9393. }
  9394. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9395. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9396. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->getMapFlag(MF_BATTLEGROUND))) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->getMapFlag(MF_BATTLEGROUND))))
  9397. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9398. }
  9399. if( night_flag && mapdata->getMapFlag(MF_NIGHTENABLED) )
  9400. { //Display night.
  9401. if( !sd->state.night )
  9402. {
  9403. sd->state.night = 1;
  9404. clif_status_load(&sd->bl, EFST_SKE, 1);
  9405. }
  9406. }
  9407. else if( sd->state.night )
  9408. { //Clear night display.
  9409. sd->state.night = 0;
  9410. clif_status_load(&sd->bl, EFST_SKE, 0);
  9411. }
  9412. if( mapdata->getMapFlag(MF_BATTLEGROUND) )
  9413. {
  9414. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9415. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9416. clif_bg_updatescore_single(sd);
  9417. }
  9418. if( mapdata->getMapFlag(MF_ALLOWKS) && !mapdata_flag_ks(mapdata) )
  9419. {
  9420. char output[128];
  9421. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9422. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9423. }
  9424. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9425. mapdata->hpmeter_visible++;
  9426. sd->state.hpmeter_visible = 1;
  9427. }
  9428. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9429. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9430. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9431. #ifdef VIP_ENABLE
  9432. if (!sd->state.connect_new &&
  9433. !sd->vip.disableshowrate &&
  9434. sd->state.pmap != sd->bl.m &&
  9435. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->getMapFlag(MF_BEXP)
  9436. )
  9437. {
  9438. clif_display_pinfo( *sd );
  9439. }
  9440. #endif
  9441. // Instances do not need their own channels
  9442. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->getMapFlag(MF_NOMAPCHANNELAUTOJOIN) )
  9443. channel_mjoin(sd); //join new map
  9444. clif_pk_mode_message(sd);
  9445. }
  9446. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9447. clif_guild_notice(sd); // Displays at end
  9448. }
  9449. mail_clear(sd);
  9450. /* Guild Aura Init */
  9451. if( sd->guild && sd->state.gmaster_flag ) {
  9452. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild->guild,GD_LEADERSHIP));
  9453. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild->guild,GD_GLORYWOUNDS));
  9454. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild->guild,GD_SOULCOLD));
  9455. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild->guild,GD_HAWKEYES));
  9456. }
  9457. if( sd->state.vending ) { /* show we have a vending */
  9458. clif_openvending(sd,sd->bl.id,sd->vending);
  9459. clif_showvendingboard( *sd );
  9460. }
  9461. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9462. if(!sd->state.autotrade && mapdata->getMapFlag(MF_LOADEVENT)) // Lance
  9463. npc_script_event(sd, NPCE_LOADMAP);
  9464. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9465. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9466. if (sd->sc.opt2) //Client loses these on warp.
  9467. clif_changeoption(&sd->bl);
  9468. if ((sd->sc.getSCE(SC_MONSTER_TRANSFORM) || sd->sc.getSCE(SC_ACTIVE_MONSTER_TRANSFORM)) && battle_config.mon_trans_disable_in_gvg && mapdata_flag_gvg2(mapdata)) {
  9469. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM);
  9470. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM);
  9471. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9472. }
  9473. clif_weather_check(sd);
  9474. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9475. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9476. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9477. else
  9478. sd->areanpc.clear();
  9479. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9480. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9481. pc_setdead(sd);
  9482. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9483. if(pc_isdead(sd))
  9484. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9485. else {
  9486. skill_usave_trigger(sd);
  9487. if (battle_config.spawn_direction)
  9488. clif_changed_dir(&sd->bl, SELF);
  9489. }
  9490. // Trigger skill effects if you appear standing on them
  9491. if(!battle_config.pc_invincible_time)
  9492. skill_unit_move(&sd->bl,gettick(),1);
  9493. pc_show_questinfo_reinit(sd);
  9494. pc_show_questinfo(sd);
  9495. #if PACKETVER >= 20150513
  9496. if( sd->mail.inbox.unread ){
  9497. clif_Mail_new(sd, 0, NULL, NULL);
  9498. }
  9499. #endif
  9500. sd->state.connect_new = 0;
  9501. sd->state.changemap = false;
  9502. }
  9503. /// Server's tick (ZC_NOTIFY_TIME).
  9504. /// 007f <time>.L
  9505. void clif_notify_time(map_session_data* sd, t_tick time)
  9506. {
  9507. int fd = sd->fd;
  9508. WFIFOHEAD(fd,packet_len(0x7f));
  9509. WFIFOW(fd,0) = 0x7f;
  9510. WFIFOL(fd,2) = client_tick(time);
  9511. WFIFOSET(fd,packet_len(0x7f));
  9512. }
  9513. /// Request for server's tick.
  9514. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9515. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9516. /// There are various variants of this packet, some of them have padding between fields.
  9517. void clif_parse_TickSend(int fd, map_session_data *sd)
  9518. {
  9519. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9520. clif_notify_time(sd, gettick());
  9521. }
  9522. /// Sends hotkey bar.
  9523. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9524. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9525. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9526. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9527. void clif_hotkeys_send( map_session_data *sd, int tab ){
  9528. #if defined(HOTKEY_SAVING) && ( PACKETVER_MAIN_NUM >= 20070711 || PACKETVER_RE_NUM >= 20080827 || PACKETVER_AD_NUM >= 20070711 || PACKETVER_SAK_NUM >= 20070628 )
  9529. nullpo_retv( sd );
  9530. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9531. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9532. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9533. if( tab == 0 ){
  9534. p.rotate = sd->status.hotkey_rowshift;
  9535. }else{
  9536. p.rotate = sd->status.hotkey_rowshift2;
  9537. }
  9538. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9539. p.tab = tab;
  9540. #endif
  9541. #endif
  9542. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9543. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9544. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9545. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9546. }
  9547. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9548. #endif
  9549. }
  9550. /// Request to update a position on the hotkey row bar
  9551. void clif_parse_HotkeyRowShift( int fd, map_session_data *sd ){
  9552. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9553. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9554. if( p->tab == 0 ){
  9555. sd->status.hotkey_rowshift = p->rowshift;
  9556. }else{
  9557. sd->status.hotkey_rowshift2 = p->rowshift;
  9558. }
  9559. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9560. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9561. sd->status.hotkey_rowshift = p->rowshift;
  9562. #endif
  9563. }
  9564. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9565. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9566. void clif_parse_Hotkey(int fd, map_session_data *sd) {
  9567. #ifdef HOTKEY_SAVING
  9568. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9569. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9570. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9571. if( idx >= MAX_HOTKEYS_DB ){
  9572. return;
  9573. }
  9574. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9575. sd->status.hotkeys[idx].id = p->hotkey.id;
  9576. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9577. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9578. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9579. const unsigned short idx = p->index;
  9580. if( idx >= MAX_HOTKEYS_DB ){
  9581. return;
  9582. }
  9583. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9584. sd->status.hotkeys[idx].id = p->hotkey.id;
  9585. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9586. #endif
  9587. #endif
  9588. }
  9589. /// Displays cast-like progress bar (ZC_PROGRESS).
  9590. /// 02f0 <color>.L <time>.L
  9591. void clif_progressbar(map_session_data * sd, unsigned long color, unsigned int second)
  9592. {
  9593. int fd = sd->fd;
  9594. WFIFOHEAD(fd,packet_len(0x2f0));
  9595. WFIFOW(fd,0) = 0x2f0;
  9596. WFIFOL(fd,2) = color;
  9597. WFIFOL(fd,6) = second;
  9598. WFIFOSET(fd,packet_len(0x2f0));
  9599. }
  9600. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9601. /// 02f2
  9602. void clif_progressbar_abort(map_session_data * sd)
  9603. {
  9604. int fd = sd->fd;
  9605. WFIFOHEAD(fd,packet_len(0x2f2));
  9606. WFIFOW(fd,0) = 0x2f2;
  9607. WFIFOSET(fd,packet_len(0x2f2));
  9608. }
  9609. /// Notification from the client, that the progress bar has reached 100%.
  9610. /// 02f1 (CZ_PROGRESS)
  9611. void clif_parse_progressbar(int fd, map_session_data * sd){
  9612. // No progressbar active, ignore it
  9613. if( !sd->progressbar.npc_id ){
  9614. return;
  9615. }
  9616. int npc_id = sd->progressbar.npc_id;
  9617. bool closing = false;
  9618. // Check if the progress was canceled
  9619. if( gettick() < sd->progressbar.timeout && sd->st ){
  9620. closing = true;
  9621. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9622. // If a message window was open, offer a close button to the user
  9623. if( sd->st->mes_active ){
  9624. clif_scriptclose( sd, npc_id );
  9625. }
  9626. }
  9627. sd->progressbar.npc_id = 0;
  9628. sd->progressbar.timeout = 0;
  9629. sd->state.workinprogress = WIP_DISABLE_NONE;
  9630. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9631. sd->idletime = last_tick;
  9632. }
  9633. npc_scriptcont(sd, npc_id, closing);
  9634. }
  9635. /// Displays cast-like progress bar on a NPC
  9636. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9637. void clif_progressbar_npc( struct npc_data *nd, map_session_data* sd ){
  9638. #if PACKETVER >= 20130821
  9639. unsigned char buf[14];
  9640. if( nd->progressbar.timeout > 0 ){
  9641. WBUFW(buf,0) = 0x9d1;
  9642. WBUFL(buf,2) = nd->bl.id;
  9643. WBUFL(buf,6) = nd->progressbar.color;
  9644. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9645. if( sd ){
  9646. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9647. }else{
  9648. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9649. }
  9650. }
  9651. #endif
  9652. }
  9653. /// Request to walk to a certain position on the current map.
  9654. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9655. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9656. /// There are various variants of this packet, some of them have padding between fields.
  9657. void clif_parse_WalkToXY(int fd, map_session_data *sd)
  9658. {
  9659. short x, y;
  9660. if (pc_isdead(sd)) {
  9661. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9662. return;
  9663. }
  9664. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9665. ; //You CAN walk on this OPT1 value.
  9666. else if (sd->progressbar.npc_id) {
  9667. clif_progressbar_abort(sd);
  9668. return; // First walk attempt cancels the progress bar
  9669. } else if (pc_cant_act(sd))
  9670. return;
  9671. if(sd->sc.getSCE(SC_RUN) || sd->sc.getSCE(SC_WUGDASH))
  9672. return;
  9673. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9674. //A move command one cell west is only valid if the target cell is free
  9675. if(battle_config.official_cell_stack_limit > 0
  9676. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9677. return;
  9678. // Cloaking wall check is actually updated when you click to process next movement
  9679. // not when you move each cell. This is official behaviour.
  9680. if (sd->sc.getSCE(SC_CLOAKING))
  9681. skill_check_cloaking(&sd->bl, sd->sc.getSCE(SC_CLOAKING));
  9682. status_change_end(&sd->bl, SC_ROLLINGCUTTER); // If you move, you lose your counters. [malufett]
  9683. status_change_end(&sd->bl, SC_CRESCIVEBOLT);
  9684. pc_delinvincibletimer(sd);
  9685. //Set last idle time... [Skotlex]
  9686. if (battle_config.idletime_option&IDLE_WALK)
  9687. sd->idletime = last_tick;
  9688. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9689. sd->idletime_hom = last_tick;
  9690. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9691. sd->idletime_mer = last_tick;
  9692. unit_walktoxy(&sd->bl, x, y, 4);
  9693. }
  9694. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9695. /// 018b <result>.W
  9696. /// result:
  9697. /// 0 = disconnect (quit)
  9698. /// 1 = cannot disconnect (wait 10 seconds)
  9699. /// ? = ignored
  9700. void clif_disconnect_ack(map_session_data* sd, short result)
  9701. {
  9702. int fd = sd->fd;
  9703. WFIFOHEAD(fd,packet_len(0x18b));
  9704. WFIFOW(fd,0) = 0x18b;
  9705. WFIFOW(fd,2) = result;
  9706. WFIFOSET(fd,packet_len(0x18b));
  9707. }
  9708. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9709. /// 018a <type>.W
  9710. /// type:
  9711. /// 0 = quit
  9712. void clif_parse_QuitGame(int fd, map_session_data *sd)
  9713. {
  9714. /* Rovert's prevent logout option fixed [Valaris] */
  9715. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9716. if( !sd->sc.getSCE(SC_CLOAKING) && !sd->sc.getSCE(SC_HIDING) && !sd->sc.getSCE(SC_CHASEWALK) && !sd->sc.getSCE(SC_CLOAKINGEXCEED) && !sd->sc.getSCE(SC_SUHIDE) && !sd->sc.getSCE(SC_NEWMOON) &&
  9717. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9718. {
  9719. pc_damage_log_clear(sd,0);
  9720. clif_disconnect_ack(sd, 0);
  9721. flush_fifo( fd );
  9722. if( battle_config.drop_connection_on_quit ){
  9723. set_eof( fd );
  9724. }
  9725. } else {
  9726. clif_disconnect_ack(sd, 1);
  9727. }
  9728. }
  9729. /// Requesting unit's name.
  9730. /// 0094 <id>.L (CZ_REQNAME)
  9731. /// 0368 <id>.L (CZ_REQNAME2)
  9732. /// There are various variants of this packet, some of them have padding between fields.
  9733. void clif_parse_GetCharNameRequest(int fd, map_session_data *sd)
  9734. {
  9735. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9736. struct block_list* bl;
  9737. //status_change *sc;
  9738. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9739. id = sd->bl.id;
  9740. bl = map_id2bl(id);
  9741. if( bl == NULL )
  9742. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9743. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9744. return; // Block namerequests past view range
  9745. // 'see people in GM hide' cheat detection
  9746. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9747. sc = status_get_sc(bl);
  9748. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9749. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9750. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9751. ) {
  9752. char gm_msg[256];
  9753. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target (id: %d).\n", sd->status.name, sd->status.account_id, id);
  9754. ShowWarning(gm_msg);
  9755. // information is sent to all online GMs
  9756. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9757. return;
  9758. }
  9759. */
  9760. clif_name(&sd->bl,bl,SELF);
  9761. }
  9762. /// Validates and processes global messages
  9763. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9764. /// There are various variants of this packet.
  9765. void clif_parse_GlobalMessage(int fd, map_session_data* sd)
  9766. {
  9767. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9768. size_t length;
  9769. // validate packet and retrieve name and message
  9770. if( !clif_process_message(sd, false, name, message, output ) )
  9771. return;
  9772. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9773. channel_send(sd->gcbind,sd,message);
  9774. return;
  9775. }
  9776. // send message to others (using the send buffer for temp. storage)
  9777. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9778. length = strlen(output) + 1;
  9779. // send back message to the speaker
  9780. WFIFOHEAD(fd,4+length);
  9781. WFIFOW(fd,0) = 0x8e;
  9782. WFIFOW(fd,2) = (uint16)(4+length);
  9783. safestrncpy(WFIFOCP(fd,4), output, length );
  9784. WFIFOSET(fd, WFIFOW(fd,2));
  9785. #ifdef PCRE_SUPPORT
  9786. // trigger listening npcs
  9787. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9788. #endif
  9789. // Chat logging type 'O' / Global Chat
  9790. log_chat(LOG_CHAT_GLOBAL, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  9791. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9792. }
  9793. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9794. /// Request to warp to a map on given coordinates.
  9795. /// 0140 <map name>.16B <x>.W <y>.W
  9796. void clif_parse_MapMove(int fd, map_session_data *sd)
  9797. {
  9798. char command[MAP_NAME_LENGTH_EXT+25];
  9799. char* map_name;
  9800. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9801. map_name = RFIFOCP(fd,info->pos[0]);
  9802. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9803. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9804. RFIFOW(fd,info->pos[1]), //x
  9805. RFIFOW(fd,info->pos[2])); //y
  9806. is_atcommand(fd, sd, command, 1);
  9807. }
  9808. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9809. /// 009c <id>.L <head dir>.W <dir>.B
  9810. /// head dir:
  9811. /// 0 = straight
  9812. /// 1 = turned CW
  9813. /// 2 = turned CCW
  9814. /// dir:
  9815. /// 0 = north
  9816. /// 1 = northwest
  9817. /// 2 = west
  9818. /// 3 = southwest
  9819. /// 4 = south
  9820. /// 5 = southeast
  9821. /// 6 = east
  9822. /// 7 = northeast
  9823. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9824. {
  9825. unsigned char buf[64];
  9826. WBUFW(buf,0) = 0x9c;
  9827. WBUFL(buf,2) = bl->id;
  9828. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9829. WBUFB(buf,8) = unit_getdir(bl);
  9830. clif_send(buf, packet_len(0x9c), bl, target);
  9831. if (disguised(bl)) {
  9832. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9833. WBUFW(buf,6) = 0;
  9834. clif_send(buf, packet_len(0x9c), bl, SELF);
  9835. }
  9836. }
  9837. /// Request to change own body and head direction.
  9838. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9839. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9840. /// There are various variants of this packet, some of them have padding between fields.
  9841. void clif_parse_ChangeDir(int fd, map_session_data *sd)
  9842. {
  9843. unsigned char headdir, dir;
  9844. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9845. headdir = RFIFOB(fd,info->pos[0]);
  9846. dir = RFIFOB(fd,info->pos[1]);
  9847. pc_setdir(sd, dir, headdir);
  9848. clif_changed_dir(&sd->bl, AREA_WOS);
  9849. }
  9850. /// Request to show an emotion (CZ_REQ_EMOTION).
  9851. /// 00bf <type>.B
  9852. /// type:
  9853. /// @see enum emotion_type
  9854. void clif_parse_Emotion(int fd, map_session_data *sd)
  9855. {
  9856. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9857. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9858. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9859. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9860. return;
  9861. }
  9862. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9863. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9864. sd->emotionlasttime = time(NULL);
  9865. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9866. return;
  9867. }
  9868. sd->emotionlasttime = time(NULL);
  9869. if (battle_config.idletime_option&IDLE_EMOTION)
  9870. sd->idletime = last_tick;
  9871. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9872. sd->idletime_hom = last_tick;
  9873. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9874. sd->idletime_mer = last_tick;
  9875. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9876. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9877. return;
  9878. }
  9879. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9880. emoticon = rnd()%6+ET_DICE1;
  9881. }
  9882. clif_emotion(&sd->bl, emoticon);
  9883. } else
  9884. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9885. }
  9886. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9887. /// 00c2 <count>.L
  9888. void clif_user_count(map_session_data* sd, int count)
  9889. {
  9890. int fd = sd->fd;
  9891. WFIFOHEAD(fd,packet_len(0xc2));
  9892. WFIFOW(fd,0) = 0xc2;
  9893. WFIFOL(fd,2) = count;
  9894. WFIFOSET(fd,packet_len(0xc2));
  9895. }
  9896. /// /w /who (CZ_REQ_USER_COUNT).
  9897. /// Request to display amount of currently connected players.
  9898. /// 00c1
  9899. void clif_parse_HowManyConnections(int fd, map_session_data *sd)
  9900. {
  9901. clif_user_count(sd, map_getusers());
  9902. }
  9903. void clif_parse_ActionRequest_sub(map_session_data *sd, int action_type, int target_id, t_tick tick)
  9904. {
  9905. if (pc_isdead(sd)) {
  9906. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9907. return;
  9908. }
  9909. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9910. if (action_type != 0x00 && action_type != 0x07) {
  9911. if (sd->sc.cant.interact)
  9912. return;
  9913. pc_stop_walking(sd, 1);
  9914. }
  9915. pc_stop_attack(sd);
  9916. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9917. target_id = sd->bl.id;
  9918. switch(action_type)
  9919. {
  9920. case 0x00: // once attack
  9921. case 0x07: // continuous attack
  9922. if( pc_cant_act(sd) )
  9923. return;
  9924. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9925. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9926. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9927. return;
  9928. }
  9929. }
  9930. pc_delinvincibletimer(sd);
  9931. if (battle_config.idletime_option&IDLE_ATTACK)
  9932. sd->idletime = last_tick;
  9933. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9934. sd->idletime_hom = last_tick;
  9935. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9936. sd->idletime_mer = last_tick;
  9937. unit_attack(&sd->bl, target_id, action_type != 0);
  9938. break;
  9939. case 0x02: // sitdown
  9940. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9941. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9942. break;
  9943. }
  9944. if(pc_issit(sd)) {
  9945. //Bugged client? Just refresh them.
  9946. clif_sitting(&sd->bl);
  9947. return;
  9948. }
  9949. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9950. break;
  9951. if (sd->sc.count && (
  9952. sd->sc.getSCE(SC_DANCING) ||
  9953. (sd->sc.getSCE(SC_GRAVITATION) && sd->sc.getSCE(SC_GRAVITATION)->val3 == BCT_SELF)
  9954. )) //No sitting during these states either.
  9955. break;
  9956. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9957. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9958. break;
  9959. }
  9960. if (battle_config.idletime_option&IDLE_SIT)
  9961. sd->idletime = last_tick;
  9962. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9963. sd->idletime_hom = last_tick;
  9964. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9965. sd->idletime_mer = last_tick;
  9966. pc_setsit(sd);
  9967. skill_sit(sd, true);
  9968. clif_sitting(&sd->bl);
  9969. break;
  9970. case 0x03: // standup
  9971. if (!pc_issit(sd)) {
  9972. //Bugged client? Just refresh them.
  9973. clif_standing(&sd->bl);
  9974. return;
  9975. }
  9976. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9977. break;
  9978. if (sd->state.block_action & PCBLOCK_SITSTAND) {
  9979. clif_displaymessage(sd->fd, msg_txt(sd,794)); // This action is currently blocked.
  9980. break;
  9981. }
  9982. if (pc_setstand(sd, false)) {
  9983. if (battle_config.idletime_option&IDLE_SIT)
  9984. sd->idletime = last_tick;
  9985. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_SIT)
  9986. sd->idletime_hom = last_tick;
  9987. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_SIT)
  9988. sd->idletime_mer = last_tick;
  9989. skill_sit(sd, false);
  9990. clif_standing(&sd->bl);
  9991. }
  9992. break;
  9993. }
  9994. }
  9995. /// Request for an action.
  9996. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9997. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9998. /// action:
  9999. /// 0 = attack
  10000. /// 1 = pick up item
  10001. /// 2 = sit down
  10002. /// 3 = stand up
  10003. /// 7 = continous attack
  10004. /// 12 = (touch skill?)
  10005. /// There are various variants of this packet, some of them have padding between fields.
  10006. void clif_parse_ActionRequest(int fd, map_session_data *sd)
  10007. {
  10008. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10009. clif_parse_ActionRequest_sub(sd,
  10010. RFIFOB(fd,info->pos[1]),
  10011. RFIFOL(fd,info->pos[0]),
  10012. gettick()
  10013. );
  10014. }
  10015. /// Response to the death/system menu (CZ_RESTART).
  10016. /// 00b2 <type>.B
  10017. /// type:
  10018. /// 0 = restart (respawn)
  10019. /// 1 = char-select (disconnect)
  10020. void clif_parse_Restart(int fd, map_session_data *sd)
  10021. {
  10022. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  10023. case 0x00:
  10024. pc_respawn(sd,CLR_OUTSIGHT);
  10025. break;
  10026. case 0x01:
  10027. /* Rovert's Prevent logout option - Fixed [Valaris] */
  10028. if( !sd->sc.getSCE(SC_CLOAKING) && !sd->sc.getSCE(SC_HIDING) && !sd->sc.getSCE(SC_CHASEWALK) && !sd->sc.getSCE(SC_CLOAKINGEXCEED) && !sd->sc.getSCE(SC_SUHIDE) && !sd->sc.getSCE(SC_NEWMOON) &&
  10029. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  10030. { //Send to char-server for character selection.
  10031. pc_damage_log_clear(sd,0);
  10032. chrif_charselectreq(sd, session[fd]->client_addr);
  10033. } else {
  10034. clif_disconnect_ack(sd, 1);
  10035. }
  10036. break;
  10037. }
  10038. }
  10039. /// Validates and processes whispered messages (CZ_WHISPER).
  10040. /// 0096 <packet len>.W <nick>.24B <message>.?B
  10041. void clif_parse_WisMessage(int fd, map_session_data* sd)
  10042. {
  10043. map_session_data* dstsd;
  10044. int i;
  10045. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  10046. // validate packet and retrieve name and message
  10047. if( !clif_process_message( sd, true, target, message, output ) )
  10048. return;
  10049. // Chat logging type 'W' / Whisper
  10050. log_chat(LOG_CHAT_WHISPER, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  10051. //-------------------------------------------------------//
  10052. // Lordalfa - Paperboy - To whisper NPC commands //
  10053. //-------------------------------------------------------//
  10054. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  10055. {
  10056. char* str = target+4; //Skip the NPC: string part.
  10057. struct npc_data* npc;
  10058. if ((npc = npc_name2id(str))) {
  10059. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  10060. char *split;
  10061. char event[EVENT_NAME_LENGTH];
  10062. str = message;
  10063. // skip codepage indicator, if detected
  10064. if( str[0] == '|' && strlen(str) >= 4 )
  10065. str += 3;
  10066. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  10067. split = strchr(str,'#');
  10068. if( split == NULL ) { // use the remaining string
  10069. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  10070. for( ++i; i < NUM_WHISPER_VAR; ++i )
  10071. split_data[i][0] = '\0';
  10072. break;
  10073. }
  10074. *split = '\0';
  10075. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  10076. str = split+1;
  10077. }
  10078. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  10079. char variablename[CHAT_SIZE_MAX];
  10080. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  10081. set_var_str( sd, variablename, split_data[i] );
  10082. }
  10083. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  10084. npc_event(sd,event,0); // Calls the NPC label
  10085. return;
  10086. }
  10087. } else if( target[0] == '#' ) {
  10088. struct Channel *channel = NULL;
  10089. char* chname = target;
  10090. channel = channel_name2channel(chname,sd,3);
  10091. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  10092. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  10093. channel_send(channel,sd,message);
  10094. }
  10095. else if( channel->pass[0] == '\0') { //no pass needed
  10096. if (channel_join(channel,sd)==0)
  10097. channel_send(channel,sd,message); //join success
  10098. }
  10099. else {
  10100. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  10101. }
  10102. return;
  10103. }
  10104. }
  10105. // searching destination character
  10106. dstsd = map_nick2sd(target,false);
  10107. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  10108. // player is not on this map-server
  10109. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  10110. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  10111. // and if we ask for 'Test', we must not contact 'test' player
  10112. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  10113. intif_wis_message(sd, target, message, strlen(message) + 1);
  10114. return;
  10115. }
  10116. // if player ignores everyone
  10117. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10118. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  10119. clif_wis_end(fd, 1); // 1: target character is not logged in
  10120. else
  10121. clif_wis_end(fd, 3); // 3: everyone ignored by target
  10122. return;
  10123. }
  10124. // if player is autotrading
  10125. if (dstsd->state.autotrade == 1){
  10126. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  10127. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  10128. return;
  10129. }
  10130. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  10131. // if player ignores the source character
  10132. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  10133. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  10134. clif_wis_end(fd, 2); // 2: ignored by target
  10135. return;
  10136. }
  10137. }
  10138. // notify sender of success
  10139. clif_wis_end(fd, 0); // 0: success to send wisper
  10140. // Normal message
  10141. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  10142. }
  10143. /// /b /nb (CZ_BROADCAST).
  10144. /// Request to broadcast a message on whole server.
  10145. /// 0099 <packet len>.W <text>.?B 00
  10146. void clif_parse_Broadcast(int fd, map_session_data* sd) {
  10147. char command[CHAT_SIZE_MAX+11];
  10148. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10149. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10150. char* msg = RFIFOCP(fd,info->pos[1]);
  10151. // as the length varies depending on the command used, just block unreasonably long strings
  10152. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10153. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  10154. is_atcommand(fd, sd, command, 1);
  10155. }
  10156. /// Request to pick up an item.
  10157. /// 009f <id>.L (CZ_ITEM_PICKUP)
  10158. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  10159. /// There are various variants of this packet, some of them have padding between fields.
  10160. void clif_parse_TakeItem(int fd, map_session_data *sd)
  10161. {
  10162. struct flooritem_data *fitem;
  10163. int map_object_id;
  10164. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10165. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  10166. do {
  10167. if (pc_isdead(sd)) {
  10168. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10169. break;
  10170. }
  10171. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  10172. break;
  10173. if (pc_cant_act(sd))
  10174. break;
  10175. if (!pc_takeitem(sd, fitem))
  10176. break;
  10177. return;
  10178. } while (0);
  10179. // Client REQUIRES a fail packet or you can no longer pick items.
  10180. clif_additem(sd,0,0,6);
  10181. }
  10182. /// Request to drop an item.
  10183. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  10184. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  10185. /// There are various variants of this packet, some of them have padding between fields.
  10186. void clif_parse_DropItem(int fd, map_session_data *sd){
  10187. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10188. int item_index = RFIFOW(fd,info->pos[0]) -2;
  10189. int item_amount = RFIFOW(fd,info->pos[1]) ;
  10190. for(;;) {
  10191. if (pc_isdead(sd))
  10192. break;
  10193. if (pc_cant_act2(sd) || sd->npc_id)
  10194. break;
  10195. if (sd->sc.cant.drop)
  10196. break;
  10197. if (!pc_dropitem(sd, item_index, item_amount))
  10198. break;
  10199. if (battle_config.idletime_option&IDLE_DROPITEM)
  10200. sd->idletime = last_tick;
  10201. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  10202. sd->idletime_hom = last_tick;
  10203. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  10204. sd->idletime_mer = last_tick;
  10205. return;
  10206. }
  10207. //Because the client does not like being ignored.
  10208. clif_dropitem(sd, item_index,0);
  10209. }
  10210. /// Request to use an item.
  10211. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  10212. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  10213. /// There are various variants of this packet, some of them have padding between fields.
  10214. void clif_parse_UseItem(int fd, map_session_data *sd)
  10215. {
  10216. int n;
  10217. if (pc_isdead(sd)) {
  10218. clif_clearunit_area(&sd->bl, CLR_DEAD);
  10219. return;
  10220. }
  10221. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  10222. clif_msg(sd, WORK_IN_PROGRESS);
  10223. return;
  10224. }
  10225. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  10226. if (battle_config.idletime_option&IDLE_USEITEM)
  10227. sd->idletime = last_tick;
  10228. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10229. sd->idletime_hom = last_tick;
  10230. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10231. sd->idletime_mer = last_tick;
  10232. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10233. if(n <0 || n >= MAX_INVENTORY)
  10234. return;
  10235. if (!pc_useitem(sd,n))
  10236. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10237. }
  10238. /// Request to equip an item
  10239. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10240. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10241. void clif_parse_EquipItem(int fd,map_session_data *sd)
  10242. {
  10243. int index;
  10244. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10245. if(pc_isdead(sd)) {
  10246. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10247. return;
  10248. }
  10249. index = RFIFOW(fd,info->pos[0])-2;
  10250. if (index < 0 || index >= MAX_INVENTORY)
  10251. return; //Out of bounds check.
  10252. if(sd->npc_id && !sd->npc_item_flag) {
  10253. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10254. return;
  10255. } else if (sd->state.storage_flag || sd->sc.opt1)
  10256. ; //You can equip/unequip stuff while storage is open/under status changes
  10257. else if (pc_cant_act2(sd))
  10258. return;
  10259. if(!sd->inventory.u.items_inventory[index].identify) {
  10260. clif_equipitemack( *sd, ITEM_EQUIP_ACK_FAIL, index ); // fail
  10261. return;
  10262. }
  10263. if(!sd->inventory_data[index])
  10264. return;
  10265. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10266. pet_equipitem(sd,index);
  10267. return;
  10268. }
  10269. if (battle_config.idletime_option&IDLE_USEITEM)
  10270. sd->idletime = last_tick;
  10271. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10272. sd->idletime_hom = last_tick;
  10273. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10274. sd->idletime_mer = last_tick;
  10275. //Client doesn't send the position for ammo.
  10276. if(sd->inventory_data[index]->type == IT_AMMO)
  10277. pc_equipitem(sd,index,EQP_AMMO);
  10278. else {
  10279. int req_pos;
  10280. #if PACKETVER >= 20120925
  10281. req_pos = RFIFOL(fd,info->pos[1]);
  10282. #else
  10283. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10284. #endif
  10285. pc_equipitem(sd,index,req_pos);
  10286. }
  10287. }
  10288. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10289. /// 00ab <index>.W
  10290. void clif_parse_UnequipItem(int fd,map_session_data *sd)
  10291. {
  10292. int index;
  10293. if(pc_isdead(sd)) {
  10294. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10295. return;
  10296. }
  10297. if (sd->npc_id && !sd->npc_item_flag) {
  10298. clif_msg_color( sd, C_ITEM_NOEQUIP, color_table[COLOR_RED] );
  10299. return;
  10300. } else if (sd->state.storage_flag || sd->sc.opt1)
  10301. ; //You can equip/unequip stuff while storage is open/under status changes
  10302. else if (pc_cant_act2(sd))
  10303. return;
  10304. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10305. if (battle_config.idletime_option&IDLE_USEITEM)
  10306. sd->idletime = last_tick;
  10307. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10308. sd->idletime_hom = last_tick;
  10309. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10310. sd->idletime_mer = last_tick;
  10311. pc_unequipitem(sd,index,1);
  10312. }
  10313. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10314. /// 0090 <id>.L <type>.B
  10315. /// type:
  10316. /// 1 = click
  10317. void clif_parse_NpcClicked(int fd,map_session_data *sd)
  10318. {
  10319. struct block_list *bl;
  10320. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10321. if(pc_isdead(sd)) {
  10322. clif_clearunit_area(&sd->bl,CLR_DEAD);
  10323. return;
  10324. }
  10325. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10326. #ifdef RENEWAL
  10327. clif_msg( sd, WORK_IN_PROGRESS );
  10328. #endif
  10329. return;
  10330. }
  10331. if( sd->state.mail_writing )
  10332. return;
  10333. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10334. //type = RFIFOB(fd,info->pos[1]);
  10335. if (!bl) return;
  10336. switch (bl->type) {
  10337. case BL_MOB:
  10338. case BL_PC:
  10339. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  10340. break;
  10341. case BL_NPC:
  10342. #ifdef RENEWAL
  10343. if (sd->ud.skill_id < RK_ENCHANTBLADE && sd->ud.skilltimer != INVALID_TIMER) { // Should only show an error message for non-3rd job skills with a running timer
  10344. clif_msg(sd, WORK_IN_PROGRESS);
  10345. break;
  10346. }
  10347. #endif
  10348. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10349. struct npc_data* nd = (struct npc_data*)bl;
  10350. // Progressbar is running
  10351. if( nd->progressbar.timeout > 0 ){
  10352. return;
  10353. }
  10354. npc_click(sd,nd);
  10355. }
  10356. break;
  10357. }
  10358. }
  10359. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10360. /// 00c5 <id>.L <type>.B
  10361. /// type:
  10362. /// 0 = buy
  10363. /// 1 = sell
  10364. void clif_parse_NpcBuySellSelected(int fd,map_session_data *sd)
  10365. {
  10366. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10367. if (sd->state.trading)
  10368. return;
  10369. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10370. }
  10371. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10372. /// 00ca <result>.B
  10373. /// result:
  10374. /// 0 = "The deal has successfully completed."
  10375. /// 1 = "You do not have enough zeny."
  10376. /// 2 = "You are over your Weight Limit."
  10377. /// 3 = "Out of the maximum capacity, you have too many items."
  10378. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10379. /// 10 = "Props open-air store sales will be traded in RODEX"
  10380. /// 11 = "The exchange failed."
  10381. /// 12 = "The exchange was well done."
  10382. /// 13 = "The item is already sold and out of stock."
  10383. /// 14 = "There is not enough goods to exchange."
  10384. void clif_npc_buy_result( map_session_data* sd, e_purchase_result result ){
  10385. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10386. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10387. p.result = (uint8)result;
  10388. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10389. }
  10390. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10391. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10392. void clif_parse_NpcBuyListSend( int fd, map_session_data* sd ){
  10393. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10394. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10395. e_purchase_result result;
  10396. if( sd->state.trading || !sd->npc_shopid )
  10397. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10398. else{
  10399. std::vector<s_npc_buy_list> items = {};
  10400. items.reserve( n );
  10401. for( uint16 i = 0; i < n; i++ ){
  10402. s_npc_buy_list item = {};
  10403. item.nameid = p->items[i].itemId;
  10404. item.qty = p->items[i].amount;
  10405. items.push_back( item );
  10406. }
  10407. result = npc_buylist( sd, items );
  10408. }
  10409. sd->npc_shopid = 0; //Clear shop data.
  10410. clif_npc_buy_result(sd, result);
  10411. }
  10412. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10413. /// 00cb <result>.B
  10414. /// result:
  10415. /// 0 = "The deal has successfully completed."
  10416. /// 1 = "The deal has failed."
  10417. void clif_npc_sell_result(map_session_data* sd, unsigned char result)
  10418. {
  10419. int fd = sd->fd;
  10420. WFIFOHEAD(fd,packet_len(0xcb));
  10421. WFIFOW(fd,0) = 0xcb;
  10422. WFIFOB(fd,2) = result;
  10423. WFIFOSET(fd,packet_len(0xcb));
  10424. }
  10425. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10426. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10427. void clif_parse_NpcSellListSend(int fd,map_session_data *sd)
  10428. {
  10429. int fail=0,n;
  10430. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10431. PACKET_CZ_PC_SELL_ITEMLIST* p = reinterpret_cast<PACKET_CZ_PC_SELL_ITEMLIST*>(RFIFOP(fd, 0));
  10432. n = (p->packetLength - 4) / sizeof(PACKET_CZ_PC_SELL_ITEMLIST_sub); // (pktlen-(cmd+len))/listsize
  10433. if (sd->state.trading || !sd->npc_shopid)
  10434. fail = 1;
  10435. else
  10436. fail = npc_selllist(sd, n, p->sellList);
  10437. sd->npc_shopid = 0; //Clear shop data.
  10438. clif_npc_sell_result(sd, fail);
  10439. }
  10440. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10441. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10442. /// type:
  10443. /// 0 = private
  10444. /// 1 = public
  10445. void clif_parse_CreateChatRoom(int fd, map_session_data* sd)
  10446. {
  10447. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10448. int len = RFIFOW(fd,info->pos[0])-15;
  10449. int limit = RFIFOW(fd,info->pos[1]);
  10450. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10451. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10452. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10453. char s_password[CHATROOM_PASS_SIZE];
  10454. char s_title[CHATROOM_TITLE_SIZE];
  10455. if (sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM)
  10456. return;
  10457. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10458. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10459. return;
  10460. }
  10461. if( npc_isnear(&sd->bl) ) {
  10462. // uncomment to send msg_txt.
  10463. //char output[150];
  10464. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10465. //clif_displaymessage(sd->fd, output);
  10466. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10467. return;
  10468. }
  10469. if( len <= 0 )
  10470. return; // invalid input
  10471. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10472. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10473. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10474. }
  10475. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10476. /// 00d9 <chat ID>.L <passwd>.8B
  10477. void clif_parse_ChatAddMember(int fd, map_session_data* sd){
  10478. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10479. int chatid = RFIFOL(fd,info->pos[0]);
  10480. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10481. chat_joinchat(sd,chatid,password);
  10482. }
  10483. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10484. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10485. /// type:
  10486. /// 0 = private
  10487. /// 1 = public
  10488. void clif_parse_ChatRoomStatusChange(int fd, map_session_data* sd){
  10489. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10490. int len = RFIFOW(fd,info->pos[0])-15;
  10491. int limit = RFIFOW(fd,info->pos[1]);
  10492. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10493. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10494. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10495. char s_password[CHATROOM_PASS_SIZE];
  10496. char s_title[CHATROOM_TITLE_SIZE];
  10497. if( len <= 0 )
  10498. return; // invalid input
  10499. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10500. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10501. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10502. }
  10503. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10504. /// 00e0 <role>.L <nick>.24B
  10505. /// role:
  10506. /// 0 = owner
  10507. /// 1 = normal
  10508. void clif_parse_ChangeChatOwner(int fd, map_session_data* sd)
  10509. {
  10510. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10511. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10512. }
  10513. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10514. /// 00e2 <name>.24B
  10515. void clif_parse_KickFromChat(int fd,map_session_data *sd)
  10516. {
  10517. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10518. }
  10519. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10520. /// 00e3
  10521. void clif_parse_ChatLeave(int fd, map_session_data* sd)
  10522. {
  10523. chat_leavechat(sd,0);
  10524. }
  10525. //Handles notifying asker and rejecter of what has just ocurred.
  10526. //Type is used to determine the correct msg_txt to use:
  10527. //0:
  10528. static void clif_noask_sub(map_session_data *sd, map_session_data *tsd, int type)
  10529. {
  10530. const char* msg;
  10531. char output[256];
  10532. // Your request has been rejected by autoreject option.
  10533. msg = msg_txt(sd,392);
  10534. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10535. //Notice that a request was rejected.
  10536. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10537. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10538. }
  10539. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10540. /// 00e4 <account id>.L
  10541. void clif_parse_TradeRequest(int fd,map_session_data *sd)
  10542. {
  10543. map_session_data *t_sd;
  10544. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10545. if(!sd->chatID && pc_cant_act(sd))
  10546. return; //You can trade while in a chatroom.
  10547. if(t_sd){
  10548. // @noask [LuzZza]
  10549. if(t_sd->state.noask) {
  10550. clif_noask_sub(sd, t_sd, 0);
  10551. return;
  10552. }
  10553. if (t_sd->state.mail_writing) {
  10554. int old = sd->trade_partner;
  10555. // Fake trading
  10556. sd->trade_partner = t_sd->status.account_id;
  10557. clif_tradestart(sd, 5);
  10558. // Restore old state
  10559. sd->trade_partner = old;
  10560. return;
  10561. }
  10562. }
  10563. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10564. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10565. return;
  10566. }
  10567. trade_traderequest(sd,t_sd);
  10568. }
  10569. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10570. /// 00e6 <result>.B
  10571. /// result:
  10572. /// 3 = accepted
  10573. /// 4 = rejected
  10574. void clif_parse_TradeAck(int fd,map_session_data *sd)
  10575. {
  10576. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10577. }
  10578. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10579. /// 00e8 <index>.W <amount>.L
  10580. void clif_parse_TradeAddItem(int fd,map_session_data *sd)
  10581. {
  10582. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10583. short index = RFIFOW(fd,info->pos[0]);
  10584. int amount = RFIFOL(fd,info->pos[1]);
  10585. if( index == 0 )
  10586. trade_tradeaddzeny(sd, amount);
  10587. else
  10588. trade_tradeadditem(sd, server_index(index), (short)amount);
  10589. }
  10590. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10591. /// 00eb
  10592. void clif_parse_TradeOk(int fd,map_session_data *sd)
  10593. {
  10594. trade_tradeok(sd);
  10595. }
  10596. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10597. /// 00ed
  10598. void clif_parse_TradeCancel(int fd,map_session_data *sd)
  10599. {
  10600. trade_tradecancel(sd);
  10601. }
  10602. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10603. /// 00ef
  10604. void clif_parse_TradeCommit(int fd,map_session_data *sd)
  10605. {
  10606. trade_tradecommit(sd);
  10607. }
  10608. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10609. /// 0118
  10610. void clif_parse_StopAttack(int fd,map_session_data *sd)
  10611. {
  10612. pc_stop_attack(sd);
  10613. if (sd) sd->ud.state.attack_continue = 0;
  10614. }
  10615. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10616. /// 0126 <index>.W <amount>.L
  10617. void clif_parse_PutItemToCart( int fd, map_session_data *sd ){
  10618. if (pc_istrading(sd) || !pc_iscarton(sd) || pc_cant_act2(sd))
  10619. return;
  10620. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10621. return;
  10622. struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART* p = (struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART*)RFIFOP( fd, 0 );
  10623. pc_putitemtocart( sd, server_index( p->index ), p->count);
  10624. }
  10625. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10626. /// 0127 <index>.W <amount>.L
  10627. void clif_parse_GetItemFromCart(int fd,map_session_data *sd)
  10628. {
  10629. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10630. if (!pc_iscarton(sd) || pc_cant_act2(sd))
  10631. return;
  10632. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10633. return;
  10634. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10635. }
  10636. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10637. /// 012a
  10638. void clif_parse_RemoveOption(int fd,map_session_data *sd)
  10639. {
  10640. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10641. #ifdef NEW_CARTS
  10642. && sd->sc.getSCE(SC_PUSH_CART) )
  10643. pc_setcart(sd,0);
  10644. #else
  10645. )
  10646. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10647. #endif
  10648. else // priority to remove this option before we can clear cart
  10649. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10650. }
  10651. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10652. /// 097f <Length>.W <identity>.L <type>.B
  10653. void clif_SelectCart(map_session_data *sd) {
  10654. #if PACKETVER >= 20150826
  10655. int i = 0, carts = 3;
  10656. int fd = sd->fd;
  10657. WFIFOHEAD(fd,8 + carts);
  10658. WFIFOW(fd,0) = 0x97f;
  10659. WFIFOW(fd,2) = 8 + carts;
  10660. WFIFOL(fd,4) = sd->status.account_id;
  10661. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10662. for( i = 0; i < carts; i++ ) {
  10663. WFIFOB(fd,8 + i) = 10 + i;
  10664. }
  10665. WFIFOSET(fd,8 + carts);
  10666. #endif
  10667. }
  10668. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10669. /// 0980 <identity>.L <type>.B
  10670. void clif_parse_SelectCart(int fd,map_session_data *sd) {
  10671. #if PACKETVER >= 20150826
  10672. int type;
  10673. // Check identity
  10674. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10675. return;
  10676. type = (int)RFIFOB(fd,6);
  10677. // Check type
  10678. if( type < 10 || type > 12 )
  10679. return;
  10680. pc_setcart(sd, type);
  10681. #endif
  10682. }
  10683. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10684. /// 01af <num>.W
  10685. void clif_parse_ChangeCart(int fd,map_session_data *sd)
  10686. {// TODO: State tracking?
  10687. int type;
  10688. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10689. return;
  10690. #ifdef RENEWAL
  10691. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10692. clif_msg(sd, WORK_IN_PROGRESS);
  10693. return;
  10694. }
  10695. #endif
  10696. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10697. if(
  10698. #ifdef NEW_CARTS
  10699. #if PACKETVER >= 20191106
  10700. (type == 13 && sd->status.base_level > 100) ||
  10701. #endif
  10702. (type == 9 && sd->status.base_level > 130) ||
  10703. (type == 8 && sd->status.base_level > 120) ||
  10704. (type == 7 && sd->status.base_level > 110) ||
  10705. (type == 6 && sd->status.base_level > 100) ||
  10706. #endif
  10707. (type == 5 && sd->status.base_level > 90) ||
  10708. (type == 4 && sd->status.base_level > 80) ||
  10709. (type == 3 && sd->status.base_level > 65) ||
  10710. (type == 2 && sd->status.base_level > 40) ||
  10711. (type == 1))
  10712. pc_setcart(sd, type);
  10713. }
  10714. /// Request to increase status (CZ_STATUS_CHANGE).
  10715. /// 00bb <status id>.W <amount>.B
  10716. /// status id:
  10717. /// SP_STR ~ SP_LUK
  10718. /// amount:
  10719. /// Old clients always send 1 for this, even when using /str+ and the like.
  10720. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10721. void clif_parse_StatusUp(int fd,map_session_data *sd)
  10722. {
  10723. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10724. if( increase_amount < 0 ) {
  10725. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10726. fd, increase_amount);
  10727. }
  10728. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10729. }
  10730. /// Request to increase trait status.
  10731. /// 0b24 <status id>.W <amount>.W
  10732. /// status id:
  10733. /// SP_POW ~ SP_CON
  10734. /// amount:
  10735. /// The amount to increase the trait status
  10736. void clif_parse_traitstatus_up( int fd, map_session_data *sd ){
  10737. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10738. struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP* p = (struct PACKET_CZ_UNCONFIRMED_TSTATUS_UP*)RFIFOP( fd, 0 );
  10739. if( p->amount < 0 ){
  10740. ShowDebug( "clif_parse_traitstatus_up: Negative 'increase' value sent by client! %s (AID: %d, CID: %d, value: %d)\n", sd->status.name, sd->status.account_id, sd->status.char_id, p->amount );
  10741. return;
  10742. }
  10743. pc_traitstatusup( sd, p->type, p->amount );
  10744. #endif
  10745. }
  10746. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10747. /// 0112 <skill id>.W
  10748. void clif_parse_SkillUp(int fd,map_session_data *sd)
  10749. {
  10750. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10751. }
  10752. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10753. {
  10754. int lv;
  10755. if( !hd )
  10756. return;
  10757. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10758. clif_emotion(&hd->bl, ET_THINK);
  10759. return;
  10760. }
  10761. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10762. target_id = hd->bl.id;
  10763. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10764. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10765. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10766. clif_emotion(&hd->bl, ET_THINK);
  10767. if (hd->master)
  10768. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10769. return;
  10770. }
  10771. lv = hom_checkskill(hd, skill_id);
  10772. if( skill_lv > lv )
  10773. skill_lv = lv;
  10774. if( skill_lv )
  10775. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10776. }
  10777. static void clif_parse_UseSkillToPos_homun(struct homun_data *hd, map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10778. {
  10779. int lv;
  10780. if( !hd )
  10781. return;
  10782. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10783. clif_emotion(&hd->bl, ET_THINK);
  10784. return;
  10785. }
  10786. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10787. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10788. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10789. clif_emotion(&hd->bl, ET_THINK);
  10790. if (hd->master)
  10791. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10792. return;
  10793. }
  10794. #ifdef RENEWAL
  10795. if (hd->sc.getSCE(SC_BASILICA_CELL))
  10796. #else
  10797. if (hd->sc.getSCE(SC_BASILICA))
  10798. #endif
  10799. return;
  10800. lv = hom_checkskill(hd, skill_id);
  10801. if( skill_lv > lv )
  10802. skill_lv = lv;
  10803. if( skill_lv )
  10804. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10805. }
  10806. static void clif_parse_UseSkillToId_mercenary(s_mercenary_data *md, map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10807. {
  10808. int lv;
  10809. if( !md )
  10810. return;
  10811. if( skill_isNotOk_mercenary(skill_id, md) )
  10812. return;
  10813. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10814. target_id = md->bl.id;
  10815. if( md->ud.skilltimer != INVALID_TIMER )
  10816. {
  10817. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10818. }
  10819. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10820. return;
  10821. lv = mercenary_checkskill(md, skill_id);
  10822. if( skill_lv > lv )
  10823. skill_lv = lv;
  10824. if( skill_lv )
  10825. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10826. }
  10827. static void clif_parse_UseSkillToPos_mercenary(s_mercenary_data *md, map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10828. {
  10829. int lv;
  10830. if( !md )
  10831. return;
  10832. if( skill_isNotOk_mercenary(skill_id, md) )
  10833. return;
  10834. if( md->ud.skilltimer != INVALID_TIMER )
  10835. return;
  10836. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10837. {
  10838. if (md->master)
  10839. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10840. return;
  10841. }
  10842. #ifdef RENEWAL
  10843. if (md->sc.getSCE(SC_BASILICA_CELL))
  10844. #else
  10845. if (md->sc.getSCE(SC_BASILICA))
  10846. #endif
  10847. return;
  10848. lv = mercenary_checkskill(md, skill_id);
  10849. if( skill_lv > lv )
  10850. skill_lv = lv;
  10851. if( skill_lv )
  10852. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10853. }
  10854. void clif_parse_skill_toid( map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10855. t_tick tick = gettick();
  10856. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10857. int inf = skill_get_inf(skill_id);
  10858. if (inf&INF_GROUND_SKILL || !inf)
  10859. return; //Using a ground/passive skill on a target? WRONG.
  10860. if (sd->state.block_action & PCBLOCK_SKILL) {
  10861. clif_msg(sd, WORK_IN_PROGRESS);
  10862. return;
  10863. }
  10864. if( SKILL_CHK_HOMUN(skill_id) ) {
  10865. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10866. return;
  10867. }
  10868. if( SKILL_CHK_MERC(skill_id) ) {
  10869. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10870. return;
  10871. }
  10872. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10873. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10874. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10875. sd->idletime = last_tick;
  10876. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10877. sd->idletime_hom = last_tick;
  10878. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10879. sd->idletime_mer = last_tick;
  10880. if( sd->npc_id ){
  10881. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10882. #ifdef RENEWAL
  10883. clif_msg( sd, WORK_IN_PROGRESS );
  10884. #endif
  10885. return;
  10886. }
  10887. }
  10888. if ((pc_cant_act2(sd) || sd->chatID) &&
  10889. skill_id != RK_REFRESH &&
  10890. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10891. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10892. return;
  10893. if( pc_issit(sd) )
  10894. return;
  10895. if( skill_isNotOk(skill_id, sd) )
  10896. return;
  10897. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10898. target_id = sd->bl.id; // never trust the client
  10899. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10900. target_id = sd->bl.id;
  10901. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10902. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10903. return;
  10904. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10905. if( sd->skillitem != skill_id ) {
  10906. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10907. return;
  10908. }
  10909. }
  10910. if( sd->sc.option&OPTION_COSTUME )
  10911. return;
  10912. #ifndef RENEWAL
  10913. if( sd->sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd->sc.getSCE(SC_BASILICA)->val4 != sd->bl.id) )
  10914. return; // On basilica only caster can use Basilica again to stop it.
  10915. #endif
  10916. if( sd->menuskill_id ) {
  10917. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10918. clif_menuskill_clear(sd); //Cancel pet capture.
  10919. }else if( sd->menuskill_id == SG_FEEL ){
  10920. clif_menuskill_clear( sd ); // Cancel selection
  10921. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10922. return; //Can't use skills while a menu is open.
  10923. }
  10924. if( sd->skillitem == skill_id ) {
  10925. if( skill_lv != sd->skillitemlv )
  10926. skill_lv = sd->skillitemlv;
  10927. if( !(inf&INF_SELF_SKILL) )
  10928. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10929. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10930. return;
  10931. }
  10932. sd->skillitem = sd->skillitemlv = 0;
  10933. if( SKILL_CHK_GUILD(skill_id) ) {
  10934. if (sd->guild && sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING)
  10935. skill_lv = guild_checkskill(sd->guild->guild, skill_id);
  10936. else
  10937. skill_lv = 0;
  10938. } else {
  10939. if( skill_id != ALL_EQSWITCH ){
  10940. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10941. }
  10942. }
  10943. pc_delinvincibletimer(sd);
  10944. if( skill_lv )
  10945. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10946. }
  10947. /// Request to use a targeted skill.
  10948. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10949. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10950. /// There are various variants of this packet, some of them have padding between fields.
  10951. void clif_parse_UseSkillToId( int fd, map_session_data *sd ){
  10952. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10953. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10954. }
  10955. /*==========================================
  10956. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10957. *------------------------------------------*/
  10958. static void clif_parse_UseSkillToPosSub(int fd, map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10959. {
  10960. t_tick tick = gettick();
  10961. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10962. return; //Using a target skill on the ground? WRONG.
  10963. if (sd->state.block_action & PCBLOCK_SKILL) {
  10964. clif_msg(sd, WORK_IN_PROGRESS);
  10965. return;
  10966. }
  10967. if( SKILL_CHK_HOMUN(skill_id) ) {
  10968. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10969. return;
  10970. }
  10971. if( SKILL_CHK_MERC(skill_id) ) {
  10972. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10973. return;
  10974. }
  10975. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10976. #ifdef RENEWAL
  10977. clif_msg( sd, WORK_IN_PROGRESS );
  10978. #endif
  10979. return;
  10980. }
  10981. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10982. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10983. sd->idletime = last_tick;
  10984. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10985. sd->idletime_hom = last_tick;
  10986. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10987. sd->idletime_mer = last_tick;
  10988. if( skill_isNotOk(skill_id, sd) )
  10989. return;
  10990. if( skillmoreinfo != -1 ) {
  10991. if( pc_issit(sd) ) {
  10992. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10993. return;
  10994. }
  10995. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10996. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10997. }
  10998. if( sd->ud.skilltimer != INVALID_TIMER )
  10999. return;
  11000. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  11001. if( sd->skillitem != skill_id ) {
  11002. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  11003. return;
  11004. }
  11005. }
  11006. if( sd->sc.option&OPTION_COSTUME )
  11007. return;
  11008. #ifndef RENEWAL
  11009. if( sd->sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd->sc.getSCE(SC_BASILICA)->val4 != sd->bl.id) )
  11010. return; // On basilica only caster can use Basilica again to stop it.
  11011. #endif
  11012. if( sd->menuskill_id ) {
  11013. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  11014. clif_menuskill_clear(sd); //Cancel pet capture.
  11015. }else if( sd->menuskill_id == SG_FEEL ){
  11016. clif_menuskill_clear( sd ); // Cancel selection
  11017. } else if( sd->menuskill_id != SA_AUTOSPELL )
  11018. return; //Can't use skills while a menu is open.
  11019. }
  11020. pc_delinvincibletimer(sd);
  11021. if( sd->skillitem == skill_id ) {
  11022. if( skill_lv != sd->skillitemlv )
  11023. skill_lv = sd->skillitemlv;
  11024. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  11025. } else {
  11026. int lv;
  11027. sd->skillitem = sd->skillitemlv = 0;
  11028. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  11029. if( skill_lv > lv )
  11030. skill_lv = lv;
  11031. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  11032. }
  11033. }
  11034. }
  11035. /// Request to use a ground skill.
  11036. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  11037. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  11038. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  11039. /// There are various variants of this packet, some of them have padding between fields.
  11040. void clif_parse_UseSkillToPos(int fd, map_session_data *sd)
  11041. {
  11042. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11043. if (pc_cant_act(sd))
  11044. return;
  11045. if (pc_issit(sd))
  11046. return;
  11047. clif_parse_UseSkillToPosSub(fd, sd,
  11048. RFIFOW(fd,info->pos[0]), //skill lv
  11049. RFIFOW(fd,info->pos[1]), //skill num
  11050. RFIFOW(fd,info->pos[2]), //pos x
  11051. RFIFOW(fd,info->pos[3]), //pos y
  11052. // TODO: find out what this is intended to do
  11053. //RFIFOB(fd, info->pos[4])
  11054. -1 //Skill more info.
  11055. );
  11056. }
  11057. /// Request to use a ground skill with text.
  11058. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  11059. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  11060. /// There are various variants of this packet, some of them have padding between fields.
  11061. void clif_parse_UseSkillToPosMoreInfo(int fd, map_session_data *sd)
  11062. {
  11063. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11064. if (pc_cant_act(sd))
  11065. return;
  11066. if (pc_issit(sd))
  11067. return;
  11068. clif_parse_UseSkillToPosSub(fd, sd,
  11069. RFIFOW(fd,info->pos[0]), //Skill lv
  11070. RFIFOW(fd,info->pos[1]), //Skill num
  11071. RFIFOW(fd,info->pos[2]), //pos x
  11072. RFIFOW(fd,info->pos[3]), //pos y
  11073. info->pos[4] //skill more info
  11074. );
  11075. }
  11076. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  11077. /// 011b <skill id>.W <map name>.16B
  11078. void clif_parse_UseSkillMap(int fd, map_session_data* sd)
  11079. {
  11080. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11081. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  11082. char map_name[MAP_NAME_LENGTH];
  11083. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  11084. sd->state.workinprogress = WIP_DISABLE_NONE;
  11085. if(skill_id != sd->menuskill_id)
  11086. return;
  11087. //It is possible to use teleport with the storage window open bugreport:8027
  11088. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  11089. clif_menuskill_clear(sd);
  11090. return;
  11091. }
  11092. pc_delinvincibletimer(sd);
  11093. skill_castend_map(sd,skill_id,map_name);
  11094. }
  11095. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  11096. /// 011d
  11097. void clif_parse_RequestMemo(int fd,map_session_data *sd)
  11098. {
  11099. if (!pc_isdead(sd))
  11100. pc_memo(sd,-1);
  11101. }
  11102. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  11103. /// 018e <name id>.W { <material id>.W }*3
  11104. void clif_parse_ProduceMix(int fd,map_session_data *sd){
  11105. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  11106. switch( sd->menuskill_id ) {
  11107. case -1:
  11108. case AM_PHARMACY:
  11109. case RK_RUNEMASTERY:
  11110. case GC_RESEARCHNEWPOISON:
  11111. break;
  11112. default:
  11113. return;
  11114. }
  11115. if (pc_istrading(sd)) {
  11116. //Make it fail to avoid shop exploits where you sell something different than you see.
  11117. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11118. clif_menuskill_clear(sd);
  11119. return;
  11120. }
  11121. int produce_idx;
  11122. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  11123. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  11124. clif_menuskill_clear(sd);
  11125. }
  11126. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  11127. /// 025b <mk type>.W <name id>.W
  11128. /// mk type:
  11129. /// 1 = cooking
  11130. /// 2 = arrow
  11131. /// 3 = elemental
  11132. /// 4 = GN_MIX_COOKING
  11133. /// 5 = GN_MAKEBOMB
  11134. /// 6 = GN_S_PHARMACY
  11135. /// 7 = MT_M_MACHINE - Unconfirmed
  11136. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  11137. void clif_parse_Cooking(int fd,map_session_data *sd) {
  11138. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  11139. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  11140. short food_idx = -1;
  11141. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  11142. return;
  11143. if (pc_istrading(sd)) {
  11144. //Make it fail to avoid shop exploits where you sell something different than you see.
  11145. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11146. clif_menuskill_clear(sd);
  11147. return;
  11148. }
  11149. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  11150. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  11151. clif_menuskill_clear(sd);
  11152. }
  11153. /// Answer to repair weapon item selection dialog
  11154. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  11155. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  11156. void clif_parse_RepairItem( int fd, map_session_data *sd ){
  11157. // Hercules has wrong date -> use correct one here
  11158. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  11159. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  11160. #else
  11161. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  11162. #endif
  11163. if (sd->menuskill_id != BS_REPAIRWEAPON)
  11164. return;
  11165. if (pc_istrading(sd)) {
  11166. //Make it fail to avoid shop exploits where you sell something different than you see.
  11167. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11168. clif_menuskill_clear(sd);
  11169. return;
  11170. }
  11171. skill_repairweapon( sd, p->item.index );
  11172. clif_menuskill_clear(sd);
  11173. }
  11174. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  11175. /// 0222 <index>.L
  11176. void clif_parse_WeaponRefine( int fd, map_session_data *sd ){
  11177. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  11178. return;
  11179. if (pc_istrading(sd)) {
  11180. //Make it fail to avoid shop exploits where you sell something different than you see.
  11181. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11182. clif_menuskill_clear(sd);
  11183. return;
  11184. }
  11185. skill_weaponrefine( sd, server_index( RFIFOL( fd, 2 ) ) );
  11186. clif_menuskill_clear(sd);
  11187. }
  11188. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  11189. /// 00b8 <npc id>.L <choice>.B
  11190. /// choice:
  11191. /// 1~254 = menu item
  11192. /// 255 = cancel
  11193. /// NOTE: If there were more than 254 items in the list, choice
  11194. /// overflows to choice%256.
  11195. void clif_parse_NpcSelectMenu(int fd,map_session_data *sd){
  11196. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11197. int npc_id = RFIFOL(fd,info->pos[0]);
  11198. uint8 select = RFIFOB(fd,info->pos[1]);
  11199. #ifdef SECURE_NPCTIMEOUT
  11200. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  11201. return;
  11202. #endif
  11203. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11204. TBL_NPC* nd = map_id2nd(npc_id);
  11205. ShowWarning("Invalid menu selection on npc %d:'%s' - got %d, valid range is [%d..%d] (player AID:%d, CID:%d, name:'%s')!\n", npc_id, (nd)?nd->name:"invalid npc id", select, 1, sd->npc_menu, sd->bl.id, sd->status.char_id, sd->status.name);
  11206. clif_GM_kick(NULL,sd);
  11207. return;
  11208. }
  11209. sd->npc_menu = select;
  11210. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11211. sd->idletime = last_tick;
  11212. }
  11213. npc_scriptcont(sd,npc_id, false);
  11214. }
  11215. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11216. /// 00b9 <npc id>.L
  11217. void clif_parse_NpcNextClicked(int fd,map_session_data *sd)
  11218. {
  11219. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11220. sd->idletime = last_tick;
  11221. }
  11222. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11223. }
  11224. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11225. /// 0143 <npc id>.L <value>.L
  11226. void clif_parse_NpcAmountInput(int fd,map_session_data *sd){
  11227. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11228. int npcid = RFIFOL(fd,info->pos[0]);
  11229. int amount = (int)RFIFOL(fd,info->pos[1]);
  11230. sd->npc_amount = amount;
  11231. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11232. sd->idletime = last_tick;
  11233. }
  11234. npc_scriptcont(sd, npcid, false);
  11235. }
  11236. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11237. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11238. void clif_parse_NpcStringInput(int fd, map_session_data* sd){
  11239. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11240. int message_len = RFIFOW(fd,info->pos[0])-8;
  11241. int npcid = RFIFOL(fd,info->pos[1]);
  11242. const char* message = RFIFOCP(fd,info->pos[2]);
  11243. if( message_len <= 0 )
  11244. return; // invalid input
  11245. #if PACKETVER >= 20151001
  11246. message_len++;
  11247. #endif
  11248. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11249. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11250. sd->idletime = last_tick;
  11251. }
  11252. npc_scriptcont(sd, npcid, false);
  11253. }
  11254. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11255. /// 0146 <npc id>.L
  11256. void clif_parse_NpcCloseClicked(int fd,map_session_data *sd)
  11257. {
  11258. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11259. return;
  11260. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11261. sd->idletime = last_tick;
  11262. }
  11263. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11264. }
  11265. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11266. /// 0178 <index>.W
  11267. /// index:
  11268. /// -1 = cancel
  11269. void clif_parse_ItemIdentify(int fd,map_session_data *sd) {
  11270. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11271. if (sd->menuskill_id != MC_IDENTIFY)
  11272. return;
  11273. // Ignore the request
  11274. // - Invalid item index
  11275. // - Invalid item ID or item doesn't exist
  11276. // - Item is already identified
  11277. if (idx < 0 || idx >= MAX_INVENTORY ||
  11278. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  11279. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11280. sd->state.workinprogress = WIP_DISABLE_NONE;
  11281. clif_menuskill_clear(sd);
  11282. return;
  11283. }
  11284. skill_identify(sd, idx);
  11285. clif_menuskill_clear(sd);
  11286. }
  11287. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11288. /// 01ae <name id>.W
  11289. void clif_parse_SelectArrow(int fd,map_session_data *sd) {
  11290. if (pc_istrading(sd)) {
  11291. //Make it fail to avoid shop exploits where you sell something different than you see.
  11292. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  11293. clif_menuskill_clear(sd);
  11294. return;
  11295. }
  11296. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11297. switch (sd->menuskill_id) {
  11298. case AC_MAKINGARROW:
  11299. skill_arrow_create(sd,p->itemId);
  11300. break;
  11301. case SA_CREATECON:
  11302. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11303. break;
  11304. case GC_POISONINGWEAPON:
  11305. skill_poisoningweapon(sd,p->itemId);
  11306. break;
  11307. case NC_MAGICDECOY:
  11308. skill_magicdecoy(sd,p->itemId);
  11309. break;
  11310. }
  11311. clif_menuskill_clear(sd);
  11312. }
  11313. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11314. /// 01ce <skill id>.L
  11315. void clif_parse_AutoSpell(int fd,map_session_data *sd)
  11316. {
  11317. if (sd->menuskill_id != SA_AUTOSPELL)
  11318. return;
  11319. sd->state.workinprogress = WIP_DISABLE_NONE;
  11320. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11321. clif_menuskill_clear(sd);
  11322. }
  11323. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11324. /// 017a <card index>.W
  11325. void clif_parse_UseCard(int fd,map_session_data *sd)
  11326. {
  11327. if (sd->state.trading != 0)
  11328. return;
  11329. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11330. }
  11331. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11332. /// 017c <card index>.W <equip index>.W
  11333. void clif_parse_InsertCard(int fd,map_session_data *sd)
  11334. {
  11335. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11336. if (sd->state.trading != 0)
  11337. return;
  11338. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11339. }
  11340. /// Request of character's name by char ID.
  11341. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11342. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11343. /// There are various variants of this packet, some of them have padding between fields.
  11344. void clif_parse_SolveCharName(int fd, map_session_data *sd)
  11345. {
  11346. int charid;
  11347. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11348. map_reqnickdb(sd, charid);
  11349. }
  11350. /// /resetskill /resetstate (CZ_RESET).
  11351. /// Request to reset stats or skills.
  11352. /// 0197 <type>.W
  11353. /// type:
  11354. /// 0 = state
  11355. /// 1 = skill
  11356. void clif_parse_ResetChar(int fd, map_session_data *sd) {
  11357. char cmd[15];
  11358. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11359. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11360. else
  11361. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11362. is_atcommand(fd, sd, cmd, 1);
  11363. }
  11364. /// /lb /nlb (CZ_LOCALBROADCAST).
  11365. /// Request to broadcast a message on current map.
  11366. /// 019c <packet len>.W <text>.?B
  11367. void clif_parse_LocalBroadcast(int fd, map_session_data* sd)
  11368. {
  11369. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11370. char command[CHAT_SIZE_MAX+16];
  11371. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11372. char* msg = RFIFOCP(fd,info->pos[1]);
  11373. // as the length varies depending on the command used, just block unreasonably long strings
  11374. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11375. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11376. is_atcommand(fd, sd, command, 1);
  11377. }
  11378. /// Request to move an item from inventory to storage.
  11379. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11380. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11381. /// There are various variants of this packet, some of them have padding between fields.
  11382. void clif_parse_MoveToKafra(int fd, map_session_data *sd)
  11383. {
  11384. int item_index, item_amount;
  11385. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11386. if (pc_istrading(sd))
  11387. return;
  11388. item_index = RFIFOW(fd,info->pos[0])-2;
  11389. item_amount = RFIFOL(fd,info->pos[1]);
  11390. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11391. return;
  11392. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11393. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11394. return;
  11395. }
  11396. if (sd->state.storage_flag == 1)
  11397. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11398. else
  11399. if (sd->state.storage_flag == 2)
  11400. storage_guild_storageadd(sd, item_index, item_amount);
  11401. else if (sd->state.storage_flag == 3)
  11402. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11403. }
  11404. /// Request to move an item from storage to inventory.
  11405. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11406. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11407. /// There are various variants of this packet, some of them have padding between fields.
  11408. void clif_parse_MoveFromKafra(int fd,map_session_data *sd)
  11409. {
  11410. int item_index, item_amount;
  11411. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11412. item_index = RFIFOW(fd,info->pos[0])-1;
  11413. item_amount = RFIFOL(fd,info->pos[1]);
  11414. if (sd->state.storage_flag == 1)
  11415. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11416. else if(sd->state.storage_flag == 2)
  11417. storage_guild_storageget(sd, item_index, item_amount);
  11418. else if(sd->state.storage_flag == 3)
  11419. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11420. }
  11421. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11422. /// 0129 <index>.W <amount>.L
  11423. void clif_parse_MoveToKafraFromCart(int fd, map_session_data *sd){
  11424. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11425. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11426. int amount = RFIFOL(fd,info->pos[1]);
  11427. if( sd->state.vending )
  11428. return;
  11429. if (!pc_iscarton(sd))
  11430. return;
  11431. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11432. return;
  11433. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11434. return;
  11435. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11436. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  11437. return;
  11438. }
  11439. if (sd->state.storage_flag == 1)
  11440. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11441. else if (sd->state.storage_flag == 2)
  11442. storage_guild_storageaddfromcart(sd, idx, amount);
  11443. else if (sd->state.storage_flag == 3)
  11444. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11445. }
  11446. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11447. /// 0128 <index>.W <amount>.L
  11448. void clif_parse_MoveFromKafraToCart(int fd, map_session_data *sd){
  11449. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11450. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11451. int amount = RFIFOL(fd,info->pos[1]);
  11452. if( sd->state.vending )
  11453. return;
  11454. if (!pc_iscarton(sd))
  11455. return;
  11456. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11457. return;
  11458. if (sd->state.storage_flag == 1)
  11459. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11460. else
  11461. if (sd->state.storage_flag == 2)
  11462. storage_guild_storagegettocart(sd, idx, amount);
  11463. else if (sd->state.storage_flag == 3)
  11464. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11465. }
  11466. /// Request to close storage (CZ_CLOSE_STORE).
  11467. /// 00f7
  11468. void clif_parse_CloseKafra(int fd, map_session_data *sd)
  11469. {
  11470. if( sd->state.storage_flag == 1 )
  11471. storage_storageclose(sd);
  11472. else
  11473. if( sd->state.storage_flag == 2 )
  11474. storage_guild_storageclose(sd);
  11475. else if( sd->state.storage_flag == 3 )
  11476. storage_premiumStorage_close(sd);
  11477. }
  11478. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11479. /// 023a <info>.W
  11480. /// info:
  11481. /// 0 = password has not been set yet
  11482. /// 1 = storage is password-protected
  11483. /// 8 = too many wrong passwords
  11484. /// ? = ignored
  11485. /// NOTE: This packet is only available on certain non-kRO clients.
  11486. void clif_storagepassword(map_session_data* sd, short info)
  11487. {
  11488. int fd = sd->fd;
  11489. WFIFOHEAD(fd,packet_len(0x23a));
  11490. WFIFOW(fd,0) = 0x23a;
  11491. WFIFOW(fd,2) = info;
  11492. WFIFOSET(fd,packet_len(0x23a));
  11493. }
  11494. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11495. /// 023b <type>.W <password>.16B <new password>.16B
  11496. /// type:
  11497. /// 2 = change password
  11498. /// 3 = check password
  11499. /// NOTE: This packet is only available on certain non-kRO clients.
  11500. void clif_parse_StoragePassword(int fd, map_session_data *sd){ //@TODO
  11501. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11502. // int type = RFIFOW(fd,info->pos[0]);
  11503. // char* password = RFIFOP(fd,info->pos[1]);
  11504. // char* new_password = RFIFOP(fd,info->pos[2]);
  11505. // storage_changepass(sd,password,new_password);
  11506. }
  11507. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11508. /// 023c <result>.W <error count>.W
  11509. /// result:
  11510. /// 4 = password change success
  11511. /// 5 = password change failure
  11512. /// 6 = password check success
  11513. /// 7 = password check failure
  11514. /// 8 = too many wrong passwords
  11515. /// ? = ignored
  11516. /// NOTE: This packet is only available on certain non-kRO clients.
  11517. void clif_storagepassword_result(map_session_data* sd, short result, short error_count)
  11518. {
  11519. int fd = sd->fd;
  11520. WFIFOHEAD(fd,packet_len(0x23c));
  11521. WFIFOW(fd,0) = 0x23c;
  11522. WFIFOW(fd,2) = result;
  11523. WFIFOW(fd,4) = error_count;
  11524. WFIFOSET(fd,packet_len(0x23c));
  11525. }
  11526. /// Party creation request
  11527. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11528. void clif_parse_CreateParty(int fd, map_session_data *sd){
  11529. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11530. name[NAME_LENGTH-1] = '\0';
  11531. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11532. clif_displaymessage(fd, msg_txt(sd,227));
  11533. return;
  11534. }
  11535. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11536. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11537. return;
  11538. }
  11539. party_create(sd,name,0,0);
  11540. }
  11541. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11542. void clif_parse_CreateParty2(int fd, map_session_data *sd){
  11543. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11544. char* name = RFIFOCP(fd,info->pos[0]);
  11545. int item1 = RFIFOB(fd,info->pos[1]);
  11546. int item2 = RFIFOB(fd,info->pos[2]);
  11547. name[NAME_LENGTH-1] = '\0';
  11548. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11549. clif_displaymessage(fd, msg_txt(sd,227));
  11550. return;
  11551. }
  11552. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11553. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11554. return;
  11555. }
  11556. party_create(sd,name,item1,item2);
  11557. }
  11558. /// Party invitation request
  11559. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11560. void clif_parse_PartyInvite(int fd, map_session_data *sd)
  11561. {
  11562. map_session_data *t_sd;
  11563. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11564. clif_displaymessage(fd, msg_txt(sd,227));
  11565. return;
  11566. }
  11567. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11568. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11569. clif_noask_sub(sd, t_sd, 1);
  11570. return;
  11571. }
  11572. party_invite(sd, t_sd);
  11573. }
  11574. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11575. void clif_parse_PartyInvite2(int fd, map_session_data *sd){
  11576. map_session_data *t_sd;
  11577. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11578. name[NAME_LENGTH-1] = '\0';
  11579. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11580. clif_displaymessage(fd, msg_txt(sd,227));
  11581. return;
  11582. }
  11583. t_sd = map_nick2sd(name,false);
  11584. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11585. clif_noask_sub(sd, t_sd, 1);
  11586. return;
  11587. }
  11588. party_invite(sd, t_sd);
  11589. }
  11590. /// Party invitation reply
  11591. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11592. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11593. /// flag:
  11594. /// 0 = reject
  11595. /// 1 = accept
  11596. void clif_parse_ReplyPartyInvite(int fd,map_session_data *sd)
  11597. {
  11598. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11599. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11600. RFIFOL(fd,info->pos[1]));
  11601. }
  11602. //(CZ_PARTY_JOIN_REQ_ACK)
  11603. void clif_parse_ReplyPartyInvite2(int fd,map_session_data *sd)
  11604. {
  11605. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11606. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11607. RFIFOB(fd,info->pos[1]));
  11608. }
  11609. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11610. /// 0100
  11611. void clif_parse_LeaveParty(int fd, map_session_data *sd)
  11612. {
  11613. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11614. clif_displaymessage(fd, msg_txt(sd,227));
  11615. return;
  11616. }
  11617. party_leave(sd);
  11618. }
  11619. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11620. /// 0103 <account id>.L <char name>.24B
  11621. void clif_parse_RemovePartyMember(int fd, map_session_data *sd)
  11622. {
  11623. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11624. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11625. clif_displaymessage(fd, msg_txt(sd,227));
  11626. return;
  11627. }
  11628. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11629. RFIFOCP(fd,info->pos[1]));
  11630. }
  11631. /// Request to change party options.
  11632. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11633. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11634. void clif_parse_PartyChangeOption(int fd, map_session_data *sd)
  11635. {
  11636. struct party_data *p;
  11637. int i,expflag;
  11638. int cmd = RFIFOW(fd,0);
  11639. struct s_packet_db* info = &packet_db[cmd];
  11640. if( !sd->status.party_id )
  11641. return;
  11642. p = party_search(sd->status.party_id);
  11643. if( p == NULL )
  11644. return;
  11645. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11646. if( i == MAX_PARTY )
  11647. return; //Shouldn't happen
  11648. if( !p->party.member[i].leader )
  11649. return;
  11650. expflag = RFIFOL(fd,info->pos[0]);
  11651. if(cmd == 0x0102){ //Client can't change the item-field
  11652. party_changeoption(sd, expflag, p->party.item);
  11653. }
  11654. else {
  11655. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11656. party_changeoption(sd, expflag, itemflag);
  11657. }
  11658. }
  11659. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11660. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11661. void clif_parse_PartyMessage(int fd, map_session_data* sd){
  11662. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11663. // validate packet and retrieve name and message
  11664. if( !clif_process_message( sd, false, name, message, output ) )
  11665. return;
  11666. party_send_message(sd, output, strlen(output) + 1 );
  11667. }
  11668. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11669. /// 07da <account id>.L
  11670. void clif_parse_PartyChangeLeader(int fd, map_session_data* sd){
  11671. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11672. }
  11673. /// Party Booking in KRO [Spiria]
  11674. ///
  11675. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11676. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11677. void clif_parse_PartyBookingRegisterReq(int fd, map_session_data* sd){
  11678. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11679. short level = RFIFOW(fd,info->pos[0]);
  11680. short mapid = RFIFOW(fd,info->pos[1]);
  11681. int idxpbj = info->pos[2];
  11682. short job[MAX_PARTY_BOOKING_JOBS];
  11683. int i;
  11684. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11685. job[i] = RFIFOB(fd,idxpbj+i*2);
  11686. party_booking_register(sd, level, mapid, job);
  11687. }
  11688. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11689. /// 0803 <result>.W
  11690. /// result:
  11691. /// 0 = success
  11692. /// 1 = failure
  11693. /// 2 = already registered
  11694. void clif_PartyBookingRegisterAck(map_session_data *sd, int flag)
  11695. {
  11696. int fd = sd->fd;
  11697. WFIFOHEAD(fd,packet_len(0x803));
  11698. WFIFOW(fd,0) = 0x803;
  11699. WFIFOW(fd,2) = flag;
  11700. WFIFOSET(fd,packet_len(0x803));
  11701. }
  11702. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11703. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11704. void clif_parse_PartyBookingSearchReq(int fd, map_session_data* sd){
  11705. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11706. short level = RFIFOW(fd,info->pos[0]);
  11707. short mapid = RFIFOW(fd,info->pos[1]);
  11708. short job = RFIFOW(fd,info->pos[2]);
  11709. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11710. short resultcount = RFIFOW(fd,info->pos[4]);
  11711. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11712. }
  11713. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11714. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11715. /// more results:
  11716. /// 0 = no
  11717. /// 1 = yes
  11718. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11719. {
  11720. int i, j;
  11721. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11722. struct party_booking_ad_info *pb_ad;
  11723. WFIFOHEAD(fd,size*count + 5);
  11724. WFIFOW(fd,0) = 0x805;
  11725. WFIFOW(fd,2) = size*count + 5;
  11726. WFIFOB(fd,4) = more_result;
  11727. for(i=0; i<count; i++)
  11728. {
  11729. pb_ad = results[i];
  11730. WFIFOL(fd,i*size+5) = pb_ad->index;
  11731. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11732. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11733. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11734. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11735. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11736. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11737. }
  11738. WFIFOSET(fd,WFIFOW(fd,2));
  11739. }
  11740. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11741. /// 0806
  11742. void clif_parse_PartyBookingDeleteReq(int fd, map_session_data* sd)
  11743. {
  11744. if(party_booking_delete(sd))
  11745. clif_PartyBookingDeleteAck(sd, 0);
  11746. }
  11747. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11748. /// 0807 <result>.W
  11749. /// result:
  11750. /// 0 = success
  11751. /// 1 = success (auto-removed expired ad)
  11752. /// 2 = failure
  11753. /// 3 = nothing registered
  11754. void clif_PartyBookingDeleteAck(map_session_data* sd, int flag)
  11755. {
  11756. int fd = sd->fd;
  11757. WFIFOHEAD(fd,packet_len(0x807));
  11758. WFIFOW(fd,0) = 0x807;
  11759. WFIFOW(fd,2) = flag;
  11760. WFIFOSET(fd,packet_len(0x807));
  11761. }
  11762. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11763. /// 0808 { <job>.W }*6
  11764. void clif_parse_PartyBookingUpdateReq(int fd, map_session_data* sd)
  11765. {
  11766. short job[MAX_PARTY_BOOKING_JOBS];
  11767. int i;
  11768. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11769. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11770. job[i] = RFIFOW(fd,idxpbu+i*2);
  11771. party_booking_update(sd, job);
  11772. }
  11773. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11774. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11775. void clif_PartyBookingInsertNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11776. {
  11777. int i;
  11778. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11779. if(pb_ad == NULL) return;
  11780. WBUFW(buf,0) = 0x809;
  11781. WBUFL(buf,2) = pb_ad->index;
  11782. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11783. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11784. WBUFW(buf,34) = pb_ad->p_detail.level;
  11785. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11786. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11787. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11788. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11789. }
  11790. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11791. /// 080a <index>.L { <job>.W }*6
  11792. void clif_PartyBookingUpdateNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11793. {
  11794. int i;
  11795. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11796. if(pb_ad == NULL) return;
  11797. WBUFW(buf,0) = 0x80a;
  11798. WBUFL(buf,2) = pb_ad->index;
  11799. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11800. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11801. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11802. }
  11803. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11804. /// 080b <index>.L
  11805. void clif_PartyBookingDeleteNotify(map_session_data* sd, int index)
  11806. {
  11807. uint8 buf[6];
  11808. WBUFW(buf,0) = 0x80b;
  11809. WBUFL(buf,2) = index;
  11810. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11811. }
  11812. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11813. /// 012e
  11814. void clif_parse_CloseVending(int fd, map_session_data* sd)
  11815. {
  11816. vending_closevending(sd);
  11817. }
  11818. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11819. /// 0130 <account id>.L
  11820. void clif_parse_VendingListReq(int fd, map_session_data* sd)
  11821. {
  11822. if( sd->npc_id ) {// using an NPC
  11823. return;
  11824. }
  11825. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11826. }
  11827. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11828. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11829. void clif_parse_PurchaseReq(int fd, map_session_data* sd){
  11830. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC*)RFIFOP( fd, 0 );
  11831. vending_purchasereq( sd, p->AID, sd->vended_id, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11832. // whether it fails or not, the buy window is closed
  11833. sd->vended_id = 0;
  11834. }
  11835. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11836. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11837. void clif_parse_PurchaseReq2(int fd, map_session_data* sd){
  11838. #if PACKETVER >= 20100105
  11839. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2*)RFIFOP( fd, 0 );
  11840. vending_purchasereq( sd, p->AID, p->UniqueID, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11841. // whether it fails or not, the buy window is closed
  11842. sd->vended_id = 0;
  11843. #endif
  11844. }
  11845. /// Confirm or cancel the shop preparation window.
  11846. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11847. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11848. /// result:
  11849. /// 0 = canceled
  11850. /// 1 = open
  11851. void clif_parse_OpenVending(int fd, map_session_data* sd){
  11852. int cmd = RFIFOW(fd,0);
  11853. struct s_packet_db* info = &packet_db[cmd];
  11854. short len = (short)RFIFOW(fd,info->pos[0]);
  11855. const char* message = RFIFOCP(fd,info->pos[1]);
  11856. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11857. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11858. len -= 84;
  11859. }
  11860. else { //(CZ_REQ_OPENSTORE2)
  11861. bool flag;
  11862. len -= 85;
  11863. flag = RFIFOB(fd,info->pos[2]) != 0;
  11864. if (!flag) {
  11865. sd->state.prevend = 0;
  11866. sd->state.workinprogress = WIP_DISABLE_NONE;
  11867. }
  11868. }
  11869. if( sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM )
  11870. return;
  11871. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11872. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11873. return;
  11874. }
  11875. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11876. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11877. return;
  11878. }
  11879. if( message[0] == '\0' ) // invalid input
  11880. return;
  11881. vending_openvending(sd, message, data, len/8, NULL);
  11882. }
  11883. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11884. /// 0165 <char id>.L <guild name>.24B
  11885. void clif_parse_CreateGuild(int fd,map_session_data *sd){
  11886. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11887. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11888. name[NAME_LENGTH-1] = '\0';
  11889. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11890. clif_displaymessage(fd, msg_txt(sd,228));
  11891. return;
  11892. }
  11893. if(sd->clan){
  11894. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11895. return;
  11896. }
  11897. guild_create(sd, name);
  11898. }
  11899. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11900. /// 014d
  11901. void clif_parse_GuildCheckMaster(int fd, map_session_data *sd)
  11902. {
  11903. clif_guild_masterormember(sd);
  11904. }
  11905. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11906. /// 014f <type>.L
  11907. /// type:
  11908. /// 0 = basic info
  11909. /// 1 = member manager
  11910. /// 2 = positions
  11911. /// 3 = skills
  11912. /// 4 = expulsion list
  11913. /// 5 = unknown (GM_ALLGUILDLIST)
  11914. /// 6 = notice
  11915. void clif_parse_GuildRequestInfo(int fd, map_session_data *sd)
  11916. {
  11917. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11918. if( !sd->status.guild_id && !sd->bg_id )
  11919. return;
  11920. switch( type )
  11921. {
  11922. case 0: // Basic Information Guild, hostile alliance information
  11923. clif_guild_basicinfo( *sd );
  11924. clif_guild_allianceinfo(sd);
  11925. clif_guild_castle_list(*sd);
  11926. break;
  11927. case 1: // Members list, list job title
  11928. clif_guild_positionnamelist(sd);
  11929. clif_guild_memberlist( *sd );
  11930. break;
  11931. case 2: // List job title, title information list
  11932. clif_guild_positionnamelist(sd);
  11933. clif_guild_positioninfolist(sd);
  11934. break;
  11935. case 3: // Skill list
  11936. clif_guild_skillinfo(sd);
  11937. break;
  11938. case 4: // Expulsion list
  11939. clif_guild_expulsionlist(sd);
  11940. break;
  11941. default:
  11942. ShowError("clif: guild request info: unknown type %d\n", type);
  11943. break;
  11944. }
  11945. }
  11946. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11947. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11948. void clif_parse_GuildChangePositionInfo(int fd, map_session_data *sd)
  11949. {
  11950. int i;
  11951. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11952. int len = RFIFOW(fd,info->pos[0]);
  11953. int idxgpos = info->pos[1];
  11954. if(!sd->state.gmaster_flag)
  11955. return;
  11956. for(i = idxgpos; i < len; i += 40 ){
  11957. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11958. }
  11959. }
  11960. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11961. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11962. void clif_parse_GuildChangeMemberPosition( int fd, map_session_data *sd ){
  11963. if(!sd->state.gmaster_flag)
  11964. return;
  11965. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS* p = (struct PACKET_CZ_REQ_CHANGE_MEMBERPOS*)RFIFOP( fd, 0 );
  11966. int16 entries = ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] );
  11967. for( int16 i = 0; i < entries; i++ ){
  11968. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS_sub& entry = p->list[i];
  11969. // Guild leadership change
  11970. if( entry.position == 0 ){
  11971. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11972. clif_msg( sd, GUILD_MASTER_WOE );
  11973. return;
  11974. }
  11975. if( battle_config.guild_leaderchange_delay && DIFF_TICK( time( nullptr ),sd->guild->guild.last_leader_change ) < battle_config.guild_leaderchange_delay ){
  11976. clif_msg( sd, GUILD_MASTER_DELAY );
  11977. return;
  11978. }
  11979. guild_gm_change( sd->status.guild_id, entry.CID );
  11980. // No further entries will be processed - the requesting player lost his guild master status
  11981. return;
  11982. }else if( entry.position > 0 ){
  11983. guild_change_memberposition( sd->status.guild_id, entry.AID, entry.CID, entry.position );
  11984. }
  11985. }
  11986. }
  11987. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11988. /// 0151 <guild id>.L
  11989. void clif_parse_GuildRequestEmblem(int fd,map_session_data *sd)
  11990. {
  11991. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11992. auto g = guild_search(guild_id);
  11993. if (g)
  11994. clif_guild_emblem(*sd, g->guild);
  11995. }
  11996. /// Validates data of a guild emblem (compressed bitmap)
  11997. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11998. EMBVALIDATE_SUCCESS = 0,
  11999. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  12000. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of inter_config.emblem_transparency_limit
  12001. };
  12002. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  12003. {
  12004. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  12005. unsigned long buf_len = sizeof(buf);
  12006. int offset = 0;
  12007. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  12008. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  12009. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  12010. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  12011. ))
  12012. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  12013. if(inter_config.emblem_transparency_limit != 100) {
  12014. int i, transcount = 1, tmp[3];
  12015. for(i = offset; i < buf_len-1; i++) {
  12016. int j = i%3;
  12017. tmp[j] = RBUFL(buf,i);
  12018. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  12019. transcount++;
  12020. }
  12021. if(((transcount*300)/(buf_len-offset)) > inter_config.emblem_transparency_limit) //convert in % to chk
  12022. return EMBVALIDATE_ERR_TRANSPARENCY;
  12023. }
  12024. return EMBVALIDATE_SUCCESS;
  12025. }
  12026. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  12027. /// 0153 <packet len>.W <emblem data>.?B
  12028. void clif_parse_GuildChangeEmblem(int fd,map_session_data *sd){
  12029. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12030. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  12031. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  12032. int emb_val=0;
  12033. if( !emblem_len || !sd->state.gmaster_flag )
  12034. return;
  12035. if(!(inter_config.emblem_woe_change) && is_agit_start() ){
  12036. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  12037. return;
  12038. }
  12039. emb_val = clif_validate_emblem(emblem, emblem_len);
  12040. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  12041. ShowWarning("clif_parse_GuildChangeEmblem: Rejected malformed guild emblem (size=%lu, accound_id=%d, char_id=%d, guild_id=%d).\n", emblem_len, sd->status.account_id, sd->status.char_id, sd->status.guild_id);
  12042. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  12043. return;
  12044. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  12045. char output[128];
  12046. safesnprintf(output,sizeof(output),msg_txt(sd,387),inter_config.emblem_transparency_limit);
  12047. clif_messagecolor(&sd->bl,color_table[COLOR_RED],output,false,SELF); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  12048. return;
  12049. }
  12050. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  12051. }
  12052. /// Request to update the guild emblem id (version, according to Gravity)
  12053. /// 0b46 <guild id>.L <version>.L
  12054. void clif_parse_GuildChangeEmblem2(int fd, map_session_data* sd) {
  12055. nullpo_retv(sd);
  12056. #if PACKETVER >= 20190724
  12057. const PACKET_CZ_GUILD_EMBLEM_CHANGE2* p = (PACKET_CZ_GUILD_EMBLEM_CHANGE2*)RFIFOP(fd, 0);
  12058. auto &g = sd->guild;
  12059. if (!g || g->guild.guild_id != p->guild_id)
  12060. return;
  12061. if (!sd->state.gmaster_flag)
  12062. return;
  12063. if (!inter_config.emblem_woe_change && is_agit_start()) {
  12064. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  12065. return;
  12066. }
  12067. guild_change_emblem_version(sd, p->version);
  12068. #endif
  12069. }
  12070. /// Guild notice update request (CZ_GUILD_NOTICE).
  12071. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  12072. void clif_parse_GuildChangeNotice(int fd, map_session_data* sd){
  12073. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12074. int guild_id = RFIFOL(fd,info->pos[0]);
  12075. char* msg1 = RFIFOCP(fd,info->pos[1]);
  12076. char* msg2 = RFIFOCP(fd,info->pos[2]);
  12077. if(!sd->state.gmaster_flag)
  12078. return;
  12079. // compensate for some client defects when using multilanguage mode
  12080. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  12081. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  12082. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  12083. guild_change_notice(sd, guild_id, msg1, msg2);
  12084. }
  12085. // Helper function for guild invite functions
  12086. int clif_sub_guild_invite(int fd, map_session_data *sd, map_session_data *t_sd)
  12087. {
  12088. if (t_sd == NULL) // not online or does not exist
  12089. return 1;
  12090. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  12091. clif_displaymessage(fd, msg_txt(sd,228));
  12092. return 1;
  12093. }
  12094. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  12095. clif_noask_sub(sd, t_sd, 2);
  12096. return 1;
  12097. }
  12098. // Players in a clan can not join a guild
  12099. if(t_sd && t_sd->clan){
  12100. return 1;
  12101. }
  12102. guild_invite(sd, t_sd);
  12103. return 0;
  12104. }
  12105. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  12106. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  12107. void clif_parse_GuildInvite(int fd,map_session_data *sd){
  12108. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12109. map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  12110. // int inv_aid = RFIFOL(fd,info->pos[1]);
  12111. // int inv_cid = RFIFOL(fd,info->pos[2]);
  12112. if (clif_sub_guild_invite(fd, sd, t_sd))
  12113. return;
  12114. }
  12115. /// Guild invite request (/guildinvite)
  12116. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  12117. void
  12118. clif_parse_GuildInvite2(int fd, map_session_data *sd) {
  12119. map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  12120. if (clif_sub_guild_invite(fd, sd, t_sd))
  12121. return;
  12122. }
  12123. /// Answer to guild invitation (CZ_JOIN_GUILD).
  12124. /// 016b <guild id>.L <answer>.L
  12125. /// answer:
  12126. /// 0 = refuse
  12127. /// 1 = accept
  12128. void clif_parse_GuildReplyInvite(int fd,map_session_data *sd){
  12129. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12130. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  12131. RFIFOL(fd,info->pos[1]));
  12132. }
  12133. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  12134. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  12135. void clif_parse_GuildLeave(int fd,map_session_data *sd){
  12136. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12137. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12138. clif_displaymessage(fd, msg_txt(sd,228));
  12139. return;
  12140. }
  12141. if( sd->bg_id ) {
  12142. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  12143. return;
  12144. }
  12145. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  12146. RFIFOL(fd,info->pos[1]),
  12147. RFIFOL(fd,info->pos[2]),
  12148. RFIFOCP(fd,info->pos[3]));
  12149. }
  12150. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  12151. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  12152. void clif_parse_GuildExpulsion(int fd,map_session_data *sd){
  12153. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12154. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  12155. { // Guild locked.
  12156. clif_displaymessage(fd, msg_txt(sd,228));
  12157. return;
  12158. }
  12159. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  12160. RFIFOL(fd,info->pos[1]),
  12161. RFIFOL(fd,info->pos[2]),
  12162. RFIFOCP(fd,info->pos[3]));
  12163. }
  12164. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  12165. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  12166. void clif_parse_GuildMessage(int fd, map_session_data* sd){
  12167. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  12168. // validate packet and retrieve name and message
  12169. if( !clif_process_message( sd, false, name, message, output ) )
  12170. return;
  12171. if( sd->bg_id )
  12172. bg_send_message(sd, output, strlen(output) );
  12173. else
  12174. guild_send_message(sd, output, strlen(output) );
  12175. }
  12176. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  12177. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  12178. void clif_parse_GuildRequestAlliance(int fd, map_session_data *sd)
  12179. {
  12180. map_session_data *t_sd;
  12181. if(!sd->state.gmaster_flag)
  12182. return;
  12183. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12184. clif_displaymessage(fd, msg_txt(sd,228));
  12185. return;
  12186. }
  12187. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12188. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12189. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12190. // @noask [LuzZza]
  12191. if(t_sd && t_sd->state.noask) {
  12192. clif_noask_sub(sd, t_sd, 3);
  12193. return;
  12194. }
  12195. guild_reqalliance(sd,t_sd);
  12196. }
  12197. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12198. /// 0172 <inviter account id>.L <answer>.L
  12199. /// answer:
  12200. /// 0 = refuse
  12201. /// 1 = accept
  12202. void clif_parse_GuildReplyAlliance(int fd, map_session_data *sd){
  12203. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12204. guild_reply_reqalliance(sd,
  12205. RFIFOL(fd,info->pos[0]),
  12206. RFIFOL(fd,info->pos[1]));
  12207. }
  12208. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12209. /// 0183 <opponent guild id>.L <relation>.L
  12210. /// relation:
  12211. /// 0 = Ally
  12212. /// 1 = Enemy
  12213. void clif_parse_GuildDelAlliance(int fd, map_session_data *sd){
  12214. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12215. if(!sd->state.gmaster_flag)
  12216. return;
  12217. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12218. clif_displaymessage(fd, msg_txt(sd,228));
  12219. return;
  12220. }
  12221. guild_delalliance(sd,
  12222. RFIFOL(fd,info->pos[0]),
  12223. RFIFOL(fd,info->pos[1]));
  12224. }
  12225. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12226. /// 0180 <account id>.L
  12227. void clif_parse_GuildOpposition(int fd, map_session_data *sd)
  12228. {
  12229. map_session_data *t_sd;
  12230. if(!sd->state.gmaster_flag)
  12231. return;
  12232. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12233. clif_displaymessage(fd, msg_txt(sd,228));
  12234. return;
  12235. }
  12236. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12237. // @noask [LuzZza]
  12238. if(t_sd && t_sd->state.noask) {
  12239. clif_noask_sub(sd, t_sd, 4);
  12240. return;
  12241. }
  12242. guild_opposition(sd,t_sd);
  12243. }
  12244. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12245. /// 015d <key>.40B
  12246. /// key:
  12247. /// now guild name; might have been (intended) email, since the
  12248. /// field name and size is same as the one in CH_DELETE_CHAR.
  12249. void clif_parse_GuildBreak(int fd, map_session_data *sd)
  12250. {
  12251. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12252. clif_displaymessage(fd, msg_txt(sd,228));
  12253. return;
  12254. }
  12255. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12256. }
  12257. /// Pet
  12258. ///
  12259. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12260. /// 01a1 <type>.B
  12261. /// type:
  12262. /// 0 = pet information
  12263. /// 1 = feed
  12264. /// 2 = performance
  12265. /// 3 = return to egg
  12266. /// 4 = unequip accessory
  12267. void clif_parse_PetMenu(int fd, map_session_data *sd){
  12268. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12269. }
  12270. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12271. /// 019f <id>.L
  12272. void clif_parse_CatchPet(int fd, map_session_data *sd){
  12273. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12274. }
  12275. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12276. /// 01a7 <index>.W
  12277. void clif_parse_SelectEgg(int fd, map_session_data *sd){
  12278. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12279. return;
  12280. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12281. clif_menuskill_clear(sd);
  12282. }
  12283. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12284. /// 01a9 <data>.L
  12285. /// data:
  12286. /// is either emotion (@see enum emotion_type) or a compound value
  12287. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12288. /// entry (given in parentheses) in data\pettalktable.xml
  12289. /// act id:
  12290. /// 0 = feeding
  12291. /// 1 = hunting
  12292. /// 2 = danger
  12293. /// 3 = dead
  12294. /// 4 = normal (stand)
  12295. /// 5 = special performance (perfor_s)
  12296. /// 6 = level up (levelup)
  12297. /// 7 = performance 1 (perfor_1)
  12298. /// 8 = performance 2 (perfor_2)
  12299. /// 9 = performance 3 (perfor_3)
  12300. /// 10 = log-in greeting (connect)
  12301. /// hungry value:
  12302. /// 0 = very hungry (hungry)
  12303. /// 1 = hungry (bit_hungry)
  12304. /// 2 = satisfied (noting)
  12305. /// 3 = stuffed (full)
  12306. /// 4 = full (so_full)
  12307. void clif_parse_SendEmotion(int fd, map_session_data *sd)
  12308. {
  12309. if(sd->pd)
  12310. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12311. }
  12312. /// Request to change pet's name (CZ_RENAME_PET).
  12313. /// 01a5 <name>.24B
  12314. void clif_parse_ChangePetName(int fd, map_session_data *sd)
  12315. {
  12316. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12317. }
  12318. /// /kill (CZ_DISCONNECT_CHARACTER).
  12319. /// Request to disconnect a character.
  12320. /// 00cc <account id>.L
  12321. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12322. void clif_parse_GMKick(int fd, map_session_data *sd)
  12323. {
  12324. struct block_list *target;
  12325. int tid;
  12326. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12327. target = map_id2bl(tid);
  12328. if (!target) {
  12329. clif_GM_kickack(sd, 0);
  12330. return;
  12331. }
  12332. switch (target->type) {
  12333. case BL_PC:
  12334. {
  12335. char command[NAME_LENGTH+6];
  12336. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12337. is_atcommand(fd, sd, command, 1);
  12338. }
  12339. break;
  12340. /**
  12341. * This one does not invoke any atcommand, so we need to check for permissions.
  12342. */
  12343. case BL_MOB:
  12344. {
  12345. char command[100];
  12346. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12347. clif_GM_kickack(sd, 0);
  12348. return;
  12349. }
  12350. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12351. log_atcommand(sd, command);
  12352. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12353. }
  12354. break;
  12355. case BL_NPC:
  12356. {
  12357. struct npc_data* nd = (struct npc_data *)target;
  12358. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12359. npc_unload_duplicates(nd);
  12360. npc_unload(nd,true);
  12361. npc_read_event_script();
  12362. }
  12363. }
  12364. break;
  12365. default:
  12366. clif_GM_kickack(sd, 0);
  12367. }
  12368. }
  12369. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12370. /// Request to disconnect all characters.
  12371. /// 00ce
  12372. void clif_parse_GMKickAll(int fd, map_session_data* sd) {
  12373. char cmd[15];
  12374. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12375. is_atcommand(fd, sd, cmd, 1);
  12376. }
  12377. /// /remove (CZ_REMOVE_AID).
  12378. /// Request to warp to a character with given login ID.
  12379. /// 01ba <account name>.24B
  12380. /// /shift (CZ_SHIFT).
  12381. /// Request to warp to a character with given name.
  12382. /// 01bb <char name>.24B
  12383. void clif_parse_GMShift(int fd, map_session_data *sd)
  12384. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12385. char *player_name;
  12386. char command[NAME_LENGTH+8];
  12387. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12388. player_name[NAME_LENGTH-1] = '\0';
  12389. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12390. is_atcommand(fd, sd, command, 1);
  12391. }
  12392. /// /remove (CZ_REMOVE_AID_SSO).
  12393. /// Request to warp to a character with given account ID.
  12394. /// 0843 <account id>.L
  12395. void clif_parse_GMRemove2(int fd, map_session_data* sd)
  12396. {
  12397. uint32 account_id;
  12398. map_session_data* pl_sd;
  12399. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12400. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12401. char command[NAME_LENGTH+8];
  12402. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12403. is_atcommand(fd, sd, command, 1);
  12404. }
  12405. }
  12406. /// /recall (CZ_RECALL).
  12407. /// Request to summon a player with given login ID to own position.
  12408. /// 01bc <account name>.24B
  12409. /// /summon (CZ_RECALL_GID).
  12410. /// Request to summon a player with given name to own position.
  12411. /// 01bd <char name>.24B
  12412. void clif_parse_GMRecall(int fd, map_session_data *sd)
  12413. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12414. char *player_name;
  12415. char command [NAME_LENGTH+8];
  12416. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12417. player_name[NAME_LENGTH-1] = '\0';
  12418. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12419. is_atcommand(fd, sd, command, 1);
  12420. }
  12421. /// /recall (CZ_RECALL_SSO).
  12422. /// Request to summon a player with given account ID to own position.
  12423. /// 0842 <account id>.L
  12424. void clif_parse_GMRecall2(int fd, map_session_data* sd)
  12425. {
  12426. uint32 account_id;
  12427. map_session_data* pl_sd;
  12428. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12429. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  12430. char command[NAME_LENGTH+8];
  12431. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12432. is_atcommand(fd, sd, command, 1);
  12433. }
  12434. }
  12435. /// /item /monster (CZ_ITEM_CREATE).
  12436. /// Request to execute GM commands.
  12437. /// Usage:
  12438. /// /item n - summon n monster or acquire n item/s
  12439. /// /item money - grants 2147483647 zenies
  12440. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12441. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12442. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12443. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12444. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12445. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12446. /// 013f <item/mob name>.24B
  12447. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12448. void clif_parse_GM_Item_Monster(int fd, map_session_data *sd)
  12449. {
  12450. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12451. int mob_id = 0;
  12452. StringBuf command;
  12453. char *str;
  12454. //#if PACKETVER >= 20131218
  12455. // char str[100];
  12456. //#else
  12457. // char str[24];
  12458. //#endif
  12459. str = RFIFOCP(fd,info->pos[0]);
  12460. if (!str || str[0] == '\0')
  12461. return;
  12462. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12463. return;
  12464. trim(str);
  12465. // Zeny
  12466. if( strcmpi(str, "money") == 0 ) {
  12467. StringBuf_Init(&command);
  12468. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12469. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12470. StringBuf_Destroy(&command);
  12471. return;
  12472. }
  12473. std::shared_ptr<item_data> id = item_db.searchname( str );
  12474. // Item
  12475. if( id ){
  12476. StringBuf_Init(&command);
  12477. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12478. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12479. }else{
  12480. if (id->flag.guid)
  12481. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12482. else
  12483. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12484. }
  12485. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12486. StringBuf_Destroy(&command);
  12487. return;
  12488. }
  12489. // Monster
  12490. if ((mob_id = mobdb_searchname(str)) == 0)
  12491. mob_id = mobdb_checkid(atoi(str));
  12492. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12493. if( mob != nullptr ) {
  12494. StringBuf_Init(&command);
  12495. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12496. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12497. StringBuf_Destroy(&command);
  12498. return;
  12499. }
  12500. }
  12501. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12502. /// 019d <effect state>.L
  12503. /// effect state:
  12504. /// TODO: Any OPTION_* ?
  12505. void clif_parse_GMHide(int fd, map_session_data *sd) {
  12506. char cmd[6];
  12507. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12508. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12509. is_atcommand(fd, sd, cmd, 1);
  12510. }
  12511. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12512. /// 0149 <account id>.L <type>.B <value>.W
  12513. /// type:
  12514. /// 0 = positive points
  12515. /// 1 = negative points
  12516. /// 2 = self mute (+10 minutes)
  12517. void clif_parse_GMReqNoChat(int fd,map_session_data *sd)
  12518. {
  12519. int id, type, value;
  12520. map_session_data *dstsd;
  12521. char command[NAME_LENGTH+15];
  12522. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12523. id = RFIFOL(fd,info->pos[0]);
  12524. type = RFIFOB(fd,info->pos[1]);
  12525. value = RFIFOW(fd,info->pos[2]);
  12526. if( type == 0 )
  12527. value = -value;
  12528. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12529. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12530. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12531. return;
  12532. dstsd = map_id2sd(id);
  12533. if( dstsd == NULL )
  12534. return;
  12535. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12536. is_atcommand(fd, sd, command, 1);
  12537. }
  12538. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12539. /// GM adjustment of a player's manner value by -60.
  12540. /// 0212 <char name>.24B
  12541. void clif_parse_GMRc(int fd, map_session_data* sd)
  12542. {
  12543. char command[NAME_LENGTH+15];
  12544. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12545. name[NAME_LENGTH-1] = '\0';
  12546. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12547. is_atcommand(fd, sd, command, 1);
  12548. }
  12549. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12550. /// 01e0 <account id>.L <account name>.24B
  12551. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12552. {
  12553. WFIFOHEAD(fd,packet_len(0x1e0));
  12554. WFIFOW(fd,0) = 0x1e0;
  12555. WFIFOL(fd,2) = account_id;
  12556. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12557. WFIFOSET(fd,packet_len(0x1e0));
  12558. }
  12559. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12560. /// 01df <account id>.L
  12561. //! TODO: Figure out how does this actually work
  12562. void clif_parse_GMReqAccountName(int fd, map_session_data *sd)
  12563. {
  12564. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12565. /*
  12566. char query[30];
  12567. safesnprintf(query,sizeof(query),"%d", account_id);
  12568. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12569. */
  12570. clif_account_name(fd, account_id, "");
  12571. }
  12572. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12573. /// GM single cell type change request.
  12574. /// 0198 <x>.W <y>.W <type>.W
  12575. /// type:
  12576. /// 0 = not walkable
  12577. /// 1 = walkable
  12578. void clif_parse_GMChangeMapType(int fd, map_session_data *sd)
  12579. {
  12580. int x,y,type;
  12581. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12582. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12583. return;
  12584. x = RFIFOW(fd,info->pos[0]);
  12585. y = RFIFOW(fd,info->pos[1]);
  12586. type = RFIFOW(fd,info->pos[2]);
  12587. map_setgatcell(sd->bl.m,x,y,type);
  12588. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12589. //FIXME: once players leave the map, the client 'forgets' this information.
  12590. }
  12591. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12592. /// Request to allow/deny whispers from a nick.
  12593. /// 00cf <nick>.24B <type>.B
  12594. /// type:
  12595. /// 0 = (/ex nick) deny speech from nick
  12596. /// 1 = (/in nick) allow speech from nick
  12597. void clif_parse_PMIgnore(int fd, map_session_data* sd)
  12598. {
  12599. char* nick;
  12600. uint8 type;
  12601. int i;
  12602. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12603. nick = RFIFOCP(fd,info->pos[0]);
  12604. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12605. type = RFIFOB(fd,info->pos[1]);
  12606. if( type == 0 ) { // Add name to ignore list (block)
  12607. if (strcmp(wisp_server_name, nick) == 0) {
  12608. clif_wisexin(sd, type, 1); // fail
  12609. return;
  12610. }
  12611. // try to find a free spot, while checking for duplicates at the same time
  12612. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12613. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12614. clif_wisexin(sd, type, 2); // too many blocks
  12615. return;
  12616. }
  12617. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12618. clif_wisexin(sd, type, 0); // Aegis reports success.
  12619. return;
  12620. }
  12621. //Insert in position i
  12622. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12623. } else { // Remove name from ignore list (unblock)
  12624. // find entry
  12625. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12626. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[0] == '\0' ) { //Not found
  12627. clif_wisexin(sd, type, 1); // fail
  12628. return;
  12629. }
  12630. // move everything one place down to overwrite removed entry
  12631. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12632. // wipe last entry
  12633. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12634. }
  12635. clif_wisexin(sd, type, 0); // success
  12636. }
  12637. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12638. /// Request to allow/deny all whispers.
  12639. /// 00d0 <type>.B
  12640. /// type:
  12641. /// 0 = (/exall) deny all speech
  12642. /// 1 = (/inall) allow all speech
  12643. void clif_parse_PMIgnoreAll(int fd, map_session_data *sd)
  12644. {
  12645. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12646. if( type == 0 ) {// Deny all
  12647. if( sd->state.ignoreAll ) {
  12648. flag = 1; // fail
  12649. } else {
  12650. sd->state.ignoreAll = 1;
  12651. flag = 0; // success
  12652. }
  12653. } else {//Unblock everyone
  12654. if( sd->state.ignoreAll ) {
  12655. sd->state.ignoreAll = 0;
  12656. flag = 0; // success
  12657. } else {
  12658. if (sd->ignore[0].name[0] != '\0')
  12659. { //Wipe the ignore list.
  12660. memset(sd->ignore, 0, sizeof(sd->ignore));
  12661. flag = 0; // success
  12662. } else {
  12663. flag = 1; // fail
  12664. }
  12665. }
  12666. }
  12667. clif_wisall(sd, type, flag);
  12668. }
  12669. /// Whisper ignore list (ZC_WHISPER_LIST).
  12670. /// 00d4 <packet len>.W { <char name>.24B }*
  12671. void clif_PMIgnoreList(map_session_data* sd)
  12672. {
  12673. int i, fd = sd->fd;
  12674. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12675. WFIFOW(fd,0) = 0xd4;
  12676. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12677. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12678. }
  12679. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12680. WFIFOSET(fd,WFIFOW(fd,2));
  12681. }
  12682. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12683. /// 00d3
  12684. void clif_parse_PMIgnoreList(int fd,map_session_data *sd)
  12685. {
  12686. clif_PMIgnoreList(sd);
  12687. }
  12688. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12689. /// 01e7
  12690. void clif_parse_NoviceDoriDori(int fd, map_session_data *sd)
  12691. {
  12692. if (sd->state.doridori) return;
  12693. switch (sd->class_&MAPID_UPPERMASK) {
  12694. case MAPID_SOUL_LINKER:
  12695. case MAPID_STAR_GLADIATOR:
  12696. case MAPID_TAEKWON:
  12697. if (!sd->state.rest)
  12698. break;
  12699. [[fallthrough]];
  12700. case MAPID_SUPER_NOVICE:
  12701. case MAPID_SUPER_BABY:
  12702. case MAPID_SUPER_NOVICE_E:
  12703. case MAPID_SUPER_BABY_E:
  12704. sd->state.doridori=1;
  12705. break;
  12706. }
  12707. }
  12708. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12709. /// 01ed
  12710. /// Note: This packet is caused by 7 lines of any text, followed by
  12711. /// the prayer and an another line of any text. The prayer is
  12712. /// defined by lines 790~793 in data\msgstringtable.txt
  12713. /// "Dear angel, can you hear my voice?"
  12714. /// "I am" (space separated player name) "Super Novice~"
  12715. /// "Help me out~ Please~ T_T"
  12716. void clif_parse_NoviceExplosionSpirits(int fd, map_session_data *sd)
  12717. {
  12718. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12719. t_exp next = pc_nextbaseexp(sd);
  12720. if( next ) {
  12721. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12722. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12723. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12724. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12725. }
  12726. }
  12727. }
  12728. }
  12729. /// Friends List
  12730. ///
  12731. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12732. /// 0206 <account id>.L <char id>.L <state>.B
  12733. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12734. /// state:
  12735. /// 0 = online
  12736. /// 1 = offline
  12737. void clif_friendslist_toggle(map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12738. {
  12739. int i, fd = sd->fd;
  12740. //Seek friend.
  12741. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12742. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12743. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12744. return; //Not found
  12745. WFIFOHEAD(fd,packet_len(0x206));
  12746. WFIFOW(fd, 0) = 0x206;
  12747. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12748. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12749. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12750. #if PACKETVER >= 20180221
  12751. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12752. #endif
  12753. WFIFOSET(fd, packet_len(0x206));
  12754. }
  12755. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12756. int clif_friendslist_toggle_sub(map_session_data *sd,va_list ap)
  12757. {
  12758. uint32 account_id, char_id, online;
  12759. account_id = va_arg(ap, int);
  12760. char_id = va_arg(ap, int);
  12761. online = va_arg(ap, int);
  12762. clif_friendslist_toggle(sd, account_id, char_id, online);
  12763. return 0;
  12764. }
  12765. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12766. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12767. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12768. void clif_friendslist_send( map_session_data& sd ){
  12769. struct PACKET_ZC_FRIENDS_LIST* p = (struct PACKET_ZC_FRIENDS_LIST*)packet_buffer;
  12770. p->packetType = HEADER_ZC_FRIENDS_LIST;
  12771. p->PacketLength = sizeof( *p );
  12772. for( int i = 0, c = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12773. struct PACKET_ZC_FRIENDS_LIST_sub& f = p->friends[c];
  12774. f.AID = sd.status.friends[i].account_id;
  12775. f.CID = sd.status.friends[i].char_id;
  12776. #if !( PACKETVER_MAIN_NUM >= 20180307 || PACKETVER_RE_NUM >= 20180221 || PACKETVER_ZERO_NUM >= 20180328 ) || PACKETVER >= 20200902
  12777. safestrncpy( f.name, sd.status.friends[i].name, sizeof( f.name ) );
  12778. #endif
  12779. c++;
  12780. p->PacketLength += sizeof( f );
  12781. }
  12782. clif_send( p, p->PacketLength, &sd.bl, SELF );
  12783. // Sending the online players
  12784. for( int i = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12785. if( map_charid2sd( sd.status.friends[i].char_id ) ){
  12786. clif_friendslist_toggle( &sd, sd.status.friends[i].account_id, sd.status.friends[i].char_id, 1 );
  12787. }
  12788. }
  12789. }
  12790. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12791. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12792. /// result:
  12793. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12794. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12795. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12796. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12797. void clif_friendslist_reqack(map_session_data *sd, map_session_data *f_sd, int type)
  12798. {
  12799. int fd;
  12800. nullpo_retv(sd);
  12801. fd = sd->fd;
  12802. WFIFOHEAD(fd,packet_len(0x209));
  12803. WFIFOW(fd,0) = 0x209;
  12804. WFIFOW(fd,2) = type;
  12805. if (f_sd) {
  12806. WFIFOL(fd,4) = f_sd->status.account_id;
  12807. WFIFOL(fd,8) = f_sd->status.char_id;
  12808. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12809. }
  12810. WFIFOSET(fd, packet_len(0x209));
  12811. }
  12812. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12813. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12814. void clif_friendlist_req(map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12815. {
  12816. int fd = sd->fd;
  12817. WFIFOHEAD(fd,packet_len(0x207));
  12818. WFIFOW(fd,0) = 0x207;
  12819. WFIFOL(fd,2) = account_id;
  12820. WFIFOL(fd,6) = char_id;
  12821. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12822. WFIFOSET(fd,packet_len(0x207));
  12823. }
  12824. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12825. /// 0202 <name>.24B
  12826. void clif_parse_FriendsListAdd(int fd, map_session_data *sd)
  12827. {
  12828. map_session_data *f_sd;
  12829. int i;
  12830. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12831. // Friend doesn't exist (no player with this name)
  12832. if (f_sd == NULL) {
  12833. clif_displaymessage(fd, msg_txt(sd,3));
  12834. return;
  12835. }
  12836. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12837. return;
  12838. }
  12839. // ensure that the request player's friend list is not full
  12840. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12841. if( i == MAX_FRIENDS ){
  12842. clif_friendslist_reqack(sd, f_sd, 2);
  12843. return;
  12844. }
  12845. // @noask [LuzZza]
  12846. if(f_sd->state.noask) {
  12847. clif_noask_sub(sd, f_sd, 5);
  12848. return;
  12849. }
  12850. // Friend already exists
  12851. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12852. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12853. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12854. return;
  12855. }
  12856. }
  12857. f_sd->friend_req = sd->status.char_id;
  12858. sd->friend_req = f_sd->status.char_id;
  12859. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12860. }
  12861. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12862. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12863. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12864. /// reply:
  12865. /// 0 = rejected
  12866. /// 1 = accepted
  12867. void clif_parse_FriendsListReply(int fd, map_session_data *sd)
  12868. {
  12869. map_session_data *f_sd;
  12870. uint32 account_id;
  12871. char reply;
  12872. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12873. account_id = RFIFOL(fd,info->pos[0]);
  12874. //char_id = RFIFOL(fd,info->pos[1]);
  12875. #if PACKETVER < 6
  12876. reply = RFIFOB(fd,info->pos[2]);
  12877. #else
  12878. reply = RFIFOL(fd,info->pos[2]);
  12879. #endif
  12880. if( sd->bl.id == account_id ) {// adding oneself as friend
  12881. return;
  12882. }
  12883. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12884. if (f_sd == NULL)
  12885. return;
  12886. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12887. clif_friendslist_reqack(f_sd, sd, 1);
  12888. else {
  12889. int i;
  12890. // Find an empty slot
  12891. for (i = 0; i < MAX_FRIENDS; i++)
  12892. if (f_sd->status.friends[i].char_id == 0)
  12893. break;
  12894. if (i == MAX_FRIENDS) {
  12895. clif_friendslist_reqack(f_sd, sd, 2);
  12896. return;
  12897. }
  12898. f_sd->status.friends[i].account_id = sd->status.account_id;
  12899. f_sd->status.friends[i].char_id = sd->status.char_id;
  12900. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12901. clif_friendslist_reqack(f_sd, sd, 0);
  12902. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12903. if (battle_config.friend_auto_add) {
  12904. // Also add f_sd to sd's friendlist.
  12905. for (i = 0; i < MAX_FRIENDS; i++) {
  12906. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12907. return; //No need to add anything.
  12908. if (sd->status.friends[i].char_id == 0)
  12909. break;
  12910. }
  12911. if (i == MAX_FRIENDS) {
  12912. clif_friendslist_reqack(sd, f_sd, 2);
  12913. return;
  12914. }
  12915. sd->status.friends[i].account_id = f_sd->status.account_id;
  12916. sd->status.friends[i].char_id = f_sd->status.char_id;
  12917. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12918. clif_friendslist_reqack(sd, f_sd, 0);
  12919. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12920. }
  12921. }
  12922. }
  12923. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12924. /// 0203 <account id>.L <char id>.L
  12925. void clif_parse_FriendsListRemove(int fd, map_session_data *sd)
  12926. {
  12927. map_session_data *f_sd = NULL;
  12928. uint32 account_id, char_id;
  12929. int i, j;
  12930. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12931. account_id = RFIFOL(fd,info->pos[0]);
  12932. char_id = RFIFOL(fd,info->pos[1]);
  12933. // Search friend
  12934. for (i = 0; i < MAX_FRIENDS &&
  12935. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12936. if (i == MAX_FRIENDS) {
  12937. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12938. return;
  12939. }
  12940. //remove from friend's list first
  12941. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12942. for (i = 0; i < MAX_FRIENDS &&
  12943. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12944. if (i != MAX_FRIENDS) {
  12945. // move all chars up
  12946. for(j = i + 1; j < MAX_FRIENDS; j++)
  12947. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12948. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12949. //should the guy be notified of some message? we should add it here if so
  12950. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12951. WFIFOW(f_sd->fd,0) = 0x20a;
  12952. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12953. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12954. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12955. }
  12956. } else { //friend not online -- ask char server to delete from his friendlist
  12957. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12958. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12959. return;
  12960. }
  12961. }
  12962. // We can now delete from original requester
  12963. for (i = 0; i < MAX_FRIENDS &&
  12964. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12965. // move all chars up
  12966. for(j = i + 1; j < MAX_FRIENDS; j++)
  12967. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12968. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12969. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12970. WFIFOHEAD(fd,packet_len(0x20a));
  12971. WFIFOW(fd,0) = 0x20a;
  12972. WFIFOL(fd,2) = account_id;
  12973. WFIFOL(fd,6) = char_id;
  12974. WFIFOSET(fd, packet_len(0x20a));
  12975. }
  12976. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12977. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12978. void clif_PVPInfo(map_session_data* sd)
  12979. {
  12980. int fd = sd->fd;
  12981. WFIFOHEAD(fd,packet_len(0x210));
  12982. WFIFOW(fd,0) = 0x210;
  12983. WFIFOL(fd,2) = sd->status.char_id;
  12984. WFIFOL(fd,6) = sd->status.account_id;
  12985. WFIFOL(fd,10) = sd->pvp_won; // times won
  12986. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12987. WFIFOL(fd,18) = sd->pvp_point;
  12988. WFIFOSET(fd, packet_len(0x210));
  12989. }
  12990. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12991. /// 020f <char id>.L <account id>.L
  12992. void clif_parse_PVPInfo(int fd,map_session_data *sd)
  12993. {
  12994. // TODO: Is there a way to use this on an another player (char/acc id)?
  12995. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12996. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12997. clif_PVPInfo(sd);
  12998. }
  12999. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  13000. /// 0254 <which>.B
  13001. /// which: (unused atm for security purpose)
  13002. /// 0 = sun
  13003. /// 1 = moon
  13004. /// 2 = star
  13005. void clif_parse_FeelSaveOk(int fd,map_session_data *sd)
  13006. {
  13007. int i;
  13008. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13009. if (sd->menuskill_id != SG_FEEL)
  13010. return;
  13011. i = sd->menuskill_val-1;
  13012. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  13013. sd->feel_map[i].index = map_id2index(sd->bl.m);
  13014. sd->feel_map[i].m = sd->bl.m;
  13015. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  13016. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  13017. // clif_misceffect2(&sd->bl, 0x1b0);
  13018. // clif_misceffect2(&sd->bl, 0x21f);
  13019. clif_feel_info(sd, i, 0);
  13020. clif_menuskill_clear(sd);
  13021. }
  13022. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  13023. /// 0253 <which>.B
  13024. /// which:
  13025. /// 0 = sun
  13026. /// 1 = moon
  13027. /// 2 = star
  13028. void clif_feel_req(int fd, map_session_data *sd, uint16 skill_lv)
  13029. {
  13030. WFIFOHEAD(fd,packet_len(0x253));
  13031. WFIFOW(fd,0)=0x253;
  13032. WFIFOB(fd,2)=TOB(skill_lv-1);
  13033. WFIFOSET(fd, packet_len(0x253));
  13034. sd->menuskill_id = SG_FEEL;
  13035. sd->menuskill_val = skill_lv;
  13036. }
  13037. /// Request to change homunculus' name (CZ_RENAME_MER).
  13038. /// 0231 <name>.24B
  13039. void clif_parse_ChangeHomunculusName(int fd, map_session_data *sd){
  13040. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  13041. }
  13042. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  13043. /// 0234 <id>.L
  13044. void clif_parse_HomMoveToMaster(int fd, map_session_data *sd){
  13045. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  13046. struct block_list *bl = NULL;
  13047. struct unit_data *ud = NULL;
  13048. if( sd->md && sd->md->bl.id == id )
  13049. bl = &sd->md->bl;
  13050. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13051. bl = &sd->hd->bl; // Moving Homunculus
  13052. else
  13053. return;
  13054. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  13055. ud = unit_bl2ud(bl);
  13056. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  13057. }
  13058. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  13059. /// 0232 <id>.L <position data>.3B
  13060. void clif_parse_HomMoveTo(int fd, map_session_data *sd){
  13061. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13062. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  13063. struct block_list *bl = NULL;
  13064. short x, y;
  13065. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  13066. if( sd->md && sd->md->bl.id == id )
  13067. bl = &sd->md->bl; // Moving Mercenary
  13068. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13069. bl = &sd->hd->bl; // Moving Homunculus
  13070. else
  13071. return;
  13072. unit_walktoxy(bl, x, y, 4);
  13073. }
  13074. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  13075. /// 0233 <id>.L <target id>.L <action>.B
  13076. /// action:
  13077. /// always 0
  13078. void clif_parse_HomAttack(int fd,map_session_data *sd)
  13079. {
  13080. struct block_list *bl = NULL;
  13081. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13082. int id = RFIFOL(fd,info->pos[0]);
  13083. int target_id = RFIFOL(fd,info->pos[1]);
  13084. int action_type = RFIFOB(fd,info->pos[2]);
  13085. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  13086. bl = &sd->hd->bl;
  13087. else if( sd->md && sd->md->bl.id == id )
  13088. bl = &sd->md->bl;
  13089. else return;
  13090. unit_stop_attack(bl);
  13091. unit_attack(bl, target_id, action_type != 0);
  13092. }
  13093. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  13094. /// 022d <type>.W <command>.B
  13095. /// type:
  13096. /// always 0
  13097. /// command:
  13098. /// 0 = homunculus information
  13099. /// 1 = feed
  13100. /// 2 = delete
  13101. void clif_parse_HomMenu(int fd, map_session_data *sd)
  13102. { //[orn]
  13103. int cmd = RFIFOW(fd,0);
  13104. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  13105. if(!hom_is_active(sd->hd))
  13106. return;
  13107. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  13108. }
  13109. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  13110. /// 0292
  13111. void clif_parse_AutoRevive(int fd, map_session_data *sd)
  13112. {
  13113. pc_revive_item(sd);
  13114. }
  13115. /// Information about character's status values (ZC_ACK_STATUS_GM).
  13116. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  13117. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  13118. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  13119. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  13120. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  13121. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  13122. void clif_check(int fd, map_session_data* pl_sd)
  13123. {
  13124. WFIFOHEAD(fd,packet_len(0x214));
  13125. WFIFOW(fd, 0) = 0x214;
  13126. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  13127. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  13128. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  13129. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  13130. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  13131. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  13132. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  13133. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  13134. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  13135. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  13136. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  13137. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  13138. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  13139. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  13140. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  13141. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  13142. WFIFOW(fd,22) = pl_sd->battle_status.def;
  13143. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  13144. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  13145. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  13146. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  13147. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  13148. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  13149. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  13150. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  13151. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  13152. WFIFOSET(fd,packet_len(0x214));
  13153. }
  13154. /// /check (CZ_REQ_STATUS_GM).
  13155. /// Request character's status values.
  13156. /// 0213 <char name>.24B
  13157. void clif_parse_Check(int fd, map_session_data *sd)
  13158. {
  13159. char charname[NAME_LENGTH];
  13160. map_session_data* pl_sd;
  13161. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  13162. return;
  13163. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  13164. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  13165. {
  13166. return;
  13167. }
  13168. clif_check(fd, pl_sd);
  13169. }
  13170. /// MAIL SYSTEM
  13171. /// By Zephyrus
  13172. ///
  13173. /// Notification about the result of adding an item to mail
  13174. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13175. /// result:
  13176. /// 0 = success
  13177. /// 1 = failure
  13178. /// 0a05 <result>.B <index>.W <amount>.W <item id>.W <item type>.B <identified>.B <damaged>.B <refine>.B (ZC_ACK_ADD_ITEM_TO_MAIL)
  13179. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13180. /// result:
  13181. /// 0 = success
  13182. /// 1 = over weight
  13183. /// 2 = fatal error
  13184. void clif_Mail_setattachment( map_session_data* sd, int index, int amount, uint8 flag ){
  13185. int fd = sd->fd;
  13186. #if PACKETVER < 20150513
  13187. WFIFOHEAD(fd,packet_len(0x255));
  13188. WFIFOW(fd,0) = 0x255;
  13189. WFIFOW(fd,2) = index;
  13190. WFIFOB(fd,4) = flag;
  13191. WFIFOSET(fd,packet_len(0x255));
  13192. #else
  13193. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13194. if( flag ){
  13195. memset( &p, 0, sizeof( p ) );
  13196. }else{
  13197. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13198. p.index = index;
  13199. p.count = amount;
  13200. p.itemId = client_nameid( item->nameid );
  13201. p.type = itemtype( item->nameid );
  13202. p.IsIdentified = item->identify ? 1 : 0;
  13203. p.IsDamaged = item->attribute ? 1 : 0;
  13204. p.refiningLevel = item->refine;
  13205. clif_addcards( &p.slot, item );
  13206. clif_add_random_options( p.optionData, *item );
  13207. p.weight = 0;
  13208. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13209. if( sd->mail.item[i].nameid == 0 ){
  13210. continue;
  13211. }
  13212. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13213. }
  13214. p.favorite = item->favorite;
  13215. p.location = pc_equippoint( sd, server_index( index ) );
  13216. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13217. p.grade = item->enchantgrade;
  13218. #endif
  13219. }
  13220. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13221. p.result = flag;
  13222. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13223. #endif
  13224. }
  13225. /// Notification about the result of retrieving a mail attachment
  13226. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13227. /// result:
  13228. /// 0 = success
  13229. /// 1 = failure
  13230. /// 2 = too many items
  13231. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13232. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13233. void clif_mail_getattachment(map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13234. #if PACKETVER < 20150513
  13235. int fd = sd->fd;
  13236. WFIFOHEAD(fd,packet_len(0x245));
  13237. WFIFOW(fd,0) = 0x245;
  13238. WFIFOB(fd,2) = result;
  13239. WFIFOSET(fd,packet_len(0x245));
  13240. #else
  13241. switch( type ){
  13242. case MAIL_ATT_ITEM:
  13243. case MAIL_ATT_ZENY:
  13244. break;
  13245. default:
  13246. return;
  13247. }
  13248. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13249. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13250. p.MailID = msg->id;
  13251. p.opentype = msg->type;
  13252. p.result = result;
  13253. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13254. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13255. #endif
  13256. }
  13257. /// Notification about the result of sending a mail
  13258. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13259. /// result:
  13260. /// 0 = success
  13261. /// 1 = recipinent does not exist
  13262. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13263. void clif_Mail_send(map_session_data* sd, enum mail_send_result result){
  13264. #if PACKETVER < 20150513
  13265. int fd = sd->fd;
  13266. WFIFOHEAD(fd,packet_len(0x249));
  13267. WFIFOW(fd,0) = 0x249;
  13268. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13269. WFIFOSET(fd,packet_len(0x249));
  13270. #else
  13271. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13272. p.PacketType = rodexwriteresult;
  13273. p.result = result;
  13274. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13275. #endif
  13276. }
  13277. /// Notification about the result of deleting a mail.
  13278. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13279. /// result:
  13280. /// 0 = success
  13281. /// 1 = failure
  13282. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13283. void clif_mail_delete( map_session_data* sd, struct mail_message *msg, bool success ){
  13284. #if PACKETVER < 20150513
  13285. int fd = sd->fd;
  13286. WFIFOHEAD(fd, packet_len(0x257));
  13287. WFIFOW(fd,0) = 0x257;
  13288. WFIFOL(fd,2) = msg->id;
  13289. WFIFOW(fd,6) = !success;
  13290. WFIFOSET(fd, packet_len(0x257));
  13291. #else
  13292. // This is only a success notification
  13293. if( success ){
  13294. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13295. p.PacketType = rodexdelete;
  13296. p.opentype = msg->type;
  13297. p.MailID = msg->id;
  13298. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13299. }
  13300. #endif
  13301. }
  13302. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13303. /// 0274 <mail id>.L <result>.W
  13304. /// result:
  13305. /// 0 = success
  13306. /// 1 = failure
  13307. void clif_Mail_return(int fd, int mail_id, short fail)
  13308. {
  13309. WFIFOHEAD(fd,packet_len(0x274));
  13310. WFIFOW(fd,0) = 0x274;
  13311. WFIFOL(fd,2) = mail_id;
  13312. WFIFOW(fd,6) = fail;
  13313. WFIFOSET(fd,packet_len(0x274));
  13314. }
  13315. /// Notification about new mail.
  13316. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13317. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13318. void clif_Mail_new(map_session_data* sd, int mail_id, const char *sender, const char *title){
  13319. #if PACKETVER < 20150513
  13320. int fd = sd->fd;
  13321. WFIFOHEAD(fd,packet_len(0x24a));
  13322. WFIFOW(fd,0) = 0x24a;
  13323. WFIFOL(fd,2) = mail_id;
  13324. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13325. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13326. WFIFOSET(fd,packet_len(0x24a));
  13327. #else
  13328. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13329. p.PacketType = rodexicon;
  13330. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13331. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13332. #endif
  13333. }
  13334. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13335. /// 0260 <type>.L
  13336. /// type:
  13337. /// 0 = open
  13338. /// 1 = close
  13339. void clif_Mail_window(int fd, int flag)
  13340. {
  13341. WFIFOHEAD(fd,packet_len(0x260));
  13342. WFIFOW(fd,0) = 0x260;
  13343. WFIFOL(fd,2) = flag;
  13344. WFIFOSET(fd,packet_len(0x260));
  13345. }
  13346. /// Lists mails stored in inbox.
  13347. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13348. /// read:
  13349. /// 0 = unread
  13350. /// 1 = read
  13351. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13352. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13353. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13354. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13355. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13356. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13357. void clif_Mail_refreshinbox(map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13358. #if PACKETVER < 20150513
  13359. int fd = sd->fd;
  13360. struct mail_data *md = &sd->mail.inbox;
  13361. struct mail_message *msg;
  13362. int len, i, j;
  13363. len = 8 + (73 * md->amount);
  13364. WFIFOHEAD(fd,len);
  13365. WFIFOW(fd,0) = 0x240;
  13366. WFIFOW(fd,2) = len;
  13367. WFIFOL(fd,4) = md->amount;
  13368. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13369. {
  13370. msg = &md->msg[i];
  13371. if (msg->id < 1)
  13372. continue;
  13373. WFIFOL(fd,8+73*j) = msg->id;
  13374. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13375. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13376. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13377. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13378. j++;
  13379. }
  13380. WFIFOSET(fd,len);
  13381. if( md->full ) {// TODO: is this official?
  13382. char output[100];
  13383. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13384. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13385. }
  13386. #else
  13387. int fd = sd->fd;
  13388. struct mail_data *md = &sd->mail.inbox;
  13389. struct mail_message *msg;
  13390. int i, j, k, offset, titleLength;
  13391. uint8 mailType, amount, remaining;
  13392. uint32 now = (uint32)time(NULL);
  13393. #if PACKETVER >= 20170419
  13394. int cmd = 0xac2;
  13395. #elif PACKETVER >= 20160601
  13396. int cmd = 0xa7d;
  13397. #else
  13398. int cmd = 0x9f0;
  13399. #endif
  13400. if( battle_config.mail_daily_count ){
  13401. mail_refresh_remaining_amount(sd);
  13402. }
  13403. #if PACKETVER >= 20170419
  13404. // Always send all
  13405. i = md->amount;
  13406. #else
  13407. // If a starting mail id was sent
  13408. if( mailID != 0 ){
  13409. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13410. // Unknown mail
  13411. if( i == md->amount ){
  13412. // Ignore the request for now
  13413. return; // TODO: Should we just show the first page instead?
  13414. }
  13415. // It was actually the oldest/first mail, there is no further page
  13416. if( i == 0 ){
  13417. return;
  13418. }
  13419. // We actually want the next/older mail
  13420. i -= 1;
  13421. }else{
  13422. i = md->amount;
  13423. }
  13424. #endif
  13425. // Count the remaining mails from the starting mail or the beginning
  13426. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13427. for( j = i, remaining = 0; j >= 0; j-- ){
  13428. msg = &md->msg[j];
  13429. if (msg->id < 1)
  13430. continue;
  13431. #if PACKETVER < 20170419
  13432. if (msg->type != type)
  13433. continue;
  13434. #endif
  13435. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13436. continue;
  13437. remaining++;
  13438. }
  13439. #if PACKETVER >= 20170419
  13440. // Always send all
  13441. amount = remaining;
  13442. #else
  13443. if( remaining > MAIL_PAGE_SIZE ){
  13444. amount = MAIL_PAGE_SIZE;
  13445. }else{
  13446. amount = remaining;
  13447. }
  13448. #endif
  13449. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13450. WFIFOW(fd, 0) = cmd;
  13451. #if PACKETVER >= 20170419
  13452. WFIFOB(fd, 4) = 1; // Unknown
  13453. offset = 5;
  13454. #else
  13455. WFIFOB(fd, 4) = type;
  13456. WFIFOB(fd, 5) = amount;
  13457. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13458. offset = 7;
  13459. #endif
  13460. for( amount = 0; i >= 0; i-- ){
  13461. msg = &md->msg[i];
  13462. if (msg->id < 1)
  13463. continue;
  13464. #if PACKETVER < 20170419
  13465. if (msg->type != type)
  13466. continue;
  13467. #endif
  13468. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13469. continue;
  13470. #if PACKETVER >= 20170419
  13471. WFIFOB(fd, offset) = msg->type;
  13472. offset += 1;
  13473. #endif
  13474. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13475. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13476. mailType = MAIL_TYPE_TEXT; // Normal letter
  13477. if( msg->zeny > 0 ){
  13478. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13479. }
  13480. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13481. if( msg->item[k].nameid > 0 ){
  13482. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13483. break;
  13484. }
  13485. }
  13486. #if PACKETVER >= 20170419
  13487. // If it came from an npc?
  13488. if( !msg->send_id ){
  13489. mailType |= MAIL_TYPE_NPC;
  13490. }
  13491. #endif
  13492. WFIFOB(fd, offset + 9) = mailType;
  13493. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13494. #if PACKETVER < 20170419
  13495. // How much time has passed since you received the mail
  13496. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13497. offset += 4;
  13498. #endif
  13499. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13500. if( msg->scheduled_deletion > 0 ){
  13501. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13502. }else{
  13503. // Fake the scheduled deletion to one year in the future
  13504. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13505. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13506. }
  13507. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13508. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13509. offset += 40 + titleLength;
  13510. }
  13511. WFIFOW(fd, 2) = (int16)offset;
  13512. WFIFOSET(fd, offset);
  13513. #endif
  13514. }
  13515. /// Mail inbox list request.
  13516. /// 023f (CZ_MAIL_GET_LIST)
  13517. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13518. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13519. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13520. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13521. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13522. void clif_parse_Mail_refreshinbox(int fd, map_session_data *sd){
  13523. if( mail_invalid_operation( sd ) ){
  13524. return;
  13525. }
  13526. #if PACKETVER < 20150513
  13527. struct mail_data* md = &sd->mail.inbox;
  13528. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13529. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13530. else
  13531. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13532. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13533. mail_removezeny(sd, false);
  13534. #else
  13535. int cmd = RFIFOW(fd, 0);
  13536. #if PACKETVER < 20170419
  13537. uint8 openType = RFIFOB(fd, 2);
  13538. uint64 mailId = RFIFOQ(fd, 3);
  13539. #else
  13540. uint8 openType;
  13541. uint64 mailId = RFIFOQ(fd, 2);
  13542. int i;
  13543. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13544. if( i == MAIL_MAX_INBOX ){
  13545. openType = MAIL_INBOX_NORMAL;
  13546. mailId = 0;
  13547. }else{
  13548. openType = sd->mail.inbox.msg[i].type;
  13549. mailId = 0;
  13550. }
  13551. #endif
  13552. switch( openType ){
  13553. case MAIL_INBOX_NORMAL:
  13554. case MAIL_INBOX_ACCOUNT:
  13555. case MAIL_INBOX_RETURNED:
  13556. break;
  13557. default:
  13558. // Unknown type: ignore request
  13559. return;
  13560. }
  13561. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13562. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13563. return;
  13564. }
  13565. // If it is not a next page request
  13566. if( cmd != 0x9ee ){
  13567. mailId = 0;
  13568. }
  13569. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13570. #endif
  13571. }
  13572. /// Opens a mail
  13573. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13574. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13575. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13576. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13577. /// { }*n
  13578. // TODO: Packet description => for repeated block
  13579. void clif_Mail_read( map_session_data *sd, int mail_id ){
  13580. int i, fd = sd->fd;
  13581. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13582. if( i == MAIL_MAX_INBOX ) {
  13583. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13584. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13585. return;
  13586. } else {
  13587. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13588. struct item *item;
  13589. int msg_len = strlen(msg->body);
  13590. if( msg_len == 0 ) {
  13591. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13592. msg_len = strlen(msg->body);
  13593. }
  13594. #if PACKETVER < 20150513
  13595. item = &msg->item[0];
  13596. int len = 101 + msg_len;
  13597. WFIFOHEAD(fd,len);
  13598. WFIFOW(fd,0) = 0x242;
  13599. WFIFOW(fd,2) = len;
  13600. WFIFOL(fd,4) = msg->id;
  13601. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13602. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13603. WFIFOL(fd,72) = 0;
  13604. WFIFOL(fd,76) = msg->zeny;
  13605. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13606. if( item->nameid && data != nullptr ) {
  13607. WFIFOL(fd,80) = item->amount;
  13608. WFIFOW(fd,84) = client_nameid( item->nameid );
  13609. WFIFOW(fd,86) = itemtype( item->nameid );
  13610. WFIFOB(fd,88) = item->identify;
  13611. WFIFOB(fd,89) = item->attribute;
  13612. WFIFOB(fd,90) = item->refine;
  13613. WFIFOW(fd,91) = item->card[0];
  13614. WFIFOW(fd,93) = item->card[1];
  13615. WFIFOW(fd,95) = item->card[2];
  13616. WFIFOW(fd,97) = item->card[3];
  13617. } else // no item, set all to zero
  13618. memset(WFIFOP(fd,80), 0x00, 19);
  13619. WFIFOB(fd,99) = (unsigned char)msg_len;
  13620. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13621. WFIFOSET(fd,len);
  13622. #else
  13623. msg_len += 1; // Zero Termination
  13624. struct PACKET_ZC_ACK_READ_RODEX *p = (struct PACKET_ZC_ACK_READ_RODEX *)packet_buffer;
  13625. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13626. p->PacketLength = sizeof( struct PACKET_ZC_ACK_READ_RODEX );
  13627. p->opentype = msg->type;
  13628. p->MailID = msg->id;
  13629. p->TextcontentsLength = msg_len;
  13630. p->zeny = msg->zeny;
  13631. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13632. p->PacketLength += p->TextcontentsLength;
  13633. p->ItemCnt = 0;
  13634. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13635. item = &msg->item[j];
  13636. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13637. if( item->nameid > 0 && item->amount > 0 && data != nullptr ){
  13638. struct PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = (struct PACKET_ZC_ACK_READ_RODEX_SUB*)WBUFP( p, p->PacketLength );
  13639. mailitem->ITID = client_nameid( item->nameid );
  13640. mailitem->count = item->amount;
  13641. mailitem->type = itemtype( item->nameid );
  13642. mailitem->IsIdentified = item->identify ? 1 : 0;
  13643. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13644. mailitem->refiningLevel = item->refine;
  13645. mailitem->location = pc_equippoint_sub( sd, data.get() );
  13646. mailitem->viewSprite = data->look;
  13647. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13648. clif_addcards( &mailitem->slot, item );
  13649. clif_add_random_options( mailitem->option_data, *item );
  13650. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13651. mailitem->grade = item->enchantgrade;
  13652. #endif
  13653. p->PacketLength += sizeof( *mailitem );
  13654. p->ItemCnt++;
  13655. }
  13656. }
  13657. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13658. #endif
  13659. if (msg->status == MAIL_UNREAD) {
  13660. msg->status = MAIL_READ;
  13661. intif_Mail_read(mail_id);
  13662. clif_parse_Mail_refreshinbox(fd, sd);
  13663. sd->mail.inbox.unread--;
  13664. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13665. }
  13666. }
  13667. }
  13668. /// Request to open a mail.
  13669. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13670. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13671. void clif_parse_Mail_read(int fd, map_session_data *sd){
  13672. #if PACKETVER < 20150513
  13673. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13674. #else
  13675. //uint8 openType = RFIFOB(fd, 2);
  13676. int mail_id = (int)RFIFOQ(fd, 3);
  13677. #endif
  13678. if( mail_id <= 0 )
  13679. return;
  13680. if( mail_invalid_operation(sd) )
  13681. return;
  13682. clif_Mail_read(sd, mail_id);
  13683. }
  13684. /// Allow a player to begin writing a mail
  13685. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13686. void clif_send_Mail_beginwrite_ack( map_session_data *sd, char* name, bool success ){
  13687. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13688. p.PacketType = rodexopenwrite;
  13689. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13690. p.result = success;
  13691. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13692. }
  13693. /// Request to start writing a mail
  13694. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13695. void clif_parse_Mail_beginwrite( int fd, map_session_data *sd ){
  13696. char name[NAME_LENGTH];
  13697. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13698. if( mail_invalid_operation( sd ) ){
  13699. return;
  13700. }
  13701. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13702. clif_send_Mail_beginwrite_ack(sd, name, false);
  13703. return;
  13704. }
  13705. mail_clear(sd);
  13706. sd->state.mail_writing = true;
  13707. clif_send_Mail_beginwrite_ack(sd, name,true);
  13708. }
  13709. /// Notification that the client cancelled writing a mail
  13710. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13711. void clif_parse_Mail_cancelwrite( int fd, map_session_data *sd ){
  13712. sd->state.mail_writing = false;
  13713. }
  13714. /// Give the client information about the recipient, if available
  13715. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13716. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13717. void clif_Mail_Receiver_Ack( map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13718. #if PACKETVER >= 20141119
  13719. PACKET_ZC_CHECKNAME p = { 0 };
  13720. p.PacketType = HEADER_ZC_CHECKNAME;
  13721. p.CharId = char_id;
  13722. p.Class = class_;
  13723. p.BaseLevel = level;
  13724. #if PACKETVER >= 20160302
  13725. strncpy(p.Name, name, NAME_LENGTH);
  13726. #endif
  13727. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13728. #endif
  13729. }
  13730. /// Request information about the recipient
  13731. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13732. void clif_parse_Mail_Receiver_Check(int fd, map_session_data *sd) {
  13733. #if PACKETVER >= 20140423
  13734. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13735. struct PACKET_CZ_CHECKNAME2* p = (struct PACKET_CZ_CHECKNAME2*)RFIFOP( fd, 0 );
  13736. #else
  13737. struct PACKET_CZ_CHECKNAME1* p = (struct PACKET_CZ_CHECKNAME1*)RFIFOP( fd, 0 );
  13738. #endif
  13739. static char name[NAME_LENGTH];
  13740. if( mail_invalid_operation( sd ) ){
  13741. return;
  13742. }
  13743. safestrncpy(name, p->Name, NAME_LENGTH);
  13744. intif_mail_checkreceiver(sd, name);
  13745. #endif
  13746. }
  13747. /// Request to receive mail's attachment.
  13748. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13749. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13750. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13751. void clif_parse_Mail_getattach( int fd, map_session_data *sd ){
  13752. int i;
  13753. struct mail_message* msg;
  13754. #if PACKETVER < 20150513
  13755. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13756. int attachment = MAIL_ATT_ALL;
  13757. #else
  13758. uint16 packet_id = RFIFOW(fd, 0);
  13759. int mail_id = (int)RFIFOQ(fd, 2);
  13760. //int openType = RFIFOB(fd, 10);
  13761. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13762. #endif
  13763. if( !chrif_isconnected() )
  13764. return;
  13765. if( mail_id <= 0 )
  13766. return;
  13767. if( mail_invalid_operation(sd) )
  13768. return;
  13769. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13770. if( i == MAIL_MAX_INBOX )
  13771. return;
  13772. msg = &sd->mail.inbox.msg[i];
  13773. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13774. attachment &= ~MAIL_ATT_ZENY;
  13775. }
  13776. if( attachment&MAIL_ATT_ITEM ){
  13777. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13778. // No items were found
  13779. if( i == MAIL_MAX_ITEM ){
  13780. attachment &= ~MAIL_ATT_ITEM;
  13781. }
  13782. }
  13783. // Either no attachment requested at all or there are no zeny or items in the mail
  13784. if( attachment == MAIL_ATT_NONE ){
  13785. return;
  13786. }
  13787. if( attachment&MAIL_ATT_ZENY ){
  13788. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13789. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13790. return;
  13791. }else{
  13792. // Store the pending zeny (required for the "retrieve all" feature)
  13793. sd->mail.pending_zeny += msg->zeny;
  13794. // To make sure another request fails
  13795. msg->zeny = 0;
  13796. }
  13797. }
  13798. if( attachment&MAIL_ATT_ITEM ){
  13799. int slots = 0, totalweight = 0;
  13800. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13801. struct item* item = &msg->item[i];
  13802. if( item->nameid > 0 && item->amount > 0 ){
  13803. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13804. if(data == nullptr)
  13805. continue;
  13806. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13807. case CHKADDITEM_NEW:
  13808. slots += data->inventorySlotNeeded( item->amount );
  13809. break;
  13810. case CHKADDITEM_OVERAMOUNT:
  13811. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13812. return;
  13813. }
  13814. totalweight += data->weight * item->amount;
  13815. }
  13816. }
  13817. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13818. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13819. return;
  13820. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13821. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13822. return;
  13823. }
  13824. // To make sure another request fails
  13825. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13826. // Store the pending weight (required for the "retrieve all" feature)
  13827. sd->mail.pending_weight += totalweight;
  13828. // Store the pending slots (required for the "retrieve all" feature)
  13829. sd->mail.pending_slots += slots;
  13830. }
  13831. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13832. }
  13833. /// Request to delete a mail.
  13834. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13835. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13836. void clif_parse_Mail_delete(int fd, map_session_data *sd){
  13837. #if PACKETVER < 20150513
  13838. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13839. #else
  13840. //int openType = RFIFOB(fd, 2);
  13841. int mail_id = (int)RFIFOQ(fd, 3);
  13842. #endif
  13843. int i, j;
  13844. if( !chrif_isconnected() )
  13845. return;
  13846. if( mail_id <= 0 )
  13847. return;
  13848. if( mail_invalid_operation(sd) )
  13849. return;
  13850. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13851. if (i < MAIL_MAX_INBOX) {
  13852. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13853. // can't delete mail without removing zeny first
  13854. if( msg->zeny > 0 ){
  13855. clif_mail_delete(sd, msg, false);
  13856. return;
  13857. }
  13858. // can't delete mail without removing attachment(s) first
  13859. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13860. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13861. clif_mail_delete(sd, msg, false);
  13862. return;
  13863. }
  13864. }
  13865. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13866. sd->mail.inbox.unread--;
  13867. clif_Mail_new(sd,0,NULL,NULL);
  13868. }
  13869. }
  13870. }
  13871. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13872. /// 0273 <mail id>.L <receive name>.24B
  13873. void clif_parse_Mail_return(int fd, map_session_data *sd){
  13874. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13875. struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN* p = (struct PACKET_CZ_UNCONFIRMED_RODEX_RETURN*)RFIFOP( fd, 0 );
  13876. //ShowDump( p, sizeof( p ) );
  13877. int mail_id = p->msgId;
  13878. // not supported for now
  13879. return;
  13880. #else
  13881. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13882. #endif
  13883. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13884. int i;
  13885. if( mail_id <= 0 )
  13886. return;
  13887. if( mail_invalid_operation(sd) )
  13888. return;
  13889. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13890. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13891. intif_Mail_return(sd->status.char_id, mail_id);
  13892. else
  13893. clif_Mail_return(sd->fd, mail_id, 1);
  13894. }
  13895. /// Request to add an item or Zeny to mail.
  13896. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13897. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13898. void clif_parse_Mail_setattach(int fd, map_session_data *sd){
  13899. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13900. uint16 idx = RFIFOW(fd,info->pos[0]);
  13901. #if PACKETVER < 20150513
  13902. int amount = RFIFOL(fd,info->pos[1]);
  13903. #else
  13904. int amount = RFIFOW(fd,info->pos[1]);
  13905. #endif
  13906. unsigned char flag;
  13907. if( !chrif_isconnected() )
  13908. return;
  13909. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13910. return;
  13911. if (sd->inventory_data[server_index(idx)] == nullptr)
  13912. return;
  13913. if( mail_invalid_operation( sd ) ){
  13914. return;
  13915. }
  13916. flag = mail_setitem(sd, idx, amount);
  13917. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13918. clif_msg( sd, C_ITEM_EQUIP_SWITCH );
  13919. }else{
  13920. clif_Mail_setattachment(sd,idx,amount,flag);
  13921. }
  13922. }
  13923. /// Remove an item from a mail
  13924. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13925. void clif_mail_removeitem( map_session_data* sd, bool success, int index, int amount ){
  13926. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13927. p.PacketType = rodexremoveitem;
  13928. p.result = success;
  13929. p.index = index;
  13930. p.cnt = amount;
  13931. int total = 0;
  13932. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13933. if( sd->mail.item[i].nameid == 0 ){
  13934. break;
  13935. }
  13936. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13937. }
  13938. p.weight = total;
  13939. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13940. }
  13941. /// Request to reset mail item and/or Zeny
  13942. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13943. /// type:
  13944. /// 0 = reset all
  13945. /// 1 = remove item
  13946. /// 2 = remove zeny
  13947. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13948. void clif_parse_Mail_winopen(int fd, map_session_data *sd)
  13949. {
  13950. #if PACKETVER < 20150513
  13951. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13952. if (type == 0 || type == 1)
  13953. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13954. if (type == 0 || type == 2)
  13955. mail_removezeny(sd, false);
  13956. #else
  13957. uint16 index = RFIFOW(fd, 2);
  13958. uint16 count = RFIFOW(fd, 4);
  13959. mail_removeitem(sd,0,index,count);
  13960. #endif
  13961. }
  13962. /// Request to send mail
  13963. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13964. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13965. /// 0a6e <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <char id>.L <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL2)
  13966. void clif_parse_Mail_send(int fd, map_session_data *sd){
  13967. #if PACKETVER < 20150513
  13968. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13969. if( !chrif_isconnected() )
  13970. return;
  13971. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13972. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13973. return;
  13974. }
  13975. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13976. #else
  13977. uint16 length = RFIFOW(fd, 2);
  13978. if( length < 0x3e ){
  13979. ShowWarning("Too short...\n");
  13980. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13981. return;
  13982. }
  13983. if( mail_invalid_operation( sd ) ){
  13984. return;
  13985. }
  13986. // Forged request without a begin writing packet?
  13987. if( !sd->state.mail_writing ){
  13988. return; // Ignore it
  13989. }
  13990. char receiver[NAME_LENGTH];
  13991. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13992. // char sender[NAME_LENGTH];
  13993. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13994. uint64 zeny = RFIFOQ(fd, 52);
  13995. uint16 titleLength = RFIFOW(fd, 60);
  13996. uint16 textLength = RFIFOW(fd, 62);
  13997. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13998. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13999. char title[MAIL_TITLE_LENGTH];
  14000. char text[MAIL_BODY_LENGTH];
  14001. #if PACKETVER <= 20160330
  14002. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  14003. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  14004. #else
  14005. // 64 = <char id>.L
  14006. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  14007. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  14008. #endif
  14009. if( zeny > 0 ){
  14010. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  14011. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  14012. return;
  14013. }
  14014. }
  14015. mail_send(sd, receiver, title, text, realTextLength);
  14016. #endif
  14017. }
  14018. /// AUCTION SYSTEM
  14019. /// By Zephyrus
  14020. ///
  14021. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  14022. /// 025f <type>.L
  14023. /// type:
  14024. /// 0 = open
  14025. /// 1 = close
  14026. void clif_Auction_openwindow(map_session_data *sd)
  14027. {
  14028. int fd = sd->fd;
  14029. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  14030. return;
  14031. if( !battle_config.feature_auction )
  14032. return;
  14033. WFIFOHEAD(fd,packet_len(0x25f));
  14034. WFIFOW(fd,0) = 0x25f;
  14035. WFIFOL(fd,2) = 0;
  14036. WFIFOSET(fd,packet_len(0x25f));
  14037. }
  14038. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  14039. /// 0252 <packet len>.W <pages>.L <count>.L { <auction id>.L <seller name>.24B <name id>.W <type>.L <amount>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <now price>.L <max price>.L <buyer name>.24B <delete time>.L }*
  14040. void clif_Auction_results(map_session_data *sd, short count, short pages, uint8 *buf)
  14041. {
  14042. int i, fd = sd->fd, len = sizeof(struct auction_data);
  14043. struct auction_data auction;
  14044. WFIFOHEAD(fd,12 + (count * 83));
  14045. WFIFOW(fd,0) = 0x252;
  14046. WFIFOW(fd,2) = 12 + (count * 83);
  14047. WFIFOL(fd,4) = pages;
  14048. WFIFOL(fd,8) = count;
  14049. for( i = 0; i < count; i++ ) {
  14050. int k = 12 + (i * 83);
  14051. memcpy(&auction, RBUFP(buf,i * len), len);
  14052. WFIFOL(fd,k) = auction.auction_id;
  14053. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  14054. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  14055. WFIFOL(fd,30+k) = auction.type;
  14056. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  14057. WFIFOB(fd,36+k) = auction.item.identify;
  14058. WFIFOB(fd,37+k) = auction.item.attribute;
  14059. WFIFOB(fd,38+k) = auction.item.refine;
  14060. WFIFOW(fd,39+k) = auction.item.card[0];
  14061. WFIFOW(fd,41+k) = auction.item.card[1];
  14062. WFIFOW(fd,43+k) = auction.item.card[2];
  14063. WFIFOW(fd,45+k) = auction.item.card[3];
  14064. WFIFOL(fd,47+k) = auction.price;
  14065. WFIFOL(fd,51+k) = auction.buynow;
  14066. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  14067. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  14068. }
  14069. WFIFOSET(fd,WFIFOW(fd,2));
  14070. }
  14071. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  14072. /// 0256 <index>.W <result>.B
  14073. /// result:
  14074. /// 0 = success
  14075. /// 1 = failure
  14076. static void clif_Auction_setitem(int fd, int index, bool fail)
  14077. {
  14078. WFIFOHEAD(fd,packet_len(0x256));
  14079. WFIFOW(fd,0) = 0x256;
  14080. WFIFOW(fd,2) = index;
  14081. WFIFOB(fd,4) = fail;
  14082. WFIFOSET(fd,packet_len(0x256));
  14083. }
  14084. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  14085. /// 024b <type>.W
  14086. /// type:
  14087. /// 0 = create (any other action in auction window)
  14088. /// 1 = cancel (cancel pressed on register tab)
  14089. /// ? = junk, uninitialized value (ex. when switching between list filters)
  14090. void clif_parse_Auction_cancelreg(int fd, map_session_data *sd){
  14091. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14092. if( sd->auction.amount > 0 )
  14093. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  14094. sd->auction.amount = 0;
  14095. }
  14096. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  14097. /// 024c <index>.W <count>.L
  14098. void clif_parse_Auction_setitem(int fd, map_session_data *sd){
  14099. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14100. int idx = RFIFOW(fd,info->pos[0]) - 2;
  14101. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  14102. if( !battle_config.feature_auction )
  14103. return;
  14104. if( sd->auction.amount > 0 )
  14105. sd->auction.amount = 0;
  14106. if( idx < 0 || idx >= MAX_INVENTORY ) {
  14107. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  14108. return;
  14109. }
  14110. if( amount != 1 || amount > sd->inventory.u.items_inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  14111. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  14112. return;
  14113. }
  14114. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[idx].nameid);
  14115. if( id != nullptr && !(id->type == IT_ARMOR || id->type == IT_PETARMOR || id->type == IT_WEAPON || id->type == IT_CARD || id->type == IT_ETC || id->type == IT_SHADOWGEAR) )
  14116. { // Consumable or pets are not allowed
  14117. clif_Auction_setitem(sd->fd, idx, true);
  14118. return;
  14119. }
  14120. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  14121. !sd->inventory.u.items_inventory[idx].identify ||
  14122. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  14123. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  14124. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  14125. clif_Auction_setitem(sd->fd, idx, true);
  14126. return;
  14127. }
  14128. sd->auction.index = idx;
  14129. sd->auction.amount = amount;
  14130. clif_Auction_setitem(fd, idx + 2, false);
  14131. }
  14132. /// Result from an auction action (ZC_AUCTION_RESULT).
  14133. /// 0250 <result>.B
  14134. /// result:
  14135. /// 0 = You have failed to bid into the auction
  14136. /// 1 = You have successfully bid in the auction
  14137. /// 2 = The auction has been canceled
  14138. /// 3 = An auction with at least one bidder cannot be canceled
  14139. /// 4 = You cannot register more than 5 items in an auction at a time
  14140. /// 5 = You do not have enough Zeny to pay the Auction Fee
  14141. /// 6 = You have won the auction
  14142. /// 7 = You have failed to win the auction
  14143. /// 8 = You do not have enough Zeny
  14144. /// 9 = You cannot place more than 5 bids at a time
  14145. void clif_Auction_message(int fd, unsigned char flag)
  14146. {
  14147. WFIFOHEAD(fd,packet_len(0x250));
  14148. WFIFOW(fd,0) = 0x250;
  14149. WFIFOB(fd,2) = flag;
  14150. WFIFOSET(fd,packet_len(0x250));
  14151. }
  14152. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  14153. /// 025e <result>.W
  14154. /// result:
  14155. /// 0 = You have ended the auction
  14156. /// 1 = You cannot end the auction
  14157. /// 2 = Auction ID is incorrect
  14158. void clif_Auction_close(int fd, unsigned char flag)
  14159. {
  14160. WFIFOHEAD(fd,packet_len(0x25e));
  14161. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  14162. WFIFOW(fd,2) = flag;
  14163. WFIFOSET(fd,packet_len(0x25e));
  14164. }
  14165. /// Request to add an auction (CZ_AUCTION_ADD).
  14166. /// 024d <now money>.L <max money>.L <delete hour>.W
  14167. void clif_parse_Auction_register(int fd, map_session_data *sd)
  14168. {
  14169. struct auction_data auction;
  14170. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14171. if( !battle_config.feature_auction )
  14172. return;
  14173. auction.price = RFIFOL(fd,info->pos[0]);
  14174. auction.buynow = RFIFOL(fd,info->pos[1]);
  14175. auction.hours = RFIFOW(fd,info->pos[2]);
  14176. // Invalid Situations...
  14177. if( sd->auction.amount < 1 ) {
  14178. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  14179. return;
  14180. }
  14181. if( auction.price >= auction.buynow ) {
  14182. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  14183. return;
  14184. }
  14185. if( auction.hours < 1 || auction.hours > 48 ) {
  14186. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14187. return;
  14188. }
  14189. // Auction checks...
  14190. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14191. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14192. clif_Auction_message(fd, 2); // The auction has been canceled
  14193. return;
  14194. }
  14195. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14196. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14197. return;
  14198. }
  14199. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14200. auction.buynow = battle_config.auction_maximumprice;
  14201. if( auction.price >= auction.buynow )
  14202. auction.price = auction.buynow - 1;
  14203. }
  14204. auction.auction_id = 0;
  14205. auction.seller_id = sd->status.char_id;
  14206. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14207. auction.buyer_id = 0;
  14208. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14209. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14210. {
  14211. clif_Auction_message(fd, 2); // The auction has been canceled
  14212. return;
  14213. }
  14214. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[sd->auction.index].nameid);
  14215. if( id == nullptr )
  14216. { // Just in case
  14217. clif_Auction_message(fd, 2); // The auction has been canceled
  14218. return;
  14219. }
  14220. safestrncpy(auction.item_name, id->ename.c_str(), sizeof(auction.item_name));
  14221. auction.type = id->type;
  14222. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14223. auction.item.amount = 1;
  14224. auction.timestamp = 0;
  14225. if( !intif_Auction_register(&auction) )
  14226. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14227. else
  14228. {
  14229. int zeny = auction.hours*battle_config.auction_feeperhour;
  14230. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14231. sd->auction.amount = 0;
  14232. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION);
  14233. }
  14234. }
  14235. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14236. /// 024e <auction id>.L
  14237. void clif_parse_Auction_cancel(int fd, map_session_data *sd){
  14238. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14239. intif_Auction_cancel(sd->status.char_id, auction_id);
  14240. }
  14241. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14242. /// 025d <auction id>.L
  14243. void clif_parse_Auction_close(int fd, map_session_data *sd){
  14244. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14245. intif_Auction_close(sd->status.char_id, auction_id);
  14246. }
  14247. /// Places a bid on an auction (CZ_AUCTION_BUY).
  14248. /// 024f <auction id>.L <money>.L
  14249. void clif_parse_Auction_bid(int fd, map_session_data *sd){
  14250. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14251. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  14252. int bid = RFIFOL(fd,info->pos[1]);
  14253. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  14254. clif_displaymessage(sd->fd, msg_txt(sd,246));
  14255. return;
  14256. }
  14257. if( bid <= 0 )
  14258. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14259. else if( bid > sd->status.zeny )
  14260. clif_Auction_message(fd, 8); // You do not have enough zeny
  14261. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14262. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14263. else {
  14264. pc_payzeny(sd, bid, LOG_TYPE_AUCTION);
  14265. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14266. }
  14267. }
  14268. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14269. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14270. /// search type:
  14271. /// 0 = armor
  14272. /// 1 = weapon
  14273. /// 2 = card
  14274. /// 3 = misc
  14275. /// 4 = name search
  14276. /// 5 = auction id search
  14277. void clif_parse_Auction_search(int fd, map_session_data* sd){
  14278. char search_text[NAME_LENGTH];
  14279. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14280. short type = RFIFOW(fd,info->pos[0]);
  14281. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14282. int page = RFIFOW(fd,info->pos[3]);
  14283. if( !battle_config.feature_auction )
  14284. return;
  14285. clif_parse_Auction_cancelreg(fd, sd);
  14286. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14287. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14288. }
  14289. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14290. /// 025c <type>.W
  14291. /// type:
  14292. /// 0 = sell (own auctions)
  14293. /// 1 = buy (own bids)
  14294. void clif_parse_Auction_buysell(int fd, map_session_data* sd)
  14295. {
  14296. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14297. if( !battle_config.feature_auction )
  14298. return;
  14299. clif_parse_Auction_cancelreg(fd, sd);
  14300. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14301. }
  14302. /// CASH/POINT SHOP
  14303. ///
  14304. void clif_cashshop_open( map_session_data* sd, int tab ){
  14305. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14306. nullpo_retv( sd );
  14307. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14308. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14309. p.cashPoints = sd->cashPoints;
  14310. p.kafraPoints = sd->kafraPoints;
  14311. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14312. p.tab = tab;
  14313. #endif
  14314. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14315. #endif
  14316. }
  14317. void clif_parse_cashshop_open_request( int fd, map_session_data* sd ){
  14318. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14319. nullpo_retv( sd );
  14320. int tab = 0;
  14321. #if PACKETVER >= 20191224
  14322. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14323. tab = p->tab;
  14324. #endif
  14325. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14326. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14327. return;
  14328. }
  14329. sd->state.cashshop_open = true;
  14330. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14331. clif_cashshop_open( sd, tab );
  14332. #endif
  14333. }
  14334. void clif_parse_cashshop_close( int fd, map_session_data* sd ){
  14335. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14336. sd->state.cashshop_open = false;
  14337. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14338. // No need to do anything here
  14339. #endif
  14340. }
  14341. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14342. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14343. void clif_parse_CashShopReqTab(int fd, map_session_data *sd) {
  14344. #if PACKETVER_MAIN_NUM >= 20100824 || PACKETVER_RE_NUM >= 20100824 || defined(PACKETVER_ZERO)
  14345. struct PACKET_CZ_REQ_SE_CASH_TAB_CODE* p_in = (struct PACKET_CZ_REQ_SE_CASH_TAB_CODE*)RFIFOP( fd, 0 );
  14346. // TODO: most likely wrong answer packet. Most likely HEADER_ZC_ACK_SE_CASH_ITEM_LIST (0x847) would be correct [Lemongrass]
  14347. // [4144] packet exists only in 2011 and was dropped after
  14348. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14349. std::shared_ptr<s_cash_item_tab> tab = cash_shop_db.find( static_cast<e_cash_shop_tab>( p_in->tab ) );
  14350. if( tab == nullptr ){
  14351. return;
  14352. }
  14353. // Skip empty tabs, the client only expects filled ones
  14354. if( tab->items.empty() ){
  14355. return;
  14356. }
  14357. #if !(PACKETVER_SUPPORTS_SALES)
  14358. if( tab->tab == CASHSHOP_TAB_SALE ){
  14359. return;
  14360. }
  14361. #endif
  14362. struct PACKET_ZC_ACK_SE_CASH_ITEM_LIST2* p = (struct PACKET_ZC_ACK_SE_CASH_ITEM_LIST2*)packet_buffer;
  14363. p->packetType = HEADER_ZC_ACK_SE_CASH_ITEM_LIST2;
  14364. p->packetLength = sizeof( struct PACKET_ZC_ACK_SE_CASH_ITEM_LIST2 );
  14365. p->tab = tab->tab;
  14366. p->count = 0;
  14367. for( std::shared_ptr<s_cash_item> item : tab->items ){
  14368. p->items[p->count].itemId = client_nameid( item->nameid );
  14369. p->items[p->count].price = item->price;
  14370. p->packetLength += sizeof( struct PACKET_ZC_ACK_SE_CASH_ITEM_LIST2_sub );
  14371. p->count++;
  14372. }
  14373. clif_send( p, p->packetLength, &sd->bl, SELF );
  14374. #endif
  14375. #endif
  14376. }
  14377. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14378. void clif_cashshop_list( map_session_data* sd ){
  14379. nullpo_retv( sd );
  14380. for( const auto& pair : cash_shop_db ){
  14381. std::shared_ptr<s_cash_item_tab> tab = pair.second;
  14382. // Skip empty tabs, the client only expects filled ones
  14383. if( tab->items.empty() ){
  14384. continue;
  14385. }
  14386. #if !(PACKETVER_SUPPORTS_SALES)
  14387. if( tab->tab == CASHSHOP_TAB_SALE ){
  14388. continue;
  14389. }
  14390. #endif
  14391. struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *p = (struct PACKET_ZC_ACK_SCHEDULER_CASHITEM *)packet_buffer;
  14392. p->packetType = HEADER_ZC_ACK_SCHEDULER_CASHITEM;
  14393. p->packetLength = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM );
  14394. p->count = 0;
  14395. p->tabNum = tab->tab;
  14396. for( std::shared_ptr<s_cash_item> item : tab->items ){
  14397. p->items[p->count].itemId = client_nameid( item->nameid );
  14398. p->items[p->count].price = item->price;
  14399. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14400. struct item_data* id = itemdb_search( item->nameid );
  14401. if( id == nullptr ){
  14402. p->items[p->count].location = 0;
  14403. p->items[p->count].viewSprite = 0;
  14404. }else{
  14405. p->items[p->count].location = pc_equippoint_sub( sd, id );
  14406. p->items[p->count].viewSprite = id->look;
  14407. }
  14408. #endif
  14409. p->count++;
  14410. p->packetLength += sizeof( p->items[0] );
  14411. if( ( static_cast<size_t>( p->packetLength ) + sizeof( p->items[0] ) ) >= INT16_MAX ){
  14412. // Send current data
  14413. clif_send( p, p->packetLength, &sd->bl, SELF );
  14414. // Start a new packet
  14415. p->count = 0;
  14416. p->packetLength = sizeof( struct PACKET_ZC_ACK_SCHEDULER_CASHITEM );
  14417. }
  14418. }
  14419. clif_send( p, p->packetLength, &sd->bl, SELF );
  14420. }
  14421. }
  14422. void clif_parse_cashshop_list_request( int fd, map_session_data* sd ){
  14423. if( !sd->status.cashshop_sent ) {
  14424. clif_cashshop_list( sd );
  14425. #if PACKETVER_SUPPORTS_SALES
  14426. sale_notify_login(sd);
  14427. #endif
  14428. sd->status.cashshop_sent = true;
  14429. }
  14430. }
  14431. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14432. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14433. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14434. void clif_cashshop_show( map_session_data *sd, struct npc_data *nd ){
  14435. nullpo_retv( sd );
  14436. nullpo_retv( nd );
  14437. int fd = sd->fd;
  14438. if( !session_isActive( fd ) ){
  14439. return;
  14440. }
  14441. sd->npc_shopid = nd->bl.id;
  14442. int cost[2] = { 0, 0 };
  14443. npc_shop_currency_type( sd, nd, cost, true );
  14444. struct PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = (struct PACKET_ZC_PC_CASH_POINT_ITEMLIST*)packet_buffer;
  14445. p->packetType = HEADER_ZC_PC_CASH_POINT_ITEMLIST;
  14446. p->packetLength = sizeof( *p );
  14447. p->cashPoints = cost[0];
  14448. #if PACKETVER >= 20070711
  14449. p->kafraPoints = cost[1];
  14450. #endif
  14451. for( int i = 0; i < nd->u.shop.count; i++ ) {
  14452. struct item_data* id = itemdb_search( nd->u.shop.shop_item[i].nameid );
  14453. p->items[i].price = nd->u.shop.shop_item[i].value;
  14454. p->items[i].discountPrice = nd->u.shop.shop_item[i].value; // Discount Price
  14455. p->items[i].itemType = itemtype( id->nameid );
  14456. p->items[i].itemId = client_nameid( id->nameid );
  14457. #ifdef ENABLE_OLD_CASHSHOP_PREVIEW_PATCH
  14458. p->items[i].location = pc_equippoint_sub( sd, id );
  14459. p->items[i].viewSprite = id->look;
  14460. memset( p->items[i].unused, 0, sizeof( p->items[i].unused ) );
  14461. #endif
  14462. p->packetLength += sizeof( p->items[0] );
  14463. }
  14464. clif_send( p, p->packetLength, &sd->bl, SELF );
  14465. }
  14466. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14467. /// 0289 <cash point>.L <error>.W
  14468. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14469. /// error:
  14470. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14471. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14472. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14473. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14474. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14475. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14476. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14477. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14478. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14479. void clif_cashshop_ack(map_session_data* sd, int error)
  14480. {
  14481. int fd, cost[2] = { 0, 0 };
  14482. struct npc_data *nd;
  14483. nullpo_retv(sd);
  14484. fd = sd->fd;
  14485. nd = map_id2nd(sd->npc_shopid);
  14486. npc_shop_currency_type(sd, nd, cost, false);
  14487. WFIFOHEAD(fd, packet_len(0x289));
  14488. WFIFOW(fd,0) = 0x289;
  14489. WFIFOL(fd,2) = cost[0];
  14490. #if PACKETVER < 20070711
  14491. WFIFOW(fd,6) = TOW(error);
  14492. #else
  14493. WFIFOL(fd,6) = cost[1];
  14494. WFIFOW(fd,10) = TOW(error);
  14495. #endif
  14496. WFIFOSET(fd, packet_len(0x289));
  14497. }
  14498. void clif_cashshop_result( map_session_data *sd, t_itemid item_id, uint16 result ){
  14499. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14500. nullpo_retv( sd );
  14501. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet = {};
  14502. packet.packetType = HEADER_ZC_SE_PC_BUY_CASHITEM_RESULT;
  14503. if( item_id != 0 ){
  14504. packet.itemId = client_nameid( item_id );
  14505. }else{
  14506. packet.itemId = 0;
  14507. }
  14508. packet.result = result;
  14509. packet.cashPoints = sd->cashPoints;
  14510. packet.kafraPoints = sd->kafraPoints;
  14511. clif_send( &packet, sizeof( packet ), &sd->bl, SELF );
  14512. #endif
  14513. }
  14514. /// Request to buy item(s) from cash shop.
  14515. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14516. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14517. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14518. void clif_parse_npccashshop_buy( int fd, map_session_data *sd ){
  14519. nullpo_retv( sd );
  14520. if( sd->state.trading || !sd->npc_shopid ){
  14521. clif_cashshop_ack( sd, 1 );
  14522. return;
  14523. }
  14524. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14525. #if PACKETVER < 20070711
  14526. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14527. #elif PACKETVER < 20101116
  14528. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14529. #else
  14530. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14531. if( p->packetLength < sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM ) || p->packetLength != sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM ) + p->count * s_itl ){
  14532. ShowWarning( "Player %u sent incorrect cash shop buy packet (len %u:%" PRIdPTR ")!\n", sd->status.char_id, p->packetLength, sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM ) + p->count * s_itl );
  14533. return;
  14534. }
  14535. std::vector<s_npc_buy_list> item_list = {};
  14536. item_list.reserve( p->count );
  14537. for( int i = 0; i < p->count; i++ ){
  14538. s_npc_buy_list item = {};
  14539. item.nameid = p->items[i].itemId;
  14540. item.qty = p->items[i].amount;
  14541. item_list.push_back( item );
  14542. }
  14543. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14544. #endif
  14545. }
  14546. /// Request to buy item(s) from cash shop.
  14547. /// 0848 <packet len>.W <count>.W <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W <tab>.W }.6B*count (CZ_SE_PC_BUY_CASHITEM_LIST)
  14548. void clif_parse_cashshop_buy( int fd, map_session_data *sd ){
  14549. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14550. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14551. if( p->packetLength < sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST ) || p->packetLength != sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST ) + p->count * s_itl ){
  14552. ShowWarning( "Player %u sent incorrect cash shop buy packet (len %u:%" PRIdPTR ")!\n", sd->status.char_id, p->packetLength, sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST ) + p->count * s_itl );
  14553. return;
  14554. }
  14555. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14556. }
  14557. /// Adoption System
  14558. ///
  14559. /// Adoption message (ZC_BABYMSG).
  14560. /// 0216 <msg>.L
  14561. /// msg:
  14562. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14563. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14564. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14565. void clif_Adopt_reply(map_session_data *sd, int type)
  14566. {
  14567. int fd = sd->fd;
  14568. WFIFOHEAD(fd,6);
  14569. WFIFOW(fd,0) = 0x216;
  14570. WFIFOL(fd,2) = type;
  14571. WFIFOSET(fd,6);
  14572. }
  14573. /// Adoption confirmation (ZC_REQ_BABY).
  14574. /// 01f6 <account id>.L <char id>.L <name>.B
  14575. void clif_Adopt_request(map_session_data *sd, map_session_data *src, int p_id)
  14576. {
  14577. int fd = sd->fd;
  14578. WFIFOHEAD(fd,34);
  14579. WFIFOW(fd,0) = 0x1f6;
  14580. WFIFOL(fd,2) = src->status.account_id;
  14581. WFIFOL(fd,6) = p_id;
  14582. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14583. WFIFOSET(fd,34);
  14584. }
  14585. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14586. /// 01f9 <account id>.L
  14587. void clif_parse_Adopt_request(int fd, map_session_data *sd)
  14588. {
  14589. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14590. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14591. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14592. {
  14593. tsd->adopt_invite = sd->status.account_id;
  14594. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14595. }
  14596. }
  14597. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14598. /// 01f7 <account id>.L <char id>.L <answer>.L
  14599. /// answer:
  14600. /// 0 = rejected
  14601. /// 1 = accepted
  14602. void clif_parse_Adopt_reply(int fd, map_session_data *sd){
  14603. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14604. int p1_id = RFIFOL(fd,info->pos[0]);
  14605. int p2_id = RFIFOL(fd,info->pos[1]);
  14606. int result = RFIFOL(fd,info->pos[2]);
  14607. map_session_data* p1_sd = map_id2sd(p1_id);
  14608. map_session_data* p2_sd = map_id2sd(p2_id);
  14609. int pid = sd->adopt_invite;
  14610. sd->adopt_invite = 0;
  14611. if( p1_sd == NULL || p2_sd == NULL )
  14612. return; // Both players need to be online
  14613. if( pid != p1_sd->status.account_id )
  14614. return; // Incorrect values
  14615. if( result == 0 )
  14616. return; // Rejected
  14617. pc_adoption(p1_sd, p2_sd, sd);
  14618. }
  14619. /// Convex Mirror
  14620. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B (ZC_BOSS_INFO)
  14621. /// infoType:
  14622. /// BOSS_INFO_NOT = No boss on this map.
  14623. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14624. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14625. /// BOSS_INFO_DEAD = Boss is dead.
  14626. void clif_bossmapinfo( map_session_data& sd, mob_data* md, e_bossmap_info flag ){
  14627. PACKET_ZC_BOSS_INFO p = {};
  14628. p.packetType = HEADER_ZC_BOSS_INFO;
  14629. p.type = flag;
  14630. switch (flag) {
  14631. case BOSS_INFO_NOT:
  14632. // No data required
  14633. break;
  14634. case BOSS_INFO_ALIVE_WITHMSG:
  14635. [[fallthrough]];
  14636. case BOSS_INFO_ALIVE:
  14637. p.x = md->bl.x;
  14638. p.y = md->bl.y;
  14639. break;
  14640. case BOSS_INFO_DEAD: {
  14641. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14642. unsigned int seconds;
  14643. int hours, minutes;
  14644. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14645. hours = seconds / (60 * 60);
  14646. seconds = seconds - (60 * 60 * hours);
  14647. minutes = seconds / 60;
  14648. p.minHours = hours;
  14649. p.minMinutes = minutes;
  14650. break;
  14651. }
  14652. }
  14653. if( md != nullptr ){
  14654. safestrncpy( p.name, md->db->jname.c_str(), sizeof( p.name ) );
  14655. }
  14656. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  14657. }
  14658. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14659. /// 02d6 <account id>.L
  14660. void clif_parse_ViewPlayerEquip(int fd, map_session_data* sd)
  14661. {
  14662. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14663. map_session_data* tsd = map_id2sd(aid);
  14664. if (!tsd)
  14665. return;
  14666. if (sd->bl.m != tsd->bl.m)
  14667. return;
  14668. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14669. clif_viewequip_ack(sd, tsd);
  14670. else
  14671. clif_msg(sd, VIEW_EQUIP_FAIL);
  14672. }
  14673. /// Request to a configuration.
  14674. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14675. /// type: see enum e_config_type
  14676. /// flag:
  14677. /// false = disabled
  14678. /// true = enabled
  14679. void clif_parse_configuration( int fd, map_session_data* sd ){
  14680. int cmd = RFIFOW(fd,0);
  14681. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14682. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14683. switch( type ){
  14684. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14685. sd->status.show_equip = flag;
  14686. break;
  14687. case CONFIG_CALL:
  14688. sd->status.disable_call = flag;
  14689. break;
  14690. case CONFIG_PET_AUTOFEED:
  14691. // Player can not click this if he does not have a pet
  14692. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14693. return;
  14694. }
  14695. sd->pd->pet.autofeed = flag;
  14696. break;
  14697. case CONFIG_HOMUNCULUS_AUTOFEED:
  14698. // Player can not click this if he does not have a homunculus or it is vaporized
  14699. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14700. return;
  14701. }
  14702. sd->hd->homunculus.autofeed = flag;
  14703. break;
  14704. default:
  14705. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14706. return;
  14707. }
  14708. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14709. }
  14710. /// Request to change party invitation tick.
  14711. /// value:
  14712. /// 0 = disabled
  14713. /// 1 = enabled
  14714. void clif_parse_PartyTick(int fd, map_session_data* sd)
  14715. {
  14716. bool flag = RFIFOB(fd,6) ? true : false;
  14717. sd->status.allow_party = flag;
  14718. clif_partytickack(sd, flag);
  14719. }
  14720. /// Questlog System [Kevin] [Inkfish]
  14721. ///
  14722. /**
  14723. * Safe check to init packet len & quest num for player.
  14724. * @param def_len
  14725. * @param info_len Length of each quest info.
  14726. * @param avail_quests Avail quests that player has.
  14727. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14728. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14729. **/
  14730. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14731. (*limit_out) = (0xFFFF - def_len) / info_len;
  14732. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14733. (*len_out) = ((*limit_out) * info_len) + def_len;
  14734. }
  14735. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14736. std::string race_name;
  14737. switch( objective->race ){
  14738. case RC_FORMLESS: race_name = "Formless"; break;
  14739. case RC_UNDEAD: race_name = "Undead"; break;
  14740. case RC_BRUTE: race_name = "Brute"; break;
  14741. case RC_PLANT: race_name = "Plant"; break;
  14742. case RC_INSECT: race_name = "Insect"; break;
  14743. case RC_FISH: race_name = "Fish"; break;
  14744. case RC_DEMON: race_name = "Demon"; break;
  14745. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14746. case RC_ANGEL: race_name = "Angel"; break;
  14747. case RC_DRAGON: race_name = "Dragon"; break;
  14748. default:
  14749. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14750. [[fallthrough]];
  14751. case RC_ALL: race_name = ""; break;
  14752. }
  14753. std::string size_name;
  14754. switch( objective->size ){
  14755. case SZ_SMALL: size_name = "Small"; break;
  14756. case SZ_MEDIUM: size_name = "Medium"; break;
  14757. case SZ_BIG: size_name = "Large"; break;
  14758. default:
  14759. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14760. [[fallthrough]];
  14761. case SZ_ALL: size_name = ""; break;
  14762. }
  14763. std::string ele_name;
  14764. switch( objective->element ){
  14765. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14766. case ELE_WATER: ele_name = "Water Element"; break;
  14767. case ELE_EARTH: ele_name = "Earth Element"; break;
  14768. case ELE_FIRE: ele_name = "Fire Element"; break;
  14769. case ELE_WIND: ele_name = "Wind Element"; break;
  14770. case ELE_POISON: ele_name = "Poison Element"; break;
  14771. case ELE_HOLY: ele_name = "Holy Element"; break;
  14772. case ELE_DARK: ele_name = "Shadow Element"; break;
  14773. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14774. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14775. default:
  14776. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14777. [[fallthrough]];
  14778. case ELE_ALL: ele_name = ""; break;
  14779. }
  14780. std::string str;
  14781. if( !objective->map_name.empty() ){
  14782. str += objective->map_name;
  14783. }
  14784. if( !race_name.empty() ){
  14785. if( !str.empty() ){
  14786. str += ", ";
  14787. }
  14788. str += race_name;
  14789. }
  14790. if( !size_name.empty() ){
  14791. if( !str.empty() ){
  14792. str += ", ";
  14793. }
  14794. str += size_name;
  14795. }
  14796. if( !ele_name.empty() ){
  14797. if( !str.empty() ){
  14798. str += ", ";
  14799. }
  14800. str += ele_name;
  14801. }
  14802. return str;
  14803. }
  14804. /// Sends list of all quest states
  14805. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14806. /// 097a <packet len>.W <num>.L { <quest id>.L <active>.B <remaining time>.L <time>.L <count>.W { <mob_id>.L <killed>.W <total>.W <mob name>.24B }*count }*num (ZC_ALL_QUEST_LIST2)
  14807. /// 09f8 <packet len>.W <num>.L { <quest id>.L <active>.B <remaining time>.L <time>.L <count>.W { <hunt identification>.L <mob type>.L <mob_id>.L <min level>.W <max level>.W <killed>.W <total>.W <mob name>.24B }*count }*num (ZC_ALL_QUEST_LIST3)
  14808. void clif_quest_send_list(map_session_data *sd)
  14809. {
  14810. nullpo_retv(sd);
  14811. int fd = sd->fd;
  14812. int i;
  14813. int offset = 8;
  14814. int limit = 0;
  14815. #if PACKETVER >= 20141022
  14816. #if PACKETVER >= 20150513
  14817. int size = 22 + NAME_LENGTH;
  14818. #else
  14819. int size = 10 + NAME_LENGTH;
  14820. #endif
  14821. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14822. WFIFOHEAD(fd,i);
  14823. #if PACKETVER >= 20150513
  14824. WFIFOW(fd, 0) = 0x9f8;
  14825. #else
  14826. WFIFOW(fd, 0) = 0x97a;
  14827. #endif
  14828. WFIFOL(fd, 4) = limit;
  14829. for (i = 0; i < limit; i++) {
  14830. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14831. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14832. offset += 4;
  14833. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14834. offset++;
  14835. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14836. offset += 4;
  14837. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14838. offset += 4;
  14839. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14840. offset += 2;
  14841. if (!qi->objectives.empty()) {
  14842. std::shared_ptr<s_mob_db> mob;
  14843. for (int j = 0; j < qi->objectives.size(); j++) {
  14844. mob = mob_db.find(qi->objectives[j]->mob_id);
  14845. e_race race = qi->objectives[j]->race;
  14846. e_size size = qi->objectives[j]->size;
  14847. e_element element = qi->objectives[j]->element;
  14848. #if PACKETVER >= 20150513
  14849. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14850. offset += 4;
  14851. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14852. offset += 4;
  14853. #endif
  14854. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14855. offset += 4;
  14856. #if PACKETVER >= 20150513
  14857. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14858. offset += 2;
  14859. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14860. offset += 2;
  14861. #endif
  14862. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14863. offset += 2;
  14864. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14865. offset += 2;
  14866. if (mob && qi->objectives[j]->mob_id > 0)
  14867. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14868. else
  14869. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14870. offset += NAME_LENGTH;
  14871. }
  14872. }
  14873. }
  14874. WFIFOW(fd, 2) = offset;
  14875. WFIFOSET(fd, offset);
  14876. #else
  14877. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14878. WFIFOHEAD(fd,i);
  14879. WFIFOW(fd, 0) = 0x2b1;
  14880. WFIFOL(fd, 4) = limit;
  14881. for (i = 0; i < limit; i++) {
  14882. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14883. offset += 4;
  14884. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14885. offset += 1;
  14886. }
  14887. WFIFOW(fd, 2) = offset;
  14888. WFIFOSET(fd, offset);
  14889. #endif
  14890. }
  14891. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14892. /// 02b2 <packet len>.W <num>.L { <quest id>.L <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3 }*num
  14893. void clif_quest_send_mission(map_session_data *sd)
  14894. {
  14895. nullpo_retv(sd);
  14896. int fd = sd->fd;
  14897. int limit = 0;
  14898. int len = sd->avail_quests*104+8;
  14899. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14900. WFIFOHEAD(fd, len);
  14901. WFIFOW(fd, 0) = 0x2b2;
  14902. WFIFOW(fd, 2) = len;
  14903. WFIFOL(fd, 4) = limit;
  14904. for (int i = 0; i < limit; i++) {
  14905. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14906. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14907. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14908. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14909. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14910. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14911. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14912. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14913. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14914. if (mob && qi->objectives[j]->mob_id > 0)
  14915. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14916. else
  14917. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14918. }
  14919. }
  14920. WFIFOSET(fd, len);
  14921. }
  14922. /// Notification about a new quest
  14923. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3 (ZC_ADD_QUEST)
  14924. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14925. /// 09f9 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <hunt identification>.L <mob type>.L <mob id>.L <min level>.W <max level>.W <mob count>.W <mob name>.24B }*3 (ZC_ADD_QUEST_EX)
  14926. void clif_quest_add(map_session_data *sd, struct quest *qd)
  14927. {
  14928. nullpo_retv(sd);
  14929. nullpo_retv(qd);
  14930. int fd = sd->fd;
  14931. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14932. if (!qi)
  14933. return;
  14934. #if PACKETVER >= 20150513
  14935. int cmd = 0x9f9;
  14936. #else
  14937. int cmd = 0x2b3;
  14938. #endif
  14939. WFIFOHEAD(fd, packet_len(cmd));
  14940. WFIFOW(fd, 0) = cmd;
  14941. WFIFOL(fd, 2) = qd->quest_id;
  14942. WFIFOB(fd, 6) = qd->state;
  14943. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14944. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14945. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14946. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14947. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14948. e_race race = qi->objectives[i]->race;
  14949. e_size size = qi->objectives[i]->size;
  14950. e_element element = qi->objectives[i]->element;
  14951. #if PACKETVER >= 20150513
  14952. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14953. offset += 4;
  14954. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14955. offset += 4;
  14956. #endif
  14957. WFIFOL(fd, offset) = ((mob && qi->objectives[i]->mob_id > 0) ? qi->objectives[i]->mob_id : MOBID_PORING); // 0 can't be used as it displays "Novice" job regardless of the clif_mobtype_name
  14958. offset += 4;
  14959. #if PACKETVER >= 20150513
  14960. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14961. offset += 2;
  14962. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14963. offset += 2;
  14964. #endif
  14965. WFIFOW(fd, offset) = qd->count[i];
  14966. offset += 2;
  14967. if (mob && qi->objectives[i]->mob_id > 0)
  14968. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14969. else
  14970. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14971. offset += NAME_LENGTH;
  14972. }
  14973. WFIFOSET(fd, packet_len(cmd));
  14974. #if PACKETVER >= 20150513
  14975. int len = 4 + qi->objectives.size() * 12;
  14976. WFIFOHEAD(fd, len);
  14977. WFIFOW(fd, 0) = 0x8fe;
  14978. WFIFOW(fd, 2) = len;
  14979. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14980. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14981. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  14982. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  14983. WFIFOW(fd, offset + 10) = qd->count[i];
  14984. }
  14985. WFIFOSET(fd, len);
  14986. #endif
  14987. }
  14988. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14989. /// 02b4 <quest id>.L
  14990. void clif_quest_delete(map_session_data *sd, int quest_id)
  14991. {
  14992. int fd = sd->fd;
  14993. WFIFOHEAD(fd, packet_len(0x2b4));
  14994. WFIFOW(fd, 0) = 0x2b4;
  14995. WFIFOL(fd, 2) = quest_id;
  14996. WFIFOSET(fd, packet_len(0x2b4));
  14997. }
  14998. /// Notification of an update to the hunting mission counter
  14999. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  15000. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  15001. void clif_quest_update_objective(map_session_data *sd, struct quest *qd)
  15002. {
  15003. int fd = sd->fd;
  15004. int offset = 6;
  15005. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  15006. int len = qi->objectives.size() * 12 + 6;
  15007. #if PACKETVER >= 20150513
  15008. int cmd = 0x9fa;
  15009. #else
  15010. int cmd = 0x2b5;
  15011. #endif
  15012. WFIFOHEAD(fd, len);
  15013. WFIFOW(fd, 0) = cmd;
  15014. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  15015. for (int i = 0; i < qi->objectives.size(); i++) {
  15016. WFIFOL(fd, offset) = qd->quest_id;
  15017. offset += 4;
  15018. #if PACKETVER >= 20150513
  15019. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  15020. offset += 4;
  15021. #else
  15022. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  15023. offset += 4;
  15024. #endif
  15025. WFIFOW(fd, offset) = qi->objectives[i]->count;
  15026. offset += 2;
  15027. WFIFOW(fd, offset) = qd->count[i];
  15028. offset += 2;
  15029. }
  15030. WFIFOW(fd, 2) = offset;
  15031. WFIFOSET(fd, offset);
  15032. }
  15033. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  15034. /// 02b6 <quest id>.L <active>.B
  15035. void clif_parse_questStateAck(int fd, map_session_data *sd)
  15036. {
  15037. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15038. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  15039. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  15040. }
  15041. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  15042. /// 02b7 <quest id>.L <active>.B
  15043. void clif_quest_update_status(map_session_data *sd, int quest_id, bool active)
  15044. {
  15045. int fd = sd->fd;
  15046. WFIFOHEAD(fd, packet_len(0x2b7));
  15047. WFIFOW(fd, 0) = 0x2b7;
  15048. WFIFOL(fd, 2) = quest_id;
  15049. WFIFOB(fd, 6) = active;
  15050. WFIFOSET(fd, packet_len(0x2b7));
  15051. }
  15052. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  15053. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  15054. /// effect:
  15055. /// 0 = none
  15056. /// 1 = exclamation mark icon
  15057. /// 2 = question mark icon
  15058. /// color:
  15059. /// 0 = yellow
  15060. /// 1 = orange
  15061. /// 2 = green
  15062. /// 3 = purple
  15063. void clif_quest_show_event(map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  15064. {
  15065. #if PACKETVER >= 20090218
  15066. nullpo_retv(sd);
  15067. nullpo_retv(bl);
  15068. int fd = sd->fd;
  15069. WFIFOHEAD(fd, packet_len(0x446));
  15070. WFIFOW(fd, 0) = 0x446;
  15071. WFIFOL(fd, 2) = bl->id;
  15072. WFIFOW(fd, 6) = bl->x;
  15073. WFIFOW(fd, 8) = bl->y;
  15074. WFIFOW(fd, 10) = effect;
  15075. WFIFOW(fd, 12) = color;
  15076. WFIFOSET(fd, packet_len(0x446));
  15077. #endif
  15078. }
  15079. /// Mercenary System
  15080. ///
  15081. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  15082. /// 02a2 <var id>.W <value>.L
  15083. void clif_mercenary_updatestatus(map_session_data *sd, int type)
  15084. {
  15085. s_mercenary_data *md;
  15086. struct status_data *status;
  15087. int fd;
  15088. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15089. return;
  15090. fd = sd->fd;
  15091. status = &md->battle_status;
  15092. WFIFOHEAD(fd,packet_len(0x2a2));
  15093. WFIFOW(fd,0) = 0x2a2;
  15094. WFIFOW(fd,2) = type;
  15095. switch( type ) {
  15096. case SP_ATK1:
  15097. {
  15098. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15099. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  15100. }
  15101. break;
  15102. case SP_MATK1:
  15103. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  15104. break;
  15105. case SP_HIT:
  15106. WFIFOL(fd,4) = status->hit;
  15107. break;
  15108. case SP_CRITICAL:
  15109. WFIFOL(fd,4) = status->cri/10;
  15110. break;
  15111. case SP_DEF1:
  15112. WFIFOL(fd,4) = status->def;
  15113. break;
  15114. case SP_MDEF1:
  15115. WFIFOL(fd,4) = status->mdef;
  15116. break;
  15117. case SP_MERCFLEE:
  15118. WFIFOL(fd,4) = status->flee;
  15119. break;
  15120. case SP_ASPD:
  15121. WFIFOL(fd,4) = status->amotion;
  15122. break;
  15123. case SP_HP:
  15124. WFIFOL(fd,4) = status->hp;
  15125. break;
  15126. case SP_MAXHP:
  15127. WFIFOL(fd,4) = status->max_hp;
  15128. break;
  15129. case SP_SP:
  15130. WFIFOL(fd,4) = status->sp;
  15131. break;
  15132. case SP_MAXSP:
  15133. WFIFOL(fd,4) = status->max_sp;
  15134. break;
  15135. case SP_MERCKILLS:
  15136. WFIFOL(fd,4) = md->mercenary.kill_count;
  15137. break;
  15138. case SP_MERCFAITH:
  15139. WFIFOL(fd,4) = mercenary_get_faith(md);
  15140. break;
  15141. }
  15142. WFIFOSET(fd,packet_len(0x2a2));
  15143. }
  15144. /// Mercenary base status data (ZC_MER_INIT).
  15145. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  15146. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  15147. /// <calls>.L <kills>.L <atk range>.W
  15148. void clif_mercenary_info(map_session_data *sd)
  15149. {
  15150. int fd;
  15151. s_mercenary_data *md;
  15152. struct status_data *status;
  15153. int atk;
  15154. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  15155. return;
  15156. fd = sd->fd;
  15157. status = &md->battle_status;
  15158. WFIFOHEAD(fd,packet_len(0x29b));
  15159. WFIFOW(fd,0) = 0x29b;
  15160. WFIFOL(fd,2) = md->bl.id;
  15161. // Mercenary shows ATK as a random value between ATK ~ ATK2
  15162. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15163. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  15164. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  15165. WFIFOW(fd,10) = status->hit;
  15166. WFIFOW(fd,12) = status->cri/10;
  15167. WFIFOW(fd,14) = status->def;
  15168. WFIFOW(fd,16) = status->mdef;
  15169. WFIFOW(fd,18) = status->flee;
  15170. WFIFOW(fd,20) = status->amotion;
  15171. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  15172. WFIFOW(fd,46) = md->db->lv;
  15173. WFIFOL(fd,48) = status->hp;
  15174. WFIFOL(fd,52) = status->max_hp;
  15175. WFIFOL(fd,56) = status->sp;
  15176. WFIFOL(fd,60) = status->max_sp;
  15177. WFIFOL(fd,64) = client_tick(time(NULL) + (mercenary_get_lifetime(md) / 1000));
  15178. WFIFOW(fd,68) = mercenary_get_faith(md);
  15179. WFIFOL(fd,70) = mercenary_get_calls(md);
  15180. WFIFOL(fd,74) = md->mercenary.kill_count;
  15181. WFIFOW(fd,78) = md->battle_status.rhw.range;
  15182. WFIFOSET(fd,packet_len(0x29b));
  15183. }
  15184. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  15185. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  15186. void clif_mercenary_skillblock(map_session_data *sd)
  15187. {
  15188. s_mercenary_data *md;
  15189. int fd, len = 4;
  15190. if( sd == NULL || (md = sd->md) == NULL )
  15191. return;
  15192. fd = sd->fd;
  15193. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15194. WFIFOW(fd,0) = 0x29d;
  15195. for (const auto &it : md->db->skill) {
  15196. uint16 id = it.first;
  15197. if (!SKILL_CHK_MERC(id))
  15198. continue;
  15199. uint16 lv = it.second;
  15200. WFIFOW(fd,len) = id;
  15201. WFIFOL(fd,len+2) = skill_get_inf(id);
  15202. WFIFOW(fd,len+6) = lv;
  15203. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15204. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15205. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15206. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15207. len += 37;
  15208. }
  15209. WFIFOW(fd,2) = len;
  15210. WFIFOSET(fd,len);
  15211. }
  15212. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15213. /// 029f <command>.B
  15214. /// 1 = mercenary information
  15215. /// 2 = delete
  15216. void clif_parse_mercenary_action(int fd, map_session_data* sd)
  15217. {
  15218. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15219. if( sd->md == NULL )
  15220. return;
  15221. if( option == 2 ) mercenary_delete(sd->md, 2);
  15222. }
  15223. /// Mercenary Message
  15224. /// message:
  15225. /// 0 = Mercenary soldier's duty hour is over.
  15226. /// 1 = Your mercenary soldier has been killed.
  15227. /// 2 = Your mercenary soldier has been fired.
  15228. /// 3 = Your mercenary soldier has ran away.
  15229. void clif_mercenary_message(map_session_data* sd, int message){
  15230. clif_msg(sd, MERC_MSG_BASE + message);
  15231. }
  15232. /// Notification about the remaining time of a rental item.
  15233. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15234. void clif_rental_time( map_session_data* sd, t_itemid nameid, int seconds ){
  15235. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15236. struct PACKET_ZC_CASH_TIME_COUNTER p;
  15237. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15238. p.itemId = client_nameid( nameid );
  15239. p.seconds = seconds;
  15240. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15241. }
  15242. /// Deletes a rental item from client's inventory.
  15243. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15244. void clif_rental_expired( map_session_data* sd, int index, t_itemid nameid ){
  15245. // '<ItemName>' item has been deleted from the Inventory
  15246. struct PACKET_ZC_CASH_ITEM_DELETE p;
  15247. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15248. p.index = client_index( index );
  15249. p.itemId = client_nameid( nameid );
  15250. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15251. }
  15252. /// Book Reading (ZC_READ_BOOK).
  15253. /// 0294 <book id>.L <page>.L
  15254. void clif_readbook(int fd, int book_id, int page)
  15255. {
  15256. WFIFOHEAD(fd,packet_len(0x294));
  15257. WFIFOW(fd,0) = 0x294;
  15258. WFIFOL(fd,2) = book_id;
  15259. WFIFOL(fd,6) = page;
  15260. WFIFOSET(fd,packet_len(0x294));
  15261. }
  15262. /// Battlegrounds
  15263. ///
  15264. /// Updates HP bar of a camp member.
  15265. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15266. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15267. void clif_bg_hp(map_session_data *sd) {
  15268. #if PACKETVER < 20140613
  15269. unsigned char buf[34];
  15270. const int cmd = 0x2e0;
  15271. #else
  15272. unsigned char buf[14];
  15273. const int cmd = 0xa0e;
  15274. #endif
  15275. nullpo_retv(sd);
  15276. WBUFW(buf,0) = cmd;
  15277. WBUFL(buf,2) = sd->status.account_id;
  15278. #if PACKETVER < 20140613
  15279. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15280. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15281. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15282. WBUFW(buf,32) = 100;
  15283. } else {
  15284. WBUFW(buf,30) = sd->battle_status.hp;
  15285. WBUFW(buf,32) = sd->battle_status.max_hp;
  15286. }
  15287. #else
  15288. if( sd->battle_status.max_hp > INT32_MAX ) {
  15289. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15290. WBUFL(buf,10) = 100;
  15291. } else {
  15292. WBUFL(buf,6) = sd->battle_status.hp;
  15293. WBUFL(buf,10) = sd->battle_status.max_hp;
  15294. }
  15295. #endif
  15296. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15297. }
  15298. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15299. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15300. void clif_bg_xy(map_session_data *sd)
  15301. {
  15302. unsigned char buf[36];
  15303. nullpo_retv(sd);
  15304. WBUFW(buf,0)=0x2df;
  15305. WBUFL(buf,2)=sd->status.account_id;
  15306. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15307. WBUFW(buf,30)=sd->status.class_;
  15308. WBUFW(buf,32)=sd->bl.x;
  15309. WBUFW(buf,34)=sd->bl.y;
  15310. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15311. }
  15312. void clif_bg_xy_remove(map_session_data *sd)
  15313. {
  15314. unsigned char buf[36];
  15315. nullpo_retv(sd);
  15316. WBUFW(buf,0)=0x2df;
  15317. WBUFL(buf,2)=sd->status.account_id;
  15318. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15319. WBUFW(buf,30)=0;
  15320. WBUFW(buf,32)=-1;
  15321. WBUFW(buf,34)=-1;
  15322. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15323. }
  15324. /// Notifies clients of a battleground message.
  15325. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15326. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, int len ){
  15327. map_session_data *sd = bg_getavailablesd( bg );
  15328. if( sd == nullptr ){
  15329. return;
  15330. }
  15331. // limit length
  15332. len = min( len + 1, CHAT_SIZE_MAX );
  15333. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15334. WBUFW(buf,0) = 0x2dc;
  15335. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  15336. WBUFL(buf,4) = src_id;
  15337. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15338. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15339. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15340. }
  15341. /// Validates and processes battlechat messages.
  15342. /// All messages that are sent after enabling battleground chat with /battlechat.
  15343. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15344. void clif_parse_BattleChat(int fd, map_session_data* sd){
  15345. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15346. if( !clif_process_message( sd, false, name, message, output ) )
  15347. return;
  15348. bg_send_message(sd, output, strlen(output) );
  15349. }
  15350. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15351. /// 02de <camp A points>.W <camp B points>.W
  15352. void clif_bg_updatescore(int16 m)
  15353. {
  15354. struct block_list bl;
  15355. unsigned char buf[6];
  15356. struct map_data *mapdata = map_getmapdata(m);
  15357. bl.id = 0;
  15358. bl.type = BL_NUL;
  15359. bl.m = m;
  15360. WBUFW(buf,0) = 0x2de;
  15361. WBUFW(buf,2) = mapdata->bgscore_lion;
  15362. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15363. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15364. }
  15365. void clif_bg_updatescore_single(map_session_data *sd)
  15366. {
  15367. int fd;
  15368. nullpo_retv(sd);
  15369. fd = sd->fd;
  15370. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15371. WFIFOHEAD(fd,packet_len(0x2de));
  15372. WFIFOW(fd,0) = 0x2de;
  15373. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15374. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15375. WFIFOSET(fd,packet_len(0x2de));
  15376. }
  15377. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15378. /// 02dd <account id>.L <name>.24B <camp>.W
  15379. void clif_sendbgemblem_area(map_session_data *sd)
  15380. {
  15381. unsigned char buf[33];
  15382. nullpo_retv(sd);
  15383. WBUFW(buf, 0) = 0x2dd;
  15384. WBUFL(buf,2) = sd->bl.id;
  15385. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15386. WBUFW(buf,30) = sd->bg_id;
  15387. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15388. }
  15389. void clif_sendbgemblem_single(int fd, map_session_data *sd)
  15390. {
  15391. nullpo_retv(sd);
  15392. WFIFOHEAD(fd,32);
  15393. WFIFOW(fd,0) = 0x2dd;
  15394. WFIFOL(fd,2) = sd->bl.id;
  15395. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15396. WFIFOW(fd,30) = sd->bg_id;
  15397. WFIFOSET(fd,packet_len(0x2dd));
  15398. }
  15399. /// Battlegrounds queue incoming apply request from client.
  15400. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15401. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15402. void clif_parse_bg_queue_apply_request(int fd, map_session_data *sd)
  15403. {
  15404. if (!battle_config.feature_bgqueue)
  15405. return;
  15406. nullpo_retv(sd);
  15407. short type = RFIFOW(fd,2);
  15408. char name[NAME_LENGTH];
  15409. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15410. if (sd->bg_queue_id > 0) {
  15411. //ShowWarning("clif_parse_bg_queue_apply_request: Received duplicate queue application: %d from player %s (AID:%d CID:%d).\n", type, sd->status.name, sd->status.account_id, sd->status.char_id);
  15412. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15413. return;
  15414. } else if (type == 1) // Solo
  15415. bg_queue_join_solo(name, sd);
  15416. else if (type == 2) // Party
  15417. bg_queue_join_party(name, sd);
  15418. else if (type == 4) // Guild
  15419. bg_queue_join_guild(name, sd);
  15420. else {
  15421. ShowWarning("clif_parse_bg_queue_apply_request: Received invalid queue type: %d from player %s (AID:%d CID:%d).\n", type, sd->status.name, sd->status.account_id, sd->status.char_id);
  15422. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15423. return;
  15424. }
  15425. }
  15426. /// Outgoing battlegrounds queue apply result.
  15427. /// Result types: @see e_bg_queue_apply_ack
  15428. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15429. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, map_session_data *sd)
  15430. {
  15431. nullpo_retv(sd);
  15432. int fd = sd->fd;
  15433. WFIFOHEAD(fd, packet_len(0x8d8));
  15434. WFIFOW(fd,0) = 0x8d8;
  15435. WFIFOB(fd,2) = result;
  15436. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15437. WFIFOSET(fd, packet_len(0x8d8));
  15438. }
  15439. /// Outgoing battlegrounds queue apply notification.
  15440. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15441. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15442. void clif_bg_queue_apply_notify(const char *name, map_session_data *sd)
  15443. {
  15444. nullpo_retv(sd);
  15445. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15446. if (queue == nullptr) {
  15447. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15448. return;
  15449. }
  15450. int fd = sd->fd;
  15451. WFIFOHEAD(fd, packet_len(0x8d9));
  15452. WFIFOW(fd,0) = 0x8d9;
  15453. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15454. WFIFOL(fd,2+NAME_LENGTH) = queue->teama_members.size() + queue->teamb_members.size();
  15455. WFIFOSET(fd, packet_len(0x8d9));
  15456. }
  15457. /// Battlegrounds queue outgoing cancel result.
  15458. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15459. void clif_bg_queue_cancel_result(bool success, const char *name, map_session_data *sd)
  15460. {
  15461. nullpo_retv(sd);
  15462. int fd = sd->fd;
  15463. WFIFOHEAD(fd, packet_len(0x8d8));
  15464. WFIFOW(fd,0) = 0x8db;
  15465. WFIFOB(fd,2) = success;
  15466. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15467. WFIFOSET(fd, packet_len(0x8d8));
  15468. }
  15469. /// Battlegrounds queue incoming cancel request from client.
  15470. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15471. void clif_parse_bg_queue_cancel_request(int fd, map_session_data *sd)
  15472. {
  15473. if (!battle_config.feature_bgqueue)
  15474. return;
  15475. nullpo_retv(sd);
  15476. bool success;
  15477. if (sd->bg_queue_id > 0) {
  15478. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15479. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15480. return; // Make the cancel button do nothing if the entry window is open. Otherwise it'll crash the game when you click on both the queue status and entry status window.
  15481. else
  15482. success = bg_queue_leave(sd);
  15483. } else {
  15484. ShowWarning("clif_parse_bg_queue_cancel_request: Player trying to request leaving non-existent queue with name: %s (AID:%d CID:%d).\n", sd->status.name, sd->status.account_id, sd->status.char_id);
  15485. success = false;
  15486. }
  15487. char name[NAME_LENGTH];
  15488. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15489. clif_bg_queue_cancel_result(success, name, sd);
  15490. }
  15491. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15492. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15493. void clif_bg_queue_lobby_notify(const char *name, map_session_data *sd)
  15494. {
  15495. nullpo_retv(sd);
  15496. int fd = sd->fd;
  15497. WFIFOHEAD(fd, packet_len(0x8df));
  15498. WFIFOW(fd,0) = 0x8df;
  15499. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15500. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15501. WFIFOSET(fd, packet_len(0x8df));
  15502. }
  15503. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15504. /// Result types: 1(Accept), 2(Decline).
  15505. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15506. void clif_parse_bg_queue_lobby_reply(int fd, map_session_data *sd)
  15507. {
  15508. nullpo_retv(sd);
  15509. if(sd->bg_queue_id > 0) {
  15510. uint8 result = RFIFOB(fd, 2);
  15511. if(result == 1) { // Accept
  15512. bg_queue_on_accept_invite(sd);
  15513. } else if(result == 2) { // Decline
  15514. bg_queue_leave(sd);
  15515. clif_bg_queue_entry_init(sd);
  15516. }
  15517. }
  15518. }
  15519. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15520. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15521. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, map_session_data *sd)
  15522. {
  15523. nullpo_retv(sd);
  15524. int fd = sd->fd;
  15525. WFIFOHEAD(fd, packet_len(0x8e1));
  15526. WFIFOW(fd,0) = 0x8e1;
  15527. WFIFOB(fd,2) = result;
  15528. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15529. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15530. WFIFOSET(fd, packet_len(0x8e1));
  15531. }
  15532. /// Battlegrounds queue incoming queue number request from client.
  15533. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15534. void clif_parse_bg_queue_request_queue_number(int fd, map_session_data *sd)
  15535. {
  15536. nullpo_retv(sd);
  15537. char name[NAME_LENGTH];
  15538. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15539. clif_bg_queue_apply_notify(name, sd);
  15540. }
  15541. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15542. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15543. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15544. void clif_bg_queue_entry_init(map_session_data *sd)
  15545. {
  15546. nullpo_retv(sd);
  15547. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15548. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15549. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15550. }
  15551. /// Custom Fonts (ZC_NOTIFY_FONT).
  15552. /// 02ef <account_id>.L <font id>.W
  15553. void clif_font(map_session_data *sd)
  15554. {
  15555. #if PACKETVER >= 20080102
  15556. unsigned char buf[8];
  15557. nullpo_retv(sd);
  15558. WBUFW(buf,0) = 0x2ef;
  15559. WBUFL(buf,2) = sd->bl.id;
  15560. WBUFW(buf,6) = sd->status.font;
  15561. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15562. #endif
  15563. }
  15564. /// Required to start the instancing information window on Client
  15565. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15566. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15567. void clif_instance_create(int instance_id, int num)
  15568. {
  15569. #if PACKETVER >= 20071128
  15570. map_session_data *sd = NULL;
  15571. enum send_target target = PARTY;
  15572. unsigned char buf[65];
  15573. instance_getsd(instance_id, sd, &target);
  15574. if (!sd)
  15575. return;
  15576. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15577. if (!db)
  15578. return;
  15579. WBUFW(buf,0) = 0x2cb;
  15580. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15581. WBUFW(buf,63) = num;
  15582. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15583. #endif
  15584. return;
  15585. }
  15586. /// To announce Instancing queue creation if no maps available
  15587. /// S 0x2cc <Standby Position>.W
  15588. void clif_instance_changewait(int instance_id, int num)
  15589. {
  15590. #if PACKETVER >= 20071128
  15591. map_session_data *sd = NULL;
  15592. enum send_target target = PARTY;
  15593. unsigned char buf[4];
  15594. instance_getsd(instance_id, sd, &target);
  15595. if (!sd)
  15596. return;
  15597. WBUFW(buf,0) = 0x2cc;
  15598. WBUFW(buf,2) = num;
  15599. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15600. #endif
  15601. return;
  15602. }
  15603. /// Notify the current status to members
  15604. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15605. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15606. {
  15607. #if PACKETVER >= 20071128
  15608. map_session_data *sd = NULL;
  15609. enum send_target target = PARTY;
  15610. unsigned char buf[71];
  15611. instance_getsd(instance_id, sd, &target);
  15612. if (!sd)
  15613. return;
  15614. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15615. if (!db)
  15616. return;
  15617. WBUFW(buf,0) = 0x2cd;
  15618. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15619. WBUFL(buf,63) = limit1;
  15620. WBUFL(buf,67) = limit2;
  15621. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15622. #endif
  15623. return;
  15624. }
  15625. /// Notify a status change to members
  15626. /// S 0x2ce <Message ID>.L
  15627. /// 0 = Notification (EnterLimitDate update?)
  15628. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15629. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15630. /// 3 = The Memorial Dungeon has been removed.
  15631. /// 4 = Create failure (removes the instance window)
  15632. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15633. {
  15634. #if PACKETVER >= 20071128
  15635. map_session_data *sd = NULL;
  15636. enum send_target target = PARTY;
  15637. unsigned char buf[10];
  15638. instance_getsd(instance_id, sd, &target);
  15639. if (!sd)
  15640. return;
  15641. WBUFW(buf,0) = 0x2ce;
  15642. WBUFL(buf,2) = type;
  15643. WBUFL(buf,6) = limit;
  15644. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15645. #endif
  15646. return;
  15647. }
  15648. /// Destroy an instance from the status window
  15649. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15650. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15651. {
  15652. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15653. return;
  15654. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15655. switch (p->command) {
  15656. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15657. instance_destroy_command(sd);
  15658. break;
  15659. }
  15660. }
  15661. void clif_instance_info( map_session_data& sd ){
  15662. if( sd.instance_id > 0 ){
  15663. instance_reqinfo( &sd, sd.instance_id );
  15664. }
  15665. if( sd.status.party_id > 0 ){
  15666. struct party_data* p = party_search( sd.status.party_id );
  15667. if( p != nullptr && p->instance_id > 0 ){
  15668. instance_reqinfo( &sd, p->instance_id );
  15669. }
  15670. }
  15671. if( sd.guild != nullptr && sd.guild->instance_id > 0 ){
  15672. instance_reqinfo( &sd, sd.guild->instance_id );
  15673. }
  15674. if( sd.clan != nullptr && sd.clan->instance_id > 0 ){
  15675. instance_reqinfo( &sd, sd.clan->instance_id );
  15676. }
  15677. }
  15678. /// Notifies clients about item picked up by a party member.
  15679. /// 02b8 <account id>.L <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B (ZC_ITEM_PICKUP_PARTY)
  15680. void clif_party_show_picker( map_session_data* sd, struct item* item_data ){
  15681. #if PACKETVER >= 20071002
  15682. nullpo_retv( sd );
  15683. nullpo_retv( item_data );
  15684. struct item_data* id = itemdb_search( item_data->nameid );
  15685. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15686. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15687. p.AID = sd->status.account_id;
  15688. p.itemId = client_nameid( item_data->nameid );
  15689. p.identified = item_data->identify;
  15690. p.damaged = item_data->attribute;
  15691. p.refine = item_data->refine;
  15692. clif_addcards( &p.slot, item_data );
  15693. p.location = id->equip; // equip location
  15694. p.itemType = itemtype( id->nameid ); // item type
  15695. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15696. p.grade = item_data->enchantgrade;
  15697. #endif
  15698. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15699. #endif
  15700. }
  15701. /** Display gained exp.
  15702. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15703. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15704. * amount: INT32_MIN ~ INT32_MAX
  15705. * var id:
  15706. * SP_BASEEXP, SP_JOBEXP
  15707. * exp type:
  15708. * 0 = normal exp gained/lost
  15709. * 1 = quest exp gained/lost
  15710. * @param sd Player
  15711. * @param exp EXP value gained/loss
  15712. * @param type SP_BASEEXP, SP_JOBEXP
  15713. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15714. * @param lost True:if losing EXP
  15715. */
  15716. void clif_displayexp(map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15717. {
  15718. int fd;
  15719. int offset;
  15720. #if PACKETVER >= 20170830
  15721. int cmd = 0xacc;
  15722. #else
  15723. int cmd = 0x7f6;
  15724. #endif
  15725. nullpo_retv(sd);
  15726. fd = sd->fd;
  15727. WFIFOHEAD(fd, packet_len(cmd));
  15728. WFIFOW(fd,0) = cmd;
  15729. WFIFOL(fd,2) = sd->bl.id;
  15730. #if PACKETVER >= 20170830
  15731. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15732. offset = 4;
  15733. #else
  15734. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15735. offset = 0;
  15736. #endif
  15737. WFIFOW(fd,10+offset) = type;
  15738. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15739. WFIFOSET(fd,packet_len(cmd));
  15740. }
  15741. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15742. /// type:
  15743. /// 0 = Displays 'value' for 5 seconds.
  15744. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15745. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15746. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15747. /// value:
  15748. /// Except for type 3 it is interpreted as seconds for displaying as DD:HH:MM:SS, HH:MM:SS, MM:SS or SS (leftmost '00' is not displayed).
  15749. void clif_showdigit(map_session_data* sd, unsigned char type, int value)
  15750. {
  15751. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15752. WFIFOW(sd->fd,0) = 0x1b1;
  15753. WFIFOB(sd->fd,2) = type;
  15754. WFIFOL(sd->fd,3) = value;
  15755. WFIFOSET(sd->fd, packet_len(0x1b1));
  15756. }
  15757. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15758. /// 021d <state>.L
  15759. /// state:
  15760. /// 0 = Full effects
  15761. /// 1 = Reduced effects
  15762. ///
  15763. /// NOTE: The state is used on Aegis for sending skill unit packet
  15764. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15765. /// whenever possible. Due to the way the decision check is
  15766. /// constructed, this state tracking was rendered useless,
  15767. /// as the only skill unit, that is sent with 0x1c9 is
  15768. /// Graffiti.
  15769. void clif_parse_LessEffect(int fd, map_session_data* sd){
  15770. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15771. sd->state.lesseffect = ( isLess != 0 );
  15772. }
  15773. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15774. void clif_parse_ItemListWindowSelected(int fd, map_session_data* sd) {
  15775. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15776. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15777. int type = RFIFOL(fd,info->pos[1]);
  15778. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15779. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15780. if( sd->state.trading || sd->npc_shopid )
  15781. return;
  15782. if( flag == 0 || n == 0) {
  15783. clif_menuskill_clear(sd);
  15784. return; // Canceled by player.
  15785. }
  15786. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15787. clif_menuskill_clear(sd);
  15788. return; // Prevent hacking.
  15789. }
  15790. switch( type ) {
  15791. case 0: // Change Material
  15792. skill_changematerial(sd,n,item_list);
  15793. break;
  15794. case 1: // Level 1: Pure to Rough
  15795. case 2: // Level 2: Rough to Pure
  15796. skill_elementalanalysis(sd,n,type,item_list);
  15797. break;
  15798. }
  15799. clif_menuskill_clear(sd);
  15800. return;
  15801. }
  15802. /*==========================================
  15803. * Elemental System
  15804. *==========================================*/
  15805. void clif_elemental_updatestatus(map_session_data *sd, int type) {
  15806. s_elemental_data *ed;
  15807. struct status_data *status;
  15808. int fd;
  15809. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15810. return;
  15811. fd = sd->fd;
  15812. status = &ed->battle_status;
  15813. WFIFOHEAD(fd,8);
  15814. WFIFOW(fd,0) = 0x81e;
  15815. WFIFOW(fd,2) = type;
  15816. switch( type ) {
  15817. case SP_HP:
  15818. WFIFOL(fd,4) = status->hp;
  15819. break;
  15820. case SP_MAXHP:
  15821. WFIFOL(fd,4) = status->max_hp;
  15822. break;
  15823. case SP_SP:
  15824. WFIFOL(fd,4) = status->sp;
  15825. break;
  15826. case SP_MAXSP:
  15827. WFIFOL(fd,4) = status->max_sp;
  15828. break;
  15829. }
  15830. WFIFOSET(fd,8);
  15831. }
  15832. void clif_elemental_info(map_session_data *sd) {
  15833. int fd;
  15834. s_elemental_data *ed;
  15835. struct status_data *status;
  15836. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15837. return;
  15838. fd = sd->fd;
  15839. status = &ed->battle_status;
  15840. WFIFOHEAD(fd,22);
  15841. WFIFOW(fd, 0) = 0x81d;
  15842. WFIFOL(fd, 2) = ed->bl.id;
  15843. WFIFOL(fd, 6) = status->hp;
  15844. WFIFOL(fd,10) = status->max_hp;
  15845. WFIFOL(fd,14) = status->sp;
  15846. WFIFOL(fd,18) = status->max_sp;
  15847. WFIFOSET(fd,22);
  15848. }
  15849. /// Buying Store System
  15850. ///
  15851. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15852. /// 0810 <slots>.B
  15853. void clif_buyingstore_open(map_session_data* sd)
  15854. {
  15855. int fd = sd->fd;
  15856. WFIFOHEAD(fd,packet_len(0x810));
  15857. WFIFOW(fd,0) = 0x810;
  15858. WFIFOB(fd,2) = sd->buyingstore.slots;
  15859. WFIFOSET(fd,packet_len(0x810));
  15860. }
  15861. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15862. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15863. /// result:
  15864. /// 0 = cancel
  15865. /// 1 = open
  15866. static void clif_parse_ReqOpenBuyingStore( int fd, map_session_data* sd ){
  15867. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15868. // TODO: Make this check global for all variable length packets.
  15869. // minimum packet length
  15870. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15871. ShowError( "clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%" PRIdPTR ", length=%u, account_id=%d).\n", sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ), p->packetLength, sd->bl.id );
  15872. return;
  15873. }
  15874. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15875. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15876. return;
  15877. }
  15878. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15879. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15880. return;
  15881. }
  15882. char storename[MESSAGE_SIZE];
  15883. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15884. // so that buyingstore_create knows, how many elements it has access to
  15885. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15886. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15887. ShowError( "clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%" PRIdPTR ")\n", packet_len, sd->bl.id, sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) );
  15888. return;
  15889. }
  15890. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), NULL );
  15891. }
  15892. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15893. /// 0812 <result>.W <total weight>.L
  15894. /// result:
  15895. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15896. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15897. /// 8 = "No sale (purchase) information available." (0x705)
  15898. /// ? = nothing
  15899. void clif_buyingstore_open_failed(map_session_data* sd, unsigned short result, unsigned int weight)
  15900. {
  15901. int fd = sd->fd;
  15902. WFIFOHEAD(fd,packet_len(0x812));
  15903. WFIFOW(fd,0) = 0x812;
  15904. WFIFOW(fd,2) = result;
  15905. WFIFOL(fd,4) = weight;
  15906. WFIFOSET(fd,packet_len(0x812));
  15907. }
  15908. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15909. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15910. void clif_buyingstore_myitemlist( map_session_data* sd ){
  15911. nullpo_retv( sd );
  15912. int fd = sd->fd;
  15913. if( !session_isActive( fd ) ){
  15914. return;
  15915. }
  15916. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15917. WFIFOHEAD( fd, length );
  15918. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15919. p->packetType = 0x813;
  15920. p->packetLength = length;
  15921. p->AID = sd->bl.id;
  15922. p->zenyLimit = sd->buyingstore.zenylimit;
  15923. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15924. p->items[i].price = sd->buyingstore.items[i].price;
  15925. p->items[i].amount = sd->buyingstore.items[i].amount;
  15926. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15927. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15928. }
  15929. WFIFOSET( fd, p->packetLength );
  15930. }
  15931. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15932. /// 0814 <account id>.L <store name>.80B
  15933. void clif_buyingstore_entry( map_session_data& sd, struct block_list* tbl ){
  15934. #if PACKETVER >= 20100420
  15935. enum send_target target;
  15936. if( tbl == nullptr ){
  15937. tbl = &sd.bl;
  15938. target = AREA_WOS;
  15939. }else{
  15940. target = SELF;
  15941. }
  15942. struct PACKET_ZC_BUYING_STORE_ENTRY p = {};
  15943. p.packetType = HEADER_ZC_BUYING_STORE_ENTRY;
  15944. p.makerAID = sd.status.account_id;
  15945. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  15946. clif_send( &p, sizeof( p ), tbl, target );
  15947. #endif
  15948. }
  15949. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15950. /// 0815
  15951. static void clif_parse_ReqCloseBuyingStore(int fd, map_session_data* sd)
  15952. {
  15953. buyingstore_close(sd);
  15954. }
  15955. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15956. /// 0816 <account id>.L
  15957. void clif_buyingstore_disappear_entry( map_session_data& sd, struct block_list* tbl ){
  15958. #if PACKETVER >= 20100309
  15959. enum send_target target;
  15960. if( tbl == nullptr ){
  15961. tbl = &sd.bl;
  15962. target = AREA_WOS;
  15963. }else{
  15964. target = SELF;
  15965. }
  15966. struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY p = {};
  15967. p.packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY;
  15968. p.makerAID = sd.status.account_id;
  15969. clif_send( &p, sizeof( p ), tbl, target );
  15970. #endif
  15971. }
  15972. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15973. /// 0817 <account id>.L
  15974. static void clif_parse_ReqClickBuyingStore(int fd, map_session_data* sd)
  15975. {
  15976. uint32 account_id;
  15977. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15978. buyingstore_open(sd, account_id);
  15979. }
  15980. /// Sends buying store item list.
  15981. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }* (ZC_ACK_ITEMLIST_BUYING_STORE)
  15982. void clif_buyingstore_itemlist( map_session_data* sd, map_session_data* pl_sd ){
  15983. nullpo_retv( sd );
  15984. nullpo_retv( pl_sd );
  15985. int fd = sd->fd;
  15986. if( !session_isActive( fd ) ){
  15987. return;
  15988. }
  15989. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15990. WFIFOHEAD( fd, length );
  15991. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15992. p->packetType = 0x818;
  15993. p->packetLength = length;
  15994. p->AID = pl_sd->bl.id;
  15995. p->storeId = pl_sd->buyer_id;
  15996. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15997. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15998. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15999. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  16000. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  16001. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  16002. }
  16003. WFIFOSET( fd, p->packetLength );
  16004. }
  16005. /// Request to sell items to a buying store.
  16006. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  16007. static void clif_parse_ReqTradeBuyingStore( int fd, map_session_data* sd ){
  16008. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  16009. // minimum packet length
  16010. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  16011. ShowError( "clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%" PRIdPTR ", length=%u, account_id=%d).\n", sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ), p->packetLength, sd->bl.id );
  16012. return;
  16013. }
  16014. // so that buyingstore_trade knows, how many elements it has access to
  16015. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  16016. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  16017. ShowError( "clif_parse_ReqTradeBuyingStore: Unexpected item list size %u (account_id=%d, buyer_id=%d, block size=%" PRIdPTR ")\n", packet_len, sd->bl.id, p->AID, sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  16018. return;
  16019. }
  16020. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  16021. }
  16022. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  16023. /// 081a <result>.W
  16024. /// result:
  16025. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  16026. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  16027. /// ? = nothing
  16028. void clif_buyingstore_trade_failed_buyer(map_session_data* sd, short result)
  16029. {
  16030. int fd = sd->fd;
  16031. WFIFOHEAD(fd,packet_len(0x81a));
  16032. WFIFOW(fd,0) = 0x81a;
  16033. WFIFOW(fd,2) = result;
  16034. WFIFOSET(fd,packet_len(0x81a));
  16035. }
  16036. /// Updates the zeny limit and an item in the buying store item list.
  16037. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  16038. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  16039. void clif_buyingstore_update_item( map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  16040. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  16041. p.packetType = buyingStoreUpdateItemType;
  16042. p.itemId = client_nameid( nameid );
  16043. p.amount = amount;
  16044. p.zenyLimit = sd->buyingstore.zenylimit;
  16045. #if PACKETVER >= 20141016
  16046. p.zeny = zeny;
  16047. p.charId = char_id; // GID
  16048. p.updateTime = (int)time(NULL);
  16049. #endif
  16050. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16051. }
  16052. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  16053. /// 081c <index>.W <amount>.W <price>.L
  16054. /// message:
  16055. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  16056. ///
  16057. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  16058. void clif_buyingstore_delete_item(map_session_data* sd, short index, unsigned short amount, int price)
  16059. {
  16060. int fd = sd->fd;
  16061. WFIFOHEAD(fd,packet_len(0x81c));
  16062. WFIFOW(fd,0) = 0x81c;
  16063. WFIFOW(fd,2) = client_index( index );
  16064. WFIFOW(fd,4) = amount;
  16065. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  16066. WFIFOSET(fd,packet_len(0x81c));
  16067. }
  16068. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  16069. /// 0824 <result>.W <name id>.W
  16070. /// result:
  16071. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  16072. /// 6 = "The trade failed, because the entered amount of item %s is higher, than the buyer is willing to buy." (0x6d3, MSI_BUYINGSTORE_TRADE_OVERCOUNT)
  16073. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  16074. /// ? = nothing
  16075. void clif_buyingstore_trade_failed_seller( map_session_data* sd, short result, t_itemid nameid ){
  16076. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  16077. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  16078. p.result = result;
  16079. p.itemId = client_nameid( nameid );
  16080. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16081. }
  16082. /// Search Store Info System
  16083. ///
  16084. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  16085. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  16086. /// type:
  16087. /// 0 = Vending
  16088. /// 1 = Buying Store
  16089. ///
  16090. /// NOTE: The client determines the item ids by specifying a name and optionally,
  16091. /// amount of card slots. If the client does not know about the item it
  16092. /// cannot be searched.
  16093. static void clif_parse_SearchStoreInfo( int fd, map_session_data *sd ){
  16094. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  16095. // minimum packet length
  16096. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  16097. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected length=%" PRIdPTR ", length=%u, account_id=%d).\n", sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ), p->packetLength, sd->bl.id );
  16098. return;
  16099. }
  16100. // check, if there is enough data for the claimed count of items
  16101. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  16102. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  16103. ShowError( "clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%" PRIdPTR ")\n", packet_len, sd->bl.id, sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) );
  16104. return;
  16105. }
  16106. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  16107. if( count < p->itemsCount + p->cardsCount ){
  16108. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  16109. return;
  16110. }
  16111. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  16112. }
  16113. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  16114. /// 0836 <packet len>.W <is first page>.B <is next page>.B <remaining uses>.B { <store id>.L <account id>.L <shop name>.80B <nameid>.W <item type>.B <price>.L <amount>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  16115. /// is first page:
  16116. /// 0 = appends to existing results
  16117. /// 1 = clears previous results before displaying this result set
  16118. /// is next page:
  16119. /// 0 = no "next" label
  16120. /// 1 = "next" label to retrieve more results
  16121. void clif_search_store_info_ack( map_session_data* sd ){
  16122. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  16123. nullpo_retv( sd );
  16124. int fd = sd->fd;
  16125. if( !session_isActive( fd ) ){
  16126. return;
  16127. }
  16128. unsigned int start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  16129. unsigned int end = umin( sd->searchstore.items.size(), start + SEARCHSTORE_RESULTS_PER_PAGE );
  16130. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  16131. WFIFOHEAD( fd, len );
  16132. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  16133. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  16134. p->packetLength = len;
  16135. p->firstPage = !sd->searchstore.pages;
  16136. p->nextPage = searchstore_querynext( sd );
  16137. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  16138. for( int i = 0; i < end - start; i++ ) {
  16139. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  16140. p->items[i].storeId = ssitem->store_id;
  16141. p->items[i].AID = ssitem->account_id;
  16142. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  16143. p->items[i].itemId = client_nameid( ssitem->nameid );
  16144. p->items[i].itemType = itemtype( ssitem->nameid );
  16145. p->items[i].price = ssitem->price;
  16146. p->items[i].amount = ssitem->amount;
  16147. p->items[i].refine = ssitem->refine;
  16148. // make-up an item for clif_addcards
  16149. struct item it = {};
  16150. for( int j = 0; j < MAX_SLOTS; j++ ){
  16151. it.card[j] = ssitem->card[j];
  16152. }
  16153. it.nameid = ssitem->nameid;
  16154. it.amount = ssitem->amount;
  16155. clif_addcards( &p->items[i].slot, &it );
  16156. #if PACKETVER >= 20150226
  16157. clif_add_random_options( p->items[i].option_data, it );
  16158. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  16159. p->items[i].grade = ssitem->enchantgrade;
  16160. #endif
  16161. #endif
  16162. }
  16163. WFIFOSET( fd, len );
  16164. #endif
  16165. }
  16166. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  16167. /// 0837 <reason>.B
  16168. /// reason:
  16169. /// 0 = "No matching stores were found." (0x70b)
  16170. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  16171. /// 2 = "You cannot search anymore." (0x706)
  16172. /// 3 = "You cannot search yet." (0x708)
  16173. /// 4 = "No sale (purchase) information available." (0x705)
  16174. void clif_search_store_info_failed(map_session_data* sd, unsigned char reason)
  16175. {
  16176. int fd = sd->fd;
  16177. WFIFOHEAD(fd,packet_len(0x837));
  16178. WFIFOW(fd,0) = 0x837;
  16179. WFIFOB(fd,2) = reason;
  16180. WFIFOSET(fd,packet_len(0x837));
  16181. }
  16182. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  16183. /// 0838
  16184. static void clif_parse_SearchStoreInfoNextPage(int fd, map_session_data* sd)
  16185. {
  16186. searchstore_next(sd);
  16187. }
  16188. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  16189. /// 083a <type>.W <remaining uses>.B
  16190. /// type:
  16191. /// 0 = Search Stores
  16192. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  16193. void clif_open_search_store_info(map_session_data* sd)
  16194. {
  16195. int fd = sd->fd;
  16196. WFIFOHEAD(fd,packet_len(0x83a));
  16197. WFIFOW(fd,0) = 0x83a;
  16198. WFIFOW(fd,2) = sd->searchstore.effect;
  16199. #if PACKETVER > 20100701
  16200. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16201. #endif
  16202. WFIFOSET(fd,packet_len(0x83a));
  16203. }
  16204. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16205. /// 083b
  16206. static void clif_parse_CloseSearchStoreInfo(int fd, map_session_data* sd)
  16207. {
  16208. searchstore_close(sd);
  16209. }
  16210. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16211. /// 083c <account id>.L <store id>.L <nameid>.W
  16212. static void clif_parse_SearchStoreInfoListItemClick( int fd, map_session_data* sd ){
  16213. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16214. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16215. }
  16216. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16217. /// 083d <xPos>.W <yPos>.W
  16218. void clif_search_store_info_click_ack(map_session_data* sd, short x, short y)
  16219. {
  16220. int fd = sd->fd;
  16221. WFIFOHEAD(fd,packet_len(0x83d));
  16222. WFIFOW(fd,0) = 0x83d;
  16223. WFIFOW(fd,2) = x;
  16224. WFIFOW(fd,4) = y;
  16225. WFIFOSET(fd,packet_len(0x83d));
  16226. }
  16227. /// Parse function for packet debugging.
  16228. void clif_parse_debug(int fd,map_session_data *sd)
  16229. {
  16230. int cmd, packet_len;
  16231. // clif_parse ensures, that there is at least 2 bytes of data
  16232. cmd = RFIFOW(fd,0);
  16233. if( sd ) {
  16234. packet_len = packet_db[cmd].len;
  16235. if( packet_len == 0 )
  16236. {// unknown
  16237. packet_len = RFIFOREST(fd);
  16238. }
  16239. else if( packet_len == -1 )
  16240. {// variable length
  16241. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16242. }
  16243. ShowDebug("Packet debug of 0x%04X (length %d), %s session #%d, %d/%d (AID/CID)\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id);
  16244. }
  16245. else
  16246. {
  16247. packet_len = RFIFOREST(fd);
  16248. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16249. }
  16250. ShowDump(RFIFOP(fd,0), packet_len);
  16251. }
  16252. /*==========================================
  16253. * Server tells client to display a window similar to Magnifier (item) one
  16254. * Server populates the window with avilable elemental converter options according to player's inventory
  16255. *------------------------------------------*/
  16256. void clif_elementalconverter_list( map_session_data *sd ){
  16257. nullpo_retv( sd );
  16258. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)packet_buffer;
  16259. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16260. int count = 0;
  16261. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16262. if( skill_can_produce_mix( sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16263. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16264. count++;
  16265. }
  16266. }
  16267. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16268. clif_send( p, p->packetLength, &sd->bl, SELF );
  16269. if( count > 0 ){
  16270. sd->menuskill_id = SA_CREATECON;
  16271. sd->menuskill_val = count;
  16272. }
  16273. }
  16274. /**
  16275. * Rune Knight
  16276. **/
  16277. void clif_millenniumshield(struct block_list *bl, short shields) {
  16278. #if PACKETVER >= 20081217
  16279. unsigned char buf[10];
  16280. WBUFW(buf,0) = 0x440;
  16281. WBUFL(buf,2) = bl->id;
  16282. WBUFW(buf,6) = shields;
  16283. WBUFW(buf,8) = 0;
  16284. clif_send(buf,packet_len(0x440),bl,AREA);
  16285. #endif
  16286. }
  16287. /**
  16288. * Mechanic
  16289. **/
  16290. /*==========================================
  16291. * Magic Decoy Material List
  16292. *------------------------------------------*/
  16293. void clif_magicdecoy_list( map_session_data *sd, uint16 skill_lv, short x, short y ){
  16294. nullpo_retv( sd );
  16295. int fd = sd->fd;
  16296. if( !session_isActive( fd ) ){
  16297. return;
  16298. }
  16299. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16300. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP(fd, 0);
  16301. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16302. int count = 0;
  16303. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16304. if( itemdb_group.item_exists( IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid ) ) {
  16305. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16306. count++;
  16307. }
  16308. }
  16309. if( count > 0 ) {
  16310. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16311. WFIFOSET( fd, p->packetLength );
  16312. sd->menuskill_id = NC_MAGICDECOY;
  16313. sd->menuskill_val = skill_lv;
  16314. sd->sc.comet_x = x;
  16315. sd->sc.comet_y = y;
  16316. }else{
  16317. clif_skill_fail( sd, NC_MAGICDECOY, USESKILL_FAIL_LEVEL, 0 );
  16318. }
  16319. }
  16320. /*==========================================
  16321. * Guillotine Cross Poisons List
  16322. *------------------------------------------*/
  16323. void clif_poison_list( map_session_data *sd, uint16 skill_lv ){
  16324. nullpo_retv( sd );
  16325. int fd = sd->fd;
  16326. if( !session_isActive( fd ) ){
  16327. return;
  16328. }
  16329. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + MAX_INVENTORY * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub ) );
  16330. struct PACKET_ZC_MAKINGARROW_LIST *p = (struct PACKET_ZC_MAKINGARROW_LIST *)WFIFOP( fd, 0 );
  16331. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16332. int count = 0;
  16333. for( int i = 0; i < MAX_INVENTORY; i++ ){
  16334. if( itemdb_group.item_exists( IG_POISON, sd->inventory.u.items_inventory[i].nameid ) ){
  16335. p->items[count].itemId = client_nameid( sd->inventory.u.items_inventory[i].nameid );
  16336. count++;
  16337. }
  16338. }
  16339. if( count > 0 ){
  16340. p->packetLength = sizeof( struct PACKET_ZC_MAKINGARROW_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGARROW_LIST_sub );
  16341. WFIFOSET( fd, p->packetLength );
  16342. sd->menuskill_id = GC_POISONINGWEAPON;
  16343. sd->menuskill_val = skill_lv;
  16344. }else{
  16345. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON, 0 );
  16346. }
  16347. }
  16348. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  16349. int clif_autoshadowspell_list(map_session_data *sd) {
  16350. int fd, i, c;
  16351. nullpo_ret(sd);
  16352. fd = sd->fd;
  16353. if( !session_isActive(fd) )
  16354. return 0;
  16355. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  16356. return 0;
  16357. WFIFOHEAD(fd, 2 * 6 + 4);
  16358. WFIFOW(fd,0) = 0x442;
  16359. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  16360. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  16361. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  16362. skill_get_inf2(sd->status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16363. {
  16364. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  16365. c++;
  16366. }
  16367. if( c > 0 ) {
  16368. WFIFOW(fd,2) = 8 + c * 2;
  16369. WFIFOL(fd,4) = c;
  16370. WFIFOSET(fd,WFIFOW(fd,2));
  16371. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  16372. sd->menuskill_val = c;
  16373. } else {
  16374. status_change_end(&sd->bl,SC_STOP);
  16375. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  16376. }
  16377. return 1;
  16378. }
  16379. /*===========================================
  16380. * Skill list for Four Elemental Analysis
  16381. * and Change Material skills.
  16382. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16383. *------------------------------------------*/
  16384. int clif_skill_itemlistwindow( map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16385. #if PACKETVER >= 20090922
  16386. int fd = sd->fd;
  16387. nullpo_ret(sd);
  16388. sd->menuskill_id = skill_id; // To prevent hacking.
  16389. sd->menuskill_val = skill_lv;
  16390. if( skill_id == GN_CHANGEMATERIAL )
  16391. skill_lv = 0; // Changematerial
  16392. WFIFOHEAD(fd, packet_len(0x7e3));
  16393. WFIFOW(fd,0) = 0x7e3;
  16394. WFIFOL(fd,2) = skill_lv;
  16395. WFIFOL(fd,4) = 0;
  16396. WFIFOSET(fd, packet_len(0x7e3));
  16397. #endif
  16398. return 1;
  16399. }
  16400. /*==========================================
  16401. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16402. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16403. * RFIFOL(fd,2) - type (currently not used)
  16404. *------------------------------------------*/
  16405. void clif_parse_SkillSelectMenu(int fd, map_session_data *sd) {
  16406. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16407. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  16408. if (sd->menuskill_id == SA_AUTOSPELL) {
  16409. sd->state.workinprogress = WIP_DISABLE_NONE;
  16410. skill_autospell(sd, RFIFOW(fd, info->pos[1]));
  16411. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16412. if (pc_istrading(sd)) {
  16413. clif_skill_fail(sd, sd->ud.skill_id, USESKILL_FAIL_LEVEL, 0);
  16414. clif_menuskill_clear(sd);
  16415. return;
  16416. }
  16417. skill_select_menu(sd, RFIFOW(fd, info->pos[1]));
  16418. } else
  16419. return;
  16420. clif_menuskill_clear(sd);
  16421. }
  16422. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16423. /// 08cf <id>.L <type>.W <num>.W
  16424. void clif_spiritcharm(map_session_data *sd) {
  16425. unsigned char buf[10];
  16426. nullpo_retv(sd);
  16427. WBUFW(buf,0) = 0x08cf;
  16428. WBUFL(buf,2) = sd->bl.id;
  16429. WBUFW(buf,6) = sd->spiritcharm_type;
  16430. WBUFW(buf,8) = sd->spiritcharm;
  16431. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16432. }
  16433. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  16434. /// 0907 <index>.W
  16435. ///
  16436. /// R 0908 <index>.w <type>.b
  16437. /// type:
  16438. /// 0 = move item to personal tab
  16439. /// 1 = move item to normal tab
  16440. void clif_parse_MoveItem(int fd, map_session_data *sd) {
  16441. #if PACKETVER >= 20111122
  16442. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16443. int index = RFIFOW(fd,info->pos[0]) - 2;
  16444. int type = RFIFOB(fd, info->pos[1]);
  16445. /* can't move while dead. */
  16446. if(pc_isdead(sd)) {
  16447. return;
  16448. }
  16449. if (index < 0 || index >= MAX_INVENTORY)
  16450. return;
  16451. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  16452. sd->inventory.u.items_inventory[index].favorite = 0;
  16453. else if( type == 0 )
  16454. sd->inventory.u.items_inventory[index].favorite = 1;
  16455. else
  16456. return;/* nothing to do. */
  16457. clif_favorite_item(sd, index);
  16458. #endif
  16459. }
  16460. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  16461. /// 0900 <index>.W <favorite>.B
  16462. void clif_favorite_item(map_session_data* sd, unsigned short index) {
  16463. int fd = sd->fd;
  16464. WFIFOHEAD(fd,packet_len(0x908));
  16465. WFIFOW(fd,0) = 0x908;
  16466. WFIFOW(fd,2) = index+2;
  16467. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  16468. WFIFOSET(fd,packet_len(0x908));
  16469. }
  16470. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16471. void clif_snap( struct block_list *bl, short x, short y ) {
  16472. unsigned char buf[10];
  16473. WBUFW(buf,0) = 0x8d2;
  16474. WBUFL(buf,2) = bl->id;
  16475. WBUFW(buf,6) = x;
  16476. WBUFW(buf,8) = y;
  16477. if( disguised(bl) )
  16478. {
  16479. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16480. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16481. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16482. } else
  16483. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16484. }
  16485. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16486. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16487. #if PACKETVER >= 20120404
  16488. WFIFOHEAD(fd,packet_len(0x977));
  16489. WFIFOW(fd,0) = 0x977;
  16490. WFIFOL(fd,2) = md->bl.id;
  16491. WFIFOL(fd,6) = md->status.hp;
  16492. WFIFOL(fd,10) = md->status.max_hp;
  16493. WFIFOSET(fd,packet_len(0x977));
  16494. #endif
  16495. }
  16496. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16497. void __attribute__ ((unused)) clif_parse_dull(int fd, map_session_data *sd) {
  16498. return;
  16499. }
  16500. void clif_partytickack(map_session_data* sd, bool flag) {
  16501. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  16502. WFIFOW(sd->fd,0) = 0x2c9;
  16503. WFIFOB(sd->fd,2) = flag;
  16504. WFIFOSET(sd->fd, packet_len(0x2c9));
  16505. }
  16506. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16507. /// 0979 <world name>.24B <char name>.24B
  16508. void clif_ackworldinfo(map_session_data* sd) {
  16509. int fd;
  16510. nullpo_retv(sd);
  16511. fd = sd->fd;
  16512. WFIFOHEAD(fd,packet_len(0x979));
  16513. WFIFOW(fd,0)=0x979;
  16514. //AID -> world name ?
  16515. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16516. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16517. WFIFOSET(fd,packet_len(0x979));
  16518. }
  16519. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16520. /// 0978 <AID>.L
  16521. void clif_parse_reqworldinfo(int fd,map_session_data *sd) {
  16522. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16523. if(sd)
  16524. clif_ackworldinfo(sd);
  16525. }
  16526. static void clif_loadConfirm( map_session_data *sd ){
  16527. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16528. nullpo_retv( sd );
  16529. struct PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16530. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16531. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16532. clif_instance_info( *sd );
  16533. #endif
  16534. }
  16535. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16536. /// 0447
  16537. void clif_parse_blocking_playcancel( int fd, map_session_data *sd ){
  16538. clif_loadConfirm( sd );
  16539. }
  16540. /// req world info (CZ_CLIENT_VERSION)
  16541. /// 044A <version>.L
  16542. void clif_parse_client_version(int fd, map_session_data *sd) {
  16543. //if(sd)
  16544. ;
  16545. }
  16546. /// Ranking list
  16547. /// ranking pointlist { <name>.24B <point>.L }*10
  16548. void clif_sub_ranklist(unsigned char *buf,int idx,map_session_data* sd, enum e_rank rankingtype){
  16549. struct fame_list* list;
  16550. int i, size = MAX_FAME_LIST;
  16551. switch(rankingtype) {
  16552. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16553. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16554. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16555. // PK currently unsupported
  16556. case RANK_KILLER: list = NULL; size = 0; break;
  16557. default:
  16558. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16559. return;
  16560. }
  16561. //Packet size limits this list to 10 elements. [Skotlex]
  16562. for (i = 0; i < min(10,size); i++) {
  16563. if (list[i].id > 0) {
  16564. const char* name;
  16565. if (strcmp(list[i].name, "-") == 0 &&
  16566. (name = map_charid2nick(list[i].id)) != NULL)
  16567. {
  16568. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16569. } else {
  16570. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16571. }
  16572. } else {
  16573. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16574. }
  16575. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16576. }
  16577. for(;i < 10; i++) { //In case the MAX is less than 10.
  16578. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16579. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16580. }
  16581. }
  16582. /// Request for the blacksmith ranklist.
  16583. /// /blacksmith command sends this packet to the server.
  16584. /// 0217 (CZ_BLACKSMITH_RANK)
  16585. void clif_parse_Blacksmith( int fd, map_session_data *sd ){
  16586. clif_ranklist(sd,RANK_BLACKSMITH);
  16587. }
  16588. /// Request for the alchemist ranklist.
  16589. /// /alchemist command sends this packet to the server.
  16590. /// 0218 (CZ_ALCHEMIST_RANK)
  16591. void clif_parse_Alchemist( int fd, map_session_data *sd ){
  16592. clif_ranklist(sd,RANK_ALCHEMIST);
  16593. }
  16594. /// Request for the taekwon ranklist.
  16595. /// /taekwon command sends this packet to the server.
  16596. /// 0225 (CZ_TAEKWON_RANK)
  16597. void clif_parse_Taekwon( int fd, map_session_data *sd ){
  16598. clif_ranklist(sd,RANK_TAEKWON);
  16599. }
  16600. /// Request for the killer ranklist.
  16601. /// /pk command sends this packet to the server.
  16602. /// 0237 (CZ_KILLER_RANK)
  16603. void clif_parse_RankingPk( int fd, map_session_data *sd ){
  16604. clif_ranklist(sd,RANK_KILLER);
  16605. }
  16606. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16607. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16608. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16609. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16610. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16611. void clif_ranklist(map_session_data *sd, int16 rankingType) {
  16612. enum e_rank rank;
  16613. #if PACKETVER < 20130710
  16614. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16615. short cmd;
  16616. switch( rankingType ){
  16617. case RANK_BLACKSMITH: cmd = 0x219; break;
  16618. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16619. case RANK_TAEKWON: cmd = 0x226; break;
  16620. case RANK_KILLER: cmd = 0x238; break;
  16621. default:
  16622. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16623. return;
  16624. }
  16625. // Can be safely casted here, since we validated it before
  16626. rank = (enum e_rank)rankingType;
  16627. WBUFW(buf,0) = cmd;
  16628. clif_sub_ranklist(buf,2,sd,rank);
  16629. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16630. #else
  16631. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16632. int mypoint = 0;
  16633. switch( rankingType ){
  16634. case RANK_BLACKSMITH:
  16635. case RANK_ALCHEMIST:
  16636. case RANK_TAEKWON:
  16637. case RANK_KILLER:
  16638. break;
  16639. default:
  16640. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16641. return;
  16642. }
  16643. // Can be safely casted here, since we validated it before
  16644. rank = (enum e_rank)rankingType;
  16645. WBUFW(buf,0) = 0x97d;
  16646. WBUFW(buf,2) = rank;
  16647. clif_sub_ranklist(buf,4,sd,rank);
  16648. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16649. case MAPID_BLACKSMITH:
  16650. case MAPID_ALCHEMIST:
  16651. case MAPID_TAEKWON:
  16652. mypoint = sd->status.fame;
  16653. }
  16654. WBUFL(buf,284) = mypoint; //mypoint
  16655. clif_send(buf, 288, &sd->bl, SELF);
  16656. #endif
  16657. }
  16658. /*
  16659. * 097c <type> (CZ_REQ_RANKING)
  16660. * type
  16661. * 0: /blacksmith
  16662. * 1: /alchemist
  16663. * 2: /taekwon
  16664. * 3: /pk
  16665. * */
  16666. void clif_parse_ranklist(int fd,map_session_data *sd) {
  16667. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16668. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16669. clif_ranklist(sd,rankingtype);
  16670. }
  16671. /// Updates the fame rank points for the given ranking.
  16672. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16673. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16674. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16675. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16676. void clif_update_rankingpoint(map_session_data &sd, int rankingtype, int point) {
  16677. int fd = sd.fd;
  16678. #if PACKETVER < 20130710
  16679. short cmd;
  16680. switch(rankingtype){
  16681. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16682. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16683. case RANK_TAEKWON: cmd = 0x224; break;
  16684. default:
  16685. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16686. return;
  16687. }
  16688. WFIFOHEAD(fd,packet_len(cmd));
  16689. WFIFOW(fd,0) = cmd;
  16690. WFIFOL(fd,2) = point;
  16691. WFIFOL(fd,6) = sd.status.fame;
  16692. WFIFOSET(fd, packet_len(cmd));
  16693. #else
  16694. WFIFOHEAD(fd,packet_len(0x97e));
  16695. WFIFOW(fd,0) = 0x97e;
  16696. WFIFOW(fd,2) = rankingtype;
  16697. WFIFOL(fd,4) = point;
  16698. WFIFOL(fd,8) = sd.status.fame;
  16699. WFIFOSET(fd,packet_len(0x97e));
  16700. #endif
  16701. }
  16702. /**
  16703. * Transmit personal information to player. (rates)
  16704. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16705. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16706. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16707. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16708. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16709. * FIXME!
  16710. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16711. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16712. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16713. */
  16714. #ifdef VIP_ENABLE
  16715. void clif_display_pinfo( map_session_data& sd ){
  16716. #if PACKETVER_MAIN_NUM >= 20110627 || PACKETVER_RE_NUM >= 20110628 || defined(PACKETVER_ZERO)
  16717. // TODO: Whoever wants to take the blame, fix this crappy logic below - and yes I know indentation is wrong, but CANT TOUCH THIS! *sings* [Lemongrass]
  16718. int details_bexp[PINFO_MAX], details_drop[PINFO_MAX], details_penalty[PINFO_MAX];
  16719. /**
  16720. * EXP
  16721. */
  16722. //0:PCRoom
  16723. details_bexp[PINFO_BASIC] = map_getmapflag( sd.bl.m, MF_BEXP );
  16724. if (details_bexp[PINFO_BASIC] == 100 || !details_bexp[PINFO_BASIC])
  16725. details_bexp[PINFO_BASIC] = 0;
  16726. else {
  16727. if (details_bexp[PINFO_BASIC] < 100) {
  16728. details_bexp[PINFO_BASIC] = 100 - details_bexp[PINFO_BASIC];
  16729. details_bexp[PINFO_BASIC] = 0 - details_bexp[PINFO_BASIC];
  16730. } else
  16731. details_bexp[PINFO_BASIC] = details_bexp[PINFO_BASIC] - 100;
  16732. }
  16733. //1:Premium
  16734. if( pc_isvip( &sd ) ){
  16735. details_bexp[PINFO_PREMIUM] = battle_config.vip_base_exp_increase * battle_config.base_exp_rate / 100;
  16736. if (details_bexp[PINFO_PREMIUM] < 0)
  16737. details_bexp[PINFO_PREMIUM] = 0 - details_bexp[PINFO_PREMIUM];
  16738. } else
  16739. details_bexp[PINFO_PREMIUM] = 0;
  16740. //2:Server
  16741. details_bexp[PINFO_SERVER] = battle_config.base_exp_rate;
  16742. if (details_bexp[PINFO_SERVER] == 100)
  16743. details_bexp[PINFO_SERVER] = 0;
  16744. else {
  16745. if (details_bexp[PINFO_SERVER] < 100) {
  16746. details_bexp[PINFO_SERVER] = 100 - details_bexp[PINFO_SERVER];
  16747. details_bexp[PINFO_SERVER] = 0 - details_bexp[PINFO_SERVER];
  16748. } else
  16749. details_bexp[PINFO_SERVER] = details_bexp[PINFO_SERVER] - 100;
  16750. }
  16751. //3:TPLUS
  16752. details_bexp[PINFO_CAFE] = 0;
  16753. /**
  16754. * Drop rate
  16755. */
  16756. //0:PCRoom
  16757. details_drop[PINFO_BASIC] = 0;
  16758. //1:Premium
  16759. if( pc_isvip( &sd ) ){
  16760. details_drop[PINFO_PREMIUM] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16761. if (details_drop[PINFO_PREMIUM] < 0)
  16762. details_drop[PINFO_PREMIUM] = 0 - details_drop[PINFO_PREMIUM];
  16763. } else
  16764. details_drop[PINFO_PREMIUM] = 0;
  16765. //2:Server
  16766. details_drop[PINFO_SERVER] = battle_config.item_rate_common;
  16767. if (details_drop[PINFO_SERVER] == 100)
  16768. details_drop[PINFO_SERVER] = 0;
  16769. else {
  16770. if (details_drop[PINFO_SERVER] < 100) {
  16771. details_drop[PINFO_SERVER] = 100 - details_drop[PINFO_SERVER];
  16772. details_drop[PINFO_SERVER] = 0 - details_drop[PINFO_SERVER];
  16773. } else
  16774. details_drop[PINFO_SERVER] = details_drop[PINFO_SERVER] - 100;
  16775. }
  16776. //3:TPLUS
  16777. details_drop[PINFO_CAFE] = 0;
  16778. /**
  16779. * Penalty rate
  16780. */
  16781. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16782. //0:PCRoom
  16783. details_penalty[PINFO_BASIC] = 0;
  16784. //1:Premium
  16785. if( pc_isvip( &sd ) ){
  16786. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base;
  16787. if (details_penalty[PINFO_PREMIUM] == 100)
  16788. details_penalty[PINFO_PREMIUM] = 0;
  16789. else {
  16790. if (details_penalty[PINFO_PREMIUM] < 100) {
  16791. details_penalty[PINFO_PREMIUM] = 100 - details_penalty[PINFO_PREMIUM];
  16792. details_penalty[PINFO_PREMIUM] = 0 - details_penalty[PINFO_PREMIUM];
  16793. } else
  16794. details_penalty[PINFO_PREMIUM] = details_penalty[PINFO_PREMIUM] - 100;
  16795. }
  16796. if (battle_config.death_penalty_base > battle_config.vip_exp_penalty_base)
  16797. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base - battle_config.death_penalty_base;
  16798. } else
  16799. details_penalty[PINFO_PREMIUM] = 0;
  16800. //2:Server
  16801. details_penalty[PINFO_SERVER] = battle_config.death_penalty_base;
  16802. if (details_penalty[PINFO_SERVER] == 100)
  16803. details_penalty[PINFO_SERVER] = 0;
  16804. else {
  16805. if (details_penalty[PINFO_SERVER] < 100) {
  16806. details_penalty[PINFO_SERVER] = 100 - details_penalty[PINFO_SERVER];
  16807. details_penalty[PINFO_SERVER] = 0 - details_penalty[PINFO_SERVER];
  16808. } else
  16809. details_penalty[PINFO_SERVER] = details_penalty[PINFO_SERVER] - 100;
  16810. }
  16811. //3:TPLUS
  16812. details_penalty[PINFO_CAFE] = 0;
  16813. struct PACKET_ZC_PERSONAL_INFOMATION* p = (struct PACKET_ZC_PERSONAL_INFOMATION*)packet_buffer;
  16814. p->packetType = HEADER_ZC_PERSONAL_INFOMATION;
  16815. p->length = sizeof( *p ) + PINFO_MAX * sizeof( p->details[0] );
  16816. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16817. p->total_exp = 100 * 1000;
  16818. p->total_death = 100 * 1000;
  16819. p->total_drop = 100 * 1000;
  16820. #else
  16821. p->total_exp = 100;
  16822. p->total_death = 100;
  16823. p->total_drop = 100;
  16824. #endif
  16825. for( int i = PINFO_BASIC; i < PINFO_MAX; i++ ){
  16826. p->details[i].type = i; // infotype 0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16827. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16828. p->details[i].exp = details_bexp[i] * 1000;
  16829. p->details[i].death = details_penalty[i] * 1000;
  16830. p->details[i].drop = details_drop[i] * 1000;
  16831. #else
  16832. p->details[i].exp = details_bexp[i];
  16833. p->details[i].death = details_penalty[i];
  16834. p->details[i].drop = details_drop[i];
  16835. #endif
  16836. p->total_exp += p->details[i].exp;
  16837. p->total_death += p->details[i].death;
  16838. p->total_drop += p->details[i].drop;
  16839. }
  16840. clif_send( p, p->length, &sd.bl, SELF );
  16841. #endif
  16842. }
  16843. #endif
  16844. void clif_parse_GMFullStrip(int fd, map_session_data *sd) {
  16845. char cmd[30];
  16846. int t_aid = RFIFOL(fd,2);
  16847. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16848. is_atcommand(fd, sd, cmd, 1);
  16849. }
  16850. /**
  16851. * Marks Crimson Marker target on mini-map to the caster
  16852. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16853. * @param fd
  16854. * @param bl Crimson Marker target
  16855. **/
  16856. void clif_crimson_marker( map_session_data& sd, struct block_list& bl, bool remove ){
  16857. #if PACKETVER_MAIN_NUM >= 20130731 || PACKETVER_RE_NUM >= 20130707 || defined(PACKETVER_ZERO)
  16858. struct PACKET_ZC_C_MARKERINFO p = {};
  16859. p.PacketType = HEADER_ZC_C_MARKERINFO;
  16860. p.AID = bl.id;
  16861. if( remove ){
  16862. p.xPos = -1;
  16863. p.yPos = -1;
  16864. }else{
  16865. p.xPos = bl.x;
  16866. p.yPos = bl.y;
  16867. }
  16868. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16869. #endif
  16870. }
  16871. /**
  16872. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16873. **/
  16874. void clif_notify_bindOnEquip( map_session_data& sd, int16 index ){
  16875. #if PACKETVER >= 20070227
  16876. struct PACKET_ZC_NOTIFY_BIND_ON_EQUIP p = {};
  16877. p.packetType = HEADER_ZC_NOTIFY_BIND_ON_EQUIP;
  16878. p.index = client_index( index );
  16879. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16880. #endif
  16881. }
  16882. /**
  16883. * [Ind/Hercules]
  16884. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16885. **/
  16886. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16887. char buf[256];
  16888. size_t len;
  16889. nullpo_retv(bl);
  16890. if(!message)
  16891. return;
  16892. len = strlen(message)+1;
  16893. if( len > sizeof(buf)-8 ) {
  16894. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16895. len = sizeof(buf)-8;
  16896. }
  16897. WBUFW(buf,0) = 0x8b3;
  16898. WBUFW(buf,2) = (uint16)(len+8);
  16899. WBUFL(buf,4) = bl->id;
  16900. safestrncpy(WBUFCP(buf,8), message, len);
  16901. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16902. }
  16903. /**
  16904. * [Ind/Hercules]
  16905. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16906. **/
  16907. void clif_party_leaderchanged(map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16908. unsigned char buf[10];
  16909. nullpo_retv(sd);
  16910. WBUFW(buf,0) = 0x7fc;
  16911. WBUFL(buf,2) = prev_leader_aid;
  16912. WBUFL(buf,6) = new_leader_aid;
  16913. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16914. }
  16915. /**
  16916. * Sends a clan message to a player
  16917. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16918. **/
  16919. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16920. #if PACKETVER >= 20131223
  16921. map_session_data *sd;
  16922. uint8 buf[256];
  16923. if( len == 0 ){
  16924. return;
  16925. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16926. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16927. len = sizeof(buf)-5-NAME_LENGTH;
  16928. }
  16929. WBUFW(buf, 0) = 0x98e;
  16930. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16931. // Offially the sender name should also be filled here, but it is not required by the client and since it's in the message too we do not fill it
  16932. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16933. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16934. if((sd = clan_getavailablesd(clan)) != NULL)
  16935. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16936. #endif
  16937. }
  16938. /**
  16939. * Parses a clan message from a player.
  16940. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16941. **/
  16942. void clif_parse_clan_chat( int fd, map_session_data* sd ){
  16943. #if PACKETVER >= 20131223
  16944. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16945. // validate packet and retrieve name and message
  16946. if( !clif_process_message(sd, false, name, message, output ) )
  16947. return;
  16948. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16949. #endif
  16950. }
  16951. /**
  16952. * Sends the basic clan informations to the client.
  16953. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16954. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16955. **/
  16956. void clif_clan_basicinfo( map_session_data *sd ){
  16957. #if PACKETVER >= 20131223
  16958. int fd, offset, length, i, flag;
  16959. struct clan* clan;
  16960. char mapname[MAP_NAME_LENGTH_EXT];
  16961. nullpo_retv( sd );
  16962. nullpo_retv( clan = sd->clan );
  16963. // Check if the player has a valid session and is not autotrading
  16964. if( !clif_session_isValid( sd ) ){
  16965. return;
  16966. }
  16967. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16968. fd = sd->fd;
  16969. WFIFOHEAD(fd,length);
  16970. memset( WFIFOP(fd, 0), 0, length );
  16971. WFIFOW( fd, 0 ) = 0x98a;
  16972. WFIFOL( fd, 4 ) = clan->id;
  16973. offset = 8;
  16974. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16975. offset += NAME_LENGTH;
  16976. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16977. offset += NAME_LENGTH;
  16978. mapindex_getmapname_ext( clan->map, mapname );
  16979. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16980. offset += MAP_NAME_LENGTH_EXT;
  16981. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16982. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16983. for( flag = 0; flag < 2; flag++ ){
  16984. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16985. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16986. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16987. offset += NAME_LENGTH;
  16988. }
  16989. }
  16990. }
  16991. WFIFOW( fd, 2 ) = offset;
  16992. WFIFOSET(fd,offset);
  16993. #endif
  16994. }
  16995. /**
  16996. * Updates the online and maximum player count of a clan.
  16997. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16998. **/
  16999. void clif_clan_onlinecount( struct clan* clan ){
  17000. #if PACKETVER >= 20131223
  17001. uint8 buf[6];
  17002. map_session_data *sd;
  17003. WBUFW(buf,0) = 0x988;
  17004. WBUFW(buf,2) = clan->connect_member;
  17005. WBUFW(buf,4) = clan->max_member;
  17006. if((sd = clan_getavailablesd(clan)) != NULL)
  17007. clif_send(buf, 6, &sd->bl, CLAN);
  17008. #endif
  17009. }
  17010. /**
  17011. * Notifies the client that the player has left his clan.
  17012. * 0989 (ZC_ACK_CLAN_LEAVE)
  17013. **/
  17014. void clif_clan_leave( map_session_data* sd ){
  17015. #if PACKETVER >= 20131223
  17016. int fd;
  17017. nullpo_retv( sd );
  17018. if( !clif_session_isValid( sd ) ){
  17019. return;
  17020. }
  17021. fd = sd->fd;
  17022. WFIFOHEAD(fd,2);
  17023. WFIFOW(fd,0) = 0x989;
  17024. WFIFOSET(fd,2);
  17025. #endif
  17026. }
  17027. /**
  17028. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  17029. * 0A2F <result>.B <title_id>.L
  17030. */
  17031. void clif_change_title_ack(map_session_data *sd, unsigned char result, unsigned long title_id)
  17032. {
  17033. #if PACKETVER >= 20150513
  17034. int fd;
  17035. nullpo_retv(sd);
  17036. if (!clif_session_isValid(sd))
  17037. return;
  17038. fd = sd->fd;
  17039. WFIFOHEAD(fd, packet_len(0xa2f));
  17040. WFIFOW(fd, 0) = 0xa2f;
  17041. WFIFOB(fd, 2) = result;
  17042. WFIFOL(fd, 3) = title_id;
  17043. WFIFOSET(fd, packet_len(0xa2f));
  17044. #endif
  17045. }
  17046. /**
  17047. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  17048. * 0A2E <title_id>.L
  17049. */
  17050. void clif_parse_change_title(int fd, map_session_data *sd)
  17051. {
  17052. int title_id;
  17053. nullpo_retv(sd);
  17054. title_id = RFIFOL(fd, 2);
  17055. if( title_id == sd->status.title_id ){
  17056. // It is exactly the same as the old one
  17057. return;
  17058. }else if( title_id <= 0 ){
  17059. sd->status.title_id = 0;
  17060. }else{
  17061. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  17062. clif_change_title_ack(sd, 1, title_id);
  17063. return;
  17064. }
  17065. sd->status.title_id = title_id;
  17066. }
  17067. clif_name_area(&sd->bl);
  17068. clif_change_title_ack(sd, 0, title_id);
  17069. }
  17070. #ifdef DUMP_UNKNOWN_PACKET
  17071. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  17072. {
  17073. const char* packet_txt = "save/packet.txt";
  17074. FILE* fp;
  17075. time_t time_server;
  17076. struct tm *datetime;
  17077. char datestr[512];
  17078. time(&time_server); // get time in seconds since 1/1/1970
  17079. datetime = localtime(&time_server); // convert seconds in structure
  17080. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  17081. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  17082. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  17083. if( sd ) {
  17084. fprintf(fp, "Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID) at %s \n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id,datestr);
  17085. } else {
  17086. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17087. }
  17088. WriteDump(fp, RFIFOP(fd,0), packet_len);
  17089. fprintf(fp, "\n");
  17090. fclose(fp);
  17091. } else {
  17092. ShowError("Failed to write '%s'.\n", packet_txt);
  17093. // Dump on console instead
  17094. if( sd ) {
  17095. ShowDebug("Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID) at %s\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id,datestr);
  17096. } else {
  17097. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17098. }
  17099. ShowDump(RFIFOP(fd,0), packet_len);
  17100. }
  17101. }
  17102. #endif
  17103. /// Roulette System
  17104. /// Author: Yommy
  17105. void roulette_generate_bonus( map_session_data& sd ){
  17106. if( battle_config.feature_roulette_bonus_reward && sd.roulette.bonusItemID == 0 ){
  17107. int next_stage = 0;
  17108. if( sd.roulette_point.bronze > 0 ){
  17109. next_stage = 0;
  17110. }else if( sd.roulette_point.silver > 9 ){
  17111. next_stage = 2;
  17112. }else if( sd.roulette_point.gold > 9 ){
  17113. next_stage = 4;
  17114. }
  17115. // Get bonus item stage only from current stage or higher
  17116. int reward_stage = rnd_value( next_stage, MAX_ROULETTE_LEVEL - 1 );
  17117. sd.roulette.bonusItemID = rd.nameid[reward_stage][rnd()%rd.items[reward_stage]];
  17118. }else{
  17119. sd.roulette.bonusItemID = 0;
  17120. }
  17121. }
  17122. /// Opens the roulette window
  17123. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  17124. void clif_roulette_open( map_session_data* sd ){
  17125. nullpo_retv( sd );
  17126. roulette_generate_bonus( *sd );
  17127. struct packet_roulette_open_ack p;
  17128. p.PacketType = 0xa1a;
  17129. p.Result = 0; // result
  17130. p.Serial = 0; // serial
  17131. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  17132. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  17133. p.AdditionItemID = sd->roulette.bonusItemID;
  17134. p.GoldPoint = sd->roulette_point.gold;
  17135. p.SilverPoint = sd->roulette_point.silver;
  17136. p.BronzePoint = sd->roulette_point.bronze;
  17137. sd->state.roulette_open = true;
  17138. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17139. }
  17140. /// Request to open the roulette window
  17141. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  17142. void clif_parse_roulette_open( int fd, map_session_data* sd ){
  17143. nullpo_retv(sd);
  17144. if (!battle_config.feature_roulette) {
  17145. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17146. return;
  17147. }
  17148. clif_roulette_open(sd);
  17149. }
  17150. /// Sends the info about the available roulette rewards to the client
  17151. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  17152. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  17153. void clif_roulette_info( map_session_data* sd ){
  17154. nullpo_retv(sd);
  17155. struct packet_roulette_info_ack p;
  17156. p.PacketType = rouletteinfoackType;
  17157. p.PacketLength = sizeof(p);
  17158. p.RouletteSerial = 1;
  17159. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  17160. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  17161. p.ItemInfo[count].Row = i;
  17162. p.ItemInfo[count].Position = j;
  17163. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  17164. p.ItemInfo[count].Count = rd.qty[i][j];
  17165. #if PACKETVER >= 20180511
  17166. p.ItemInfo[count].unused = 0;
  17167. #endif
  17168. count++;
  17169. }
  17170. }
  17171. clif_send( &p, sizeof(p), &sd->bl, SELF );
  17172. }
  17173. /// Request the roulette reward data
  17174. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  17175. void clif_parse_roulette_info( int fd, map_session_data* sd ){
  17176. nullpo_retv(sd);
  17177. if (!battle_config.feature_roulette) {
  17178. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17179. return;
  17180. }
  17181. clif_roulette_info(sd);
  17182. }
  17183. /// Notification of the client that the roulette window was closed
  17184. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  17185. void clif_parse_roulette_close( int fd, map_session_data* sd ){
  17186. nullpo_retv(sd);
  17187. if (!battle_config.feature_roulette) {
  17188. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17189. return;
  17190. }
  17191. sd->state.roulette_open = false;
  17192. }
  17193. /// Response to a item reward request
  17194. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17195. static void clif_roulette_recvitem_ack(map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17196. #if PACKETVER >= 20141016
  17197. nullpo_retv(sd);
  17198. struct packet_roulette_itemrecv_ack p;
  17199. p.PacketType = roulettercvitemackType;
  17200. p.Result = type;
  17201. p.AdditionItemID = sd->roulette.bonusItemID;
  17202. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17203. #endif
  17204. }
  17205. /**
  17206. * Claim roulette reward
  17207. * @param sd Player
  17208. * @return 0:Success
  17209. **/
  17210. static uint8 clif_roulette_getitem(map_session_data *sd) {
  17211. struct item it;
  17212. uint8 res = 1;
  17213. unsigned short factor = 1;
  17214. nullpo_retr(1, sd);
  17215. if (sd->roulette.prizeIdx < 0)
  17216. return RECV_ITEM_FAILED;
  17217. memset(&it, 0, sizeof(it));
  17218. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17219. it.identify = 1;
  17220. if( sd->roulette.bonusItemID != 0 ){
  17221. if( sd->roulette.bonusItemID == it.nameid && battle_config.feature_roulette_bonus_reward && !( rd.flag[sd->roulette.prizeStage][sd->roulette.prizeIdx]&1 ) ){
  17222. factor = 2;
  17223. // Reset the Bonus Item to trigger new calculation
  17224. sd->roulette.bonusItemID = 0;
  17225. }else{
  17226. for( int i = 0; i < MAX_ROULETTE_LEVEL && sd->roulette.bonusItemID != 0; i++ ){
  17227. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i && sd->roulette.bonusItemID != 0; j++ ){
  17228. if( rd.nameid[i][j] == sd->roulette.bonusItemID ){
  17229. // If you reached a equal or higher level than the first level with the bonus item in it, you missed your chance and a new bonus item will be calculated
  17230. if( sd->roulette.prizeStage >= i ){
  17231. // Reset the Bonus Item to trigger new calculation and to cancel the loops
  17232. sd->roulette.bonusItemID = 0;
  17233. }
  17234. }
  17235. }
  17236. }
  17237. }
  17238. }
  17239. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx] * factor, LOG_TYPE_ROULETTE)) == 0) {
  17240. ; // onSuccess
  17241. }
  17242. if( sd->roulette.bonusItemID == 0 ){
  17243. roulette_generate_bonus( *sd );
  17244. }
  17245. sd->roulette.claimPrize = false;
  17246. sd->roulette.prizeStage = 0;
  17247. sd->roulette.prizeIdx = -1;
  17248. sd->roulette.stage = 0;
  17249. return res;
  17250. }
  17251. /// Update Roulette window with current stats
  17252. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17253. void clif_roulette_generate( map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17254. nullpo_retv( sd );
  17255. struct packet_roulette_generate_ack p;
  17256. p.PacketType = roulettgenerateackType;
  17257. p.Result = result;
  17258. p.Step = stage;
  17259. p.Idx = prizeIdx;
  17260. p.AdditionItemID = battle_config.feature_roulette_bonus_reward ? bonusItemID : 0;
  17261. p.RemainGold = sd->roulette_point.gold;
  17262. p.RemainSilver = sd->roulette_point.silver;
  17263. p.RemainBronze = sd->roulette_point.bronze;
  17264. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17265. }
  17266. /// Request to start the roulette
  17267. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17268. void clif_parse_roulette_generate( int fd, map_session_data* sd ){
  17269. enum GENERATE_ROULETTE_ACK result;
  17270. nullpo_retv(sd);
  17271. if (!battle_config.feature_roulette) {
  17272. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17273. return;
  17274. }
  17275. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17276. return;
  17277. }
  17278. // Player has not claimed his prize yet
  17279. if( sd->roulette.claimPrize ){
  17280. clif_roulette_getitem( sd );
  17281. }
  17282. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17283. // Make sure everything is reset
  17284. sd->roulette.stage = 0;
  17285. sd->roulette.claimPrize = false;
  17286. sd->roulette.prizeStage = 0;
  17287. sd->roulette.prizeIdx = -1;
  17288. }
  17289. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17290. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17291. }else{
  17292. if (!sd->roulette.stage) {
  17293. if (sd->roulette_point.bronze > 0) {
  17294. sd->roulette_point.bronze -= 1;
  17295. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17296. } else if (sd->roulette_point.silver > 9) {
  17297. sd->roulette_point.silver -= 10;
  17298. sd->roulette.stage = 2;
  17299. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17300. } else if (sd->roulette_point.gold > 9) {
  17301. sd->roulette_point.gold -= 10;
  17302. sd->roulette.stage = 4;
  17303. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17304. }
  17305. }
  17306. sd->roulette.prizeStage = sd->roulette.stage;
  17307. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17308. sd->roulette.claimPrize = true;
  17309. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17310. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17311. result = GENERATE_ROULETTE_LOSING;
  17312. sd->roulette.stage = 0;
  17313. }else{
  17314. result = GENERATE_ROULETTE_SUCCESS;
  17315. sd->roulette.stage++;
  17316. }
  17317. }
  17318. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx), sd->roulette.bonusItemID);
  17319. }
  17320. /// Request to claim a prize
  17321. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17322. void clif_parse_roulette_item( int fd, map_session_data* sd ){
  17323. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17324. nullpo_retv(sd);
  17325. if (!battle_config.feature_roulette) {
  17326. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17327. return;
  17328. }
  17329. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17330. return;
  17331. }
  17332. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17333. switch (clif_roulette_getitem(sd)) {
  17334. case ADDITEM_SUCCESS:
  17335. type = RECV_ITEM_SUCCESS;
  17336. break;
  17337. case ADDITEM_INVALID:
  17338. case ADDITEM_OVERITEM:
  17339. case ADDITEM_OVERAMOUNT:
  17340. type = RECV_ITEM_OVERCOUNT;
  17341. break;
  17342. case ADDITEM_OVERWEIGHT:
  17343. type = RECV_ITEM_OVERWEIGHT;
  17344. break;
  17345. case ADDITEM_STACKLIMIT:
  17346. default:
  17347. type = RECV_ITEM_FAILED;
  17348. break;
  17349. }
  17350. }
  17351. clif_roulette_recvitem_ack(sd,type);
  17352. }
  17353. /// MERGE ITEM
  17354. /**
  17355. * Acknowledge the client about item merger result
  17356. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17357. * @param fd
  17358. * @param sd
  17359. **/
  17360. void clif_merge_item_ack( map_session_data &sd, enum MERGE_ITEM_ACK type, uint16 index = 0, uint16 count = 0 ){
  17361. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17362. struct PACKET_ZC_ACK_MERGE_ITEM p = {};
  17363. p.packetType = HEADER_ZC_ACK_MERGE_ITEM;
  17364. if( type == MERGE_ITEM_SUCCESS ){
  17365. p.index = client_index( index );
  17366. }else{
  17367. p.index = index;
  17368. }
  17369. p.amount = count;
  17370. p.reason = type;
  17371. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17372. #endif
  17373. }
  17374. /**
  17375. * Check if item has the pair to be merged
  17376. * @param sd
  17377. * @param it Item
  17378. * @return True if has pair, False if not
  17379. **/
  17380. static bool clif_merge_item_has_pair(map_session_data *sd, struct item *it) {
  17381. struct item *it_;
  17382. unsigned short i;
  17383. nullpo_retr(false, sd);
  17384. ARR_FIND(0, MAX_INVENTORY, i, (it_ = &sd->inventory.u.items_inventory[i]) && it->nameid == it_->nameid && it->bound == it_->bound && memcmp(it_, it, sizeof(struct item)) != 0);
  17385. if (i < MAX_INVENTORY)
  17386. return true;
  17387. return false;
  17388. }
  17389. /**
  17390. * Check if item can be merged
  17391. * @param id Item Data
  17392. * @param it Item
  17393. * @return True if can be merged, False if not
  17394. **/
  17395. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17396. if (!id || !it)
  17397. return false;
  17398. if (id->type == IT_CASH)
  17399. return false;
  17400. if (!itemdb_isstackable2(id))
  17401. return false;
  17402. if (itemdb_isspecial(it->card[0]))
  17403. return false;
  17404. if (!it->unique_id)
  17405. return false;
  17406. return true;
  17407. }
  17408. /**
  17409. * Open available item to be merged.
  17410. * Only show 1 item in 1 process.
  17411. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17412. * @param sd
  17413. **/
  17414. void clif_merge_item_open( map_session_data& sd ){
  17415. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17416. struct PACKET_ZC_MERGE_ITEM_OPEN* p = (struct PACKET_ZC_MERGE_ITEM_OPEN*)packet_buffer;
  17417. p->packetType = HEADER_ZC_MERGE_ITEM_OPEN;
  17418. p->packetLen = sizeof( *p );
  17419. int n = 0;
  17420. // Get entries
  17421. for( int i = 0; i < MAX_INVENTORY; i++ ){
  17422. struct item* it = &sd.inventory.u.items_inventory[i];
  17423. if( !clif_merge_item_check( sd.inventory_data[i], it ) ){
  17424. continue;
  17425. }
  17426. if( clif_merge_item_has_pair( &sd, it ) ){
  17427. p->items[n++].index = client_index( i );
  17428. p->packetLen += sizeof( p->items[0] );
  17429. }
  17430. }
  17431. // No item need to be merged
  17432. if( n < 2 ){
  17433. clif_msg( &sd, MERGE_ITEM_NOT_AVAILABLE );
  17434. return;
  17435. }
  17436. clif_send( p, p->packetLen, &sd.bl, SELF );
  17437. #endif
  17438. }
  17439. /**
  17440. * Process item merge request.
  17441. * 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17442. * @param fd
  17443. * @param sd
  17444. **/
  17445. void clif_parse_merge_item_req( int fd, map_session_data* sd ){
  17446. struct PACKET_CZ_REQ_MERGE_ITEM* p = (struct PACKET_CZ_REQ_MERGE_ITEM*)RFIFOP( fd, 0 );
  17447. int count = ( p->packetLength - sizeof( *p ) ) / sizeof( p->indices[0] );
  17448. // No item need to be merged
  17449. if( count < 2 ){
  17450. clif_msg( sd, MERGE_ITEM_NOT_AVAILABLE );
  17451. return;
  17452. }
  17453. uint16 idx_main = server_index( p->indices[0] );
  17454. if( idx_main >= MAX_INVENTORY ){
  17455. return;
  17456. }
  17457. if( !clif_merge_item_check( sd->inventory_data[idx_main], &sd->inventory.u.items_inventory[idx_main] ) ){
  17458. clif_msg( sd, MERGE_ITEM_NOT_AVAILABLE );
  17459. return;
  17460. }
  17461. // Ensure each index only comes once
  17462. std::unordered_set<uint16> indices;
  17463. for( int i = 1; i < count; i++ ){
  17464. uint16 idx = server_index( p->indices[i] );
  17465. if( idx >= MAX_INVENTORY ){
  17466. return;
  17467. }
  17468. if( sd->inventory_data[idx] == nullptr ){
  17469. return;
  17470. }
  17471. // Check if it is the same item
  17472. if( sd->inventory_data[idx]->nameid != sd->inventory_data[idx_main]->nameid ){
  17473. return;
  17474. }
  17475. if( !clif_merge_item_check( sd->inventory_data[idx], &sd->inventory.u.items_inventory[idx] ) ){
  17476. clif_msg( sd, MERGE_ITEM_NOT_AVAILABLE );
  17477. return;
  17478. }
  17479. indices.insert( idx );
  17480. }
  17481. if( indices.empty() ){
  17482. clif_msg( sd, MERGE_ITEM_NOT_AVAILABLE );
  17483. return;
  17484. }
  17485. uint32 total_amount = sd->inventory.u.items_inventory[idx_main].amount;
  17486. for( uint16 idx : indices ){
  17487. total_amount += sd->inventory.u.items_inventory[idx].amount;
  17488. }
  17489. uint16 stack = sd->inventory_data[idx_main]->stack.amount;
  17490. if( stack == 0 ){
  17491. stack = MAX_AMOUNT;
  17492. }
  17493. if( total_amount >= stack ){
  17494. clif_merge_item_ack( *sd, MERGE_ITEM_FAILED_MAX_COUNT );
  17495. return;
  17496. }
  17497. // Merrrrge!!!!
  17498. for( uint16 idx : indices ){
  17499. uint16 amount = sd->inventory.u.items_inventory[idx].amount;
  17500. log_pick_pc( sd, LOG_TYPE_MERGE_ITEM, -amount, &sd->inventory.u.items_inventory[idx] );
  17501. memset( &sd->inventory.u.items_inventory[idx], 0, sizeof( sd->inventory.u.items_inventory[0] ) );
  17502. sd->inventory_data[idx] = nullptr;
  17503. clif_delitem( sd, idx, amount, 0 );
  17504. }
  17505. sd->inventory.u.items_inventory[idx_main].amount = total_amount;
  17506. clif_merge_item_ack( *sd, MERGE_ITEM_SUCCESS, idx_main, total_amount );
  17507. }
  17508. /**
  17509. * Cancel item merge
  17510. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17511. * @param fd
  17512. * @param sd
  17513. **/
  17514. void clif_parse_merge_item_cancel(int fd, map_session_data* sd) {
  17515. return; // Nothing todo yet
  17516. }
  17517. static std::string clif_hide_name(const char* original_name)
  17518. {
  17519. std::string censored(original_name);
  17520. int hide = min(battle_config.broadcast_hide_name, censored.length() - 1);
  17521. censored.replace(censored.length() - hide, hide, hide, '*');
  17522. return censored;
  17523. }
  17524. /**
  17525. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17526. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17527. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17528. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17529. **/
  17530. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17531. char name[NAME_LENGTH];
  17532. if( battle_config.broadcast_hide_name ){
  17533. std::string dispname = clif_hide_name(char_name);
  17534. safestrncpy(name, dispname.c_str(), sizeof(name));
  17535. }else{
  17536. safestrncpy( name, char_name, sizeof( name ) );
  17537. }
  17538. switch( type ){
  17539. case ITEMOBTAIN_TYPE_BOXITEM:
  17540. #if PACKETVER >= 20091201
  17541. {
  17542. struct PACKET_ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN_item p = {};
  17543. p.PacketType = package_item_announceType;
  17544. p.PacketLength = sizeof( p );
  17545. p.type = type;
  17546. p.ItemID = client_nameid( nameid );
  17547. p.len = NAME_LENGTH;
  17548. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17549. p.boxItemID_len = (int8)sizeof( p.BoxItemID );
  17550. p.BoxItemID = client_nameid( container );
  17551. #if PACKETVER_MAIN_NUM >= 20220518 || PACKETVER_ZERO_NUM >= 20220518
  17552. p.refineLevel_len = (int8)sizeof( p.refineLevel );
  17553. p.refineLevel = 0; // TODO: implement
  17554. #endif
  17555. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17556. }
  17557. #endif
  17558. break;
  17559. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17560. case ITEMOBTAIN_TYPE_NPC:
  17561. {
  17562. struct packet_item_drop_announce p;
  17563. p.PacketType = item_drop_announceType;
  17564. p.type = type;
  17565. p.ItemID = client_nameid( nameid );
  17566. p.len = NAME_LENGTH;
  17567. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17568. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17569. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17570. p.monsterNameLen = NAME_LENGTH;
  17571. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17572. }else{
  17573. p.monsterNameLen = 0;
  17574. p.monsterName[0] = '\0';
  17575. }
  17576. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17577. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17578. #else
  17579. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17580. #endif
  17581. clif_send( &p, p.PacketLength, NULL, ALL_CLIENT );
  17582. }
  17583. break;
  17584. }
  17585. }
  17586. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17587. /// 0A02 <view>.W
  17588. /// Value <flag> has the following effects:
  17589. /// 1: Open a Dress Room window.
  17590. void clif_dressing_room(map_session_data *sd, int flag) {
  17591. #if PACKETVER >= 20150513
  17592. int fd = sd->fd;
  17593. nullpo_retv(sd);
  17594. WFIFOHEAD(fd, packet_len(0xa02));
  17595. WFIFOW(fd,0) = 0xa02;
  17596. WFIFOW(fd,2) = flag;
  17597. WFIFOSET(fd, packet_len(0xa02));
  17598. #endif
  17599. }
  17600. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17601. /// 0A35 <result>.W
  17602. void clif_parse_Oneclick_Itemidentify(int fd, map_session_data *sd) {
  17603. #if PACKETVER >= 20150513
  17604. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17605. // Ignore the request
  17606. // - Invalid item index
  17607. // - Invalid item ID or item doesn't exist
  17608. // - Item is already identified
  17609. if (idx < 0 || idx >= MAX_INVENTORY ||
  17610. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == NULL ||
  17611. sd->inventory.u.items_inventory[idx].identify)
  17612. return;
  17613. // Ignore the request - No magnifiers in inventory
  17614. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17615. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17616. return;
  17617. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17618. return;
  17619. skill_identify(sd, idx);
  17620. #endif
  17621. }
  17622. /// Starts navigation to the given target on client side
  17623. void clif_navigateTo(map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17624. #if PACKETVER >= 20111010
  17625. int fd = sd->fd;
  17626. WFIFOHEAD(fd,27);
  17627. WFIFOW(fd,0) = 0x08e2;
  17628. // How detailed will our navigation be?
  17629. if( mob_id > 0 ){
  17630. x = 0;
  17631. y = 0;
  17632. WFIFOB(fd,2) = 3; // monster with destination field
  17633. }else if( x > 0 && y > 0 ){
  17634. WFIFOB(fd,2) = 0; // with coordinates
  17635. }else{
  17636. x = 0;
  17637. y = 0;
  17638. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17639. }
  17640. // Which services can be used for transportation?
  17641. WFIFOB(fd,3) = flag;
  17642. // If this flag is set, the navigation window will not be opened up
  17643. WFIFOB(fd,4) = hideWindow;
  17644. // Target map
  17645. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17646. // Target x
  17647. WFIFOW(fd,21) = x;
  17648. // Target y
  17649. WFIFOW(fd,23) = y;
  17650. // Target monster ID
  17651. WFIFOW(fd,25) = mob_id;
  17652. WFIFOSET(fd,27);
  17653. #endif
  17654. }
  17655. /// Send hat effects to the client (ZC_HAT_EFFECT).
  17656. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  17657. void clif_hat_effects( map_session_data* sd, struct block_list* bl, enum send_target target ){
  17658. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17659. map_session_data *tsd;
  17660. struct block_list* tbl;
  17661. if( target == SELF ){
  17662. tsd = BL_CAST(BL_PC,bl);
  17663. tbl = &sd->bl;
  17664. }else{
  17665. tsd = sd;
  17666. tbl = bl;
  17667. }
  17668. nullpo_retv( tsd );
  17669. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->getMapFlag(MF_NOCOSTUME) ){
  17670. return;
  17671. }
  17672. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17673. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17674. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) * tsd->hatEffects.size() );
  17675. p->aid = tsd->bl.id;
  17676. p->status = 1;
  17677. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17678. p->effects[i] = tsd->hatEffects[i];
  17679. }
  17680. clif_send( p, p->packetLength, tbl, target );
  17681. #endif
  17682. }
  17683. void clif_hat_effect_single( map_session_data* sd, uint16 effectId, bool enable ){
  17684. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17685. nullpo_retv( sd );
  17686. struct PACKET_ZC_EQUIPMENT_EFFECT* p = (struct PACKET_ZC_EQUIPMENT_EFFECT*)packet_buffer;
  17687. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17688. p->packetLength = (int16)( sizeof( struct PACKET_ZC_EQUIPMENT_EFFECT ) + sizeof( int16 ) );
  17689. p->aid = sd->bl.id;
  17690. p->status = enable;
  17691. p->effects[0] = effectId;
  17692. clif_send( p, p->packetLength, &sd->bl, AREA );
  17693. #endif
  17694. }
  17695. /// Notify the client that a sale has started
  17696. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17697. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17698. #if PACKETVER_SUPPORTS_SALES
  17699. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17700. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17701. p.itemId = client_nameid( sale_item->nameid );
  17702. p.remainingTime = (uint32)(sale_item->end - time(NULL)); // time in S
  17703. clif_send( &p, sizeof( p ), bl, target );
  17704. #endif
  17705. }
  17706. /// Notify the client that a sale has ended
  17707. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17708. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17709. #if PACKETVER_SUPPORTS_SALES
  17710. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17711. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17712. p.itemId = client_nameid( sale_item->nameid );
  17713. clif_send( &p, sizeof( p ), bl, target );
  17714. #endif
  17715. }
  17716. /// Update the remaining amount of a sale item.
  17717. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17718. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17719. #if PACKETVER_SUPPORTS_SALES
  17720. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17721. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17722. p.itemId = client_nameid( sale_item->nameid );
  17723. p.amount = sale_item->amount;
  17724. clif_send( &p, sizeof( p ), bl, target );
  17725. #endif
  17726. }
  17727. /// The client requested a refresh of the current remaining count of a sale item
  17728. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17729. void clif_parse_sale_refresh( int fd, map_session_data* sd ){
  17730. #if PACKETVER_SUPPORTS_SALES
  17731. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17732. struct sale_item_data* sale;
  17733. if( p->AID != sd->status.account_id ){
  17734. return;
  17735. }
  17736. sale = sale_find_item( p->itemId, true );
  17737. if( sale == NULL ){
  17738. return;
  17739. }
  17740. clif_sale_amount(sale, &sd->bl, SELF);
  17741. #endif
  17742. }
  17743. /// Opens the sale administration window on the client
  17744. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17745. void clif_sale_open( map_session_data* sd ){
  17746. #if PACKETVER_SUPPORTS_SALES
  17747. nullpo_retv(sd);
  17748. if( sd->state.sale_open ){
  17749. return;
  17750. }
  17751. sd->state.sale_open = true;
  17752. int fd = sd->fd;
  17753. WFIFOHEAD(fd, 2);
  17754. WFIFOW(fd, 0) = 0x9b5;
  17755. WFIFOSET(fd, 2);
  17756. #endif
  17757. }
  17758. /// Client request to open the sale administration window.
  17759. /// This is sent by /limitedsale
  17760. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17761. void clif_parse_sale_open( int fd, map_session_data* sd ){
  17762. #if PACKETVER_SUPPORTS_SALES
  17763. nullpo_retv(sd);
  17764. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17765. return;
  17766. }
  17767. char command[CHAT_SIZE_MAX];
  17768. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17769. is_atcommand(fd, sd, command, 1);
  17770. #endif
  17771. }
  17772. /// Closes the sale administration window on the client.
  17773. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17774. void clif_sale_close(map_session_data* sd) {
  17775. #if PACKETVER_SUPPORTS_SALES
  17776. nullpo_retv(sd);
  17777. if( !sd->state.sale_open ){
  17778. return;
  17779. }
  17780. sd->state.sale_open = false;
  17781. int fd = sd->fd;
  17782. WFIFOHEAD(fd, 2);
  17783. WFIFOW(fd, 0) = 0x9bd;
  17784. WFIFOSET(fd, 2);
  17785. #endif
  17786. }
  17787. /// Client request to close the sale administration window.
  17788. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17789. void clif_parse_sale_close(int fd, map_session_data* sd) {
  17790. #if PACKETVER_SUPPORTS_SALES
  17791. nullpo_retv(sd);
  17792. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17793. return;
  17794. }
  17795. clif_sale_close(sd);
  17796. #endif
  17797. }
  17798. /// Reply to a item search request for item sale administration.
  17799. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17800. void clif_sale_search_reply( map_session_data* sd, std::shared_ptr<s_cash_item> item ){
  17801. #if PACKETVER_SUPPORTS_SALES
  17802. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17803. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17804. if( item != NULL ){
  17805. p.result = 0;
  17806. p.itemId = client_nameid( item->nameid );
  17807. p.price = item->price;
  17808. }else{
  17809. p.result = 1;
  17810. p.itemId = 0;
  17811. p.price = 0;
  17812. }
  17813. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17814. #endif
  17815. }
  17816. /// Search request for an item sale administration.
  17817. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17818. void clif_parse_sale_search( int fd, map_session_data* sd ){
  17819. #if PACKETVER_SUPPORTS_SALES
  17820. char item_name[ITEM_NAME_LENGTH];
  17821. nullpo_retv(sd);
  17822. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17823. return;
  17824. }
  17825. if( !sd->state.sale_open ){
  17826. return;
  17827. }
  17828. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17829. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17830. // not found
  17831. if( id == nullptr ){
  17832. clif_sale_search_reply( sd, nullptr );
  17833. return;
  17834. }
  17835. clif_sale_search_reply( sd, cash_shop_db.findItemInTab( CASHSHOP_TAB_SALE, id->nameid ) );
  17836. #endif
  17837. }
  17838. /// Reply if an item was successfully put on sale or not.
  17839. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17840. void clif_sale_add_reply( map_session_data* sd, enum e_sale_add_result result ){
  17841. #if PACKETVER_SUPPORTS_SALES
  17842. int fd = sd->fd;
  17843. WFIFOHEAD(fd, 4);
  17844. WFIFOW(fd, 0) = 0x9af;
  17845. WFIFOW(fd, 2) = (uint16)result;
  17846. WFIFOSET(fd, 4);
  17847. #endif
  17848. }
  17849. /// A client request to put an item on sale.
  17850. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17851. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17852. void clif_parse_sale_add( int fd, map_session_data* sd ){
  17853. #if PACKETVER_SUPPORTS_SALES
  17854. nullpo_retv( sd );
  17855. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17856. if( p->AID != sd->status.account_id ){
  17857. return;
  17858. }
  17859. if( !sd->state.sale_open ){
  17860. return;
  17861. }
  17862. time_t endTime = p->startTime + p->hours * 60 * 60;
  17863. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17864. #endif
  17865. }
  17866. /// Reply to an item removal from sale.
  17867. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17868. void clif_sale_remove_reply( map_session_data* sd, bool failed ){
  17869. #if PACKETVER_SUPPORTS_SALES
  17870. int fd = sd->fd;
  17871. WFIFOHEAD(fd, 4);
  17872. WFIFOW(fd, 0) = 0x9b1;
  17873. WFIFOW(fd, 2) = failed;
  17874. WFIFOSET(fd, 4);
  17875. #endif
  17876. }
  17877. /// Request to remove an item from sale.
  17878. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17879. void clif_parse_sale_remove( int fd, map_session_data* sd ){
  17880. #if PACKETVER_SUPPORTS_SALES
  17881. nullpo_retv( sd );
  17882. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17883. if( p->AID != sd->status.account_id ){
  17884. return;
  17885. }
  17886. if( !sd->state.sale_open ){
  17887. return;
  17888. }
  17889. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17890. #endif
  17891. }
  17892. /// Achievement System
  17893. /// Author: Luxuri, Aleos
  17894. /**
  17895. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17896. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17897. */
  17898. void clif_achievement_list_all(map_session_data *sd)
  17899. {
  17900. nullpo_retv(sd);
  17901. if (!battle_config.feature_achievement) {
  17902. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17903. return;
  17904. }
  17905. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17906. if (count == 0)
  17907. return;
  17908. int len = (50 * count) + 22;
  17909. int fd = sd->fd;
  17910. int *info = achievement_level(sd, true);
  17911. WFIFOHEAD(fd,len);
  17912. WFIFOW(fd, 0) = 0xa23;
  17913. WFIFOW(fd, 2) = len;
  17914. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17915. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17916. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17917. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17918. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17919. for (int i = 0; i < count; i++) {
  17920. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17921. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17922. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17923. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17924. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17925. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17926. }
  17927. WFIFOSET(fd, len);
  17928. }
  17929. /**
  17930. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17931. * 0a24 <ACHPoint>.L
  17932. */
  17933. void clif_achievement_update(map_session_data *sd, struct achievement *ach, int count)
  17934. {
  17935. nullpo_retv(sd);
  17936. if (!battle_config.feature_achievement) {
  17937. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17938. return;
  17939. }
  17940. int fd = sd->fd;
  17941. int *info = achievement_level(sd, true);
  17942. WFIFOHEAD(fd, packet_len(0xa24));
  17943. WFIFOW(fd, 0) = 0xa24;
  17944. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17945. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17946. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17947. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17948. if (ach) {
  17949. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17950. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17951. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17952. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17953. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17954. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17955. } else
  17956. memset(WFIFOP(fd, 16), 0, 40);
  17957. WFIFOSET(fd, packet_len(0xa24));
  17958. }
  17959. /**
  17960. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17961. * 0a25 <achievementID>.L
  17962. */
  17963. void clif_parse_AchievementCheckReward(int fd, map_session_data *sd)
  17964. {
  17965. nullpo_retv(sd);
  17966. if( sd->achievement_data.save )
  17967. intif_achievement_save(sd);
  17968. achievement_check_reward(sd, RFIFOL(fd,2));
  17969. }
  17970. /**
  17971. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17972. * 0a26 <result>.W <achievementID>.L
  17973. */
  17974. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17975. {
  17976. WFIFOHEAD(fd, packet_len(0xa26));
  17977. WFIFOW(fd, 0) = 0xa26;
  17978. WFIFOB(fd, 2) = result;
  17979. WFIFOL(fd, 3) = achievement_id;
  17980. WFIFOSET(fd, packet_len(0xa26));
  17981. }
  17982. /// Process the pet evolution request
  17983. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17984. void clif_parse_pet_evolution( int fd, map_session_data *sd ){
  17985. #if PACKETVER >= 20141008
  17986. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17987. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17988. if (!pet) {
  17989. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17990. return;
  17991. }
  17992. pet_evolution(sd, pet->class_);
  17993. #endif
  17994. }
  17995. /// Sends the result of the evolution to the client.
  17996. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17997. void clif_pet_evolution_result( map_session_data* sd, e_pet_evolution_result result ){
  17998. #if PACKETVER >= 20141008
  17999. int fd = sd->fd;
  18000. WFIFOHEAD(fd, packet_len(0x9fc));
  18001. WFIFOW(fd, 0) = 0x9fc;
  18002. WFIFOL(fd, 2) = static_cast<uint32>(result);
  18003. WFIFOSET(fd, packet_len(0x9fc));
  18004. #endif
  18005. }
  18006. /*
  18007. * This packet is sent by /changedress or /nocosplay
  18008. *
  18009. * 0ae8
  18010. */
  18011. void clif_parse_changedress( int fd, map_session_data* sd ){
  18012. #if PACKETVER >= 20180103
  18013. char command[CHAT_SIZE_MAX];
  18014. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  18015. is_atcommand( fd, sd, command, 1 );
  18016. #endif
  18017. }
  18018. /// Opens an UI window of the given type and initializes it with the given data
  18019. /// 0AE2 <type>.B <data>.L
  18020. void clif_ui_open( map_session_data& sd, enum out_ui_type ui_type, int32 data ){
  18021. #if PACKETVER >= 20151202
  18022. // If the UI requires state tracking
  18023. switch( ui_type ){
  18024. case OUT_UI_STYLIST:
  18025. sd.state.stylist_open = true;
  18026. break;
  18027. case OUT_UI_ENCHANTGRADE:
  18028. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  18029. sd.state.enchantgrade_open = true;
  18030. break;
  18031. #else
  18032. return;
  18033. #endif
  18034. }
  18035. struct PACKET_ZC_UI_OPEN p = {};
  18036. p.PacketType = HEADER_ZC_UI_OPEN;
  18037. p.UIType = ui_type;
  18038. #if PACKETVER >= 20171122
  18039. p.data = data;
  18040. #endif
  18041. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  18042. #endif
  18043. }
  18044. /// Request to open an UI window of the given type
  18045. /// 0A68 <type>.B
  18046. void clif_parse_open_ui( int fd, map_session_data* sd ){
  18047. switch( RFIFOB(fd,2) ){
  18048. case IN_UI_ATTENDANCE:
  18049. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  18050. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  18051. }else if( pc_attendance_enabled() ){
  18052. clif_ui_open( *sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  18053. }else{
  18054. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  18055. }
  18056. break;
  18057. #if PACKETVER >= 20160316
  18058. case IN_UI_MACRO_REGISTER:
  18059. clif_ui_open(*sd, OUT_UI_CAPTCHA, 0);
  18060. break;
  18061. case IN_UI_MACRO_DETECTOR:
  18062. clif_ui_open(*sd, OUT_UI_MACRO, 0);
  18063. break;
  18064. #endif
  18065. }
  18066. }
  18067. /// Response for attedance request
  18068. /// 0AF0 <unknown>.L <data>.L
  18069. void clif_attendence_response( map_session_data *sd, int32 data ){
  18070. nullpo_retv(sd);
  18071. int fd = sd->fd;
  18072. WFIFOHEAD(fd,packet_len(0xAF0));
  18073. WFIFOW(fd,0) = 0xAF0;
  18074. WFIFOL(fd,2) = 0;
  18075. WFIFOL(fd,6) = data;
  18076. WFIFOSET(fd,packet_len(0xAF0));
  18077. }
  18078. /// Request from the client to retrieve today's attendance reward
  18079. /// 0AEF
  18080. void clif_parse_attendance_request( int fd, map_session_data* sd ){
  18081. pc_attendance_claim_reward(sd);
  18082. }
  18083. /// Send out the percentage of weight that causes it to be displayed in red.
  18084. /// 0ADE <percentage>.L
  18085. void clif_weight_limit( map_session_data* sd ){
  18086. #if PACKETVER >= 20171025
  18087. nullpo_retv(sd);
  18088. int fd = sd->fd;
  18089. WFIFOHEAD(fd, packet_len(0xADE));
  18090. WFIFOW(fd, 0) = 0xADE;
  18091. #ifdef RENEWAL
  18092. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  18093. #else
  18094. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  18095. #endif
  18096. WFIFOSET(fd, packet_len(0xADE));
  18097. #endif
  18098. }
  18099. enum e_private_airship_response : uint32{
  18100. PRIVATEAIRSHIP_OK,
  18101. PRIVATEAIRSHIP_RETRY,
  18102. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  18103. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  18104. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  18105. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  18106. };
  18107. /// Send out the response to a private airship request
  18108. /// 0A4A <response>.L
  18109. void clif_private_airship_response( map_session_data* sd, enum e_private_airship_response response ){
  18110. #if PACKETVER >= 20180321
  18111. nullpo_retv( sd );
  18112. int fd = sd->fd;
  18113. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  18114. WFIFOW( fd, 0 ) = 0xA4A;
  18115. WFIFOL( fd, 2 ) = response;
  18116. WFIFOSET( fd, packet_len( 0xA4A ) );
  18117. #endif
  18118. }
  18119. /// Parses a request for a private airship
  18120. /// 0A49 <mapname>.16B <itemid>.W
  18121. void clif_parse_private_airship_request( int fd, map_session_data* sd ){
  18122. #if PACKETVER >= 20180321
  18123. // Check if the feature is enabled
  18124. if( !battle_config.feature_privateairship ){
  18125. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  18126. return;
  18127. }
  18128. // Check if the player is allowed to warp from the source map
  18129. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  18130. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  18131. return;
  18132. }
  18133. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  18134. char mapname[MAP_NAME_LENGTH_EXT];
  18135. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  18136. int16 mapindex = mapindex_name2id( mapname );
  18137. // Check if we know the mapname
  18138. if( mapindex < 0 ){
  18139. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18140. return;
  18141. }
  18142. int16 mapid = map_mapindex2mapid( mapindex );
  18143. // Check if the map is available on this server
  18144. if( mapid < 0 ){
  18145. // TODO: add multi map-server support, cant validate the mapflags of the other server
  18146. return;
  18147. }
  18148. // Check if the player tried to warp to the map he is on
  18149. if( sd->bl.m == mapid ){
  18150. // This is blocked by the client, but just to be sure
  18151. return;
  18152. }
  18153. // This can only be a hack, so we prevent it
  18154. if( map_getmapdata( mapid )->instance_id ){
  18155. // Ignore requests to warp directly into a running instance
  18156. return;
  18157. }
  18158. // Check if the player is allowed to warp to the target map
  18159. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  18160. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18161. return;
  18162. }
  18163. t_itemid item_id = p->ItemID;
  18164. // Check if the item sent by the client is known to us
  18165. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  18166. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  18167. return;
  18168. }
  18169. int idx = pc_search_inventory( sd, item_id );
  18170. // Check if the player has the item at all
  18171. if( idx < 0 ){
  18172. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  18173. return;
  18174. }
  18175. // Delete the chosen item
  18176. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  18177. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  18178. return;
  18179. }
  18180. // Warp the player to a random spot on the destination map
  18181. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  18182. #endif
  18183. }
  18184. /// Sends out the usage history of the guild storage
  18185. /// 09DA <size>.W <result>.W <count>.W { <id>.L <item id>.W <amount>.L <action>.B <refine>.L <unique id>.Q <identify>.B <item type>.W
  18186. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  18187. void clif_guild_storage_log( map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  18188. #if PACKETVER >= 20140205
  18189. nullpo_retv( sd );
  18190. int fd = sd->fd;
  18191. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  18192. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18193. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  18194. }else{
  18195. log.clear();
  18196. }
  18197. WFIFOHEAD( fd, size );
  18198. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  18199. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  18200. p->PacketLength = size;
  18201. p->result = result;
  18202. p->amount = (uint16)log.size();
  18203. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18204. for( int i = 0; i < log.size(); i++ ){
  18205. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  18206. struct guild_log_entry& entry = log[i];
  18207. item->id = entry.id;
  18208. item->itemId = client_nameid( entry.item.nameid );
  18209. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  18210. item->action = entry.amount > 0; // action = true(put), false(get)
  18211. item->refine = entry.item.refine;
  18212. item->uniqueId = entry.item.unique_id;
  18213. item->IsIdentified = entry.item.identify;
  18214. item->itemType = itemtype( entry.item.nameid );
  18215. clif_addcards( &item->slot, &entry.item );
  18216. safestrncpy( item->name, entry.name, NAME_LENGTH );
  18217. safestrncpy( item->time, entry.time, NAME_LENGTH );
  18218. item->attribute = entry.item.attribute;
  18219. }
  18220. }
  18221. WFIFOSET( fd, p->PacketLength );
  18222. #endif
  18223. }
  18224. /// Activates the client camera info or updates the client camera with the given values.
  18225. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18226. void clif_camerainfo( map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18227. #if PACKETVER >= 20160525
  18228. int fd = sd->fd;
  18229. WFIFOHEAD(fd, packet_len(0xa78));
  18230. WFIFOW(fd, 0) = 0xa78;
  18231. WFIFOB(fd, 2) = show;
  18232. WFIFOF(fd, 3) = range;
  18233. WFIFOF(fd, 7) = rotation;
  18234. WFIFOF(fd, 11) = latitude;
  18235. WFIFOSET(fd, packet_len(0xa78));
  18236. #endif
  18237. }
  18238. /// Activates or deactives the client camera info or updates the camera settings.
  18239. /// This packet is triggered by /viewpointvalue or /setcamera
  18240. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18241. void clif_parse_camerainfo( int fd, map_session_data* sd ){
  18242. char command[CHAT_SIZE_MAX];
  18243. // /viewpointvalue
  18244. if( RFIFOB( fd, 2 ) == 1 ){
  18245. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18246. // /setcamera
  18247. }else{
  18248. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18249. }
  18250. is_atcommand( fd, sd, command, 1 );
  18251. }
  18252. /// Send the full list of items in the equip switch window
  18253. /// 0a9b <length>.W { <index>.W <position>.L }*
  18254. void clif_equipswitch_list( map_session_data* sd ){
  18255. #if PACKETVER >= 20170208
  18256. int fd = sd->fd;
  18257. int offset, i, position;
  18258. WFIFOW(fd, 0) = 0xa9b;
  18259. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18260. short index = sd->equip_switch_index[i];
  18261. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18262. WFIFOW(fd, offset) = index + 2;
  18263. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18264. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18265. offset += 6;
  18266. }
  18267. }
  18268. WFIFOW(fd, 2) = offset;
  18269. WFIFOSET(fd, offset);
  18270. #endif
  18271. }
  18272. /// Acknowledgement for removing an equip to the equip switch window
  18273. /// 0a9a <index>.W <position.>.L <failure>.W
  18274. void clif_equipswitch_remove( map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18275. #if PACKETVER >= 20170208
  18276. int fd = sd->fd;
  18277. WFIFOHEAD(fd, packet_len(0xa9a));
  18278. WFIFOW(fd, 0) = 0xa9a;
  18279. WFIFOW(fd, 2) = index + 2;
  18280. WFIFOL(fd, 4) = pos;
  18281. WFIFOW(fd, 8) = failed;
  18282. WFIFOSET(fd, packet_len(0xa9a));
  18283. #endif
  18284. }
  18285. /// Request to remove an equip from the equip switch window
  18286. /// 0a99 <index>.W <position>.L <= 20170502
  18287. /// 0a99 <index>.W
  18288. void clif_parse_equipswitch_remove( int fd, map_session_data* sd ){
  18289. #if PACKETVER >= 20170208
  18290. uint16 index = RFIFOW(fd, 2) - 2;
  18291. bool removed = false;
  18292. if( !battle_config.feature_equipswitch ){
  18293. return;
  18294. }
  18295. // Check if the index is valid
  18296. if( index >= MAX_INVENTORY ){
  18297. return;
  18298. }
  18299. pc_equipswitch_remove( sd, index );
  18300. #endif
  18301. }
  18302. /// Acknowledgement for adding an equip to the equip switch window
  18303. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18304. /// 0a98 <index>.W <position.>.L <flag>.W
  18305. void clif_equipswitch_add( map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18306. #if PACKETVER >= 20170208
  18307. int fd = sd->fd;
  18308. WFIFOHEAD(fd, packet_len(0xa98));
  18309. WFIFOW(fd, 0) = 0xa98;
  18310. WFIFOW(fd, 2) = index + 2;
  18311. WFIFOL(fd, 4) = pos;
  18312. #if PACKETVER <= 20170502
  18313. WFIFOL(fd, 8) = flag;
  18314. #else
  18315. WFIFOW(fd, 8) = flag;
  18316. #endif
  18317. WFIFOSET(fd,packet_len(0xa98));
  18318. #endif
  18319. }
  18320. /// Request to add an equip to the equip switch window
  18321. /// 0a97 <index>.W <position>.L
  18322. void clif_parse_equipswitch_add( int fd, map_session_data* sd ){
  18323. #if PACKETVER >= 20170208
  18324. uint16 index = RFIFOW(fd, 2) - 2;
  18325. uint32 position = RFIFOL(fd, 4);
  18326. if( !battle_config.feature_equipswitch ){
  18327. return;
  18328. }
  18329. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18330. return;
  18331. }
  18332. if( sd->state.trading || sd->npc_shopid ){
  18333. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18334. return;
  18335. }
  18336. if( sd->inventory_data[index]->type == IT_AMMO ){
  18337. position = EQP_AMMO;
  18338. }
  18339. pc_equipitem( sd, index, position, true );
  18340. #endif
  18341. }
  18342. /// Acknowledgement packet for the full equip switch
  18343. /// 0a9d <failed>.W
  18344. void clif_equipswitch_reply( map_session_data* sd, bool failed ){
  18345. #if PACKETVER >= 20170208
  18346. int fd = sd->fd;
  18347. WFIFOHEAD(fd, packet_len(0xa9d));
  18348. WFIFOW(fd, 0) = 0xa9d;
  18349. WFIFOW(fd, 2) = failed;
  18350. WFIFOSET(fd, packet_len(0xa9d));
  18351. #endif
  18352. }
  18353. /// Request to do a full equip switch
  18354. /// 0a9c
  18355. void clif_parse_equipswitch_request( int fd, map_session_data* sd ){
  18356. #if PACKETVER >= 20170208
  18357. int i;
  18358. t_tick tick = gettick();
  18359. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18360. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18361. // Client will not let you send a request
  18362. return;
  18363. }
  18364. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18365. if( !battle_config.feature_equipswitch ){
  18366. return;
  18367. }
  18368. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18369. if( i == EQI_MAX ){
  18370. // client will show: "There is no item to replace." and should not even come here
  18371. clif_equipswitch_reply( sd, false );
  18372. return;
  18373. }
  18374. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18375. return;
  18376. }
  18377. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18378. #endif
  18379. }
  18380. /// Request to do a single equip switch
  18381. /// 0ace <index>.W
  18382. void clif_parse_equipswitch_request_single( int fd, map_session_data* sd ){
  18383. #if PACKETVER >= 20170502
  18384. uint16 index = RFIFOW(fd, 2) - 2;
  18385. if( !battle_config.feature_equipswitch ){
  18386. return;
  18387. }
  18388. // Check if the index is valid
  18389. if( index >= MAX_INVENTORY ){
  18390. return;
  18391. }
  18392. // Check if the item exists
  18393. if (sd->inventory_data[index] == nullptr)
  18394. return;
  18395. // Check if the item was already added to equip switch
  18396. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18397. if( sd->npc_id ){
  18398. #ifdef RENEWAL
  18399. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18400. clif_msg( sd, WORK_IN_PROGRESS );
  18401. return;
  18402. }
  18403. #endif
  18404. if( !sd->npc_item_flag ){
  18405. return;
  18406. }
  18407. }
  18408. pc_equipswitch( sd, index );
  18409. return;
  18410. }
  18411. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18412. #endif
  18413. }
  18414. void clif_parse_StartUseSkillToId( int fd, map_session_data* sd ){
  18415. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18416. const struct PACKET_CZ_USE_SKILL_START* p = (struct PACKET_CZ_USE_SKILL_START*)RFIFOP( fd, 0 );
  18417. // Only rolling cutter is supported for now
  18418. if( p->skillId != GC_ROLLINGCUTTER ){
  18419. return;
  18420. }
  18421. // Already running - cant happen on officials, since only one skill is supported
  18422. if( sd->skill_keep_using.skill_id != 0 ){
  18423. return;
  18424. }
  18425. sd->skill_keep_using.tid = INVALID_TIMER;
  18426. sd->skill_keep_using.skill_id = p->skillId;
  18427. sd->skill_keep_using.level = p->skillLv;
  18428. sd->skill_keep_using.target = p->targetId;
  18429. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18430. #endif
  18431. }
  18432. void clif_parse_StopUseSkillToId( int fd, map_session_data* sd ){
  18433. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18434. const struct PACKET_CZ_USE_SKILL_END* p = (struct PACKET_CZ_USE_SKILL_END*)RFIFOP( fd, 0 );
  18435. // Not running
  18436. if( sd->skill_keep_using.skill_id == 0 ){
  18437. return;
  18438. }
  18439. #if 0
  18440. // Hack
  18441. if( p->skillId != sd->skill_keep_using.skill_id ){
  18442. return;
  18443. }
  18444. #endif
  18445. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18446. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18447. sd->skill_keep_using.tid = INVALID_TIMER;
  18448. }
  18449. sd->skill_keep_using.skill_id = 0;
  18450. sd->skill_keep_using.level = 0;
  18451. sd->skill_keep_using.target = 0;
  18452. #endif
  18453. }
  18454. void clif_ping( map_session_data* sd ){
  18455. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18456. nullpo_retv( sd );
  18457. int fd = sd->fd;
  18458. if( !session_isActive( fd ) ){
  18459. return;
  18460. }
  18461. struct PACKET_ZC_PING_LIVE p = {};
  18462. p.packetType = HEADER_ZC_PING_LIVE;
  18463. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18464. #endif
  18465. }
  18466. int clif_ping_timer_sub( map_session_data *sd, va_list ap ){
  18467. nullpo_ret( sd );
  18468. int fd = sd->fd;
  18469. if( !session_isActive( fd ) ){
  18470. return 0;
  18471. }
  18472. t_tick tick = va_arg( ap, t_tick );
  18473. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18474. clif_ping( sd );
  18475. }
  18476. return 0;
  18477. }
  18478. TIMER_FUNC( clif_ping_timer ){
  18479. map_foreachpc( clif_ping_timer_sub, gettick() );
  18480. return 0;
  18481. }
  18482. /**
  18483. * Opens the refine UI on the designated client.
  18484. * 0aa0
  18485. */
  18486. void clif_refineui_open( map_session_data* sd ){
  18487. #if PACKETVER >= 20161012
  18488. nullpo_retv( sd );
  18489. struct PACKET_ZC_OPEN_REFINING_UI p = {};
  18490. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18491. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18492. sd->state.refineui_open = true;
  18493. #endif
  18494. }
  18495. /**
  18496. * Parses cancel/close of the refine UI on client side.
  18497. * 0aa4
  18498. */
  18499. void clif_parse_refineui_close( int fd, map_session_data* sd ){
  18500. #if PACKETVER >= 20161012
  18501. sd->state.refineui_open = false;
  18502. #endif
  18503. }
  18504. /**
  18505. * Adds the selected item into the refine UI and sends the possible materials
  18506. * to the client.
  18507. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18508. */
  18509. void clif_refineui_info( map_session_data* sd, uint16 index ){
  18510. #if PACKETVER >= 20161012
  18511. int fd = sd->fd;
  18512. // Get the item db reference
  18513. struct item_data* id = sd->inventory_data[index];
  18514. // No item data was found
  18515. if( id == NULL ){
  18516. return;
  18517. }
  18518. // Check the inventory
  18519. struct item* item = &sd->inventory.u.items_inventory[index];
  18520. // No item was found at the given index
  18521. if( item == NULL ){
  18522. return;
  18523. }
  18524. // Check if the item is identified
  18525. if( !item->identify ){
  18526. return;
  18527. }
  18528. // Check if the item is broken
  18529. if( item->attribute ){
  18530. return;
  18531. }
  18532. struct PACKET_ZC_REFINING_MATERIAL_LIST* p = (struct PACKET_ZC_REFINING_MATERIAL_LIST*)packet_buffer;
  18533. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18534. p->packetLength = sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18535. p->itemIndex = client_index( index );
  18536. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18537. // No possibilities were found
  18538. if( info == nullptr ){
  18539. p->blacksmithBlessing = 0;
  18540. }else{
  18541. p->blacksmithBlessing = (uint8)info->blessing_amount;
  18542. uint16 count = 0;
  18543. for( uint16 i = REFINE_COST_NORMAL; i < REFINE_COST_MAX; i++ ){
  18544. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18545. if( cost != nullptr ){
  18546. p->req[count].itemId = client_nameid( cost->nameid );
  18547. p->req[count].chance = (uint8)( cost->chance / 100 );
  18548. p->req[count].zeny = cost->zeny;
  18549. p->packetLength += sizeof( struct PACKET_ZC_REFINING_MATERIAL_LIST_SUB );
  18550. count++;
  18551. }
  18552. }
  18553. }
  18554. clif_send( p, p->packetLength, &sd->bl, SELF );
  18555. #endif
  18556. }
  18557. /**
  18558. * Client request to add an item to the refine UI.
  18559. * 0aa1 <index>.W
  18560. */
  18561. void clif_parse_refineui_add( int fd, map_session_data* sd ){
  18562. #if PACKETVER >= 20161012
  18563. struct PACKET_CZ_REFINING_SELECT_ITEM* p = (struct PACKET_CZ_REFINING_SELECT_ITEM*)RFIFOP( fd, 0 );
  18564. uint16 index = server_index( p->index );
  18565. // Check if the refine UI is open
  18566. if( !sd->state.refineui_open ){
  18567. return;
  18568. }
  18569. // Check if the index is valid
  18570. if( index >= MAX_INVENTORY ){
  18571. return;
  18572. }
  18573. // Send out the requirements for the refine process
  18574. clif_refineui_info( sd, index );
  18575. #endif
  18576. }
  18577. /**
  18578. * Client requests to try to refine an item.
  18579. * 0aa3 <index>.W <material>.W <catalyst>.B
  18580. */
  18581. void clif_parse_refineui_refine( int fd, map_session_data* sd ){
  18582. #if PACKETVER >= 20161012
  18583. struct PACKET_CZ_REQ_REFINING* p = (struct PACKET_CZ_REQ_REFINING*)RFIFOP( fd, 0 );
  18584. uint16 index = server_index( p->index );
  18585. t_itemid material = p->itemId;
  18586. int16 j;
  18587. // Check if the refine UI is open
  18588. if( !sd->state.refineui_open ){
  18589. return;
  18590. }
  18591. // Check if the index is valid
  18592. if( index >= MAX_INVENTORY ){
  18593. return;
  18594. }
  18595. // Get the item db reference
  18596. struct item_data* id = sd->inventory_data[index];
  18597. // No item data was found
  18598. if( id == NULL ){
  18599. return;
  18600. }
  18601. // Check the inventory
  18602. struct item* item = &sd->inventory.u.items_inventory[index];
  18603. // No item was found at the given index
  18604. if( item == NULL ){
  18605. return;
  18606. }
  18607. // Check if the item is identified
  18608. if( !item->identify ){
  18609. return;
  18610. }
  18611. // Check if the item is broken
  18612. if( item->attribute ){
  18613. return;
  18614. }
  18615. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18616. // No refine possible
  18617. if( info == nullptr ){
  18618. return;
  18619. }
  18620. // No possibilities were found
  18621. if( info->costs.empty() ){
  18622. return;
  18623. }
  18624. // Check if the player has the selected material
  18625. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18626. return;
  18627. }
  18628. int16 blacksmith_index = -1;
  18629. uint16 blacksmith_amount = 0;
  18630. // Check if the player has enough blacksmith blessings
  18631. if( p->blacksmithBlessing != 0 ){
  18632. blacksmith_amount = info->blessing_amount;
  18633. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18634. if( blacksmith_amount == 0 ){
  18635. return;
  18636. }
  18637. // Check if the player has blacksmith blessings
  18638. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18639. return;
  18640. }
  18641. // Check if the player has enough blacksmith blessings
  18642. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18643. return;
  18644. }
  18645. }
  18646. std::shared_ptr<s_refine_cost> cost = nullptr;
  18647. for( const auto& pair : info->costs ){
  18648. if( pair.second->nameid == material ){
  18649. cost = pair.second;
  18650. break;
  18651. }
  18652. }
  18653. // The material was not in the list of possible materials
  18654. if( cost == nullptr ){
  18655. return;
  18656. }
  18657. // Try to pay for the refine
  18658. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME ) ){
  18659. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18660. return;
  18661. }
  18662. // Delete the required material
  18663. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18664. return;
  18665. }
  18666. // Delete the required blacksmith blessings
  18667. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18668. return;
  18669. }
  18670. // Try to refine the item
  18671. if( cost->chance >= ( rnd() % 10000 ) ){
  18672. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18673. // Success
  18674. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18675. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18676. clif_misceffect( &sd->bl, 3 );
  18677. clif_refine( fd, 0, index, item->refine );
  18678. if (info->broadcast_success) {
  18679. clif_broadcast_refine_result(*sd, item->nameid, item->refine, true);
  18680. }
  18681. if( id->type == IT_WEAPON ){
  18682. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18683. }
  18684. clif_refineui_info( sd, index );
  18685. }else{
  18686. // Failure
  18687. if (info->broadcast_failure) {
  18688. clif_broadcast_refine_result(*sd, item->nameid, item->refine, false);
  18689. }
  18690. // Blacksmith blessings were used to prevent breaking and downgrading
  18691. if( blacksmith_amount > 0 ){
  18692. clif_refine( fd, 3, index, item->refine );
  18693. clif_refineui_info( sd, index );
  18694. // Delete the item if it is breakable
  18695. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18696. clif_refine( fd, 1, index, item->refine );
  18697. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18698. // Downgrade the item if necessary
  18699. }else if( cost->downgrade_amount > 0 ){
  18700. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18701. clif_refine( fd, 2, index, item->refine );
  18702. clif_refineui_info(sd, index);
  18703. // Only show failure, but dont do anything
  18704. }else{
  18705. clif_refine( fd, 3, index, item->refine );
  18706. clif_refineui_info( sd, index );
  18707. }
  18708. clif_misceffect( &sd->bl, 2 );
  18709. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18710. }
  18711. #endif
  18712. }
  18713. void clif_unequipall_reply( map_session_data* sd, bool failed ){
  18714. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18715. struct PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18716. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18717. p.result = failed;
  18718. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18719. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18720. }
  18721. void clif_parse_unequipall( int fd, map_session_data* sd ){
  18722. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18723. if( pc_cant_act( sd ) ){
  18724. clif_unequipall_reply( sd, true );
  18725. return;
  18726. }
  18727. struct PACKET_CZ_REQ_TAKEOFF_EQUIP_ALL* p = (struct PACKET_CZ_REQ_TAKEOFF_EQUIP_ALL*)RFIFOP( fd, 0 );
  18728. #if PACKETVER_MAIN_NUM >= 20230906
  18729. uint32 location = p->location;
  18730. int max = EQI_MAX;
  18731. #else
  18732. uint32 location = 0xFFFFFFFF;
  18733. int max = EQI_COSTUME_HEAD_TOP;
  18734. #endif
  18735. for( int i = 0; i < max; i++ ){
  18736. if( sd->equip_index[i] >= 0 && ( location & equip_bitmask[i] ) != 0 ){
  18737. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18738. }
  18739. }
  18740. clif_unequipall_reply( sd, false );
  18741. #endif
  18742. }
  18743. void clif_stylist_response( map_session_data* sd, bool failed ){
  18744. #if PACKETVER >= 20151104
  18745. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18746. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18747. p.flag = failed;
  18748. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18749. if( !failed ){
  18750. sd->state.stylist_open = false;
  18751. }
  18752. #endif
  18753. }
  18754. bool clif_parse_stylist_buy_sub( map_session_data* sd, _look look, int16 index ){
  18755. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18756. if( list == nullptr ){
  18757. return false;
  18758. }
  18759. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18760. if( entry == nullptr ){
  18761. return false;
  18762. }
  18763. std::shared_ptr<s_stylist_costs> costs;
  18764. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18765. costs = entry->doram;
  18766. }else{
  18767. costs = entry->human;
  18768. }
  18769. if( costs == nullptr ){
  18770. return false;
  18771. }
  18772. if( sd->status.zeny < costs->price ){
  18773. return false;
  18774. }
  18775. int16 inventoryIndex = -1;
  18776. if( costs->requiredItem != 0 ){
  18777. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18778. if( inventoryIndex < 0 ){
  18779. // No other option
  18780. if( costs->requiredItemBox == 0 ){
  18781. return false;
  18782. }
  18783. // Check if the box that contains the item is in the inventory
  18784. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18785. // The box containing the item also does not exist
  18786. if( inventoryIndex < 0 ){
  18787. return false;
  18788. }
  18789. }
  18790. }else if( costs->requiredItemBox != 0 ){
  18791. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18792. if( inventoryIndex < 0 ){
  18793. return false;
  18794. }
  18795. }
  18796. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18797. return false;
  18798. }
  18799. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER ) != 0 ){
  18800. return false;
  18801. }
  18802. switch( look ){
  18803. case LOOK_HAIR:
  18804. case LOOK_HAIR_COLOR:
  18805. case LOOK_CLOTHES_COLOR:
  18806. case LOOK_BODY2:
  18807. pc_changelook( sd, look, entry->value );
  18808. break;
  18809. case LOOK_HEAD_BOTTOM:
  18810. case LOOK_HEAD_MID:
  18811. case LOOK_HEAD_TOP: {
  18812. struct mail_message msg = {};
  18813. msg.dest_id = sd->status.char_id;
  18814. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18815. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18816. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18817. msg.item[0].nameid = entry->value;
  18818. msg.item[0].identify = 1;
  18819. msg.item[0].amount = 1;
  18820. msg.status = MAIL_NEW;
  18821. msg.type = MAIL_INBOX_NORMAL;
  18822. msg.timestamp = time( nullptr );
  18823. intif_Mail_send( 0, &msg );
  18824. } break;
  18825. }
  18826. return true;
  18827. }
  18828. void clif_parse_stylist_buy( int fd, map_session_data* sd ){
  18829. #if PACKETVER >= 20151104
  18830. #if PACKETVER >= 20180516
  18831. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18832. #else
  18833. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18834. #endif
  18835. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18836. clif_stylist_response( sd, true );
  18837. return;
  18838. }
  18839. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18840. clif_stylist_response( sd, true );
  18841. return;
  18842. }
  18843. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18844. clif_stylist_response( sd, true );
  18845. return;
  18846. }
  18847. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18848. clif_stylist_response( sd, true );
  18849. return;
  18850. }
  18851. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18852. clif_stylist_response( sd, true );
  18853. return;
  18854. }
  18855. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18856. clif_stylist_response( sd, true );
  18857. return;
  18858. }
  18859. #if PACKETVER >= 20180516
  18860. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18861. clif_stylist_response( sd, true );
  18862. return;
  18863. }
  18864. #endif
  18865. clif_stylist_response( sd, false );
  18866. #endif
  18867. }
  18868. void clif_parse_stylist_close( int fd, map_session_data* sd ){
  18869. #if PACKETVER >= 20151104
  18870. sd->state.stylist_open = false;
  18871. #endif
  18872. }
  18873. void clif_inventory_expansion_info( map_session_data* sd ){
  18874. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18875. nullpo_retv( sd );
  18876. struct PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18877. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18878. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18879. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18880. #endif
  18881. }
  18882. enum class e_inventory_expansion_response : uint8{
  18883. ASK_CONFIRMATION = 0,
  18884. FAILED,
  18885. BUSY,
  18886. MISSING_ITEM,
  18887. MAXIMUM_REACHED
  18888. };
  18889. void clif_inventory_expansion_response( map_session_data* sd, e_inventory_expansion_response response ){
  18890. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18891. nullpo_retv( sd );
  18892. struct PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18893. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18894. p.result = (uint8)response;
  18895. p.itemId = sd->state.inventory_expansion_confirmation;
  18896. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18897. #endif
  18898. }
  18899. void clif_parse_inventory_expansion_request( int fd, map_session_data* sd ){
  18900. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18901. // Check if player is dead or busy with other stuff
  18902. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18903. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18904. return;
  18905. }
  18906. // Check if the player already reached the maximum
  18907. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18908. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18909. return;
  18910. }
  18911. static std::map<t_itemid, uint16> items = {
  18912. // The order of entries in this list defines which will be used first
  18913. // This order and the usable items are hardcoded into the client
  18914. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18915. { ITEMID_INVENTORY_EX_EVT, 10 },
  18916. { ITEMID_INVENTORY_EX_DIS, 10 },
  18917. { ITEMID_INVENTORY_EX, 10 },
  18918. };
  18919. int16 index = -1;
  18920. bool found_over_limit = false;
  18921. for( const auto& entry : items ){
  18922. // Check if the player has the required item
  18923. index = pc_search_inventory( sd, entry.first );
  18924. // Found an item
  18925. if( index >= 0 ){
  18926. // Check if the player would exceed the maximum
  18927. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18928. found_over_limit = true;
  18929. }else{
  18930. found_over_limit = false;
  18931. sd->state.inventory_expansion_confirmation = entry.first;
  18932. sd->state.inventory_expansion_amount = entry.second;
  18933. break;
  18934. }
  18935. }
  18936. }
  18937. // Check if an item was found
  18938. if( sd->state.inventory_expansion_confirmation == 0 ){
  18939. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18940. return;
  18941. }
  18942. // Check if an item would have been found, but the player would exceed the maximum
  18943. if( found_over_limit ){
  18944. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18945. return;
  18946. }
  18947. // The player met all requirements => ask him for confirmation
  18948. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18949. #endif
  18950. }
  18951. enum class e_inventory_expansion_result : uint8{
  18952. SUCCESS = 0,
  18953. FAILED,
  18954. BUSY,
  18955. MISSING_ITEM,
  18956. MAXIMUM_REACHED
  18957. };
  18958. void clif_inventory_expansion_result( map_session_data* sd, e_inventory_expansion_result result ){
  18959. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18960. nullpo_retv( sd );
  18961. struct PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18962. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18963. p.result = (uint8)result;
  18964. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18965. // Reset the state tracking
  18966. sd->state.inventory_expansion_confirmation = 0;
  18967. sd->state.inventory_expansion_amount = 0;
  18968. #endif
  18969. }
  18970. void clif_parse_inventory_expansion_confirm( int fd, map_session_data* sd ){
  18971. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18972. if( sd->state.inventory_expansion_confirmation == 0 ){
  18973. return;
  18974. }
  18975. // Check if player is dead
  18976. if( pc_isdead( sd ) ){
  18977. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18978. return;
  18979. }
  18980. // Check if the player already reached the maximum
  18981. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18982. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18983. return;
  18984. }
  18985. // Check if the player has the required item
  18986. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18987. // The player did not have the item anymore
  18988. if( index < 0 ){
  18989. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18990. return;
  18991. }
  18992. // Check if the player would exceed the maximum
  18993. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18994. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18995. return;
  18996. }
  18997. // Delete the required item
  18998. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18999. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  19000. return;
  19001. }
  19002. // Increase the slots
  19003. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  19004. // Save player data (slots) and inventory data (removed item)
  19005. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  19006. // Inform the player of success
  19007. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  19008. clif_inventory_expansion_info( sd );
  19009. #endif
  19010. }
  19011. void clif_parse_inventory_expansion_reject( int fd, map_session_data* sd ){
  19012. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  19013. sd->state.inventory_expansion_confirmation = 0;
  19014. sd->state.inventory_expansion_amount = 0;
  19015. #endif
  19016. }
  19017. void clif_barter_open( map_session_data& sd, struct npc_data& nd ){
  19018. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19019. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  19020. return;
  19021. }
  19022. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19023. if( barter == nullptr ){
  19024. return;
  19025. }
  19026. sd.state.barter_open = true;
  19027. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*)packet_buffer;
  19028. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  19029. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO );
  19030. int16 count = 0;
  19031. for( const auto& itemPair : barter->items ){
  19032. struct PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub* item = &p->list[count];
  19033. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  19034. item->nameid = client_nameid( id->nameid );
  19035. item->type = itemtype( id->nameid );
  19036. if( itemPair.second->stockLimited ){
  19037. item->amount = itemPair.second->stock;
  19038. }else{
  19039. item->amount = -1;
  19040. }
  19041. item->weight = id->weight;
  19042. item->index = itemPair.second->index;
  19043. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19044. item->viewSprite = id->look;
  19045. item->location = pc_equippoint_sub( &sd, id.get() );
  19046. #endif
  19047. // Use a loop if someone did not start with index 0
  19048. for( const auto& requirementPair : itemPair.second->requirements ){
  19049. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19050. item->currencyNameid = client_nameid( requirement->nameid );
  19051. item->currencyAmount = requirement->amount;
  19052. // It is a normal barter, cancel after first entry
  19053. break;
  19054. }
  19055. p->packetLength += (int16)( sizeof( *item ) );
  19056. count++;
  19057. }
  19058. clif_send( p, p->packetLength, &sd.bl, SELF );
  19059. #endif
  19060. }
  19061. void clif_parse_barter_close( int fd, map_session_data* sd ){
  19062. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19063. if( sd->state.barter_open ){
  19064. sd->npc_shopid = 0;
  19065. sd->state.barter_open = false;
  19066. }
  19067. #endif
  19068. }
  19069. void clif_parse_barter_buy( int fd, map_session_data* sd ){
  19070. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19071. // No shop open
  19072. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  19073. return;
  19074. }
  19075. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19076. // Unknown shop
  19077. if( nd == nullptr ){
  19078. return;
  19079. }
  19080. // Not a barter
  19081. if( nd->subtype != NPCTYPE_BARTER ){
  19082. return;
  19083. }
  19084. // It is an extended barter
  19085. if( nd->u.barter.extended ){
  19086. return;
  19087. }
  19088. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19089. if( barter == nullptr ){
  19090. return;
  19091. }
  19092. struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19093. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE_sub );
  19094. // Empty purchase list
  19095. if( entries == 0 ){
  19096. return;
  19097. }
  19098. std::vector<s_barter_purchase> purchases;
  19099. purchases.reserve( entries );
  19100. // Make sure each shop index and target item id is only used once
  19101. for( int i = 0; i < entries; i++ ){
  19102. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19103. // Invalid shop index
  19104. if( item == nullptr ){
  19105. return;
  19106. }
  19107. for( int j = i + 1; j < entries; j++ ){
  19108. // Same shop index
  19109. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19110. return;
  19111. }
  19112. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19113. // Invalid shop index
  19114. if( item2 == nullptr ){
  19115. return;
  19116. }
  19117. // Same target item id
  19118. if( item->nameid == item2->nameid ){
  19119. return;
  19120. }
  19121. }
  19122. s_barter_purchase purchase = {};
  19123. purchase.item = item;
  19124. purchase.amount = p->list[i].amount;
  19125. purchases.push_back( purchase );
  19126. }
  19127. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19128. #endif
  19129. }
  19130. void clif_barter_extended_open( map_session_data& sd, struct npc_data& nd ){
  19131. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19132. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  19133. return;
  19134. }
  19135. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19136. if( barter == nullptr ){
  19137. return;
  19138. }
  19139. sd.state.barter_extended_open = true;
  19140. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*)packet_buffer;
  19141. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  19142. p->packetLength = (int16)sizeof( struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO );
  19143. p->items_count = 0;
  19144. for( const auto& itemPair : barter->items ){
  19145. // Needs dynamic calculation, because of variable currencies
  19146. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*)( ( (uint8*)p ) + p->packetLength );
  19147. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  19148. item->nameid = client_nameid( id->nameid );
  19149. item->type = itemtype( id->nameid );
  19150. if( itemPair.second->stockLimited ){
  19151. item->amount = itemPair.second->stock;
  19152. }else{
  19153. item->amount = -1;
  19154. }
  19155. item->weight = id->weight;
  19156. item->index = itemPair.second->index;
  19157. item->zeny = itemPair.second->price;
  19158. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19159. item->viewSprite = id->look;
  19160. item->location = pc_equippoint_sub( &sd, id.get() );
  19161. #endif
  19162. p->packetLength += (int16)( sizeof( *item ) - sizeof( item->currencies ) );
  19163. p->items_count++;
  19164. item->currency_count = 0;
  19165. for( const auto& requirementPair : itemPair.second->requirements ){
  19166. // Needs dynamic calculation, because of variable currencies
  19167. struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = (struct PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*)( ( (uint8*)p ) + p->packetLength );
  19168. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19169. req->nameid = requirement->nameid;
  19170. if( requirement->refine >= 0 ){
  19171. req->refine_level = requirement->refine;
  19172. }else{
  19173. req->refine_level = 0;
  19174. }
  19175. req->amount = requirement->amount;
  19176. req->type = itemtype( requirement->nameid );
  19177. p->packetLength += (int16)( sizeof( *req ) );
  19178. item->currency_count++;
  19179. }
  19180. }
  19181. clif_send( p, p->packetLength, &sd.bl, SELF );
  19182. #endif
  19183. }
  19184. void clif_parse_barter_extended_close( int fd, map_session_data* sd ){
  19185. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19186. if( sd->state.barter_extended_open ){
  19187. sd->npc_shopid = 0;
  19188. sd->state.barter_extended_open = false;
  19189. }
  19190. #endif
  19191. }
  19192. void clif_parse_barter_extended_buy( int fd, map_session_data* sd ){
  19193. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19194. // No shop open
  19195. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  19196. return;
  19197. }
  19198. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19199. // Unknown shop
  19200. if( nd == nullptr ){
  19201. return;
  19202. }
  19203. // Not a barter
  19204. if( nd->subtype != NPCTYPE_BARTER ){
  19205. return;
  19206. }
  19207. // Not an extended barter
  19208. if( !nd->u.barter.extended ){
  19209. return;
  19210. }
  19211. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19212. if( barter == nullptr ){
  19213. return;
  19214. }
  19215. struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19216. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE_sub );
  19217. // Empty purchase list
  19218. if( entries == 0 ){
  19219. return;
  19220. }
  19221. std::vector<s_barter_purchase> purchases;
  19222. purchases.reserve( entries );
  19223. // Make sure each shop index and target item id is only used once
  19224. for( int i = 0; i < entries; i++ ){
  19225. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19226. // Invalid shop index
  19227. if( item == nullptr ){
  19228. return;
  19229. }
  19230. for( int j = i + 1; j < entries; j++ ){
  19231. // Same shop index
  19232. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19233. return;
  19234. }
  19235. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19236. // Invalid shop index
  19237. if( item2 == nullptr ){
  19238. return;
  19239. }
  19240. // Same target item id
  19241. if( item->nameid == item2->nameid ){
  19242. return;
  19243. }
  19244. }
  19245. s_barter_purchase purchase = {};
  19246. purchase.item = item;
  19247. purchase.amount = p->list[i].amount;
  19248. purchases.push_back( purchase );
  19249. }
  19250. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19251. #endif
  19252. }
  19253. void clif_summon_init(struct mob_data& md) {
  19254. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19255. struct block_list* master_bl = battle_get_master(&md.bl);
  19256. if( master_bl == nullptr ){
  19257. return;
  19258. }
  19259. struct PACKET_ZC_SUMMON_HP_INIT p = {};
  19260. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19261. p.summonAID = md.bl.id;
  19262. p.CurrentHP = md.status.hp;
  19263. p.MaxHP = md.status.max_hp;
  19264. clif_send( &p, sizeof( p ), master_bl, SELF );
  19265. #endif
  19266. }
  19267. void clif_summon_hp_bar(struct mob_data& md) {
  19268. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19269. struct block_list* master_bl = battle_get_master(&md.bl);
  19270. if( master_bl == nullptr ){
  19271. return;
  19272. }
  19273. struct PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19274. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19275. p.summonAID = md.bl.id;
  19276. p.VarId = SP_HP; // HP parameter
  19277. p.Value = md.status.hp;
  19278. clif_send( &p, sizeof( p ), master_bl, SELF );
  19279. #endif
  19280. }
  19281. void clif_laphine_synthesis_open( map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19282. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19283. nullpo_retv( sd );
  19284. sd->state.laphine_synthesis = synthesis->item_id;
  19285. struct PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19286. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19287. p.itemId = client_nameid( synthesis->item_id );
  19288. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19289. #endif
  19290. }
  19291. void clif_parse_laphine_synthesis_close( int fd, map_session_data* sd ){
  19292. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19293. sd->state.laphine_synthesis = 0;
  19294. #endif
  19295. }
  19296. enum e_laphine_synthesis_result : int16{
  19297. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19298. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19299. LAPHINE_SYNTHESIS_ITEM = 7
  19300. };
  19301. void clif_laphine_synthesis_result( map_session_data* sd, enum e_laphine_synthesis_result result ){
  19302. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19303. nullpo_retv( sd );
  19304. struct PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19305. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19306. p.result = result;
  19307. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19308. #endif
  19309. }
  19310. void clif_parse_laphine_synthesis( int fd, map_session_data* sd ){
  19311. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19312. if( sd->state.laphine_synthesis == 0 ){
  19313. return;
  19314. }
  19315. struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*)RFIFOP( fd, 0 );
  19316. if( sd->state.laphine_synthesis != p->itemId ){
  19317. return;
  19318. }
  19319. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19320. if( synthesis == nullptr ){
  19321. return;
  19322. }
  19323. size_t count = ( p->packetLength - sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19324. // Player sent more or less than actually required
  19325. if( count != synthesis->requiredRequirements ){
  19326. return;
  19327. }
  19328. // Check for duplicates
  19329. for( size_t i = 0; i < count; i++ ){
  19330. for( size_t j = i + 1; j < count; j++ ){
  19331. if( p->items[i].index == p->items[j].index ){
  19332. return;
  19333. }
  19334. }
  19335. }
  19336. for( size_t i = 0; i < count; i++ ){
  19337. int16 index = server_index( p->items[i].index );
  19338. if( index >= MAX_INVENTORY ){
  19339. return;
  19340. }
  19341. if( sd->inventory_data[index] == nullptr ){
  19342. return;
  19343. }
  19344. struct item* item = &sd->inventory.u.items_inventory[index];
  19345. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19346. if( requirement == nullptr ){
  19347. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19348. return;
  19349. }
  19350. if( p->items[i].count != requirement->amount ){
  19351. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19352. return;
  19353. }
  19354. if( item->amount < requirement->amount ){
  19355. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19356. return;
  19357. }
  19358. if( item->refine < synthesis->minimumRefine ){
  19359. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19360. return;
  19361. }
  19362. if( item->refine > synthesis->maximumRefine ){
  19363. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19364. return;
  19365. }
  19366. if( item->equip != 0 ){
  19367. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19368. return;
  19369. }
  19370. if( item->equipSwitch != 0 ){
  19371. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19372. return;
  19373. }
  19374. }
  19375. // If triggered from item
  19376. if( sd->itemid == sd->state.laphine_synthesis ){
  19377. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19378. if( index < 0 ){
  19379. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19380. return;
  19381. }
  19382. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19383. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19384. return;
  19385. }
  19386. }
  19387. }
  19388. for( size_t i = 0; i < count; i++ ){
  19389. int16 index = server_index( p->items[i].index );
  19390. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19391. return;
  19392. }
  19393. }
  19394. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, sd );
  19395. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19396. #endif
  19397. }
  19398. void clif_laphine_upgrade_open( map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19399. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19400. nullpo_retv( sd );
  19401. sd->state.laphine_upgrade = upgrade->item_id;
  19402. struct PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19403. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19404. p.itemId = client_nameid( upgrade->item_id );
  19405. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19406. #endif
  19407. }
  19408. void clif_parse_laphine_upgrade_close( int fd, map_session_data* sd ){
  19409. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19410. sd->state.laphine_upgrade = 0;
  19411. #endif
  19412. }
  19413. void clif_laphine_upgrade_result( map_session_data *sd, bool failed ){
  19414. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19415. struct PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19416. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19417. p.result = failed;
  19418. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19419. #endif
  19420. }
  19421. static void clif_item_preview( map_session_data *sd, int16 index ){
  19422. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19423. nullpo_retv( sd );
  19424. struct item* item = &sd->inventory.u.items_inventory[index];
  19425. struct PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19426. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19427. p.index = client_index( index );
  19428. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19429. p.isDamaged = item->attribute != 0;
  19430. #endif
  19431. p.refiningLevel = item->refine;
  19432. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19433. p.grade = item->enchantgrade;
  19434. #endif
  19435. clif_addcards( &p.slot, item );
  19436. clif_add_random_options( p.option_data, *item );
  19437. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19438. #endif
  19439. }
  19440. void clif_parse_laphine_upgrade( int fd, map_session_data* sd ){
  19441. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19442. if( sd->state.laphine_upgrade == 0 ){
  19443. return;
  19444. }
  19445. struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*)RFIFOP( fd, 0 );
  19446. if( sd->state.laphine_upgrade != p->itemId ){
  19447. return;
  19448. }
  19449. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19450. if( upgrade == nullptr ){
  19451. return;
  19452. }
  19453. uint16 index = server_index( p->index );
  19454. if( index >= MAX_INVENTORY ){
  19455. return;
  19456. }
  19457. if( sd->inventory_data[index] == nullptr ){
  19458. return;
  19459. }
  19460. struct item* item = &sd->inventory.u.items_inventory[index];
  19461. // Not a valid target item
  19462. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19463. clif_laphine_upgrade_result( sd, true );
  19464. return;
  19465. }
  19466. // If target item is not identified
  19467. if( item->identify == 0 ){
  19468. clif_laphine_upgrade_result( sd, true );
  19469. return;
  19470. }
  19471. // If target item is equipped
  19472. if( item->equip != 0 ){
  19473. clif_laphine_upgrade_result( sd, true );
  19474. return;
  19475. }
  19476. // If target item is in equipswitch
  19477. if( item->equipSwitch != 0 ){
  19478. clif_laphine_upgrade_result( sd, true );
  19479. return;
  19480. }
  19481. // Check minimum refine requirement
  19482. if( item->refine < upgrade->minimumRefine ){
  19483. clif_laphine_upgrade_result( sd, true );
  19484. return;
  19485. }
  19486. // Check maximum refine requirement
  19487. if( item->refine > upgrade->maximumRefine ){
  19488. clif_laphine_upgrade_result( sd, true );
  19489. return;
  19490. }
  19491. // If no cards are allowed
  19492. if( !upgrade->cardsAllowed ){
  19493. for( int i = 0; i < MAX_SLOTS; i++ ){
  19494. if( item->card[i] != 0 ){
  19495. clif_laphine_upgrade_result( sd, true );
  19496. return;
  19497. }
  19498. }
  19499. }
  19500. // If random options are required
  19501. if( upgrade->requiredRandomOptions > 0 ){
  19502. int i;
  19503. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19504. if( item->option[i].id != 0 ){
  19505. break;
  19506. }
  19507. }
  19508. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19509. clif_laphine_upgrade_result( sd, true );
  19510. return;
  19511. }
  19512. }
  19513. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19514. if( index2 < 0 ){
  19515. clif_laphine_upgrade_result( sd, true );
  19516. return;
  19517. }
  19518. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19519. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19520. return;
  19521. }
  19522. }
  19523. // Log removal of item
  19524. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19525. // Visually remove it from the client
  19526. clif_delitem( sd, index, 1, 0 );
  19527. // Apply the random options
  19528. if( upgrade->randomOptionGroup != nullptr ){
  19529. upgrade->randomOptionGroup->apply( *item );
  19530. }
  19531. // Change the refine rate if needed
  19532. if( upgrade->resultRefine > 0 ){
  19533. // Absolute refine level change
  19534. item->refine = max( item->refine, upgrade->resultRefine );
  19535. }else if( upgrade->resultRefineMaximum > 0 ){
  19536. // If a minimum is specified it can also downgrade
  19537. if( upgrade->resultRefineMinimum ){
  19538. item->refine = static_cast<uint8>( rnd_value<uint16>( upgrade->resultRefineMinimum, upgrade->resultRefineMaximum ) );
  19539. }else{
  19540. // Otherwise it can only be upgraded until the maximum, but not downgraded
  19541. item->refine = static_cast<uint8>( rnd_value<uint16>( item->refine, upgrade->resultRefineMaximum ) );
  19542. }
  19543. }else if( upgrade->resultRefineMinimum > 0 ){
  19544. // No maximum has been specified, so it can be anything between minimum and MAX_REFINE
  19545. item->refine = static_cast<uint8>( rnd_value<uint16>( upgrade->resultRefineMinimum, MAX_REFINE ) );
  19546. }
  19547. // Log retrieving the item again -> with the new options
  19548. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19549. // Make it visible for the client again
  19550. clif_additem( sd, index, 1, 0 );
  19551. // Open a preview of the item
  19552. clif_item_preview( sd, index );
  19553. // Tell the client we are done
  19554. clif_laphine_upgrade_result( sd, false );
  19555. #endif
  19556. }
  19557. void clif_enchantgrade_add( map_session_data& sd, uint16 index = UINT16_MAX, std::shared_ptr<s_enchantgradelevel> gradeLevel = nullptr ){
  19558. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19559. struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST* p = (struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST*)packet_buffer;
  19560. p->PacketType = HEADER_ZC_GRADE_ENCHANT_MATERIAL_LIST;
  19561. p->PacketLength = sizeof( struct PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST );
  19562. if( index < UINT16_MAX ){
  19563. p->index = client_index( index );
  19564. p->success_chance = gradeLevel->chances[sd.inventory.u.items_inventory[index].refine] / 100;
  19565. p->blessing_info.id = client_nameid( gradeLevel->catalyst.item );
  19566. p->blessing_info.amount = gradeLevel->catalyst.amountPerStep;
  19567. p->blessing_info.max_blessing = gradeLevel->catalyst.maximumSteps;
  19568. p->blessing_info.bonus = gradeLevel->catalyst.chanceIncrease / 100;
  19569. // Not displayed by client
  19570. p->protect_itemid = 0;
  19571. p->protect_amount = 0;
  19572. int i = 0;
  19573. for( const auto& pair : gradeLevel->options ){
  19574. std::shared_ptr<s_enchantgradeoption> option = pair.second;
  19575. p->material_info[i].nameid = client_nameid( option->item );
  19576. p->material_info[i].amount = option->amount;
  19577. p->material_info[i].price = option->zeny;
  19578. p->material_info[i].downgrade = option->downgrade_amount > 0;
  19579. p->material_info[i].breakable = option->breaking_rate > 0;
  19580. p->PacketLength += sizeof( struct GRADE_ENCHANT_MATERIAL );
  19581. i++;
  19582. }
  19583. }else{
  19584. p->index = -1;
  19585. p->success_chance = 0;
  19586. p->blessing_info.id = 0;
  19587. p->blessing_info.amount = 0;
  19588. p->blessing_info.max_blessing = 0;
  19589. p->blessing_info.bonus = 0;
  19590. p->protect_itemid = 0;
  19591. p->protect_amount = 0;
  19592. }
  19593. clif_send( p, p->PacketLength, &sd.bl, SELF );
  19594. #endif
  19595. }
  19596. void clif_parse_enchantgrade_add( int fd, map_session_data* sd ){
  19597. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19598. nullpo_retv( sd );
  19599. if( !sd->state.enchantgrade_open ){
  19600. return;
  19601. }
  19602. struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT* p = (struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT*)RFIFOP( fd, 0 );
  19603. uint16 index = server_index( p->index );
  19604. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19605. return;
  19606. }
  19607. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19608. // Unsupported item type - no answer, because client should have actually prevented this request
  19609. if( enchantgrade == nullptr ){
  19610. return;
  19611. }
  19612. // Item can't be enhanced
  19613. if( !sd->inventory_data[index]->flag.gradable ){
  19614. return;
  19615. }
  19616. uint16 level = 0;
  19617. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19618. level = sd->inventory_data[index]->weapon_level;
  19619. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19620. level = sd->inventory_data[index]->armor_level;
  19621. }
  19622. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19623. // Cannot upgrade this weapon or armor level
  19624. if( enchantgradelevels == enchantgrade->levels.end() ){
  19625. clif_enchantgrade_add( *sd );
  19626. return;
  19627. }
  19628. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19629. // Cannot increase enchantgrade any further - no answer, because client should have actually prevented this request
  19630. if( enchantgradelevel == nullptr ){
  19631. return;
  19632. }
  19633. clif_enchantgrade_add( *sd, index, enchantgradelevel );
  19634. #endif
  19635. }
  19636. /// <summary>
  19637. /// Sends the result for trying to enchant an item
  19638. /// </summary>
  19639. /// <param name="sd">The player session</param>
  19640. /// <param name="index">The target item</param>
  19641. /// <param name="result">
  19642. /// 0= The grade has been successfully upgraded.
  19643. /// 1= Refinement failed.
  19644. /// 2= The refine level has decreased.
  19645. /// 3= Equipment destroyed.
  19646. /// 4= The equipment is protected.
  19647. /// </param>
  19648. void clif_enchantgrade_result( map_session_data& sd, uint16 index, e_enchantgrade_result result ){
  19649. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19650. struct PACKET_ZC_GRADE_ENCHANT_ACK p = {};
  19651. p.PacketType = HEADER_ZC_GRADE_ENCHANT_ACK;
  19652. p.index = client_index( index );
  19653. p.grade = sd.inventory.u.items_inventory[index].enchantgrade;
  19654. p.result = result;
  19655. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19656. #endif
  19657. }
  19658. void clif_enchantgrade_announce( map_session_data& sd, struct item& item, bool success ){
  19659. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19660. struct PACKET_ZC_GRADE_ENCHANT_BROADCAST_RESULT p = {};
  19661. p.packetType = HEADER_ZC_GRADE_ENCHANT_BROADCAST_RESULT;
  19662. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  19663. p.itemId = client_nameid( item.nameid );
  19664. p.grade = item.enchantgrade;
  19665. p.status = success;
  19666. clif_send( &p, sizeof( p ), nullptr, ALL_CLIENT );
  19667. #endif
  19668. }
  19669. void clif_parse_enchantgrade_start( int fd, map_session_data* sd ){
  19670. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19671. nullpo_retv( sd );
  19672. if( !sd->state.enchantgrade_open ){
  19673. return;
  19674. }
  19675. struct PACKET_CZ_GRADE_ENCHANT_REQUEST* p = (struct PACKET_CZ_GRADE_ENCHANT_REQUEST*)RFIFOP( fd, 0 );
  19676. uint16 index = server_index( p->index );
  19677. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19678. return;
  19679. }
  19680. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19681. // Unsupported item type - no answer
  19682. if( enchantgrade == nullptr ){
  19683. return;
  19684. }
  19685. uint16 level = 0;
  19686. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19687. level = sd->inventory_data[index]->weapon_level;
  19688. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19689. level = sd->inventory_data[index]->armor_level;
  19690. }
  19691. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19692. // Cannot upgrade this weapon or armor level - no answer
  19693. if( enchantgradelevels == enchantgrade->levels.end() ){
  19694. return;
  19695. }
  19696. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19697. // Cannot increase enchantgrade any further - no answer
  19698. if( enchantgradelevel == nullptr ){
  19699. return;
  19700. }
  19701. uint16 totalChance = enchantgradelevel->chances[sd->inventory.u.items_inventory[index].refine];
  19702. // No chance to increase the enchantgrade
  19703. if( totalChance == 0 ){
  19704. return;
  19705. }
  19706. std::shared_ptr<s_enchantgradeoption> option = util::map_find( enchantgradelevel->options, (uint16)p->material_index );
  19707. // Unknown option id - no answer
  19708. if( option == nullptr ){
  19709. return;
  19710. }
  19711. // Not enough zeny
  19712. if( sd->status.zeny < option->zeny ){
  19713. return;
  19714. }
  19715. uint16 steps = min( p->blessing_amount, enchantgradelevel->catalyst.maximumSteps );
  19716. std::unordered_map<uint16, uint16> requiredItems;
  19717. if( p->blessing_flag ){
  19718. // If the catalysator item is the same as the option item build the sum of amounts
  19719. if( enchantgradelevel->catalyst.item == option->item ){
  19720. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps + option->amount;
  19721. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19722. if( index < 0 ){
  19723. return;
  19724. }
  19725. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19726. return;
  19727. }
  19728. requiredItems[index] = amount;
  19729. }else{
  19730. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps;
  19731. // Check catalysator item
  19732. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19733. if( index < 0 ){
  19734. return;
  19735. }
  19736. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19737. return;
  19738. }
  19739. requiredItems[index] = amount;
  19740. // Check option item
  19741. index = pc_search_inventory( sd, option->item );
  19742. if( index < 0 ){
  19743. return;
  19744. }
  19745. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19746. return;
  19747. }
  19748. requiredItems[index] = option->amount;
  19749. }
  19750. totalChance += steps * enchantgradelevel->catalyst.chanceIncrease;
  19751. }else{
  19752. // Check option item
  19753. int16 index = pc_search_inventory( sd, option->item );
  19754. if( index < 0 ){
  19755. return;
  19756. }
  19757. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19758. return;
  19759. }
  19760. requiredItems[index] = option->amount;
  19761. }
  19762. // All items should be there, start deleting
  19763. for( const auto& pair : requiredItems ){
  19764. if( pc_delitem( sd, pair.first, pair.second, 0, 0, LOG_TYPE_ENCHANTGRADE ) != 0 ){
  19765. return;
  19766. }
  19767. }
  19768. if( pc_payzeny( sd, option->zeny, LOG_TYPE_ENCHANTGRADE ) > 0 ){
  19769. return;
  19770. }
  19771. if( rnd()%10000 < totalChance ){
  19772. // Log removal of item
  19773. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19774. // Increase enchantgrade
  19775. sd->inventory.u.items_inventory[index].enchantgrade = min( sd->inventory.u.items_inventory[index].enchantgrade + 1, MAX_ENCHANTGRADE );
  19776. // On successful enchantgrade increase the refine is reset
  19777. sd->inventory.u.items_inventory[index].refine = 0;
  19778. // Log retrieving the item again -> with the new refine and enchantgrade
  19779. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19780. // Show success
  19781. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_SUCCESS );
  19782. // Check if it has to be announced
  19783. if( enchantgradelevel->announceSuccess ){
  19784. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], true );
  19785. }
  19786. }else{
  19787. // Check if it has to be announced (has to be done before deleting the item from inventory)
  19788. if( enchantgradelevel->announceFail ){
  19789. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], false );
  19790. }
  19791. // Delete the item if it is breakable
  19792. if( option->breaking_rate > 0 && ( rnd() % 10000 ) < option->breaking_rate ){
  19793. // Delete the item
  19794. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_ENCHANTGRADE );
  19795. // Show failure
  19796. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_BREAK );
  19797. // Downgrade the item if necessary
  19798. }else if( option->downgrade_amount > 0 ){
  19799. // Log removal of item
  19800. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19801. // Decrease refine level
  19802. sd->inventory.u.items_inventory[index].refine = cap_value( sd->inventory.u.items_inventory[index].refine - option->downgrade_amount, 0, MAX_REFINE );
  19803. // Log retrieving the item again -> with the new refine
  19804. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19805. // Show downgrade
  19806. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_DOWNGRADE );
  19807. // Only show failure, but dont do anything
  19808. }else{
  19809. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_FAILED );
  19810. }
  19811. }
  19812. #endif
  19813. }
  19814. void clif_parse_enchantgrade_close( int fd, map_session_data* sd ){
  19815. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19816. nullpo_retv( sd );
  19817. sd->state.enchantgrade_open = false;
  19818. #endif
  19819. }
  19820. void clif_reputation_type( map_session_data& sd, int64 type, int64 points ){
  19821. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19822. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19823. p->packetType = HEADER_ZC_REPUTE_INFO;
  19824. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO ) + sizeof( struct PACKET_ZC_REPUTE_INFO_sub );
  19825. p->success = true;
  19826. struct PACKET_ZC_REPUTE_INFO_sub* entry = &p->list[0];
  19827. entry->type = type;
  19828. entry->points = points;
  19829. clif_send( p, p->packetLength, &sd.bl, SELF );
  19830. #endif
  19831. }
  19832. void clif_reputation_list( map_session_data& sd ){
  19833. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19834. struct PACKET_ZC_REPUTE_INFO* p = (struct PACKET_ZC_REPUTE_INFO*)packet_buffer;
  19835. p->packetType = HEADER_ZC_REPUTE_INFO;
  19836. p->packetLength = sizeof( struct PACKET_ZC_REPUTE_INFO );
  19837. p->success = true;
  19838. size_t index = 0;
  19839. for( const auto& entry : reputation_db ){
  19840. std::shared_ptr<s_reputation> reputation = entry.second;
  19841. struct PACKET_ZC_REPUTE_INFO_sub* list_entry = &p->list[index];
  19842. list_entry->type = reputation->id;
  19843. list_entry->points = pc_readreg2( &sd, reputation->variable.c_str() );
  19844. p->packetLength += sizeof( *list_entry );
  19845. index++;
  19846. }
  19847. clif_send( p, p->packetLength, &sd.bl, SELF );
  19848. #endif
  19849. }
  19850. void clif_item_reform_open( map_session_data& sd, t_itemid item ){
  19851. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19852. struct PACKET_ZC_OPEN_REFORM_UI p = {};
  19853. p.PacketType = HEADER_ZC_OPEN_REFORM_UI;
  19854. p.ITID = item;
  19855. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19856. sd.state.item_reform = item;
  19857. #endif
  19858. }
  19859. void clif_parse_item_reform_close( int fd, map_session_data* sd ){
  19860. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19861. sd->state.item_reform = 0;
  19862. #endif
  19863. }
  19864. void clif_item_reform_result( map_session_data& sd, uint16 index, uint8 result ){
  19865. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19866. struct PACKET_ZC_ITEM_REFORM_ACK p = {};
  19867. p.PacketType = HEADER_ZC_ITEM_REFORM_ACK;
  19868. p.index = client_index( index );
  19869. p.result = result;
  19870. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19871. if( result == 0 ){
  19872. // Client closes the window on success
  19873. sd.state.item_reform = 0;
  19874. }
  19875. #endif
  19876. }
  19877. void clif_parse_item_reform_start( int fd, map_session_data* sd ){
  19878. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19879. // Not opened
  19880. if( sd->state.item_reform == 0 ){
  19881. return;
  19882. }
  19883. struct PACKET_CZ_ITEM_REFORM *p = (struct PACKET_CZ_ITEM_REFORM*)RFIFOP( fd, 0 );
  19884. // Item mismatch
  19885. if( p->ITID != sd->state.item_reform ){
  19886. return;
  19887. }
  19888. uint16 index = server_index( p->index );
  19889. if( index >= MAX_INVENTORY ){
  19890. return;
  19891. }
  19892. if( sd->inventory_data[index] == nullptr ){
  19893. return;
  19894. }
  19895. std::shared_ptr<s_item_reform> reform = item_reform_db.find( sd->state.item_reform );
  19896. if( reform == nullptr ){
  19897. return;
  19898. }
  19899. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19900. std::shared_ptr<s_item_reform_base> base = util::umap_find( reform->base_items, selected_item.nameid );
  19901. if( base == nullptr ){
  19902. return;
  19903. }
  19904. // If target item is not identified
  19905. if( selected_item.identify == 0 ){
  19906. return;
  19907. }
  19908. // If target item is equipped
  19909. if( selected_item.equip != 0 ){
  19910. return;
  19911. }
  19912. // Check minimum refine requirement
  19913. if( selected_item.refine < base->minimumRefine ){
  19914. return;
  19915. }
  19916. // Check maximum refine requirement
  19917. if( selected_item.refine > base->maximumRefine ){
  19918. return;
  19919. }
  19920. // If no cards are allowed
  19921. if( !base->cardsAllowed ){
  19922. for( int i = 0; i < MAX_SLOTS; i++ ){
  19923. if( selected_item.card[i] != 0 ){
  19924. return;
  19925. }
  19926. }
  19927. }
  19928. // If random options are required
  19929. if( base->requiredRandomOptions > 0 ){
  19930. int i;
  19931. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19932. if( selected_item.option[i].id != 0 ){
  19933. break;
  19934. }
  19935. }
  19936. if( ( i + 1 ) < base->requiredRandomOptions ){
  19937. return;
  19938. }
  19939. }
  19940. std::unordered_map<uint16, uint16> materials;
  19941. // Check if all materials exist
  19942. for( const auto& material : base->materials ){
  19943. int16 material_index = pc_search_inventory( sd, material.first );
  19944. if( material_index < 0 ){
  19945. return;
  19946. }
  19947. if( sd->inventory.u.items_inventory[material_index].amount < material.second ){
  19948. return;
  19949. }
  19950. materials[material_index] = material.second;
  19951. }
  19952. // Remove the material
  19953. for( const auto& material : materials ){
  19954. if( pc_delitem( sd, material.first, material.second, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19955. return;
  19956. }
  19957. }
  19958. // If triggered from item
  19959. if( sd->itemid == sd->state.item_reform && pc_delitem( sd, sd->itemindex, 1, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19960. return;
  19961. }
  19962. // Log removal of item
  19963. log_pick_pc( sd, LOG_TYPE_REFORM, -1, &selected_item );
  19964. // Visually remove it from the client
  19965. clif_delitem( sd, index, 1, 0 );
  19966. // Apply the random options
  19967. if( base->randomOptionGroup != nullptr ){
  19968. base->randomOptionGroup->apply( selected_item );
  19969. }
  19970. // Change the refine rate if needed
  19971. if( base->refineChange != 0 ){
  19972. selected_item.refine = cap_value( selected_item.refine + base->refineChange, 0, MAX_REFINE );
  19973. }
  19974. // Remove all cards and socket enchants
  19975. if( base->clearSlots ){
  19976. for( int i = 0; i < MAX_SLOTS; i++ ){
  19977. selected_item.card[i] = 0;
  19978. }
  19979. }
  19980. // Remove the current enchantgrade
  19981. if( base->removeEnchantgrade ){
  19982. selected_item.enchantgrade = 0;
  19983. }
  19984. // Finally change the item id
  19985. selected_item.nameid = base->resultItemId;
  19986. // Link inventory data cache to the new item
  19987. sd->inventory_data[index] = itemdb_search( base->resultItemId );
  19988. // Log retrieving the item again -> with the new options
  19989. log_pick_pc( sd, LOG_TYPE_REFORM, 1, &selected_item );
  19990. // Make it visible for the client again
  19991. clif_additem( sd, index, 1, 0 );
  19992. clif_item_reform_result( *sd, index, 0 );
  19993. #endif
  19994. }
  19995. void clif_enchantwindow_open( map_session_data& sd, uint64 clientLuaIndex ){
  19996. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19997. // Hardcoded clientside check
  19998. if( sd.weight > ( ( sd.max_weight * 70 ) / 100 ) ){
  19999. clif_msg_color( &sd, C_ENCHANT_OVERWEIGHT, color_table[COLOR_RED] );
  20000. sd.state.item_enchant_index = 0;
  20001. return;
  20002. }
  20003. struct PACKET_ZC_UI_OPEN_V3 p = {};
  20004. p.packetType = HEADER_ZC_UI_OPEN_V3;
  20005. p.type = OUT_UI_ENCHANT;
  20006. p.data = clientLuaIndex;
  20007. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20008. sd.state.item_enchant_index = clientLuaIndex;
  20009. #endif
  20010. }
  20011. void clif_enchantwindow_result( map_session_data& sd, bool success, t_itemid enchant = 0 ){
  20012. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  20013. struct PACKET_ZC_RESPONSE_ENCHANT p = {};
  20014. p.PacketType = HEADER_ZC_RESPONSE_ENCHANT;
  20015. if( success ){
  20016. p.msgId = C_ENCHANT_SUCCESS;
  20017. }else{
  20018. p.msgId = C_ENCHANT_FAILURE;
  20019. }
  20020. p.ITID = enchant;
  20021. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20022. sd.state.item_enchant_index = 0;
  20023. #endif
  20024. }
  20025. bool clif_parse_enchant_basecheck( struct item& selected_item, std::shared_ptr<s_item_enchant> enchant ){
  20026. if( selected_item.equip != 0 ){
  20027. return false;
  20028. }
  20029. if( selected_item.equipSwitch != 0 ){
  20030. return false;
  20031. }
  20032. if( selected_item.attribute != 0 ){
  20033. return false;
  20034. }
  20035. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20036. return false;
  20037. }
  20038. if( selected_item.refine < enchant->minimumRefine ){
  20039. return false;
  20040. }
  20041. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20042. return false;
  20043. }
  20044. if( !enchant->allowRandomOptions ){
  20045. for( const s_item_randomoption& option : selected_item.option ){
  20046. if( option.id != 0 ){
  20047. return false;
  20048. }
  20049. }
  20050. }
  20051. return true;
  20052. }
  20053. void clif_parse_enchantwindow_general( int fd, map_session_data* sd ){
  20054. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20055. struct PACKET_CZ_REQUEST_RANDOM_ENCHANT *p = (struct PACKET_CZ_REQUEST_RANDOM_ENCHANT*)RFIFOP( fd, 0 );
  20056. if( sd->state.item_enchant_index != p->enchant_group ){
  20057. return;
  20058. }
  20059. uint16 index = server_index( p->index );
  20060. if( index >= MAX_INVENTORY ){
  20061. return;
  20062. }
  20063. if( sd->inventory_data[index] == nullptr ){
  20064. return;
  20065. }
  20066. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20067. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20068. if( enchant == nullptr ){
  20069. return;
  20070. }
  20071. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20072. return;
  20073. }
  20074. uint16 slot = MAX_SLOTS;
  20075. for( uint16 nextSlot : enchant->order ){
  20076. if( selected_item.card[nextSlot] == 0 ){
  20077. slot = nextSlot;
  20078. break;
  20079. }
  20080. }
  20081. if( slot == MAX_SLOTS ){
  20082. return;
  20083. }
  20084. if( slot < sd->inventory_data[index]->slots ){
  20085. return;
  20086. }
  20087. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20088. if( enchant_slot == nullptr ){
  20089. return;
  20090. }
  20091. std::shared_ptr<s_item_enchant_normal> enchants_for_enchantgrade = util::umap_find( enchant_slot->normal.enchants, (uint16)selected_item.enchantgrade );
  20092. if( enchants_for_enchantgrade == nullptr ){
  20093. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 829 ), false, SELF); // Enchanting is not possible for your item's enchant grade.
  20094. clif_enchantwindow_result( *sd, false );
  20095. return;
  20096. }
  20097. if( sd->status.zeny < enchant_slot->normal.zeny ){
  20098. return;
  20099. }
  20100. std::unordered_map<uint16, uint16> materials;
  20101. for( const auto& entry : enchant_slot->normal.materials ){
  20102. int16 idx = pc_search_inventory( sd, entry.first );
  20103. if( idx < 0 ){
  20104. return;
  20105. }
  20106. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20107. return;
  20108. }
  20109. materials[idx] = entry.second;
  20110. }
  20111. if( pc_payzeny( sd, enchant_slot->normal.zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20112. return;
  20113. }
  20114. for( const auto& entry : materials ){
  20115. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20116. return;
  20117. }
  20118. }
  20119. uint32 chance = enchant_slot->normal.chance;
  20120. for( int i = 0; i <= MAX_ENCHANTGRADE; i++ ){
  20121. chance += enchant_slot->normal.enchantgradeChanceIncrease[i];
  20122. }
  20123. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20124. clif_enchantwindow_result( *sd, false );
  20125. return;
  20126. }
  20127. // Log removal of item
  20128. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20129. size_t maximum = 3 * enchant_slot->normal.enchants.size();
  20130. bool enchanted = false;
  20131. for( int i = 0; i < maximum; i++ ){
  20132. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  20133. if( rnd_value( 0, 10000 ) < normal_enchant->chance ){
  20134. selected_item.card[slot] = normal_enchant->item_id;
  20135. enchanted = true;
  20136. break;
  20137. }
  20138. }
  20139. if( !enchanted ){
  20140. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  20141. selected_item.card[slot] = normal_enchant->item_id;
  20142. }
  20143. // Log retrieving the item again -> with the new enchant
  20144. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20145. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20146. #endif
  20147. }
  20148. void clif_parse_enchantwindow_perfect( int fd, map_session_data* sd ){
  20149. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20150. struct PACKET_CZ_REQUEST_PERFECT_ENCHANT *p = (struct PACKET_CZ_REQUEST_PERFECT_ENCHANT*)RFIFOP( fd, 0 );
  20151. if( sd->state.item_enchant_index != p->enchant_group ){
  20152. return;
  20153. }
  20154. uint16 index = server_index( p->index );
  20155. if( index >= MAX_INVENTORY ){
  20156. return;
  20157. }
  20158. if( sd->inventory_data[index] == nullptr ){
  20159. return;
  20160. }
  20161. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20162. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20163. if( enchant == nullptr ){
  20164. return;
  20165. }
  20166. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20167. return;
  20168. }
  20169. uint16 slot = MAX_SLOTS;
  20170. for( uint16 nextSlot : enchant->order ){
  20171. if( selected_item.card[nextSlot] == 0 ){
  20172. slot = nextSlot;
  20173. break;
  20174. }
  20175. }
  20176. if( slot == MAX_SLOTS ){
  20177. return;
  20178. }
  20179. if( slot < sd->inventory_data[index]->slots ){
  20180. return;
  20181. }
  20182. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20183. if( enchant_slot == nullptr ){
  20184. return;
  20185. }
  20186. std::shared_ptr<s_item_enchant_perfect> perfect_enchant = util::umap_find( enchant_slot->perfect.enchants, p->ITID );
  20187. if( perfect_enchant == nullptr ){
  20188. return;
  20189. }
  20190. if( sd->status.zeny < perfect_enchant->zeny ){
  20191. return;
  20192. }
  20193. std::unordered_map<uint16, uint16> materials;
  20194. for( const auto& entry : perfect_enchant->materials ){
  20195. int16 idx = pc_search_inventory( sd, entry.first );
  20196. if( idx < 0 ){
  20197. return;
  20198. }
  20199. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20200. return;
  20201. }
  20202. materials[idx] = entry.second;
  20203. }
  20204. if( pc_payzeny( sd, perfect_enchant->zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20205. return;
  20206. }
  20207. for( const auto& entry : materials ){
  20208. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20209. return;
  20210. }
  20211. }
  20212. // Log removal of item
  20213. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20214. selected_item.card[slot] = perfect_enchant->item_id;
  20215. // Log retrieving the item again -> with the new enchant
  20216. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20217. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20218. #endif
  20219. }
  20220. void clif_parse_enchantwindow_upgrade( int fd, map_session_data* sd ){
  20221. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20222. struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT *p = (struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT*)RFIFOP( fd, 0 );
  20223. if( sd->state.item_enchant_index != p->enchant_group ){
  20224. return;
  20225. }
  20226. uint16 index = server_index( p->index );
  20227. if( index >= MAX_INVENTORY ){
  20228. return;
  20229. }
  20230. if( sd->inventory_data[index] == nullptr ){
  20231. return;
  20232. }
  20233. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20234. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20235. if( enchant == nullptr ){
  20236. return;
  20237. }
  20238. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20239. return;
  20240. }
  20241. uint16 slot = p->slot;
  20242. if( slot >= MAX_SLOTS ){
  20243. return;
  20244. }
  20245. if( slot < sd->inventory_data[index]->slots ){
  20246. return;
  20247. }
  20248. if( selected_item.card[slot] == 0 ){
  20249. return;
  20250. }
  20251. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20252. if( enchant_slot == nullptr ){
  20253. return;
  20254. }
  20255. std::shared_ptr<s_item_enchant_upgrade> upgrade = util::umap_find( enchant_slot->upgrade.enchants, selected_item.card[slot] );
  20256. if( upgrade == nullptr ){
  20257. return;
  20258. }
  20259. if( sd->status.zeny < upgrade->zeny ){
  20260. return;
  20261. }
  20262. std::unordered_map<uint16, uint16> materials;
  20263. for( const auto& entry : upgrade->materials ){
  20264. int16 idx = pc_search_inventory( sd, entry.first );
  20265. if( idx < 0 ){
  20266. return;
  20267. }
  20268. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20269. return;
  20270. }
  20271. materials[idx] = entry.second;
  20272. }
  20273. if( pc_payzeny( sd, upgrade->zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20274. return;
  20275. }
  20276. for( const auto& entry : materials ){
  20277. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20278. return;
  20279. }
  20280. }
  20281. // Log removal of item
  20282. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20283. selected_item.card[slot] = upgrade->upgrade_item_id;
  20284. // Log retrieving the item again -> with the new enchant
  20285. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20286. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20287. #endif
  20288. }
  20289. void clif_parse_enchantwindow_reset( int fd, map_session_data* sd ){
  20290. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20291. struct PACKET_CZ_REQUEST_RESET_ENCHANT *p = (struct PACKET_CZ_REQUEST_RESET_ENCHANT*)RFIFOP( fd, 0 );
  20292. if( sd->state.item_enchant_index != p->enchant_group ){
  20293. return;
  20294. }
  20295. uint16 index = server_index( p->index );
  20296. if( index >= MAX_INVENTORY ){
  20297. return;
  20298. }
  20299. if( sd->inventory_data[index] == nullptr ){
  20300. return;
  20301. }
  20302. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20303. if( selected_item.equip != 0 ){
  20304. return;
  20305. }
  20306. if( selected_item.equipSwitch != 0 ){
  20307. return;
  20308. }
  20309. if( selected_item.attribute != 0 ){
  20310. return;
  20311. }
  20312. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20313. if( enchant == nullptr ){
  20314. return;
  20315. }
  20316. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20317. return;
  20318. }
  20319. if( selected_item.refine < enchant->minimumRefine ){
  20320. return;
  20321. }
  20322. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20323. return;
  20324. }
  20325. bool is_enchanted = false;
  20326. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20327. if( selected_item.card[i] != 0 ){
  20328. is_enchanted = true;
  20329. break;
  20330. }
  20331. }
  20332. if( !is_enchanted ){
  20333. return;
  20334. }
  20335. if( sd->status.zeny < enchant->reset.zeny ){
  20336. return;
  20337. }
  20338. std::unordered_map<uint16, uint16> materials;
  20339. for( const auto& entry : enchant->reset.materials ){
  20340. int16 idx = pc_search_inventory( sd, entry.first );
  20341. if( idx < 0 ){
  20342. return;
  20343. }
  20344. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20345. return;
  20346. }
  20347. materials[idx] = entry.second;
  20348. }
  20349. if( pc_payzeny( sd, enchant->reset.zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20350. return;
  20351. }
  20352. for( const auto& entry : materials ){
  20353. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20354. return;
  20355. }
  20356. }
  20357. uint32 chance = enchant->reset.chance;
  20358. if( chance == 0 ){
  20359. return;
  20360. }
  20361. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20362. clif_enchantwindow_result( *sd, false );
  20363. return;
  20364. }
  20365. // Log removal of item
  20366. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20367. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20368. selected_item.card[i] = 0;
  20369. }
  20370. // Log retrieving the item again -> with the new enchant
  20371. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20372. clif_enchantwindow_result( *sd, true );
  20373. #endif
  20374. }
  20375. void clif_parse_enchantwindow_close( int fd, map_session_data* sd ){
  20376. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20377. sd->state.item_enchant_index = 0;
  20378. #endif
  20379. }
  20380. void clif_parse_itempackage_select( int fd, map_session_data* sd ){
  20381. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220316
  20382. struct PACKET_CZ_USE_PACKAGEITEM* p = (struct PACKET_CZ_USE_PACKAGEITEM*)RFIFOP( fd, 0 );
  20383. if( p->AID != sd->status.account_id ){
  20384. return;
  20385. }
  20386. uint16 index = server_index( p->index );
  20387. if( index >= MAX_INVENTORY ){
  20388. return;
  20389. }
  20390. if( sd->inventory_data[index] == nullptr ){
  20391. return;
  20392. }
  20393. if( sd->inventory_data[index]->nameid != p->itemID ){
  20394. return;
  20395. }
  20396. if( sd->inventory_data[index]->elv > sd->status.base_level ){
  20397. return;
  20398. }
  20399. std::shared_ptr<s_item_package> package = item_package_db.find( p->itemID );
  20400. if( package == nullptr ){
  20401. return;
  20402. }
  20403. std::shared_ptr<s_item_package_group> group = util::umap_find( package->groups, p->BoxIndex );
  20404. if( group == nullptr ){
  20405. return;
  20406. }
  20407. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_PACKAGE ) != 0 ){
  20408. return;
  20409. }
  20410. for( const auto& entry : group->items ){
  20411. struct item item = {};
  20412. item.nameid = entry.second->item_id;
  20413. item.identify = 1;
  20414. item.refine = (char)entry.second->refine;
  20415. if( entry.second->rentalhours ){
  20416. item.expire_time = (uint32)( time( nullptr ) + entry.second->rentalhours * 3600 );
  20417. }
  20418. // Check if it is a pet egg
  20419. std::shared_ptr<s_pet_db> pet = pet_db_search( item.nameid, PET_EGG );
  20420. if( pet != nullptr ){
  20421. for( int i = 0; i < entry.second->amount; i++ ){
  20422. pet_create_egg( sd, item.nameid );
  20423. }
  20424. }else if( entry.second->amount > 1 && ( !itemdb_isstackable( item.nameid ) || item.expire_time > 0 ) ){
  20425. for( int i = 0; i < entry.second->amount; i++ ){
  20426. // New random options on each iteration
  20427. if( entry.second->randomOptionGroup != nullptr ){
  20428. entry.second->randomOptionGroup->apply( item );
  20429. }
  20430. pc_additem( sd, &item, 1, LOG_TYPE_PACKAGE );
  20431. }
  20432. }else{
  20433. if( entry.second->randomOptionGroup != nullptr ){
  20434. entry.second->randomOptionGroup->apply( item );
  20435. }
  20436. pc_additem( sd, &item, entry.second->amount, LOG_TYPE_PACKAGE );
  20437. }
  20438. }
  20439. #endif
  20440. }
  20441. void clif_broadcast_refine_result(map_session_data& sd, t_itemid itemId, int8 level, bool success)
  20442. {
  20443. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  20444. PACKET_ZC_BROADCAST_ITEMREFINING_RESULT p{};
  20445. p.packetType = HEADER_ZC_BROADCAST_ITEMREFINING_RESULT;
  20446. p.itemId = itemId;
  20447. p.refine_level = level;
  20448. p.status = (int8)success;
  20449. if (battle_config.broadcast_hide_name) {
  20450. std::string dispname = clif_hide_name(sd.status.name);
  20451. safestrncpy(p.name, dispname.c_str(), sizeof(p.name));
  20452. }
  20453. else {
  20454. safestrncpy(p.name, sd.status.name, sizeof(p.name));
  20455. }
  20456. clif_send(&p, sizeof(p), &sd.bl, ALL_CLIENT);
  20457. #endif
  20458. }
  20459. void clif_parse_captcha_register(int fd, map_session_data *sd) {
  20460. #if PACKETVER >= 20160316
  20461. nullpo_retv(sd);
  20462. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20463. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20464. return;
  20465. }
  20466. PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *p = (PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20467. pc_macro_captcha_register(*sd, p->imageSize, p->answer);
  20468. #endif
  20469. }
  20470. void clif_captcha_upload_request(map_session_data &sd) {
  20471. #if PACKETVER >= 20160330
  20472. PACKET_ZC_ACK_UPLOAD_MACRO_DETECTOR p = {};
  20473. p.PacketType = HEADER_ZC_ACK_UPLOAD_MACRO_DETECTOR;
  20474. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20475. if (sd.captcha_upload.cd != nullptr) {
  20476. p.captchaFlag = 0;
  20477. } else {
  20478. p.captchaFlag = 1;
  20479. }
  20480. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20481. #endif
  20482. }
  20483. void clif_parse_captcha_upload(int fd, map_session_data *sd) {
  20484. #if PACKETVER >= 20160316
  20485. nullpo_retv(sd);
  20486. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20487. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20488. return;
  20489. }
  20490. PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20491. int16 upload_size = p->PacketLength - sizeof(PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA);
  20492. if (upload_size < 1 || upload_size > MAX_CAPTCHA_CHUNK_SIZE)
  20493. return;
  20494. if (sd->captcha_upload.upload_size + upload_size > sd->captcha_upload.cd->image_size)
  20495. return;
  20496. pc_macro_captcha_register_upload(*sd, upload_size, p->imageData);
  20497. #endif
  20498. }
  20499. void clif_captcha_upload_end(map_session_data &sd) {
  20500. #if PACKETVER >= 20160330
  20501. PACKET_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA p = {};
  20502. p.PacketType = HEADER_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA;
  20503. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20504. #endif
  20505. }
  20506. void clif_parse_captcha_preview_request(int fd, map_session_data *sd) {
  20507. #if PACKETVER >= 20160323
  20508. nullpo_retv(sd);
  20509. if (!(pc_has_permission(sd, PC_PERM_MACRO_REGISTER) && pc_has_permission(sd, PC_PERM_MACRO_DETECT))) {
  20510. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20511. return;
  20512. }
  20513. PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *p = (PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20514. clif_captcha_preview_response(*sd, captcha_db.find(p->captchaID));
  20515. #endif
  20516. }
  20517. void clif_captcha_preview_response(map_session_data &sd, std::shared_ptr<s_captcha_data> cd) {
  20518. #if PACKETVER >= 20160330
  20519. PACKET_ZC_ACK_PREVIEW_MACRO_DETECTOR p = {};
  20520. p.PacketType = HEADER_ZC_ACK_PREVIEW_MACRO_DETECTOR;
  20521. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20522. if (cd == nullptr) {
  20523. p.captchaFlag = 1;
  20524. p.imageSize = 0;
  20525. } else {
  20526. p.captchaFlag = 0;
  20527. p.imageSize = cd->image_size;
  20528. }
  20529. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20530. if (cd != nullptr) {
  20531. for (uint16 offset = 0; offset < cd->image_size;) {
  20532. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20533. PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20534. p2->PacketType = HEADER_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA;
  20535. p2->PacketLength = (int16)(sizeof(PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20536. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20537. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20538. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20539. offset += chunk_size;
  20540. }
  20541. }
  20542. #endif
  20543. }
  20544. void clif_macro_detector_request(map_session_data &sd) {
  20545. #if PACKETVER >= 20160330
  20546. std::shared_ptr<s_captcha_data> cd = sd.macro_detect.cd;
  20547. if (cd == nullptr) {
  20548. return;
  20549. }
  20550. // Send preview initialization request to the client.
  20551. PACKET_ZC_APPLY_MACRO_DETECTOR p = {};
  20552. p.PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR;
  20553. p.imageSize = cd->image_size;
  20554. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20555. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20556. for (uint16 offset = 0; offset < cd->image_size;) {
  20557. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20558. PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *p2 = (PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA *)packet_buffer;
  20559. p2->PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR_CAPTCHA;
  20560. p2->PacketLength = (int16)(sizeof(PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA) + chunk_size);
  20561. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20562. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20563. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20564. offset += chunk_size;
  20565. }
  20566. #endif
  20567. }
  20568. void clif_macro_detector_request_show(map_session_data &sd) {
  20569. #if PACKETVER >= 20160330
  20570. PACKET_ZC_REQ_ANSWER_MACRO_DETECTOR p = {};
  20571. p.PacketType = HEADER_ZC_REQ_ANSWER_MACRO_DETECTOR;
  20572. p.retryCount = sd.macro_detect.retry;
  20573. p.timeout = battle_config.macro_detection_timeout;
  20574. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20575. #endif
  20576. }
  20577. void clif_parse_macro_detector_download_ack(int fd, map_session_data *sd) {
  20578. #if PACKETVER >= 20160316
  20579. nullpo_retv(sd);
  20580. if (sd->macro_detect.retry != 0) {
  20581. //PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20582. clif_macro_detector_request_show(*sd);
  20583. }
  20584. #endif
  20585. }
  20586. void clif_parse_macro_detector_answer(int fd, map_session_data *sd) {
  20587. #if PACKETVER >= 20160316
  20588. nullpo_retv(sd);
  20589. PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *p = (PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20590. pc_macro_detector_process_answer(*sd, p->answer);
  20591. #endif
  20592. }
  20593. void clif_macro_detector_status(map_session_data &sd, e_macro_detect_status stype) {
  20594. #if PACKETVER >= 20160330
  20595. PACKET_ZC_CLOSE_MACRO_DETECTOR p = {};
  20596. p.PacketType = HEADER_ZC_CLOSE_MACRO_DETECTOR;
  20597. p.status = stype;
  20598. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20599. #endif
  20600. }
  20601. void clif_parse_macro_reporter_select(int fd, map_session_data *sd) {
  20602. #if PACKETVER >= 20160330
  20603. nullpo_retv(sd);
  20604. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20605. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20606. return;
  20607. }
  20608. PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *p = (PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *)RFIFOP(fd, 0);
  20609. pc_macro_reporter_area_select(*sd, p->xPos, p->yPos, p->RadiusRange);
  20610. #endif
  20611. }
  20612. void clif_macro_reporter_select(map_session_data &sd, const std::vector<uint32> &aid_list) {
  20613. #if PACKETVER >= 20160330
  20614. PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *p = (PACKET_ZC_ACK_PLAYER_AID_IN_RANGE *)packet_buffer;
  20615. p->PacketType = HEADER_ZC_ACK_PLAYER_AID_IN_RANGE;
  20616. p->PacketLength = static_cast<int16>(sizeof(PACKET_ZC_ACK_PLAYER_AID_IN_RANGE) + sizeof(uint32) * aid_list.size());
  20617. for (size_t i = 0; i < aid_list.size(); i++)
  20618. p->AID[i] = aid_list[static_cast<int32>(i)];
  20619. clif_send(p, p->PacketLength, &sd.bl, SELF);
  20620. #endif
  20621. }
  20622. void clif_parse_macro_reporter_ack(int fd, map_session_data *sd) {
  20623. #if PACKETVER >= 20160316
  20624. nullpo_retv(sd);
  20625. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20626. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20627. return;
  20628. }
  20629. PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *p = (PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20630. map_session_data *tsd = map_id2sd(p->AID);
  20631. if (tsd == nullptr) {
  20632. clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
  20633. return;
  20634. }
  20635. if (tsd->macro_detect.retry != 0) {
  20636. clif_macro_reporter_status(*sd, MCR_INPROGRESS);
  20637. return;
  20638. }
  20639. if (captcha_db.empty()) {
  20640. clif_macro_reporter_status(*sd, MCR_NO_DATA);
  20641. return;
  20642. }
  20643. pc_macro_reporter_process(*tsd, sd->status.account_id);
  20644. clif_macro_reporter_status(*sd, MCR_MONITORING);
  20645. #endif
  20646. }
  20647. void clif_macro_reporter_status(map_session_data &sd, e_macro_report_status stype) {
  20648. #if PACKETVER >= 20160330
  20649. PACKET_ZC_ACK_APPLY_MACRO_DETECTOR p = {};
  20650. p.PacketType = HEADER_ZC_ACK_APPLY_MACRO_DETECTOR;
  20651. p.status = stype;
  20652. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20653. #endif
  20654. }
  20655. void clif_dynamicnpc_result( map_session_data& sd, e_dynamicnpc_result result ){
  20656. #if PACKETVER_MAIN_NUM >= 20140430 || PACKETVER_RE_NUM >= 20140430 || defined(PACKETVER_ZERO)
  20657. struct PACKET_ZC_DYNAMICNPC_CREATE_RESULT p = {};
  20658. p.PacketType = HEADER_ZC_DYNAMICNPC_CREATE_RESULT;
  20659. p.result = result;
  20660. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20661. #endif
  20662. }
  20663. void clif_partybooking_ask( map_session_data* sd, map_session_data* joining_sd ){
  20664. #if PACKETVER >= 20191204
  20665. struct PACKET_ZC_PARTY_REQ_MASTER_TO_JOIN p = { 0 };
  20666. p.packetType = HEADER_ZC_PARTY_REQ_MASTER_TO_JOIN;
  20667. p.CID = joining_sd->status.char_id;
  20668. p.AID = joining_sd->status.account_id;
  20669. safestrncpy( p.name, joining_sd->status.name, NAME_LENGTH );
  20670. p.x = joining_sd->status.base_level;
  20671. p.y = joining_sd->status.class_;
  20672. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20673. #endif
  20674. }
  20675. void clif_parse_partybooking_join( int fd, map_session_data* sd ){
  20676. #if PACKETVER >= 20191204
  20677. struct PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN* p = (struct PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN*)RFIFOP( fd, 0 );
  20678. // Character is already in a party
  20679. if( sd->status.party_id != 0 ){
  20680. return;
  20681. }
  20682. map_session_data* tsd = map_charid2sd( p->CID );
  20683. // Target player is offline
  20684. if( tsd == nullptr ){
  20685. return;
  20686. }
  20687. if( tsd->status.account_id != p->AID ){
  20688. return;
  20689. }
  20690. struct s_party_booking_requirement requirement;
  20691. if( !party_booking_load( tsd->status.account_id, tsd->status.char_id, &requirement ) ){
  20692. return;
  20693. }
  20694. if( sd->status.base_level < requirement.minimum_level ){
  20695. return;
  20696. }
  20697. if( sd->status.base_level > requirement.maximum_level ){
  20698. return;
  20699. }
  20700. // Already requested to join this party
  20701. if( util::vector_exists( tsd->party_booking_requests, sd->status.char_id ) ){
  20702. return;
  20703. }
  20704. // Store information that the player tried to join the party
  20705. tsd->party_booking_requests.push_back( sd->status.char_id );
  20706. clif_partybooking_ask( tsd, sd );
  20707. #endif
  20708. }
  20709. void clif_partybooking_reply( map_session_data* sd, map_session_data* party_leader_sd, bool accepted ){
  20710. #if PACKETVER >= 20191204
  20711. struct PACKET_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER p = { 0 };
  20712. if( party_leader_sd->status.party_id == 0 ){
  20713. return;
  20714. }
  20715. struct party_data* party = party_search( party_leader_sd->status.party_id );
  20716. if( party == nullptr ){
  20717. return;
  20718. }
  20719. p.packetType = HEADER_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER;
  20720. safestrncpy( p.player_name, party_leader_sd->status.name, NAME_LENGTH );
  20721. safestrncpy( p.party_name, party->party.name, NAME_LENGTH );
  20722. p.AID = party_leader_sd->status.account_id;
  20723. p.refused = !accepted;
  20724. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20725. #endif
  20726. }
  20727. void clif_parse_partybooking_reply( int fd, map_session_data* sd ){
  20728. #if PACKETVER >= 20191204
  20729. struct PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN* p = (struct PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN*)RFIFOP( fd, 0 );
  20730. map_session_data* tsd = map_charid2sd( p->CID );
  20731. // Target player is offline
  20732. if( tsd == nullptr ){
  20733. return;
  20734. }
  20735. if( tsd->status.account_id != p->AID ){
  20736. return;
  20737. }
  20738. // Check if the player even requested to join the party
  20739. if( !util::vector_exists( sd->party_booking_requests, p->CID ) ){
  20740. return;
  20741. }
  20742. util::vector_erase_if_exists( sd->party_booking_requests, p->CID );
  20743. // Only party leaders can reply
  20744. if( !party_isleader( sd ) ){
  20745. return;
  20746. }
  20747. if( p->accept ){
  20748. party_join( tsd, sd->status.party_id );
  20749. }
  20750. clif_partybooking_reply( tsd, sd, p->accept );
  20751. #endif
  20752. }
  20753. void clif_parse_reset_skill( int fd, map_session_data* sd ){
  20754. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220203
  20755. PACKET_CZ_RESET_SKILL* p = (PACKET_CZ_RESET_SKILL*)RFIFOP( fd, 0 );
  20756. #endif
  20757. }
  20758. void clif_set_dialog_align(map_session_data& sd, int npcid, e_say_dialog_align align)
  20759. {
  20760. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20761. PACKET_ZC_DIALOG_TEXT_ALIGN p = {};
  20762. p.PacketType = HEADER_ZC_DIALOG_TEXT_ALIGN;
  20763. p.align = align;
  20764. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20765. #endif // PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20766. }
  20767. void clif_set_npc_window_size(map_session_data& sd, int width, int height)
  20768. {
  20769. #if PACKETVER_MAIN_NUM >= 20220504
  20770. PACKET_ZC_DIALOG_WINDOW_SIZE p = {};
  20771. p.PacketType = HEADER_ZC_DIALOG_WINDOW_SIZE;
  20772. p.width = width;
  20773. p.height = height;
  20774. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20775. #endif // PACKETVER_MAIN_NUM >= 20220504
  20776. }
  20777. void clif_set_npc_window_pos(map_session_data& sd, int x, int y)
  20778. {
  20779. #if PACKETVER_MAIN_NUM >= 20220504
  20780. PACKET_ZC_DIALOG_WINDOW_POS p = {};
  20781. p.PacketType = HEADER_ZC_DIALOG_WINDOW_POS;
  20782. p.x = x;
  20783. p.y = y;
  20784. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20785. #endif // PACKETVER_MAIN_NUM >= 20220504
  20786. }
  20787. void clif_set_npc_window_pos_percent(map_session_data& sd, int x, int y)
  20788. {
  20789. #if PACKETVER_MAIN_NUM >= 20220504
  20790. PACKET_ZC_DIALOG_WINDOW_POS2 p = {};
  20791. p.PacketType = HEADER_ZC_DIALOG_WINDOW_POS2;
  20792. p.x = x;
  20793. p.y = y;
  20794. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20795. #endif // PACKETVER_MAIN_NUM >= 20220504
  20796. }
  20797. /*==========================================
  20798. * Main client packet processing function
  20799. *------------------------------------------*/
  20800. static int clif_parse(int fd)
  20801. {
  20802. int cmd, packet_len;
  20803. TBL_PC* sd;
  20804. int pnum;
  20805. #ifdef PACKET_OBFUSCATION
  20806. int cmd2;
  20807. #endif
  20808. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  20809. // Note: "click masters" can do 80+ clicks in 10 seconds
  20810. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS] -- This actually aids packet spammers, but stuff like /str+ gets slow without it [Ai4rei]
  20811. { // begin main client packet processing loop
  20812. sd = (TBL_PC *)session[fd]->session_data;
  20813. if (session[fd]->flag.eof) {
  20814. if (sd) {
  20815. if (sd->state.autotrade) {
  20816. //Disassociate character from the socket connection.
  20817. session[fd]->session_data = NULL;
  20818. sd->fd = 0;
  20819. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  20820. } else
  20821. if (sd->state.active) {
  20822. // Player logout display [Valaris]
  20823. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  20824. clif_quitsave(fd, sd);
  20825. } else {
  20826. //Unusual logout (during log on/off/map-changer procedure)
  20827. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  20828. map_quit(sd);
  20829. }
  20830. } else {
  20831. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  20832. }
  20833. do_close(fd);
  20834. return 0;
  20835. }
  20836. if (RFIFOREST(fd) < 2)
  20837. return 0;
  20838. cmd = RFIFOW(fd, 0);
  20839. #ifdef PACKET_OBFUSCATION
  20840. // Check if it is a player that tries to connect to the map server.
  20841. if( sd ){
  20842. // Decrypt the current packet ID with the last key stored in the session.
  20843. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  20844. }else{
  20845. // Store the original value for checking
  20846. cmd2 = cmd;
  20847. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  20848. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20849. }
  20850. #endif
  20851. // filter out invalid / unsupported packets
  20852. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  20853. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  20854. #ifdef DUMP_INVALID_PACKET
  20855. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20856. #endif
  20857. #ifdef PACKET_OBFUSCATION_WARN
  20858. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  20859. if( !sd ){
  20860. #ifdef PACKET_OBFUSCATION
  20861. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  20862. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  20863. }
  20864. #else
  20865. // Try to use the initial keys for the decryption of the packet ID.
  20866. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20867. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  20868. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  20869. }
  20870. #endif
  20871. }
  20872. #endif
  20873. set_eof(fd);
  20874. return 0;
  20875. }
  20876. // determine real packet length
  20877. packet_len = packet_db[cmd].len;
  20878. if (packet_len == -1) { // variable-length packet
  20879. if (RFIFOREST(fd) < 4)
  20880. return 0;
  20881. packet_len = RFIFOW(fd,2);
  20882. if (packet_len < 4 || packet_len > 32768) {
  20883. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  20884. #ifdef DUMP_INVALID_PACKET
  20885. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20886. #endif
  20887. set_eof(fd);
  20888. return 0;
  20889. }
  20890. }
  20891. if ((int)RFIFOREST(fd) < packet_len){
  20892. ShowWarning( "clif_parse: Received packet 0x%04x with expected packet length %d, but only %d bytes remaining, disconnecting session #%d.\n", cmd, packet_len, RFIFOREST( fd ), fd );
  20893. #ifdef DUMP_INVALID_PACKET
  20894. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  20895. #endif
  20896. set_eof( fd );
  20897. return 0; // not enough data received to form the packet
  20898. }
  20899. #ifdef PACKET_OBFUSCATION
  20900. RFIFOW(fd, 0) = cmd;
  20901. if (sd)
  20902. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  20903. #endif
  20904. if( packet_db[cmd].func == clif_parse_debug )
  20905. packet_db[cmd].func(fd, sd);
  20906. else if( packet_db[cmd].func != NULL ) {
  20907. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  20908. ; //Only valid packet when there is no session
  20909. else
  20910. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  20911. ; //Only valid packet when player is not on a map
  20912. else
  20913. packet_db[cmd].func(fd, sd);
  20914. }
  20915. #ifdef DUMP_UNKNOWN_PACKET
  20916. else DumpUnknown(fd,sd,cmd,packet_len);
  20917. #endif
  20918. RFIFOSKIP(fd, packet_len);
  20919. }; // main loop end
  20920. return 0;
  20921. }
  20922. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, map_session_data *), ... ){
  20923. va_list argp;
  20924. int i;
  20925. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  20926. return;
  20927. packet_db[cmd].len = length;
  20928. packet_db[cmd].func = func;
  20929. va_start(argp, func);
  20930. for( i = 0; i < MAX_PACKET_POS; i++ ){
  20931. int offset = va_arg(argp, int);
  20932. if( offset == 0 ){
  20933. break;
  20934. }
  20935. packet_db[cmd].pos[i] = offset;
  20936. }
  20937. if( i == MAX_PACKET_POS ){
  20938. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  20939. }
  20940. va_end(argp);
  20941. }
  20942. /*==========================================
  20943. * Reads packets and setups its array reference
  20944. *------------------------------------------*/
  20945. void packetdb_readdb(){
  20946. memset(packet_db,0,sizeof(packet_db));
  20947. #include "clif_packetdb.hpp"
  20948. #include "clif_shuffle.hpp"
  20949. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  20950. #ifdef PACKET_OBFUSCATION
  20951. ShowStatus("Packet Obfuscation: " CL_GREEN "Enabled" CL_RESET ". Keys: " CL_WHITE "0x%08X, 0x%08X, 0x%08X" CL_RESET "\n", clif_cryptKey[0], clif_cryptKey[1], clif_cryptKey[2]);
  20952. #else
  20953. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  20954. #endif
  20955. }
  20956. /*==========================================
  20957. *
  20958. *------------------------------------------*/
  20959. void do_init_clif(void) {
  20960. const int colors[COLOR_MAX] = {
  20961. 0x00FF00, // COLOR_DEFAULT
  20962. 0xFF0000, // COLOR_RED
  20963. 0xFFFFFF, // COLOR_WHITE
  20964. 0xFFFF00, // COLOR_YELLOW
  20965. 0x00FFFF, // COLOR_CYAN
  20966. 0xB5FFB5, // COLOR_LIGHT_GREEN
  20967. 0xFFFF63, // COLOR_LIGHT_YELLOW
  20968. };
  20969. /**
  20970. * Setup Color Table (saves unnecessary load of strtoul on every call)
  20971. **/
  20972. for( int i = 0; i < COLOR_MAX; i++ ){
  20973. color_table[i] = ( colors[i] & 0x0000FF ) << 16 | ( colors[i] & 0x00FF00 ) | ( colors[i] & 0xFF0000 ) >> 16; //RGB to BGR
  20974. }
  20975. packetdb_readdb();
  20976. set_defaultparse(clif_parse);
  20977. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  20978. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  20979. exit(EXIT_FAILURE);
  20980. }
  20981. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  20982. add_timer_func_list(clif_delayquit, "clif_delayquit");
  20983. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  20984. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  20985. if( battle_config.ping_timer_interval > 0 ){
  20986. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  20987. }
  20988. #endif
  20989. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  20990. }
  20991. void do_final_clif(void) {
  20992. ers_destroy(delay_clearunit_ers);
  20993. }