clif.cpp 755 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829
  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 <cstdarg>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <ctime>
  10. #include <unordered_set>
  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 "unit.hpp"
  56. #include "vending.hpp"
  57. using namespace rathena;
  58. static inline uint32 client_tick( t_tick tick ){
  59. return (uint32)tick;
  60. }
  61. #if PACKETVER >= 20170830
  62. static inline int64 client_exp(t_exp exp) {
  63. return (int64)u64min(exp, MAX_EXP);
  64. }
  65. #else
  66. static inline int32 client_exp(t_exp exp) {
  67. return (int32)u64min(exp, MAX_EXP);
  68. }
  69. #endif
  70. /* for clif_clearunit_delayed */
  71. static struct eri *delay_clearunit_ers;
  72. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  73. unsigned long color_table[COLOR_MAX];
  74. #include "clif_obfuscation.hpp"
  75. static bool clif_session_isValid(map_session_data *sd);
  76. static void clif_loadConfirm( map_session_data *sd );
  77. static void clif_favorite_item( map_session_data& sd, uint16 index );
  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 int32 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. int32 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, uint16 pos, int16 x, int16 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, uint16 pos, int16 x0, int16 y0, int16 x1, int16 y1, uint8 sx0, uint8 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(int32 fd, uint16 pos, int16 x, int16 y, unsigned char dir) {
  166. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  167. }
  168. static inline void RBUFPOS(const uint8* p, uint16 pos, int16* x, int16* y, unsigned char* dir) {
  169. p += pos;
  170. if( x ) {
  171. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  172. }
  173. if( y ) {
  174. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  175. }
  176. if( dir ) {
  177. dir[0] = ( p[2] & 0x0f );
  178. }
  179. }
  180. static inline void RBUFPOS2(const uint8* p, uint16 pos, int16* x0, int16* y0, int16* x1, int16* y1, unsigned char* sx0, unsigned char* sy0) {
  181. p += pos;
  182. if( x0 ) {
  183. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  184. }
  185. if( y0 ) {
  186. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  187. }
  188. if( x1 ) {
  189. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  190. }
  191. if( y1 ) {
  192. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  193. }
  194. if( sx0 ) {
  195. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  196. }
  197. if( sy0 ) {
  198. sy0[0] = ( p[5] & 0x0f ) >> 0;
  199. }
  200. }
  201. static inline void RFIFOPOS(int32 fd, uint16 pos, int16* x, int16* y, unsigned char* dir) {
  202. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  203. }
  204. static inline void RFIFOPOS2(int32 fd, uint16 pos, int16* x0, int16* y0, int16* x1, int16* y1, unsigned char* sx0, unsigned char* sy0) {
  205. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  206. }
  207. //To idenfity disguised characters.
  208. static inline bool disguised(struct block_list* bl) {
  209. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  210. }
  211. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  212. static inline uint32 mes_len_check(char* mes, uint32 len, uint32 max) {
  213. if( len > max )
  214. len = max;
  215. mes[len-1] = '\0';
  216. return len;
  217. }
  218. static char map_ip_str[128];
  219. static uint32 map_ip;
  220. static uint32 bind_ip = INADDR_ANY;
  221. static uint16 map_port = 5121;
  222. static bool clif_ally_only = false;
  223. int32 map_fd;
  224. static int32 clif_parse (int32 fd);
  225. /*==========================================
  226. * Ip setting of map-server
  227. *------------------------------------------*/
  228. int32 clif_setip(const char* ip) {
  229. char ip_str[16];
  230. map_ip = host2ip(ip);
  231. if (!map_ip) {
  232. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  233. return 0;
  234. }
  235. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  236. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  237. return 1;
  238. }
  239. void clif_setbindip(const char* ip)
  240. {
  241. bind_ip = host2ip(ip);
  242. if (bind_ip) {
  243. char ip_str[16];
  244. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  245. } else {
  246. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  247. }
  248. }
  249. /*==========================================
  250. * Sets map port to 'port'
  251. * is run from map.cpp upon loading map server configuration
  252. *------------------------------------------*/
  253. void clif_setport(uint16 port)
  254. {
  255. map_port = port;
  256. }
  257. /*==========================================
  258. * Returns map server IP
  259. *------------------------------------------*/
  260. uint32 clif_getip(void)
  261. {
  262. return map_ip;
  263. }
  264. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  265. uint32 clif_refresh_ip(void)
  266. {
  267. uint32 new_ip;
  268. new_ip = host2ip(map_ip_str);
  269. if (new_ip && new_ip != map_ip) {
  270. map_ip = new_ip;
  271. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  272. return map_ip;
  273. }
  274. return 0;
  275. }
  276. /*==========================================
  277. * Returns map port which is set by clif_setport()
  278. *------------------------------------------*/
  279. uint16 clif_getport(void)
  280. {
  281. return map_port;
  282. }
  283. #if PACKETVER >= 20071106
  284. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  285. switch (bl->type) {
  286. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  287. case BL_ITEM: return 0x2; //ITEM_TYPE
  288. case BL_SKILL: return 0x3; //SKILL_TYPE
  289. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  290. case BL_MOB:
  291. if( pcdb_checkid( status_get_viewdata( bl )->class_ ) ){
  292. return 0x0; //PC_TYPE
  293. }else{
  294. switch( ( (mob_data*)bl )->special_state.ai ){
  295. case AI_ABR:
  296. return 0xd; //NPC_ABR_TYPE
  297. case AI_BIONIC:
  298. return 0xe; //NPC_BIONIC_TYPE
  299. default:
  300. return 0x5; //NPC_MOB_TYPE
  301. }
  302. }
  303. case BL_NPC:
  304. // From 2017-07-26 on NPC type units can also use player sprites.
  305. // There is one exception and this is if they are walking.
  306. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  307. #if PACKETVER >= 20170726
  308. if (pcdb_checkid( status_get_viewdata( bl )->class_ ) && walking)
  309. return 0x0;
  310. else if (mobdb_checkid( status_get_viewdata( bl )->class_ )) // FIXME: categorize NPCs able to walk
  311. return 0xC;
  312. else
  313. return 0x6;
  314. #else
  315. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  316. #endif
  317. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  318. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  319. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  320. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  321. default: return 0x1; //NPC_TYPE
  322. }
  323. }
  324. #endif
  325. static bool clif_session_isValid(map_session_data *sd) {
  326. return ( sd != nullptr && session_isActive(sd->fd) );
  327. }
  328. /*==========================================
  329. * sub process of clif_send
  330. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  331. * In order to send area-wise packets, such as:
  332. * - AREA : everyone nearby your area
  333. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  334. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  335. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  336. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  337. *------------------------------------------*/
  338. static int32 clif_send_sub(struct block_list *bl, va_list ap)
  339. {
  340. struct block_list *src_bl;
  341. map_session_data *sd;
  342. unsigned char *buf;
  343. int32 len, type, fd;
  344. nullpo_ret(bl);
  345. nullpo_ret(sd = (map_session_data *)bl);
  346. // Don't send to disconnected clients.
  347. if( !session_isActive( fd = sd->fd ) ){
  348. return 0;
  349. }
  350. buf = va_arg(ap,unsigned char*);
  351. len = va_arg(ap,int32);
  352. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  353. type = va_arg(ap,int32);
  354. switch(type) {
  355. case AREA_WOS:
  356. if (bl == src_bl)
  357. return 0;
  358. break;
  359. case AREA_WOC:
  360. if (sd->chatID || bl == src_bl)
  361. return 0;
  362. break;
  363. case AREA_WOSC:
  364. {
  365. if(src_bl->type == BL_PC) {
  366. map_session_data *ssd = (map_session_data *)src_bl;
  367. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  368. return 0;
  369. }
  370. else if(src_bl->type == BL_NPC) {
  371. struct npc_data *nd = (struct npc_data *)src_bl;
  372. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  373. return 0;
  374. }
  375. }
  376. break;
  377. }
  378. if( src_bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)src_bl ), *sd ) ){
  379. // Do not send anything
  380. return 0;
  381. }
  382. /* unless visible, hold it here */
  383. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  384. !sd->sc.getSCE(SC_INTRAVISION) && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  385. return 0;
  386. WFIFOHEAD(fd, len);
  387. if (WFIFOP(fd,0) == buf) {
  388. ShowError("WARNING: Invalid use of clif_send function\n");
  389. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  390. ShowError(" Please correct your code.\n");
  391. // don't send to not move the pointer of the packet for next sessions in the loop
  392. //WFIFOSET(fd,0);//## TODO is this ok?
  393. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  394. return 0;
  395. }
  396. memcpy(WFIFOP(fd,0), buf, len);
  397. WFIFOSET(fd,len);
  398. return 0;
  399. }
  400. /*==========================================
  401. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  402. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  403. *------------------------------------------*/
  404. int32 clif_send(const void* buf, int32 len, struct block_list* bl, enum send_target type)
  405. {
  406. int32 i;
  407. map_session_data *sd, *tsd;
  408. struct party_data *p = nullptr;
  409. std::shared_ptr<s_battleground_data> bg;
  410. int32 x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  411. struct s_mapiterator* iter;
  412. if( type != ALL_CLIENT )
  413. nullpo_ret(bl);
  414. sd = BL_CAST(BL_PC, bl);
  415. switch(type) {
  416. case ALL_CLIENT: //All player clients.
  417. iter = mapit_getallusers();
  418. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  419. if( session_isActive( fd = tsd->fd ) ){
  420. WFIFOHEAD( fd, len );
  421. memcpy( WFIFOP( fd, 0 ), buf, len );
  422. WFIFOSET( fd, len );
  423. }
  424. }
  425. mapit_free(iter);
  426. break;
  427. case ALL_SAMEMAP: //All players on the same map
  428. iter = mapit_getallusers();
  429. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  430. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  431. WFIFOHEAD( fd, len );
  432. memcpy( WFIFOP( fd, 0 ), buf, len );
  433. WFIFOSET( fd, len );
  434. }
  435. }
  436. mapit_free(iter);
  437. break;
  438. case AREA:
  439. case AREA_WOSC:
  440. if (sd && bl->prev == nullptr) //Otherwise source misses the packet.[Skotlex]
  441. clif_send (buf, len, bl, SELF);
  442. [[fallthrough]];
  443. case AREA_WOC:
  444. case AREA_WOS:
  445. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  446. BL_PC, buf, len, bl, type);
  447. break;
  448. case AREA_CHAT_WOC:
  449. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  450. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  451. break;
  452. case CHAT:
  453. case CHAT_WOS:
  454. {
  455. struct chat_data *cd;
  456. if (sd) {
  457. cd = (struct chat_data*)map_id2bl(sd->chatID);
  458. } else if (bl->type == BL_CHAT) {
  459. cd = (struct chat_data*)bl;
  460. } else break;
  461. if (cd == nullptr)
  462. break;
  463. for(i = 0; i < cd->users; i++) {
  464. if (type == CHAT_WOS && cd->usersd[i] == sd)
  465. continue;
  466. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  467. WFIFOHEAD(fd,len);
  468. memcpy(WFIFOP(fd,0), buf, len);
  469. WFIFOSET(fd,len);
  470. }
  471. }
  472. }
  473. break;
  474. case PARTY_AREA:
  475. case PARTY_AREA_WOS:
  476. x0 = bl->x - AREA_SIZE;
  477. y0 = bl->y - AREA_SIZE;
  478. x1 = bl->x + AREA_SIZE;
  479. y1 = bl->y + AREA_SIZE;
  480. [[fallthrough]];
  481. case PARTY:
  482. case PARTY_WOS:
  483. case PARTY_SAMEMAP:
  484. case PARTY_SAMEMAP_WOS:
  485. if (sd && sd->status.party_id)
  486. p = party_search(sd->status.party_id);
  487. if (p) {
  488. for(i=0;i<MAX_PARTY;i++){
  489. if( (sd = p->data[i].sd) == nullptr )
  490. continue;
  491. if( !session_isActive( fd = sd->fd ) )
  492. continue;
  493. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  494. continue;
  495. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  496. continue;
  497. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  498. continue;
  499. WFIFOHEAD(fd, len);
  500. memcpy(WFIFOP(fd, 0), buf, len);
  501. WFIFOSET(fd, len);
  502. }
  503. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  504. break;
  505. iter = mapit_getallusers();
  506. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  507. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  508. WFIFOHEAD( fd, len );
  509. memcpy( WFIFOP( fd, 0 ), buf, len );
  510. WFIFOSET( tsd->fd, len );
  511. }
  512. }
  513. mapit_free(iter);
  514. }
  515. break;
  516. case DUEL:
  517. case DUEL_WOS:
  518. if (!sd || !sd->duel_group) break; //Invalid usage.
  519. iter = mapit_getallusers();
  520. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  521. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  522. continue;
  523. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  524. WFIFOHEAD( fd, len );
  525. memcpy( WFIFOP( fd, 0 ), buf, len );
  526. WFIFOSET( fd, len );
  527. }
  528. }
  529. mapit_free(iter);
  530. break;
  531. case SELF:
  532. if( clif_session_isValid(sd) ){
  533. fd = sd->fd;
  534. WFIFOHEAD(fd,len);
  535. memcpy(WFIFOP(fd,0), buf, len);
  536. WFIFOSET(fd,len);
  537. }
  538. break;
  539. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  540. case GUILD_AREA:
  541. case GUILD_AREA_WOS:
  542. x0 = bl->x - AREA_SIZE;
  543. y0 = bl->y - AREA_SIZE;
  544. x1 = bl->x + AREA_SIZE;
  545. y1 = bl->y + AREA_SIZE;
  546. [[fallthrough]];
  547. case GUILD_SAMEMAP:
  548. case GUILD_SAMEMAP_WOS:
  549. case GUILD:
  550. case GUILD_WOS:
  551. case GUILD_NOBG: {
  552. if (!sd || !sd->status.guild_id || !sd->guild)
  553. break;
  554. const auto &g = sd->guild->guild;
  555. for(i = 0; i < g.max_member; i++) {
  556. if( (sd = g.member[i].sd) != nullptr ){
  557. if( !session_isActive( fd = sd->fd ) )
  558. continue;
  559. if( type == GUILD_NOBG && sd->bg_id )
  560. continue;
  561. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  562. continue;
  563. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  564. continue;
  565. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  566. continue;
  567. WFIFOHEAD(fd,len);
  568. memcpy(WFIFOP(fd,0), buf, len);
  569. WFIFOSET(fd,len);
  570. }
  571. }
  572. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  573. break;
  574. iter = mapit_getallusers();
  575. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  576. if( tsd->guildspy == g.guild_id && session_isActive( fd = tsd->fd ) ){
  577. WFIFOHEAD( fd, len );
  578. memcpy( WFIFOP( fd, 0 ), buf, len );
  579. WFIFOSET( fd, len );
  580. }
  581. }
  582. mapit_free(iter);
  583. break;
  584. }
  585. case BG_AREA:
  586. case BG_AREA_WOS:
  587. x0 = bl->x - AREA_SIZE;
  588. y0 = bl->y - AREA_SIZE;
  589. x1 = bl->x + AREA_SIZE;
  590. y1 = bl->y + AREA_SIZE;
  591. [[fallthrough]];
  592. case BG_SAMEMAP:
  593. case BG_SAMEMAP_WOS:
  594. case BG:
  595. case BG_WOS:
  596. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  597. {
  598. for (const auto &member : bg->members) {
  599. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  600. continue;
  601. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  602. continue;
  603. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  604. continue;
  605. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  606. continue;
  607. WFIFOHEAD(fd,len);
  608. memcpy(WFIFOP(fd,0), buf, len);
  609. WFIFOSET(fd,len);
  610. }
  611. }
  612. break;
  613. case CLAN:
  614. if( sd && sd->clan ){
  615. struct clan* clan = sd->clan;
  616. for( i = 0; i < clan->max_member; i++ ){
  617. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  618. continue;
  619. }
  620. WFIFOHEAD(fd,len);
  621. memcpy(WFIFOP(fd,0), buf, len);
  622. WFIFOSET(fd,len);
  623. }
  624. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  625. break;
  626. iter = mapit_getallusers();
  627. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  628. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  629. WFIFOHEAD(fd, len);
  630. memcpy(WFIFOP(fd, 0), buf, len);
  631. WFIFOSET(fd, len);
  632. }
  633. }
  634. mapit_free(iter);
  635. }
  636. break;
  637. default:
  638. ShowError("clif_send: Unrecognized type %d\n",type);
  639. return -1;
  640. }
  641. return 0;
  642. }
  643. /// Notifies the client, that it's connection attempt was accepted.
  644. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  645. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  646. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  647. void clif_authok(map_session_data *sd)
  648. {
  649. PACKET_ZC_ACCEPT_ENTER packet{};
  650. packet.packetType = HEADER_ZC_ACCEPT_ENTER;
  651. packet.startTime = client_tick(gettick());
  652. WBUFPOS(packet.posDir, 0, sd->bl.x, sd->bl.y, sd->ud.dir);
  653. packet.xSize = 5; // ignored
  654. packet.ySize = 5; // ignored
  655. #if PACKETVER >= 20080102
  656. packet.font = sd->status.font;
  657. #endif
  658. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  659. packet.sex = sd->status.sex;
  660. #endif
  661. clif_send(&packet, sizeof(packet), &sd->bl, SELF);
  662. }
  663. /// Notifies the client, that it's connection attempt was refused.
  664. /// 0074 <error code>.B (ZC_REFUSE_ENTER)
  665. /// error code:
  666. /// 0 = client type mismatch
  667. /// 1 = ID mismatch
  668. /// 2 = mobile - out of available time
  669. /// 3 = mobile - already logged in
  670. /// 4 = mobile - waiting state
  671. void clif_authrefuse(int32 fd, uint8 error_code)
  672. {
  673. PACKET_ZC_REFUSE_ENTER packet{};
  674. packet.packetType = HEADER_ZC_REFUSE_ENTER;
  675. packet.errorCode = error_code;
  676. socket_send<PACKET_ZC_REFUSE_ENTER>(fd, packet);
  677. }
  678. /// Notifies the client of a ban or forced disconnect.
  679. /// 0081 <error code>.B (SC_NOTIFY_BAN)
  680. /// error code:
  681. /// 0 = BAN_UNFAIR
  682. /// 1 = server closed -> MsgStringTable[4]
  683. /// 2 = ID already logged in -> MsgStringTable[5]
  684. /// 3 = timeout/too much lag -> MsgStringTable[241]
  685. /// 4 = server full -> MsgStringTable[264]
  686. /// 5 = underaged -> MsgStringTable[305]
  687. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  688. /// 9 = too many connections from this ip -> MsgStringTable[529]
  689. /// 10 = out of available time paid for -> MsgStringTable[530]
  690. /// 11 = BAN_PAY_SUSPEND
  691. /// 12 = BAN_PAY_CHANGE
  692. /// 13 = BAN_PAY_WRONGIP
  693. /// 14 = BAN_PAY_PNGAMEROOM
  694. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  695. /// 16 = BAN_JAPAN_REFUSE1
  696. /// 17 = BAN_JAPAN_REFUSE2
  697. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  698. /// 100 = BAN_PC_IP_UNFAIR
  699. /// 101 = BAN_PC_IP_COUNT_ALL
  700. /// 102 = BAN_PC_IP_COUNT
  701. /// 103 = BAN_GRAVITY_MEM_AGREE
  702. /// 104 = BAN_GAME_MEM_AGREE
  703. /// 105 = BAN_HAN_VALID
  704. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  705. /// 107 = BAN_OVER_CHARACTER_LIST
  706. /// 108 = BAN_IP_BLOCK
  707. /// 109 = BAN_INVALID_PWD_CNT
  708. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  709. /// ? = disconnected -> MsgStringTable[3]
  710. void clif_authfail_fd(int32 fd, int32 type)
  711. {
  712. if (!session_isValid(fd) || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  713. return;
  714. PACKET_SC_NOTIFY_BAN packet{};
  715. packet.packetType = HEADER_SC_NOTIFY_BAN;
  716. packet.errorCode = static_cast<uint8>(type);
  717. socket_send<PACKET_SC_NOTIFY_BAN>(fd, packet);
  718. set_eof(fd);
  719. }
  720. /// Notifies the client, whether it can disconnect and change servers.
  721. /// 00b3 <type>.B (ZC_RESTART_ACK)
  722. /// type:
  723. /// 1 = disconnect, char-select
  724. /// ? = nothing
  725. void clif_charselectok(int32 id, uint8 ok)
  726. {
  727. map_session_data* sd = map_id2sd(id);
  728. if (sd == nullptr)
  729. return;
  730. PACKET_ZC_RESTART_ACK packet{};
  731. packet.packetType = HEADER_ZC_RESTART_ACK;
  732. packet.type = ok;
  733. clif_send( &packet, sizeof( packet ), &sd->bl, SELF );
  734. }
  735. /// Makes an item appear on the ground.
  736. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  737. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  738. /// 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)
  739. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  740. nullpo_retv(fitem);
  741. if( fitem->item.nameid == 0 ){
  742. return;
  743. }
  744. struct packet_dropflooritem p;
  745. p.PacketType = dropflooritemType;
  746. p.ITAID = fitem->bl.id;
  747. p.ITID = client_nameid( fitem->item.nameid );
  748. #if PACKETVER >= 20130000 /* not sure date */
  749. p.type = itemtype( fitem->item.nameid );
  750. #endif
  751. p.IsIdentified = fitem->item.identify ? 1 : 0;
  752. p.xPos = fitem->bl.x;
  753. p.yPos = fitem->bl.y;
  754. p.subX = fitem->subx;
  755. p.subY = fitem->suby;
  756. p.count = fitem->item.amount;
  757. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  758. if( canShowEffect ){
  759. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  760. if( dropEffect > 0 ){
  761. p.showdropeffect = 1;
  762. p.dropeffectmode = dropEffect - 1;
  763. }else if (battle_config.rndopt_drop_pillar != 0){
  764. uint8 optionCount = 0;
  765. for (uint8 i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  766. if (fitem->item.option[i].id != 0) {
  767. optionCount++;
  768. }
  769. }
  770. if (optionCount > 0) {
  771. p.showdropeffect = 1;
  772. if (optionCount == 1)
  773. p.dropeffectmode = DROPEFFECT_BLUE_PILLAR - 1;
  774. else if (optionCount == 2)
  775. p.dropeffectmode = DROPEFFECT_YELLOW_PILLAR - 1;
  776. else
  777. p.dropeffectmode = DROPEFFECT_PURPLE_PILLAR - 1;
  778. } else {
  779. p.showdropeffect = 0;
  780. p.dropeffectmode = DROPEFFECT_NONE;
  781. }
  782. } else {
  783. p.showdropeffect = 0;
  784. p.dropeffectmode = DROPEFFECT_NONE;
  785. }
  786. }else{
  787. p.showdropeffect = 0;
  788. p.dropeffectmode = DROPEFFECT_NONE;
  789. }
  790. #endif
  791. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  792. }
  793. /// Makes an item disappear from the ground.
  794. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  795. void clif_clearflooritem( flooritem_data& fitem, map_session_data* tsd ){
  796. PACKET_ZC_ITEM_DISAPPEAR packet{};
  797. packet.packetType = HEADER_ZC_ITEM_DISAPPEAR;
  798. packet.itemAid = fitem.bl.id;
  799. if( tsd == nullptr ){
  800. clif_send(&packet, sizeof(PACKET_ZC_ITEM_DISAPPEAR), &fitem.bl, AREA);
  801. } else {
  802. clif_send(&packet, sizeof(PACKET_ZC_ITEM_DISAPPEAR), &tsd->bl, SELF );
  803. }
  804. }
  805. /// Makes a unit (char, npc, mob, homun) disappear to one client.
  806. /// 0080 <id>.L <type>.B (ZC_NOTIFY_VANISH)
  807. /// type:
  808. /// 0 = out of sight
  809. /// 1 = died
  810. /// 2 = logged out
  811. /// 3 = teleport
  812. /// 4 = trickdead
  813. void clif_clearunit_single( uint32 GID, clr_type type, map_session_data& tsd ){
  814. PACKET_ZC_NOTIFY_VANISH packet{};
  815. packet.packetType = HEADER_ZC_NOTIFY_VANISH;
  816. packet.gid = GID;
  817. packet.type = static_cast<decltype(packet.type)>(type);
  818. clif_send( &packet, sizeof( packet ), &tsd.bl, SELF );
  819. }
  820. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area.
  821. /// 0080 <id>.L <type>.B (ZC_NOTIFY_VANISH)
  822. /// type:
  823. /// 0 = out of sight
  824. /// 1 = died
  825. /// 2 = logged out
  826. /// 3 = teleport
  827. /// 4 = trickdead
  828. void clif_clearunit_area( block_list& bl, clr_type type ){
  829. PACKET_ZC_NOTIFY_VANISH packet{};
  830. packet.packetType = HEADER_ZC_NOTIFY_VANISH;
  831. packet.gid = bl.id;
  832. packet.type = static_cast<uint8>(type);
  833. clif_send(&packet, sizeof(PACKET_ZC_NOTIFY_VANISH), &bl, type == CLR_DEAD ? AREA : AREA_WOS);
  834. if(disguised(&bl)) {
  835. packet.gid = disguised_bl_id( bl.id );
  836. clif_send(&packet, sizeof(PACKET_ZC_NOTIFY_VANISH), &bl, SELF);
  837. }
  838. }
  839. /// Used to make monsters with player-sprites disappear after dying
  840. /// like normal monsters, because the client does not remove those
  841. /// automatically.
  842. static TIMER_FUNC(clif_clearunit_delayed_sub){
  843. struct block_list *bl = (struct block_list *)data;
  844. if( bl != nullptr ){
  845. clif_clearunit_area( *bl, (clr_type)id );
  846. ers_free( delay_clearunit_ers, bl );
  847. }
  848. return 0;
  849. }
  850. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  851. {
  852. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  853. tbl->next = nullptr;
  854. tbl->prev = nullptr;
  855. tbl->id = bl->id;
  856. tbl->m = bl->m;
  857. tbl->x = bl->x;
  858. tbl->y = bl->y;
  859. tbl->type = BL_NUL;
  860. add_timer(tick, clif_clearunit_delayed_sub, (int32)type, (intptr_t)tbl);
  861. }
  862. void clif_get_weapon_view(map_session_data* sd, t_itemid *rhand, t_itemid *lhand)
  863. {
  864. if(sd->sc.option&OPTION_COSTUME)
  865. {
  866. *rhand = *lhand = 0;
  867. return;
  868. }
  869. #if PACKETVER < 4
  870. *rhand = sd->status.weapon;
  871. *lhand = sd->status.shield;
  872. #else
  873. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  874. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  875. {
  876. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  877. if (id->view_id > 0)
  878. *rhand = id->view_id;
  879. else
  880. *rhand = id->nameid;
  881. } else
  882. *rhand = 0;
  883. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  884. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  885. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  886. {
  887. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  888. if (id->view_id > 0)
  889. *lhand = id->view_id;
  890. else
  891. *lhand = id->nameid;
  892. } else
  893. *lhand = 0;
  894. #endif
  895. }
  896. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  897. static int32 clif_setlevel_sub(int32 lv) {
  898. if( lv < battle_config.max_lv ) {
  899. ;
  900. } else if( lv < battle_config.aura_lv ) {
  901. lv = battle_config.max_lv - 1;
  902. } else {
  903. lv = battle_config.max_lv;
  904. }
  905. return lv;
  906. }
  907. static int32 clif_setlevel(struct block_list* bl) {
  908. int32 lv = status_get_lv(bl);
  909. if( battle_config.client_limit_unit_lv&bl->type )
  910. return clif_setlevel_sub(lv);
  911. switch( bl->type ) {
  912. case BL_NPC:
  913. case BL_PET:
  914. // npcs and pets do not have level
  915. return 0;
  916. }
  917. return lv;
  918. }
  919. /*==========================================
  920. * Prepares 'unit standing/spawning' packet
  921. *------------------------------------------*/
  922. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  923. nullpo_retv( bl );
  924. map_session_data* sd = BL_CAST( BL_PC, bl );
  925. status_change* sc = status_get_sc( bl );
  926. struct view_data* vd = status_get_viewdata( bl );
  927. int32 g_id = status_get_guild_id( bl );
  928. #if PACKETVER < 20091103
  929. if( !pcdb_checkid( vd->class_ ) ){
  930. struct packet_idle_unit2 p;
  931. p.PacketType = idle_unit2Type;
  932. #if PACKETVER >= 20071106
  933. p.objecttype = clif_bl_type( bl, walking );
  934. #endif
  935. p.GID = bl->id;
  936. p.speed = status_get_speed( bl );
  937. p.bodyState = ( sc ) ? sc->opt1 : 0;
  938. p.healthState = ( sc ) ? sc->opt2 : 0;
  939. p.effectState = ( sc ) ? sc->option : 0;
  940. p.job = vd->class_;
  941. p.head = vd->hair_style;
  942. p.weapon = vd->weapon;
  943. p.accessory = vd->head_bottom;
  944. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  945. // The hell, why flags work like this?
  946. p.shield = status_get_emblem_id( bl );
  947. p.accessory2 = GetWord( g_id, 1 );
  948. p.accessory3 = GetWord( g_id, 0 );
  949. }else{
  950. p.shield = vd->shield;
  951. p.accessory2 = vd->head_top;
  952. p.accessory3 = vd->head_mid;
  953. }
  954. p.headpalette = vd->hair_color;
  955. p.bodypalette = vd->cloth_color;
  956. p.headDir = ( sd )? sd->head_dir : 0;
  957. p.GUID = g_id;
  958. p.GEmblemVer = status_get_emblem_id( bl );
  959. p.honor = ( sd ) ? sd->status.manner : 0;
  960. p.virtue = ( sc ) ? sc->opt3 : 0;
  961. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  962. p.sex = vd->sex;
  963. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  964. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  965. p.state = vd->dead_sit;
  966. p.clevel = clif_setlevel( bl );
  967. clif_send( &p, sizeof( p ), tbl, target );
  968. return;
  969. }
  970. #endif
  971. struct packet_idle_unit p;
  972. p.PacketType = idle_unitType;
  973. #if PACKETVER >= 20091103
  974. p.PacketLength = sizeof(p);
  975. p.objecttype = clif_bl_type( bl, walking );
  976. #endif
  977. #if PACKETVER >= 20131223
  978. p.AID = bl->id;
  979. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  980. #else
  981. p.GID = bl->id;
  982. #endif
  983. p.speed = status_get_speed(bl);
  984. p.bodyState = (sc) ? sc->opt1 : 0;
  985. p.healthState = (sc) ? sc->opt2 : 0;
  986. // npc option changed?
  987. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  988. map_session_data* sd = (map_session_data*)tbl;
  989. struct npc_data* nd = (struct npc_data*)bl;
  990. int32 option = (sc) ? sc->option : 0;
  991. if( !nd->vd.dead_sit ){
  992. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  993. option ^= OPTION_CLOAK;
  994. }
  995. }
  996. p.effectState = option;
  997. }else{
  998. p.effectState = (sc) ? sc->option : 0;
  999. }
  1000. p.job = vd->class_;
  1001. p.head = vd->hair_style;
  1002. p.weapon = vd->weapon;
  1003. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1004. p.shield = vd->shield;
  1005. #endif
  1006. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1007. // The hell, why flags work like this?
  1008. p.accessory = status_get_emblem_id( bl );
  1009. p.accessory2 = GetWord( g_id, 1 );
  1010. p.accessory3 = GetWord( g_id, 0 );
  1011. }else{
  1012. p.accessory = vd->head_bottom;
  1013. p.accessory2 = vd->head_top;
  1014. p.accessory3 = vd->head_mid;
  1015. }
  1016. p.headpalette = vd->hair_color;
  1017. p.bodypalette = vd->cloth_color;
  1018. p.headDir = (sd)? sd->head_dir : 0;
  1019. #if PACKETVER >= 20101124
  1020. p.robe = vd->robe;
  1021. #endif
  1022. p.GUID = g_id;
  1023. p.GEmblemVer = status_get_emblem_id( bl );
  1024. p.honor = (sd) ? sd->status.manner : 0;
  1025. p.virtue = (sc) ? sc->opt3 : 0;
  1026. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1027. p.sex = vd->sex;
  1028. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1029. p.xSize = p.ySize = (sd) ? 5 : 0;
  1030. p.state = vd->dead_sit;
  1031. p.clevel = clif_setlevel( bl );
  1032. #if PACKETVER >= 20080102
  1033. p.font = (sd) ? sd->status.font : 0;
  1034. #endif
  1035. #if PACKETVER >= 20120221
  1036. 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 ) ) ){
  1037. p.maxHP = status_get_max_hp(bl);
  1038. p.HP = status_get_hp(bl);
  1039. }else{
  1040. p.maxHP = -1;
  1041. p.HP = -1;
  1042. }
  1043. if( bl->type == BL_MOB ){
  1044. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1045. }else if( bl->type == BL_PET ){
  1046. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1047. }else{
  1048. p.isBoss = BOSSTYPE_NONE;
  1049. }
  1050. #endif
  1051. #if PACKETVER >= 20150513
  1052. p.body = vd->body_style;
  1053. #endif
  1054. /* Might be earlier, this is when the named item bug began */
  1055. #if PACKETVER >= 20131223
  1056. safestrncpy(p.name, status_get_name( *bl ), NAME_LENGTH);
  1057. #endif
  1058. clif_send( &p, sizeof( p ), tbl, target );
  1059. // if disguised, send to self
  1060. if( disguised( bl ) ){
  1061. #if PACKETVER >= 20091103
  1062. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1063. #if PACKETVER >= 20131223
  1064. p.AID = disguised_bl_id( bl->id );
  1065. #else
  1066. p.GID = disguised_bl_id( bl->id );
  1067. #endif
  1068. #else
  1069. p.GID = disguised_bl_id( bl->id );
  1070. #endif
  1071. clif_send(&p, sizeof(p), bl, SELF);
  1072. }
  1073. }
  1074. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1075. nullpo_retv( bl );
  1076. map_session_data* sd = BL_CAST( BL_PC, bl );
  1077. status_change* sc = status_get_sc( bl );
  1078. struct view_data* vd = status_get_viewdata( bl );
  1079. int32 g_id = status_get_guild_id( bl );
  1080. #if PACKETVER < 20091103
  1081. if( !pcdb_checkid( vd->class_ ) ){
  1082. struct packet_spawn_unit2 p;
  1083. p.PacketType = spawn_unit2Type;
  1084. #if PACKETVER >= 20071106
  1085. p.objecttype = clif_bl_type( bl, false );
  1086. #endif
  1087. p.GID = bl->id;
  1088. p.speed = status_get_speed( bl );
  1089. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1090. p.healthState = ( sc ) ? sc->opt2 : 0;
  1091. p.effectState = ( sc ) ? sc->option : 0;
  1092. p.head = vd->hair_style;
  1093. p.weapon = vd->weapon;
  1094. p.accessory = vd->head_bottom;
  1095. p.job = vd->class_;
  1096. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1097. // The hell, why flags work like this?
  1098. p.shield = status_get_emblem_id( bl );
  1099. p.accessory2 = GetWord( g_id, 1 );
  1100. p.accessory3 = GetWord( g_id, 0 );
  1101. }else{
  1102. p.shield = vd->shield;
  1103. p.accessory2 = vd->head_top;
  1104. p.accessory3 = vd->head_mid;
  1105. }
  1106. p.headpalette = vd->hair_color;
  1107. p.bodypalette = vd->cloth_color;
  1108. p.headDir = ( sd ) ? sd->head_dir : 0;
  1109. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1110. p.sex = vd->sex;
  1111. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1112. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1113. clif_send( &p, sizeof( p ), bl, target );
  1114. return;
  1115. }
  1116. #endif
  1117. struct packet_spawn_unit p;
  1118. p.PacketType = spawn_unitType;
  1119. #if PACKETVER >= 20091103
  1120. p.PacketLength = sizeof(p);
  1121. p.objecttype = clif_bl_type( bl, false );
  1122. #endif
  1123. #if PACKETVER >= 20131223
  1124. p.AID = bl->id;
  1125. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1126. #else
  1127. p.GID = bl->id;
  1128. #endif
  1129. p.speed = status_get_speed( bl );
  1130. p.bodyState = (sc) ? sc->opt1 : 0;
  1131. p.healthState = (sc) ? sc->opt2 : 0;
  1132. p.effectState = (sc) ? sc->option : 0;
  1133. p.job = vd->class_;
  1134. p.head = vd->hair_style;
  1135. p.weapon = vd->weapon;
  1136. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1137. p.shield = vd->shield;
  1138. #endif
  1139. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1140. // The hell, why flags work like this?
  1141. p.accessory = status_get_emblem_id( bl );
  1142. p.accessory2 = GetWord( g_id, 1 );
  1143. p.accessory3 = GetWord( g_id, 0 );
  1144. }else{
  1145. p.accessory = vd->head_bottom;
  1146. p.accessory2 = vd->head_top;
  1147. p.accessory3 = vd->head_mid;
  1148. }
  1149. p.headpalette = vd->hair_color;
  1150. p.bodypalette = vd->cloth_color;
  1151. p.headDir = (sd)? sd->head_dir : 0;
  1152. #if PACKETVER >= 20101124
  1153. p.robe = vd->robe;
  1154. #endif
  1155. p.GUID = g_id;
  1156. p.GEmblemVer = status_get_emblem_id( bl );
  1157. p.honor = (sd) ? sd->status.manner : 0;
  1158. p.virtue = (sc) ? sc->opt3 : 0;
  1159. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1160. p.sex = vd->sex;
  1161. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1162. p.xSize = p.ySize = (sd) ? 5 : 0;
  1163. p.clevel = clif_setlevel( bl );
  1164. #if PACKETVER >= 20080102
  1165. p.font = (sd) ? sd->status.font : 0;
  1166. #endif
  1167. #if PACKETVER >= 20120221
  1168. 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 ) ) ){
  1169. p.maxHP = status_get_max_hp( bl );
  1170. p.HP = status_get_hp( bl );
  1171. }else{
  1172. p.maxHP = -1;
  1173. p.HP = -1;
  1174. }
  1175. if( bl->type == BL_MOB ){
  1176. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1177. }else if( bl->type == BL_PET ){
  1178. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1179. }else{
  1180. p.isBoss = BOSSTYPE_NONE;
  1181. }
  1182. #endif
  1183. #if PACKETVER >= 20150513
  1184. p.body = vd->body_style;
  1185. #endif
  1186. /* Might be earlier, this is when the named item bug began */
  1187. #if PACKETVER >= 20131223
  1188. safestrncpy( p.name, status_get_name( *bl ), NAME_LENGTH );
  1189. #endif
  1190. if( disguised( bl ) ){
  1191. nullpo_retv( sd );
  1192. if( sd->status.class_ != sd->disguise ){
  1193. clif_send( &p, sizeof( p ), bl, target );
  1194. }
  1195. #if PACKETVER >= 20091103
  1196. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1197. #if PACKETVER >= 20131223
  1198. p.AID = disguised_bl_id( bl->id );
  1199. #else
  1200. p.GID = disguised_bl_id( bl->id );
  1201. #endif
  1202. #else
  1203. p.GID = disguised_bl_id( bl->id );
  1204. #endif
  1205. clif_send( &p, sizeof( p ), bl, SELF );
  1206. }else{
  1207. clif_send( &p, sizeof( p ), bl, target );
  1208. }
  1209. }
  1210. /*==========================================
  1211. * Prepares 'unit walking' packet
  1212. *------------------------------------------*/
  1213. static void clif_set_unit_walking( struct block_list& bl, map_session_data* tsd, struct unit_data& ud, enum send_target target ){
  1214. struct packet_unit_walking p;
  1215. p.PacketType = unit_walkingType;
  1216. #if PACKETVER >= 20091103
  1217. p.PacketLength = sizeof(p);
  1218. #endif
  1219. #if PACKETVER >= 20071106
  1220. p.objecttype = clif_bl_type( &bl, true );
  1221. #endif
  1222. map_session_data* sd = BL_CAST(BL_PC, &bl);
  1223. #if PACKETVER >= 20131223
  1224. p.AID = bl.id;
  1225. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1226. #else
  1227. p.GID = bl.id;
  1228. #endif
  1229. p.speed = status_get_speed( &bl );
  1230. status_change* sc = status_get_sc( &bl );
  1231. p.bodyState = (sc) ? sc->opt1 : 0;
  1232. p.healthState = (sc) ? sc->opt2 : 0;
  1233. p.effectState = (sc) ? sc->option : 0;
  1234. struct view_data* vd = status_get_viewdata( &bl );
  1235. p.job = vd->class_;
  1236. p.head = vd->hair_style;
  1237. p.weapon = vd->weapon;
  1238. p.accessory = vd->head_bottom;
  1239. p.moveStartTime = client_tick(gettick());
  1240. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1241. p.shield = vd->shield;
  1242. #endif
  1243. p.accessory2 = vd->head_top;
  1244. p.accessory3 = vd->head_mid;
  1245. p.headpalette = vd->hair_color;
  1246. p.bodypalette = vd->cloth_color;
  1247. p.headDir = (sd) ? sd->head_dir : 0;
  1248. #if PACKETVER >= 20101124
  1249. p.robe = vd->robe;
  1250. #endif
  1251. p.GUID = status_get_guild_id( &bl );
  1252. p.GEmblemVer = status_get_emblem_id( &bl );
  1253. p.honor = (sd) ? sd->status.manner : 0;
  1254. p.virtue = (sc) ? sc->opt3 : 0;
  1255. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1256. p.sex = vd->sex;
  1257. WBUFPOS2(&p.MoveData[0], 0, bl.x, bl.y, ud.to_x, ud.to_y, ud.sx, ud.sy);
  1258. p.xSize = p.ySize = (sd) ? 5 : 0;
  1259. p.clevel = clif_setlevel( &bl );
  1260. #if PACKETVER >= 20080102
  1261. p.font = (sd) ? sd->status.font : 0;
  1262. #endif
  1263. #if PACKETVER >= 20120221
  1264. 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 ) ) ){
  1265. p.maxHP = status_get_max_hp( &bl );
  1266. p.HP = status_get_hp( &bl );
  1267. } else {
  1268. p.maxHP = -1;
  1269. p.HP = -1;
  1270. }
  1271. if( bl.type == BL_MOB ){
  1272. p.isBoss = reinterpret_cast<mob_data*>( &bl )->get_bosstype();
  1273. }else if( bl.type == BL_PET ){
  1274. p.isBoss = reinterpret_cast<pet_data*>( &bl )->db->get_bosstype();
  1275. }else{
  1276. p.isBoss = BOSSTYPE_NONE;
  1277. }
  1278. #endif
  1279. #if PACKETVER >= 20150513
  1280. p.body = vd->body_style;
  1281. #endif
  1282. /* Might be earlier, this is when the named item bug began */
  1283. #if PACKETVER >= 20131223
  1284. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1285. #endif
  1286. clif_send( &p, sizeof(p), tsd ? &tsd->bl : &bl, target );
  1287. // if disguised, send the info to self
  1288. if( disguised( &bl ) ){
  1289. #if PACKETVER >= 20091103
  1290. p.objecttype = pcdb_checkid( status_get_viewdata( &bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1291. #if PACKETVER >= 20131223
  1292. p.AID = disguised_bl_id( bl.id );
  1293. #else
  1294. p.GID = disguised_bl_id( bl.id );
  1295. #endif
  1296. #else
  1297. p.GID = disguised_bl_id( bl.id );
  1298. #endif
  1299. clif_send(&p, sizeof(p), &bl, SELF);
  1300. }
  1301. }
  1302. /// Changes sprite of a non player object.
  1303. /// 01b0 <id>.L <type>.B <value>.L (ZC_NPCSPRITE_CHANGE)
  1304. void clif_class_change( block_list& bl, int32 class_, enum send_target target, map_session_data* sd ){
  1305. if( pcdb_checkid( class_ ) ){
  1306. // player classes yield missing sprites
  1307. return;
  1308. }
  1309. PACKET_ZC_NPCSPRITE_CHANGE p = {};
  1310. p.packetType = HEADER_ZC_NPCSPRITE_CHANGE;
  1311. p.GID = bl.id;
  1312. // Unused
  1313. p.type = 0;
  1314. p.class_ = class_;
  1315. if( sd != nullptr ){
  1316. bl = sd->bl;
  1317. }
  1318. clif_send( &p, sizeof( p ), &bl, target );
  1319. }
  1320. void clif_servantball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1321. PACKET_ZC_SPIRITS p = {};
  1322. p.PacketType = HEADER_ZC_SPIRITS;
  1323. p.AID = sd.bl.id;
  1324. p.num = sd.servantball;
  1325. if( target == nullptr ){
  1326. target = &sd.bl;
  1327. }
  1328. clif_send( &p, sizeof( p ), target, send_target );
  1329. }
  1330. void clif_abyssball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1331. PACKET_ZC_SPIRITS p = {};
  1332. p.PacketType = HEADER_ZC_SPIRITS;
  1333. p.AID = sd.bl.id;
  1334. p.num = sd.abyssball;
  1335. if( target == nullptr ){
  1336. target = &sd.bl;
  1337. }
  1338. clif_send( &p, sizeof( p ), target, send_target );
  1339. }
  1340. /// Notifies the client of an object's Millenium Shields.
  1341. static void clif_millenniumshield_single( map_session_data& sd, map_session_data& tsd ){
  1342. #if PACKETVER >= 20081126
  1343. status_change_entry* sce = sd.sc.getSCE( SC_MILLENNIUMSHIELD );
  1344. if( sce == nullptr ){
  1345. return;
  1346. }
  1347. PACKET_ZC_MILLENNIUMSHIELD packet{};
  1348. packet.packetType = HEADER_ZC_MILLENNIUMSHIELD;
  1349. packet.aid = sd.bl.id;
  1350. packet.num = sce->val2;
  1351. packet.state = 0;
  1352. clif_send( &packet, sizeof( packet ), &tsd.bl, SELF );
  1353. #endif
  1354. }
  1355. /*==========================================
  1356. * Kagerou/Oboro amulet spirit
  1357. *------------------------------------------*/
  1358. static void clif_spiritcharm_single( map_session_data& sd, map_session_data& tsd ){
  1359. #if PACKETVER >= 20111102
  1360. if( sd.spiritcharm_type == CHARM_TYPE_NONE ){
  1361. return;
  1362. }
  1363. if( sd.spiritcharm <= 0 ){
  1364. return;
  1365. }
  1366. PACKET_ZC_SPIRITS_ATTRIBUTE packet{};
  1367. packet.packetType = HEADER_ZC_SPIRITS_ATTRIBUTE;
  1368. packet.aid = sd.bl.id;
  1369. packet.spiritsType = static_cast<decltype(packet.spiritsType)>(sd.spiritcharm_type);
  1370. packet.num = static_cast<decltype(packet.num)>(sd.spiritcharm);
  1371. clif_send( &packet, sizeof( packet ), &tsd.bl, SELF );
  1372. #endif
  1373. }
  1374. /*==========================================
  1375. * Enchanting Shadow / Shadow Scar Spirit
  1376. *------------------------------------------*/
  1377. void clif_enchantingshadow_spirit(unit_data &ud) {
  1378. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191120 || PACKETVER_ZERO_NUM >= 20191127
  1379. PACKET_ZC_TARGET_SPIRITS p = {};
  1380. p.packetType = HEADER_ZC_TARGET_SPIRITS;
  1381. p.GID = ud.bl->id;
  1382. p.unknown_val = 0;
  1383. p.amount = static_cast<uint16>(ud.shadow_scar_timer.size());
  1384. clif_send(&p, sizeof(p), ud.bl, AREA);
  1385. #endif
  1386. }
  1387. /*==========================================
  1388. * Run when player changes map / refreshes
  1389. * Tells its client to display all weather settings being used by this map
  1390. *------------------------------------------*/
  1391. static void clif_weather_check(map_session_data *sd)
  1392. {
  1393. int16 m = sd->bl.m;
  1394. int32 fd = sd->fd;
  1395. if (map_getmapflag(m, MF_SNOW)
  1396. || map_getmapflag(m, MF_CLOUDS)
  1397. || map_getmapflag(m, MF_FOG)
  1398. || map_getmapflag(m, MF_FIREWORKS)
  1399. || map_getmapflag(m, MF_SAKURA)
  1400. || map_getmapflag(m, MF_LEAVES)
  1401. || map_getmapflag(m, MF_CLOUDS2))
  1402. {
  1403. if (map_getmapflag(m, MF_SNOW))
  1404. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1405. if (map_getmapflag(m, MF_CLOUDS))
  1406. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1407. if (map_getmapflag(m, MF_CLOUDS2))
  1408. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1409. if (map_getmapflag(m, MF_FOG))
  1410. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1411. if (map_getmapflag(m, MF_FIREWORKS)) {
  1412. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1413. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1414. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1415. }
  1416. if (map_getmapflag(m, MF_SAKURA))
  1417. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1418. if (map_getmapflag(m, MF_LEAVES))
  1419. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1420. }
  1421. }
  1422. /**
  1423. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1424. **/
  1425. void clif_weather(int16 m)
  1426. {
  1427. struct s_mapiterator* iter;
  1428. map_session_data *sd=nullptr;
  1429. iter = mapit_getallusers();
  1430. for( sd = (map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (map_session_data*)mapit_next(iter) )
  1431. {
  1432. if( sd->bl.m == m )
  1433. clif_weather_check(sd);
  1434. }
  1435. mapit_free(iter);
  1436. }
  1437. /**
  1438. * Hide a NPC from the effects of Maya Purple card.
  1439. * @param bl: Block data
  1440. * @return True if NPC is disabled or false otherwise
  1441. */
  1442. static inline bool clif_npc_mayapurple(block_list *bl) {
  1443. nullpo_retr(false, bl);
  1444. if (bl->type == BL_NPC) {
  1445. npc_data *nd = map_id2nd(bl->id);
  1446. // TODO: Confirm if waitingroom cause any special cases
  1447. if (/* nd->chat_id == 0 && */ nd->is_invisible)
  1448. return true;
  1449. }
  1450. return false;
  1451. }
  1452. /**
  1453. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1454. **/
  1455. int32 clif_spawn( struct block_list *bl, bool walking ){
  1456. struct view_data *vd;
  1457. vd = status_get_viewdata(bl);
  1458. if( !vd || vd->class_ == JT_INVISIBLE )
  1459. return 0;
  1460. // Hide NPC from Maya Purple card
  1461. if (clif_npc_mayapurple(bl))
  1462. return 0;
  1463. if( bl->type == BL_NPC && !vd->dead_sit ){
  1464. clif_set_unit_idle( bl, walking, AREA_WOS, bl );
  1465. }else{
  1466. clif_spawn_unit( bl, AREA_WOS );
  1467. }
  1468. if (vd->cloth_color)
  1469. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1470. if (vd->body_style)
  1471. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1472. switch (bl->type)
  1473. {
  1474. case BL_PC:
  1475. {
  1476. TBL_PC *sd = ((TBL_PC*)bl);
  1477. if (sd->spiritball > 0)
  1478. clif_spiritball(&sd->bl);
  1479. if (sd->sc.getSCE(SC_MILLENNIUMSHIELD))
  1480. clif_millenniumshield( sd->bl, sd->sc.getSCE( SC_MILLENNIUMSHIELD )->val2 );
  1481. if (sd->soulball > 0)
  1482. clif_soulball(sd);
  1483. if (sd->servantball > 0)
  1484. clif_servantball( *sd );
  1485. if (sd->abyssball > 0)
  1486. clif_abyssball( *sd );
  1487. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1488. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1489. else if(sd->state.size==SZ_MEDIUM)
  1490. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1491. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1492. clif_sendbgemblem_area(sd);
  1493. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1494. clif_spiritcharm( *sd );
  1495. if (sd->status.robe)
  1496. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1497. clif_efst_status_change_sub(bl, bl, AREA);
  1498. clif_hat_effects( *sd, sd->bl, AREA );
  1499. }
  1500. break;
  1501. case BL_MOB:
  1502. {
  1503. TBL_MOB *md = ((TBL_MOB*)bl);
  1504. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1505. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1506. else if(md->special_state.size==SZ_MEDIUM)
  1507. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1508. if ( md->special_state.ai == AI_ABR || md->special_state.ai == AI_BIONIC )
  1509. clif_summon_init(*md);
  1510. }
  1511. break;
  1512. case BL_NPC:
  1513. {
  1514. TBL_NPC *nd = ((TBL_NPC*)bl);
  1515. if( nd->size == SZ_BIG )
  1516. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1517. else if( nd->size == SZ_MEDIUM )
  1518. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1519. clif_efst_status_change_sub(bl, bl, AREA);
  1520. clif_progressbar_npc_area(nd);
  1521. }
  1522. break;
  1523. case BL_PET:
  1524. // If the pet wears equip
  1525. if( vd->head_bottom != 0 ){
  1526. pet_data& pd = *reinterpret_cast<pet_data*>( bl );
  1527. clif_send_petdata( nullptr, pd, CHANGESTATEPET_ACCESSORY );
  1528. }
  1529. break;
  1530. }
  1531. return 0;
  1532. }
  1533. /// Notifies client of a change in an homunculus' status parameter.
  1534. /// 0x7db <type>.W <value>.L (ZC_HO_PAR_CHANGE)
  1535. /// 0xba5 <type>.W <value>.Q (ZC_HO_PAR_CHANGE2)
  1536. void clif_homunculus_updatestatus(map_session_data& sd, _sp type) {
  1537. #if PACKETVER >= 20090610
  1538. if( !hom_is_active(sd.hd) )
  1539. return;
  1540. PACKET_ZC_HO_PAR_CHANGE p = {};
  1541. p.packetType = HEADER_ZC_HO_PAR_CHANGE;
  1542. p.type = static_cast<decltype(p.type)>(type);
  1543. status_data* status = &sd.hd->battle_status;
  1544. switch (type) {
  1545. case SP_BASEEXP:
  1546. p.value = static_cast<decltype(p.value)>( std::min<decltype(sd.hd->homunculus.exp)>( sd.hd->homunculus.exp, std::numeric_limits<decltype(p.value)>::max() ) );
  1547. break;
  1548. case SP_HP:
  1549. // Homunculus HP and SP bars will screw up if the percentage calculation exceeds signed values
  1550. // Any value above will screw up the bars
  1551. // Since max values depend on PACKET_ZC_PROPERTY_HOMUN we check for each version of that packet
  1552. #if PACKETVER_MAIN_NUM >= 20200819 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20190626
  1553. // Tested maximum: 2147483647 (INT32_MAX)
  1554. if (status->max_hp > INT32_MAX)
  1555. #elif PACKETVER_MAIN_NUM >= 20131230 || PACKETVER_RE_NUM >= 20131230 || defined(PACKETVER_ZERO)
  1556. // Tested maximum: 21474836 (INT32_MAX / 100)
  1557. if (status->max_hp > INT32_MAX / 100)
  1558. #else
  1559. // Tested maximum: 32767 (INT16_MAX)
  1560. if (status->max_hp > INT16_MAX)
  1561. #endif
  1562. p.value = status->hp / (status->max_hp / 100);
  1563. else
  1564. p.value = static_cast<decltype(p.value)>(status->hp);
  1565. break;
  1566. case SP_SP:
  1567. #if PACKETVER_MAIN_NUM >= 20200819 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20190626
  1568. // Tested maximum: 2147483647 (INT32_MAX)
  1569. if (status->max_sp > INT32_MAX)
  1570. #else
  1571. // Tested maximum: 32767 (INT16_MAX)
  1572. if (status->max_sp > INT16_MAX)
  1573. #endif
  1574. p.value = status->sp / (status->max_sp / 100);
  1575. else
  1576. p.value = static_cast<decltype(p.value)>(status->sp);
  1577. break;
  1578. default:
  1579. ShowError("clif_homunculus_updatestatus: Unsupported type %d.\n", type);
  1580. return;
  1581. }
  1582. clif_send(&p, sizeof(p), &sd.bl, SELF);
  1583. #endif
  1584. }
  1585. /// Sends information about owned homunculus to the client . [orn]
  1586. /// 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)
  1587. /// 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)
  1588. void clif_hominfo( map_session_data *sd, struct homun_data *hd, int32 flag ){
  1589. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1590. nullpo_retv( sd );
  1591. nullpo_retv( hd );
  1592. struct status_data *status = &hd->battle_status;
  1593. PACKET_ZC_PROPERTY_HOMUN p = {};
  1594. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1595. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1596. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1597. 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 );
  1598. p.level = hd->homunculus.level;
  1599. p.hunger = hd->homunculus.hunger;
  1600. p.intimacy = hd->homunculus.intimacy / 100;
  1601. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1602. p.itemId = 0; // equip id
  1603. #endif
  1604. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1605. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1606. p.hit = status->hit;
  1607. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1608. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1609. }else{
  1610. p.crit = status->cri / 10;
  1611. }
  1612. #ifdef RENEWAL
  1613. p.def = status->def + status->def2;
  1614. p.mdef = status->mdef + status->mdef2;
  1615. #else
  1616. p.def = status->def + status->vit;
  1617. p.mdef = status->mdef;
  1618. #endif
  1619. p.flee = status->flee;
  1620. p.amotion = (flag) ? 0 : status->amotion;
  1621. // Homunculus HP and SP bars will screw up if the percentage calculation exceeds signed values
  1622. // Any value above will screw up the bars
  1623. #if PACKETVER_MAIN_NUM >= 20200819 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20190626
  1624. // Tested maximum: 2147483647 (INT32_MAX)
  1625. if (status->max_hp > INT32_MAX)
  1626. #elif PACKETVER_MAIN_NUM >= 20131230 || PACKETVER_RE_NUM >= 20131230 || defined(PACKETVER_ZERO)
  1627. // Tested maximum: 21474836 (INT32_MAX / 100)
  1628. if (status->max_hp > INT32_MAX / 100)
  1629. #else
  1630. // Tested maximum: 32767 (INT16_MAX)
  1631. if (status->max_hp > INT16_MAX)
  1632. #endif
  1633. {
  1634. p.hp = status->hp / ( status->max_hp / 100 );
  1635. p.maxHp = 100;
  1636. }else{
  1637. p.hp = static_cast<decltype(p.hp)>(status->hp);
  1638. p.maxHp = static_cast<decltype(p.maxHp)>(status->max_hp);
  1639. }
  1640. #if PACKETVER_MAIN_NUM >= 20200819 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20190626
  1641. // Tested maximum: 2147483647 (INT32_MAX)
  1642. if (status->max_sp > INT32_MAX)
  1643. #else
  1644. // Tested maximum: 32767 (INT16_MAX)
  1645. if (status->max_sp > INT16_MAX)
  1646. #endif
  1647. {
  1648. p.sp = status->sp / ( status->max_sp / 100 );
  1649. p.maxSp = 100;
  1650. }else{
  1651. p.sp = static_cast<decltype(p.sp)>(status->sp);
  1652. p.maxSp = static_cast<decltype(p.maxSp)>(status->max_sp);
  1653. }
  1654. p.exp = static_cast<decltype(p.exp)>( std::min<decltype(hd->homunculus.exp)>( hd->homunculus.exp, std::numeric_limits<decltype(p.exp)>::max() ) );
  1655. p.expNext = static_cast<decltype(p.expNext)>( std::min<decltype(hd->exp_next)>( hd->exp_next, std::numeric_limits<decltype(p.expNext)>::max() ) );
  1656. switch( hom_class2type( hd->homunculus.class_ ) ){
  1657. case HT_REG:
  1658. case HT_EVO:
  1659. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1660. p.expNext = 0;
  1661. }
  1662. break;
  1663. case HT_S:
  1664. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1665. p.expNext = 0;
  1666. }
  1667. break;
  1668. }
  1669. p.skillPoints = hd->homunculus.skillpts;
  1670. p.range = status_get_range( &hd->bl );
  1671. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1672. #endif
  1673. }
  1674. /// Notification about a change in homunuculus' state.
  1675. /// 0230 <type>.B <state>.B <id>.L <data>.L (ZC_CHANGESTATE_MER)
  1676. /// type:
  1677. /// unused
  1678. /// state:
  1679. /// 0 = pre-init
  1680. /// 1 = intimacy
  1681. /// 2 = hunger
  1682. /// 3 = accessory?
  1683. /// ? = ignored
  1684. void clif_send_homdata( homun_data& hd, e_hom_state2 state ){
  1685. #if PACKETVER >= 20050523
  1686. if( hd.master == nullptr ){
  1687. return;
  1688. }
  1689. uint32 param;
  1690. switch( state ){
  1691. case SP_ACK:
  1692. param = 0;
  1693. break;
  1694. case SP_INTIMATE:
  1695. // TODO: Why is something like this here? [Lemongrass]
  1696. if( hd.homunculus.class_ == hd.homunculusDB->evo_class && hom_intimacy_intimacy2grade( hd.homunculus.intimacy ) >= HOMGRADE_LOYAL ){
  1697. hom_calc_skilltree( &hd );
  1698. }
  1699. param = hd.homunculus.intimacy / 100;
  1700. break;
  1701. case SP_HUNGRY:
  1702. param = hd.homunculus.hunger;
  1703. break;
  1704. default:
  1705. return;
  1706. }
  1707. PACKET_ZC_CHANGESTATE_MER packet{};
  1708. packet.packetType = HEADER_ZC_CHANGESTATE_MER;
  1709. packet.type = 0;
  1710. packet.state = state;
  1711. packet.gid = hd.bl.id;
  1712. packet.data = param;
  1713. clif_send( &packet, sizeof( packet ), &hd.master->bl, SELF );
  1714. #endif
  1715. }
  1716. void clif_homskillinfoblock( homun_data& hd ){
  1717. #if PACKETVER >= 20050530
  1718. map_session_data* sd = hd.master;
  1719. if( sd == nullptr ){
  1720. return;
  1721. }
  1722. PACKET_ZC_HOSKILLINFO_LIST* packet = reinterpret_cast<PACKET_ZC_HOSKILLINFO_LIST*>(packet_buffer);
  1723. packet->packetType = HEADER_ZC_HOSKILLINFO_LIST;
  1724. packet->packetLength = sizeof( *packet );
  1725. for(int32 i = 0, count = 0; i < MAX_HOMUNSKILL; i++) {
  1726. int32 id = hd.homunculus.hskill[i].id;
  1727. if (id != 0) {
  1728. int32 combo = (hd.homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1729. int16 idx = hom_skill_get_index(id);
  1730. if (idx == -1)
  1731. continue;
  1732. packet->skills[count].id = id;
  1733. packet->skills[count].inf = (combo) ? INF_SELF_SKILL : skill_get_inf(id);
  1734. packet->skills[count].unknown = 0;
  1735. packet->skills[count].level = hd.homunculus.hskill[idx].lv;
  1736. packet->skills[count].sp = skill_get_sp(id,hd.homunculus.hskill[idx].lv);
  1737. packet->skills[count].range = skill_get_range2(&hd.bl,id,hd.homunculus.hskill[idx].lv,false);
  1738. safestrncpy(packet->skills[count].name, skill_get_name(id), NAME_LENGTH);
  1739. packet->skills[count].upgradable = (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;
  1740. packet->packetLength += sizeof( packet->skills[0] );
  1741. count++;
  1742. }
  1743. }
  1744. clif_send( packet, packet->packetLength, &sd->bl, SELF );
  1745. #endif
  1746. }
  1747. void clif_homskillup( homun_data& hd, uint16 skill_id ){
  1748. #if PACKETVER >= 20050531
  1749. int16 idx = hom_skill_get_index( skill_id );
  1750. if( idx == -1 ){
  1751. return;
  1752. }
  1753. map_session_data* sd = hd.master;
  1754. if( sd == nullptr ){
  1755. return;
  1756. }
  1757. PACKET_ZC_HOSKILLINFO_UPDATE packet{};
  1758. packet.packetType = HEADER_ZC_HOSKILLINFO_UPDATE;
  1759. packet.skill_id = skill_id;
  1760. packet.Level = hd.homunculus.hskill[idx].lv;
  1761. packet.SP = skill_get_sp(skill_id,hd.homunculus.hskill[idx].lv);
  1762. packet.AttackRange = skill_get_range2(&hd.bl,skill_id,hd.homunculus.hskill[idx].lv,false);
  1763. packet.upgradable = (hd.homunculus.level < hom_skill_get_min_level(hd.homunculus.class_, skill_id) || hd.homunculus.hskill[idx].lv >= hom_skill_tree_get_max(skill_id, hd.homunculus.class_)) ? 0 : 1;
  1764. clif_send( &packet, sizeof( packet ), &sd->bl, SELF );
  1765. #endif
  1766. }
  1767. /// Result of request to feed a homun/merc.
  1768. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1769. /// result:
  1770. /// 0 = failure
  1771. /// 1 = success
  1772. void clif_hom_food( map_session_data& sd, int32 foodid, bool success ){
  1773. PACKET_ZC_FEED_MER packet{};
  1774. packet.packetType = HEADER_ZC_FEED_MER;
  1775. packet.result = success;
  1776. packet.itemId = client_nameid( foodid );
  1777. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1778. }
  1779. /// Notifies the client, that it is walking.
  1780. /// 0087 <walk start time>.L <walk data>.6B (ZC_NOTIFY_PLAYERMOVE)
  1781. void clif_walkok( map_session_data& sd ){
  1782. PACKET_ZC_NOTIFY_PLAYERMOVE packet{};
  1783. packet.packetType = HEADER_ZC_NOTIFY_PLAYERMOVE;
  1784. packet.moveStartTime = client_tick(gettick());
  1785. WBUFPOS2(packet.moveData, 0, sd.bl.x, sd.bl.y, sd.ud.to_x, sd.ud.to_y, 8, 8);
  1786. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1787. }
  1788. /// Notifies clients in an area, that an other visible object is walking.
  1789. /// Note: unit must not be self
  1790. void clif_move( struct unit_data& ud )
  1791. {
  1792. struct block_list* bl = ud.bl;
  1793. struct view_data* vd = status_get_viewdata(bl);
  1794. if (bl == nullptr || vd == nullptr)
  1795. return;
  1796. // This performance check is needed to keep GM-hidden objects from being notified to bots.
  1797. if (vd->class_ == JT_INVISIBLE)
  1798. return;
  1799. // Hide NPC from Maya Purple card
  1800. if (clif_npc_mayapurple(bl))
  1801. return;
  1802. status_change* sc = nullptr;
  1803. if ((sc = status_get_sc(bl)) && sc->option & (OPTION_HIDE | OPTION_CLOAK | OPTION_INVISIBLE | OPTION_CHASEWALK))
  1804. clif_ally_only = true;
  1805. clif_set_unit_walking( *bl, nullptr, ud, AREA_WOS );
  1806. if (vd->cloth_color)
  1807. clif_refreshlook(bl, bl->id, LOOK_CLOTHES_COLOR, vd->cloth_color, AREA_WOS);
  1808. if (vd->body_style)
  1809. clif_refreshlook(bl, bl->id, LOOK_BODY2, vd->body_style, AREA_WOS);
  1810. switch (bl->type) {
  1811. case BL_PC:
  1812. {
  1813. map_session_data* sd = reinterpret_cast<map_session_data*>( bl );
  1814. if (sd->state.size == SZ_BIG) // tiny/big players [Valaris]
  1815. clif_specialeffect(&sd->bl, EF_GIANTBODY2, AREA);
  1816. else if (sd->state.size == SZ_MEDIUM)
  1817. clif_specialeffect(&sd->bl, EF_BABYBODY2, AREA);
  1818. if (sd->status.robe)
  1819. clif_refreshlook(bl, bl->id, LOOK_ROBE, sd->status.robe, AREA);
  1820. }
  1821. break;
  1822. case BL_MOB:
  1823. {
  1824. mob_data* md = reinterpret_cast<mob_data*>( bl );
  1825. if (md->special_state.size == SZ_BIG) // tiny/big mobs [Valaris]
  1826. clif_specialeffect(&md->bl, EF_GIANTBODY2, AREA);
  1827. else if (md->special_state.size == SZ_MEDIUM)
  1828. clif_specialeffect(&md->bl, EF_BABYBODY2, AREA);
  1829. }
  1830. break;
  1831. case BL_PET:
  1832. // If the pet wears equip
  1833. if( vd->head_bottom != 0 ){
  1834. pet_data& pd = *reinterpret_cast<pet_data*>( bl );
  1835. clif_send_petdata( nullptr, pd, CHANGESTATEPET_ACCESSORY );
  1836. }
  1837. break;
  1838. }
  1839. clif_ally_only = false;
  1840. }
  1841. /*==========================================
  1842. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1843. *------------------------------------------*/
  1844. static TIMER_FUNC(clif_delayquit){
  1845. map_session_data *sd = nullptr;
  1846. //Remove player from map server
  1847. if ((sd = map_id2sd(id)) != nullptr && sd->fd == 0) //Should be a disconnected player.
  1848. map_quit(sd);
  1849. return 0;
  1850. }
  1851. /*==========================================
  1852. *
  1853. *------------------------------------------*/
  1854. void clif_quitsave(int32 fd,map_session_data *sd) {
  1855. if (!battle_config.prevent_logout ||
  1856. sd->canlog_tick == 0 ||
  1857. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1858. map_quit(sd);
  1859. else if (session_isValid(sd->fd)) {
  1860. //Disassociate session from player (session is deleted after this function was called)
  1861. //And set a timer to make him quit later.
  1862. session[sd->fd]->session_data = nullptr;
  1863. sd->fd = 0;
  1864. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1865. }
  1866. }
  1867. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1868. /// 0091 <map name>.16B <x>.W <y>.W
  1869. void clif_changemap( map_session_data& sd, int16 m, uint16 x, uint16 y ){
  1870. PACKET_ZC_NPCACK_MAPMOVE packet{};
  1871. packet.packetType = HEADER_ZC_NPCACK_MAPMOVE;
  1872. mapindex_getmapname_ext(map_mapid2mapname(m), packet.mapName);
  1873. packet.xPos = x;
  1874. packet.yPos = y;
  1875. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1876. }
  1877. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1878. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1879. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE_DOMAIN)
  1880. void clif_changemapserver( map_session_data& sd, const char* map, uint16 x, uint16 y, uint32 ip, uint16 port ){
  1881. PACKET_ZC_NPCACK_SERVERMOVE packet{};
  1882. packet.packetType = HEADER_ZC_NPCACK_SERVERMOVE;
  1883. mapindex_getmapname_ext(map, packet.mapName);
  1884. packet.xPos = x;
  1885. packet.yPos = y;
  1886. packet.ip = htonl(ip);
  1887. packet.port = ntows(htons(port)); // [!] LE byte order here [!]
  1888. #if PACKETVER >= 20170315
  1889. safestrncpy( packet.domain, "", sizeof( packet.domain ) );
  1890. #endif
  1891. #ifdef DEBUG
  1892. ShowDebug( "Sending the client (%d %d.%d.%d.%d) to map-server with ip %d.%d.%d.%d and port %hu\n", sd.status.account_id, CONVIP(session[sd.fd]->client_addr), CONVIP(ip), port );
  1893. #endif
  1894. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1895. }
  1896. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1897. /// This function combines both calls and allows to simplify the calling code
  1898. void clif_blown(struct block_list *bl)
  1899. {
  1900. clif_slide(*bl, bl->x, bl->y);
  1901. clif_fixpos( *bl );
  1902. }
  1903. /// Visually moves(slides) a character to x,y. If the target cell
  1904. /// isn't walkable, the char doesn't move at all. If the char is
  1905. /// sitting it will stand up.
  1906. /// 0088 <id>.L <x>.W <y>.W (ZC_STOPMOVE)
  1907. void clif_fixpos( block_list& bl ){
  1908. PACKET_ZC_STOPMOVE packet = {};
  1909. packet.packetType = HEADER_ZC_STOPMOVE;
  1910. packet.AID = bl.id;
  1911. packet.xPos = bl.x;
  1912. packet.yPos = bl.y;
  1913. clif_send( &packet, sizeof( packet ), &bl, AREA);
  1914. if( disguised( &bl ) ){
  1915. packet.AID = disguised_bl_id( bl.id );
  1916. clif_send( &packet, sizeof( packet ), &bl, SELF );
  1917. }
  1918. }
  1919. /// Displays the buy/sell dialog of an NPC shop.
  1920. /// 00c4 <shop id>.L (ZC_SELECT_DEALTYPE)
  1921. void clif_npcbuysell( map_session_data& sd, npc_data& nd ){
  1922. PACKET_ZC_SELECT_DEALTYPE packet{};
  1923. packet.packetType = HEADER_ZC_SELECT_DEALTYPE;
  1924. packet.npcId = nd.bl.id;
  1925. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1926. }
  1927. /// Presents list of items, that can be bought in an NPC shop.
  1928. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1929. void clif_buylist( map_session_data& sd, npc_data& nd ){
  1930. PACKET_ZC_PC_PURCHASE_ITEMLIST* p = reinterpret_cast<PACKET_ZC_PC_PURCHASE_ITEMLIST*>( packet_buffer );
  1931. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST;
  1932. p->packetLength = sizeof( *p );
  1933. for( int32 i = 0, count = 0, discount = npc_shop_discount( &nd ); i < nd.u.shop.count; i++ ){
  1934. int32 val = nd.u.shop.shop_item[i].value;
  1935. p->items[count].price = val;
  1936. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( &sd, val ) : val;
  1937. p->items[count].itemType = itemtype( nd.u.shop.shop_item[i].nameid );
  1938. p->items[count].itemId = client_nameid( nd.u.shop.shop_item[i].nameid );
  1939. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1940. std::shared_ptr<item_data> id = item_db.find(nd.u.shop.shop_item[i].nameid);
  1941. p->items[count].viewSprite = id->look;
  1942. p->items[count].location = pc_equippoint_sub( &sd, id.get() );
  1943. #endif
  1944. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  1945. count++;
  1946. }
  1947. clif_send( p, p->packetLength, &sd.bl, SELF );
  1948. }
  1949. /// Presents list of items, that can be sold to an NPC shop.
  1950. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }* (ZC_PC_SELL_ITEMLIST)
  1951. void clif_selllist( map_session_data& sd){
  1952. if( !sd.npc_shopid ){
  1953. return;
  1954. }
  1955. npc_data* nd = map_id2nd( sd.npc_shopid );
  1956. if( nd == nullptr ){
  1957. return;
  1958. }
  1959. PACKET_ZC_PC_SELL_ITEMLIST *packet = reinterpret_cast<PACKET_ZC_PC_SELL_ITEMLIST*>(packet_buffer);
  1960. packet->packetType = HEADER_ZC_PC_SELL_ITEMLIST;
  1961. packet->packetLength = sizeof( *packet );
  1962. for( int32 i = 0, c = 0; i < MAX_INVENTORY; i++ ){
  1963. if( sd.inventory.u.items_inventory[i].nameid <= 0 ){
  1964. continue;
  1965. }
  1966. if( sd.inventory_data[i] == nullptr ){
  1967. continue;
  1968. }
  1969. if( !pc_can_sell_item( &sd, &sd.inventory.u.items_inventory[i], nd->subtype ) ){
  1970. continue;
  1971. }
  1972. int32 price;
  1973. if( battle_config.rental_item_novalue && sd.inventory.u.items_inventory[i].expire_time ){
  1974. price = 0;
  1975. }else{
  1976. price = sd.inventory_data[i]->value_sell;
  1977. if( price < 0 ){
  1978. continue;
  1979. }
  1980. }
  1981. packet->items[c].index = client_index(i);
  1982. packet->items[c].price = price;
  1983. packet->items[c].overcharge = pc_modifysellvalue( &sd, price );
  1984. packet->packetLength += sizeof( packet->items[0] );
  1985. c++;
  1986. }
  1987. clif_send( packet, packet->packetLength, &sd.bl, SELF );
  1988. }
  1989. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1990. /// 09d4
  1991. void clif_parse_NPCShopClosed(int32 fd, map_session_data *sd) {
  1992. // TODO: State tracking?
  1993. sd->npc_shopid = 0;
  1994. }
  1995. /**
  1996. * Presents list of items, that can be sold to a Market shop.
  1997. * @author: Ind and Yommy
  1998. **/
  1999. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  2000. void clif_npc_market_open( map_session_data& sd, npc_data& nd ){
  2001. #if PACKETVER >= 20131223
  2002. if( sd.state.trading ){
  2003. return;
  2004. }
  2005. PACKET_ZC_NPC_MARKET_OPEN* p = reinterpret_cast<PACKET_ZC_NPC_MARKET_OPEN*>( packet_buffer );
  2006. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  2007. p->packetLength = sizeof( *p );
  2008. for( int32 i = 0, count = 0; i < nd.u.shop.count; i++ ){
  2009. struct npc_item_list *item = &nd.u.shop.shop_item[i];
  2010. if( !item->nameid ){
  2011. continue;
  2012. }
  2013. std::shared_ptr<item_data> id = item_db.find(item->nameid);
  2014. if( !id ){
  2015. continue;
  2016. }
  2017. PACKET_ZC_NPC_MARKET_OPEN_sub& entry = p->list[count];
  2018. entry.nameid = client_nameid( item->nameid );
  2019. entry.type = itemtype( item->nameid );
  2020. entry.price = item->value;
  2021. entry.qty = item->qty;
  2022. entry.weight = id->weight;
  2023. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  2024. entry.location = pc_equippoint_sub( &sd, id.get() );
  2025. #endif
  2026. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  2027. count++;
  2028. }
  2029. clif_send( p, p->packetLength, &sd.bl, SELF );
  2030. sd.state.trading = 1;
  2031. #endif
  2032. }
  2033. /// Closes the Market shop window.
  2034. void clif_parse_NPCMarketClosed(int32 fd, map_session_data *sd) {
  2035. nullpo_retv(sd);
  2036. sd->npc_shopid = 0;
  2037. sd->state.trading = 0;
  2038. }
  2039. /// Purchase item from Market shop.
  2040. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  2041. void clif_npc_market_purchase_ack( map_session_data& sd, e_purchase_result res, std::vector<s_npc_buy_list>& list ){
  2042. #if PACKETVER >= 20131223
  2043. struct npc_data *nd = map_id2nd( sd.npc_shopid );
  2044. if( nd == nullptr ){
  2045. return;
  2046. }
  2047. PACKET_ZC_NPC_MARKET_PURCHASE_RESULT* p = reinterpret_cast<PACKET_ZC_NPC_MARKET_PURCHASE_RESULT*>( packet_buffer );
  2048. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  2049. p->PacketLength = sizeof( *p );
  2050. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  2051. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 0 : -1 );
  2052. #else
  2053. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 1 : 0 );
  2054. #endif
  2055. if( res == e_purchase_result::PURCHASE_SUCCEED ){
  2056. for( int32 i = 0, j, count = 0; i < list.size(); i++ ){
  2057. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  2058. // Not found
  2059. if( j == nd->u.shop.count ){
  2060. continue;
  2061. }
  2062. p->list[count].ITID = client_nameid( list[i].nameid );
  2063. p->list[count].qty = list[i].qty;
  2064. p->list[count].price = nd->u.shop.shop_item[j].value;
  2065. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( p->list[0] ) );
  2066. count++;
  2067. }
  2068. }
  2069. clif_send( p, p->PacketLength, &sd.bl, SELF );
  2070. #endif
  2071. }
  2072. /// Purchase item from Market shop.
  2073. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2074. void clif_parse_NPCMarketPurchase(int32 fd, map_session_data *sd) {
  2075. #if PACKETVER >= 20131223
  2076. if( sd == nullptr ){
  2077. return;
  2078. }
  2079. if( !sd->npc_shopid ){
  2080. return;
  2081. }
  2082. const PACKET_CZ_NPC_MARKET_PURCHASE* p = reinterpret_cast<PACKET_CZ_NPC_MARKET_PURCHASE*>( RFIFOP( fd, 0 ) );
  2083. int32 count = ( p->PacketLength - sizeof( *p ) ) / sizeof( p->list[0] );
  2084. std::vector<s_npc_buy_list> items;
  2085. items.reserve( count );
  2086. for( int32 i = 0; i < count; i++ ){
  2087. s_npc_buy_list item = {};
  2088. item.nameid = p->list[i].ITID;
  2089. item.qty = p->list[i].qty;
  2090. items.push_back( item );
  2091. }
  2092. e_purchase_result res = npc_buylist( sd, items );
  2093. clif_npc_market_purchase_ack( *sd, res, items );
  2094. #endif
  2095. }
  2096. /// Displays an NPC dialog message.
  2097. /// 00b4 <packet len>.W <npc id>.L <message>.?B (ZC_SAY_DIALOG)
  2098. /// Client behavior (dialog window):
  2099. /// - disable mouse targeting
  2100. /// - open the dialog window
  2101. /// - set npcid of dialog window (0 by default)
  2102. /// - if set to clear on next mes, clear contents
  2103. /// - append this text
  2104. void clif_scriptmes( map_session_data& sd, uint32 npcid, const char *mes ){
  2105. PACKET_ZC_SAY_DIALOG* p = reinterpret_cast<PACKET_ZC_SAY_DIALOG*>( packet_buffer );
  2106. int16 length = (int16)( strlen( mes ) + 1 );
  2107. p->PacketType = HEADER_ZC_SAY_DIALOG;
  2108. p->PacketLength = sizeof( *p ) + length;
  2109. p->NpcID = npcid;
  2110. safestrncpy( p->message, mes, length );
  2111. clif_send( p, p->PacketLength, &sd.bl, SELF );
  2112. }
  2113. /// Adds a 'next' button to an NPC dialog.
  2114. /// 00b5 <npc id>.L (ZC_WAIT_DIALOG)
  2115. /// Client behavior (dialog window):
  2116. /// - disable mouse targeting
  2117. /// - open the dialog window
  2118. /// - add 'next' button
  2119. /// When 'next' is pressed:
  2120. /// - 00B9 <npcid of dialog window>.L
  2121. /// - set to clear on next mes
  2122. /// - remove 'next' button
  2123. void clif_scriptnext( map_session_data& sd, uint32 npcid ){
  2124. PACKET_ZC_WAIT_DIALOG p = {};
  2125. p.PacketType = HEADER_ZC_WAIT_DIALOG;
  2126. p.NpcID = npcid;
  2127. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2128. }
  2129. /// Adds a 'close' button to an NPC dialog.
  2130. /// 00b6 <npc id>.L (ZC_CLOSE_DIALOG)
  2131. /// Client behavior:
  2132. /// - if dialog window is open:
  2133. /// - remove 'next' button
  2134. /// - add 'close' button
  2135. /// - else:
  2136. /// - enable mouse targeting
  2137. /// - close the dialog window
  2138. /// - close the menu window
  2139. /// When 'close' is pressed:
  2140. /// - enable mouse targeting
  2141. /// - close the dialog window
  2142. /// - close the menu window
  2143. /// - 0146 <npcid of dialog window>.L
  2144. void clif_scriptclose( map_session_data& sd, uint32 npcid ){
  2145. PACKET_ZC_CLOSE_DIALOG packet{};
  2146. packet.packetType = HEADER_ZC_CLOSE_DIALOG;
  2147. packet.npcId = npcid;
  2148. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2149. }
  2150. /**
  2151. * Close script when player is idle
  2152. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2153. * @author [Ind/Hercules]
  2154. * @param sd : player pointer
  2155. * @param npcid : npc gid to close
  2156. */
  2157. void clif_scriptclear( map_session_data& sd, int32 npcid ){
  2158. PACKET_ZC_CLEAR_DIALOG p = {};
  2159. p.packetType = HEADER_ZC_CLEAR_DIALOG;
  2160. p.GID = npcid;
  2161. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2162. }
  2163. void clif_sendfakenpc( map_session_data& sd, uint32 npcid ){
  2164. sd.state.using_fake_npc = 1;
  2165. // Code below is a copy of clif_set_unit_idle
  2166. struct packet_idle_unit p;
  2167. p.PacketType = idle_unitType;
  2168. #if PACKETVER >= 20091103
  2169. p.PacketLength = sizeof(p);
  2170. p.objecttype = 0x1; // NPC_TYPE
  2171. #endif
  2172. #if PACKETVER >= 20131223
  2173. p.AID = npcid;
  2174. p.GID = 0;
  2175. #else
  2176. p.GID = npcid;
  2177. #endif
  2178. p.speed = 0;
  2179. p.bodyState = 0;
  2180. p.healthState = 0;
  2181. p.effectState = 0;
  2182. p.job = JT_HIDDEN_NPC;
  2183. p.head = 0;
  2184. p.weapon = 0;
  2185. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  2186. p.shield = 0;
  2187. #endif
  2188. p.accessory = 0;
  2189. p.accessory2 = 0;
  2190. p.accessory3 = 0;
  2191. p.headpalette = 0;
  2192. p.bodypalette = 0;
  2193. p.headDir = 0;
  2194. #if PACKETVER >= 20101124
  2195. p.robe = 0;
  2196. #endif
  2197. p.GUID = 0;
  2198. p.GEmblemVer = 0;
  2199. p.honor = 0;
  2200. p.virtue = 0;
  2201. p.isPKModeON = 0;
  2202. p.sex = SEX_FEMALE;
  2203. WBUFPOS( &p.PosDir[0], 0, sd.bl.x, sd.bl.y, sd.ud.dir );
  2204. p.xSize = p.ySize = 5;
  2205. p.state = 0;
  2206. p.clevel = 0;
  2207. #if PACKETVER >= 20080102
  2208. p.font = 0;
  2209. #endif
  2210. #if PACKETVER >= 20120221
  2211. p.maxHP = -1;
  2212. p.HP = -1;
  2213. #endif
  2214. #if PACKETVER >= 20150513
  2215. p.body = 0;
  2216. #endif
  2217. /* Might be earlier, this is when the named item bug began */
  2218. #if PACKETVER >= 20131223
  2219. safestrncpy( p.name, "", NAME_LENGTH);
  2220. #endif
  2221. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2222. }
  2223. /// Displays an NPC dialog menu.
  2224. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B (ZC_MENU_LIST)
  2225. /// Client behavior:
  2226. /// - disable mouse targeting
  2227. /// - close the menu window
  2228. /// - open the menu window
  2229. /// - add options to the menu (separated in the text by ":")
  2230. /// - set npcid of menu window
  2231. /// - if dialog window is open:
  2232. /// - remove 'next' button
  2233. /// When 'ok' is pressed:
  2234. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2235. /// - close the menu window
  2236. /// When 'cancel' is pressed:
  2237. /// - 00B8 <npcid of menu window>.L <-1>.B
  2238. /// - enable mouse targeting
  2239. /// - close a bunch of windows...
  2240. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2241. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2242. /// TODO investigate behavior of other windows [FlavioJS]
  2243. void clif_scriptmenu( map_session_data& sd, uint32 npcid, const char* mes ){
  2244. struct block_list *bl = nullptr;
  2245. if (!sd.state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd.bl.m ||
  2246. bl->x<sd.bl.x-AREA_SIZE-1 || bl->x>sd.bl.x+AREA_SIZE+1 ||
  2247. bl->y<sd.bl.y-AREA_SIZE-1 || bl->y>sd.bl.y+AREA_SIZE+1))))
  2248. clif_sendfakenpc( sd, npcid );
  2249. // String length + 1 byte for zero termination
  2250. size_t mes_length = strlen( mes ) + 1;
  2251. PACKET_ZC_MENU_LIST* packet = reinterpret_cast<PACKET_ZC_MENU_LIST*>( packet_buffer );
  2252. packet->packetType = HEADER_ZC_MENU_LIST;
  2253. packet->packetLength = sizeof( PACKET_ZC_MENU_LIST );
  2254. packet->npcId = npcid;
  2255. safestrncpy( packet->menu, mes, mes_length );
  2256. packet->packetLength += static_cast<decltype(packet->packetLength)>( mes_length );
  2257. clif_send( packet, packet->packetLength, &sd.bl, SELF );
  2258. }
  2259. /// Displays an NPC dialog input box for numbers.
  2260. /// 0142 <npc id>.L (ZC_OPEN_EDITDLG)
  2261. /// Client behavior (inputnum window):
  2262. /// - if npcid exists in the client:
  2263. /// - open the inputnum window
  2264. /// - set npcid of inputnum window
  2265. /// When 'ok' is pressed:
  2266. /// - if inputnum window has text:
  2267. /// - if npcid exists in the client:
  2268. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2269. /// - close inputnum window
  2270. void clif_scriptinput( map_session_data& sd, uint32 npcid ){
  2271. struct block_list *bl = nullptr;
  2272. if (!sd.state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd.bl.m ||
  2273. bl->x<sd.bl.x-AREA_SIZE-1 || bl->x>sd.bl.x+AREA_SIZE+1 ||
  2274. bl->y<sd.bl.y-AREA_SIZE-1 || bl->y>sd.bl.y+AREA_SIZE+1))))
  2275. clif_sendfakenpc( sd, npcid );
  2276. PACKET_ZC_OPEN_EDITDLG packet{};
  2277. packet.packetType = HEADER_ZC_OPEN_EDITDLG;
  2278. packet.npcId = npcid;
  2279. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2280. }
  2281. /// Displays an NPC dialog input box for strings.
  2282. /// 01d4 <npc id>.L (ZC_OPEN_EDITDLGSTR)
  2283. /// Client behavior (inputstr window):
  2284. /// - if npcid is 0 or npcid exists in the client:
  2285. /// - open the inputstr window
  2286. /// - set npcid of inputstr window
  2287. /// When 'ok' is pressed:
  2288. /// - if inputstr window has text and isn't an insult(manner.txt):
  2289. /// - if npcid is 0 or npcid exists in the client:
  2290. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2291. /// - close inputstr window
  2292. void clif_scriptinputstr( map_session_data& sd, uint32 npcid ){
  2293. struct block_list *bl = nullptr;
  2294. if (!sd.state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd.bl.m ||
  2295. bl->x<sd.bl.x-AREA_SIZE-1 || bl->x>sd.bl.x+AREA_SIZE+1 ||
  2296. bl->y<sd.bl.y-AREA_SIZE-1 || bl->y>sd.bl.y+AREA_SIZE+1))))
  2297. clif_sendfakenpc( sd, npcid );
  2298. PACKET_ZC_OPEN_EDITDLGSTR packet{};
  2299. packet.packetType = HEADER_ZC_OPEN_EDITDLGSTR;
  2300. packet.npcId = npcid;
  2301. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2302. }
  2303. /// Marks a position on client's minimap.
  2304. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L (ZC_COMPASS)
  2305. /// npc id:
  2306. /// is ignored in the client
  2307. /// type:
  2308. /// 0 = display mark for 15 seconds
  2309. /// 1 = display mark until dead or teleported
  2310. /// 2 = remove mark
  2311. /// color:
  2312. /// 0x00RRGGBB
  2313. void clif_viewpoint( map_session_data& sd, uint32 npc_id, int32 type, uint16 x, uint16 y, int32 id, uint32 color ){
  2314. PACKET_ZC_COMPASS packet{};
  2315. packet.packetType = HEADER_ZC_COMPASS;
  2316. packet.npcId = npc_id;
  2317. packet.type = type;
  2318. packet.xPos = x;
  2319. packet.yPos = y;
  2320. packet.id = id;
  2321. packet.color = color;
  2322. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2323. }
  2324. /// Displays an illustration image.
  2325. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2326. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2327. /// type:
  2328. /// 0 = bottom left corner
  2329. /// 1 = bottom middle
  2330. /// 2 = bottom right corner
  2331. /// 3 = middle of screen, inside a movable window
  2332. /// 4 = middle of screen, movable with a close button, chrome-less
  2333. /// 255 = clear all displayed cutins
  2334. void clif_cutin( map_session_data& sd, const char* image, int32 type ){
  2335. PACKET_ZC_SHOW_IMAGE packet{};
  2336. packet.packetType = HEADER_ZC_SHOW_IMAGE;
  2337. safestrncpy(packet.image, image, sizeof(packet.image));
  2338. packet.type = type;
  2339. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2340. }
  2341. /*==========================================
  2342. * Fills in card data from the given item and into the buffer. [Skotlex]
  2343. *------------------------------------------*/
  2344. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2345. nullpo_retv( buf );
  2346. // Blank data
  2347. if( item == nullptr ){
  2348. buf->card[0] = 0;
  2349. buf->card[1] = 0;
  2350. buf->card[2] = 0;
  2351. buf->card[3] = 0;
  2352. return;
  2353. }
  2354. // Pet eggs
  2355. if( item->card[0] == CARD0_PET ){
  2356. buf->card[0] = 0;
  2357. buf->card[1] = 0;
  2358. // Pet intimacy
  2359. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2360. buf->card[2] = item->card[3] >> 1;
  2361. // Pet renamed flag
  2362. buf->card[3] = item->card[3] & 1;
  2363. return;
  2364. }
  2365. // Forged/created items
  2366. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2367. buf->card[0] = item->card[0];
  2368. buf->card[1] = item->card[1];
  2369. buf->card[2] = item->card[2];
  2370. buf->card[3] = item->card[3];
  2371. return;
  2372. }
  2373. int32 i = 0, j;
  2374. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2375. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2376. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2377. }
  2378. // Normal items.
  2379. for( int32 k = 0; k < 4; k++, i++ ){
  2380. if( item->card[i] > 0 ){
  2381. buf->card[k] = client_nameid( item->card[i] );
  2382. }else{
  2383. buf->card[k] = 0;
  2384. }
  2385. }
  2386. }
  2387. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2388. /// A maximum of 5 random options can be supported.
  2389. static void clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item& it ){
  2390. for( int32 i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2391. if( it.option[i].id ){
  2392. buf[i].index = it.option[i].id; // OptIndex
  2393. buf[i].value = it.option[i].value; // Value
  2394. buf[i].param = it.option[i].param; // Param1
  2395. }else{
  2396. buf[i].index = 0;
  2397. buf[i].value = 0;
  2398. buf[i].param = 0;
  2399. }
  2400. }
  2401. #if MAX_ITEM_RDM_OPT < 5
  2402. for( ; i < 5; i++ ){
  2403. buf[i].index = 0; // OptIndex
  2404. buf[i].value = 0; // Value
  2405. buf[i].param = 0; // Param1
  2406. }
  2407. #endif
  2408. }
  2409. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2410. /// 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)
  2411. /// 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)
  2412. /// 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)
  2413. /// 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)
  2414. /// 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)
  2415. /// 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)
  2416. void clif_additem( map_session_data *sd, int32 n, int32 amount, unsigned char fail ){
  2417. nullpo_retv( sd );
  2418. int32 fd = sd->fd;
  2419. if( !session_isActive( fd ) ){
  2420. return;
  2421. }
  2422. PACKET_ZC_ITEM_PICKUP_ACK p = {};
  2423. if( fail ){
  2424. p = {};
  2425. }else{
  2426. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2427. return;
  2428. }
  2429. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2430. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2431. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2432. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2433. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2434. p.location = pc_equippoint(sd,n);
  2435. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2436. #if PACKETVER >= 20061218
  2437. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2438. #if PACKETVER >= 20071002
  2439. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2440. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2441. */
  2442. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2443. #if PACKETVER >= 20150226
  2444. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[n] );
  2445. #if PACKETVER >= 20160921
  2446. p.favorite = ( sd->inventory.u.items_inventory[n].favorite != 0 ) ? 1 : 0;
  2447. p.look = sd->inventory_data[n]->look;
  2448. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2449. p.grade = sd->inventory.u.items_inventory[n].enchantgrade;
  2450. #endif
  2451. #endif
  2452. #endif
  2453. #endif
  2454. #endif
  2455. }
  2456. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2457. p.Index = client_index( n );
  2458. p.count = amount;
  2459. p.result = fail;
  2460. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2461. }
  2462. /// Notifies the client, that an inventory item was deleted or dropped.
  2463. /// 00af <index>.W <amount>.W (ZC_ITEM_THROW_ACK)
  2464. void clif_dropitem( map_session_data& sd, int32 index, int32 amount ){
  2465. PACKET_ZC_ITEM_THROW_ACK packet{};
  2466. packet.packetType = HEADER_ZC_ITEM_THROW_ACK;
  2467. packet.index = client_index( index );
  2468. packet.count = amount;
  2469. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2470. }
  2471. /// Notifies the client, that an inventory item was deleted.
  2472. /// 07fa <delete type>.W <index>.W <amount>.W (ZC_DELETE_ITEM_FROM_BODY)
  2473. /// delete type:
  2474. /// 0 = Normal
  2475. /// 1 = Item used for a skill
  2476. /// 2 = Refine failed
  2477. /// 3 = Material changed
  2478. /// 4 = Moved to storage
  2479. /// 5 = Moved to cart
  2480. /// 6 = Item sold
  2481. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2482. void clif_delitem( map_session_data& sd, int32 index, int32 amount, int16 reason ){
  2483. #if PACKETVER >= 20091117
  2484. PACKET_ZC_DELETE_ITEM_FROM_BODY packet{};
  2485. packet.packetType = HEADER_ZC_DELETE_ITEM_FROM_BODY;
  2486. packet.deleteType = reason;
  2487. packet.index = client_index( index );
  2488. packet.count = amount;
  2489. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2490. #else
  2491. clif_dropitem( sd, index, amount );
  2492. #endif
  2493. }
  2494. static void clif_item_equip( int16 idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int32 eqp_pos ){
  2495. nullpo_retv( p );
  2496. nullpo_retv( it );
  2497. nullpo_retv( id );
  2498. p->index = idx;
  2499. p->ITID = client_nameid( it->nameid );
  2500. p->type = itemtype( it->nameid );
  2501. #if PACKETVER < 20120925
  2502. p->IsIdentified = it->identify ? 1 : 0;
  2503. #endif
  2504. p->location = eqp_pos;
  2505. p->WearState = it->equip;
  2506. #if PACKETVER < 20120925
  2507. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2508. #endif
  2509. p->RefiningLevel = it->refine;
  2510. clif_addcards( &p->slot, it );
  2511. #if PACKETVER >= 20071002
  2512. p->HireExpireDate = it->expire_time;
  2513. #endif
  2514. #if PACKETVER >= 20080102
  2515. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2516. #endif
  2517. #if PACKETVER >= 20100629
  2518. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2519. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2520. #endif
  2521. #if PACKETVER >= 20120925
  2522. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2523. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2524. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2525. p->Flag.SpareBits = 0;
  2526. #endif
  2527. #if PACKETVER >= 20150226
  2528. clif_add_random_options( p->option_data, *it );
  2529. // Client ingores the value anyway and recalculates it
  2530. p->option_count = 0;
  2531. #endif
  2532. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2533. p->grade = it->enchantgrade;
  2534. #endif
  2535. }
  2536. static void clif_item_normal( int16 idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2537. nullpo_retv(p);
  2538. nullpo_retv(i);
  2539. nullpo_retv(id);
  2540. p->index = idx;
  2541. p->ITID = client_nameid( i->nameid );
  2542. p->type = itemtype( i->nameid );
  2543. #if PACKETVER < 20120925
  2544. p->IsIdentified = i->identify ? 1 : 0;
  2545. #endif
  2546. p->count = i->amount;
  2547. p->WearState = id->equip;
  2548. #if PACKETVER >= 5
  2549. clif_addcards( &p->slot, i );
  2550. #endif
  2551. #if PACKETVER >= 20080102
  2552. p->HireExpireDate = i->expire_time;
  2553. #endif
  2554. #if PACKETVER >= 20120925
  2555. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2556. p->Flag.PlaceETCTab = ( i->favorite != 0 ) ? 1 : 0;
  2557. p->Flag.SpareBits = 0;
  2558. #endif
  2559. }
  2560. static void clif_inventoryStart( map_session_data*sd, e_inventory_type type, const char *name ){
  2561. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2562. nullpo_retv(sd);
  2563. nullpo_retv(name);
  2564. char buf[sizeof(PACKET_ZC_INVENTORY_START) + 24];
  2565. memset(buf, 0, sizeof(buf));
  2566. PACKET_ZC_INVENTORY_START *p = (PACKET_ZC_INVENTORY_START *)buf;
  2567. p->packetType = HEADER_ZC_INVENTORY_START;
  2568. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2569. p->invType = type;
  2570. #endif
  2571. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2572. int32 strLen = (int32)safestrnlen(name, 24) + 1;
  2573. if (strLen > 24)
  2574. strLen = 24;
  2575. const int32 len = sizeof(PACKET_ZC_INVENTORY_START) + strLen;
  2576. p->packetLength = len;
  2577. safestrncpy(p->name, name, strLen);
  2578. #else
  2579. const int32 len = sizeof(PACKET_ZC_INVENTORY_START);
  2580. safestrncpy(p->name, name, NAME_LENGTH);
  2581. #endif
  2582. clif_send( p, len, &sd->bl, SELF );
  2583. #endif
  2584. }
  2585. static void clif_inventoryEnd( map_session_data *sd, e_inventory_type type ){
  2586. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2587. nullpo_retv(sd);
  2588. PACKET_ZC_INVENTORY_END p = {};
  2589. p.packetType = HEADER_ZC_INVENTORY_END;
  2590. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2591. p.invType = type;
  2592. #endif
  2593. p.flag = 0;
  2594. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2595. #endif
  2596. }
  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. int32 equip = 0;
  2607. int32 normal = 0;
  2608. storage_sortitem( sd->storage.u.items_inventory, ARRAYLENGTH( sd->storage.u.items_inventory ) );
  2609. for( int32 i = 0; i < MAX_INVENTORY; i++ ){
  2610. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2611. continue;
  2612. }
  2613. // Non-stackable (Equippable)
  2614. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2615. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2616. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2617. itemlist_equip.PacketType = inventorylistequipType;
  2618. itemlist_equip.PacketLength = static_cast<decltype(itemlist_equip.PacketLength)>( ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip ) );
  2619. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2620. itemlist_equip.invType = type;
  2621. #endif
  2622. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2623. equip = 0;
  2624. }
  2625. // Stackable (Normal)
  2626. }else{
  2627. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2628. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2629. itemlist_normal.PacketType = inventorylistnormalType;
  2630. itemlist_normal.PacketLength = static_cast<decltype(itemlist_normal.PacketLength)>( ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal ) );
  2631. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2632. itemlist_normal.invType = type;
  2633. #endif
  2634. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2635. normal = 0;
  2636. }
  2637. }
  2638. }
  2639. if( normal ){
  2640. itemlist_normal.PacketType = inventorylistnormalType;
  2641. itemlist_normal.PacketLength = static_cast<decltype(itemlist_normal.PacketLength)>( ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal ) );
  2642. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2643. itemlist_normal.invType = type;
  2644. #endif
  2645. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2646. }
  2647. if( sd->equip_index[EQI_AMMO] >= 0 )
  2648. clif_arrowequip( *sd );
  2649. if( equip ) {
  2650. itemlist_equip.PacketType = inventorylistequipType;
  2651. itemlist_equip.PacketLength = static_cast<decltype(itemlist_equip.PacketLength)>( ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip ) );
  2652. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2653. itemlist_equip.invType = type;
  2654. #endif
  2655. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2656. }
  2657. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2658. clif_inventoryEnd( sd, type );
  2659. #endif
  2660. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2661. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2662. for( int32 i = 0; i < MAX_INVENTORY; i++ ){
  2663. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr )
  2664. continue;
  2665. if ( sd->inventory.u.items_inventory[i].favorite != 0 )
  2666. clif_favorite_item( *sd, i );
  2667. }
  2668. #endif
  2669. }
  2670. //Required when items break/get-repaired. Only sends equippable item list.
  2671. void clif_equiplist( map_session_data *sd ){
  2672. // TODO: implement again => only send equip part
  2673. clif_inventorylist( sd );
  2674. }
  2675. void clif_storagelist(map_session_data* sd, struct item* items, int32 items_length, const char *storename){
  2676. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2677. e_inventory_type type = INVTYPE_STORAGE;
  2678. clif_inventoryStart( sd, type, storename );
  2679. #endif
  2680. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2681. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2682. int32 equip = 0;
  2683. int32 normal = 0;
  2684. for( int32 i = 0; i < items_length; i++ ){
  2685. if( items[i].nameid == 0 ){
  2686. continue;
  2687. }
  2688. struct item_data* id = itemdb_search( items[i].nameid );
  2689. // Non-stackable (Equippable)
  2690. if( !itemdb_isstackable2( id ) ){
  2691. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2692. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2693. storage_itemlist_equip.PacketType = storageListEquipType;
  2694. storage_itemlist_equip.PacketLength = static_cast<decltype(storage_itemlist_equip.PacketLength)>( ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip ) );
  2695. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2696. storage_itemlist_equip.invType = type;
  2697. #elif PACKETVER >= 20120925
  2698. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2699. #endif
  2700. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2701. equip = 0;
  2702. }
  2703. // Stackable (Normal)
  2704. }else{
  2705. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2706. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2707. storage_itemlist_normal.PacketType = storageListNormalType;
  2708. storage_itemlist_normal.PacketLength = static_cast<decltype(storage_itemlist_normal.PacketLength)>( ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal ) );
  2709. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2710. storage_itemlist_normal.invType = type;
  2711. #elif PACKETVER >= 20120925
  2712. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2713. #endif
  2714. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2715. normal = 0;
  2716. }
  2717. }
  2718. }
  2719. if( normal ){
  2720. storage_itemlist_normal.PacketType = storageListNormalType;
  2721. storage_itemlist_normal.PacketLength = static_cast<decltype(storage_itemlist_normal.PacketLength)>( ( sizeof( storage_itemlist_normal ) - sizeof( storage_itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal ) );
  2722. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2723. storage_itemlist_normal.invType = type;
  2724. #elif PACKETVER >= 20120925
  2725. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2726. #endif
  2727. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2728. }
  2729. if( equip ) {
  2730. storage_itemlist_equip.PacketType = storageListEquipType;
  2731. storage_itemlist_equip.PacketLength = static_cast<decltype(storage_itemlist_equip.PacketLength)>( ( sizeof( storage_itemlist_equip ) - sizeof( storage_itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip ) );
  2732. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2733. storage_itemlist_equip.invType = type;
  2734. #elif PACKETVER >= 20120925
  2735. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2736. #endif
  2737. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2738. }
  2739. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2740. clif_inventoryEnd( sd, type );
  2741. #endif
  2742. }
  2743. void clif_cartlist( map_session_data *sd ){
  2744. nullpo_retv( sd );
  2745. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2746. e_inventory_type type = INVTYPE_CART;
  2747. clif_inventoryStart( sd, type, "" );
  2748. #endif
  2749. static struct packet_itemlist_normal itemlist_normal;
  2750. static struct packet_itemlist_equip itemlist_equip;
  2751. int32 normal = 0;
  2752. int32 equip = 0;
  2753. storage_sortitem( sd->storage.u.items_cart, ARRAYLENGTH( sd->storage.u.items_cart ) );
  2754. for( int32 i = 0; i < MAX_CART; i++ ){
  2755. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2756. continue;
  2757. }
  2758. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2759. // Non-stackable (Equippable)
  2760. if( !itemdb_isstackable2(id) ){
  2761. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2762. // Stackable (Normal)
  2763. }else{
  2764. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2765. }
  2766. }
  2767. if( normal ){
  2768. itemlist_normal.PacketType = cartlistnormalType;
  2769. itemlist_normal.PacketLength = static_cast<decltype(itemlist_normal.PacketLength)>( ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal ) );
  2770. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2771. itemlist_normal.invType = type;
  2772. #endif
  2773. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2774. }
  2775. if( equip ){
  2776. itemlist_equip.PacketType = cartlistequipType;
  2777. itemlist_equip.PacketLength = static_cast<decltype(itemlist_equip.PacketLength)>( ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip ) );
  2778. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2779. itemlist_equip.invType = type;
  2780. #endif
  2781. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2782. }
  2783. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2784. clif_inventoryEnd( sd, type );
  2785. #endif
  2786. }
  2787. /// Removes cart.
  2788. /// 012b (ZC_CARTOFF)
  2789. /// Client behaviour:
  2790. /// Closes the cart storage and removes all it's items from memory.
  2791. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2792. void clif_clearcart(int32 fd)
  2793. {
  2794. PACKET_ZC_CARTOFF packet{};
  2795. packet.packetType = HEADER_ZC_CARTOFF;
  2796. socket_send<PACKET_ZC_CARTOFF>(fd, packet);
  2797. }
  2798. /// Sends XY location to all other guild members
  2799. /// 01eb <account id>.L <x>.W <y>.W (ZC_NOTIFY_POSITION_TO_GUILDM)
  2800. void clif_guild_xy( map_session_data& sd ){
  2801. PACKET_ZC_NOTIFY_POSITION_TO_GUILDM packet{};
  2802. packet.packetType = HEADER_ZC_NOTIFY_POSITION_TO_GUILDM;
  2803. packet.aid = sd.status.account_id;
  2804. packet.xPos = sd.bl.x;
  2805. packet.yPos = sd.bl.y;
  2806. clif_send(&packet, sizeof(packet), &sd.bl, GUILD_SAMEMAP_WOS);
  2807. }
  2808. /// Sends XY location to a specific guild member
  2809. /// 01eb <account id>.L <x>.W <y>.W (ZC_NOTIFY_POSITION_TO_GUILDM)
  2810. void clif_guild_xy_single( map_session_data& sd, map_session_data& tsd ){
  2811. if( sd.bg_id ){
  2812. return;
  2813. }
  2814. PACKET_ZC_NOTIFY_POSITION_TO_GUILDM packet{};
  2815. packet.packetType = HEADER_ZC_NOTIFY_POSITION_TO_GUILDM;
  2816. packet.aid = sd.status.account_id;
  2817. packet.xPos = sd.bl.x;
  2818. packet.yPos = sd.bl.y;
  2819. clif_send( &packet, sizeof( packet ), &tsd.bl, SELF );
  2820. }
  2821. /// Removes XY location from all other guild members
  2822. /// 01eb <account id>.L <x>.W <y>.W (ZC_NOTIFY_POSITION_TO_GUILDM)
  2823. void clif_guild_xy_remove( map_session_data& sd ){
  2824. PACKET_ZC_NOTIFY_POSITION_TO_GUILDM packet{};
  2825. packet.packetType = HEADER_ZC_NOTIFY_POSITION_TO_GUILDM;
  2826. packet.aid = sd.status.account_id;
  2827. packet.xPos = -1;
  2828. packet.yPos = -1;
  2829. clif_send( &packet, sizeof( packet ), &sd.bl, GUILD_SAMEMAP_WOS );
  2830. }
  2831. /*==========================================
  2832. * Load castle list for guild UI. [Asheraf] / [Balfear]
  2833. *------------------------------------------*/
  2834. void clif_guild_castle_list(map_session_data& sd){
  2835. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2836. auto &g = sd.guild;
  2837. if (g == nullptr)
  2838. return;
  2839. int32 castle_count = guild_checkcastles(g->guild);
  2840. if( castle_count <= 0 ){
  2841. return;
  2842. }
  2843. PACKET_ZC_GUILD_AGIT_INFO* p = reinterpret_cast<PACKET_ZC_GUILD_AGIT_INFO*>( packet_buffer );
  2844. p->packetType = HEADER_ZC_GUILD_AGIT_INFO;
  2845. p->packetLength = sizeof( *p );
  2846. int32 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<decltype(p->packetLength)>( sizeof( p->castle_list[0] ) );
  2851. ++i;
  2852. }
  2853. }
  2854. clif_send(p, p->packetLength, &sd.bl, SELF);
  2855. #endif
  2856. }
  2857. /*==========================================
  2858. * Send castle info Economy/Defence. [Asheraf] / [Balfear]
  2859. *------------------------------------------*/
  2860. void clif_guild_castleinfo(map_session_data& sd, std::shared_ptr<guild_castle> castle ){
  2861. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2862. if( castle->client_id == 0 ){
  2863. return;
  2864. }
  2865. PACKET_ZC_REQ_ACK_AGIT_INVESTMENT p = {};
  2866. p.packetType = HEADER_ZC_REQ_ACK_AGIT_INVESTMENT;
  2867. p.castle_id = static_cast<int8>( castle->client_id );
  2868. p.economy = castle->economy;
  2869. p.defense = castle->defense;
  2870. clif_send(&p, sizeof(p), &sd.bl, SELF);
  2871. #endif
  2872. }
  2873. /*==========================================
  2874. * Show teleport request result. [Asheraf] / [Balfear]
  2875. *------------------------------------------*/
  2876. void clif_guild_castle_teleport_res(map_session_data& sd, enum e_siege_teleport_result result){
  2877. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2878. PACKET_ZC_REQ_ACK_MOVE_GUILD_AGIT p = {};
  2879. p.packetType = HEADER_ZC_REQ_ACK_MOVE_GUILD_AGIT;
  2880. p.result = static_cast<int16>( result );
  2881. clif_send(&p, sizeof(p), &sd.bl, SELF);
  2882. #endif
  2883. }
  2884. /*==========================================
  2885. * Request castle info. [Asheraf] / [Balfear]
  2886. *------------------------------------------*/
  2887. void clif_parse_guild_castle_info_request(int32 fd, map_session_data* sd){
  2888. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515
  2889. if( sd == nullptr ){
  2890. return;
  2891. }
  2892. auto &g = sd->guild;
  2893. if (g == nullptr)
  2894. return;
  2895. const PACKET_CZ_REQ_AGIT_INVESTMENT* p = reinterpret_cast<PACKET_CZ_REQ_AGIT_INVESTMENT*>( RFIFOP( fd, 0 ) );
  2896. std::shared_ptr<guild_castle> gc = castle_db.find_by_clientid( p->castle_id );
  2897. if (gc == nullptr)
  2898. return;
  2899. if (gc->guild_id != g->guild.guild_id)
  2900. return;
  2901. clif_guild_castleinfo(*sd, gc);
  2902. #endif
  2903. }
  2904. /*==========================================
  2905. * Teleport to castle. [Asheraf] / [Balfear]
  2906. *------------------------------------------*/
  2907. void clif_parse_guild_castle_teleport_request(int32 fd, map_session_data* sd){
  2908. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515
  2909. const PACKET_CZ_REQ_MOVE_GUILD_AGIT* p = reinterpret_cast<PACKET_CZ_REQ_MOVE_GUILD_AGIT*>RFIFOP( fd, 0 );
  2910. auto &g = sd->guild;
  2911. if (g == nullptr)
  2912. return;
  2913. std::shared_ptr<guild_castle> gc = castle_db.find_by_clientid( p->castle_id );
  2914. if (gc == nullptr)
  2915. return;
  2916. if (!gc->warp_enabled)
  2917. return;
  2918. if (gc->guild_id != g->guild.guild_id)
  2919. return;
  2920. if (map_getmapflag(sd->bl.m, MF_GVG_CASTLE)
  2921. || map_getmapflag(sd->bl.m, MF_NOTELEPORT)
  2922. || map_getmapflag(sd->bl.m, MF_NOWARP))
  2923. return;
  2924. uint32 zeny = gc->zeny;
  2925. switch( gc->type ){
  2926. case WOE_FIRST_EDITION:
  2927. if( agit_flag ){
  2928. zeny = gc->zeny_siege;
  2929. }
  2930. break;
  2931. case WOE_SECOND_EDITION:
  2932. if( agit2_flag ){
  2933. zeny = gc->zeny_siege;
  2934. }
  2935. break;
  2936. case WOE_THIRD_EDITION:
  2937. if( agit3_flag ){
  2938. zeny = gc->zeny_siege;
  2939. }
  2940. break;
  2941. }
  2942. if (zeny && pc_payzeny(sd, zeny, LOG_TYPE_OTHER)) {
  2943. clif_guild_castle_teleport_res(*sd, SIEGE_TP_NOT_ENOUGH_ZENY);
  2944. return;
  2945. }
  2946. pc_setpos(sd, gc->mapindex, gc->warp_x, gc->warp_y, CLR_OUTSIGHT);
  2947. #endif
  2948. }
  2949. /*==========================================
  2950. *
  2951. *------------------------------------------*/
  2952. static int32 clif_hpmeter_sub( struct block_list *bl, va_list ap ){
  2953. map_session_data* sd = va_arg( ap, map_session_data* );
  2954. map_session_data* tsd = BL_CAST( BL_PC, bl );
  2955. nullpo_ret(sd);
  2956. nullpo_ret(tsd);
  2957. if( pc_has_permission( tsd, PC_PERM_VIEW_HPMETER ) ){
  2958. clif_hpmeter_single( *tsd, sd->status.account_id, sd->battle_status.hp, sd->battle_status.max_hp );
  2959. }
  2960. return 0;
  2961. }
  2962. /*==========================================
  2963. * Server tells all players that are allowed to view HP bars
  2964. * and are nearby 'sd' that 'sd' hp bar was updated.
  2965. *------------------------------------------*/
  2966. static int32 clif_hpmeter(map_session_data *sd)
  2967. {
  2968. nullpo_ret(sd);
  2969. 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);
  2970. return 0;
  2971. }
  2972. /**
  2973. * Send HP bar update to others.
  2974. * @param sd: Player invoking update
  2975. */
  2976. void clif_update_hp(map_session_data &sd) {
  2977. if (map_getmapdata(sd.bl.m)->hpmeter_visible)
  2978. clif_hpmeter(&sd);
  2979. if (!battle_config.party_hp_mode && sd.status.party_id)
  2980. clif_party_hp( sd );
  2981. if (sd.bg_id)
  2982. clif_bg_hp(&sd);
  2983. }
  2984. /// Notifies client of a character parameter change.
  2985. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2986. static void clif_par_change(map_session_data& sd, uint16 varId, int32 count) {
  2987. PACKET_ZC_PAR_CHANGE packet{};
  2988. packet.PacketType = HEADER_ZC_PAR_CHANGE;
  2989. packet.varID = varId;
  2990. packet.count = count;
  2991. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2992. }
  2993. /// Notifies client of a character parameter change.
  2994. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2995. static void clif_longpar_change(map_session_data& sd, uint16 varId, int32 amount) {
  2996. PACKET_ZC_LONGPAR_CHANGE packet{};
  2997. packet.PacketType = HEADER_ZC_LONGPAR_CHANGE;
  2998. packet.varID = varId;
  2999. packet.amount = amount;
  3000. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3001. }
  3002. /// Notifies client of a character parameter change.
  3003. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  3004. static void clif_zc_status_change(map_session_data& sd, uint16 status_id, uint8 value) {
  3005. PACKET_ZC_STATUS_CHANGE packet{};
  3006. packet.PacketType = HEADER_ZC_STATUS_CHANGE;
  3007. packet.statusID = status_id;
  3008. packet.value = value;
  3009. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3010. }
  3011. /// Notifies client of a character parameter change.
  3012. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  3013. static void clif_cartcount( map_session_data& sd ){
  3014. PACKET_ZC_NOTIFY_CARTITEM_COUNTINFO packet{};
  3015. packet.PacketType = HEADER_ZC_NOTIFY_CARTITEM_COUNTINFO;
  3016. packet.curCount = sd.cart_num;
  3017. packet.maxCount = MAX_CART;
  3018. packet.curWeight = sd.cart_weight;
  3019. packet.maxWeight = sd.cart_weight_max;
  3020. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3021. }
  3022. /// Tells the client how far it is allowed to attack (weapon range)
  3023. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  3024. static void clif_attackrange( map_session_data& sd, int16 range ){
  3025. PACKET_ZC_ATTACK_RANGE packet{};
  3026. packet.PacketType = HEADER_ZC_ATTACK_RANGE;
  3027. packet.currentAttRange = range;
  3028. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3029. }
  3030. /// Notifies client of a character parameter change.
  3031. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  3032. static void clif_couplestatus(map_session_data& sd, uint32 status_type, int32 defaultStatus, int32 plusStatus) {
  3033. PACKET_ZC_COUPLESTATUS packet{};
  3034. packet.PacketType = HEADER_ZC_COUPLESTATUS;
  3035. packet.statusType = status_type;
  3036. packet.defaultStatus = defaultStatus;
  3037. packet.plusStatus = plusStatus;
  3038. clif_send(&packet, sizeof(packet), &sd.bl, SELF);
  3039. }
  3040. /// Notifies client of a character parameter change.
  3041. /// 0acb <var id>.W <value>.Q (ZC_LONGLONGPAR_CHANGE)
  3042. static void clif_longlongpar_change(map_session_data& sd, uint16 varId, int64 amount) {
  3043. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  3044. PACKET_ZC_LONGLONGPAR_CHANGE packet{};
  3045. packet.PacketType = HEADER_ZC_LONGLONGPAR_CHANGE;
  3046. packet.varID = varId;
  3047. packet.amount = amount;
  3048. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3049. #endif
  3050. }
  3051. /// Notifies client of a character parameter change.
  3052. void clif_updatestatus( map_session_data& sd, enum _sp type ){
  3053. switch(type){
  3054. case SP_WEIGHT:
  3055. pc_updateweightstatus(&sd);
  3056. clif_par_change(sd, type, sd.weight);
  3057. break;
  3058. case SP_MAXWEIGHT:
  3059. clif_par_change(sd, type, sd.max_weight);
  3060. break;
  3061. case SP_SPEED:
  3062. clif_par_change(sd, type, sd.battle_status.speed);
  3063. break;
  3064. case SP_BASELEVEL:
  3065. clif_par_change(sd, type, sd.status.base_level);
  3066. break;
  3067. case SP_JOBLEVEL:
  3068. clif_par_change(sd, type, sd.status.job_level);
  3069. break;
  3070. case SP_KARMA:
  3071. // Adding this back, I wonder if the client intercepts this - [Lance]
  3072. clif_par_change(sd, type, sd.status.karma);
  3073. break;
  3074. case SP_MANNER:
  3075. clif_par_change(sd, type, sd.status.manner);
  3076. break;
  3077. case SP_STATUSPOINT:
  3078. clif_par_change(sd, type, sd.status.status_point);
  3079. break;
  3080. case SP_SKILLPOINT:
  3081. clif_par_change(sd, type, sd.status.skill_point);
  3082. break;
  3083. case SP_HIT:
  3084. clif_par_change(sd, type, sd.battle_status.hit);
  3085. break;
  3086. case SP_FLEE1:
  3087. clif_par_change(sd, type, sd.battle_status.flee);
  3088. break;
  3089. case SP_FLEE2:
  3090. clif_par_change(sd, type, sd.battle_status.flee2/10);
  3091. break;
  3092. case SP_MAXHP:
  3093. clif_par_change(sd, type, sd.battle_status.max_hp);
  3094. break;
  3095. case SP_MAXSP:
  3096. clif_par_change(sd, type, sd.battle_status.max_sp);
  3097. break;
  3098. case SP_HP:
  3099. // On officials the HP never go below 1, even if you die [Lemongrass]
  3100. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  3101. if (sd.battle_status.hp == 0) {
  3102. clif_par_change(sd, type, (sd.class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd.battle_status.max_hp/2);
  3103. } else {
  3104. clif_par_change(sd, type, sd.battle_status.hp);
  3105. }
  3106. break;
  3107. case SP_SP:
  3108. clif_par_change(sd, type, sd.battle_status.sp);
  3109. break;
  3110. case SP_ASPD:
  3111. clif_par_change(sd, type, sd.battle_status.amotion);
  3112. break;
  3113. case SP_ATK1:
  3114. clif_par_change(sd, type, pc_leftside_atk(&sd));
  3115. break;
  3116. case SP_DEF1:
  3117. clif_par_change(sd, type, pc_leftside_def(&sd));
  3118. break;
  3119. case SP_MDEF1:
  3120. clif_par_change(sd, type, pc_leftside_mdef(&sd));
  3121. break;
  3122. case SP_ATK2:
  3123. clif_par_change(sd, type, pc_rightside_atk(&sd));
  3124. break;
  3125. case SP_DEF2:
  3126. clif_par_change(sd, type, pc_rightside_def(&sd));
  3127. break;
  3128. case SP_MDEF2: {
  3129. //negative check (in case you have something like Berserk active)
  3130. int32 mdef2 = pc_rightside_mdef(&sd);
  3131. #ifndef RENEWAL
  3132. clif_par_change(sd, type, mdef2 < 0 ? 0 : mdef2);
  3133. #else
  3134. clif_par_change(sd, type, mdef2);
  3135. #endif
  3136. }
  3137. break;
  3138. case SP_CRITICAL:
  3139. clif_par_change(sd, type, sd.battle_status.cri/10);
  3140. break;
  3141. case SP_MATK1:
  3142. clif_par_change(sd, type, pc_rightside_matk(&sd));
  3143. break;
  3144. case SP_MATK2:
  3145. clif_par_change(sd, type, pc_leftside_matk(&sd));
  3146. break;
  3147. case SP_ZENY:
  3148. clif_longpar_change(sd, type, sd.status.zeny);
  3149. break;
  3150. #if PACKETVER >= 20170830
  3151. case SP_BASEEXP:
  3152. clif_longlongpar_change(sd, type, client_exp(sd.status.base_exp));
  3153. break;
  3154. case SP_JOBEXP:
  3155. clif_longlongpar_change(sd, type, client_exp(sd.status.job_exp));
  3156. break;
  3157. case SP_NEXTBASEEXP:
  3158. clif_longlongpar_change(sd, type, client_exp(pc_nextbaseexp(&sd)));
  3159. break;
  3160. case SP_NEXTJOBEXP:
  3161. clif_longlongpar_change(sd, type, client_exp(pc_nextjobexp(&sd)));
  3162. break;
  3163. #else
  3164. case SP_BASEEXP:
  3165. clif_longpar_change(sd, type, client_exp(sd.status.base_exp));
  3166. break;
  3167. case SP_JOBEXP:
  3168. clif_longpar_change(sd, type, client_exp(sd.status.job_exp));
  3169. break;
  3170. case SP_NEXTBASEEXP:
  3171. clif_longpar_change(sd, type, client_exp(pc_nextbaseexp(&sd)));
  3172. break;
  3173. case SP_NEXTJOBEXP:
  3174. clif_longpar_change(sd, type, client_exp(pc_nextjobexp(&sd)));
  3175. break;
  3176. #endif
  3177. /**
  3178. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3179. **/
  3180. case SP_USTR:
  3181. case SP_UAGI:
  3182. case SP_UVIT:
  3183. case SP_UINT:
  3184. case SP_UDEX:
  3185. case SP_ULUK:
  3186. clif_zc_status_change(sd, static_cast<uint16>(type), static_cast<uint8>(pc_need_status_point(&sd, type-SP_USTR+SP_STR, 1)));
  3187. break;
  3188. case SP_ATTACKRANGE:
  3189. clif_attackrange( sd, sd.battle_status.rhw.range );
  3190. break;
  3191. case SP_STR:
  3192. clif_couplestatus(sd, type, sd.status.str, sd.battle_status.str - sd.status.str);
  3193. break;
  3194. case SP_AGI:
  3195. clif_couplestatus(sd, type, sd.status.agi, sd.battle_status.agi - sd.status.agi);
  3196. break;
  3197. case SP_VIT:
  3198. clif_couplestatus(sd, type, sd.status.vit, sd.battle_status.vit - sd.status.vit);
  3199. break;
  3200. case SP_INT:
  3201. clif_couplestatus(sd, type, sd.status.int_, sd.battle_status.int_ - sd.status.int_);
  3202. break;
  3203. case SP_DEX:
  3204. clif_couplestatus(sd, type, sd.status.dex, sd.battle_status.dex - sd.status.dex);
  3205. break;
  3206. case SP_LUK:
  3207. clif_couplestatus(sd, type, sd.status.luk, sd.battle_status.luk - sd.status.luk);
  3208. break;
  3209. case SP_CARTINFO:
  3210. clif_cartcount( sd );
  3211. break;
  3212. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3213. case SP_AP:
  3214. clif_par_change( sd, SP_AP, sd.battle_status.ap );
  3215. break;
  3216. case SP_TRAITPOINT:
  3217. clif_par_change( sd, SP_TRAITPOINT, sd.status.trait_point );
  3218. break;
  3219. case SP_MAXAP:
  3220. clif_par_change( sd, SP_MAXAP, sd.battle_status.max_ap );
  3221. break;
  3222. case SP_POW:
  3223. clif_couplestatus( sd, SP_POW, sd.status.pow, sd.battle_status.pow - sd.status.pow );
  3224. break;
  3225. case SP_STA:
  3226. clif_couplestatus( sd, SP_STA, sd.status.sta, sd.battle_status.sta - sd.status.sta );
  3227. break;
  3228. case SP_WIS:
  3229. clif_couplestatus( sd, SP_WIS, sd.status.wis, sd.battle_status.wis - sd.status.wis );
  3230. break;
  3231. case SP_SPL:
  3232. clif_couplestatus( sd, SP_SPL, sd.status.spl, sd.battle_status.spl - sd.status.spl );
  3233. break;
  3234. case SP_CON:
  3235. clif_couplestatus( sd, SP_CON, sd.status.con, sd.battle_status.con - sd.status.con );
  3236. break;
  3237. case SP_CRT:
  3238. clif_couplestatus( sd, SP_CRT, sd.status.crt, sd.battle_status.crt - sd.status.crt );
  3239. break;
  3240. case SP_UPOW:
  3241. case SP_USTA:
  3242. case SP_UWIS:
  3243. case SP_USPL:
  3244. case SP_UCON:
  3245. case SP_UCRT:
  3246. clif_zc_status_change( sd, static_cast<uint16>( type ), static_cast<uint8>( pc_need_trait_point( &sd, type - SP_UPOW + SP_POW, 1 ) ) );
  3247. break;
  3248. case SP_PATK:
  3249. clif_par_change( sd, SP_PATK, sd.battle_status.patk );
  3250. break;
  3251. case SP_SMATK:
  3252. clif_par_change( sd, SP_SMATK, sd.battle_status.smatk );
  3253. break;
  3254. case SP_RES:
  3255. clif_par_change( sd, SP_RES, sd.battle_status.res );
  3256. break;
  3257. case SP_MRES:
  3258. clif_par_change( sd, SP_MRES, sd.battle_status.mres );
  3259. break;
  3260. case SP_HPLUS:
  3261. clif_par_change( sd, SP_HPLUS, sd.battle_status.hplus );
  3262. break;
  3263. case SP_CRATE:
  3264. clif_par_change( sd, SP_CRATE, sd.battle_status.crate );
  3265. break;
  3266. #else
  3267. case SP_AP:
  3268. case SP_TRAITPOINT:
  3269. case SP_MAXAP:
  3270. case SP_POW:
  3271. case SP_STA:
  3272. case SP_WIS:
  3273. case SP_SPL:
  3274. case SP_CON:
  3275. case SP_CRT:
  3276. case SP_UPOW:
  3277. case SP_USTA:
  3278. case SP_UWIS:
  3279. case SP_USPL:
  3280. case SP_UCON:
  3281. case SP_UCRT:
  3282. case SP_PATK:
  3283. case SP_SMATK:
  3284. case SP_RES:
  3285. case SP_MRES:
  3286. case SP_HPLUS:
  3287. case SP_CRATE:
  3288. // 4th job status are not supported by older clients
  3289. return;
  3290. #endif
  3291. default:
  3292. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3293. return;
  3294. }
  3295. // Additional update packets that should be sent right after
  3296. switch( type ){
  3297. case SP_BASELEVEL:
  3298. if( sd.status.party_id ){
  3299. struct party_data* p;
  3300. int32 i;
  3301. if( ( p = party_search( sd.status.party_id ) ) != nullptr ){
  3302. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd.status.char_id);
  3303. if( i < MAX_PARTY ){
  3304. p->party.member[i].lv = sd.status.base_level;
  3305. clif_party_job_and_level( sd );
  3306. }
  3307. }
  3308. }
  3309. break;
  3310. case SP_HP:
  3311. clif_update_hp( sd );
  3312. break;
  3313. }
  3314. }
  3315. /// Notifies client of a parameter change of an another player.
  3316. /// 01ab <account id>.L <var id>.W <value>.L (ZC_PAR_CHANGE_USER)
  3317. /// var id:
  3318. /// SP_MANNER
  3319. /// ?
  3320. void clif_changemanner( map_session_data& sd ) {
  3321. PACKET_ZC_PAR_CHANGE_USER packet{};
  3322. packet.packetType = HEADER_ZC_PAR_CHANGE_USER;
  3323. packet.gid = sd.bl.id;
  3324. packet.type = static_cast<decltype(packet.type)>(SP_MANNER);
  3325. packet.value = sd.status.manner;
  3326. clif_send( &packet, sizeof( packet ), &sd.bl, AREA_WOS );
  3327. }
  3328. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3329. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3330. void clif_sprite_change( struct block_list *bl, int32 id, int32 type, int32 val, int32 val2, enum send_target target ){
  3331. PACKET_ZC_SPRITE_CHANGE p = {};
  3332. p.packetType = sendLookType;
  3333. p.AID = id;
  3334. p.type = type;
  3335. p.val = val;
  3336. #if PACKETVER >= 4
  3337. p.val2 = val2;
  3338. #endif
  3339. clif_send( &p, sizeof( p ), bl, target );
  3340. }
  3341. /// Updates sprite/style properties of an object.
  3342. void clif_changelook(struct block_list *bl, int32 type, int32 val) {
  3343. map_session_data* sd;
  3344. status_change* sc;
  3345. struct view_data* vd;
  3346. enum send_target target = AREA;
  3347. int32 val2 = 0;
  3348. nullpo_retv(bl);
  3349. sd = BL_CAST(BL_PC, bl);
  3350. sc = status_get_sc(bl);
  3351. vd = status_get_viewdata(bl);
  3352. if( vd ) //temp hack to let Warp Portal change appearance
  3353. switch(type) {
  3354. case LOOK_WEAPON:
  3355. if (sd) {
  3356. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3357. val = vd->weapon;
  3358. }
  3359. else
  3360. vd->weapon = val;
  3361. break;
  3362. case LOOK_SHIELD:
  3363. if (sd) {
  3364. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3365. val = vd->shield;
  3366. }
  3367. else
  3368. vd->shield = val;
  3369. break;
  3370. case LOOK_BASE:
  3371. if (!sd)
  3372. break;
  3373. if ( val == JT_INVISIBLE )
  3374. return;
  3375. if (sd->sc.option&OPTION_COSTUME)
  3376. vd->weapon = vd->shield = 0;
  3377. if (!vd->cloth_color)
  3378. break;
  3379. if (sd) {
  3380. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3381. vd->cloth_color = 0;
  3382. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3383. vd->cloth_color = 0;
  3384. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3385. vd->cloth_color = 0;
  3386. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3387. vd->cloth_color = 0;
  3388. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3389. vd->cloth_color = 0;
  3390. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3391. vd->body_style = 0;
  3392. }
  3393. break;
  3394. case LOOK_HAIR:
  3395. vd->hair_style = val;
  3396. break;
  3397. case LOOK_HEAD_BOTTOM:
  3398. vd->head_bottom = val;
  3399. break;
  3400. case LOOK_HEAD_TOP:
  3401. vd->head_top = val;
  3402. break;
  3403. case LOOK_HEAD_MID:
  3404. vd->head_mid = val;
  3405. break;
  3406. case LOOK_HAIR_COLOR:
  3407. vd->hair_color = val;
  3408. break;
  3409. case LOOK_CLOTHES_COLOR:
  3410. if (val && sd) {
  3411. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3412. val = 0;
  3413. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3414. val = 0;
  3415. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3416. val = 0;
  3417. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3418. val = 0;
  3419. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3420. val = 0;
  3421. }
  3422. vd->cloth_color = val;
  3423. break;
  3424. case LOOK_SHOES:
  3425. #if PACKETVER > 3
  3426. if (sd) {
  3427. int32 n;
  3428. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3429. if(sd->inventory_data[n]->view_id > 0)
  3430. val = sd->inventory_data[n]->view_id;
  3431. else
  3432. val = sd->inventory.u.items_inventory[n].nameid;
  3433. } else
  3434. val = 0;
  3435. }
  3436. #endif
  3437. //Shoes? No packet uses this....
  3438. break;
  3439. case LOOK_BODY:
  3440. // unknown purpose
  3441. break;
  3442. case LOOK_ROBE:
  3443. #if PACKETVER < 20110111
  3444. return;
  3445. #else
  3446. vd->robe = val;
  3447. #endif
  3448. break;
  3449. case LOOK_BODY2:
  3450. #if PACKETVER < 20150513
  3451. return;
  3452. #else
  3453. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3454. val = 0;
  3455. vd->body_style = val;
  3456. #endif
  3457. break;
  3458. }
  3459. // prevent leaking the presence of GM-hidden objects
  3460. if( sc && sc->option&OPTION_INVISIBLE )
  3461. target = SELF;
  3462. #if PACKETVER < 4
  3463. if (target != SELF && bl->type == BL_NPC && (((TBL_NPC*)bl)->is_invisible))
  3464. target = SELF;
  3465. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3466. #else
  3467. if (bl->type != BL_NPC) {
  3468. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3469. type = LOOK_WEAPON;
  3470. val = (vd ? vd->weapon : 0);
  3471. val2 = (vd ? vd->shield : 0);
  3472. }
  3473. if (disguised(bl)) {
  3474. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3475. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3476. } else
  3477. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3478. } else
  3479. unit_refresh(bl);
  3480. #endif
  3481. }
  3482. //Sends a change-base-look packet required for traps as they are triggered.
  3483. void clif_changetraplook(struct block_list *bl,int32 val) {
  3484. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3485. }
  3486. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3487. void clif_refreshlook(struct block_list *bl, int32 id, int32 type, int32 val, enum send_target target) {
  3488. clif_sprite_change(bl, id, type, val, 0, target);
  3489. }
  3490. /// Character status (ZC_STATUS).
  3491. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3492. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3493. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3494. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3495. void clif_initialstatus( map_session_data& sd ) {
  3496. PACKET_ZC_STATUS packet{};
  3497. packet.packetType = HEADER_ZC_STATUS;
  3498. packet.point = min(sd.status.status_point, INT16_MAX);
  3499. packet.str = min(sd.status.str, UINT8_MAX);
  3500. packet.standardStr = pc_need_status_point( &sd, SP_STR, 1 );
  3501. packet.agi = min(sd.status.agi, UINT8_MAX);
  3502. packet.standardAgi = pc_need_status_point( &sd, SP_AGI,1 );
  3503. packet.vit = min(sd.status.vit, UINT8_MAX);
  3504. packet.standardVit = pc_need_status_point( &sd, SP_VIT,1 );
  3505. packet.int_ = min(sd.status.int_, UINT8_MAX);
  3506. packet.standardInt = pc_need_status_point( &sd, SP_INT,1 );
  3507. packet.dex = min(sd.status.dex, UINT8_MAX);
  3508. packet.standardDex = pc_need_status_point( &sd, SP_DEX,1 );
  3509. packet.luk = min(sd.status.luk, UINT8_MAX);
  3510. packet.standardLuk = pc_need_status_point( &sd, SP_LUK,1 );
  3511. packet.attPower = pc_leftside_atk( &sd );
  3512. packet.refiningPower = pc_rightside_atk( &sd );
  3513. packet.max_mattPower = pc_rightside_matk( &sd );
  3514. packet.min_mattPower = pc_leftside_matk( &sd );
  3515. packet.itemdefPower = pc_leftside_def( &sd );
  3516. packet.plusdefPower = pc_rightside_def( &sd );
  3517. packet.mdefPower = pc_leftside_mdef( &sd );
  3518. #ifdef RENEWAL
  3519. packet.plusmdefPower = pc_rightside_mdef( &sd );
  3520. #else
  3521. // Negative check for Frenzy'ed characters.
  3522. packet.plusmdefPower = std::max( pc_rightside_mdef( &sd ), 0 );
  3523. #endif
  3524. packet.hitSuccessValue = sd.battle_status.hit;
  3525. packet.avoidSuccessValue = sd.battle_status.flee;
  3526. packet.plusAvoidSuccessValue = sd.battle_status.flee2 / 10;
  3527. packet.criticalSuccessValue = sd.battle_status.cri / 10;
  3528. packet.ASPD = sd.battle_status.amotion;
  3529. packet.plusASPD = 0;
  3530. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3531. clif_updatestatus(sd, SP_STR);
  3532. clif_updatestatus(sd, SP_AGI);
  3533. clif_updatestatus(sd, SP_VIT);
  3534. clif_updatestatus(sd, SP_INT);
  3535. clif_updatestatus(sd, SP_DEX);
  3536. clif_updatestatus(sd, SP_LUK);
  3537. clif_updatestatus(sd, SP_ATTACKRANGE);
  3538. clif_updatestatus(sd, SP_ASPD);
  3539. #ifdef RENEWAL
  3540. clif_updatestatus(sd, SP_POW);
  3541. clif_updatestatus(sd, SP_STA);
  3542. clif_updatestatus(sd, SP_WIS);
  3543. clif_updatestatus(sd, SP_SPL);
  3544. clif_updatestatus(sd, SP_CON);
  3545. clif_updatestatus(sd, SP_CRT);
  3546. clif_updatestatus(sd, SP_PATK);
  3547. clif_updatestatus(sd, SP_SMATK);
  3548. clif_updatestatus(sd, SP_RES);
  3549. clif_updatestatus(sd, SP_MRES);
  3550. clif_updatestatus(sd, SP_HPLUS);
  3551. clif_updatestatus(sd, SP_CRATE);
  3552. clif_updatestatus(sd, SP_TRAITPOINT);
  3553. clif_updatestatus(sd, SP_AP);
  3554. clif_updatestatus(sd, SP_MAXAP);
  3555. clif_updatestatus(sd, SP_UPOW);
  3556. clif_updatestatus(sd, SP_USTA);
  3557. clif_updatestatus(sd, SP_UWIS);
  3558. clif_updatestatus(sd, SP_USPL);
  3559. clif_updatestatus(sd, SP_UCON);
  3560. clif_updatestatus(sd, SP_UCRT);
  3561. #endif
  3562. }
  3563. /// Marks an ammunition item in inventory as equipped.
  3564. /// 013c <index>.W (ZC_EQUIP_ARROW)
  3565. void clif_arrowequip( map_session_data& sd ) {
  3566. #if PACKETVER >= 20121128
  3567. clif_status_change(&sd.bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3568. #endif
  3569. PACKET_ZC_EQUIP_ARROW packet{};
  3570. packet.packetType = HEADER_ZC_EQUIP_ARROW;
  3571. // Inventory index of the arrow
  3572. packet.index = client_index( sd.equip_index[EQI_AMMO] );
  3573. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3574. }
  3575. /// Ammunition action message.
  3576. /// 013b <type>.W (ZC_ACTION_FAILURE)
  3577. /// type:
  3578. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3579. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3580. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3581. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3582. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3583. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3584. void clif_arrow_fail( map_session_data& sd, e_action_failure type ) {
  3585. PACKET_ZC_ACTION_FAILURE packet{};
  3586. packet.packetType = HEADER_ZC_ACTION_FAILURE;
  3587. packet.type = static_cast<decltype(packet.type)>(type);
  3588. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3589. }
  3590. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3591. /// 01ad <packet len>.W { <name id>.W }*
  3592. void clif_arrow_create_list( map_session_data& sd ){
  3593. PACKET_ZC_MAKINGARROW_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGARROW_LIST*>( packet_buffer );
  3594. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3595. p->packetLength = sizeof( *p );
  3596. int32 count = 0;
  3597. for (const auto &it : skill_arrow_db) {
  3598. t_itemid nameid = it.second->nameid;
  3599. if( !item_db.exists( nameid ) ){
  3600. continue;
  3601. }
  3602. int32 index = pc_search_inventory( &sd, nameid );
  3603. if( index < 0 ){
  3604. continue;
  3605. }
  3606. if( sd.inventory.u.items_inventory[index].equip ){
  3607. continue;
  3608. }
  3609. if( !sd.inventory.u.items_inventory[index].identify ){
  3610. continue;
  3611. }
  3612. p->items[count].itemId = client_nameid( nameid );
  3613. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  3614. count++;
  3615. }
  3616. clif_send( p, p->packetLength, &sd.bl, SELF );
  3617. if( count > 0 ){
  3618. sd.menuskill_id = AC_MAKINGARROW;
  3619. sd.menuskill_val = count;
  3620. }
  3621. }
  3622. /// Notifies the client, about the result of an status change request.
  3623. /// 00bc <status id>.W <result>.B <value>.B (ZC_STATUS_CHANGE_ACK)
  3624. /// status id:
  3625. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3626. /// result:
  3627. /// 0 = failure
  3628. /// 1 = success
  3629. void clif_statusupack( map_session_data& sd, int32 type, bool success, int32 val ) {
  3630. PACKET_ZC_STATUS_CHANGE_ACK packet{};
  3631. packet.packetType = HEADER_ZC_STATUS_CHANGE_ACK;
  3632. packet.sp = static_cast<decltype(packet.sp)>(type);
  3633. packet.ok = success;
  3634. packet.value = cap_value(val, 0, UINT8_MAX);
  3635. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3636. }
  3637. /// Notifies the client about the result of a request to equip an item.
  3638. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3639. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3640. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3641. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3642. /// @ok: //inversed forv2 v5
  3643. /// 0 = failure
  3644. /// 1 = success
  3645. /// 2 = failure due to low level
  3646. void clif_equipitemack( map_session_data& sd, uint8 flag, int32 index, int32 pos ){
  3647. PACKET_ZC_REQ_WEAR_EQUIP_ACK p = {};
  3648. p.PacketType = HEADER_ZC_REQ_WEAR_EQUIP_ACK;
  3649. p.index = client_index( index );
  3650. p.wearLocation = pos;
  3651. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20100629
  3652. if( flag == ITEM_EQUIP_ACK_OK && sd.inventory_data[index]->equip&EQP_VISIBLE ){
  3653. p.wItemSpriteNumber = sd.inventory_data[index]->look;
  3654. }else{
  3655. p.wItemSpriteNumber = 0;
  3656. }
  3657. #endif
  3658. p.result = flag;
  3659. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  3660. }
  3661. /// Notifies the client about the result of a request to take off an item.
  3662. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3663. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3664. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3665. /// @success : //inversed for v2 v5
  3666. /// 0 = failure
  3667. /// 1 = success
  3668. void clif_unequipitemack( map_session_data& sd, uint16 server_index, int32 pos, bool success ){
  3669. #if PACKETVER >= 20110824
  3670. success = !success;
  3671. #endif
  3672. PACKET_ZC_REQ_TAKEOFF_EQUIP_ACK p{};
  3673. p.packetType = HEADER_ZC_REQ_TAKEOFF_EQUIP_ACK;
  3674. p.index = client_index(server_index);
  3675. p.wearLocation = static_cast<decltype(p.wearLocation)>(pos);
  3676. p.flag = success;
  3677. clif_send(&p,sizeof(p),&sd.bl,SELF);
  3678. }
  3679. /// Notifies clients in the area about an special/visual effect.
  3680. /// 019b <id>.L <effect id>.L (ZC_NOTIFY_EFFECT)
  3681. /// effect id:
  3682. /// 0 = base level up
  3683. /// 1 = job level up
  3684. /// 2 = refine failure
  3685. /// 3 = refine success
  3686. /// 4 = game over
  3687. /// 5 = pharmacy success
  3688. /// 6 = pharmacy failure
  3689. /// 7 = base level up (super novice)
  3690. /// 8 = job level up (super novice)
  3691. /// 9 = base level up (taekwon)
  3692. void clif_misceffect( block_list& bl, e_notify_effect type ){
  3693. PACKET_ZC_NOTIFY_EFFECT packet{};
  3694. packet.packetType = HEADER_ZC_NOTIFY_EFFECT;
  3695. packet.aid = bl.id;
  3696. packet.effectId = static_cast<decltype(packet.effectId)>(type);
  3697. clif_send( &packet, sizeof( packet ), &bl, AREA );
  3698. }
  3699. /// Notifies clients in the area of a state change.
  3700. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3701. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3702. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3703. nullpo_retv( bl );
  3704. status_change* sc = status_get_sc( bl );
  3705. //How can an option change if there's no sc?
  3706. if( sc == nullptr ){
  3707. return;
  3708. }
  3709. map_session_data* sd = BL_CAST( BL_PC, bl );
  3710. PACKET_ZC_STATE_CHANGE p = {};
  3711. p.packetType = HEADER_ZC_STATE_CHANGE;
  3712. p.AID = bl->id;
  3713. p.bodyState = sc->opt1;
  3714. p.healthState = sc->opt2;
  3715. p.effectState = sc->option;
  3716. p.isPKModeON = sd ? sd->status.karma : false;
  3717. if( target == nullptr ){
  3718. if( disguised( bl ) ){
  3719. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3720. p.AID = disguised_bl_id( p.AID );
  3721. clif_send( &p, sizeof( p ), bl, SELF );
  3722. p.AID = disguised_bl_id( p.AID );
  3723. p.effectState = OPTION_INVISIBLE;
  3724. clif_send( &p, sizeof( p ), bl, SELF );
  3725. }else{
  3726. clif_send( &p, sizeof( p ), bl, AREA );
  3727. }
  3728. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3729. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3730. if( sc->getSCE(SC_PROVOKE) ){
  3731. const struct TimerData *td = get_timer( sc->getSCE(SC_PROVOKE)->timer );
  3732. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3733. }
  3734. }else{
  3735. if( disguised( bl ) ){
  3736. p.AID = disguised_bl_id( p.AID );
  3737. clif_send( &p, sizeof( p ), target, SELF );
  3738. p.AID = disguised_bl_id( p.AID );
  3739. p.effectState = OPTION_INVISIBLE;
  3740. clif_send( &p, sizeof( p ), target, SELF );
  3741. }else{
  3742. clif_send( &p, sizeof( p ), target, SELF );
  3743. }
  3744. }
  3745. }
  3746. /// Displays status change effects on NPCs/monsters.
  3747. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L (ZC_NPC_SHOWEFST_UPDATE)
  3748. void clif_changeoption2( block_list& bl ){
  3749. status_change *sc = status_get_sc(&bl);
  3750. if (!sc)
  3751. return; //How can an option change if there's no sc?
  3752. PACKET_ZC_NPC_SHOWEFST_UPDATE packet{};
  3753. packet.packetType = HEADER_ZC_NPC_SHOWEFST_UPDATE;
  3754. packet.gid = bl.id;
  3755. packet.effectState = sc->option;
  3756. packet.level = clif_setlevel(&bl);
  3757. packet.showEFST = sc->opt3;
  3758. if (disguised(&bl)) {
  3759. clif_send( &packet, sizeof( packet ), &bl, AREA_WOS );
  3760. packet.gid = disguised_bl_id( bl.id );
  3761. clif_send( &packet, sizeof( packet ), &bl, SELF );
  3762. packet.gid = bl.id;
  3763. packet.effectState = OPTION_INVISIBLE;
  3764. clif_send( &packet, sizeof( packet ), &bl, SELF );
  3765. } else {
  3766. clif_send( &packet, sizeof( packet ), &bl, AREA );
  3767. }
  3768. }
  3769. /// Notifies the client about the result of an item use request.
  3770. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3771. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3772. void clif_useitemack( map_session_data *sd, int32 index, int32 amount, bool ok ){
  3773. nullpo_retv( sd );
  3774. int32 fd = sd->fd;
  3775. if( !session_isActive( fd ) ){
  3776. return;
  3777. }
  3778. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3779. return;
  3780. }
  3781. PACKET_ZC_USE_ITEM_ACK p = {};
  3782. p.packetType = useItemAckType;
  3783. p.index = index + 2;
  3784. #if PACKETVER > 3
  3785. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3786. p.AID = sd->bl.id;
  3787. #endif
  3788. p.amount = amount;
  3789. p.result = ok;
  3790. if( !ok ){
  3791. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3792. }else{
  3793. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3794. }
  3795. }
  3796. /// Inform client whether chatroom creation was successful or not.
  3797. /// 00d6 <flag>.B (ZC_ACK_CREATE_CHATROOM)
  3798. /// flag:
  3799. /// 0 = Room has been successfully created (opens chat room)
  3800. /// 1 = Room limit exceeded
  3801. /// 2 = Same room already exists
  3802. void clif_createchat( map_session_data& sd, e_create_chatroom flag ){
  3803. PACKET_ZC_ACK_CREATE_CHATROOM packet{};
  3804. packet.packetType = HEADER_ZC_ACK_CREATE_CHATROOM;
  3805. packet.flag = static_cast<decltype(packet.flag)>(flag);
  3806. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3807. }
  3808. /// Calculates the chat status
  3809. /// type:
  3810. /// 0 = private (password protected)
  3811. /// 1 = public
  3812. /// 2 = arena (npc waiting room)
  3813. /// 3 = PK zone (non-clickable)
  3814. static e_status_chatroom clif_chat_status( const chat_data &cd ){
  3815. if (cd.owner->type == BL_PC)
  3816. return (cd.pub) ? STATUSROOM_PUBLIC : STATUSROOM_PRIVATE;
  3817. else if (cd.owner->type == BL_NPC)
  3818. return (cd.limit) ? STATUSROOM_ARENA : STATUSROOM_PK_ZONE;
  3819. else
  3820. return STATUSROOM_PUBLIC;
  3821. }
  3822. /// Calculates the chat user count
  3823. static uint16 clif_chat_usercount( const chat_data& cd ){
  3824. if( cd.owner->type == BL_NPC ){
  3825. return cd.users + 1;
  3826. }else{
  3827. return cd.users;
  3828. }
  3829. }
  3830. /// Display a chat above the owner.
  3831. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B (ZC_ROOM_NEWENTRY)
  3832. void clif_dispchat( const chat_data& cd ){
  3833. if( cd.owner == nullptr ){
  3834. return;
  3835. }
  3836. PACKET_ZC_ROOM_NEWENTRY* p = reinterpret_cast<PACKET_ZC_ROOM_NEWENTRY*>( packet_buffer );
  3837. p->packetType = HEADER_ZC_ROOM_NEWENTRY;
  3838. p->packetSize = sizeof( *p );
  3839. p->owner = cd.owner->id;
  3840. p->id = cd.bl.id;
  3841. p->limit = cd.limit;
  3842. p->users = clif_chat_usercount( cd );
  3843. p->type = clif_chat_status( cd );
  3844. // not zero-terminated
  3845. size_t max = safestrnlen( cd.title, CHATROOM_TITLE_SIZE );
  3846. strncpy( p->title, cd.title, max );
  3847. p->packetSize += static_cast<decltype(p->packetSize)>( max );
  3848. clif_send( p, p->packetSize, cd.owner, AREA_WOSC );
  3849. }
  3850. /// Chatroom properties adjustment.
  3851. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B (ZC_CHANGE_CHATROOM)
  3852. void clif_changechatstatus(chat_data& cd) {
  3853. if( cd.owner == nullptr ){
  3854. return;
  3855. }
  3856. PACKET_ZC_CHANGE_CHATROOM* p = reinterpret_cast<PACKET_ZC_CHANGE_CHATROOM*>( packet_buffer );
  3857. p->packetType = HEADER_ZC_CHANGE_CHATROOM;
  3858. p->packetSize = sizeof(*p);
  3859. p->ownerId = cd.owner->id;
  3860. p->chatId = cd.bl.id;
  3861. p->limit = cd.limit;
  3862. p->users = clif_chat_usercount( cd );
  3863. p->flag = clif_chat_status( cd );
  3864. // not zero-terminated
  3865. size_t max = safestrnlen( cd.title, CHATROOM_TITLE_SIZE );
  3866. strncpy( p->title, cd.title, max );
  3867. p->packetSize += static_cast<decltype(p->packetSize)>( max );
  3868. clif_send(p,p->packetSize,cd.owner,CHAT);
  3869. }
  3870. /// Removes the chatroom
  3871. /// 00d8 <chat id>.L (ZC_DESTROY_ROOM)
  3872. void clif_clearchat(chat_data &cd){
  3873. PACKET_ZC_DESTROY_ROOM p{};
  3874. p.packetType = HEADER_ZC_DESTROY_ROOM;
  3875. p.chatId = cd.bl.id;
  3876. clif_send(&p,sizeof(p),cd.owner,AREA_WOSC);
  3877. }
  3878. /// Displays messages regarding join chat failures.
  3879. /// 00da <result>.B (ZC_REFUSE_ENTER_ROOM)
  3880. /// result:
  3881. /// 0 = room full
  3882. /// 1 = wrong password
  3883. /// 2 = kicked
  3884. /// 3 = success (no message)
  3885. /// 4 = no enough zeny
  3886. /// 5 = too low level
  3887. /// 6 = too high level
  3888. /// 7 = unsuitable job class
  3889. void clif_joinchatfail( map_session_data& sd, e_refuse_enter_room result ){
  3890. PACKET_ZC_REFUSE_ENTER_ROOM packet{};
  3891. packet.packetType = HEADER_ZC_REFUSE_ENTER_ROOM;
  3892. packet.result = static_cast<decltype(packet.result)>(result);
  3893. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3894. }
  3895. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3896. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3897. /// role:
  3898. /// 0 = owner (menu)
  3899. /// 1 = normal
  3900. void clif_joinchatok(map_session_data& sd, chat_data& cd){
  3901. PACKET_ZC_ENTER_ROOM* p = reinterpret_cast<PACKET_ZC_ENTER_ROOM*>( packet_buffer );
  3902. p->packetType = HEADER_ZC_ENTER_ROOM;
  3903. p->packetSize = sizeof(*p);
  3904. p->chatId = cd.bl.id;
  3905. if(cd.owner->type == BL_NPC){
  3906. PACKET_ZC_ENTER_ROOM_sub& owner = p->members[0];
  3907. owner.flag = 0;
  3908. safestrncpy(owner.name, reinterpret_cast<npc_data*>(cd.owner)->name, sizeof(owner.name));
  3909. p->packetSize += static_cast<decltype(p->packetSize)>( sizeof( owner ) );
  3910. for (size_t i = 0; i < cd.users; i++) {
  3911. PACKET_ZC_ENTER_ROOM_sub& member = p->members[i + 1];
  3912. member.flag = 1;
  3913. safestrncpy(member.name, cd.usersd[i]->status.name, sizeof(member.name));
  3914. p->packetSize += static_cast<decltype(p->packetSize)>( sizeof( member ) );
  3915. }
  3916. }else{
  3917. for (size_t i = 0; i < cd.users; i++) {
  3918. PACKET_ZC_ENTER_ROOM_sub& member = p->members[i];
  3919. member.flag = i > 0;
  3920. safestrncpy(member.name, cd.usersd[i]->status.name, sizeof(member.name));
  3921. p->packetSize += static_cast<decltype(p->packetSize)>( sizeof( member ) );
  3922. }
  3923. }
  3924. clif_send(p,p->packetSize,&sd.bl,SELF);
  3925. }
  3926. /// Notifies clients in a chat about a new member.
  3927. /// 00dc <users>.W <name>.24B (ZC_MEMBER_NEWENTRY)
  3928. void clif_addchat( chat_data& cd, map_session_data& sd ){
  3929. PACKET_ZC_MEMBER_NEWENTRY p = {};
  3930. p.packetType = HEADER_ZC_MEMBER_NEWENTRY;
  3931. p.count = cd.users;
  3932. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  3933. clif_send( &p, sizeof( p ), &sd.bl, CHAT_WOS );
  3934. }
  3935. /// Announce the new owner.
  3936. /// 00e1 <role>.L <nick>.24B (ZC_ROLE_CHANGE)
  3937. /// role:
  3938. /// 0 = owner (menu)
  3939. /// 1 = normal
  3940. void clif_chat_role( chat_data& cd, map_session_data& sd ){
  3941. PACKET_ZC_ROLE_CHANGE p = {};
  3942. p.packetType = HEADER_ZC_ROLE_CHANGE;
  3943. p.flag = cd.usersd[0] != &sd;
  3944. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  3945. clif_send( &p, sizeof( p ), &sd.bl, CHAT );
  3946. }
  3947. /// Notify about user leaving the chatroom.
  3948. /// 00dd <users>.W <nick>.24B <flag>.B (ZC_MEMBER_EXIT)
  3949. /// flag:
  3950. /// 0 = left
  3951. /// 1 = kicked
  3952. void clif_chat_leave( chat_data& cd, map_session_data& sd, bool kicked ){
  3953. PACKET_ZC_MEMBER_EXIT p = {};
  3954. p.packetType = HEADER_ZC_MEMBER_EXIT;
  3955. p.count = cd.users - 1;
  3956. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  3957. p.kicked = kicked;
  3958. clif_send( &p, sizeof( p ), &sd.bl, CHAT );
  3959. }
  3960. /// Opens a trade request window from char 'name'.
  3961. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3962. /// 01f4 <nick>.24B <targetid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3963. void clif_traderequest(map_session_data& sd, const char* name){
  3964. PACKET_ZC_REQ_EXCHANGE_ITEM p{};
  3965. p.packetType = HEADER_ZC_REQ_EXCHANGE_ITEM;
  3966. safestrncpy(p.requesterName, name, sizeof(p.requesterName));
  3967. #if PACKETVER > 6
  3968. p.targetId = sd.trade_partner.id; // Client generates a random char[5] with this info
  3969. p.targetLv = sd.trade_partner.lv;
  3970. #endif
  3971. clif_send(&p,sizeof(p),&sd.bl,SELF);
  3972. }
  3973. /// Reply to a trade-request.
  3974. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3975. /// 01f5 <result>.B <targetid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3976. /// result:
  3977. /// 0 = Char is too far
  3978. /// 1 = Character does not exist
  3979. /// 2 = Trade failed
  3980. /// 3 = Accept
  3981. /// 4 = Cancel
  3982. /// 5 = Busy
  3983. void clif_traderesponse( map_session_data& sd, e_ack_trade_response result ){
  3984. PACKET_ZC_ACK_EXCHANGE_ITEM p{};
  3985. p.packetType = HEADER_ZC_ACK_EXCHANGE_ITEM;
  3986. p.result = static_cast<decltype(p.result)>( result );
  3987. #if PACKETVER > 6
  3988. p.targetId = sd.trade_partner.id; // Client generates a random char[5] with this info
  3989. p.targetLv = sd.trade_partner.lv;
  3990. #endif
  3991. clif_send(&p,sizeof(p),&sd.bl,SELF);
  3992. }
  3993. /// Notifies the client about an item from other player in current trade.
  3994. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3995. /// 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)
  3996. /// 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)
  3997. void clif_tradeadditem( map_session_data* sd, map_session_data* tsd, int32 index, int32 amount ){
  3998. nullpo_retv( sd );
  3999. nullpo_retv( tsd );
  4000. int32 fd = tsd->fd;
  4001. if( !session_isActive( fd ) ){
  4002. return;
  4003. }
  4004. PACKET_ZC_ADD_EXCHANGE_ITEM p = {};
  4005. if( index ){
  4006. index = server_index( index );
  4007. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  4008. return;
  4009. }
  4010. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  4011. #if PACKETVER >= 20100223
  4012. p.itemType = sd->inventory_data[index]->type;
  4013. #endif
  4014. p.identified = sd->inventory.u.items_inventory[index].identify;
  4015. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  4016. p.refine = sd->inventory.u.items_inventory[index].refine;
  4017. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  4018. #if PACKETVER >= 20150226
  4019. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[index] );
  4020. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4021. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4022. p.look = sd->inventory_data[index]->look;
  4023. p.grade = sd->inventory.u.items_inventory[index].enchantgrade;
  4024. #endif
  4025. #endif
  4026. }else{
  4027. p = {};
  4028. }
  4029. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4030. p.amount = amount;
  4031. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4032. }
  4033. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4034. /// 00ea <index>.W <result>.B
  4035. /// result:
  4036. /// 0 = success
  4037. /// 1 = overweight
  4038. /// 2 = trade canceled
  4039. void clif_tradeitemok(map_session_data& sd, int32 index, e_exitem_add_result result)
  4040. {
  4041. PACKET_ZC_ACK_ADD_EXCHANGE_ITEM p = {};
  4042. p.packetType = HEADER_ZC_ACK_ADD_EXCHANGE_ITEM;
  4043. p.index = client_index(index);
  4044. p.result = static_cast<uint8>(result);
  4045. clif_send(&p, sizeof(p), &sd.bl, SELF);
  4046. }
  4047. /// Notifies the client about finishing one side of the current trade.
  4048. /// 00ec <who>.B (ZC_CONCLUDE_EXCHANGE_ITEM)
  4049. /// who:
  4050. /// 0 = self
  4051. /// 1 = other player
  4052. void clif_tradedeal_lock( map_session_data& sd, bool who ){
  4053. PACKET_ZC_CONCLUDE_EXCHANGE_ITEM packet{};
  4054. packet.packetType = HEADER_ZC_CONCLUDE_EXCHANGE_ITEM;
  4055. packet.who = who;
  4056. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4057. }
  4058. /// Notifies the client about the trade being canceled.
  4059. /// 00ee (ZC_CANCEL_EXCHANGE_ITEM)
  4060. void clif_tradecancelled( map_session_data& sd ){
  4061. PACKET_ZC_CANCEL_EXCHANGE_ITEM packet{};
  4062. packet.packetType = HEADER_ZC_CANCEL_EXCHANGE_ITEM;
  4063. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4064. }
  4065. /// Result of a trade.
  4066. /// 00f0 <result>.B (ZC_EXEC_EXCHANGE_ITEM)
  4067. /// result:
  4068. /// 0 = success
  4069. /// 1 = failure
  4070. void clif_tradecompleted( map_session_data& sd ){
  4071. PACKET_ZC_EXEC_EXCHANGE_ITEM packet{};
  4072. packet.packetType = HEADER_ZC_EXEC_EXCHANGE_ITEM;
  4073. packet.result = 0;
  4074. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4075. }
  4076. /// Resets the trade window on the send side.
  4077. /// 00f1 (ZC_EXCHANGEITEM_UNDO)
  4078. /// NOTE: Unknown purpose. Items are not removed until the window is
  4079. /// refreshed (ex. by putting another item in there).
  4080. void clif_tradeundo( map_session_data& sd ){
  4081. PACKET_ZC_EXCHANGEITEM_UNDO packet{};
  4082. packet.packetType = HEADER_ZC_EXCHANGEITEM_UNDO;
  4083. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4084. }
  4085. /// Updates storage total amount.
  4086. /// 00f2 <current count>.W <max count>.W (ZC_NOTIFY_STOREITEM_COUNTINFO)
  4087. void clif_updatestorageamount( map_session_data& sd, uint16 amount, uint16 max_amount ){
  4088. PACKET_ZC_NOTIFY_STOREITEM_COUNTINFO packet{};
  4089. packet.packetType = HEADER_ZC_NOTIFY_STOREITEM_COUNTINFO;
  4090. packet.amount = amount;
  4091. packet.max_amount = max_amount;
  4092. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4093. }
  4094. /// Notifies the client of an item being added to the storage.
  4095. /// 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)
  4096. /// 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)
  4097. /// 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)
  4098. void clif_storageitemadded( map_session_data* sd, struct item* i, int32 index, int32 amount ){
  4099. nullpo_retv( sd );
  4100. nullpo_retv( i );
  4101. int32 fd = sd->fd;
  4102. if( !session_isActive( fd ) ){
  4103. return;
  4104. }
  4105. PACKET_ZC_ADD_ITEM_TO_STORE p = {};
  4106. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4107. p.index = client_storage_index( index ); // index
  4108. p.amount = amount; // amount
  4109. p.itemId = client_nameid( i->nameid ); // id
  4110. #if PACKETVER >= 5
  4111. p.itemType = itemtype( i->nameid ); //type
  4112. #endif
  4113. p.identified = i->identify; //identify flag
  4114. p.damaged = i->attribute; // attribute
  4115. p.refine = i->refine; //refine
  4116. clif_addcards( &p.slot, i );
  4117. #if PACKETVER_MAIN_NUM >= 20140813 || PACKETVER_RE_NUM >= 20140402 || defined(PACKETVER_ZERO)
  4118. clif_add_random_options( p.option_data, *i );
  4119. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20221024
  4120. p.grade = i->enchantgrade;
  4121. #endif
  4122. #endif
  4123. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4124. }
  4125. /// Notifies the client of an item being deleted from the storage.
  4126. /// 00f6 <index>.W <amount>.L (ZC_DELETE_ITEM_FROM_STORE)
  4127. void clif_storageitemremoved( map_session_data& sd, uint16 index, uint32 amount ){
  4128. PACKET_ZC_DELETE_ITEM_FROM_STORE packet{};
  4129. packet.packetType = HEADER_ZC_DELETE_ITEM_FROM_STORE;
  4130. packet.index = client_storage_index(index);
  4131. packet.amount = amount;
  4132. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4133. }
  4134. /// Closes storage.
  4135. /// 00f8 (ZC_CLOSE_STORE)
  4136. void clif_storageclose( map_session_data& sd ){
  4137. PACKET_ZC_CLOSE_STORE packet{};
  4138. packet.packetType = HEADER_ZC_CLOSE_STORE;
  4139. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4140. }
  4141. /// Notifies clients in an area of a player's souls.
  4142. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4143. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4144. /// 0b73 <id>.L <amount>.W (ZC_SOULENERGY)
  4145. void clif_soulball( map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4146. #if PACKETVER_MAIN_NUM >= 20200414 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20200506
  4147. PACKET_ZC_SOULENERGY p = {};
  4148. p.PacketType = HEADER_ZC_SOULENERGY;
  4149. #else
  4150. PACKET_ZC_SPIRITS p = {};
  4151. p.PacketType = HEADER_ZC_SPIRITS;
  4152. #endif
  4153. p.AID = sd->bl.id;
  4154. p.num = sd->soulball;
  4155. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4156. }
  4157. /*==========================================
  4158. * Server tells 'sd' player client the abouts of 'dstsd' player
  4159. *------------------------------------------*/
  4160. static void clif_getareachar_pc(map_session_data* sd,map_session_data* dstsd)
  4161. {
  4162. struct block_list *d_bl;
  4163. int32 i;
  4164. if( dstsd->chatID ) {
  4165. chat_data* cd = map_id2cd( dstsd->chatID );
  4166. if( cd != nullptr && cd->usersd[0] == dstsd ){
  4167. clif_dispchat(*cd);
  4168. }
  4169. } else if( dstsd->state.vending )
  4170. clif_showvendingboard( *dstsd, SELF, &sd->bl );
  4171. else if( dstsd->state.buyingstore )
  4172. clif_buyingstore_entry( *dstsd, &sd->bl );
  4173. if(dstsd->spiritball > 0)
  4174. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4175. clif_millenniumshield_single( *dstsd, *sd );
  4176. clif_spiritcharm_single( *dstsd, *sd );
  4177. if (dstsd->soulball > 0)
  4178. clif_soulball( dstsd, &sd->bl, SELF );
  4179. if (dstsd->servantball > 0)
  4180. clif_servantball( *dstsd, &sd->bl, SELF );
  4181. if (dstsd->abyssball > 0)
  4182. clif_abyssball( *dstsd, &sd->bl, SELF );
  4183. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4184. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4185. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4186. )
  4187. clif_hpmeter_single( *sd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp );
  4188. // display link (sd - dstsd) to sd
  4189. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4190. if( i < MAX_DEVOTION )
  4191. clif_devotion(&sd->bl, sd);
  4192. // display links (dstsd - devotees) to sd
  4193. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4194. if( i < MAX_DEVOTION )
  4195. clif_devotion(&dstsd->bl, sd);
  4196. // display link (dstsd - crusader) to sd
  4197. if( dstsd->sc.getSCE(SC_DEVOTION) && (d_bl = map_id2bl(dstsd->sc.getSCE(SC_DEVOTION)->val1)) != nullptr )
  4198. clif_devotion(d_bl, sd);
  4199. }
  4200. void clif_getareachar_unit( map_session_data* sd,struct block_list *bl ){
  4201. struct unit_data *ud;
  4202. struct view_data *vd;
  4203. bool option = false;
  4204. uint32 option_val = 0;
  4205. vd = status_get_viewdata(bl);
  4206. if (!vd || vd->class_ == JT_INVISIBLE)
  4207. return;
  4208. // Hide NPC from Maya Purple card
  4209. if (clif_npc_mayapurple(bl))
  4210. return;
  4211. if( bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)bl ), *sd ) ){
  4212. // Do not send anything
  4213. return;
  4214. }
  4215. ud = unit_bl2ud(bl);
  4216. if( ud && ud->walktimer != INVALID_TIMER ){
  4217. clif_set_unit_walking( *bl, sd, *ud, SELF );
  4218. }else{
  4219. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4220. }
  4221. if (vd->cloth_color)
  4222. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4223. if (vd->body_style)
  4224. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4225. switch (bl->type)
  4226. {
  4227. case BL_PC:
  4228. {
  4229. TBL_PC* tsd = (TBL_PC*)bl;
  4230. clif_getareachar_pc(sd, tsd);
  4231. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4232. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4233. else if(tsd->state.size==SZ_MEDIUM)
  4234. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4235. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4236. clif_sendbgemblem_single(sd->fd,tsd);
  4237. if ( tsd->status.robe )
  4238. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4239. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4240. clif_hat_effects( *sd, tsd->bl, SELF );
  4241. }
  4242. break;
  4243. case BL_MER: // Devotion Effects
  4244. if( ((TBL_MER*)bl)->devotion_flag )
  4245. clif_devotion(bl, sd);
  4246. break;
  4247. case BL_NPC:
  4248. {
  4249. TBL_NPC* nd = (TBL_NPC*)bl;
  4250. if( nd->chat_id ){
  4251. chat_data* cd = map_id2cd( nd->chat_id );
  4252. if( cd != nullptr ){
  4253. clif_dispchat( *cd );
  4254. }
  4255. }
  4256. if( nd->size == SZ_BIG )
  4257. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4258. else if( nd->size == SZ_MEDIUM )
  4259. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4260. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4261. clif_progressbar_npc(nd, sd);
  4262. }
  4263. break;
  4264. case BL_MOB:
  4265. {
  4266. TBL_MOB* md = (TBL_MOB*)bl;
  4267. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4268. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4269. else if(md->special_state.size==SZ_MEDIUM)
  4270. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4271. #if PACKETVER >= 20120404
  4272. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4273. // Must show hp bar to all char who already hit the mob.
  4274. for( const auto& entry : md->dmglog ){
  4275. if( entry.id == sd->status.char_id ){
  4276. clif_monster_hp_bar(md, sd->fd);
  4277. }
  4278. }
  4279. }
  4280. #endif
  4281. }
  4282. break;
  4283. case BL_PET:
  4284. // If the pet wears equip
  4285. if( vd->head_bottom != 0 ){
  4286. pet_data& pd = *reinterpret_cast<pet_data*>( bl );
  4287. clif_send_petdata( sd, pd, CHANGESTATEPET_ACCESSORY );
  4288. }
  4289. break;
  4290. }
  4291. }
  4292. //Modifies the type of damage according to target status changes [Skotlex]
  4293. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4294. static enum e_damage_type clif_calc_delay( block_list& bl, e_damage_type type, int32 div, int64 damage ) {
  4295. if (damage < 1)
  4296. return type;
  4297. status_change* sc = status_get_sc( &bl );
  4298. if (sc == nullptr || sc->empty())
  4299. return type;
  4300. if (sc->getSCE(SC_ENDURE) == nullptr) // !TODO: should berserk status also change the type?
  4301. return type;
  4302. switch( type ) {
  4303. case DMG_ENDURE:
  4304. case DMG_MULTI_HIT_ENDURE:
  4305. case DMG_SPLASH_ENDURE:
  4306. return type;
  4307. case DMG_NORMAL:
  4308. case DMG_CRITICAL:
  4309. case DMG_SINGLE:
  4310. case DMG_MULTI_HIT_CRITICAL: // DMG_ENDURE despite div > 1
  4311. return DMG_ENDURE;
  4312. case DMG_MULTI_HIT:
  4313. return DMG_MULTI_HIT_ENDURE;
  4314. case DMG_SPLASH:
  4315. return DMG_SPLASH_ENDURE;
  4316. }
  4317. // Custom, unknown result of endure with types not listed
  4318. return (div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE);
  4319. }
  4320. /*==========================================
  4321. * Estimates walk delay based on the damage criteria. [Skotlex]
  4322. *------------------------------------------*/
  4323. static int32 clif_calc_walkdelay( block_list &bl, int32 delay, e_damage_type type, int64 damage, int32 div_ ) {
  4324. if (damage < 1)
  4325. return 0;
  4326. switch( type ) {
  4327. case DMG_ENDURE:
  4328. case DMG_MULTI_HIT_ENDURE:
  4329. case DMG_SPLASH_ENDURE:
  4330. return 0;
  4331. }
  4332. if (bl.type == BL_PC) {
  4333. if (battle_config.pc_walk_delay_rate != 100)
  4334. delay = delay*battle_config.pc_walk_delay_rate/100;
  4335. } else
  4336. if (battle_config.walk_delay_rate != 100)
  4337. delay = delay*battle_config.walk_delay_rate/100;
  4338. if (div_ > 1) //Multi-hit skills mean higher delays.
  4339. delay += battle_config.multihit_delay*(div_-1);
  4340. return (delay > 0) ? delay : 1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4341. }
  4342. /*========================================== [Playtester]
  4343. * Returns hallucination damage the client displays
  4344. *------------------------------------------*/
  4345. static int64 clif_hallucination_damage( block_list& bl, int64 damage ){
  4346. status_change* sc = status_get_sc( &bl );
  4347. if( sc == nullptr ){
  4348. return damage;
  4349. }
  4350. if( sc->empty() ){
  4351. return damage;
  4352. }
  4353. if( sc->getSCE( SC_HALLUCINATION ) == nullptr ){
  4354. return damage;
  4355. }
  4356. if( damage == 0 ){
  4357. return damage;
  4358. }
  4359. int32 digit = rnd() % 5 + 1;
  4360. switch (digit)
  4361. {
  4362. case 1:
  4363. return (rnd() % 10);
  4364. case 2:
  4365. return (rnd() % 100);
  4366. case 3:
  4367. return (rnd() % 1000);
  4368. case 4:
  4369. return (rnd() % 10000);
  4370. }
  4371. return (rnd() % 32767);
  4372. }
  4373. #define DEFAULT_ANIMATION_SPEED 432
  4374. /// Sends a 'damage' packet (src performs action on dst)
  4375. /// 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)
  4376. /// 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)
  4377. /// 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)
  4378. /// type:
  4379. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4380. /// 1 = pick up item
  4381. /// 2 = sit down
  4382. /// 3 = stand up
  4383. /// 4 = damage (endure)
  4384. /// 5 = (splash?)
  4385. /// 6 = (skill?)
  4386. /// 7 = (repeat damage?)
  4387. /// 8 = multi-hit damage
  4388. /// 9 = multi-hit damage (endure)
  4389. /// 10 = critical hit
  4390. /// 11 = lucky dodge
  4391. /// 12 = (touch skill?)
  4392. /// 13 = multi-hit critical
  4393. int32 clif_damage(block_list& src, block_list& dst, t_tick tick, int32 sdelay, int32 ddelay, int64 sdamage, int32 div, enum e_damage_type type, int64 sdamage2, bool spdamage){
  4394. int32 damage = (int32)cap_value(sdamage,INT_MIN,INT_MAX);
  4395. int32 damage2 = (int32)cap_value(sdamage2,INT_MIN,INT_MAX);
  4396. type = clif_calc_delay( dst, type, div, damage+damage2 );
  4397. damage = static_cast<decltype(damage)>(clif_hallucination_damage(dst, damage));
  4398. damage2 = static_cast<decltype(damage2)>(clif_hallucination_damage(dst, damage2));
  4399. // Calculate what sdelay to send to the client so it applies damage at the same time as the server
  4400. if (battle_config.synchronize_damage && src.type == BL_MOB) {
  4401. // When a clif_damage packet is sent to the client it will also send "sdelay" (amotion) as value.
  4402. // The client however does not interpret this value as AttackMotion but incorrectly as an inverted
  4403. // animation speed modifier, with 432 standing for 1x animation speed.
  4404. // The client will ignore all values above 432, but lower values will speed up the animation.
  4405. // 216 for example means play the animation at double the speed. 108 is quadruple speed.
  4406. // Each monster has an attack animation and may define the frame in the attack animation on which
  4407. // it displays the damage and makes the target flinch / stop. If the damage frame is undefined,
  4408. // it instead displays the damage / flinch / stop at the beginning of the second to last frame.
  4409. // We define the time after which the damage frame shows at 1x speed as clientamotion.
  4410. uint16 clientamotion = std::max((uint16)1, status_get_clientamotion(&src));
  4411. // Knowing when the damage frame happens in the animation allows us to synchronize the timing
  4412. // between client and server using the formula below.
  4413. sdelay = sdelay * DEFAULT_ANIMATION_SPEED / clientamotion;
  4414. // Hint: If amotion is larger than clientamotion this results in a value above 432 which makes the
  4415. // client display the attack at 1x speed. In this case we need to shorten the delay damage timer
  4416. // on the server to clientamotion ms instead (see battle_delay_damage).
  4417. sdelay = std::min(sdelay, DEFAULT_ANIMATION_SPEED);
  4418. }
  4419. PACKET_ZC_NOTIFY_ACT p{};
  4420. p.packetType = HEADER_ZC_NOTIFY_ACT;
  4421. p.srcID = src.id;
  4422. p.targetID = dst.id;
  4423. p.serverTick = client_tick(tick);
  4424. p.srcSpeed = sdelay;
  4425. p.dmgSpeed = ddelay;
  4426. if (battle_config.hide_woe_damage && map_flag_gvg(src.m)) {
  4427. p.damage = damage ? div : 0;
  4428. p.damage2 = damage2 ? div : 0;
  4429. } else {
  4430. p.damage = static_cast<decltype(p.damage)>( std::min( damage, static_cast<decltype(damage)>( std::numeric_limits<decltype(p.damage)>::max() ) ) );
  4431. p.damage2 = static_cast<decltype(p.damage2)>( std::min( damage2, static_cast<decltype(damage2)>( std::numeric_limits<decltype(p.damage2)>::max() ) ) );
  4432. }
  4433. #if PACKETVER >= 20131223
  4434. p.isSPDamage = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4435. #endif
  4436. p.div = div;
  4437. p.type = type;
  4438. if(disguised(&dst)) {
  4439. clif_send( &p, sizeof(p), &dst, AREA_WOS);
  4440. p.targetID = disguised_bl_id( dst.id );
  4441. clif_send( &p, sizeof(p), &dst, SELF);
  4442. } else
  4443. clif_send(&p, sizeof(p), &dst, AREA);
  4444. if(disguised(&src)) {
  4445. p.srcID = disguised_bl_id( src.id );
  4446. if(damage > 0)
  4447. p.damage = -1;
  4448. if(damage2 > 0)
  4449. p.damage2 = -1;
  4450. clif_send( &p, sizeof(p), &src, SELF);
  4451. }
  4452. if(&src == &dst)
  4453. unit_setdir(&src, unit_getdir(&src));
  4454. //Return adjusted can't walk delay for further processing.
  4455. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4456. }
  4457. /*==========================================
  4458. * src picks up dst
  4459. *------------------------------------------*/
  4460. void clif_takeitem(block_list& src, block_list& dst){
  4461. PACKET_ZC_NOTIFY_ACT p{};
  4462. p.packetType = HEADER_ZC_NOTIFY_ACT;
  4463. p.srcID = src.id;
  4464. p.targetID = dst.id;
  4465. p.type = DMG_PICKUP_ITEM;
  4466. clif_send(&p, sizeof(p), &src, AREA);
  4467. }
  4468. /*==========================================
  4469. * inform clients in area that `bl` is sitting
  4470. *------------------------------------------*/
  4471. void clif_sitting(block_list& bl){
  4472. PACKET_ZC_NOTIFY_ACT p{};
  4473. p.packetType = HEADER_ZC_NOTIFY_ACT;
  4474. p.srcID = bl.id;
  4475. p.type = DMG_SIT_DOWN;
  4476. clif_send(&p, sizeof(p), &bl, AREA);
  4477. if(disguised(&bl)) {
  4478. p.srcID = disguised_bl_id( bl.id );
  4479. clif_send(&p, sizeof(p), &bl, SELF);
  4480. }
  4481. }
  4482. /*==========================================
  4483. * inform clients in area that `bl` is standing
  4484. *------------------------------------------*/
  4485. void clif_standing(block_list& bl){
  4486. PACKET_ZC_NOTIFY_ACT p{};
  4487. p.packetType = HEADER_ZC_NOTIFY_ACT;
  4488. p.srcID = bl.id;
  4489. p.type = DMG_STAND_UP;
  4490. clif_send(&p, sizeof(p), &bl, AREA);
  4491. if(disguised(&bl)) {
  4492. p.srcID = disguised_bl_id( bl.id );
  4493. clif_send(&p, sizeof(p), &bl, SELF);
  4494. }
  4495. }
  4496. /// Inform client(s) about a map-cell change.
  4497. /// 0192 <x>.W <y>.W <type>.W <map name>.16B (ZC_UPDATE_MAPINFO)
  4498. void clif_changemapcell( int16 m, int16 x, int16 y, int16 type, send_target target, block_list* tbl ){
  4499. PACKET_ZC_UPDATE_MAPINFO p = {};
  4500. p.packetType = HEADER_ZC_UPDATE_MAPINFO;
  4501. p.x = x;
  4502. p.y = y;
  4503. p.type = type;
  4504. mapindex_getmapname_ext( map_mapid2mapname( m ), p.mapname );
  4505. if( tbl != nullptr ){
  4506. clif_send( &p, sizeof( p ), tbl, target );
  4507. }else{
  4508. block_list dummy_bl = {};
  4509. dummy_bl.type = BL_NUL;
  4510. dummy_bl.x = x;
  4511. dummy_bl.y = y;
  4512. dummy_bl.m = m;
  4513. clif_send( &p, sizeof( p ), &dummy_bl, target );
  4514. }
  4515. }
  4516. /// Notifies the client about an item on floor.
  4517. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B (ZC_ITEM_ENTRY)
  4518. void clif_getareachar_item( map_session_data& sd, flooritem_data& fitem ){
  4519. PACKET_ZC_ITEM_ENTRY p = {};
  4520. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4521. p.AID = fitem.bl.id;
  4522. p.itemId = client_nameid( fitem.item.nameid );
  4523. p.identify = fitem.item.identify;
  4524. p.x = fitem.bl.x;
  4525. p.y = fitem.bl.y;
  4526. p.amount = fitem.item.amount;
  4527. p.subX = fitem.subx;
  4528. p.subY = fitem.suby;
  4529. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  4530. }
  4531. /// Notifes client about Graffiti
  4532. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4533. static void clif_graffiti( skill_unit& unit, send_target target, block_list& bl ){
  4534. packet_graffiti_entry p = {};
  4535. p.PacketType = graffiti_entryType;
  4536. p.AID = unit.bl.id;
  4537. p.creatorAID = unit.group->src_id;
  4538. p.xPos = unit.bl.x;
  4539. p.yPos = unit.bl.y;
  4540. p.job = unit.group->unit_id;
  4541. p.isContens = 1;
  4542. p.isVisible = 1;
  4543. safestrncpy( p.msg, unit.group->valstr, sizeof( p.msg ) );
  4544. clif_send( &p, sizeof( p ), &bl, target );
  4545. }
  4546. /// Notifies the client of a skill unit.
  4547. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4548. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4549. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4550. /// 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)
  4551. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4552. int32 header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4553. unsigned char buf[128];
  4554. nullpo_retv(bl);
  4555. nullpo_retv(unit);
  4556. if (bl->type == BL_PC)
  4557. fd = ((TBL_PC*)bl)->fd;
  4558. if (unit->group->state.guildaura)
  4559. return;
  4560. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4561. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4562. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4563. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4564. else
  4565. unit_id = unit->group->unit_id;
  4566. if (!visible)
  4567. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4568. #if PACKETVER >= 3
  4569. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4570. clif_graffiti( *unit, target, *bl );
  4571. return;
  4572. }
  4573. #endif
  4574. #if PACKETVER <= 20120702
  4575. header = 0x011f;
  4576. //#if PACKETVER < 20110718
  4577. // header = 0x011f;
  4578. //#elif PACKETVER < 20121212
  4579. // header = 0x08c7;
  4580. #elif PACKETVER < 20130731
  4581. header = 0x099f;
  4582. #else
  4583. header = 0x09ca;
  4584. #endif
  4585. len = packet_len(header);
  4586. WBUFW(buf,pos) = header;
  4587. if (header != 0x011f) {
  4588. WBUFW(buf, pos+2) = len;
  4589. pos += 2;
  4590. }
  4591. WBUFL(buf,pos+2) = unit->bl.id;
  4592. WBUFL(buf,pos+6) = unit->group->src_id;
  4593. WBUFW(buf,pos+10) = unit->bl.x;
  4594. WBUFW(buf,pos+12) = unit->bl.y;
  4595. switch (header) {
  4596. case 0x011f:
  4597. WBUFB(buf,pos+14) = unit_id;
  4598. WBUFB(buf,pos+15) = visible;
  4599. break;
  4600. case 0x08c7:
  4601. WBUFB(buf,pos+14) = unit_id;
  4602. WBUFW(buf,pos+15) = unit->range;
  4603. WBUFB(buf,pos+17) = visible;
  4604. break;
  4605. case 0x099f:
  4606. WBUFL(buf,pos+14) = unit_id;
  4607. WBUFW(buf,pos+18) = unit->range;
  4608. WBUFB(buf,pos+20) = visible;
  4609. break;
  4610. case 0x09ca:
  4611. WBUFL(buf,pos+14) = unit_id;
  4612. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4613. WBUFB(buf,pos+19) = visible;
  4614. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4615. break;
  4616. }
  4617. clif_send(buf, len, bl, target);
  4618. if (unit->group->skill_id == WZ_ICEWALL)
  4619. clif_changemapcell( unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF, bl );
  4620. }
  4621. /// 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)
  4622. void clif_skill_unit_test(struct block_list *bl, int16 x, int16 y, int32 unit_id, int16 range, int16 skill_lv) {
  4623. unsigned char buf[128];
  4624. nullpo_retv(bl);
  4625. WBUFW(buf, 0) = 0x09ca;
  4626. WBUFW(buf, 2) = packet_len(0x09ca);
  4627. WBUFL(buf, 4) = 1000;
  4628. WBUFL(buf, 8) = 2000;
  4629. WBUFW(buf, 12) = x;
  4630. WBUFW(buf, 14) = y;
  4631. WBUFL(buf, 16) = unit_id;
  4632. WBUFB(buf, 20) = (unsigned char)range;
  4633. WBUFB(buf, 21) = 1;
  4634. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4635. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4636. }
  4637. /// Server tells client to remove unit of id 'unit->bl.id'
  4638. /// 0120 <id>.L (ZC_SKILL_DISAPPEAR)
  4639. static void clif_clearchar_skillunit( skill_unit& unit, map_session_data& sd ){
  4640. PACKET_ZC_SKILL_DISAPPEAR packet{};
  4641. packet.packetType = HEADER_ZC_SKILL_DISAPPEAR;
  4642. packet.GID = unit.bl.id;
  4643. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4644. if( unit.group && unit.group->skill_id == WZ_ICEWALL ){
  4645. clif_changemapcell( unit.bl.m, unit.bl.x, unit.bl.y, unit.val2, SELF, &sd.bl );
  4646. }
  4647. }
  4648. /// Removes a skill unit.
  4649. /// 0120 <id>.L (ZC_SKILL_DISAPPEAR)
  4650. void clif_skill_delunit( skill_unit& unit ){
  4651. PACKET_ZC_SKILL_DISAPPEAR packet{};
  4652. packet.packetType = HEADER_ZC_SKILL_DISAPPEAR;
  4653. packet.GID = unit.bl.id;
  4654. clif_send( &packet, sizeof( packet ), &unit.bl, AREA );
  4655. }
  4656. /// Sent when an object gets ankle-snared.
  4657. /// 01ac <id>.L (ZC_SKILL_UPDATE)
  4658. /// Only affects units with class [139,153] client-side.
  4659. void clif_skillunit_update( block_list& bl ){
  4660. PACKET_ZC_SKILL_UPDATE packet{};
  4661. packet.packetType = HEADER_ZC_SKILL_UPDATE;
  4662. packet.GID = bl.id;
  4663. clif_send( &packet, sizeof( packet ), &bl, AREA );
  4664. }
  4665. /*==========================================
  4666. *
  4667. *------------------------------------------*/
  4668. static int32 clif_getareachar(struct block_list* bl,va_list ap)
  4669. {
  4670. map_session_data *sd;
  4671. nullpo_ret(bl);
  4672. sd=va_arg(ap,map_session_data*);
  4673. if (!clif_session_isValid(sd))
  4674. return 0;
  4675. switch(bl->type){
  4676. case BL_ITEM:
  4677. clif_getareachar_item( *sd, *reinterpret_cast<flooritem_data*>( bl ) );
  4678. break;
  4679. case BL_SKILL:
  4680. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4681. break;
  4682. default:
  4683. if(&sd->bl == bl)
  4684. break;
  4685. clif_getareachar_unit(sd,bl);
  4686. break;
  4687. }
  4688. return 0;
  4689. }
  4690. /*==========================================
  4691. * tbl has gone out of view-size of bl
  4692. *------------------------------------------*/
  4693. int32 clif_outsight(struct block_list *bl,va_list ap)
  4694. {
  4695. struct block_list *tbl;
  4696. struct view_data *vd;
  4697. TBL_PC *sd, *tsd;
  4698. tbl=va_arg(ap,struct block_list*);
  4699. if(bl == tbl) return 0;
  4700. sd = BL_CAST(BL_PC, bl);
  4701. tsd = BL_CAST(BL_PC, tbl);
  4702. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4703. nullpo_ret(bl);
  4704. switch(bl->type){
  4705. case BL_PC:
  4706. if(sd->vd.class_ != JT_INVISIBLE)
  4707. clif_clearunit_single( bl->id, CLR_OUTSIGHT, *tsd );
  4708. if(sd->chatID){
  4709. struct chat_data *cd;
  4710. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4711. if(cd->usersd[0]==sd)
  4712. clif_dispchat(*cd);
  4713. }
  4714. if(sd->state.vending)
  4715. clif_closevendingboard(bl,tsd->fd);
  4716. if(sd->state.buyingstore)
  4717. clif_buyingstore_disappear_entry( *sd, &tsd->bl );
  4718. break;
  4719. case BL_ITEM:
  4720. clif_clearflooritem( *reinterpret_cast<flooritem_data*>( bl ), tsd );
  4721. break;
  4722. case BL_SKILL:
  4723. clif_clearchar_skillunit( *((skill_unit *)bl), *tsd );
  4724. break;
  4725. case BL_NPC:
  4726. if(!(((TBL_NPC*)bl)->is_invisible))
  4727. clif_clearunit_single( bl->id, CLR_OUTSIGHT, *tsd );
  4728. break;
  4729. default:
  4730. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4731. clif_clearunit_single( bl->id, CLR_OUTSIGHT, *tsd );
  4732. break;
  4733. }
  4734. }
  4735. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4736. nullpo_ret(tbl);
  4737. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4738. clif_clearchar_skillunit( *((skill_unit *)tbl), *sd );
  4739. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4740. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->is_invisible)))
  4741. clif_clearunit_single( tbl->id, CLR_OUTSIGHT, *sd );
  4742. }
  4743. return 0;
  4744. }
  4745. /*==========================================
  4746. * tbl has come into view of bl
  4747. *------------------------------------------*/
  4748. int32 clif_insight(struct block_list *bl,va_list ap)
  4749. {
  4750. struct block_list *tbl;
  4751. TBL_PC *sd, *tsd;
  4752. tbl=va_arg(ap,struct block_list*);
  4753. if (bl == tbl) return 0;
  4754. sd = BL_CAST(BL_PC, bl);
  4755. tsd = BL_CAST(BL_PC, tbl);
  4756. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4757. switch(bl->type){
  4758. case BL_ITEM:
  4759. clif_getareachar_item( *tsd, *reinterpret_cast<flooritem_data*>( bl ) );
  4760. break;
  4761. case BL_SKILL:
  4762. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4763. break;
  4764. default:
  4765. clif_getareachar_unit(tsd,bl);
  4766. break;
  4767. }
  4768. }
  4769. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4770. clif_getareachar_unit(sd,tbl);
  4771. }
  4772. return 0;
  4773. }
  4774. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4775. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4776. void clif_skillinfoblock(map_session_data *sd)
  4777. {
  4778. int32 fd;
  4779. int32 i,len,id;
  4780. nullpo_retv(sd);
  4781. fd = sd->fd;
  4782. if (!session_isActive(fd))
  4783. return;
  4784. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4785. WFIFOW(fd,0) = 0x10f;
  4786. bool haveCallPartnerSkill = false;
  4787. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4788. {
  4789. if( (id = sd->status.skill[i].id) != 0 )
  4790. {
  4791. // workaround for bugreport:5348
  4792. if (len + 37 > 8192)
  4793. break;
  4794. // skip WE_CALLPARTNER and send it in special way
  4795. if (id == WE_CALLPARTNER) {
  4796. haveCallPartnerSkill = true;
  4797. continue;
  4798. }
  4799. WFIFOW(fd,len) = id;
  4800. WFIFOL(fd,len+2) = skill_get_inf(id);
  4801. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4802. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4803. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4804. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4805. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4806. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4807. else
  4808. WFIFOB(fd,len+36) = 0;
  4809. len += 37;
  4810. }
  4811. }
  4812. WFIFOW(fd,2)=len;
  4813. WFIFOSET(fd,len);
  4814. // adoption fix
  4815. if (haveCallPartnerSkill) {
  4816. clif_addskill(*sd, WE_CALLPARTNER);
  4817. clif_skillinfo( *sd, WE_CALLPARTNER );
  4818. }
  4819. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4820. for ( ; i < MAX_SKILL; i++)
  4821. {
  4822. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4823. {
  4824. clif_addskill(*sd, id);
  4825. clif_skillinfo( *sd, id );
  4826. }
  4827. }
  4828. }
  4829. /**
  4830. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4831. **/
  4832. /// Adds new skill to the skill tree.
  4833. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B (ZC_ADD_SKILL)
  4834. /// 0b31 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B <isnew>.B (ZC_ADD_SKILL2)
  4835. void clif_addskill(map_session_data &sd, uint16 skill_id){
  4836. uint16 idx = skill_get_index(skill_id);
  4837. if (idx == 0)
  4838. return;
  4839. if( sd.status.skill[idx].id <= 0 )
  4840. return;
  4841. PACKET_ZC_ADD_SKILL p{};
  4842. p.packetType = HEADER_ZC_ADD_SKILL;
  4843. p.skill.id = skill_id;
  4844. p.skill.inf = skill_get_inf(skill_id);
  4845. p.skill.level = sd.status.skill[idx].lv;
  4846. p.skill.sp = static_cast<decltype(p.skill.sp)>( skill_get_sp(skill_id,sd.status.skill[idx].lv) );
  4847. p.skill.range2 = static_cast<decltype(p.skill.range2)>( skill_get_range2(&sd.bl,skill_id,sd.status.skill[idx].lv,false) );
  4848. #if PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190918
  4849. p.skill.level2 = pc_checkskill(&sd,skill_id);
  4850. #else
  4851. safestrncpy(p.skill.name, skill_get_name(skill_id), sizeof(p.skill.name));
  4852. #endif
  4853. if( sd.status.skill[idx].flag == SKILL_FLAG_PERMANENT && sd.status.skill[idx].lv < skill_tree_get_max(skill_id, sd.status.class_))
  4854. p.skill.upFlag = 1;
  4855. else
  4856. p.skill.upFlag = 0;
  4857. clif_send(&p,sizeof(p),&sd.bl,SELF);
  4858. }
  4859. /// Deletes a skill from the skill tree.
  4860. /// 0441 <skill id>.W (ZC_SKILLINFO_DELETE)
  4861. void clif_deleteskill(map_session_data& sd, uint16 skill_id, bool skip_infoblock){
  4862. #if PACKETVER >= 20081126
  4863. uint16 idx = skill_get_index(skill_id);
  4864. if (idx == 0)
  4865. return;
  4866. PACKET_ZC_SKILLINFO_DELETE p{};
  4867. p.packetType = HEADER_ZC_SKILLINFO_DELETE;
  4868. p.skillID = skill_id;
  4869. clif_send(&p,sizeof(p),&sd.bl,SELF);
  4870. #endif
  4871. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190918
  4872. if (!skip_infoblock)
  4873. #endif
  4874. clif_skillinfoblock(&sd);
  4875. }
  4876. /// Updates a skill in the skill tree.
  4877. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B (ZC_SKILLINFO_UPDATE)
  4878. void clif_skillup( map_session_data& sd, uint16 skill_id, uint16 lv, uint16 range, bool upgradable ){
  4879. uint16 idx = skill_get_index(skill_id);
  4880. if( idx == 0 ){
  4881. return;
  4882. }
  4883. PACKET_ZC_SKILLINFO_UPDATE p{};
  4884. p.packetType = HEADER_ZC_SKILLINFO_UPDATE;
  4885. p.skillId = skill_id;
  4886. p.level = lv;
  4887. p.sp = static_cast<decltype(p.sp)>( skill_get_sp( skill_id, lv ) );
  4888. p.range2 = range;
  4889. p.upFlag = upgradable;
  4890. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  4891. }
  4892. /// Updates a skill in the skill tree
  4893. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B (ZC_SKILLINFO_UPDATE2)
  4894. /// 0b33 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B <level2>.W (ZC_SKILLINFO_UPDATE3)
  4895. void clif_skillinfo( map_session_data& sd, uint16 skill_id ){
  4896. #if PACKETVER >= 20090715
  4897. uint16 idx = skill_get_index(skill_id);
  4898. if( idx == 0 ){
  4899. return;
  4900. }
  4901. PACKET_ZC_SKILLINFO_UPDATE2 p = {};
  4902. p.packetType = HEADER_ZC_SKILLINFO_UPDATE2;
  4903. p.id = skill_id;
  4904. p.level = sd.status.skill[idx].lv;
  4905. p.sp = static_cast<decltype(p.sp)>( skill_get_sp( skill_id,sd.status.skill[idx].lv ) );
  4906. p.range2 = static_cast<decltype(p.range2)>( skill_get_range2( &sd.bl,skill_id,sd.status.skill[idx].lv,false ) );
  4907. p.inf = skill_get_inf( skill_id );
  4908. if( sd.status.skill[idx].flag == SKILL_FLAG_PERMANENT && sd.status.skill[idx].lv < skill_tree_get_max( skill_id, sd.status.class_ ) ){
  4909. p.upFlag = true;
  4910. }else{
  4911. p.upFlag = false;
  4912. }
  4913. #if PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190918
  4914. p.level2 = p.level;
  4915. #endif
  4916. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  4917. #endif
  4918. }
  4919. void clif_skill_scale( struct block_list *bl, int32 src_id, int32 x, int32 y, uint16 skill_id, uint16 skill_lv, int32 casttime ){
  4920. #if PACKETVER >= 20151223
  4921. if( !battle_config.show_skill_scale ){
  4922. return;
  4923. }
  4924. PACKET_ZC_SKILL_SCALE p = {};
  4925. p.PacketType = skillscale;
  4926. p.AID = src_id;
  4927. p.skill_id = skill_id;
  4928. p.skill_lv = skill_lv;
  4929. p.x = x;
  4930. p.y = y;
  4931. p.casttime = casttime;
  4932. if( disguised( bl ) ){
  4933. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4934. p.AID = disguised_bl_id( bl->id );
  4935. clif_send( &p, sizeof( p ), bl, SELF );
  4936. }else{
  4937. clif_send( &p, sizeof( p ), bl, AREA );
  4938. }
  4939. #endif
  4940. }
  4941. /// Notifies clients in area, that an object is about to use a skill.
  4942. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4943. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4944. /// property:
  4945. /// 0 = Yellow cast aura
  4946. /// 1 = Water elemental cast aura
  4947. /// 2 = Earth elemental cast aura
  4948. /// 3 = Fire elemental cast aura
  4949. /// 4 = Wind elemental cast aura
  4950. /// 5 = Poison elemental cast aura
  4951. /// 6 = Holy elemental cast aura
  4952. /// ? = like 0
  4953. /// is disposable:
  4954. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4955. /// 1 = no text
  4956. void clif_skillcasting(struct block_list* bl, int32 src_id, int32 dst_id, int32 dst_x, int32 dst_y, uint16 skill_id, uint16 skill_lv, int32 property, int32 casttime)
  4957. {
  4958. #if PACKETVER < 20091124
  4959. const int32 cmd = 0x13e;
  4960. #else
  4961. const int32 cmd = 0x7fb;
  4962. #endif
  4963. unsigned char buf[32];
  4964. WBUFW(buf,0) = cmd;
  4965. WBUFL(buf,2) = src_id;
  4966. WBUFL(buf,6) = dst_id;
  4967. WBUFW(buf,10) = dst_x;
  4968. WBUFW(buf,12) = dst_y;
  4969. WBUFW(buf,14) = skill_id;
  4970. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4971. WBUFL(buf,20) = casttime;
  4972. #if PACKETVER >= 20091124
  4973. WBUFB(buf,24) = 0; // isDisposable
  4974. #endif
  4975. if (disguised(bl)) {
  4976. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4977. WBUFL(buf,2) = disguised_bl_id( src_id );
  4978. clif_send(buf,packet_len(cmd), bl, SELF);
  4979. } else
  4980. clif_send(buf,packet_len(cmd), bl, AREA);
  4981. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  4982. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  4983. }
  4984. }
  4985. /// Notifies clients in area, that an object canceled casting.
  4986. /// 01b9 <id>.L (ZC_DISPEL)
  4987. void clif_skillcastcancel( block_list& bl ){
  4988. PACKET_ZC_DISPEL packet{};
  4989. packet.packetType = HEADER_ZC_DISPEL;
  4990. packet.gid = bl.id;
  4991. clif_send( &packet, sizeof(PACKET_ZC_DISPEL), &bl, AREA );
  4992. }
  4993. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4994. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4995. /// num (only used when skill id = NV_BASIC and cause = 0):
  4996. /// 0 = "skill failed" MsgStringTable[159]
  4997. /// 1 = "no emotions" MsgStringTable[160]
  4998. /// 2 = "no sit" MsgStringTable[161]
  4999. /// 3 = "no chat" MsgStringTable[162]
  5000. /// 4 = "no party" MsgStringTable[163]
  5001. /// 5 = "no shout" MsgStringTable[164]
  5002. /// 6 = "no PKing" MsgStringTable[165]
  5003. /// 7 = "no alligning" MsgStringTable[383]
  5004. /// ? = ignored
  5005. /// cause:
  5006. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  5007. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5008. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5009. /// "skill failed" MsgStringTable[204] (otherwise)
  5010. /// ... = @see enum useskill_fail_cause
  5011. /// ? = ignored
  5012. ///
  5013. /// if(result!=0) doesn't display any of the previous messages
  5014. /// Note: when this packet is received an unknown flag is always set to 0,
  5015. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5016. void clif_skill_fail( map_session_data& sd, uint16 skill_id, enum useskill_fail_cause cause, int32 btype, t_itemid itemId ){
  5017. if(battle_config.display_skill_fail&1)
  5018. return; //Disable all skill failed messages
  5019. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd.state.showdelay)
  5020. return; //Disable delay failed messages
  5021. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5022. return;
  5023. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5024. return;
  5025. PACKET_ZC_ACK_TOUSESKILL p = {};
  5026. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5027. p.skillId = skill_id;
  5028. p.btype = btype;
  5029. p.itemId = itemId;
  5030. p.flag = 0; // 0 - failed
  5031. p.cause = cause;
  5032. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  5033. }
  5034. /// Skill cooldown display icon.
  5035. /// 043d <skill ID>.W <tick>.L (ZC_SKILL_POSTDELAY)
  5036. void clif_skill_cooldown( map_session_data &sd, uint16 skill_id, t_tick tick ){
  5037. #if PACKETVER_MAIN_NUM >= 20081112 || PACKETVER_RE_NUM >= 20081111 || defined(PACKETVER_ZERO)
  5038. PACKET_ZC_SKILL_POSTDELAY packet{};
  5039. packet.PacketType = HEADER_ZC_SKILL_POSTDELAY;
  5040. packet.SKID = skill_id;
  5041. packet.DelayTM = client_tick(tick);
  5042. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5043. #endif
  5044. }
  5045. /// Skill attack effect and damage.
  5046. /// 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)
  5047. /// 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)
  5048. int32 clif_skill_damage( block_list& src, block_list& dst, t_tick tick, int32 sdelay, int32 ddelay, int64 sdamage, int32 div, uint16 skill_id, uint16 skill_lv, e_damage_type type ){
  5049. type = clif_calc_delay( dst, type, div, sdamage );
  5050. sdamage = clif_hallucination_damage( dst, sdamage );
  5051. PACKET_ZC_NOTIFY_SKILL packet{};
  5052. packet.PacketType = HEADER_ZC_NOTIFY_SKILL;
  5053. packet.SKID = skill_id;
  5054. packet.AID = src.id;
  5055. packet.targetID = dst.id;
  5056. packet.startTime = client_tick( tick );
  5057. packet.attackMT = sdelay;
  5058. packet.attackedMT = ddelay;
  5059. auto damage = std::min( static_cast<decltype(packet.damage)>( sdamage ), std::numeric_limits<decltype(packet.damage)>::max() );
  5060. if (battle_config.hide_woe_damage && map_flag_gvg(src.m)) {
  5061. packet.damage = static_cast<decltype(packet.damage)>(damage ? div : 0);
  5062. } else {
  5063. packet.damage = damage;
  5064. }
  5065. packet.level = skill_lv;
  5066. packet.count = static_cast<decltype(packet.count)>(div);
  5067. // For some reason, late 2013 and newer clients have
  5068. // a issue that causes players and monsters to endure
  5069. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5070. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5071. #if PACKETVER < 20131223
  5072. packet.action = static_cast<decltype(packet.action)>(type);
  5073. #else
  5074. packet.action = static_cast<decltype(packet.action)>(( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type);
  5075. #endif
  5076. if (disguised(&dst)) {
  5077. clif_send( &packet, sizeof( packet ), &dst, AREA_WOS );
  5078. packet.targetID = disguised_bl_id( dst.id );
  5079. clif_send( &packet, sizeof( packet ), &dst, SELF );
  5080. } else {
  5081. clif_send( &packet, sizeof( packet ), &dst, AREA );
  5082. }
  5083. if (disguised(&src)) {
  5084. packet.AID = disguised_bl_id( src.id );
  5085. if (disguised(&dst)) {
  5086. packet.targetID = dst.id;
  5087. }
  5088. if (damage > 0) {
  5089. packet.damage = -1;
  5090. }
  5091. clif_send( &packet, sizeof( packet ), &src, SELF );
  5092. }
  5093. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5094. return clif_calc_walkdelay( dst, ddelay, type, damage, div );
  5095. }
  5096. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5097. /// 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
  5098. /*
  5099. int32 clif_skill_damage2(struct block_list *src,struct block_list *dst,t_tick tick,int32 sdelay,int32 ddelay,int32 damage,int32 div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  5100. {
  5101. unsigned char buf[64];
  5102. nullpo_ret(src);
  5103. nullpo_ret(dst);
  5104. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5105. type = clif_calc_delay( *dst, type, div, damage );
  5106. damage = clif_hallucination_damage( *dst, damage );
  5107. WBUFW(buf,0)=0x115;
  5108. WBUFW(buf,2)=skill_id;
  5109. WBUFL(buf,4)=src->id;
  5110. WBUFL(buf,8)=dst->id;
  5111. WBUFL(buf,12)=client_tick(tick);
  5112. WBUFL(buf,16)=sdelay;
  5113. WBUFL(buf,20)=ddelay;
  5114. WBUFW(buf,24)=dst->x;
  5115. WBUFW(buf,26)=dst->y;
  5116. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5117. WBUFW(buf,28)=damage?div:0;
  5118. } else {
  5119. WBUFW(buf,28)=damage;
  5120. }
  5121. WBUFW(buf,30)=skill_lv;
  5122. WBUFW(buf,32)=div;
  5123. WBUFB(buf,34)=type;
  5124. clif_send(buf,packet_len(0x115),src,AREA);
  5125. if(disguised(src)) {
  5126. WBUFL(buf,4)=disguised_bl_id(src->id);
  5127. if(damage > 0)
  5128. WBUFW(buf,28)=-1;
  5129. clif_send(buf,packet_len(0x115),src,SELF);
  5130. }
  5131. if (disguised(dst)) {
  5132. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5133. if (disguised(src))
  5134. WBUFL(buf,4)=src->id;
  5135. else if(damage > 0)
  5136. WBUFW(buf,28)=-1;
  5137. clif_send(buf,packet_len(0x115),dst,SELF);
  5138. }
  5139. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5140. return clif_calc_walkdelay(*dst,ddelay,type,damage,div);
  5141. }
  5142. */
  5143. /// Non-damaging skill effect
  5144. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL)
  5145. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2)
  5146. bool clif_skill_nodamage( block_list* src, block_list& dst, uint16 skill_id, int32 heal, bool success ){
  5147. PACKET_ZC_USE_SKILL p{};
  5148. p.PacketType = HEADER_ZC_USE_SKILL;
  5149. p.SKID = skill_id;
  5150. p.level = std::min( static_cast<decltype(p.level)>( heal ), std::numeric_limits<decltype(p.level)>::max() );
  5151. p.targetAID = dst.id;
  5152. p.result = success;
  5153. if(src != nullptr){
  5154. p.srcAID = src->id;
  5155. }else{
  5156. p.srcAID = 0;
  5157. }
  5158. if (disguised(&dst)) {
  5159. clif_send(&p, sizeof(p), &dst, AREA_WOS);
  5160. p.targetAID = disguised_bl_id(dst.id);
  5161. clif_send(&p, sizeof(p), &dst, SELF);
  5162. } else
  5163. clif_send(&p, sizeof(p), &dst, AREA);
  5164. if(src != nullptr && disguised(src)) {
  5165. p.srcAID = disguised_bl_id(src->id);
  5166. if (disguised(&dst)){
  5167. // It is necessary to revert the changes done above for the disguised target
  5168. p.targetAID = dst.id;
  5169. }
  5170. clif_send(&p, sizeof(p), src, SELF);
  5171. }
  5172. return success;
  5173. }
  5174. /// Non-damaging ground skill effect.
  5175. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L (ZC_NOTIFY_GROUNDSKILL)
  5176. void clif_skill_poseffect( block_list& bl, uint16 skill_id, uint16 skill_lv, uint16 x, uint16 y, t_tick tick ){
  5177. PACKET_ZC_NOTIFY_GROUNDSKILL packet{};
  5178. packet.PacketType = HEADER_ZC_NOTIFY_GROUNDSKILL;
  5179. packet.SKID = skill_id;
  5180. packet.AID = bl.id;
  5181. packet.level = skill_lv;
  5182. packet.xPos = x;
  5183. packet.yPos = y;
  5184. packet.startTime = client_tick( tick );
  5185. if (disguised(&bl)) {
  5186. clif_send( &packet, sizeof( packet ), &bl, AREA_WOS );
  5187. packet.AID = disguised_bl_id( bl.id );
  5188. clif_send( &packet, sizeof( packet ), &bl, SELF );
  5189. } else {
  5190. clif_send( &packet, sizeof( packet ), &bl, AREA );
  5191. }
  5192. }
  5193. /// Presents a list of available warp destinations.
  5194. /// 011c <skill id>.W { <map name>.16B }*4 (ZC_WARPLIST)
  5195. /// 0abe <lenght>.W <skill id>.W { <map name>.16B }*? (ZC_WARPLIST2)
  5196. void clif_skill_warppoint( map_session_data& sd, uint16 skill_id, uint16 skill_lv, std::vector<std::string>& maps ){
  5197. if(maps.empty())
  5198. return;
  5199. #if PACKETVER_MAIN_NUM >= 20170502 || PACKETVER_RE_NUM >= 20170419 || defined(PACKETVER_ZERO)
  5200. PACKET_ZC_WARPLIST* p = reinterpret_cast<PACKET_ZC_WARPLIST*>( packet_buffer );
  5201. p->packetType = HEADER_ZC_WARPLIST;
  5202. p->packetLength = sizeof( *p );
  5203. p->skillId = skill_id;
  5204. size_t memoCount = 0;
  5205. for( std::string& map : maps ){
  5206. if( map.empty() ){
  5207. continue;
  5208. }
  5209. PACKET_ZC_WARPLIST_sub& warp = p->maps[memoCount];
  5210. mapindex_getmapname_ext( map.c_str(), warp.map );
  5211. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( warp ) );
  5212. memoCount++;
  5213. }
  5214. clif_send( p, p->packetLength, &sd.bl, SELF );
  5215. #else
  5216. PACKET_ZC_WARPLIST p = {};
  5217. p.packetType = HEADER_ZC_WARPLIST;
  5218. p.skillId = skill_id;
  5219. size_t memoCount = 0, max = 4;
  5220. for( std::string& map : maps ){
  5221. if( map.empty() ){
  5222. continue;
  5223. }
  5224. PACKET_ZC_WARPLIST_sub& warp = p.maps[memoCount];
  5225. mapindex_getmapname_ext( map.c_str(), warp.map );
  5226. if( memoCount++ == max ){
  5227. break;
  5228. }
  5229. }
  5230. for( ; memoCount < max; memoCount++ ){
  5231. PACKET_ZC_WARPLIST_sub& warp = p.maps[memoCount];
  5232. strcpy( warp.map, "" );
  5233. }
  5234. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  5235. #endif
  5236. sd.menuskill_id = skill_id;
  5237. if (skill_id == AL_WARP) {
  5238. sd.menuskill_val = (sd.ud.skillx<<16)|sd.ud.skilly; //Store warp position here.
  5239. sd.state.workinprogress = WIP_DISABLE_ALL;
  5240. } else
  5241. sd.menuskill_val = skill_lv;
  5242. }
  5243. /// Memo message.
  5244. /// 011e <type>.B (ZC_ACK_REMEMBER_WARPPOINT)
  5245. /// type:
  5246. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5247. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5248. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5249. ///
  5250. /// @param sd Who receives the message
  5251. /// @param type What message
  5252. void clif_skill_memomessage( map_session_data& sd, e_ack_remember_warppoint_result result ){
  5253. PACKET_ZC_ACK_REMEMBER_WARPPOINT packet{};
  5254. packet.packetType = HEADER_ZC_ACK_REMEMBER_WARPPOINT;
  5255. packet.type = static_cast<decltype(packet.type)>(result);
  5256. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5257. }
  5258. /// Teleport message.
  5259. /// 0189 <type>.W (ZC_NOTIFY_MAPINFO)
  5260. /// type:
  5261. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5262. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5263. /// 2 = "This skill cannot be used in this area"
  5264. /// 3 = "This item cannot be used in this area"
  5265. ///
  5266. /// @param sd Who receives the message
  5267. /// @param type What message
  5268. void clif_skill_teleportmessage( map_session_data& sd, e_notify_mapinfo_result result ){
  5269. PACKET_ZC_NOTIFY_MAPINFO packet{};
  5270. packet.packetType = HEADER_ZC_NOTIFY_MAPINFO;
  5271. packet.type = static_cast<decltype(packet.type)>(result);
  5272. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5273. }
  5274. /// Displays Sense (WZ_ESTIMATION) information window.
  5275. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5276. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B (ZC_MONSTER_INFO)
  5277. void clif_skill_estimation( map_session_data& sd, mob_data& md ){
  5278. PACKET_ZC_MONSTER_INFO packet{};
  5279. packet.packetType = HEADER_ZC_MONSTER_INFO;
  5280. packet.class_ = md.vd->class_;
  5281. packet.level = static_cast<decltype(packet.level)>( md.level );
  5282. packet.size = md.status.size;
  5283. packet.hp = md.status.hp;
  5284. packet.def = static_cast<decltype(packet.def)>( ((battle_config.estimation_type&1) ? md.status.def : 0 ) + ((battle_config.estimation_type&2) ? md.status.def2 : 0 ) );
  5285. packet.race = md.status.race;
  5286. packet.mdef = static_cast<decltype(packet.mdef)>( ((battle_config.estimation_type&1) ? md.status.mdef : 0 ) + ((battle_config.estimation_type&2) ? md.status.mdef2 : 0 ) );
  5287. packet.element = md.status.def_ele;
  5288. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5289. packet.water = static_cast<decltype(packet.water)>( std::max( elemental_attribute_db.getAttribute(md.status.ele_lv, ELE_WATER, md.status.def_ele), (int16)0 ) );
  5290. packet.earth = static_cast<decltype(packet.earth)>( std::max( elemental_attribute_db.getAttribute(md.status.ele_lv, ELE_EARTH, md.status.def_ele), (int16)0 ) );
  5291. packet.fire = static_cast<decltype(packet.fire)>( std::max( elemental_attribute_db.getAttribute(md.status.ele_lv, ELE_FIRE, md.status.def_ele), (int16)0 ) );
  5292. packet.wind = static_cast<decltype(packet.wind)>( std::max( elemental_attribute_db.getAttribute(md.status.ele_lv, ELE_WIND, md.status.def_ele), (int16)0 ) );
  5293. packet.poison = static_cast<decltype(packet.poison)>( std::max( elemental_attribute_db.getAttribute(md.status.ele_lv, ELE_POISON, md.status.def_ele), (int16)0 ) );
  5294. packet.holy = static_cast<decltype(packet.holy)>( std::max( elemental_attribute_db.getAttribute(md.status.ele_lv, ELE_HOLY, md.status.def_ele), (int16)0 ) );
  5295. packet.shadow = static_cast<decltype(packet.shadow)>( std::max( elemental_attribute_db.getAttribute(md.status.ele_lv, ELE_DARK, md.status.def_ele), (int16)0 ) );
  5296. packet.ghost = static_cast<decltype(packet.ghost)>( std::max( elemental_attribute_db.getAttribute(md.status.ele_lv, ELE_GHOST, md.status.def_ele), (int16)0 ) );
  5297. packet.undead = static_cast<decltype(packet.undead)>( std::max( elemental_attribute_db.getAttribute(md.status.ele_lv, ELE_UNDEAD, md.status.def_ele), (int16)0 ) );
  5298. clif_send( &packet, sizeof( packet ), &sd.bl, (sd.status.party_id > 0) ? PARTY_SAMEMAP : SELF );
  5299. }
  5300. /// Presents a textual list of producable items.
  5301. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }* (ZC_MAKABLEITEMLIST)
  5302. /// material id:
  5303. /// unused by the client
  5304. void clif_skill_produce_mix_list( map_session_data& sd, int32 skill_id, int32 trigger ){
  5305. // Avoid resending the menu
  5306. if( sd.menuskill_id == skill_id ){
  5307. return;
  5308. }
  5309. if (skill_id == GC_CREATENEWPOISON)
  5310. skill_id = GC_RESEARCHNEWPOISON;
  5311. PACKET_ZC_MAKABLEITEMLIST* p = reinterpret_cast<PACKET_ZC_MAKABLEITEMLIST*>( packet_buffer );
  5312. p->packetType = HEADER_ZC_MAKABLEITEMLIST;
  5313. p->packetLength = sizeof( *p );
  5314. int32 count = 0;
  5315. for( int32 i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5316. if( !skill_can_produce_mix( &sd, skill_produce_db[i].nameid, trigger, 1 ) ){
  5317. continue;
  5318. }
  5319. if( skill_id > 0 && skill_produce_db[i].req_skill != skill_id ){
  5320. continue;
  5321. }
  5322. PACKET_ZC_MAKABLEITEMLIST_sub& entry = p->items[count];
  5323. entry.itemId = client_nameid( skill_produce_db[i].nameid );
  5324. entry.material[0] = 0;
  5325. entry.material[1] = 0;
  5326. entry.material[2] = 0;
  5327. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  5328. count++;
  5329. }
  5330. clif_send( p, p->packetLength, &sd.bl, SELF );
  5331. if( count > 0 ){
  5332. sd.menuskill_id = skill_id;
  5333. sd.menuskill_val = trigger;
  5334. }
  5335. }
  5336. /// Present a list of producable items.
  5337. /// 025a <packet len>.W <mk type>.W { <name id>.W }* (ZC_MAKINGITEM_LIST)
  5338. /// mk type:
  5339. /// 1 = cooking
  5340. /// 2 = arrow
  5341. /// 3 = elemental
  5342. /// 4 = GN_MIX_COOKING
  5343. /// 5 = GN_MAKEBOMB
  5344. /// 6 = GN_S_PHARMACY
  5345. /// 7 = MT_M_MACHINE
  5346. /// 8 = BO_BIONIC_PHARMACY
  5347. void clif_cooking_list( map_session_data& sd, int32 trigger, uint16 skill_id, int32 qty, int32 list_type ){
  5348. #if PACKETVER >= 20051010
  5349. // Avoid resending the menu
  5350. if( sd.menuskill_id == skill_id ){
  5351. return;
  5352. }
  5353. PACKET_ZC_MAKINGITEM_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGITEM_LIST*>( packet_buffer );
  5354. p->packetType = HEADER_ZC_MAKINGITEM_LIST;
  5355. p->packetLength = sizeof( *p );
  5356. p->makeItem = list_type;
  5357. int32 count = 0;
  5358. for( int32 i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5359. if( !skill_can_produce_mix( &sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5360. continue;
  5361. }
  5362. PACKET_ZC_MAKINGITEM_LIST_sub& entry = p->items[count];
  5363. entry.itemId = client_nameid( skill_produce_db[i].nameid );
  5364. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  5365. count++;
  5366. }
  5367. if( count > 0 || skill_id == AM_PHARMACY ){
  5368. clif_send( p, p->packetLength, &sd.bl, SELF );
  5369. sd.menuskill_id = skill_id;
  5370. sd.menuskill_val = trigger;
  5371. sd.menuskill_val2 = qty; // amount.
  5372. }else{
  5373. clif_menuskill_clear( &sd );
  5374. #if PACKETVER >= 20090922
  5375. clif_msg_skill( &sd, skill_id, MSI_SKILL_INVENTORY_KINDCNT_OVER );
  5376. #else
  5377. clif_send( p, p->packetLength, &sd.bl, SELF );
  5378. #endif
  5379. }
  5380. #endif
  5381. }
  5382. /// Notifies clients of a status change.
  5383. /// 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)]
  5384. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5385. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5386. /// @param bl Sends packet to clients around this object
  5387. /// @param id ID of object that has this effect
  5388. /// @param type Status icon see enum efst_type
  5389. /// @param flag 1:Active, 0:Deactive
  5390. /// @param tick Duration in ms
  5391. /// @param val1
  5392. /// @param val2
  5393. /// @param val3
  5394. void clif_status_change_sub(struct block_list *bl, int32 id, int32 type, int32 flag, t_tick tick, int32 val1, int32 val2, int32 val3, enum send_target target_type)
  5395. {
  5396. unsigned char buf[32];
  5397. if (type == EFST_BLANK) //It shows nothing on the client...
  5398. return;
  5399. if (type == EFST_POSTDELAY && tick == 0)
  5400. return;
  5401. nullpo_retv(bl);
  5402. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5403. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5404. tick = 200;
  5405. #if PACKETVER >= 20120618
  5406. if (flag && battle_config.display_status_timers)
  5407. WBUFW(buf,0) = 0x983;
  5408. else
  5409. #elif PACKETVER >= 20090121
  5410. if (flag && battle_config.display_status_timers)
  5411. WBUFW(buf,0) = 0x43f;
  5412. else
  5413. #endif
  5414. WBUFW(buf,0) = 0x196;
  5415. WBUFW(buf,2) = type;
  5416. WBUFL(buf,4) = id;
  5417. WBUFB(buf,8) = flag;
  5418. #if PACKETVER >= 20120618
  5419. if (flag && battle_config.display_status_timers) {
  5420. if (tick <= 0)
  5421. tick = 9999; // this is indeed what official servers do
  5422. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5423. WBUFL(buf,13) = client_tick(tick);
  5424. WBUFL(buf,17) = val1;
  5425. WBUFL(buf,21) = val2;
  5426. WBUFL(buf,25) = val3;
  5427. }
  5428. #elif PACKETVER >= 20090121
  5429. if (flag && battle_config.display_status_timers) {
  5430. if (tick <= 0)
  5431. tick = 9999; // this is indeed what official servers do
  5432. WBUFL(buf,9) = client_tick(tick);
  5433. WBUFL(buf,13) = val1;
  5434. WBUFL(buf,17) = val2;
  5435. WBUFL(buf,21) = val3;
  5436. }
  5437. #endif
  5438. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5439. }
  5440. /* Sends status effect to clients around the bl
  5441. * @param bl Object that has the effect
  5442. * @param type Status icon see enum efst_type
  5443. * @param flag 1:Active, 0:Deactive
  5444. * @param tick Duration in ms
  5445. * @param val1
  5446. * @param val2
  5447. * @param val3
  5448. */
  5449. void clif_status_change(struct block_list *bl, int32 type, int32 flag, t_tick tick, int32 val1, int32 val2, int32 val3) {
  5450. map_session_data *sd = nullptr;
  5451. if (type == EFST_BLANK) //It shows nothing on the client...
  5452. return;
  5453. if (type == EFST_POSTDELAY && tick == 0)
  5454. return;
  5455. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5456. return;
  5457. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5458. // Older clients display normal riding icon.
  5459. if (type == EFST_MADOGEAR_TYPE)
  5460. type = EFST_RIDING;
  5461. #endif
  5462. nullpo_retv(bl);
  5463. sd = BL_CAST(BL_PC, bl);
  5464. // Check if current bl type is in the returned bitmask and only send status changes that actually matter to the client
  5465. if (!(status_efst_get_bl_type(static_cast<efst_type>(type)) & bl->type))
  5466. return;
  5467. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5468. }
  5469. /**
  5470. * Send any active EFST to those around.
  5471. * @param tbl: Unit to send the packet to
  5472. * @param bl: Objects walking into view
  5473. * @param target: Client send type
  5474. */
  5475. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5476. unsigned char i;
  5477. struct sc_display_entry **sc_display;
  5478. unsigned char sc_display_count;
  5479. bool spheres_sent;
  5480. nullpo_retv(bl);
  5481. switch( bl->type ){
  5482. case BL_PC: {
  5483. map_session_data* sd = (map_session_data*)bl;
  5484. sc_display = sd->sc_display;
  5485. sc_display_count = sd->sc_display_count;
  5486. spheres_sent = !sd->state.connect_new;
  5487. }
  5488. break;
  5489. case BL_NPC: {
  5490. struct npc_data* nd = (struct npc_data*)bl;
  5491. sc_display = nd->sc_display;
  5492. sc_display_count = nd->sc_display_count;
  5493. spheres_sent = true;
  5494. }
  5495. break;
  5496. default:
  5497. return;
  5498. }
  5499. for (i = 0; i < sc_display_count; i++) {
  5500. enum sc_type type = sc_display[i]->type;
  5501. status_change *sc = status_get_sc(bl);
  5502. const struct TimerData *td = (sc && sc->getSCE(type) ? get_timer(sc->getSCE(type)->timer) : nullptr);
  5503. t_tick tick = 0;
  5504. if (td)
  5505. tick = DIFF_TICK(td->tick, gettick());
  5506. // Status changes that need special handling
  5507. switch( type ){
  5508. case SC_SPHERE_1:
  5509. case SC_SPHERE_2:
  5510. case SC_SPHERE_3:
  5511. case SC_SPHERE_4:
  5512. case SC_SPHERE_5:
  5513. if( spheres_sent ){
  5514. target = AREA_WOS;
  5515. }
  5516. break;
  5517. case SC_HELLS_PLANT:
  5518. if( sc && sc->getSCE(type) ){
  5519. tick = sc->getSCE(type)->val4;
  5520. }
  5521. break;
  5522. }
  5523. #if PACKETVER > 20120418
  5524. 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);
  5525. #else
  5526. 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);
  5527. #endif
  5528. }
  5529. }
  5530. /// Notifies the client when a player enters the screen with an active EFST.
  5531. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5532. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5533. void clif_efst_status_change(struct block_list *bl, int32 tid, enum send_target target, int32 type, t_tick tick, int32 val1, int32 val2, int32 val3) {
  5534. #if PACKETVER >= 20111108
  5535. unsigned char buf[32];
  5536. #if PACKETVER >= 20120618
  5537. const int32 cmd = 0x984;
  5538. #elif PACKETVER >= 20111108
  5539. const int32 cmd = 0x8ff;
  5540. #endif
  5541. int32 offset = 0;
  5542. if (type == EFST_BLANK)
  5543. return;
  5544. nullpo_retv(bl);
  5545. if (tick <= 0)
  5546. tick = 9999;
  5547. WBUFW(buf,offset + 0) = cmd;
  5548. WBUFL(buf,offset + 2) = tid;
  5549. WBUFW(buf,offset + 6) = type;
  5550. #if PACKETVER >= 20111108
  5551. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5552. #if PACKETVER >= 20120618
  5553. WBUFL(buf,offset + 12) = client_tick(tick);
  5554. offset += 4;
  5555. #endif
  5556. WBUFL(buf,offset + 12) = val1;
  5557. WBUFL(buf,offset + 16) = val2;
  5558. WBUFL(buf,offset + 20) = val3;
  5559. #endif
  5560. clif_send(buf,packet_len(cmd),bl,target);
  5561. #endif
  5562. }
  5563. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5564. /// 008e <packet len>.W <message>.?B
  5565. void clif_displaymessage(const int32 fd, const char* mes)
  5566. {
  5567. nullpo_retv(mes);
  5568. if( session_isActive( fd ) ){
  5569. char *message, *line;
  5570. message = aStrdup(mes);
  5571. line = strtok(message, "\n");
  5572. while(line != nullptr) {
  5573. #if PACKETVER == 20141022
  5574. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5575. /** so we redirect to ZC_NPC_CHAT **/
  5576. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5577. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5578. uint16 len = strnlen(line, CHAT_SIZE_MAX);
  5579. if (len > 0) {
  5580. WFIFOHEAD(fd, 13 + len);
  5581. WFIFOW(fd, 0) = 0x2C1;
  5582. WFIFOW(fd, 2) = 13 + len;
  5583. WFIFOL(fd, 4) = 0;
  5584. WFIFOL(fd, 8) = color;
  5585. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5586. WFIFOSET(fd, WFIFOW(fd, 2));
  5587. }
  5588. #else
  5589. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5590. int16 len;
  5591. len = static_cast<decltype(len)>( strnlen(line, CHAT_SIZE_MAX) );
  5592. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5593. WFIFOHEAD(fd, 5 + len);
  5594. WFIFOW(fd,0) = 0x8e;
  5595. WFIFOW(fd,2) = 5 + len; // 4 + len + nullptr teminate
  5596. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5597. WFIFOSET(fd, 5 + len);
  5598. }
  5599. #endif
  5600. line = strtok(nullptr, "\n");
  5601. }
  5602. aFree(message);
  5603. }
  5604. }
  5605. /// Send broadcast message in yellow or blue without font formatting.
  5606. /// 009a <packet len>.W <message>.?B (ZC_BROADCAST)
  5607. void clif_broadcast(struct block_list* bl, const char* mes, size_t len, int32 type, enum send_target target)
  5608. {
  5609. nullpo_retv(mes);
  5610. if (len < 2)
  5611. return;
  5612. PACKET_ZC_BROADCAST* p = reinterpret_cast<PACKET_ZC_BROADCAST*>( packet_buffer );
  5613. p->packetType = HEADER_ZC_BROADCAST;
  5614. p->PacketLength = sizeof( *p );
  5615. if( ( type&BC_BLUE ) != 0 ){
  5616. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5617. const char* color = "blue";
  5618. size_t length = strlen( color );
  5619. strcpy( p->message, color );
  5620. p->PacketLength += static_cast<decltype(p->PacketLength)>( length );
  5621. strncpy( &p->message[length], mes, len );
  5622. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5623. }else if( ( type&BC_WOE ) != 0 ){
  5624. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5625. const char* color = "ssss";
  5626. size_t length = strlen( color );
  5627. strcpy( p->message, color );
  5628. p->PacketLength += static_cast<decltype(p->PacketLength)>( length );
  5629. strncpy( &p->message[length], mes, len );
  5630. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5631. }else{
  5632. strncpy( p->message, mes, len );
  5633. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5634. }
  5635. clif_send( p, p->PacketLength, bl, target );
  5636. }
  5637. /*==========================================
  5638. * Displays a message on a 'bl' to all it's nearby clients
  5639. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5640. *------------------------------------------*/
  5641. void clif_GlobalMessage( block_list& bl, const char* message, enum send_target target ){
  5642. nullpo_retv(message);
  5643. int16 len = (int16)( strlen( message ) + 1 );
  5644. if( len > CHAT_SIZE_MAX ) {
  5645. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5646. len = CHAT_SIZE_MAX;
  5647. }
  5648. PACKET_ZC_NOTIFY_CHAT* p = reinterpret_cast<PACKET_ZC_NOTIFY_CHAT*>( packet_buffer );
  5649. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5650. p->PacketLength = sizeof( *p );
  5651. p->GID = bl.id;
  5652. safestrncpy( p->Message, message, len );
  5653. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5654. clif_send( p, p->PacketLength, &bl, target );
  5655. }
  5656. /// Send broadcast message with font formatting.
  5657. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5658. void clif_broadcast2(struct block_list* bl, const char* mes, size_t len, unsigned long fontColor, int16 fontType, int16 fontSize, int16 fontAlign, int16 fontY, enum send_target target)
  5659. {
  5660. nullpo_retv(mes);
  5661. if (len < 2)
  5662. return;
  5663. PACKET_ZC_BROADCAST2* p = reinterpret_cast<PACKET_ZC_BROADCAST2*>( packet_buffer );
  5664. p->packetType = HEADER_ZC_BROADCAST2;
  5665. p->PacketLength = sizeof( *p );
  5666. p->fontColor = fontColor;
  5667. p->fontType = fontType;
  5668. p->fontSize = fontSize;
  5669. p->fontAlign = fontAlign;
  5670. p->fontY = fontY;
  5671. strncpy( p->message, mes, len );
  5672. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5673. clif_send( p, p->PacketLength, bl, target );
  5674. }
  5675. /*
  5676. * Display *msg to all *users in channel
  5677. */
  5678. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5679. DBIterator *iter;
  5680. map_session_data *user;
  5681. uint16 msg_len = 0, len = 0;
  5682. unsigned char buf[CHAT_SIZE_MAX];
  5683. if (!channel || !msg)
  5684. return;
  5685. msg_len = (uint16)(strlen(msg) + 1);
  5686. if( msg_len > sizeof(buf)-12 ) {
  5687. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5688. msg_len = sizeof(buf)-12;
  5689. }
  5690. WBUFW(buf,0) = 0x2C1;
  5691. WBUFW(buf,2) = (len = msg_len + 12);
  5692. WBUFL(buf,4) = 0;
  5693. WBUFL(buf,8) = color;
  5694. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5695. iter = db_iterator(channel->users);
  5696. for( user = (map_session_data *)dbi_first(iter); dbi_exists(iter); user = (map_session_data *)dbi_next(iter) ) {
  5697. clif_send(buf, len, &user->bl, SELF);
  5698. }
  5699. dbi_destroy(iter);
  5700. }
  5701. /// Displays heal effect.
  5702. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5703. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5704. /// var id:
  5705. /// 5 = HP (SP_HP)
  5706. /// 7 = SP (SP_SP)
  5707. /// ? = ignored
  5708. void clif_heal( map_session_data& sd, int32 type, uint32 val ) {
  5709. PACKET_ZC_RECOVERY packet{};
  5710. packet.packetType = HEADER_ZC_RECOVERY;
  5711. packet.type = static_cast<decltype(packet.type)>(type);
  5712. packet.amount = std::min( static_cast<decltype(packet.amount)>( val ), std::numeric_limits<decltype(packet.amount)>::max() );
  5713. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5714. }
  5715. /// Displays resurrection effect.
  5716. /// 0148 <id>.L <type>.W (ZC_RESURRECTION)
  5717. /// type:
  5718. /// ignored
  5719. void clif_resurrection( block_list& bl ){
  5720. PACKET_ZC_RESURRECTION packet{};
  5721. packet.packetType = HEADER_ZC_RESURRECTION;
  5722. packet.gid = bl.id;
  5723. packet.type = 0;
  5724. clif_send( &packet, sizeof( packet ), &bl, AREA );
  5725. if (disguised(&bl)) {
  5726. clif_spawn(&bl);
  5727. }
  5728. }
  5729. /// Sets the map property
  5730. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5731. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5732. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5733. {
  5734. #if PACKETVER >= 20121010
  5735. int16 cmd = 0x99b;
  5736. unsigned char buf[8];
  5737. #else
  5738. int16 cmd = 0x199;
  5739. unsigned char buf[4];
  5740. #endif
  5741. WBUFW(buf,0)=cmd;
  5742. WBUFW(buf,2)=property;
  5743. #if PACKETVER >= 20121010
  5744. struct map_data *mapdata = map_getmapdata(bl->m);
  5745. map_session_data *sd = BL_CAST(BL_PC, bl);
  5746. WBUFL(buf,4) = ((mapdata->getMapFlag(MF_PVP) || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5747. ((mapdata->getMapFlag(MF_BATTLEGROUND) || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5748. ((mapdata->getMapFlag(MF_BATTLEGROUND) || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5749. ((mapdata->getMapFlag(MF_FORCEMINEFFECT) || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5750. ((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
  5751. ((mapdata->getMapFlag(MF_PVP))<<5)| // COUNT_PK - Show the PvP counter
  5752. ((mapdata->getMapFlag(MF_PARTYLOCK))<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5753. ((mapdata->getMapFlag(MF_BATTLEGROUND))<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5754. ((mapdata->getMapFlag(MF_NOCOSTUME))<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5755. ((!mapdata->getMapFlag(MF_NOUSECART))<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5756. ((!mapdata->getMapFlag(MF_NOSUNMOONSTARMIRACLE))<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5757. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5758. #endif
  5759. clif_send(buf,packet_len(cmd),bl,t);
  5760. }
  5761. /// Set the map type.
  5762. /// 01d6 <type>.W (ZC_NOTIFY_MAPPROPERTY2)
  5763. void clif_map_type( map_session_data& sd, e_map_type type ){
  5764. PACKET_ZC_NOTIFY_MAPPROPERTY2 packet{};
  5765. packet.packetType = HEADER_ZC_NOTIFY_MAPPROPERTY2;
  5766. packet.type = static_cast<decltype(packet.type)>(type);
  5767. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5768. }
  5769. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5770. /// 019a <id>.L <ranking>.L <total>.L
  5771. void clif_pvpset(map_session_data *sd,int32 pvprank,int32 pvpnum,int32 type)
  5772. {
  5773. if(type == 2) {
  5774. int32 fd = sd->fd;
  5775. WFIFOHEAD(fd,packet_len(0x19a));
  5776. WFIFOW(fd,0) = 0x19a;
  5777. WFIFOL(fd,2) = sd->bl.id;
  5778. WFIFOL(fd,6) = pvprank;
  5779. WFIFOL(fd,10) = pvpnum;
  5780. WFIFOSET(fd,packet_len(0x19a));
  5781. } else {
  5782. unsigned char buf[32];
  5783. WBUFW(buf,0) = 0x19a;
  5784. WBUFL(buf,2) = sd->bl.id;
  5785. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5786. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5787. else
  5788. WBUFL(buf,6) = pvprank;
  5789. WBUFL(buf,10) = pvpnum;
  5790. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5791. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5792. else if(!type)
  5793. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5794. else
  5795. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5796. }
  5797. }
  5798. /*==========================================
  5799. *
  5800. *------------------------------------------*/
  5801. void clif_map_property_mapall(int32 map_idx, enum map_property property)
  5802. {
  5803. struct block_list bl;
  5804. bl.id = 0;
  5805. bl.type = BL_NUL;
  5806. bl.m = map_idx;
  5807. clif_map_property( &bl, property, ALL_SAMEMAP );
  5808. }
  5809. /// Notifies the client about the result of a refine attempt.
  5810. /// 0188 <result>.W <index>.W <refine>.W (ZC_ACK_ITEMREFINING)
  5811. /// result:
  5812. /// 0 = success
  5813. /// 1 = failure
  5814. /// 2 = downgrade
  5815. /// 3 = failure (?)
  5816. void clif_refine( map_session_data& sd, uint16 index, e_ack_itemrefining result ){
  5817. PACKET_ZC_ACK_ITEMREFINING packet{};
  5818. packet.packetType = HEADER_ZC_ACK_ITEMREFINING;
  5819. packet.result = static_cast<decltype(packet.result)>(result);
  5820. packet.index = client_index( index );
  5821. packet.value = static_cast<decltype(packet.value)>( sd.inventory.u.items_inventory[index].refine );
  5822. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5823. }
  5824. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5825. /// 0223 <result>.L <nameid>.W
  5826. /// result:
  5827. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5828. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5829. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5830. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5831. void clif_upgrademessage( map_session_data* sd, int32 result, t_itemid item_id ){
  5832. PACKET_ZC_ACK_WEAPONREFINE p = {};
  5833. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5834. p.result = result;
  5835. p.itemId = client_nameid( item_id );
  5836. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5837. }
  5838. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5839. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5840. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5841. void clif_wis_message(map_session_data* sd, const char* nick, const char* mes, size_t mes_len, int32 gmlvl){
  5842. PACKET_ZC_WHISPER* p = reinterpret_cast<PACKET_ZC_WHISPER*>( packet_buffer );
  5843. p->PacketType = HEADER_ZC_WHISPER;
  5844. p->PacketLength = sizeof( *p );
  5845. safestrncpy( p->sender, nick, NAME_LENGTH );
  5846. safestrncpy( p->message, mes, mes_len );
  5847. p->PacketLength += static_cast<decltype( p->PacketLength )>( mes_len );
  5848. #if PACKETVER >= 20091104
  5849. map_session_data* ssd = map_nick2sd(nick, false);
  5850. // If it is not a message from the server or a player from another map-server
  5851. if( ssd != nullptr ){
  5852. gmlvl = pc_get_group_level(ssd);
  5853. }
  5854. p->isAdmin = (gmlvl == 99) ? 1 : 0;
  5855. #if PACKETVER_MAIN_NUM >= 20131204 || PACKETVER_RE_NUM >= 20131120 || defined(PACKETVER_ZERO)
  5856. if( ssd != nullptr ){
  5857. p->senderGID = ssd->bl.id;
  5858. }else{
  5859. p->senderGID = 0;
  5860. }
  5861. #endif
  5862. #endif
  5863. clif_send( p, p->PacketLength, &sd->bl, SELF );
  5864. }
  5865. /// Inform the player about the result of his whisper action
  5866. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5867. /// 09df <result>.B <CID>.L (ZC_ACK_WHISPER02).
  5868. /// result:
  5869. /// 0 = success to send whisper
  5870. /// 1 = target character is not loged in
  5871. /// 2 = ignored by target
  5872. /// 3 = everyone ignored by target
  5873. void clif_wis_end( map_session_data& sd, e_ack_whisper result ){
  5874. PACKET_ZC_ACK_WHISPER packet{};
  5875. packet.packetType = HEADER_ZC_ACK_WHISPER;
  5876. packet.result = static_cast<decltype(packet.result)>(result);
  5877. #if PACKETVER >= 20131223
  5878. packet.CID = sd.status.char_id;
  5879. #endif
  5880. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5881. }
  5882. /// Returns character name requested by char_id.
  5883. /// 0194 <char id>.L <name>.24B (ZC_ACK_REQNAME_BYGID)
  5884. /// 0af7 <flag>.W <char id>.L <name>.24B (ZC_ACK_REQNAME_BYGID)
  5885. void clif_solved_charname( map_session_data& sd, uint32 charid, const char* name ){
  5886. PACKET_ZC_ACK_REQNAME_BYGID packet{};
  5887. packet.packetType = HEADER_ZC_ACK_REQNAME_BYGID;
  5888. #if PACKETVER >= 20180221
  5889. packet.flag = name[0] ? 3 : 2;
  5890. #endif
  5891. packet.CID = charid;
  5892. safestrncpy( packet.name, name, NAME_LENGTH );
  5893. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5894. }
  5895. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5896. /// 017b <packet len>.W { <name id>.W }*
  5897. void clif_use_card(map_session_data *sd,int32 idx)
  5898. {
  5899. int32 i,c,ep;
  5900. int32 fd=sd->fd;
  5901. nullpo_retv(sd);
  5902. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5903. return;
  5904. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5905. return; //Avoid parsing invalid item indexes (no card/no item)
  5906. ep=sd->inventory_data[idx]->equip;
  5907. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5908. WFIFOW(fd,0)=0x17b;
  5909. for(i=c=0;i<MAX_INVENTORY;i++){
  5910. int32 j;
  5911. if(sd->inventory_data[i] == nullptr)
  5912. continue;
  5913. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5914. continue;
  5915. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5916. continue;
  5917. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5918. continue;
  5919. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5920. continue;
  5921. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5922. continue;
  5923. 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.
  5924. continue;
  5925. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5926. if( j == sd->inventory_data[i]->slots ) // No room
  5927. continue;
  5928. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5929. continue;
  5930. WFIFOW(fd,4+c*2)=i+2;
  5931. c++;
  5932. }
  5933. if( !c ) return; // no item is available for card insertion
  5934. WFIFOW(fd,2)=4+c*2;
  5935. WFIFOSET(fd,WFIFOW(fd,2));
  5936. }
  5937. /// Notifies the client about the result of item carding/composition.
  5938. /// 017d <equip index>.W <card index>.W <result>.B (ZC_ACK_ITEMCOMPOSITION)
  5939. /// result:
  5940. /// 0 = success
  5941. /// 1 = failure
  5942. void clif_insert_card( map_session_data& sd, int32 idx_equip, int32 idx_card, bool failure ){
  5943. PACKET_ZC_ACK_ITEMCOMPOSITION packet{};
  5944. packet.packetType = HEADER_ZC_ACK_ITEMCOMPOSITION;
  5945. packet.equipIndex = client_index( idx_equip );
  5946. packet.cardIndex = client_index( idx_card );
  5947. packet.result = failure;
  5948. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5949. }
  5950. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5951. /// 0177 <packet len>.W { <index>.W }*
  5952. void clif_item_identify_list(map_session_data *sd)
  5953. {
  5954. int32 i,c;
  5955. int32 fd;
  5956. nullpo_retv(sd);
  5957. fd=sd->fd;
  5958. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5959. WFIFOW(fd,0)=0x177;
  5960. for(i=c=0;i<MAX_INVENTORY;i++){
  5961. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5962. WFIFOW(fd,c*2+4)=client_index(i);
  5963. c++;
  5964. }
  5965. }
  5966. if(c > 0) {
  5967. WFIFOW(fd,2)=c*2+4;
  5968. WFIFOSET(fd,WFIFOW(fd,2));
  5969. sd->menuskill_id = MC_IDENTIFY;
  5970. sd->menuskill_val = c;
  5971. sd->state.workinprogress = WIP_DISABLE_ALL;
  5972. }
  5973. }
  5974. /// Notifies the client about the result of a item identify request.
  5975. /// 0179 <index>.W <result>.B (ZC_ACK_ITEMIDENTIFY)
  5976. /// result:
  5977. /// 0 = success
  5978. /// 1 = failure
  5979. void clif_item_identified( map_session_data& sd, int32 idx, bool failure ){
  5980. PACKET_ZC_ACK_ITEMIDENTIFY packet{};
  5981. packet.packetType = HEADER_ZC_ACK_ITEMIDENTIFY;
  5982. packet.index = client_index( idx );
  5983. packet.result = failure;
  5984. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5985. }
  5986. /// Presents a list of items that can be repaired.
  5987. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  5988. void clif_item_repair_list( map_session_data& sd, map_session_data& dstsd, uint16 lv ){
  5989. PACKET_ZC_REPAIRITEMLIST* p = reinterpret_cast<PACKET_ZC_REPAIRITEMLIST*>( packet_buffer );
  5990. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  5991. p->packetLength = sizeof( *p );
  5992. size_t c = 0;
  5993. for( size_t i = 0; i < MAX_INVENTORY; i++ ){
  5994. 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)){
  5995. p->items[c].index = static_cast<decltype( p->items[0].index )>( i );
  5996. p->items[c].itemId = client_nameid( dstsd.inventory.u.items_inventory[i].nameid );
  5997. p->items[c].refine = dstsd.inventory.u.items_inventory[i].refine;
  5998. clif_addcards( &p->items[c].slot, &dstsd.inventory.u.items_inventory[i] );
  5999. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  6000. c++;
  6001. }
  6002. }
  6003. if( c > 0 ){
  6004. clif_send( p, p->packetLength, &sd.bl, SELF );
  6005. sd.menuskill_id = BS_REPAIRWEAPON;
  6006. sd.menuskill_val = dstsd.bl.id;
  6007. sd.menuskill_val2 = lv;
  6008. }else{
  6009. clif_skill_fail( sd, sd.ud.skill_id );
  6010. }
  6011. }
  6012. /// Notifies the client about the result of a item repair request.
  6013. /// 01fe <index>.W <result>.B (ZC_ACK_ITEMREPAIR)
  6014. /// index:
  6015. /// ignored (inventory index)
  6016. /// result:
  6017. /// 0 = Item repair success.
  6018. /// 1 = Item repair failure.
  6019. void clif_item_repaireffect( map_session_data& sd, int32 idx, bool failure ){
  6020. PACKET_ZC_ACK_ITEMREPAIR packet{};
  6021. packet.packetType = HEADER_ZC_ACK_ITEMREPAIR;
  6022. packet.index = client_index( idx );
  6023. packet.result = failure;
  6024. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6025. }
  6026. /// Displays a message, that an equipment got damaged.
  6027. /// 02bb <equip location>.W <account id>.L (ZC_EQUIPITEM_DAMAGED)
  6028. void clif_item_damaged( map_session_data& sd, uint16 position ){
  6029. PACKET_ZC_EQUIPITEM_DAMAGED packet{};
  6030. packet.packetType = HEADER_ZC_EQUIPITEM_DAMAGED;
  6031. packet.equipLocation = position;
  6032. packet.GID = sd.bl.id;
  6033. // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6034. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6035. }
  6036. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6037. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6038. void clif_item_refine_list( map_session_data& sd ){
  6039. PACKET_ZC_NOTIFY_WEAPONITEMLIST* p = reinterpret_cast<PACKET_ZC_NOTIFY_WEAPONITEMLIST*>( packet_buffer );
  6040. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6041. p->packetLength = sizeof( *p );
  6042. uint16 skill_lv = pc_checkskill( &sd, WS_WEAPONREFINE );
  6043. int32 refine_item[MAX_WEAPON_LEVEL];
  6044. refine_item[0] = pc_search_inventory( &sd, ITEMID_PHRACON );
  6045. refine_item[1] = pc_search_inventory( &sd, ITEMID_EMVERETARCON );
  6046. refine_item[2] = refine_item[3] = pc_search_inventory( &sd, ITEMID_ORIDECON );
  6047. #ifdef RENEWAL
  6048. refine_item[4] = -1;
  6049. #endif
  6050. int32 count = 0;
  6051. for( int32 i = 0; i < MAX_INVENTORY; i++ ){
  6052. if( sd.inventory.u.items_inventory[i].nameid > 0 && sd.inventory.u.items_inventory[i].refine < skill_lv &&
  6053. sd.inventory_data[i] != nullptr && sd.inventory_data[i]->type == IT_WEAPON &&
  6054. sd.inventory.u.items_inventory[i].identify && sd.inventory_data[i]->weapon_level >= 1 &&
  6055. refine_item[sd.inventory_data[i]->weapon_level - 1] != -1 && !( sd.inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6056. p->items[count].index = client_index( i );
  6057. p->items[count].itemId = client_nameid( sd.inventory.u.items_inventory[i].nameid );
  6058. p->items[count].refine = sd.inventory.u.items_inventory[i].refine;
  6059. clif_addcards( &p->items[count].slot, &sd.inventory.u.items_inventory[i] );
  6060. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  6061. count++;
  6062. }
  6063. }
  6064. clif_send( p, p->packetLength, &sd.bl, SELF );
  6065. if( count > 0 ){
  6066. sd.menuskill_id = WS_WEAPONREFINE;
  6067. sd.menuskill_val = skill_lv;
  6068. }
  6069. }
  6070. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6071. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6072. void clif_item_skill( map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6073. nullpo_retv( sd );
  6074. PACKET_ZC_AUTORUN_SKILL p = {};
  6075. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6076. p.skill_id = skill_id;
  6077. p.skill_type = skill_get_inf( skill_id );
  6078. p.skill_lv = skill_lv;
  6079. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6080. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6081. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6082. p.up_flag = false;
  6083. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6084. }
  6085. /// Adds an item to character's cart.
  6086. /// 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)
  6087. /// 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)
  6088. /// 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)
  6089. void clif_cart_additem( map_session_data *sd, int32 n, int32 amount ){
  6090. nullpo_retv( sd );
  6091. int32 fd = sd->fd;
  6092. if( !session_isActive( fd ) ){
  6093. return;
  6094. }
  6095. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6096. return;
  6097. }
  6098. PACKET_ZC_ADD_ITEM_TO_CART p = {};
  6099. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6100. p.index = client_index( n );
  6101. p.amount = amount;
  6102. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6103. #if PACKETVER >= 5
  6104. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6105. #endif
  6106. p.identified = sd->cart.u.items_cart[n].identify;
  6107. p.damaged = sd->cart.u.items_cart[n].attribute;
  6108. p.refine = sd->cart.u.items_cart[n].refine;
  6109. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6110. #if PACKETVER >= 20150226
  6111. clif_add_random_options( p.option_data, sd->cart.u.items_cart[n] );
  6112. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6113. p.grade = sd->cart.u.items_cart[n].enchantgrade;
  6114. #endif
  6115. #endif
  6116. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6117. }
  6118. /// Acknowledge an item have been added to cart
  6119. /// 012c <result>.B (ZC_ACK_ADDITEM_TO_CART)
  6120. /// result:
  6121. /// 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6122. /// 1 = ADDITEM_TO_CART_FAIL_COUNT
  6123. void clif_cart_additem_ack( map_session_data& sd, e_ack_additem_to_cart flag ){
  6124. PACKET_ZC_ACK_ADDITEM_TO_CART packet{};
  6125. packet.packetType = HEADER_ZC_ACK_ADDITEM_TO_CART;
  6126. packet.result = static_cast<decltype(packet.result)>(flag);
  6127. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6128. }
  6129. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6130. void clif_bank_open( map_session_data& sd ){
  6131. #if PACKETVER >= 20130717
  6132. PACKET_ZC_ACK_OPEN_BANKING p = {};
  6133. p.packetType = HEADER_ZC_ACK_OPEN_BANKING;
  6134. p.unknown = 0;
  6135. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6136. #endif
  6137. }
  6138. /*
  6139. * Request to Open the banking system
  6140. * 09B6 <aid>L (CZ_REQ_OPEN_BANKING)
  6141. */
  6142. void clif_parse_BankOpen(int32 fd, map_session_data* sd) {
  6143. #if PACKETVER >= 20130717
  6144. const PACKET_CZ_REQ_OPEN_BANKING* p = reinterpret_cast<PACKET_CZ_REQ_OPEN_BANKING*>( RFIFOP( fd, 0 ) );
  6145. //TODO check if preventing trade or stuff like that
  6146. //also mark something in case char ain't available for saving, should we check now ?
  6147. nullpo_retv(sd);
  6148. if( !battle_config.feature_banking ) {
  6149. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6150. return;
  6151. }
  6152. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6153. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6154. return;
  6155. }
  6156. else {
  6157. if(sd->status.account_id == p->AID){
  6158. sd->state.banking = 1;
  6159. //request save ?
  6160. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6161. //on succes open bank ?
  6162. clif_bank_open( *sd );
  6163. }
  6164. }
  6165. #endif
  6166. }
  6167. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6168. void clif_bank_close( map_session_data& sd ){
  6169. #if PACKETVER >= 20130717
  6170. PACKET_ZC_ACK_CLOSE_BANKING p = {};
  6171. p.packetType = HEADER_ZC_ACK_CLOSE_BANKING;
  6172. p.unknown = 0;
  6173. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6174. #endif
  6175. }
  6176. /*
  6177. * Request to close the banking system
  6178. * 09B8 <aid>L (CZ_REQ_CLOSE_BANKING)
  6179. */
  6180. void clif_parse_BankClose(int32 fd, map_session_data* sd) {
  6181. #if PACKETVER >= 20130717
  6182. const PACKET_CZ_REQ_CLOSE_BANKING* p = reinterpret_cast<PACKET_CZ_REQ_CLOSE_BANKING*>( RFIFOP( fd, 0 ) );
  6183. nullpo_retv(sd);
  6184. if( !battle_config.feature_banking ) {
  6185. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6186. //still allow to go trough to not stuck player if we have disable it while they was in
  6187. }
  6188. if(sd->status.account_id == p->AID){
  6189. sd->state.banking = 0;
  6190. clif_bank_close( *sd );
  6191. }
  6192. #endif
  6193. }
  6194. /*
  6195. * Display how much we got in bank (I suppose)
  6196. * 09A6 <Bank_Vault>Q <Reason>W (ZC_BANKING_CHECK)
  6197. */
  6198. void clif_Bank_Check( map_session_data& sd ){
  6199. #if PACKETVER >= 20130717
  6200. PACKET_ZC_BANKING_CHECK p = {};
  6201. p.packetType = HEADER_ZC_BANKING_CHECK;
  6202. p.money = sd.bank_vault;
  6203. p.reason = 0;
  6204. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6205. #endif
  6206. }
  6207. /*
  6208. * Requesting the data in bank
  6209. * 09AB <aid>L (CZ_REQ_BANKING_CHECK)
  6210. */
  6211. void clif_parse_BankCheck(int32 fd, map_session_data* sd) {
  6212. #if PACKETVER >= 20130717
  6213. const PACKET_CZ_REQ_BANKING_CHECK* p = reinterpret_cast<PACKET_CZ_REQ_BANKING_CHECK*>( RFIFOP( fd, 0 ) );
  6214. nullpo_retv(sd);
  6215. if( !battle_config.feature_banking ) {
  6216. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6217. return;
  6218. }
  6219. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6220. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6221. return;
  6222. }
  6223. else {
  6224. if(sd->status.account_id == p->AID) //since we have it let check it for extra security
  6225. clif_Bank_Check( *sd );
  6226. }
  6227. #endif
  6228. }
  6229. /*
  6230. * Acknowledge of deposit some money in bank
  6231. 09A8 <Reason>W <Money>Q <balance>L (ZC_ACK_BANKING_DEPOSIT)
  6232. */
  6233. void clif_bank_deposit( map_session_data& sd, enum e_BANKING_DEPOSIT_ACK reason ){
  6234. #if PACKETVER >= 20130717
  6235. PACKET_ZC_ACK_BANKING_DEPOSIT p = {};
  6236. p.packetType = HEADER_ZC_ACK_BANKING_DEPOSIT;
  6237. p.money = sd.bank_vault;
  6238. p.zeny = sd.status.zeny;
  6239. p.reason = reason;
  6240. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6241. #endif
  6242. }
  6243. /*
  6244. * Request saving some money in bank
  6245. * @author : original [Yommy/Hercules]
  6246. * 09A7 <AID>L <Money>L (CZ_REQ_BANKING_DEPOSIT)
  6247. */
  6248. void clif_parse_BankDeposit(int32 fd, map_session_data* sd) {
  6249. #if PACKETVER >= 20130717
  6250. const PACKET_CZ_REQ_BANKING_DEPOSIT* p = reinterpret_cast<PACKET_CZ_REQ_BANKING_DEPOSIT*>( RFIFOP( fd, 0 ) );
  6251. nullpo_retv(sd);
  6252. if( !battle_config.feature_banking ) {
  6253. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6254. return;
  6255. }
  6256. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6257. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6258. return;
  6259. }
  6260. else {
  6261. if(sd->status.account_id == p->AID){
  6262. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,p->zeny));
  6263. clif_bank_deposit( *sd, reason );
  6264. }
  6265. }
  6266. #endif
  6267. }
  6268. /*
  6269. * Acknowledge of withdrawing some money from bank
  6270. * 09AA <Reason>W <Money>Q <balance>L (ZC_ACK_BANKING_WITHDRAW)
  6271. */
  6272. void clif_bank_withdraw( map_session_data& sd, enum e_BANKING_WITHDRAW_ACK reason ){
  6273. #if PACKETVER >= 20130717
  6274. PACKET_ZC_ACK_BANKING_WITHDRAW p = {};
  6275. p.packetType = HEADER_ZC_ACK_BANKING_WITHDRAW;
  6276. p.reason = reason;
  6277. p.money = sd.bank_vault;
  6278. p.zeny = sd.status.zeny;
  6279. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6280. #endif
  6281. }
  6282. /*
  6283. * Request Withdrawing some money from bank
  6284. * 09A9 <AID>L <Money>L (CZ_REQ_BANKING_WITHDRAW)
  6285. */
  6286. void clif_parse_BankWithdraw(int32 fd, map_session_data* sd) {
  6287. #if PACKETVER >= 20130717
  6288. const PACKET_CZ_REQ_BANKING_WITHDRAW* p = reinterpret_cast<PACKET_CZ_REQ_BANKING_WITHDRAW*>( RFIFOP( fd, 0 ) );
  6289. nullpo_retv(sd);
  6290. if( !battle_config.feature_banking ) {
  6291. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6292. return;
  6293. }
  6294. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6295. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6296. return;
  6297. }
  6298. else {
  6299. if(sd->status.account_id == p->AID){
  6300. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,p->zeny));
  6301. clif_bank_withdraw( *sd, reason );
  6302. }
  6303. }
  6304. #endif
  6305. }
  6306. /// Deletes an item from character's cart.
  6307. /// 0125 <index>.W <amount>.L (ZC_DELETE_ITEM_FROM_CART)
  6308. void clif_cart_delitem( map_session_data& sd, int32 index, int32 amount ){
  6309. PACKET_ZC_DELETE_ITEM_FROM_CART packet{};
  6310. packet.packetType = HEADER_ZC_DELETE_ITEM_FROM_CART;
  6311. packet.index = client_index( index );
  6312. packet.amount = amount;
  6313. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6314. }
  6315. /// Opens the shop creation menu.
  6316. /// 012d <num>.W (ZC_OPENSTORE)
  6317. /// num:
  6318. /// number of allowed item slots
  6319. void clif_openvendingreq( map_session_data& sd, uint16 num ){
  6320. PACKET_ZC_OPENSTORE packet{};
  6321. packet.packetType = HEADER_ZC_OPENSTORE;
  6322. packet.num = num;
  6323. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6324. }
  6325. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6326. /// 0131 <owner id>.L <message>.80B
  6327. void clif_showvendingboard( map_session_data& sd, enum send_target target, struct block_list* tbl ){
  6328. if( tbl == nullptr ){
  6329. tbl = &sd.bl;
  6330. target = AREA_WOS;
  6331. }
  6332. PACKET_ZC_STORE_ENTRY p = {};
  6333. p.packetType = HEADER_ZC_STORE_ENTRY;
  6334. p.makerAID = sd.status.account_id;
  6335. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  6336. clif_send( &p, sizeof( p ), tbl, target );
  6337. }
  6338. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6339. /// 0132 <owner id>.L
  6340. void clif_closevendingboard(struct block_list* bl, int32 fd)
  6341. {
  6342. unsigned char buf[16];
  6343. nullpo_retv(bl);
  6344. WBUFW(buf,0) = 0x132;
  6345. WBUFL(buf,2) = bl->id;
  6346. if( session_isActive(fd) ) {
  6347. WFIFOHEAD(fd,packet_len(0x132));
  6348. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6349. WFIFOSET(fd,packet_len(0x132));
  6350. } else {
  6351. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6352. }
  6353. }
  6354. /// Sends a list of items in a shop.
  6355. /// 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)
  6356. /// 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)
  6357. void clif_vendinglist( map_session_data& sd, map_session_data& vsd ){
  6358. PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = reinterpret_cast<PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*>( packet_buffer );
  6359. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6360. p->packetLength = sizeof( *p );
  6361. p->AID = vsd.status.account_id;
  6362. #if PACKETVER >= 20100105
  6363. p->venderId = vsd.vender_id;
  6364. #endif
  6365. for( int32 i = 0, count = 0; i < vsd.vend_num; i++ ){
  6366. PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub& entry = p->items[count];
  6367. int32 index = vsd.vending[i].index;
  6368. struct item_data* data = itemdb_search( vsd.cart.u.items_cart[index].nameid );
  6369. if( data == nullptr ){
  6370. continue;
  6371. }
  6372. entry.price = vsd.vending[i].value;
  6373. entry.amount = vsd.vending[i].amount;
  6374. entry.index = client_index( index );
  6375. entry.itemType = itemtype( vsd.cart.u.items_cart[index].nameid );
  6376. entry.itemId = client_nameid( vsd.cart.u.items_cart[index].nameid );
  6377. entry.identified = vsd.cart.u.items_cart[index].identify;
  6378. entry.damaged = vsd.cart.u.items_cart[index].attribute;
  6379. entry.refine = vsd.cart.u.items_cart[index].refine;
  6380. clif_addcards( &entry.slot, &vsd.cart.u.items_cart[index] );
  6381. #if PACKETVER >= 20150226
  6382. clif_add_random_options( entry.option_data, vsd.cart.u.items_cart[index] );
  6383. #if PACKETVER >= 20160921
  6384. entry.location = pc_equippoint_sub( &sd, data );
  6385. entry.viewSprite = data->look;
  6386. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6387. entry.grade = vsd.cart.u.items_cart[index].enchantgrade;
  6388. #endif
  6389. #endif
  6390. #endif
  6391. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  6392. count++;
  6393. }
  6394. clif_send( p, p->packetLength, &sd.bl, SELF );
  6395. }
  6396. /// Shop purchase failure.
  6397. /// 0135 <index>.W <amount>.W <result>.B (ZC_PC_PURCHASE_RESULT_FROMMC)
  6398. /// result:
  6399. /// 0 = success
  6400. /// 1 = not enough zeny
  6401. /// 2 = overweight
  6402. /// 4 = out of stock
  6403. /// 5 = "cannot use an npc shop while in a trade"
  6404. /// 6 = Because the store information was incorrect the item was not purchased.
  6405. /// 7 = No sales information.
  6406. void clif_buyvending( map_session_data& sd, uint16 index, uint16 amount, e_pc_purchase_result_frommc result ){
  6407. PACKET_ZC_PC_PURCHASE_RESULT_FROMMC packet{};
  6408. packet.packetType = HEADER_ZC_PC_PURCHASE_RESULT_FROMMC;
  6409. packet.index = client_index( index );
  6410. packet.amount = amount;
  6411. packet.result = static_cast<decltype(packet.result)>(result);
  6412. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6413. }
  6414. /// Show's vending player its list of items for sale.
  6415. /// 0a28 <result>.B (ZC_ACK_OPENSTORE2)
  6416. void clif_openvending_ack( map_session_data& sd, e_ack_openstore2 result ){
  6417. #if PACKETVER >= 20141022
  6418. PACKET_ZC_ACK_OPENSTORE2 packet{};
  6419. packet.packetType = HEADER_ZC_ACK_OPENSTORE2;
  6420. packet.result = static_cast<decltype(packet.result)>(result);
  6421. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6422. #endif
  6423. }
  6424. /// Shop creation success.
  6425. /// 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)
  6426. void clif_openvending( map_session_data& sd ){
  6427. PACKET_ZC_PC_PURCHASE_MYITEMLIST* p = reinterpret_cast<PACKET_ZC_PC_PURCHASE_MYITEMLIST*>( packet_buffer );
  6428. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6429. p->packetLength = sizeof( *p );
  6430. p->AID = sd.bl.id;
  6431. for( int32 i = 0; i < sd.vend_num; i++ ) {
  6432. PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub& entry = p->items[i];
  6433. int16 index = sd.vending[i].index;
  6434. entry.price = sd.vending[i].value;
  6435. entry.index = client_index( index );
  6436. entry.amount = sd.vending[i].amount;
  6437. entry.itemType = itemtype( sd.cart.u.items_cart[index].nameid );
  6438. entry.itemId = client_nameid( sd.cart.u.items_cart[index].nameid );
  6439. entry.identified = sd.cart.u.items_cart[index].identify;
  6440. entry.damaged = sd.cart.u.items_cart[index].attribute;
  6441. entry.refine = sd.cart.u.items_cart[index].refine;
  6442. clif_addcards( &entry.slot, &sd.cart.u.items_cart[index] );
  6443. #if PACKETVER >= 20150226
  6444. clif_add_random_options( entry.option_data, sd.cart.u.items_cart[index] );
  6445. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6446. entry.grade = sd.cart.u.items_cart[index].enchantgrade;
  6447. #endif
  6448. #endif
  6449. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  6450. }
  6451. clif_send( p, p->packetLength, &sd.bl, SELF );
  6452. clif_openvending_ack( sd, OPENSTORE2_SUCCESS );
  6453. }
  6454. /// Inform merchant that someone has bought an item.
  6455. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE)
  6456. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2)
  6457. void clif_vendingreport( map_session_data& sd, uint16 index, uint16 amount, uint32 char_id, int32 zeny ){
  6458. PACKET_ZC_DELETEITEM_FROM_MCSTORE packet{};
  6459. packet.packetType = HEADER_ZC_DELETEITEM_FROM_MCSTORE;
  6460. packet.index = client_index( index );
  6461. packet.amount = amount;
  6462. // TODO : not sure for client date [Napster]
  6463. #if PACKETVER >= 20141016
  6464. packet.buyerCID = char_id;
  6465. packet.date = client_tick( time(nullptr) );
  6466. packet.zeny = zeny;
  6467. #endif
  6468. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6469. }
  6470. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6471. /// 00fa <result>.B
  6472. /// result:
  6473. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6474. /// 1 = MsgStringTable[78]="party name already exists"
  6475. /// 2 = MsgStringTable[79]="already in a party"
  6476. /// 3 = cannot organize parties on this map
  6477. /// ? = nothing
  6478. void clif_party_created( map_session_data& sd, int32 result ){
  6479. PACKET_ZC_ACK_MAKE_GROUP p = {};
  6480. p.PacketType = HEADER_ZC_ACK_MAKE_GROUP;
  6481. p.result = result;
  6482. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6483. }
  6484. /// Adds new member to a party.
  6485. /// 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)
  6486. /// 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)
  6487. /// 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)
  6488. /// role:
  6489. /// 0 = leader
  6490. /// 1 = normal
  6491. /// state:
  6492. /// 0 = connected
  6493. /// 1 = disconnected
  6494. void clif_party_member_info( struct party_data& party, map_session_data& sd ){
  6495. int32 id = party_getmemberid( &party, &sd );
  6496. if( id < 0 ){
  6497. return;
  6498. }
  6499. PACKET_ZC_ADD_MEMBER_TO_GROUP p = {};
  6500. p.packetType = partymemberinfo;
  6501. p.AID = sd.status.account_id;
  6502. #if PACKETVER >= 20171207
  6503. p.GID = sd.status.char_id;
  6504. #endif
  6505. p.leader = ( party.party.member[id].leader != 0 ) ? 0 : 1;
  6506. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6507. p.class_ = sd.status.class_;
  6508. p.baseLevel = sd.status.base_level;
  6509. #endif
  6510. p.x = sd.bl.x;
  6511. p.y = sd.bl.y;
  6512. p.offline = ( party.party.member[id].online != 0 ) ? 0 : 1;
  6513. safestrncpy( p.partyName, party.party.name, sizeof( p.partyName ) );
  6514. safestrncpy( p.playerName, sd.status.name, sizeof( p.playerName ) );
  6515. mapindex_getmapname_ext( map_mapid2mapname( sd.bl.m ), p.mapName );
  6516. p.sharePickup = ( party.party.item&1 ) ? 1 : 0;
  6517. p.shareLoot = ( party.party.item&2 )? 1 : 0;
  6518. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6519. }
  6520. /// Sends party information (ZC_GROUP_LIST).
  6521. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6522. /// role:
  6523. /// 0 = leader
  6524. /// 1 = normal
  6525. /// state:
  6526. /// 0 = connected
  6527. /// 1 = disconnected
  6528. /// 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
  6529. void clif_party_info( struct party_data& party, map_session_data* sd ){
  6530. send_target target;
  6531. if( sd == nullptr ){
  6532. sd = party_getavailablesd( &party );
  6533. if( sd == nullptr ){
  6534. // Nobody is online to notify
  6535. return;
  6536. }
  6537. // Send to whole party
  6538. target = PARTY;
  6539. }else{
  6540. // Send only to self
  6541. target = SELF;
  6542. }
  6543. PACKET_ZC_GROUP_LIST* p = reinterpret_cast<PACKET_ZC_GROUP_LIST*>( packet_buffer );
  6544. p->packetType = partyinfo;
  6545. p->packetLen = sizeof( *p );
  6546. safestrncpy( p->partyName, party.party.name, sizeof( p->partyName ) );
  6547. for( int32 i = 0, c = 0; i < MAX_PARTY; i++ ){
  6548. struct party_member& m = party.party.member[i];
  6549. if( m.account_id == 0 ){
  6550. continue;
  6551. }
  6552. PACKET_ZC_GROUP_LIST_SUB& member = p->members[c];
  6553. member.AID = m.account_id;
  6554. #if PACKETVER >= 20171207
  6555. member.GID = m.char_id;
  6556. #endif
  6557. safestrncpy( member.playerName, m.name, sizeof( member.playerName ) );
  6558. mapindex_getmapname_ext( m.map, member.mapName );
  6559. member.leader = ( m.leader ) ? 0 : 1;
  6560. member.offline = ( m.online ) ? 0 : 1;
  6561. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6562. member.class_ = m.class_;
  6563. member.baseLevel = m.lv;
  6564. #endif
  6565. p->packetLen += static_cast<decltype(p->packetLen)>( sizeof( member ) );
  6566. c++;
  6567. }
  6568. clif_send( p, p->packetLen, &sd->bl, target );
  6569. }
  6570. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6571. /// 02c9 <flag>.B
  6572. /// flag:
  6573. /// 0 = allow party invites
  6574. /// 1 = auto-deny party invites
  6575. void clif_partyinvitationstate( map_session_data& sd ){
  6576. #if PACKETVER_MAIN_NUM >= 20070911 || defined(PACKETVER_RE) || PACKETVER_AD_NUM >= 20070911 || PACKETVER_SAK_NUM >= 20070904 || defined(PACKETVER_ZERO)
  6577. PACKET_ZC_PARTY_CONFIG p = {};
  6578. p.packetType = HEADER_ZC_PARTY_CONFIG;
  6579. p.denyPartyInvites = sd.status.disable_partyinvite;
  6580. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6581. #endif
  6582. }
  6583. /// Party invitation request.
  6584. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6585. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6586. void clif_party_invite( map_session_data& sd, map_session_data& tsd ){
  6587. struct party_data* party = party_search( sd.status.party_id );
  6588. if( party == nullptr ){
  6589. return;
  6590. }
  6591. PACKET_ZC_PARTY_JOIN_REQ p = {};
  6592. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ;
  6593. p.GRID = party->party.party_id;
  6594. safestrncpy( p.groupName, party->party.name, sizeof( p.groupName ) );
  6595. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6596. }
  6597. /// Party invite result.
  6598. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6599. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6600. /// result=0 : char is already in a party -> MsgStringTable[80]
  6601. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6602. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6603. /// result=3 : party is full -> MsgStringTable[83]
  6604. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6605. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6606. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6607. /// result=8 : (%s) are currently in restricted map to join a party. -> MsgStringTable[1388] (since 20080527)
  6608. /// result=9 : Cannot join a party in this map. -> MsgStringTable[1871] (since 20110215)
  6609. /// result=10 : You cannot invite or withdraw while in memorial dungeon -> message: MSG_ID_BD3 (since 20161130)
  6610. /// result=11 : The character is a level that can not join the party -> message: MSG_ID_C9A (since 20170412)
  6611. void clif_party_invite_reply( map_session_data& sd, const char* nick, enum e_party_invite_reply reply ){
  6612. #if PACKETVER < 20070904
  6613. if( reply == PARTY_REPLY_OFFLINE ){
  6614. clif_displaymessage( sd.fd, msg_txt( &sd, 3 ) ); // Character not found.
  6615. return;
  6616. }
  6617. #endif
  6618. PACKET_ZC_PARTY_JOIN_REQ_ACK p = {};
  6619. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ_ACK;
  6620. safestrncpy( p.characterName, nick, sizeof( p.characterName ) );
  6621. p.result = reply;
  6622. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6623. }
  6624. /// Updates party settings.
  6625. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6626. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6627. /// exp option:
  6628. /// 0 = exp sharing disabled
  6629. /// 1 = exp sharing enabled
  6630. /// 2 = cannot change exp sharing
  6631. ///
  6632. /// flag:
  6633. /// 0 = send to party
  6634. /// 1 = send to sd
  6635. void clif_party_option(struct party_data *p,map_session_data *sd,int32 flag)
  6636. {
  6637. unsigned char buf[16];
  6638. #if PACKETVER < 20090603
  6639. const int32 cmd = 0x101;
  6640. #else
  6641. const int32 cmd = 0x7d8;
  6642. #endif
  6643. nullpo_retv(p);
  6644. if(!sd && flag==0){
  6645. int32 i;
  6646. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6647. if (i < MAX_PARTY)
  6648. sd = p->data[i].sd;
  6649. }
  6650. if(!sd) return;
  6651. WBUFW(buf,0)=cmd;
  6652. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6653. #if PACKETVER >= 20090603
  6654. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6655. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6656. #endif
  6657. if(flag==0)
  6658. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6659. else
  6660. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6661. }
  6662. /**
  6663. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6664. * @param sd Send the notification for this player
  6665. * @param account_id Account ID of kicked member
  6666. * @param name Name of kicked member
  6667. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6668. * @param target Send target
  6669. **/
  6670. void clif_party_withdraw( map_session_data& sd, uint32 account_id, const char* name, enum e_party_member_withdraw result, enum send_target target ){
  6671. PACKET_ZC_DELETE_MEMBER_FROM_GROUP p = {};
  6672. p.PacketType = HEADER_ZC_DELETE_MEMBER_FROM_GROUP;
  6673. p.AID = account_id;
  6674. safestrncpy( p.characterName, name, sizeof( p.characterName ) );
  6675. p.result = result;
  6676. clif_send( &p, sizeof( p ), &sd.bl, target );
  6677. }
  6678. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6679. /// 0109 <packet len>.W <account id>.L <message>.?B
  6680. void clif_party_message( struct party_data& party, uint32 account_id, const char* mes, size_t len ){
  6681. map_session_data* sd = party_getavailablesd( &party );
  6682. if( sd == nullptr ){
  6683. return;
  6684. }
  6685. if (len > CHAT_SIZE_MAX) {
  6686. ShowWarning( "clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, CHAT_SIZE_MAX, party.party.party_id );
  6687. len = CHAT_SIZE_MAX;
  6688. }
  6689. PACKET_ZC_NOTIFY_CHAT_PARTY* p = reinterpret_cast<PACKET_ZC_NOTIFY_CHAT_PARTY*>( packet_buffer );
  6690. p->PacketType = HEADER_ZC_NOTIFY_CHAT_PARTY;
  6691. p->PacketLength = sizeof( *p );
  6692. p->AID = account_id;
  6693. safestrncpy( p->chatMsg, mes, len );
  6694. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  6695. clif_send( p, p->PacketLength, &sd->bl, PARTY );
  6696. }
  6697. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6698. /// 0107 <account id>.L <x>.W <y>.W
  6699. void clif_party_xy( map_session_data& sd ){
  6700. PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6701. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6702. p.AID = sd.status.account_id;
  6703. p.xPos = sd.bl.x;
  6704. p.yPos = sd.bl.y;
  6705. clif_send( &p, sizeof( p ), &sd.bl, PARTY_SAMEMAP_WOS );
  6706. }
  6707. /*==========================================
  6708. * Sends x/y dot to a single fd. [Skotlex]
  6709. *------------------------------------------*/
  6710. void clif_party_xy_single( map_session_data& sd, map_session_data& tsd ){
  6711. PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6712. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6713. p.AID = sd.status.account_id;
  6714. p.xPos = sd.bl.x;
  6715. p.yPos = sd.bl.y;
  6716. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6717. }
  6718. /// Updates HP bar of a party member.
  6719. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6720. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6721. void clif_party_hp( map_session_data& sd ){
  6722. PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6723. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6724. p.AID = sd.status.account_id;
  6725. #if PACKETVER < 20100119
  6726. // To correctly display the %hp bar. [Skotlex]
  6727. if( sd.battle_status.max_hp > INT16_MAX ){
  6728. p.hp = sd.battle_status.hp / ( sd.battle_status.max_hp / 100 );
  6729. p.maxhp = 100;
  6730. }else{
  6731. p.hp = sd.battle_status.hp;
  6732. p.maxhp = sd.battle_status.max_hp;
  6733. }
  6734. #else
  6735. p.hp = sd.battle_status.hp;
  6736. p.maxhp = sd.battle_status.max_hp;
  6737. #endif
  6738. clif_send( &p, sizeof( p ), &sd.bl, PARTY_AREA_WOS );
  6739. }
  6740. /// Notifies the party members of a character's death or revival.
  6741. /// 0AB2 <GID>.L <dead>.B
  6742. void clif_party_dead( map_session_data& sd ){
  6743. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6744. PACKET_ZC_GROUP_ISALIVE p = {};
  6745. p.packetType = HEADER_ZC_GROUP_ISALIVE;
  6746. p.AID = sd.status.account_id;
  6747. p.isDead = pc_isdead( &sd );
  6748. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6749. #endif
  6750. }
  6751. /// Updates the job and level of a party member
  6752. /// 0abd <account id>.L <job>.W <level>.W
  6753. void clif_party_job_and_level( map_session_data& sd ){
  6754. #if PACKETVER_MAIN_NUM >= 20170502 || PACKETVER_RE_NUM >= 20170419 || defined(PACKETVER_ZERO)
  6755. PACKET_ZC_NOTIFY_MEMBERINFO_TO_GROUPM p = {};
  6756. p.PacketType = HEADER_ZC_NOTIFY_MEMBERINFO_TO_GROUPM;
  6757. p.AID = sd.status.account_id;
  6758. p.job = sd.status.class_;
  6759. p.level = sd.status.base_level;
  6760. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6761. #endif
  6762. }
  6763. /*==========================================
  6764. * Sends HP bar to a single fd. [Skotlex]
  6765. *------------------------------------------*/
  6766. void clif_hpmeter_single( map_session_data& sd, uint32 id, uint32 hp, uint32 maxhp ){
  6767. PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6768. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6769. p.AID = id;
  6770. #if PACKETVER < 20100119
  6771. // To correctly display the %hp bar. [Skotlex]
  6772. if( maxhp > INT16_MAX ){
  6773. p.hp = hp / ( maxhp / 100 );
  6774. p.maxhp = 100;
  6775. }else{
  6776. p.hp = hp;
  6777. p.maxhp = maxhp;
  6778. }
  6779. #else
  6780. p.hp = hp;
  6781. p.maxhp = maxhp;
  6782. #endif
  6783. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6784. }
  6785. /// Notifies the client, that it's attack target is too far.
  6786. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W (ZC_ATTACK_FAILURE_FOR_DISTANCE)
  6787. void clif_movetoattack( map_session_data& sd, block_list& bl ){
  6788. PACKET_ZC_ATTACK_FAILURE_FOR_DISTANCE packet{};
  6789. packet.PacketType = HEADER_ZC_ATTACK_FAILURE_FOR_DISTANCE;
  6790. packet.targetAID = bl.id;
  6791. packet.targetXPos = bl.x;
  6792. packet.targetYPos = bl.y;
  6793. packet.xPos = sd.bl.x;
  6794. packet.yPos = sd.bl.y;
  6795. packet.currentAttRange = sd.battle_status.rhw.range;
  6796. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6797. }
  6798. /// Notifies the client about the result of an item produce request.
  6799. /// 018f <result>.W <name id>.W (ZC_ACK_REQMAKINGITEM)
  6800. /// result:
  6801. /// 0 = success
  6802. /// 1 = failure
  6803. /// 2 = success (alchemist)
  6804. /// 3 = failure (alchemist)
  6805. void clif_produceeffect(map_session_data* sd,int32 flag, t_itemid nameid){
  6806. if( sd == nullptr ){
  6807. return;
  6808. }
  6809. clif_solved_charname( *sd, sd->status.char_id, sd->status.name );
  6810. PACKET_ZC_ACK_REQMAKINGITEM p = {};
  6811. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  6812. p.result = flag;
  6813. p.itemId = client_nameid( nameid );
  6814. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6815. }
  6816. /// Initiates the pet taming process.
  6817. /// 019e (ZC_START_CAPTURE)
  6818. void clif_catch_process( map_session_data& sd ){
  6819. PACKET_ZC_START_CAPTURE packet{};
  6820. packet.PacketType = HEADER_ZC_START_CAPTURE;
  6821. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6822. }
  6823. /// Displays the result of a pet taming attempt.
  6824. /// 01a0 <result>.B (ZC_TRYCAPTURE_MONSTER)
  6825. /// 0 = failure
  6826. /// 1 = success
  6827. void clif_pet_roulette( map_session_data& sd, bool success ){
  6828. PACKET_ZC_TRYCAPTURE_MONSTER packet{};
  6829. packet.PacketType = HEADER_ZC_TRYCAPTURE_MONSTER;
  6830. packet.result = success;
  6831. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6832. }
  6833. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6834. /// 01a6 <packet len>.W { <index>.W }*
  6835. void clif_sendegg(map_session_data *sd)
  6836. {
  6837. int32 i,n=0,fd;
  6838. nullpo_retv(sd);
  6839. fd=sd->fd;
  6840. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6841. clif_displaymessage(fd, msg_txt(sd,666));
  6842. return;
  6843. }
  6844. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6845. WFIFOW(fd,0)=0x1a6;
  6846. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6847. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ||
  6848. sd->inventory_data[i]->type != IT_PETEGG ||
  6849. sd->inventory.u.items_inventory[i].amount <= 0)
  6850. continue;
  6851. WFIFOW(fd,n*2+4)=client_index(i);
  6852. n++;
  6853. }
  6854. WFIFOW(fd,2)=4+n*2;
  6855. WFIFOSET(fd,WFIFOW(fd,2));
  6856. sd->menuskill_id = SA_TAMINGMONSTER;
  6857. sd->menuskill_val = -1;
  6858. }
  6859. /// Sends a specific pet data update.
  6860. /// 01a4 <type>.B <id>.L <data>.L (ZC_CHANGESTATE_PET)
  6861. /// type:
  6862. /// 0 = pre-init (data = 0)
  6863. /// 1 = intimacy (data = 0~4)
  6864. /// 2 = hunger (data = 0~4)
  6865. /// 3 = accessory
  6866. /// 4 = performance (data = 1~3: normal, 4: special)
  6867. /// 5 = hairstyle
  6868. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6869. ///
  6870. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6871. void clif_send_petdata( map_session_data* sd, pet_data& pd, e_changestate_pet data_type ){
  6872. int32 value;
  6873. switch( data_type ) {
  6874. case CHANGESTATEPET_INIT:
  6875. value = 0;
  6876. break;
  6877. case CHANGESTATEPET_INTIMACY:
  6878. value = pd.pet.intimate;
  6879. break;
  6880. case CHANGESTATEPET_HUNGER:
  6881. value = pd.pet.hungry;
  6882. break;
  6883. case CHANGESTATEPET_ACCESSORY:
  6884. value = pd.vd.head_bottom;
  6885. break;
  6886. case CHANGESTATEPET_PERFORMANCE: {
  6887. int32 num;
  6888. // data = 1~3: normal, 4: special
  6889. if (pd.pet.intimate > PET_INTIMATE_LOYAL)
  6890. num = pd.get_pet_db()->s_perfor ? 4 : 3;
  6891. else if (pd.pet.intimate > PET_INTIMATE_CORDIAL) //TODO: this is way too high
  6892. num = 2;
  6893. else
  6894. num = 1;
  6895. value = rnd_value(1, num);
  6896. break;
  6897. }
  6898. case CHANGESTATEPET_HAIRSTYLE:
  6899. value = battle_config.pet_hair_style;
  6900. break;
  6901. case CHANGESTATEPET_UPDATE_EGG:
  6902. value = ( pd.pet.intimate == 1 ) ? 0 : 1;
  6903. break;
  6904. default: // shouldn't happen
  6905. return;
  6906. }
  6907. PACKET_ZC_CHANGESTATE_PET packet{};
  6908. packet.PacketType = HEADER_ZC_CHANGESTATE_PET;
  6909. packet.type = static_cast<decltype(packet.type)>( data_type );
  6910. packet.GID = pd.bl.id;
  6911. packet.data = value;
  6912. if (sd != nullptr)
  6913. clif_send( &packet, sizeof( packet ), &sd->bl, SELF );
  6914. else
  6915. clif_send( &packet, sizeof( packet ), &pd.bl, AREA );
  6916. }
  6917. /// Pet's base data.
  6918. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W (ZC_PROPERTY_PET)
  6919. void clif_send_petstatus( map_session_data& sd, pet_data& pd ){
  6920. PACKET_ZC_PROPERTY_PET packet{};
  6921. packet.PacketType = HEADER_ZC_PROPERTY_PET;
  6922. safestrncpy( packet.szName, pd.pet.name, NAME_LENGTH );
  6923. packet.bModified = battle_config.pet_rename ? 0 : pd.pet.rename_flag;
  6924. packet.nLevel = pd.pet.level;
  6925. packet.nFullness = pd.pet.hungry;
  6926. packet.nRelationship = pd.pet.intimate;
  6927. packet.ITID = static_cast<decltype(packet.ITID)>( pd.pet.equip );
  6928. #if PACKETVER >= 20081126
  6929. packet.job = pd.pet.class_;
  6930. #endif
  6931. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6932. }
  6933. /// Notification about a pet's emotion/talk.
  6934. /// 01aa <id>.L <data>.L (ZC_PET_ACT)
  6935. /// data:
  6936. /// @see CZ_PET_ACT.
  6937. void clif_pet_emotion( pet_data& pd, int32 param ){
  6938. PACKET_ZC_PET_ACT packet{};
  6939. packet.packetType = HEADER_ZC_PET_ACT;
  6940. packet.GID = pd.bl.id;
  6941. packet.data = param;
  6942. clif_send( &packet, sizeof( packet ), &pd.bl, AREA );
  6943. }
  6944. /// Result of request to feed a pet.
  6945. /// 01a3 <result>.B <name id>.W (ZC_FEED_PET)
  6946. /// result:
  6947. /// 0 = failure
  6948. /// 1 = success
  6949. void clif_pet_food( map_session_data& sd, int32 foodid, bool success ){
  6950. PACKET_ZC_FEED_PET packet{};
  6951. packet.packetType = HEADER_ZC_FEED_PET;
  6952. packet.result = success;
  6953. packet.itemId = client_nameid( foodid );
  6954. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6955. }
  6956. /// Send pet auto feed info.
  6957. void clif_pet_autofeed_status(map_session_data* sd, bool force) {
  6958. #if PACKETVER >= 20141008
  6959. nullpo_retv(sd);
  6960. if (force || battle_config.pet_autofeed_always) {
  6961. // Always send ON or OFF
  6962. if (sd->pd && battle_config.feature_pet_autofeed) {
  6963. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  6964. }
  6965. else {
  6966. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  6967. }
  6968. }
  6969. else {
  6970. // Only send when enabled
  6971. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  6972. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  6973. }
  6974. }
  6975. #endif
  6976. }
  6977. /// Presents a list of skills that can be auto-spelled.
  6978. /// 01cd { <skill id>.L }*7 (ZC_AUTOSPELLLIST)
  6979. void clif_autospell( map_session_data& sd, uint16 skill_lv ){
  6980. struct s_autospell_requirement{
  6981. uint16 skill_id;
  6982. uint16 required_autospell_skill_lv;
  6983. };
  6984. #ifdef RENEWAL
  6985. const std::vector<s_autospell_requirement> autospell_skills = {
  6986. { MG_FIREBOLT, 0 },
  6987. { MG_COLDBOLT, 0 },
  6988. { MG_LIGHTNINGBOLT, 0 },
  6989. { MG_SOULSTRIKE, 3 },
  6990. { MG_FIREBALL, 3 },
  6991. { WZ_EARTHSPIKE, 6 },
  6992. { MG_FROSTDIVER, 6 },
  6993. { MG_THUNDERSTORM, 9 },
  6994. { WZ_HEAVENDRIVE, 9 }
  6995. };
  6996. #else
  6997. const std::vector<s_autospell_requirement> autospell_skills = {
  6998. { MG_NAPALMBEAT, 0 },
  6999. { MG_COLDBOLT, 1 },
  7000. { MG_FIREBOLT, 1 },
  7001. { MG_LIGHTNINGBOLT, 1 },
  7002. { MG_SOULSTRIKE, 4 },
  7003. { MG_FIREBALL, 7 },
  7004. { MG_FROSTDIVER, 9 },
  7005. };
  7006. #endif
  7007. #if PACKETVER_MAIN_NUM >= 20181128 || PACKETVER_RE_NUM >= 20181031
  7008. PACKET_ZC_AUTOSPELLLIST* p = reinterpret_cast<PACKET_ZC_AUTOSPELLLIST*>( packet_buffer );
  7009. p->packetType = HEADER_ZC_AUTOSPELLLIST;
  7010. p->packetLength = sizeof( *p );
  7011. size_t count = 0;
  7012. for( const s_autospell_requirement& requirement : autospell_skills ){
  7013. if( skill_lv > requirement.required_autospell_skill_lv && pc_checkskill( &sd, requirement.skill_id ) ){
  7014. p->skills[count++] = requirement.skill_id;
  7015. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->skills[0] ) );
  7016. }
  7017. }
  7018. clif_send( p, p->packetLength, &sd.bl, SELF );
  7019. #elif PACKETVER_MAIN_NUM >= 20090406 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_SAK_NUM >= 20080618
  7020. PACKET_ZC_AUTOSPELLLIST p = {};
  7021. p.packetType = HEADER_ZC_AUTOSPELLLIST;
  7022. size_t count = 0;
  7023. for( const s_autospell_requirement& requirement : autospell_skills ){
  7024. if( count == ARRAYLENGTH( p.skills ) ){
  7025. break;
  7026. }
  7027. if( skill_lv > requirement.required_autospell_skill_lv && pc_checkskill( &sd, requirement.skill_id ) ){
  7028. p.skills[count++] = requirement.skill_id;
  7029. }else{
  7030. p.skills[count++] = 0;
  7031. }
  7032. }
  7033. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7034. #endif
  7035. sd.menuskill_id = SA_AUTOSPELL;
  7036. sd.menuskill_val = skill_lv;
  7037. }
  7038. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7039. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7040. void clif_devotion(struct block_list *src, map_session_data *tsd)
  7041. {
  7042. unsigned char buf[56];
  7043. nullpo_retv(src);
  7044. memset(buf,0,packet_len(0x1cf));
  7045. WBUFW(buf,0) = 0x1cf;
  7046. WBUFL(buf,2) = src->id;
  7047. if( src->type == BL_MER )
  7048. {
  7049. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7050. if( md && md->master && md->devotion_flag )
  7051. WBUFL(buf,6) = md->master->bl.id;
  7052. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7053. }
  7054. else
  7055. {
  7056. int32 i;
  7057. map_session_data *sd = BL_CAST(BL_PC,src);
  7058. if( sd == nullptr )
  7059. return;
  7060. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7061. WBUFL(buf,6+4*i) = sd->devotion[i];
  7062. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7063. }
  7064. if( tsd )
  7065. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7066. else
  7067. clif_send(buf, packet_len(0x1cf), src, AREA);
  7068. }
  7069. /// Notifies the client of an object's spirits.
  7070. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7071. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7072. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7073. nullpo_retv( bl );
  7074. PACKET_ZC_SPIRITS p = {};
  7075. p.PacketType = HEADER_ZC_SPIRITS;
  7076. p.AID = bl->id;
  7077. switch( bl->type ){
  7078. case BL_PC:
  7079. p.num = ( (map_session_data*)bl )->spiritball;
  7080. break;
  7081. case BL_HOM:
  7082. p.num = ( (struct homun_data*)bl )->homunculus.spiritball;
  7083. break;
  7084. }
  7085. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7086. }
  7087. /// Notifies clients in area of a character's combo delay.
  7088. /// 01d2 <account id>.L <delay>.L (ZC_COMBODELAY)
  7089. void clif_combo_delay( block_list& bl, t_tick wait ){
  7090. PACKET_ZC_COMBODELAY packet{};
  7091. packet.packetType = HEADER_ZC_COMBODELAY;
  7092. packet.AID = bl.id;
  7093. packet.delay = client_tick( wait );
  7094. clif_send( &packet, sizeof( packet ), &bl, AREA );
  7095. }
  7096. /// Notifies clients in area that a character has blade-stopped another.
  7097. /// 01d1 <src id>.L <dst id>.L <flag>.L (ZC_BLADESTOP)
  7098. /// flag:
  7099. /// 0 = inactive
  7100. /// 1 = active
  7101. void clif_bladestop( block_list& src, uint32 target_id, bool active ){
  7102. PACKET_ZC_BLADESTOP packet{};
  7103. packet.packetType = HEADER_ZC_BLADESTOP;
  7104. packet.srcId = src.id;
  7105. packet.targetId = target_id;
  7106. packet.flag = active;
  7107. clif_send( &packet, sizeof( packet ), &src, AREA );
  7108. }
  7109. /// MVP effect.
  7110. /// 010c <account id>.L (ZC_MVP)
  7111. void clif_mvp_effect( map_session_data& sd ){
  7112. PACKET_ZC_MVP packet{};
  7113. packet.packetType = HEADER_ZC_MVP;
  7114. packet.AID = sd.bl.id;
  7115. clif_send( &packet, sizeof( packet ), &sd.bl, AREA );
  7116. }
  7117. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7118. /// 010a <name id>.W
  7119. void clif_mvp_item( map_session_data *sd, t_itemid nameid ){
  7120. PACKET_ZC_MVP_GETTING_ITEM p = {};
  7121. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7122. p.itemId = client_nameid( nameid );
  7123. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7124. }
  7125. /// MVP EXP reward message.
  7126. /// 010b <exp>.L (ZC_MVP_GETTING_SPECIAL_EXP)
  7127. void clif_mvp_exp( map_session_data& sd, t_exp exp ){
  7128. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7129. if (battle_config.mvp_exp_reward_message) {
  7130. char e_msg[CHAT_SIZE_MAX];
  7131. sprintf(e_msg, msg_txt(&sd, 717), exp); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7132. clif_messagecolor( &sd.bl, color_table[COLOR_CYAN], e_msg, false, SELF );
  7133. }
  7134. #else
  7135. PACKET_ZC_MVP_GETTING_SPECIAL_EXP packet{};
  7136. packet.packetType = HEADER_ZC_MVP_GETTING_SPECIAL_EXP;
  7137. packet.exp = std::min( static_cast<decltype(packet.exp)>( exp ), MAX_EXP );
  7138. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  7139. #endif
  7140. }
  7141. /// Dropped MVP item reward message.
  7142. /// 010d (ZC_THROW_MVPITEM)
  7143. ///
  7144. /// "You are the MVP, but cannot obtain the reward because you are overweight."
  7145. void clif_mvp_noitem( map_session_data& sd ){
  7146. PACKET_ZC_THROW_MVPITEM packet{};
  7147. packet.packetType = HEADER_ZC_THROW_MVPITEM;
  7148. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  7149. }
  7150. /// Guild creation result.
  7151. /// 0167 <result>.B (ZC_RESULT_MAKE_GUILD)
  7152. /// result:
  7153. /// 0 = "Guild has been created."
  7154. /// 1 = "You are already in a Guild."
  7155. /// 2 = "That Guild Name already exists."
  7156. /// 3 = "You need the neccessary item to create a Guild."
  7157. void clif_guild_created( map_session_data& sd, int32 flag ){
  7158. PACKET_ZC_RESULT_MAKE_GUILD p = {};
  7159. p.packetType = HEADER_ZC_RESULT_MAKE_GUILD;
  7160. p.result = static_cast<decltype(p.result)>( flag );
  7161. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7162. }
  7163. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7164. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7165. /// mode:
  7166. /// &0x01 = allow invite
  7167. /// &0x10 = allow expel
  7168. void clif_guild_belonginfo( map_session_data& sd ){
  7169. if( sd.guild == nullptr ){
  7170. return;
  7171. }
  7172. const auto &guild = sd.guild->guild;
  7173. int32 position = guild_getposition(sd);
  7174. if( position < 0 ){
  7175. return;
  7176. }
  7177. PACKET_ZC_UPDATE_GDID p = {};
  7178. p.PacketType = HEADER_ZC_UPDATE_GDID;
  7179. p.guildId = guild.guild_id;
  7180. p.emblemVersion = guild.emblem_id;
  7181. p.mode = guild.position[position].mode;
  7182. p.isMaster = ( sd.state.gmaster_flag == 1 );
  7183. p.interSid = 0; // InterSID (unknown purpose)
  7184. safestrncpy( p.guildName, guild.name, sizeof( p.guildName ) );
  7185. #if PACKETVER_MAIN_NUM >= 20220216
  7186. p.masterGID = guild.member[0].char_id;
  7187. #endif
  7188. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7189. }
  7190. /// Guild member login notice.
  7191. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7192. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7193. /// status:
  7194. /// 0 = offline
  7195. /// 1 = online
  7196. void clif_guild_memberlogin_notice(const struct mmo_guild &g,int32 idx,int32 flag)
  7197. {
  7198. unsigned char buf[64];
  7199. map_session_data* sd;
  7200. WBUFW(buf, 0)=0x1f2;
  7201. WBUFL(buf, 2)=g.member[idx].account_id;
  7202. WBUFL(buf, 6)=g.member[idx].char_id;
  7203. WBUFL(buf,10)=flag;
  7204. if( ( sd = g.member[idx].sd ) != nullptr )
  7205. {
  7206. WBUFW(buf,14) = sd->status.sex;
  7207. WBUFW(buf,16) = sd->status.hair;
  7208. WBUFW(buf,18) = sd->status.hair_color;
  7209. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7210. }
  7211. else if( ( sd = guild_getavailablesd(g) ) != nullptr )
  7212. {
  7213. WBUFW(buf,14) = 0;
  7214. WBUFW(buf,16) = 0;
  7215. WBUFW(buf,18) = 0;
  7216. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7217. }
  7218. }
  7219. // Function `clif_guild_memberlogin_notice` sends info about
  7220. // logins and logouts of a guild member to the rest members.
  7221. // But at the 1st time (after a player login or map changing)
  7222. // the client won't show the message.
  7223. // So I suggest use this function for sending "first-time-info"
  7224. // to some player on entering the game or changing location.
  7225. // At next time the client would always show the message.
  7226. // The function sends all the statuses in the single packet
  7227. // to economize traffic. [LuzZza]
  7228. void clif_guild_send_onlineinfo(map_session_data *sd)
  7229. {
  7230. unsigned char buf[14*128];
  7231. int32 i, count=0, p_len;
  7232. nullpo_retv(sd);
  7233. p_len = packet_len(0x16d);
  7234. auto &g = sd->guild;
  7235. if (!g)
  7236. return;
  7237. for(i=0; i<g->guild.max_member; i++) {
  7238. if(g->guild.member[i].account_id > 0 &&
  7239. g->guild.member[i].account_id != sd->status.account_id) {
  7240. WBUFW(buf,count*p_len) = 0x16d;
  7241. WBUFL(buf,count*p_len+2) = g->guild.member[i].account_id;
  7242. WBUFL(buf,count*p_len+6) = g->guild.member[i].char_id;
  7243. WBUFL(buf,count*p_len+10) = g->guild.member[i].online;
  7244. count++;
  7245. }
  7246. }
  7247. clif_send(buf, p_len*count, &sd->bl, SELF);
  7248. }
  7249. /// Bitmask of enabled guild window tabs
  7250. /// 014e <menu flag>.L (ZC_ACK_GUILD_MENUINTERFACE)
  7251. /// menu flag:
  7252. /// 0x00 = Basic Info (always on)
  7253. /// &0x01 = Member manager
  7254. /// &0x02 = Positions
  7255. /// &0x04 = Skills
  7256. /// &0x10 = Expulsion list
  7257. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7258. /// &0x80 = Notice
  7259. void clif_guild_masterormember(map_session_data& sd){
  7260. PACKET_ZC_ACK_GUILD_MENUINTERFACE p{};
  7261. p.packetType = HEADER_ZC_ACK_GUILD_MENUINTERFACE;
  7262. if(sd.state.gmaster_flag){
  7263. p.menuFlag = 0xd7;
  7264. }else{
  7265. p.menuFlag = 0x57;
  7266. }
  7267. clif_send(&p,sizeof(p),&sd.bl,SELF);
  7268. }
  7269. /// Guild basic information (Territories [Valaris])
  7270. /// 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)
  7271. /// 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)
  7272. /// 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)
  7273. void clif_guild_basicinfo( map_session_data& sd ){
  7274. if( sd.guild == nullptr ){
  7275. return;
  7276. }
  7277. const auto &guild = sd.guild->guild;
  7278. PACKET_ZC_GUILD_INFO p = {};
  7279. p.PacketType = HEADER_ZC_GUILD_INFO;
  7280. p.GDID = guild.guild_id;
  7281. p.level = guild.guild_lv;
  7282. p.userNum = guild.connect_member;
  7283. p.maxUserNum = guild.max_member;
  7284. p.userAverageLevel = guild.average_lv;
  7285. p.exp = (uint32)cap_value( guild.exp, 0, MAX_GUILD_EXP );
  7286. p.maxExp = (uint32)cap_value( guild.next_exp, 0, MAX_GUILD_EXP );
  7287. p.point = 0; // Tax Points
  7288. p.honor = 0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7289. p.virtue = 0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7290. p.emblemVersion = guild.emblem_id;
  7291. safestrncpy( p.guildname, guild.name, sizeof( p.guildname ) );
  7292. safestrncpy( p.manageLand, msg_txt( &sd, 300 + guild_checkcastles( guild ) ), sizeof( p.manageLand ) );
  7293. p.zeny = 0;
  7294. #if PACKETVER >= 20200902
  7295. p.masterGID = guild.member[0].char_id; // leader
  7296. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7297. #elif PACKETVER_MAIN_NUM >= 20161019 || PACKETVER_RE_NUM >= 20160921 || defined(PACKETVER_ZERO)
  7298. p.masterGID = guild.member[0].char_id; // leader
  7299. #else
  7300. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7301. #endif
  7302. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7303. }
  7304. /// Guild alliance and opposition list
  7305. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }* (ZC_MYGUILD_BASIC_INFO)
  7306. void clif_guild_allianceinfo(map_session_data& sd){
  7307. auto &g = sd.guild;
  7308. if (g == nullptr){
  7309. return;
  7310. }
  7311. PACKET_ZC_MYGUILD_BASIC_INFO* p = reinterpret_cast<PACKET_ZC_MYGUILD_BASIC_INFO*>( packet_buffer );
  7312. p->PacketType = HEADER_ZC_MYGUILD_BASIC_INFO;
  7313. p->PacketLength = sizeof(*p);
  7314. for(size_t i=0, c = 0;i<MAX_GUILDALLIANCE;i++){
  7315. guild_alliance &a = g->guild.alliance[i];
  7316. if(a.guild_id<=0){
  7317. continue;
  7318. }
  7319. RELATED_GUILD_INFO& info = p->rgInfo[c];
  7320. info.relation = a.opposition;
  7321. info.GDID = a.guild_id;
  7322. safestrncpy(info.guildname,a.name,sizeof(info.guildname));
  7323. p->PacketLength += static_cast<decltype(p->PacketLength)>(sizeof(info));
  7324. c++;
  7325. }
  7326. clif_send(p,p->PacketLength,&sd.bl,SELF);
  7327. }
  7328. /// Guild member manager information
  7329. /// 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)
  7330. /// state:
  7331. /// 0 = offline
  7332. /// 1 = online
  7333. /// memo:
  7334. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7335. /// 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)
  7336. void clif_guild_memberlist( map_session_data& sd ){
  7337. if( sd.guild == nullptr ){
  7338. return;
  7339. }
  7340. const auto &guild = sd.guild->guild;
  7341. PACKET_ZC_MEMBERMGR_INFO* p = reinterpret_cast<PACKET_ZC_MEMBERMGR_INFO*>( packet_buffer );
  7342. p->PacketType = HEADER_ZC_MEMBERMGR_INFO;
  7343. p->packetLength = sizeof( *p );
  7344. for( int32 i = 0, c = 0; i < guild.max_member; i++ ){
  7345. const auto &member = guild.member[i];
  7346. if( member.account_id == 0 ){
  7347. continue;
  7348. }
  7349. GUILD_MEMBER_INFO& member_info = p->guildMemberInfo[c];
  7350. member_info.AID = member.account_id;
  7351. member_info.GID = member.char_id;
  7352. member_info.head = member.hair;
  7353. member_info.headPalette = member.hair_color;
  7354. member_info.sex = member.gender;
  7355. member_info.job = member.class_;
  7356. member_info.level = member.lv;
  7357. member_info.contributionExp = (uint32)cap_value( member.exp, 0, MAX_GUILD_EXP );
  7358. member_info.currentState = member.online;
  7359. member_info.positionID = member.position;
  7360. #if PACKETVER >= 20200902
  7361. member_info.lastLoginTime = member.last_login;
  7362. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7363. #elif PACKETVER_MAIN_NUM >= 20161214 || PACKETVER_RE_NUM >= 20161130 || defined(PACKETVER_ZERO)
  7364. member_info.lastLoginTime = member.last_login;
  7365. #else
  7366. 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.
  7367. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7368. #endif
  7369. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( member_info ) );
  7370. c++;
  7371. }
  7372. clif_send( p, p->packetLength, &sd.bl, SELF );
  7373. }
  7374. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7375. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7376. void clif_guild_positionnamelist(map_session_data *sd)
  7377. {
  7378. int32 i,fd;
  7379. nullpo_retv(sd);
  7380. auto &g = sd->guild;
  7381. if (!g)
  7382. return;
  7383. fd = sd->fd;
  7384. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7385. WFIFOW(fd, 0)=0x166;
  7386. for(i=0;i<MAX_GUILDPOSITION;i++){
  7387. WFIFOL(fd,i*28+4)=i;
  7388. safestrncpy(WFIFOCP(fd,i*28+8),g->guild.position[i].name,NAME_LENGTH);
  7389. }
  7390. WFIFOW(fd,2)=i*28+4;
  7391. WFIFOSET(fd,WFIFOW(fd,2));
  7392. }
  7393. /// Guild position information
  7394. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }* (ZC_POSITION_INFO)
  7395. /// mode:
  7396. /// See enum e_guild_permission
  7397. /// ranking:
  7398. /// TODO
  7399. static void clif_guild_positioninfolist(map_session_data& sd){
  7400. auto &g = sd.guild;
  7401. if (g == nullptr){
  7402. return;
  7403. }
  7404. PACKET_ZC_POSITION_INFO* p = reinterpret_cast<PACKET_ZC_POSITION_INFO*>( packet_buffer );
  7405. p->PacketType = HEADER_ZC_POSITION_INFO;
  7406. p->PacketLength = sizeof(*p);
  7407. for(size_t i=0;i<MAX_GUILDPOSITION;i++){
  7408. guild_position& gp = g->guild.position[i];
  7409. PACKET_ZC_POSITION_INFO_sub& position = p->posInfo[i];
  7410. position.positionID = static_cast<decltype(position.positionID)>( i );
  7411. position.right = gp.mode;
  7412. position.ranking = static_cast<decltype(position.ranking)>( i );
  7413. position.payRate = gp.exp_mode;
  7414. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( position ) );
  7415. }
  7416. clif_send(p,p->PacketLength,&sd.bl,SELF);
  7417. }
  7418. /// Notifies clients in a guild about updated position information.
  7419. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }* (ZC_ACK_CHANGE_GUILD_POSITIONINFO)
  7420. /// mode:
  7421. /// &0x01 = allow invite
  7422. /// &0x10 = allow expel
  7423. /// ranking:
  7424. /// TODO
  7425. void clif_guild_positionchanged(const struct mmo_guild &g,int32 idx)
  7426. {
  7427. // FIXME: This packet is intended to update the clients after a
  7428. // commit of position info changes, not sending one packet per
  7429. // position.
  7430. map_session_data *sd;
  7431. unsigned char buf[128];
  7432. WBUFW(buf, 0)=0x174;
  7433. WBUFW(buf, 2)=44; // packet len
  7434. // GUILD_REG_POSITION_INFO{
  7435. WBUFL(buf, 4)=idx;
  7436. WBUFL(buf, 8)=g.position[idx].mode;
  7437. WBUFL(buf,12)=idx;
  7438. WBUFL(buf,16)=g.position[idx].exp_mode;
  7439. safestrncpy(WBUFCP(buf,20),g.position[idx].name,NAME_LENGTH);
  7440. // }*
  7441. if( (sd=guild_getavailablesd(g))!=nullptr )
  7442. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7443. }
  7444. /// Notifies clients in a guild about updated member position assignments.
  7445. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }* (ZC_ACK_REQ_CHANGE_MEMBERS)
  7446. void clif_guild_memberpositionchanged(const struct mmo_guild &g, int32 idx)
  7447. {
  7448. // FIXME: This packet is intended to update the clients after a
  7449. // commit of member position assignment changes, not sending one
  7450. // packet per position.
  7451. map_session_data *sd;
  7452. unsigned char buf[64];
  7453. WBUFW(buf, 0)=0x156;
  7454. WBUFW(buf, 2)=16; // packet len
  7455. // MEMBER_POSITION_INFO{
  7456. WBUFL(buf, 4)=g.member[idx].account_id;
  7457. WBUFL(buf, 8)=g.member[idx].char_id;
  7458. WBUFL(buf,12)=g.member[idx].position;
  7459. // }*
  7460. if( (sd=guild_getavailablesd(g))!=nullptr )
  7461. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7462. }
  7463. /// Sends emblems bitmap data to the client that requested it.
  7464. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B (ZC_GUILD_EMBLEM_IMG)
  7465. void clif_guild_emblem(const map_session_data &sd, const struct mmo_guild &g)
  7466. {
  7467. int32 fd = sd.fd;
  7468. if( g.emblem_len <= 0 )
  7469. return;
  7470. WFIFOHEAD(fd,g.emblem_len+12);
  7471. WFIFOW(fd,0)=0x152;
  7472. WFIFOW(fd,2)=g.emblem_len+12;
  7473. WFIFOL(fd,4)=g.guild_id;
  7474. WFIFOL(fd,8)=g.emblem_id;
  7475. memcpy(WFIFOP(fd,12),g.emblem_data,g.emblem_len);
  7476. WFIFOSET(fd,WFIFOW(fd,2));
  7477. }
  7478. /// Sends update of the guild id/emblem id to everyone in the area.
  7479. /// 01b4 <id>.L <guild id>.L <emblem id>.W (ZC_CHANGE_GUILD)
  7480. /// 0b1f <guild id>.L <version>.L <AID>.L (ZC_NEW_EMBLEM_DOWNLOAD)
  7481. /// 0b47 <guild id>.L <version>.L <AID>.L (ZC_ACK_ADD_NEW_EMBLEM)
  7482. void clif_guild_emblem_area(struct block_list* bl)
  7483. {
  7484. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7485. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7486. PACKET_ZC_CHANGE_GUILD p{};
  7487. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7488. p.guild_id = status_get_guild_id(bl);
  7489. p.emblem_id = status_get_emblem_id(bl);
  7490. p.AID = bl->id;
  7491. clif_send(&p, sizeof(p), bl, AREA);
  7492. }
  7493. /// Sends guild skills.
  7494. /// 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 }* (ZC_GUILD_SKILLINFO)
  7495. void clif_guild_skillinfo( map_session_data& sd ){
  7496. auto& g = sd.guild;
  7497. if( g == nullptr ){
  7498. return;
  7499. }
  7500. PACKET_ZC_GUILD_SKILLINFO* p = reinterpret_cast<PACKET_ZC_GUILD_SKILLINFO*>( packet_buffer );
  7501. p->PacketType = HEADER_ZC_GUILD_SKILLINFO;
  7502. p->PacketLength = sizeof( *p );
  7503. p->skillPoint = g->guild.skill_point;
  7504. for( size_t i = 0, c = 0; i < MAX_GUILDSKILL; i++ ){
  7505. if( g->guild.skill[i].id <= 0 ){
  7506. continue;
  7507. }
  7508. if( !guild_check_skill_require( g->guild, g->guild.skill[i].id ) ){
  7509. continue;
  7510. }
  7511. GUILD_SKILLDATA& gs = p->skillInfo[c];
  7512. int32 skill_id = g->guild.skill[i].id;
  7513. gs.id = skill_id;
  7514. gs.inf = skill_get_inf(skill_id);
  7515. gs.level = g->guild.skill[i].lv;
  7516. if( g->guild.skill[i].lv > 0 ){
  7517. gs.sp = skill_get_sp( skill_id, g->guild.skill[i].lv );
  7518. gs.range2 = skill_get_range( skill_id, g->guild.skill[i].lv );
  7519. }else{
  7520. gs.sp = 0;
  7521. gs.range2 = 0;
  7522. }
  7523. safestrncpy( gs.name, skill_get_name( skill_id ), sizeof( gs.name ) );
  7524. gs.upFlag = ( g->guild.skill[i].lv < guild_skill_get_max( skill_id ) && &sd == g->guild.member[0].sd ) ? 1 : 0;
  7525. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( gs ) );
  7526. c++;
  7527. }
  7528. clif_send( p, p->PacketLength, &sd.bl, SELF );
  7529. }
  7530. /// Sends guild notice to client.
  7531. /// 016f <subject>.60B <notice>.120B (ZC_GUILD_NOTICE)
  7532. void clif_guild_notice( map_session_data& sd ){
  7533. auto& g = sd.guild;
  7534. if( g == nullptr ){
  7535. return;
  7536. }
  7537. if( g->guild.mes1[0] == '\0' && g->guild.mes2[0] == '\0' ){
  7538. return;
  7539. }
  7540. PACKET_ZC_GUILD_NOTICE p = {};
  7541. p.packetType = HEADER_ZC_GUILD_NOTICE;
  7542. safestrncpy( p.subject, g->guild.mes1, sizeof( p.subject ) );
  7543. safestrncpy( p.notice, g->guild.mes2, sizeof( p.notice ) );
  7544. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7545. }
  7546. /// Guild invite.
  7547. /// 016a <guild id>.L <guild name>.24B (ZC_REQ_JOIN_GUILD)
  7548. void clif_guild_invite( map_session_data& sd, const struct mmo_guild& g ){
  7549. PACKET_ZC_REQ_JOIN_GUILD p = {};
  7550. p.packetType = HEADER_ZC_REQ_JOIN_GUILD;
  7551. p.guild_id = g.guild_id;
  7552. safestrncpy( p.guild_name, g.name, sizeof( p.guild_name ) );
  7553. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7554. }
  7555. /// Reply to invite request.
  7556. /// 0169 <answer>.B (ZC_ACK_REQ_JOIN_GUILD)
  7557. /// answer:
  7558. /// 0 = Already in guild.
  7559. /// 1 = Offer rejected.
  7560. /// 2 = Offer accepted.
  7561. /// 3 = Guild full.
  7562. void clif_guild_inviteack( map_session_data& sd, int32 flag ){
  7563. PACKET_ZC_ACK_REQ_JOIN_GUILD p = {};
  7564. p.packetType = HEADER_ZC_ACK_REQ_JOIN_GUILD;
  7565. p.result = static_cast<decltype(p.result)>( flag );
  7566. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7567. }
  7568. /// Notifies clients of a guild of a leaving member.
  7569. /// 015a <char name>.24B <reason>.40B (ZC_ACK_LEAVE_GUILD)
  7570. /// 0a83 <CID>.L <reason>.40B (ZC_ACK_LEAVE_GUILD_DELNAME)
  7571. void clif_guild_leave( map_session_data& sd, const char* name, uint32 char_id, const char* mes ){
  7572. PACKET_ZC_ACK_LEAVE_GUILD p = {};
  7573. p.packetType = guildLeave;
  7574. #if PACKETVER_MAIN_NUM >= 20161019 || PACKETVER_RE_NUM >= 20160921 || defined(PACKETVER_ZERO)
  7575. p.GID = char_id;
  7576. #else
  7577. safestrncpy( p.name, name, sizeof( p.name ) );
  7578. #endif
  7579. safestrncpy( p.reason, mes, sizeof( p.reason ) );
  7580. clif_send( &p, sizeof( p ), &sd.bl, GUILD_NOBG );
  7581. }
  7582. /// Notifies clients of a guild of an expelled member.
  7583. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7584. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7585. /// 0a82 <CID>.L <reason>.40B (ZC_ACK_BAN_GUILD_DELNAME)
  7586. void clif_guild_expulsion( map_session_data& sd, const char* name, uint32 char_id, const char* mes ){
  7587. PACKET_ZC_ACK_BAN_GUILD p = {};
  7588. p.packetType = guildExpulsion;
  7589. #if PACKETVER_MAIN_NUM >= 20161019 || PACKETVER_RE_NUM >= 20160921 || defined(PACKETVER_ZERO)
  7590. p.GID = char_id;
  7591. #else
  7592. safestrncpy( p.name, name, sizeof( p.name ) );
  7593. #endif
  7594. safestrncpy( p.reason, mes, sizeof( p.reason ) );
  7595. #if PACKETVER < 20100803
  7596. // account name is not sent for security reasons
  7597. safestrncpy( p.account_name, "", sizeof( p.account_name ) );
  7598. #endif
  7599. clif_send( &p, sizeof( p ), &sd.bl, GUILD_NOBG );
  7600. }
  7601. /// Guild expulsion list
  7602. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }* (ZC_BAN_LIST)
  7603. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803) (ZC_BAN_LIST)
  7604. /// 0a87 <packet len>.W { <charid>.L <reason>.40B }* (ZC_BAN_LIST2)
  7605. /// 0b7c <packet len>.W { <charid>.L <reason>.40B <char name>.24B }* (ZC_BAN_LIST3)
  7606. static void clif_guild_expulsionlist(map_session_data& sd){
  7607. auto &g = sd.guild;
  7608. if (!g)
  7609. return;
  7610. PACKET_ZC_BAN_LIST* p = reinterpret_cast<PACKET_ZC_BAN_LIST*>( packet_buffer );
  7611. p->packetType = HEADER_ZC_BAN_LIST;
  7612. p->packetLen = sizeof(*p);
  7613. for( size_t i = 0, c = 0; i < MAX_GUILDEXPULSION; i++ ){
  7614. struct guild_expulsion& e = g->guild.expulsion[i];
  7615. if( e.account_id == 0 ){
  7616. continue;
  7617. }
  7618. PACKET_ZC_BAN_LIST_sub& banned = p->chars[c];
  7619. #if PACKETVER >= 20161019
  7620. banned.char_id = e.char_id;
  7621. #elif PACKETVER < 20100803
  7622. // account name (not used for security reasons)
  7623. safestrncpy(banned.account_name, "", sizeof(banned.account_name));
  7624. #endif
  7625. #if PACKETVER >= 20200902 || PACKETVER < 20161019
  7626. safestrncpy(banned.char_name, e.name, sizeof(banned.char_name));
  7627. #endif
  7628. safestrncpy(banned.message, e.mes, sizeof(banned.message));
  7629. p->packetLen += static_cast<decltype(p->packetLen)>(sizeof(banned));
  7630. c++;
  7631. }
  7632. clif_send(p,p->packetLen,&sd.bl,SELF);
  7633. }
  7634. /// Guild chat message
  7635. /// 017f <packet len>.W <message>.?B (ZC_GUILD_CHAT)
  7636. void clif_guild_message( const struct mmo_guild& g, const char* mes, size_t len ){
  7637. PACKET_ZC_GUILD_CHAT *p = reinterpret_cast<PACKET_ZC_GUILD_CHAT*>( packet_buffer );
  7638. // -1 for null terminator
  7639. static const size_t max_len = CHAT_SIZE_MAX - sizeof( *p ) - 1;
  7640. map_session_data* sd = guild_getavailablesd(g);
  7641. // Ignore this message, if no guildmember is available
  7642. if (sd == nullptr)
  7643. return;
  7644. if( len == 0 ){
  7645. return;
  7646. } else if( len > max_len ){
  7647. ShowWarning("clif_guild_message: Truncated message '%s' (len=%" PRIuPTR ", max=%" PRIuPTR ", guild_id=%u).\n", mes, len, max_len, g.guild_id);
  7648. len = max_len;
  7649. }
  7650. p->packetType = HEADER_ZC_GUILD_CHAT;
  7651. p->packetLength = sizeof(*p);
  7652. safestrncpy(p->message, mes, len+1);
  7653. p->packetLength += static_cast<decltype(p->packetLength)>( len + 1 );
  7654. clif_send(p, p->packetLength, &sd->bl, GUILD_NOBG);
  7655. }
  7656. /// Request for guild alliance
  7657. /// 0171 <inviter account id>.L <guild name>.24B (ZC_REQ_ALLY_GUILD).
  7658. void clif_guild_reqalliance(map_session_data& sd,uint32 account_id,const char *name)
  7659. {
  7660. PACKET_ZC_REQ_ALLY_GUILD p{};
  7661. p.packetType = HEADER_ZC_REQ_ALLY_GUILD;
  7662. p.inviterId = account_id;
  7663. safestrncpy(p.inviterGuildName,name,sizeof(p.inviterGuildName));
  7664. clif_send(&p,sizeof(p),&sd.bl,SELF);
  7665. }
  7666. /// Notifies the client about the result of a alliance request.
  7667. /// 0173 <answer>.B (ZC_ACK_REQ_ALLY_GUILD)
  7668. /// answer:
  7669. /// 0 = Already allied.
  7670. /// 1 = You rejected the offer.
  7671. /// 2 = You accepted the offer.
  7672. /// 3 = They have too any alliances.
  7673. /// 4 = You have too many alliances.
  7674. /// 5 = Alliances are disabled.
  7675. void clif_guild_allianceack(map_session_data& sd,uint8 flag){
  7676. PACKET_ZC_ACK_REQ_ALLY_GUILD p{};
  7677. p.packetType = HEADER_ZC_ACK_REQ_ALLY_GUILD;
  7678. p.flag = flag;
  7679. clif_send(&p,sizeof(p),&sd.bl,SELF);
  7680. }
  7681. /// Notifies the client that a alliance or opposition has been removed.
  7682. /// 0184 <other guild id>.L <relation>.L (ZC_DELETE_RELATED_GUILD)
  7683. /// relation:
  7684. /// 0 = Ally
  7685. /// 1 = Enemy
  7686. void clif_guild_delalliance(map_session_data& sd,uint32 guild_id,uint32 flag)
  7687. {
  7688. PACKET_ZC_DELETE_RELATED_GUILD p{};
  7689. p.packetType = HEADER_ZC_DELETE_RELATED_GUILD;
  7690. p.allyID = guild_id;
  7691. p.flag = flag;
  7692. clif_send(&p,sizeof(p),&sd.bl,SELF);
  7693. }
  7694. /// Notifies the client about the result of a opposition request.
  7695. /// 0181 <result>.B (ZC_ACK_REQ_HOSTILE_GUILD)
  7696. /// result:
  7697. /// 0 = Antagonist has been set.
  7698. /// 1 = Guild has too many Antagonists.
  7699. /// 2 = Already set as an Antagonist.
  7700. /// 3 = Antagonists are disabled.
  7701. void clif_guild_oppositionack(map_session_data& sd,uint8 flag){
  7702. PACKET_ZC_ACK_REQ_HOSTILE_GUILD p{};
  7703. p.packetType = HEADER_ZC_ACK_REQ_HOSTILE_GUILD;
  7704. p.flag = flag;
  7705. clif_send(&p,sizeof(p),&sd.bl,SELF);
  7706. }
  7707. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7708. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7709. /*
  7710. void clif_guild_allianceadded(struct guild *g,int32 idx)
  7711. {
  7712. unsigned char buf[64];
  7713. WBUFW(buf,0)=0x185;
  7714. WBUFL(buf,2)=g->alliance[idx].opposition;
  7715. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7716. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7717. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7718. }
  7719. */
  7720. /// Notifies the client about the result of a guild break.
  7721. /// 015e <reason>.L (ZC_ACK_DISORGANIZE_GUILD_RESULT)
  7722. /// 0 = success
  7723. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7724. /// 2 = there are still members in the guild
  7725. void clif_guild_broken( map_session_data& sd, int32 flag ){
  7726. PACKET_ZC_ACK_DISORGANIZE_GUILD_RESULT p = {};
  7727. p.packetType = HEADER_ZC_ACK_DISORGANIZE_GUILD_RESULT;
  7728. p.result = flag;
  7729. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7730. }
  7731. void clif_guild_position_selected(map_session_data& sd)
  7732. {
  7733. #if PACKETVER_MAIN_NUM >= 20180605 || PACKETVER_RE_NUM >= 20180605 || PACKETVER_ZERO_NUM >= 20180605
  7734. PACKET_ZC_GUILD_POSITION* p = reinterpret_cast<PACKET_ZC_GUILD_POSITION*>(packet_buffer);
  7735. p->packetType = HEADER_ZC_GUILD_POSITION;
  7736. p->packetLength = sizeof( PACKET_ZC_GUILD_POSITION );
  7737. p->AID = sd.bl.id;
  7738. if( sd.guild != nullptr ){
  7739. const auto& g = sd.guild->guild;
  7740. if( int ps = guild_getposition( sd ); ps != -1 ){
  7741. safestrncpy( p->position, g.position[ps].name, NAME_LENGTH );
  7742. p->packetLength += static_cast<decltype(p->packetLength)>( NAME_LENGTH );
  7743. }
  7744. }
  7745. clif_send( p, p->packetLength, &sd.bl, AREA );
  7746. #else
  7747. clif_name_area(&sd.bl);
  7748. #endif
  7749. }
  7750. /// Displays emotion on an object.
  7751. /// 00c0 <id>.L <type>.B (ZC_EMOTION)
  7752. /// type:
  7753. /// enum emotion_type
  7754. void clif_emotion( block_list& bl, emotion_type type ){
  7755. PACKET_ZC_EMOTION p{};
  7756. p.packetType = HEADER_ZC_EMOTION;
  7757. p.GID = bl.id;
  7758. p.type = static_cast<decltype(p.type)>( type );
  7759. clif_send( &p, sizeof(p), &bl, AREA );
  7760. }
  7761. /// Displays the contents of a talkiebox trap.
  7762. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  7763. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  7764. nullpo_retv( bl );
  7765. nullpo_retv( talkie );
  7766. PACKET_ZC_TALKBOX_CHATCONTENTS p = {};
  7767. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  7768. p.aid = bl->id;
  7769. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  7770. clif_send( &p, sizeof( PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  7771. }
  7772. /// Displays wedding effect centered on an object.
  7773. /// 01ea <id>.L (ZC_CONGRATULATION)
  7774. void clif_wedding_effect( block_list& bl ){
  7775. PACKET_ZC_CONGRATULATION p{};
  7776. p.packetType = HEADER_ZC_CONGRATULATION;
  7777. p.GID = bl.id;
  7778. clif_send( &p, sizeof(p), &bl, AREA );
  7779. }
  7780. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7781. /// 01e6 <partner name>.24B
  7782. void clif_callpartner(map_session_data& sd)
  7783. {
  7784. PACKET_ZC_COUPLENAME p = { 0 };
  7785. p.packetType = HEADER_ZC_COUPLENAME;
  7786. if( sd.status.partner_id ) {
  7787. map_session_data *p_sd = pc_get_partner(&sd);
  7788. if (p_sd != nullptr && !p_sd->state.autotrade)
  7789. safestrncpy(p.name, p_sd->status.name, NAME_LENGTH);
  7790. else
  7791. p.name[0] = 0;
  7792. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7793. p.name[0] = 0;
  7794. }
  7795. clif_send(&p, sizeof(p), &sd.bl, AREA);
  7796. }
  7797. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7798. /// 01e4
  7799. /// This packet while still implemented by the client is no longer being officially used.
  7800. /*
  7801. void clif_marriage_process(map_session_data *sd)
  7802. {
  7803. int32 fd;
  7804. nullpo_retv(sd);
  7805. fd=sd->fd;
  7806. WFIFOHEAD(fd,packet_len(0x1e4));
  7807. WFIFOW(fd,0)=0x1e4;
  7808. WFIFOSET(fd,packet_len(0x1e4));
  7809. }
  7810. */
  7811. /// Notice of divorce.
  7812. /// 0205 <partner name>.24B (ZC_DIVORCE)
  7813. void clif_divorced( map_session_data& sd, const char* name ){
  7814. PACKET_ZC_DIVORCE p{};
  7815. p.packetType = HEADER_ZC_DIVORCE;
  7816. safestrncpy( p.name, name, NAME_LENGTH );
  7817. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7818. }
  7819. /// Marriage proposal (ZC_REQ_COUPLE).
  7820. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7821. /// This packet while still implemented by the client is no longer being officially used.
  7822. /*
  7823. void clif_marriage_proposal(int32 fd, map_session_data *sd, map_session_data* ssd)
  7824. {
  7825. nullpo_retv(sd);
  7826. WFIFOHEAD(fd,packet_len(0x1e2));
  7827. WFIFOW(fd,0) = 0x1e2;
  7828. WFIFOL(fd,2) = ssd->status.account_id;
  7829. WFIFOL(fd,6) = ssd->status.char_id;
  7830. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7831. WFIFOSET(fd, packet_len(0x1e2));
  7832. }
  7833. */
  7834. /*==========================================
  7835. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7836. *------------------------------------------*/
  7837. void clif_disp_message(struct block_list* src, const char* mes, size_t len, enum send_target target)
  7838. {
  7839. unsigned char buf[256];
  7840. if( len == 0 ) {
  7841. return;
  7842. } else if( len > sizeof(buf)-5 ) {
  7843. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7844. len = sizeof(buf)-5;
  7845. }
  7846. WBUFW(buf, 0) = 0x17f;
  7847. WBUFW(buf, 2) = static_cast<int16>( len + 5 );
  7848. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7849. clif_send(buf, WBUFW(buf,2), src, target);
  7850. }
  7851. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7852. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7853. /// 00cd <result>.B
  7854. /// result:
  7855. /// 0 = failure
  7856. /// 1 = success
  7857. void clif_GM_kickack(map_session_data *sd, int32 id)
  7858. {
  7859. int32 fd;
  7860. nullpo_retv(sd);
  7861. fd = sd->fd;
  7862. WFIFOHEAD(fd,packet_len(0xcd));
  7863. WFIFOW(fd,0) = 0xcd;
  7864. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7865. WFIFOSET(fd, packet_len(0xcd));
  7866. }
  7867. void clif_GM_kick(map_session_data *sd, map_session_data *tsd)
  7868. {
  7869. nullpo_retv(tsd);
  7870. if (sd == nullptr)
  7871. tsd->state.keepshop = true;
  7872. if (session_isActive(tsd->fd))
  7873. clif_authfail_fd(tsd->fd, 15);
  7874. else
  7875. map_quit(tsd);
  7876. if (sd)
  7877. clif_GM_kickack(sd, tsd->status.account_id);
  7878. }
  7879. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7880. /// 014a <result>.L
  7881. /// result:
  7882. /// 0 = "A manner point has been successfully aligned."
  7883. /// 1 = MP_FAILURE_EXHAUST
  7884. /// 2 = MP_FAILURE_ALREADY_GIVING
  7885. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7886. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7887. /// 5 = "You got a good point from %s."
  7888. void clif_manner_message(map_session_data* sd, uint32 type)
  7889. {
  7890. int32 fd;
  7891. nullpo_retv(sd);
  7892. fd = sd->fd;
  7893. WFIFOHEAD(fd,packet_len(0x14a));
  7894. WFIFOW(fd,0) = 0x14a;
  7895. WFIFOL(fd,2) = type;
  7896. WFIFOSET(fd, packet_len(0x14a));
  7897. }
  7898. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7899. /// 014b <type>.B <GM name>.24B
  7900. /// type:
  7901. /// 0 = positive (unmute)
  7902. /// 1 = negative (mute)
  7903. void clif_GM_silence(map_session_data* sd, map_session_data* tsd, uint8 type)
  7904. {
  7905. int32 fd;
  7906. nullpo_retv(sd);
  7907. nullpo_retv(tsd);
  7908. fd = tsd->fd;
  7909. WFIFOHEAD(fd,packet_len(0x14b));
  7910. WFIFOW(fd,0) = 0x14b;
  7911. WFIFOB(fd,2) = type;
  7912. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7913. WFIFOSET(fd, packet_len(0x14b));
  7914. }
  7915. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7916. /// 00d1 <type>.B <result>.B
  7917. /// type:
  7918. /// 0 = /ex (deny)
  7919. /// 1 = /in (allow)
  7920. /// result:
  7921. /// 0 = success
  7922. /// 1 = failure
  7923. /// 2 = too many blocks
  7924. void clif_wisexin(map_session_data *sd,int32 type,int32 flag)
  7925. {
  7926. int32 fd;
  7927. nullpo_retv(sd);
  7928. fd=sd->fd;
  7929. WFIFOHEAD(fd,packet_len(0xd1));
  7930. WFIFOW(fd,0)=0xd1;
  7931. WFIFOB(fd,2)=type;
  7932. WFIFOB(fd,3)=flag;
  7933. WFIFOSET(fd,packet_len(0xd1));
  7934. }
  7935. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7936. /// 00d2 <type>.B <result>.B
  7937. /// type:
  7938. /// 0 = /exall (deny)
  7939. /// 1 = /inall (allow)
  7940. /// result:
  7941. /// 0 = success
  7942. /// 1 = failure
  7943. void clif_wisall(map_session_data *sd,int32 type,int32 flag)
  7944. {
  7945. int32 fd;
  7946. nullpo_retv(sd);
  7947. fd=sd->fd;
  7948. WFIFOHEAD(fd,packet_len(0xd2));
  7949. WFIFOW(fd,0)=0xd2;
  7950. WFIFOB(fd,2)=type;
  7951. WFIFOB(fd,3)=flag;
  7952. WFIFOSET(fd,packet_len(0xd2));
  7953. }
  7954. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7955. /// 07fe <bgm>.24B
  7956. void clif_playBGM( map_session_data& sd, const char* name ){
  7957. #if PACKETVER_MAIN_NUM >= 20220504
  7958. PACKET_ZC_PLAY_NPC_BGM* p = reinterpret_cast<PACKET_ZC_PLAY_NPC_BGM*>( packet_buffer );
  7959. size_t length = strlen( name ) + 1;
  7960. p->PacketType = HEADER_ZC_PLAY_NPC_BGM;
  7961. p->PacketLength = sizeof( *p );
  7962. p->playType = 0; // TODO: implement, send loop for the time being
  7963. safestrncpy( p->bgm, name, length );
  7964. p->PacketLength += static_cast<decltype(p->PacketLength)>( length );
  7965. clif_send( p, p->PacketLength, &sd.bl, SELF );
  7966. #elif PACKETVER >= 20091201
  7967. PACKET_ZC_PLAY_NPC_BGM p = {};
  7968. p.PacketType = HEADER_ZC_PLAY_NPC_BGM;
  7969. safestrncpy( p.bgm, name, sizeof( p.bgm ) );
  7970. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7971. #endif
  7972. }
  7973. /// Plays/stops a wave sound (ZC_SOUND).
  7974. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7975. /// file name:
  7976. /// relative to data\wav
  7977. /// act:
  7978. /// 0 = play (once)
  7979. /// 1 = play (repeat, does not work)
  7980. /// 2 = stops all sound instances of file name (does not work)
  7981. /// term:
  7982. /// unknown purpose, only relevant to act = 1
  7983. /// npc id:
  7984. /// The accustic direction of the sound is determined by the
  7985. /// relative position of the NPC to the player (3D sound).
  7986. void clif_soundeffect( struct block_list& bl, const char* name, int32 type, enum send_target target ){
  7987. PACKET_ZC_SOUND p = {};
  7988. p.PacketType = HEADER_ZC_SOUND;
  7989. safestrncpy( p.name, name, sizeof( p.name ) );
  7990. p.act = type;
  7991. p.term = 0; // TODO: implement
  7992. p.AID = bl.id;
  7993. clif_send( &p, sizeof( p ), &bl, target );
  7994. }
  7995. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7996. /// 01f3 <id>.L <effect id>.L
  7997. /// effect id:
  7998. /// @see doc/effect_list.txt
  7999. void clif_specialeffect(struct block_list* bl, int32 type, enum send_target target)
  8000. {
  8001. unsigned char buf[24];
  8002. nullpo_retv(bl);
  8003. memset(buf, 0, packet_len(0x1f3));
  8004. WBUFW(buf,0) = 0x1f3;
  8005. WBUFL(buf,2) = bl->id;
  8006. WBUFL(buf,6) = type;
  8007. clif_send(buf, packet_len(0x1f3), bl, target);
  8008. if (disguised(bl)) {
  8009. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8010. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8011. }
  8012. }
  8013. void clif_specialeffect_single(struct block_list* bl, int32 type, int32 fd)
  8014. {
  8015. WFIFOHEAD(fd,10);
  8016. WFIFOW(fd,0) = 0x1f3;
  8017. WFIFOL(fd,2) = bl->id;
  8018. WFIFOL(fd,6) = type;
  8019. WFIFOSET(fd,10);
  8020. }
  8021. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8022. /// 0284 <id>.L <effect id>.L <num data>.L
  8023. /// effect id:
  8024. /// @see doc/effect_list.txt
  8025. /// num data:
  8026. /// effect-dependent value
  8027. void clif_specialeffect_value(struct block_list* bl, int32 effect_id, int32 num, send_target target)
  8028. {
  8029. uint8 buf[14];
  8030. WBUFW(buf,0) = 0x284;
  8031. WBUFL(buf,2) = bl->id;
  8032. WBUFL(buf,6) = effect_id;
  8033. WBUFL(buf,10) = num;
  8034. clif_send(buf, packet_len(0x284), bl, target);
  8035. if( disguised(bl) )
  8036. {
  8037. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8038. clif_send(buf, packet_len(0x284), bl, SELF);
  8039. }
  8040. }
  8041. void clif_specialeffect_remove(struct block_list* bl_src, int32 effect, enum send_target e_target, struct block_list* bl_target)
  8042. {
  8043. #if PACKETVER >= 20181002
  8044. nullpo_retv( bl_src );
  8045. nullpo_retv( bl_target );
  8046. PACKET_ZC_REMOVE_EFFECT p = {};
  8047. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8048. p.aid = bl_src->id;
  8049. p.effectId = effect;
  8050. clif_send( &p, sizeof( PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8051. if( disguised(bl_src) )
  8052. {
  8053. p.aid = disguised_bl_id( bl_src->id );
  8054. clif_send( &p, sizeof( PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8055. }
  8056. #endif
  8057. }
  8058. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8059. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8060. void clif_messagecolor_target(struct block_list *bl, unsigned long color, const char *msg, bool rgb2bgr, enum send_target type, map_session_data *sd) {
  8061. uint16 msg_len = (uint16)(strlen(msg) + 1);
  8062. uint8 buf[CHAT_SIZE_MAX];
  8063. nullpo_retv(bl);
  8064. if (msg_len > sizeof(buf) - 12) {
  8065. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8066. msg_len = sizeof(buf) - 12;
  8067. }
  8068. if (rgb2bgr)
  8069. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8070. WBUFW(buf,0) = 0x2C1;
  8071. WBUFW(buf,2) = msg_len + 12;
  8072. WBUFL(buf,4) = bl->id;
  8073. WBUFL(buf,8) = color;
  8074. memcpy(WBUFCP(buf,12), msg, msg_len);
  8075. clif_send(buf, WBUFW(buf,2), (sd == nullptr ? bl : &(sd->bl)), type);
  8076. }
  8077. /**
  8078. * Notifies the client that the storage window is still open
  8079. *
  8080. * Should only be used in cases where the client closed the
  8081. * storage window without server's consent
  8082. */
  8083. void clif_refresh_storagewindow(map_session_data *sd) {
  8084. // Notify the client that the storage is open
  8085. if( sd->state.storage_flag == 1 ) {
  8086. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8087. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8088. clif_updatestorageamount(*sd, sd->storage.amount, sd->storage.max_amount);
  8089. }
  8090. // Notify the client that the gstorage is open otherwise it will
  8091. // remain locked forever and nobody will be able to access it
  8092. if( sd->state.storage_flag == 2 ) {
  8093. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8094. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8095. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8096. else {
  8097. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8098. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8099. clif_updatestorageamount(*sd, gstor->amount, gstor->max_amount);
  8100. }
  8101. }
  8102. // Notify the client that the premium storage is open
  8103. if (sd->state.storage_flag == 3) {
  8104. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8105. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8106. clif_updatestorageamount(*sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8107. }
  8108. }
  8109. // refresh the client's screen, getting rid of any effects
  8110. void clif_refresh(map_session_data *sd)
  8111. {
  8112. nullpo_retv(sd);
  8113. clif_changemap( *sd, sd->bl.m, sd->bl.x, sd->bl.y );
  8114. clif_inventorylist(sd);
  8115. clif_equipswitch_list(sd);
  8116. if(pc_iscarton(sd)) {
  8117. clif_cartlist(sd);
  8118. clif_updatestatus(*sd,SP_CARTINFO);
  8119. }
  8120. clif_updatestatus(*sd,SP_WEIGHT);
  8121. clif_updatestatus(*sd,SP_MAXWEIGHT);
  8122. clif_updatestatus(*sd,SP_STR);
  8123. clif_updatestatus(*sd,SP_AGI);
  8124. clif_updatestatus(*sd,SP_VIT);
  8125. clif_updatestatus(*sd,SP_INT);
  8126. clif_updatestatus(*sd,SP_DEX);
  8127. clif_updatestatus(*sd,SP_LUK);
  8128. #ifdef RENEWAL
  8129. clif_updatestatus(*sd,SP_POW);
  8130. clif_updatestatus(*sd,SP_STA);
  8131. clif_updatestatus(*sd,SP_WIS);
  8132. clif_updatestatus(*sd,SP_SPL);
  8133. clif_updatestatus(*sd,SP_CON);
  8134. clif_updatestatus(*sd,SP_CRT);
  8135. #endif
  8136. if (sd->spiritball)
  8137. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8138. clif_millenniumshield_single( *sd, *sd );
  8139. clif_spiritcharm_single( *sd, *sd );
  8140. if (sd->soulball)
  8141. clif_soulball( sd, &sd->bl, SELF );
  8142. if (sd->servantball)
  8143. clif_servantball( *sd, &sd->bl, SELF );
  8144. if (sd->abyssball)
  8145. clif_abyssball( *sd, &sd->bl, SELF );
  8146. if (sd->vd.cloth_color)
  8147. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8148. if (sd->vd.body_style)
  8149. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8150. if(hom_is_active(sd->hd))
  8151. clif_send_homdata( *sd->hd, SP_ACK );
  8152. if( sd->md ) {
  8153. clif_mercenary_info(sd);
  8154. clif_mercenary_skillblock(sd);
  8155. }
  8156. if( sd->ed )
  8157. clif_elemental_info(sd);
  8158. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8159. clif_weather_check(sd);
  8160. if( sd->chatID )
  8161. chat_leavechat(sd,0);
  8162. if( sd->state.vending )
  8163. clif_openvending( *sd );
  8164. if( pc_issit(sd) )
  8165. clif_sitting(sd->bl); // FIXME: just send to self, not area
  8166. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8167. clif_clearunit_single( sd->bl.id, CLR_DEAD, *sd );
  8168. else
  8169. clif_changed_dir(sd->bl, SELF);
  8170. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8171. //Issue #2143
  8172. //Cancel Trading State
  8173. if (sd->state.trading)
  8174. trade_tradecancel(sd);
  8175. //Cancel Buying/Selling State
  8176. if (sd->state.buyingstore)
  8177. buyingstore_close(sd);
  8178. mail_clear(sd);
  8179. clif_loadConfirm( sd );
  8180. if( disguised(&sd->bl) ) {/* refresh-da */
  8181. int16 disguise = sd->disguise;
  8182. pc_disguise(sd, 0);
  8183. pc_disguise(sd, disguise);
  8184. }
  8185. clif_refresh_storagewindow(sd);
  8186. }
  8187. /// Updates the object's (bl) name on client.
  8188. /// Used to update when a char leaves a party/guild. [Skotlex]
  8189. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8190. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8191. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8192. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8193. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8194. nullpo_retv( src );
  8195. nullpo_retv( bl );
  8196. switch( bl->type ){
  8197. case BL_PC: {
  8198. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8199. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8200. packet.gid = bl->id;
  8201. map_session_data *sd = (map_session_data *)bl;
  8202. //Requesting your own "shadow" name. [Skotlex]
  8203. if( src == bl && target == SELF && sd->disguise ){
  8204. packet.gid = -bl->id;
  8205. }
  8206. if( sd->fakename[0] ) {
  8207. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8208. clif_send( &packet, sizeof(packet), src, target );
  8209. return;
  8210. }
  8211. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8212. party_data *p = nullptr;
  8213. if( sd->status.party_id ){
  8214. p = party_search( sd->status.party_id );
  8215. }
  8216. // do not display party unless the player is also in a guild
  8217. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8218. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8219. }
  8220. if( sd->guild ){
  8221. int32 position;
  8222. // Will get the position of the guild the player is in
  8223. position = guild_getposition(*sd);
  8224. safestrncpy( packet.guild_name, sd->guild->guild.name, NAME_LENGTH );
  8225. safestrncpy( packet.position_name, sd->guild->guild.position[position].name, NAME_LENGTH );
  8226. }else if( sd->clan ){
  8227. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8228. }
  8229. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8230. packet.title_id = sd->status.title_id; // Title ID
  8231. #endif
  8232. clif_send(&packet, sizeof(packet), src, target);
  8233. }
  8234. break;
  8235. //[blackhole89]
  8236. case BL_HOM:
  8237. case BL_MER:
  8238. case BL_PET:
  8239. case BL_NPC:
  8240. case BL_ELEM: {
  8241. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8242. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8243. packet.gid = bl->id;
  8244. switch (bl->type) {
  8245. case BL_HOM:
  8246. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8247. break;
  8248. case BL_MER:
  8249. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8250. break;
  8251. case BL_PET:
  8252. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8253. break;
  8254. case BL_NPC:
  8255. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8256. break;
  8257. case BL_ELEM:
  8258. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8259. break;
  8260. }
  8261. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8262. unit_data *ud = unit_bl2ud(bl);
  8263. if (ud != nullptr) {
  8264. memcpy(packet.title, ud->title, NAME_LENGTH);
  8265. packet.groupId = ud->group_id;
  8266. }
  8267. #endif
  8268. clif_send(&packet, sizeof(packet), src, target);
  8269. }
  8270. break;
  8271. case BL_MOB: {
  8272. mob_data *md = (mob_data *)bl;
  8273. if( md->guardian_data && md->guardian_data->guild_id ){
  8274. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8275. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8276. packet.gid = bl->id;
  8277. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8278. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8279. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8280. clif_send(&packet, sizeof(packet), src, target);
  8281. }else if( battle_config.show_mob_info ){
  8282. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8283. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8284. packet.gid = bl->id;
  8285. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8286. char mobhp[50], *str_p = mobhp;
  8287. if( battle_config.show_mob_info&4 ){
  8288. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8289. }
  8290. if( battle_config.show_mob_info&1 ){
  8291. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8292. }
  8293. if( battle_config.show_mob_info&2 ){
  8294. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8295. }
  8296. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8297. if( str_p != mobhp ){
  8298. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8299. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8300. }
  8301. clif_send(&packet, sizeof(packet), src, target);
  8302. } else {
  8303. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8304. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8305. packet.gid = bl->id;
  8306. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8307. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8308. unit_data *ud = unit_bl2ud(bl);
  8309. if (ud != nullptr) {
  8310. memcpy(packet.title, ud->title, NAME_LENGTH);
  8311. packet.groupId = ud->group_id;
  8312. }
  8313. #endif
  8314. clif_send(&packet, sizeof(packet), src, target);
  8315. }
  8316. }
  8317. break;
  8318. case BL_CHAT:
  8319. case BL_SKILL:
  8320. // Newer clients request this, but do not need an answer
  8321. return;
  8322. default:
  8323. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8324. return;
  8325. }
  8326. }
  8327. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8328. /// 01ff <id>.L <x>.W <y>.W
  8329. ///
  8330. /// Visually moves(instant) a character to x,y. The char moves even
  8331. /// when the target cell isn't walkable. If the char is sitting it
  8332. /// stays that way.
  8333. void clif_slide(block_list& bl, int32 x, int32 y){
  8334. PACKET_ZC_HIGHJUMP p{};
  8335. p.packetType = HEADER_ZC_HIGHJUMP;
  8336. p.srcId = bl.id;
  8337. p.x = x;
  8338. p.y = y;
  8339. clif_send(&p, sizeof(p), &bl, AREA);
  8340. if( disguised(&bl) )
  8341. {
  8342. p.srcId = disguised_bl_id(bl.id);
  8343. clif_send(&p, sizeof(p), &bl, SELF);
  8344. }
  8345. }
  8346. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8347. /// 008d <packet len>.W <id>.L <message>.?B
  8348. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8349. {
  8350. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8351. int16 len_mes;
  8352. len_mes = static_cast<decltype(len_mes)>( strlen(mes) + 1 ); //Account for \0
  8353. if (len_mes > sizeof(buf)-8) {
  8354. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8355. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8356. }
  8357. // send message to others
  8358. if (flag == AREA) {
  8359. WBUFW(buf,0) = 0x8d;
  8360. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8361. WBUFL(buf,4) = bl->id;
  8362. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8363. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8364. }
  8365. // send back message to the speaker
  8366. if( bl->type == BL_PC ) {
  8367. WBUFW(buf,0) = 0x8e;
  8368. WBUFW(buf, 2) = len_mes + 4;
  8369. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8370. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8371. }
  8372. }
  8373. /*==========================
  8374. * Minimap fix [Kevin]
  8375. * Remove dot from minimap
  8376. *--------------------------*/
  8377. void clif_party_xy_remove(map_session_data* sd)
  8378. {
  8379. nullpo_retv(sd);
  8380. PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p{};
  8381. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  8382. p.AID = sd->status.account_id;
  8383. p.xPos = -1;
  8384. p.yPos = -1;
  8385. clif_send(&p, sizeof(p), &sd->bl, PARTY_SAMEMAP_WOS);
  8386. }
  8387. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8388. /// 0215 <msg id>.L
  8389. /// msg id:
  8390. /// 0x15 = End all negative status (PA_GOSPEL)
  8391. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8392. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8393. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8394. /// 0x19 = All stats +20 (PA_GOSPEL)
  8395. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8396. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8397. /// 0x1e = DEF +25% (PA_GOSPEL)
  8398. /// 0x1f = ATK +100% (PA_GOSPEL)
  8399. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8400. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8401. /// ? = nothing
  8402. void clif_gospel_info(map_session_data *sd, int32 type)
  8403. {
  8404. int32 fd=sd->fd;
  8405. WFIFOHEAD(fd,packet_len(0x215));
  8406. WFIFOW(fd,0)=0x215;
  8407. WFIFOL(fd,2)=type;
  8408. WFIFOSET(fd, packet_len(0x215));
  8409. }
  8410. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8411. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8412. /// result:
  8413. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8414. /// star:
  8415. /// 0 = Place of the Sun
  8416. /// 1 = Place of the Moon
  8417. /// 2 = Place of the Stars
  8418. /// 1 = Star Gladiator %s's %s: <mapname>
  8419. /// star:
  8420. /// 0 = Place of the Sun
  8421. /// 1 = Place of the Moon
  8422. /// 2 = Place of the Stars
  8423. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8424. /// star:
  8425. /// 0 = Target of the Sun
  8426. /// 1 = Target of the Moon
  8427. /// 2 = Target of the Stars
  8428. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8429. /// star:
  8430. /// 0 = Monster of the Sun
  8431. /// 1 = Monster of the Moon
  8432. /// 2 = Monster of the Stars
  8433. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8434. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8435. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8436. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8437. /// 40 = Target HP : <monster_id used as HP>
  8438. void clif_starskill(map_session_data* sd, const char* mapname, int32 monster_id, unsigned char star, unsigned char result)
  8439. {
  8440. int32 fd = sd->fd;
  8441. WFIFOHEAD(fd,packet_len(0x20e));
  8442. WFIFOW(fd,0) = 0x20e;
  8443. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8444. WFIFOL(fd,26) = monster_id;
  8445. WFIFOB(fd,30) = star;
  8446. WFIFOB(fd,31) = result;
  8447. WFIFOSET(fd,packet_len(0x20e));
  8448. }
  8449. /*==========================================
  8450. * Info about Star Glaldiator save map [Komurka]
  8451. * type: 1: Information, 0: Map registered
  8452. *------------------------------------------*/
  8453. void clif_feel_info(map_session_data* sd, unsigned char feel_level, unsigned char type)
  8454. {
  8455. char mapname[MAP_NAME_LENGTH_EXT];
  8456. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8457. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8458. }
  8459. /*==========================================
  8460. * Info about Star Glaldiator hate mob [Komurka]
  8461. * type: 1: Register mob, 0: Information.
  8462. *------------------------------------------*/
  8463. void clif_hate_info(map_session_data *sd, unsigned char hate_level,int32 class_, unsigned char type)
  8464. {
  8465. if( pcdb_checkid(class_) ) {
  8466. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8467. } else if( mobdb_checkid(class_) ) {
  8468. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8469. } else {
  8470. 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, (uint32)hate_level, (uint32)type);
  8471. }
  8472. }
  8473. /*==========================================
  8474. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8475. *------------------------------------------*/
  8476. void clif_mission_info(map_session_data *sd, int32 mob_id, unsigned char progress)
  8477. {
  8478. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8479. }
  8480. /*==========================================
  8481. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8482. *------------------------------------------*/
  8483. void clif_feel_hate_reset(map_session_data *sd)
  8484. {
  8485. clif_starskill(sd, "", 0, 0, 30);
  8486. }
  8487. /// Send out reply to configuration change
  8488. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8489. /// type: see enum e_config_type
  8490. /// value:
  8491. /// false = disabled
  8492. /// true = enabled
  8493. void clif_configuration( map_session_data* sd, enum e_config_type type, bool enabled ){
  8494. int32 fd;
  8495. nullpo_retv(sd);
  8496. fd = sd->fd;
  8497. WFIFOHEAD(fd, packet_len(0x2d9));
  8498. WFIFOW(fd, 0) = 0x2d9;
  8499. WFIFOL(fd, 2) = type;
  8500. WFIFOL(fd, 6) = enabled;
  8501. WFIFOSET(fd, packet_len(0x2d9));
  8502. }
  8503. /// The player's 'view equip' state, sent during login.
  8504. /// 02da <open equip window>.B (ZC_CONFIG_NOTIFY)
  8505. /// open equip window:
  8506. /// 0 = disabled
  8507. /// 1 = enabled
  8508. void clif_equipcheckbox( map_session_data& sd ){
  8509. PACKET_ZC_CONFIG_NOTIFY p{};
  8510. p.packetType = HEADER_ZC_CONFIG_NOTIFY;
  8511. p.flag = sd.status.show_equip;
  8512. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  8513. }
  8514. /// Sends info about a player's equipped items.
  8515. /// 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)
  8516. /// 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)
  8517. /// 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)
  8518. /// 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)
  8519. /// 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)
  8520. /// 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)
  8521. void clif_viewequip_ack( map_session_data& sd, map_session_data& tsd ){
  8522. #if PACKETVER_AD_NUM >= 20071211 || PACKETVER_SAK_NUM >= 20071127 || PACKETVER_MAIN_NUM >= 20071211 || defined(PACKETVER_RE)
  8523. PACKET_ZC_EQUIPWIN_MICROSCOPE* p = reinterpret_cast<PACKET_ZC_EQUIPWIN_MICROSCOPE*>( packet_buffer );
  8524. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8525. p->PacketLength = sizeof( *p );
  8526. safestrncpy( p->characterName, tsd.status.name, NAME_LENGTH );
  8527. p->job = tsd.status.class_;
  8528. p->head = tsd.vd.hair_style;
  8529. p->accessory = tsd.vd.head_bottom;
  8530. p->accessory2 = tsd.vd.head_mid;
  8531. p->accessory3 = tsd.vd.head_top;
  8532. #if PACKETVER >= 20110111
  8533. p->robe = tsd.vd.robe;
  8534. #endif
  8535. p->headpalette = tsd.vd.hair_color;
  8536. p->bodypalette = tsd.vd.cloth_color;
  8537. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8538. p->body2 = tsd.vd.body_style;
  8539. #endif
  8540. p->sex = tsd.vd.sex;
  8541. for( int32 i = 0, equip = 0; i < EQI_MAX; i++ ){
  8542. int32 k = tsd.equip_index[i];
  8543. if( k >= 0 ){
  8544. if( tsd.inventory.u.items_inventory[k].nameid == 0 || tsd.inventory_data[k] == nullptr ){ // Item doesn't exist
  8545. continue;
  8546. }
  8547. if( !tsd.inventory.u.items_inventory[k].equip ){
  8548. continue;
  8549. }
  8550. if( !itemdb_isequip2( tsd.inventory_data[k] ) ){ // Is not equippable
  8551. continue;
  8552. }
  8553. clif_item_equip( client_index( k ), &p->list[equip], &tsd.inventory.u.items_inventory[k], tsd.inventory_data[k], pc_equippoint( &tsd, k ) );
  8554. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( p->list[0] ) );
  8555. equip++;
  8556. }
  8557. }
  8558. clif_send( p, p->PacketLength, &sd.bl, SELF );
  8559. #endif
  8560. }
  8561. /// Display msgstringtable.txt string (ZC_MSG).
  8562. /// 0291 <message>.W
  8563. void clif_msg(map_session_data* sd, uint16 id)
  8564. {
  8565. int32 fd;
  8566. nullpo_retv(sd);
  8567. fd = sd->fd;
  8568. WFIFOHEAD(fd, packet_len(0x291));
  8569. WFIFOW(fd, 0) = 0x291;
  8570. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8571. WFIFOSET(fd, packet_len(0x291));
  8572. }
  8573. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8574. /// 0x7e2 <message>.W <value>.L
  8575. void clif_msg_value(map_session_data* sd, uint16 id, int32 value)
  8576. {
  8577. int32 fd = sd->fd;
  8578. WFIFOHEAD(fd, packet_len(0x7e2));
  8579. WFIFOW(fd,0) = 0x7e2;
  8580. WFIFOW(fd,2) = id;
  8581. WFIFOL(fd,4) = value;
  8582. WFIFOSET(fd, packet_len(0x7e2));
  8583. }
  8584. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8585. /// 07e6 <skill id>.W <msg id>.L
  8586. ///
  8587. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8588. /// "[SkillName] Message"
  8589. void clif_msg_skill(map_session_data* sd, uint16 skill_id, int32 msg_id)
  8590. {
  8591. int32 fd = sd->fd;
  8592. WFIFOHEAD(fd, packet_len(0x7e6));
  8593. WFIFOW(fd,0) = 0x7e6;
  8594. WFIFOW(fd,2) = skill_id;
  8595. WFIFOL(fd,4) = msg_id;
  8596. WFIFOSET(fd, packet_len(0x7e6));
  8597. }
  8598. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8599. /// 09cd <msg id>.W <color>.L
  8600. void clif_msg_color( map_session_data *sd, uint16 msg_id, uint32 color ){
  8601. nullpo_retv(sd);
  8602. int32 fd = sd->fd;
  8603. WFIFOHEAD(fd, packet_len(0x9cd));
  8604. WFIFOW(fd, 0) = 0x9cd;
  8605. WFIFOW(fd, 2) = msg_id;
  8606. WFIFOL(fd, 4) = color;
  8607. WFIFOSET(fd, packet_len(0x9cd));
  8608. }
  8609. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8610. /// Returns true if the packet was parsed successfully.
  8611. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8612. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8613. static bool clif_process_message(map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8614. const char* seperator = " : ";
  8615. int32 fd;
  8616. struct s_packet_db* info;
  8617. uint16 packetLength, inputLength;
  8618. const char *input, *name, *message;
  8619. size_t nameLength, messageLength;
  8620. fd = sd->fd;
  8621. info = &packet_db[RFIFOW(fd,0)];
  8622. packetLength = RFIFOW(fd,info->pos[0]);
  8623. input = RFIFOCP(fd,info->pos[1]);
  8624. // basic structure check for the 4-byte header
  8625. if( packetLength < 4 ){
  8626. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8627. return false;
  8628. }else{
  8629. inputLength = packetLength - 4;
  8630. }
  8631. // process <name> part of the packet
  8632. if( whisperFormat ) {
  8633. // name has fixed width
  8634. if( inputLength < NAME_LENGTH + 1 ) {
  8635. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8636. return false;
  8637. }
  8638. name = input;
  8639. // validate name
  8640. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8641. // only restriction is that the name must be zero-terminated
  8642. if( name[nameLength] != '\0' ) {
  8643. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8644. return false;
  8645. }
  8646. message = input + NAME_LENGTH;
  8647. messageLength = inputLength - NAME_LENGTH;
  8648. }else{
  8649. // name and message are separated by ' : '
  8650. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8651. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8652. // check if there's enough data provided
  8653. if( inputLength < nameLength + seperatorLength + 1 ){
  8654. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8655. return false;
  8656. }
  8657. name = input;
  8658. // validate name
  8659. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8660. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8661. {
  8662. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8663. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8664. set_eof(sd->fd); // Just kick them out to correct it.
  8665. return false;
  8666. }
  8667. message = input + nameLength + seperatorLength;
  8668. messageLength = inputLength - nameLength - seperatorLength;
  8669. }
  8670. #if PACKETVER < 20151001
  8671. // the declared length must match real length
  8672. if( messageLength != strnlen(message, messageLength)+1 ) {
  8673. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8674. return false;
  8675. }
  8676. // verify <message> part of the packet
  8677. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8678. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8679. return false;
  8680. }
  8681. #else
  8682. // No zero termination anymore
  8683. messageLength += 1;
  8684. #endif
  8685. // messages mustn't be too long
  8686. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8687. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8688. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8689. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8690. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8691. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8692. return false;
  8693. }
  8694. // If it is not a whisper message, set the name to the fakename of the player
  8695. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8696. strcpy( out_name, sd->fakename );
  8697. }else{
  8698. safestrncpy( out_name, name, nameLength + 1 );
  8699. }
  8700. safestrncpy( out_message, message, messageLength );
  8701. if( whisperFormat ){
  8702. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8703. out_full_message[nameLength] = '\0';
  8704. }else{
  8705. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8706. }
  8707. if( is_atcommand( fd, sd, out_message, 1 ) )
  8708. return false;
  8709. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8710. return false; //no "chatting" while muted.
  8711. if( battle_config.min_chat_delay ) { //[Skotlex]
  8712. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8713. return false;
  8714. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8715. }
  8716. if (battle_config.idletime_option&IDLE_CHAT)
  8717. sd->idletime = last_tick;
  8718. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8719. sd->idletime_hom = last_tick;
  8720. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  8721. sd->idletime_mer = last_tick;
  8722. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  8723. return true;
  8724. }
  8725. /**
  8726. * Displays a message if the player enters a PK Zone (during pk_mode)
  8727. * @param sd: Player data
  8728. */
  8729. inline void clif_pk_mode_message(map_session_data * sd)
  8730. {
  8731. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8732. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8733. if( (int32)sd->status.base_level < battle_config.pk_min_level ) {
  8734. char output[CHAT_SIZE_MAX];
  8735. // 1504: You've entered a PK Zone (safe until level %d).
  8736. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8737. battle_config.pk_min_level);
  8738. clif_showscript(&sd->bl, output, SELF);
  8739. } else {
  8740. // 1503: You've entered a PK Zone.
  8741. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8742. }
  8743. }
  8744. return;
  8745. }
  8746. // ---------------------
  8747. // clif_parse_wanttoconnect
  8748. // ---------------------
  8749. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8750. // error codes:
  8751. // 0 - Success
  8752. // 1 - Unknown packet_ver
  8753. // 2 - Invalid account_id
  8754. // 3 - Invalid char_id
  8755. // 4 - Invalid login_id1 (reserved)
  8756. // 5 - Invalid client_tick (reserved)
  8757. // 6 - Invalid sex
  8758. // Only the first 'invalid' error that appears is used.
  8759. static int32 clif_parse_WantToConnection_sub(int32 fd)
  8760. {
  8761. int32 value; //Value is used to temporarily store account/char_id/sex
  8762. //By default, start searching on the default one.
  8763. uint16 cmd = RFIFOW(fd, 0);
  8764. int16 packet_len;
  8765. packet_len = static_cast<decltype(packet_len)>( RFIFOREST( fd ) );
  8766. // FIXME: If the packet is not received at once, this will FAIL.
  8767. // Figure out, when it happens, that only part of the packet is
  8768. // received, or fix the function to be able to deal with that
  8769. // case.
  8770. if( packet_len != packet_db[cmd].len )
  8771. return 1; /* wrong length */
  8772. else if( (value=(int32)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8773. return 2; /* invalid account_id */
  8774. else if( (value=(int32)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8775. return 3; /* invalid char_id */
  8776. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8777. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8778. else if( (value=(int32)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8779. return 6; /* invalid sex */
  8780. else
  8781. return 0;
  8782. }
  8783. /// Request to connect to map-server.
  8784. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8785. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8786. /// There are various variants of this packet, some of them have padding between fields.
  8787. void clif_parse_WantToConnection(int32 fd, map_session_data* sd)
  8788. {
  8789. struct block_list* bl;
  8790. struct auth_node* node;
  8791. int32 cmd, account_id, char_id, login_id1, sex, err;
  8792. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8793. if (sd) {
  8794. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8795. return;
  8796. }
  8797. cmd = RFIFOW(fd, 0);
  8798. // TODO: shuffle packet
  8799. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8800. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8801. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8802. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8803. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8804. err = clif_parse_WantToConnection_sub(fd);
  8805. if( err ){ // connection rejected
  8806. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8807. err == 1 ? "." :
  8808. err == 2 ? ", possibly for having an invalid account_id." :
  8809. err == 3 ? ", possibly for having an invalid char_id." :
  8810. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8811. err == 4 ? ", possibly for having an invalid login_id1." :
  8812. err == 5 ? ", possibly for having an invalid client_tick." :
  8813. */
  8814. err == 6 ? ", possibly for having an invalid sex." :
  8815. ". ERROR invalid error code"));
  8816. WFIFOHEAD(fd,packet_len(0x6a));
  8817. WFIFOW(fd,0) = 0x6a;
  8818. WFIFOB(fd,2) = err;
  8819. WFIFOSET(fd,packet_len(0x6a));
  8820. #ifdef DUMP_INVALID_PACKET
  8821. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8822. #endif
  8823. RFIFOSKIP(fd, RFIFOREST(fd));
  8824. set_eof(fd);
  8825. return;
  8826. }
  8827. if( !global_core->is_running() ){ // not allowed
  8828. clif_authfail_fd(fd,1);// server closed
  8829. return;
  8830. }
  8831. //Check for double login.
  8832. bl = map_id2bl(account_id);
  8833. if(bl && bl->type != BL_PC) {
  8834. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8835. WFIFOHEAD(fd,packet_len(0x6a));
  8836. WFIFOW(fd,0) = 0x6a;
  8837. WFIFOB(fd,2) = 3; // Rejected by server
  8838. WFIFOSET(fd,packet_len(0x6a));
  8839. set_eof(fd);
  8840. return;
  8841. }
  8842. if (bl ||
  8843. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8844. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8845. {
  8846. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8847. return;
  8848. }
  8849. CREATE(sd, TBL_PC, 1);
  8850. new(sd) map_session_data();
  8851. sd->fd = fd;
  8852. #ifdef PACKET_OBFUSCATION
  8853. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8854. #endif
  8855. session[fd]->session_data = sd;
  8856. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8857. #if PACKETVER < 20070521
  8858. WFIFOHEAD(fd,4);
  8859. WFIFOL(fd,0) = sd->bl.id;
  8860. WFIFOSET(fd,4);
  8861. #else
  8862. WFIFOHEAD(fd,packet_len(0x283));
  8863. WFIFOW(fd,0) = 0x283;
  8864. WFIFOL(fd,2) = sd->bl.id;
  8865. WFIFOSET(fd,packet_len(0x283));
  8866. #endif
  8867. chrif_authreq(sd,false);
  8868. }
  8869. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8870. /// 007d
  8871. void clif_parse_LoadEndAck(int32 fd,map_session_data *sd)
  8872. {
  8873. bool guild_notice = false;
  8874. if(sd->bl.prev != nullptr)
  8875. return;
  8876. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8877. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8878. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  8879. sd->state.connect_new = 0;
  8880. return;
  8881. }
  8882. if (sd->state.rewarp) { //Rewarp player.
  8883. sd->state.rewarp = 0;
  8884. clif_changemap( *sd, sd->bl.m, sd->bl.x, sd->bl.y );
  8885. return;
  8886. }
  8887. sd->state.warping = 0;
  8888. // look
  8889. #if PACKETVER < 4
  8890. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8891. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8892. #else
  8893. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8894. #endif
  8895. pc_set_costume_view(sd);
  8896. if(sd->vd.cloth_color)
  8897. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8898. if(sd->vd.body_style)
  8899. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8900. // item
  8901. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8902. pc_checkitem(sd);
  8903. clif_equipswitch_list(sd);
  8904. // cart
  8905. if(pc_iscarton(sd)) {
  8906. clif_cartlist(sd);
  8907. clif_updatestatus(*sd,SP_CARTINFO);
  8908. }
  8909. // weight
  8910. clif_updatestatus(*sd,SP_WEIGHT);
  8911. clif_updatestatus(*sd,SP_MAXWEIGHT);
  8912. // guild
  8913. // (needs to go before clif_spawn() to show guild emblems correctly)
  8914. if(sd->status.guild_id)
  8915. guild_send_memberinfoshort(sd,1);
  8916. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  8917. if(battle_config.pc_invincible_time > 0) {
  8918. if(mapdata_flag_gvg(mapdata))
  8919. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8920. else
  8921. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8922. }
  8923. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  8924. map_spawnmobs(sd->bl.m);
  8925. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8926. mapdata->users_pvp++;
  8927. }
  8928. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8929. // reset the callshop flag if the player changes map
  8930. sd->state.callshop = 0;
  8931. if(map_addblock(&sd->bl))
  8932. return;
  8933. clif_spawn(&sd->bl);
  8934. // Party
  8935. // (needs to go after clif_spawn() to show hp bars correctly)
  8936. if(sd->status.party_id) {
  8937. party_send_movemap(sd);
  8938. clif_party_hp( *sd ); // Show hp after displacement [LuzZza]
  8939. }
  8940. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8941. if(!pc_isinvisible(sd) && mapdata->getMapFlag(MF_PVP)) {
  8942. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8943. if (!mapdata->getMapFlag(MF_PVP_NOCALCRANK))
  8944. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8945. sd->pvp_rank = 0;
  8946. sd->pvp_lastusers = 0;
  8947. sd->pvp_point = 5;
  8948. sd->pvp_won = 0;
  8949. sd->pvp_lost = 0;
  8950. }
  8951. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8952. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8953. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8954. else if (mapdata->getMapFlag(MF_GVG_DUNGEON))
  8955. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8956. else if( mapdata_flag_gvg(mapdata) )
  8957. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8958. else
  8959. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8960. // info about nearby objects
  8961. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8962. 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);
  8963. // pet
  8964. if( sd->pd ) {
  8965. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  8966. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8967. pet_return_egg( sd, sd->pd );
  8968. } else {
  8969. if(map_addblock(&sd->pd->bl))
  8970. return;
  8971. clif_spawn(&sd->pd->bl);
  8972. clif_send_petdata( sd, *sd->pd, CHANGESTATEPET_INIT );
  8973. clif_send_petstatus( *sd, *sd->pd );
  8974. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8975. }
  8976. }
  8977. //homunculus [blackhole89]
  8978. if( hom_is_active(sd->hd) ) {
  8979. if(map_addblock(&sd->hd->bl))
  8980. return;
  8981. clif_spawn(&sd->hd->bl);
  8982. clif_send_homdata( *sd->hd, SP_ACK );
  8983. // For some reason, official servers send the homunculus info twice, then update the HP/SP again.
  8984. clif_hominfo(sd, sd->hd, 1);
  8985. clif_hominfo(sd, sd->hd, 0);
  8986. clif_homunculus_updatestatus(*sd, SP_HP);
  8987. clif_homunculus_updatestatus(*sd, SP_SP);
  8988. clif_homskillinfoblock( *sd->hd );
  8989. status_calc_bl(&sd->hd->bl, { SCB_SPEED });
  8990. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8991. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8992. }
  8993. if( sd->md ) {
  8994. if(map_addblock(&sd->md->bl))
  8995. return;
  8996. clif_spawn(&sd->md->bl);
  8997. clif_mercenary_info(sd);
  8998. clif_mercenary_skillblock(sd);
  8999. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9000. }
  9001. if( sd->ed ) {
  9002. if (map_addblock(&sd->ed->bl))
  9003. return;
  9004. clif_spawn(&sd->ed->bl);
  9005. clif_elemental_info(sd);
  9006. clif_elemental_updatestatus(*sd, SP_HP);
  9007. clif_hpmeter_single( *sd, sd->ed->bl.id, sd->ed->battle_status.hp, sd->ed->battle_status.max_hp );
  9008. clif_elemental_updatestatus(*sd, SP_SP);
  9009. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9010. }
  9011. if(sd->state.connect_new) {
  9012. int32 lv;
  9013. guild_notice = true;
  9014. clif_skillinfoblock(sd);
  9015. clif_hotkeys_send(sd,0);
  9016. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9017. clif_hotkeys_send(sd,1);
  9018. #endif
  9019. clif_updatestatus(*sd,SP_BASEEXP);
  9020. clif_updatestatus(*sd,SP_NEXTBASEEXP);
  9021. clif_updatestatus(*sd,SP_JOBEXP);
  9022. clif_updatestatus(*sd,SP_NEXTJOBEXP);
  9023. clif_updatestatus(*sd,SP_SKILLPOINT);
  9024. clif_initialstatus( *sd );
  9025. if (sd->sc.option&OPTION_FALCON)
  9026. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9027. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9028. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9029. else if (sd->sc.option&OPTION_WUGRIDER)
  9030. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9031. else if (sd->sc.getSCE(SC_ALL_RIDING))
  9032. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9033. if(sd->status.manner < 0)
  9034. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9035. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9036. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9037. if(sd->bl.m == sd->feel_map[0].m
  9038. || sd->bl.m == sd->feel_map[1].m
  9039. || sd->bl.m == sd->feel_map[2].m)
  9040. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9041. }
  9042. if(sd->pd && sd->pd->pet.intimate > 900)
  9043. clif_pet_emotion( *sd->pd, (sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd) );
  9044. if(hom_is_active(sd->hd))
  9045. hom_init_timers(sd->hd);
  9046. if (night_flag && mapdata->getMapFlag(MF_NIGHTENABLED)) {
  9047. sd->state.night = 1;
  9048. clif_status_load(&sd->bl, EFST_SKE, 1);
  9049. }
  9050. // Notify everyone that this char logged in.
  9051. if( battle_config.friend_auto_add ){
  9052. for( const s_friend& my_friend : sd->status.friends ){
  9053. // Cancel early
  9054. if( my_friend.char_id == 0 ){
  9055. break;
  9056. }
  9057. if( map_session_data* tsd = map_charid2sd( my_friend.char_id ); tsd != nullptr ){
  9058. for( const s_friend& their_friend : tsd->status.friends ){
  9059. // Cancel early
  9060. if( their_friend.char_id == 0 ){
  9061. break;
  9062. }
  9063. if( their_friend.account_id != sd->status.account_id ){
  9064. continue;
  9065. }
  9066. if( their_friend.char_id != sd->status.char_id ){
  9067. continue;
  9068. }
  9069. clif_friendslist_toggle( *tsd, their_friend, true );
  9070. break;
  9071. }
  9072. }
  9073. }
  9074. }else{
  9075. map_foreachpc( clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, static_cast<int32>( true ) );
  9076. }
  9077. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9078. npc_script_event( *sd, NPCE_LOGIN );
  9079. }
  9080. // Set facing direction before check below to update client
  9081. if (battle_config.spawn_direction)
  9082. unit_setdir(&sd->bl, sd->status.body_direction, false);
  9083. } else {
  9084. //For some reason the client "loses" these on warp/map-change.
  9085. clif_updatestatus(*sd,SP_STR);
  9086. clif_updatestatus(*sd,SP_AGI);
  9087. clif_updatestatus(*sd,SP_VIT);
  9088. clif_updatestatus(*sd,SP_INT);
  9089. clif_updatestatus(*sd,SP_DEX);
  9090. clif_updatestatus(*sd,SP_LUK);
  9091. #ifdef RENEWAL
  9092. clif_updatestatus(*sd,SP_POW);
  9093. clif_updatestatus(*sd,SP_STA);
  9094. clif_updatestatus(*sd,SP_WIS);
  9095. clif_updatestatus(*sd,SP_SPL);
  9096. clif_updatestatus(*sd,SP_CON);
  9097. clif_updatestatus(*sd,SP_CRT);
  9098. #endif
  9099. // abort currently running script
  9100. sd->state.using_fake_npc = 0;
  9101. sd->state.menu_or_input = 0;
  9102. sd->npc_menu = 0;
  9103. if(sd->npc_id)
  9104. npc_event_dequeue(sd);
  9105. }
  9106. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9107. clif_partyinvitationstate( *sd );
  9108. #if PACKETVER >= 20070918
  9109. clif_equipcheckbox( *sd );
  9110. #endif
  9111. clif_pet_autofeed_status(sd,false);
  9112. clif_configuration( sd, CONFIG_CALL, sd->status.disable_call );
  9113. #if PACKETVER >= 20170920
  9114. if( battle_config.homunculus_autofeed_always ){
  9115. // Always send ON or OFF
  9116. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9117. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9118. }else{
  9119. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9120. }
  9121. }else{
  9122. // Only send when enabled
  9123. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9124. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9125. }
  9126. }
  9127. #endif
  9128. clif_reputation_list( *sd );
  9129. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9130. // Displays after VIP
  9131. clif_guild_notice( *sd );
  9132. guild_notice = false; // Do not display it twice
  9133. }
  9134. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9135. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9136. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->getMapFlag(MF_BATTLEGROUND))) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->getMapFlag(MF_BATTLEGROUND))))
  9137. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9138. }
  9139. if( night_flag && mapdata->getMapFlag(MF_NIGHTENABLED) )
  9140. { //Display night.
  9141. if( !sd->state.night )
  9142. {
  9143. sd->state.night = 1;
  9144. clif_status_load(&sd->bl, EFST_SKE, 1);
  9145. }
  9146. }
  9147. else if( sd->state.night )
  9148. { //Clear night display.
  9149. sd->state.night = 0;
  9150. clif_status_load(&sd->bl, EFST_SKE, 0);
  9151. }
  9152. if( mapdata->getMapFlag(MF_BATTLEGROUND) )
  9153. {
  9154. clif_map_type( *sd, MAPTYPE_BATTLEFIELD ); // Battleground Mode
  9155. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9156. clif_bg_updatescore_single(sd);
  9157. }
  9158. if( mapdata->getMapFlag(MF_ALLOWKS) && !mapdata_flag_ks(mapdata) )
  9159. {
  9160. char output[128];
  9161. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9162. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9163. }
  9164. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9165. mapdata->hpmeter_visible++;
  9166. sd->state.hpmeter_visible = 1;
  9167. }
  9168. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9169. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9170. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9171. #ifdef VIP_ENABLE
  9172. if (!sd->state.connect_new &&
  9173. !sd->vip.disableshowrate &&
  9174. sd->state.pmap != sd->bl.m &&
  9175. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->getMapFlag(MF_BEXP)
  9176. )
  9177. {
  9178. clif_display_pinfo( *sd );
  9179. }
  9180. #endif
  9181. // Instances do not need their own channels
  9182. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->getMapFlag(MF_NOMAPCHANNELAUTOJOIN) )
  9183. channel_mjoin(sd); //join new map
  9184. clif_pk_mode_message(sd);
  9185. }
  9186. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9187. // Displays at end
  9188. clif_guild_notice( *sd );
  9189. }
  9190. mail_clear(sd);
  9191. /* Guild Aura Init */
  9192. if( sd->guild && sd->state.gmaster_flag ) {
  9193. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild->guild,GD_LEADERSHIP));
  9194. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild->guild,GD_GLORYWOUNDS));
  9195. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild->guild,GD_SOULCOLD));
  9196. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild->guild,GD_HAWKEYES));
  9197. }
  9198. if( sd->state.vending ) { /* show we have a vending */
  9199. clif_openvending( *sd );
  9200. clif_showvendingboard( *sd );
  9201. }
  9202. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9203. if(!sd->state.autotrade && mapdata->getMapFlag(MF_LOADEVENT)) // Lance
  9204. npc_script_event( *sd, NPCE_LOADMAP );
  9205. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9206. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9207. if (sd->sc.opt2) //Client loses these on warp.
  9208. clif_changeoption(&sd->bl);
  9209. 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)) {
  9210. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM);
  9211. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM);
  9212. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9213. }
  9214. clif_weather_check(sd);
  9215. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9216. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9217. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9218. else
  9219. sd->areanpc.clear();
  9220. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9221. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(sd->bl) )
  9222. pc_setdead(sd);
  9223. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9224. if(pc_isdead(sd))
  9225. clif_clearunit_area( sd->bl, CLR_DEAD );
  9226. else {
  9227. skill_usave_trigger(sd);
  9228. if (battle_config.spawn_direction)
  9229. clif_changed_dir(sd->bl, SELF);
  9230. }
  9231. // Trigger skill effects if you appear standing on them
  9232. if(!battle_config.pc_invincible_time)
  9233. skill_unit_move(&sd->bl,gettick(),1);
  9234. pc_show_questinfo_reinit(sd);
  9235. pc_show_questinfo(sd);
  9236. #if PACKETVER >= 20150513
  9237. if( sd->mail.inbox.unread ){
  9238. clif_Mail_new(sd, 0, nullptr, nullptr);
  9239. }
  9240. #endif
  9241. sd->state.connect_new = 0;
  9242. sd->state.changemap = false;
  9243. }
  9244. /// Server's tick (ZC_NOTIFY_TIME).
  9245. /// 007f <time>.L
  9246. void clif_notify_time(map_session_data* sd, t_tick time)
  9247. {
  9248. int32 fd = sd->fd;
  9249. WFIFOHEAD(fd,packet_len(0x7f));
  9250. WFIFOW(fd,0) = 0x7f;
  9251. WFIFOL(fd,2) = client_tick(time);
  9252. WFIFOSET(fd,packet_len(0x7f));
  9253. }
  9254. /// Request for server's tick.
  9255. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9256. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9257. /// There are various variants of this packet, some of them have padding between fields.
  9258. void clif_parse_TickSend(int32 fd, map_session_data *sd)
  9259. {
  9260. // TODO: shuffle packet
  9261. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9262. clif_notify_time(sd, gettick());
  9263. }
  9264. /// Sends hotkey bar.
  9265. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9266. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9267. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9268. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9269. void clif_hotkeys_send( map_session_data *sd, int32 tab ){
  9270. #if defined(HOTKEY_SAVING) && ( PACKETVER_MAIN_NUM >= 20070711 || PACKETVER_RE_NUM >= 20080827 || PACKETVER_AD_NUM >= 20070711 || PACKETVER_SAK_NUM >= 20070628 )
  9271. nullpo_retv( sd );
  9272. PACKET_ZC_SHORTCUT_KEY_LIST p = {};
  9273. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9274. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9275. if( tab == 0 ){
  9276. p.rotate = sd->status.hotkey_rowshift;
  9277. }else{
  9278. p.rotate = sd->status.hotkey_rowshift2;
  9279. }
  9280. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9281. p.tab = tab;
  9282. #endif
  9283. #endif
  9284. for( int32 i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9285. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9286. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9287. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9288. }
  9289. clif_send( &p, sizeof(PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9290. #endif
  9291. }
  9292. /// Request to update a position on the hotkey row bar
  9293. void clif_parse_HotkeyRowShift( int32 fd, map_session_data *sd ){
  9294. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9295. const PACKET_CZ_SHORTCUTKEYBAR_ROTATE2* p = reinterpret_cast<PACKET_CZ_SHORTCUTKEYBAR_ROTATE2*>( RFIFOP( fd, 0 ) );
  9296. if( p->tab == 0 ){
  9297. sd->status.hotkey_rowshift = p->rowshift;
  9298. }else{
  9299. sd->status.hotkey_rowshift2 = p->rowshift;
  9300. }
  9301. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9302. const PACKET_CZ_SHORTCUTKEYBAR_ROTATE1* p = reinterpret_cast<PACKET_CZ_SHORTCUTKEYBAR_ROTATE1*>( RFIFOP( fd, 0 ) );
  9303. sd->status.hotkey_rowshift = p->rowshift;
  9304. #endif
  9305. }
  9306. /// Request to update a position on the hotkey bar.
  9307. /// 02ba <index>.W <is skill>.B <id>.L <count>.W (CZ_SHORTCUT_KEY_CHANGE)
  9308. void clif_parse_Hotkey(int32 fd, map_session_data *sd) {
  9309. #ifdef HOTKEY_SAVING
  9310. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9311. const PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = reinterpret_cast<PACKET_CZ_SHORTCUT_KEY_CHANGE2*>( RFIFOP( fd, 0 ) );
  9312. const uint16 idx = p->index + p->tab * MAX_HOTKEYS;
  9313. if( idx >= MAX_HOTKEYS_DB ){
  9314. return;
  9315. }
  9316. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9317. sd->status.hotkeys[idx].id = p->hotkey.id;
  9318. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9319. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9320. const PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = reinterpret_cast<PACKET_CZ_SHORTCUT_KEY_CHANGE1*>( RFIFOP( fd, 0 ) );
  9321. const uint16 idx = p->index;
  9322. if( idx >= MAX_HOTKEYS_DB ){
  9323. return;
  9324. }
  9325. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9326. sd->status.hotkeys[idx].id = p->hotkey.id;
  9327. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9328. #endif
  9329. #endif
  9330. }
  9331. /// Displays cast-like progress bar (ZC_PROGRESS).
  9332. /// 02f0 <color>.L <time>.L
  9333. void clif_progressbar(map_session_data * sd, unsigned long color, uint32 second)
  9334. {
  9335. int32 fd = sd->fd;
  9336. WFIFOHEAD(fd,packet_len(0x2f0));
  9337. WFIFOW(fd,0) = 0x2f0;
  9338. WFIFOL(fd,2) = color;
  9339. WFIFOL(fd,6) = second;
  9340. WFIFOSET(fd,packet_len(0x2f0));
  9341. }
  9342. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9343. /// 02f2
  9344. void clif_progressbar_abort(map_session_data * sd)
  9345. {
  9346. int32 fd = sd->fd;
  9347. WFIFOHEAD(fd,packet_len(0x2f2));
  9348. WFIFOW(fd,0) = 0x2f2;
  9349. WFIFOSET(fd,packet_len(0x2f2));
  9350. }
  9351. /// Notification from the client, that the progress bar has reached 100%.
  9352. /// 02f1 (CZ_PROGRESS)
  9353. void clif_parse_progressbar(int32 fd, map_session_data * sd){
  9354. // No progressbar active, ignore it
  9355. if( !sd->progressbar.npc_id ){
  9356. return;
  9357. }
  9358. int32 npc_id = sd->progressbar.npc_id;
  9359. bool closing = false;
  9360. // Check if the progress was canceled
  9361. if( gettick() < sd->progressbar.timeout && sd->st ){
  9362. closing = true;
  9363. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9364. // If a message window was open, offer a close button to the user
  9365. if( sd->st->mes_active ){
  9366. clif_scriptclose( *sd, npc_id );
  9367. }
  9368. }
  9369. sd->progressbar.npc_id = 0;
  9370. sd->progressbar.timeout = 0;
  9371. sd->state.workinprogress = WIP_DISABLE_NONE;
  9372. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9373. sd->idletime = last_tick;
  9374. }
  9375. npc_scriptcont(sd, npc_id, closing);
  9376. }
  9377. /// Displays cast-like progress bar on a NPC
  9378. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9379. void clif_progressbar_npc( struct npc_data *nd, map_session_data* sd ){
  9380. #if PACKETVER >= 20130821
  9381. unsigned char buf[14];
  9382. if( nd->progressbar.timeout > 0 ){
  9383. WBUFW(buf,0) = 0x9d1;
  9384. WBUFL(buf,2) = nd->bl.id;
  9385. WBUFL(buf,6) = nd->progressbar.color;
  9386. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9387. if( sd ){
  9388. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9389. }else{
  9390. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9391. }
  9392. }
  9393. #endif
  9394. }
  9395. /// Request to walk to a certain position on the current map.
  9396. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9397. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9398. /// There are various variants of this packet, some of them have padding between fields.
  9399. void clif_parse_WalkToXY(int32 fd, map_session_data *sd)
  9400. {
  9401. int16 x, y;
  9402. if (pc_isdead(sd)) {
  9403. clif_clearunit_area( sd->bl, CLR_DEAD );
  9404. return;
  9405. }
  9406. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9407. ; //You CAN walk on this OPT1 value.
  9408. else if (sd->progressbar.npc_id) {
  9409. clif_progressbar_abort(sd);
  9410. return; // First walk attempt cancels the progress bar
  9411. } else if (pc_cant_act(sd))
  9412. return;
  9413. if(sd->sc.getSCE(SC_RUN) || sd->sc.getSCE(SC_WUGDASH))
  9414. return;
  9415. // TODO: shuffle packet
  9416. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, nullptr);
  9417. //A move command one cell west is only valid if the target cell is free
  9418. if(battle_config.official_cell_stack_limit > 0
  9419. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9420. return;
  9421. // Cloaking wall check is actually updated when you click to process next movement
  9422. // not when you move each cell. This is official behaviour.
  9423. if (sd->sc.getSCE(SC_CLOAKING))
  9424. skill_check_cloaking(&sd->bl, sd->sc.getSCE(SC_CLOAKING));
  9425. status_change_end(&sd->bl, SC_ROLLINGCUTTER); // If you move, you lose your counters. [malufett]
  9426. status_change_end(&sd->bl, SC_CRESCIVEBOLT);
  9427. status_change_end(&sd->bl, SC_KI_SUL_RAMPAGE);
  9428. pc_delinvincibletimer(sd);
  9429. //Set last idle time... [Skotlex]
  9430. if (battle_config.idletime_option&IDLE_WALK)
  9431. sd->idletime = last_tick;
  9432. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9433. sd->idletime_hom = last_tick;
  9434. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9435. sd->idletime_mer = last_tick;
  9436. unit_walktoxy(&sd->bl, x, y, 4);
  9437. }
  9438. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9439. /// 018b <result>.W
  9440. /// result:
  9441. /// 0 = disconnect (quit)
  9442. /// 1 = cannot disconnect (wait 10 seconds)
  9443. /// ? = ignored
  9444. void clif_disconnect_ack(map_session_data* sd, int16 result)
  9445. {
  9446. int32 fd = sd->fd;
  9447. WFIFOHEAD(fd,packet_len(0x18b));
  9448. WFIFOW(fd,0) = 0x18b;
  9449. WFIFOW(fd,2) = result;
  9450. WFIFOSET(fd,packet_len(0x18b));
  9451. }
  9452. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9453. /// 018a <type>.W
  9454. /// type:
  9455. /// 0 = quit
  9456. void clif_parse_QuitGame(int32 fd, map_session_data *sd)
  9457. {
  9458. /* Rovert's prevent logout option fixed [Valaris] */
  9459. 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) &&
  9460. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9461. {
  9462. clif_disconnect_ack(sd, 0);
  9463. flush_fifo( fd );
  9464. if( battle_config.drop_connection_on_quit ){
  9465. set_eof( fd );
  9466. }
  9467. } else {
  9468. clif_disconnect_ack(sd, 1);
  9469. }
  9470. }
  9471. /// Requesting unit's name.
  9472. /// 0094 <id>.L (CZ_REQNAME)
  9473. /// 0368 <id>.L (CZ_REQNAME2)
  9474. /// There are various variants of this packet, some of them have padding between fields.
  9475. void clif_parse_GetCharNameRequest(int32 fd, map_session_data *sd)
  9476. {
  9477. // TODO: shuffle packet
  9478. int32 id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9479. struct block_list* bl;
  9480. //status_change *sc;
  9481. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9482. id = sd->bl.id;
  9483. bl = map_id2bl(id);
  9484. if( bl == nullptr )
  9485. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9486. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9487. return; // Block namerequests past view range
  9488. // 'see people in GM hide' cheat detection
  9489. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9490. sc = status_get_sc(bl);
  9491. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9492. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9493. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9494. ) {
  9495. char gm_msg[256];
  9496. 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);
  9497. ShowWarning(gm_msg);
  9498. // information is sent to all online GMs
  9499. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9500. return;
  9501. }
  9502. */
  9503. clif_name(&sd->bl,bl,SELF);
  9504. }
  9505. /// Validates and processes global messages
  9506. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9507. /// There are various variants of this packet.
  9508. void clif_parse_GlobalMessage(int32 fd, map_session_data* sd)
  9509. {
  9510. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9511. size_t length;
  9512. // validate packet and retrieve name and message
  9513. if( !clif_process_message(sd, false, name, message, output ) )
  9514. return;
  9515. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9516. channel_send(sd->gcbind,sd,message);
  9517. return;
  9518. }
  9519. // send message to others (using the send buffer for temp. storage)
  9520. clif_GlobalMessage( sd->bl, output, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC );
  9521. length = strlen(output) + 1;
  9522. // send back message to the speaker
  9523. WFIFOHEAD(fd,4+length);
  9524. WFIFOW(fd,0) = 0x8e;
  9525. WFIFOW(fd,2) = (uint16)(4+length);
  9526. safestrncpy(WFIFOCP(fd,4), output, length );
  9527. WFIFOSET(fd, WFIFOW(fd,2));
  9528. #ifdef PCRE_SUPPORT
  9529. // trigger listening npcs
  9530. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9531. #endif
  9532. // Chat logging type 'O' / Global Chat
  9533. log_chat(LOG_CHAT_GLOBAL, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, nullptr, message);
  9534. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9535. }
  9536. /// /mm /mapmove (as @rura GM command).
  9537. /// Request to warp to a map on given coordinates.
  9538. /// 0140 <map name>.16B <x>.W <y>.W (CZ_MOVETO_MAP)
  9539. void clif_parse_MapMove( int32 fd, map_session_data* sd){
  9540. const PACKET_CZ_MOVETO_MAP* p = reinterpret_cast<PACKET_CZ_MOVETO_MAP*>( RFIFOP( fd, 0 ) );
  9541. char map_name[MAP_NAME_LENGTH_EXT];
  9542. safestrncpy( map_name, p->map, sizeof( map_name ) );
  9543. char command[CHAT_SIZE_MAX];
  9544. safesnprintf( command, sizeof( command ),"%cmapmove %s %hu %hu", atcommand_symbol, map_name, p->x, p->y );
  9545. is_atcommand(fd, sd, command, 1);
  9546. }
  9547. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9548. /// 009c <id>.L <head dir>.W <dir>.B
  9549. /// head dir:
  9550. /// 0 = straight
  9551. /// 1 = turned CW
  9552. /// 2 = turned CCW
  9553. /// dir:
  9554. /// 0 = north
  9555. /// 1 = northwest
  9556. /// 2 = west
  9557. /// 3 = southwest
  9558. /// 4 = south
  9559. /// 5 = southeast
  9560. /// 6 = east
  9561. /// 7 = northeast
  9562. void clif_changed_dir(block_list& bl, enum send_target target){
  9563. PACKET_ZC_CHANGE_DIRECTION p{};
  9564. p.packetType = HEADER_ZC_CHANGE_DIRECTION;
  9565. p.srcId = bl.id;
  9566. if( bl.type == BL_PC ){
  9567. p.headDir = reinterpret_cast<map_session_data*>(&bl)->head_dir;
  9568. }else{
  9569. p.headDir = 0;
  9570. }
  9571. p.dir = unit_getdir(&bl);
  9572. clif_send(&p, sizeof(p), &bl, target);
  9573. if (disguised(&bl)) {
  9574. p.srcId = disguised_bl_id(bl.id);
  9575. p.headDir = 0;
  9576. clif_send(&p, sizeof(p), &bl, SELF);
  9577. }
  9578. }
  9579. /// Request to change own body and head direction.
  9580. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9581. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9582. /// There are various variants of this packet, some of them have padding between fields.
  9583. void clif_parse_ChangeDir(int32 fd, map_session_data *sd)
  9584. {
  9585. unsigned char headdir, dir;
  9586. // TODO: shuffle packet
  9587. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9588. headdir = RFIFOB(fd,info->pos[0]);
  9589. dir = RFIFOB(fd,info->pos[1]);
  9590. pc_setdir(sd, dir, headdir);
  9591. clif_changed_dir(sd->bl, AREA_WOS);
  9592. }
  9593. /// Request to show an emotion (CZ_REQ_EMOTION).
  9594. /// 00bf <type>.B
  9595. /// type:
  9596. /// @see enum emotion_type
  9597. void clif_parse_Emotion(int32 fd, map_session_data *sd){
  9598. if( sd == nullptr ){
  9599. return;
  9600. }
  9601. int32 emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9602. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9603. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9604. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9605. return;
  9606. }
  9607. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9608. if (sd->emotionlasttime + 1 >= time(nullptr)) { // not more than 1 per second
  9609. sd->emotionlasttime = time(nullptr);
  9610. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9611. return;
  9612. }
  9613. sd->emotionlasttime = time(nullptr);
  9614. if (battle_config.idletime_option&IDLE_EMOTION)
  9615. sd->idletime = last_tick;
  9616. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9617. sd->idletime_hom = last_tick;
  9618. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9619. sd->idletime_mer = last_tick;
  9620. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9621. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9622. return;
  9623. }
  9624. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9625. emoticon = rnd()%6+ET_DICE1;
  9626. }
  9627. clif_emotion( sd->bl, static_cast<emotion_type>( emoticon ) );
  9628. } else
  9629. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9630. }
  9631. /// Amount of currently online players, reply to /w /who
  9632. /// 00c2 <count>.L (ZC_USER_COUNT)
  9633. static void clif_user_count(map_session_data& sd)
  9634. {
  9635. PACKET_ZC_USER_COUNT p{};
  9636. p.packetType = HEADER_ZC_USER_COUNT;
  9637. p.playersCount = map_getusers();
  9638. clif_send(&p,sizeof(p),&sd.bl,SELF);
  9639. }
  9640. /// /w /who (CZ_REQ_USER_COUNT).
  9641. /// Request to display amount of currently connected players.
  9642. /// 00c1
  9643. void clif_parse_HowManyConnections(int32 fd, map_session_data *sd) {
  9644. if( sd == nullptr ){
  9645. return;
  9646. }
  9647. clif_user_count(*sd);
  9648. }
  9649. void clif_parse_ActionRequest_sub( map_session_data& sd, uint8 action_type, int32 target_id, t_tick tick ){
  9650. if (pc_isdead(&sd)) {
  9651. clif_clearunit_area(sd.bl, CLR_DEAD);
  9652. return;
  9653. }
  9654. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9655. if (action_type != DMG_NORMAL && action_type != DMG_REPEAT) {
  9656. if (sd.sc.cant.interact)
  9657. return;
  9658. unit_stop_walking( &sd.bl, USW_FIXPOS );
  9659. }
  9660. unit_stop_attack( &sd.bl );
  9661. if(target_id<0 && -target_id == sd.bl.id) // for disguises [Valaris]
  9662. target_id = sd.bl.id;
  9663. switch(action_type)
  9664. {
  9665. case DMG_NORMAL: // once attack
  9666. case DMG_REPEAT: // continuous attack
  9667. if( pc_cant_act(&sd) )
  9668. return;
  9669. if (!battle_config.sdelay_attack_enable && pc_checkskill(&sd, SA_FREECAST) <= 0) {
  9670. if (DIFF_TICK(tick, sd.ud.canact_tick) < 0) {
  9671. clif_skill_fail( sd, 1, USESKILL_FAIL_SKILLINTERVAL );
  9672. return;
  9673. }
  9674. }
  9675. pc_delinvincibletimer(&sd);
  9676. if (battle_config.idletime_option&IDLE_ATTACK)
  9677. sd.idletime = last_tick;
  9678. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9679. sd.idletime_hom = last_tick;
  9680. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9681. sd.idletime_mer = last_tick;
  9682. unit_attack(&sd.bl, target_id, action_type != 0);
  9683. break;
  9684. case DMG_SIT_DOWN: // sitdown
  9685. if (battle_config.basic_skill_check && pc_checkskill(&sd, NV_BASIC) < 3 && pc_checkskill(&sd, SU_BASIC_SKILL) < 1) {
  9686. clif_skill_fail( sd, 1, USESKILL_FAIL_LEVEL, 2 );
  9687. break;
  9688. }
  9689. if(pc_issit(&sd)) {
  9690. //Bugged client? Just refresh them.
  9691. clif_sitting(sd.bl);
  9692. return;
  9693. }
  9694. if (sd.ud.skilltimer != INVALID_TIMER || (sd.sc.opt1 && sd.sc.opt1 != OPT1_STONEWAIT && sd.sc.opt1 != OPT1_BURNING))
  9695. break;
  9696. if (!sd.sc.empty() && (
  9697. sd.sc.getSCE(SC_DANCING) ||
  9698. (sd.sc.getSCE(SC_GRAVITATION) && sd.sc.getSCE(SC_GRAVITATION)->val3 == BCT_SELF)
  9699. )) //No sitting during these states either.
  9700. break;
  9701. if (sd.state.block_action & PCBLOCK_SITSTAND) {
  9702. clif_displaymessage(sd.fd, msg_txt(&sd,794)); // This action is currently blocked.
  9703. break;
  9704. }
  9705. if (battle_config.idletime_option&IDLE_SIT)
  9706. sd.idletime = last_tick;
  9707. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_SIT)
  9708. sd.idletime_hom = last_tick;
  9709. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_SIT)
  9710. sd.idletime_mer = last_tick;
  9711. pc_setsit(&sd);
  9712. skill_sit(&sd, true);
  9713. clif_sitting(sd.bl);
  9714. break;
  9715. case DMG_STAND_UP: // standup
  9716. if (!pc_issit(&sd)) {
  9717. //Bugged client? Just refresh them.
  9718. clif_standing(sd.bl);
  9719. return;
  9720. }
  9721. if (sd.sc.opt1 && sd.sc.opt1 != OPT1_STONEWAIT && sd.sc.opt1 != OPT1_BURNING)
  9722. break;
  9723. if (sd.state.block_action & PCBLOCK_SITSTAND) {
  9724. clif_displaymessage(sd.fd, msg_txt(&sd,794)); // This action is currently blocked.
  9725. break;
  9726. }
  9727. if (pc_setstand(&sd, false)) {
  9728. if (battle_config.idletime_option&IDLE_SIT)
  9729. sd.idletime = last_tick;
  9730. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_SIT)
  9731. sd.idletime_hom = last_tick;
  9732. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_SIT)
  9733. sd.idletime_mer = last_tick;
  9734. skill_sit(&sd, false);
  9735. clif_standing(sd.bl);
  9736. }
  9737. break;
  9738. }
  9739. }
  9740. /// Request for an action.
  9741. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9742. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9743. /// action:
  9744. /// 0 = attack
  9745. /// 1 = pick up item
  9746. /// 2 = sit down
  9747. /// 3 = stand up
  9748. /// 7 = continous attack
  9749. /// 12 = (touch skill?)
  9750. /// There are various variants of this packet, some of them have padding between fields.
  9751. void clif_parse_ActionRequest(int32 fd, map_session_data *sd)
  9752. {
  9753. if( sd == nullptr ){
  9754. return;
  9755. }
  9756. // TODO: shuffle packet
  9757. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9758. clif_parse_ActionRequest_sub( *sd,
  9759. RFIFOB(fd,info->pos[1]),
  9760. RFIFOL(fd,info->pos[0]),
  9761. gettick()
  9762. );
  9763. }
  9764. /// Response to the death/system menu (CZ_RESTART).
  9765. /// 00b2 <type>.B
  9766. /// type:
  9767. /// 0 = restart (respawn)
  9768. /// 1 = char-select (disconnect)
  9769. void clif_parse_Restart(int32 fd, map_session_data *sd)
  9770. {
  9771. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9772. case 0x00:
  9773. pc_respawn(sd,CLR_OUTSIGHT);
  9774. break;
  9775. case 0x01:
  9776. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9777. 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) &&
  9778. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9779. { //Send to char-server for character selection.
  9780. chrif_charselectreq(sd, session[fd]->client_addr);
  9781. } else {
  9782. clif_disconnect_ack(sd, 1);
  9783. }
  9784. break;
  9785. }
  9786. }
  9787. /// Validates and processes whispered messages (CZ_WHISPER).
  9788. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9789. void clif_parse_WisMessage(int32 fd, map_session_data* sd)
  9790. {
  9791. map_session_data* dstsd;
  9792. int32 i;
  9793. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9794. // validate packet and retrieve name and message
  9795. if( !clif_process_message( sd, true, target, message, output ) )
  9796. return;
  9797. // Chat logging type 'W' / Whisper
  9798. 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);
  9799. //-------------------------------------------------------//
  9800. // Lordalfa - Paperboy - To whisper NPC commands //
  9801. //-------------------------------------------------------//
  9802. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9803. {
  9804. char* str = target+4; //Skip the NPC: string part.
  9805. struct npc_data* npc;
  9806. if ((npc = npc_name2id(str))) {
  9807. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9808. char *split;
  9809. char event[EVENT_NAME_LENGTH];
  9810. str = message;
  9811. // skip codepage indicator, if detected
  9812. if( str[0] == '|' && strlen(str) >= 4 )
  9813. str += 3;
  9814. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9815. split = strchr(str,'#');
  9816. if( split == nullptr ) { // use the remaining string
  9817. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9818. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9819. split_data[i][0] = '\0';
  9820. break;
  9821. }
  9822. *split = '\0';
  9823. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9824. str = split+1;
  9825. }
  9826. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9827. char variablename[CHAT_SIZE_MAX];
  9828. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9829. set_var_str( sd, variablename, split_data[i] );
  9830. }
  9831. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9832. npc_event(sd,event,0); // Calls the NPC label
  9833. return;
  9834. }
  9835. } else if( target[0] == '#' ) {
  9836. struct Channel *channel = nullptr;
  9837. char* chname = target;
  9838. channel = channel_name2channel(chname,sd,3);
  9839. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9840. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9841. channel_send(channel,sd,message);
  9842. }
  9843. else if( channel->pass[0] == '\0') { //no pass needed
  9844. if (channel_join(channel,sd)==0)
  9845. channel_send(channel,sd,message); //join success
  9846. }
  9847. else {
  9848. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9849. }
  9850. return;
  9851. }
  9852. }
  9853. // searching destination character
  9854. dstsd = map_nick2sd(target,false);
  9855. if (dstsd == nullptr || strcmp(dstsd->status.name, target) != 0) {
  9856. // player is not on this map-server
  9857. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9858. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9859. // and if we ask for 'Test', we must not contact 'test' player
  9860. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9861. intif_wis_message(sd, target, message, strlen(message) + 1);
  9862. return;
  9863. }
  9864. // if player ignores everyone
  9865. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9866. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9867. clif_wis_end( *sd, ACKWHISPER_TARGET_OFFLINE );
  9868. else
  9869. clif_wis_end( *sd, ACKWHISPER_ALL_IGNORED );
  9870. return;
  9871. }
  9872. // if player is autotrading
  9873. if (dstsd->state.autotrade == 1){
  9874. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9875. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9876. return;
  9877. }
  9878. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9879. // if player ignores the source character
  9880. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9881. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9882. clif_wis_end( *sd, ACKWHISPER_IGNORED );
  9883. return;
  9884. }
  9885. }
  9886. // notify sender of success
  9887. clif_wis_end( *sd, ACKWHISPER_SUCCESS );
  9888. // Normal message
  9889. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9890. }
  9891. /// /b /nb.
  9892. /// Request to broadcast a message on whole server.
  9893. /// 0099 <packet len>.W <text>.?B 00 (CZ_BROADCAST)
  9894. void clif_parse_Broadcast(int32 fd, map_session_data* sd) {
  9895. const PACKET_CZ_BROADCAST* p = reinterpret_cast<PACKET_CZ_BROADCAST*>( RFIFOP( fd, 0 ) );
  9896. if( p->packetSize < sizeof( *p ) ){
  9897. return;
  9898. }
  9899. char message[CHAT_SIZE_MAX];
  9900. safestrncpy( message, p->message, std::min<size_t>( sizeof( message ), p->packetSize - sizeof( *p ) + 1 ) );
  9901. char command[CHAT_SIZE_MAX];
  9902. safesnprintf( command, sizeof( command ),"%ckami %s", atcommand_symbol, message );
  9903. is_atcommand(fd, sd, command, 1);
  9904. }
  9905. /// Request to pick up an item.
  9906. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9907. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9908. /// There are various variants of this packet, some of them have padding between fields.
  9909. void clif_parse_TakeItem(int32 fd, map_session_data *sd)
  9910. {
  9911. struct flooritem_data *fitem;
  9912. int32 map_object_id;
  9913. // TODO: shuffle packet
  9914. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9915. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9916. do {
  9917. if (pc_isdead(sd)) {
  9918. clif_clearunit_area( sd->bl, CLR_DEAD );
  9919. break;
  9920. }
  9921. if (fitem == nullptr || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9922. break;
  9923. if (pc_cant_act(sd))
  9924. break;
  9925. if (!pc_takeitem(sd, fitem))
  9926. break;
  9927. return;
  9928. } while (0);
  9929. // Client REQUIRES a fail packet or you can no longer pick items.
  9930. clif_additem(sd,0,0,6);
  9931. }
  9932. /// Request to drop an item.
  9933. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9934. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9935. /// There are various variants of this packet, some of them have padding between fields.
  9936. void clif_parse_DropItem(int32 fd, map_session_data *sd){
  9937. // TODO: shuffle packet
  9938. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9939. int32 item_index = RFIFOW(fd,info->pos[0]) -2;
  9940. int32 item_amount = RFIFOW(fd,info->pos[1]) ;
  9941. for(;;) {
  9942. if (pc_isdead(sd))
  9943. break;
  9944. if (pc_cant_act2(sd) || sd->npc_id)
  9945. break;
  9946. if (sd->sc.cant.drop)
  9947. break;
  9948. if (!pc_dropitem(sd, item_index, item_amount))
  9949. break;
  9950. if (battle_config.idletime_option&IDLE_DROPITEM)
  9951. sd->idletime = last_tick;
  9952. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  9953. sd->idletime_hom = last_tick;
  9954. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  9955. sd->idletime_mer = last_tick;
  9956. return;
  9957. }
  9958. //Because the client does not like being ignored.
  9959. clif_dropitem( *sd, item_index, 0 );
  9960. }
  9961. /// Request to use an item.
  9962. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9963. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9964. /// There are various variants of this packet, some of them have padding between fields.
  9965. void clif_parse_UseItem(int32 fd, map_session_data *sd)
  9966. {
  9967. int32 n;
  9968. if (pc_isdead(sd)) {
  9969. clif_clearunit_area( sd->bl, CLR_DEAD );
  9970. return;
  9971. }
  9972. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  9973. clif_msg(sd, MSI_BUSY);
  9974. return;
  9975. }
  9976. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9977. if (battle_config.idletime_option&IDLE_USEITEM)
  9978. sd->idletime = last_tick;
  9979. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  9980. sd->idletime_hom = last_tick;
  9981. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  9982. sd->idletime_mer = last_tick;
  9983. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9984. if(n <0 || n >= MAX_INVENTORY)
  9985. return;
  9986. if (!pc_useitem(sd,n))
  9987. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9988. }
  9989. /// Request to equip an item
  9990. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9991. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9992. void clif_parse_EquipItem( int32 fd, map_session_data* sd ){
  9993. const PACKET_CZ_REQ_WEAR_EQUIP* p = reinterpret_cast<PACKET_CZ_REQ_WEAR_EQUIP*>( RFIFOP( fd, 0 ) );
  9994. if(pc_isdead(sd)) {
  9995. clif_clearunit_area( sd->bl, CLR_DEAD );
  9996. return;
  9997. }
  9998. uint16 index = server_index( p->index );
  9999. if( index >= MAX_INVENTORY ){
  10000. return;
  10001. }
  10002. if((sd->npc_id && !sd->npc_item_flag) || (sd->state.block_action & PCBLOCK_EQUIP)) {
  10003. clif_msg_color( sd, MSI_CAN_NOT_EQUIP_ITEM, color_table[COLOR_RED] );
  10004. return;
  10005. } else if (sd->state.storage_flag || sd->sc.opt1)
  10006. ; //You can equip/unequip stuff while storage is open/under status changes
  10007. else if (pc_cant_act2(sd))
  10008. return;
  10009. if(!sd->inventory.u.items_inventory[index].identify) {
  10010. clif_equipitemack( *sd, ITEM_EQUIP_ACK_FAIL, index ); // fail
  10011. return;
  10012. }
  10013. if(!sd->inventory_data[index])
  10014. return;
  10015. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10016. pet_equipitem(sd,index);
  10017. return;
  10018. }
  10019. if (battle_config.idletime_option&IDLE_USEITEM)
  10020. sd->idletime = last_tick;
  10021. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10022. sd->idletime_hom = last_tick;
  10023. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10024. sd->idletime_mer = last_tick;
  10025. //Client doesn't send the position for ammo.
  10026. if(sd->inventory_data[index]->type == IT_AMMO)
  10027. pc_equipitem(sd,index,EQP_AMMO);
  10028. else{
  10029. pc_equipitem( sd, index, p->position );
  10030. }
  10031. }
  10032. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10033. /// 00ab <index>.W
  10034. void clif_parse_UnequipItem(int32 fd,map_session_data *sd)
  10035. {
  10036. int32 index;
  10037. if(pc_isdead(sd)) {
  10038. clif_clearunit_area( sd->bl, CLR_DEAD );
  10039. return;
  10040. }
  10041. if((sd->npc_id && !sd->npc_item_flag) || (sd->state.block_action & PCBLOCK_EQUIP)) {
  10042. clif_msg_color( sd, MSI_CAN_NOT_EQUIP_ITEM, color_table[COLOR_RED] );
  10043. return;
  10044. } else if (sd->state.storage_flag || sd->sc.opt1)
  10045. ; //You can equip/unequip stuff while storage is open/under status changes
  10046. else if (pc_cant_act2(sd))
  10047. return;
  10048. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10049. if (battle_config.idletime_option&IDLE_USEITEM)
  10050. sd->idletime = last_tick;
  10051. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10052. sd->idletime_hom = last_tick;
  10053. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10054. sd->idletime_mer = last_tick;
  10055. pc_unequipitem(sd,index,1);
  10056. }
  10057. /// Request to start a conversation with an NPC.
  10058. /// 0090 <id>.L <type>.B (CZ_CONTACTNPC)
  10059. /// type:
  10060. /// 1 = click
  10061. void clif_parse_NpcClicked( int32 fd, map_session_data* sd ){
  10062. const PACKET_CZ_CONTACTNPC* p = reinterpret_cast<PACKET_CZ_CONTACTNPC*>( RFIFOP( fd, 0 ) );
  10063. if( sd == nullptr ){
  10064. return;
  10065. }
  10066. if(pc_isdead(sd)) {
  10067. clif_clearunit_area( sd->bl, CLR_DEAD );
  10068. return;
  10069. }
  10070. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10071. #ifdef RENEWAL
  10072. clif_msg( sd, MSI_BUSY);
  10073. #endif
  10074. return;
  10075. }
  10076. if( sd->state.mail_writing )
  10077. return;
  10078. block_list* bl = map_id2bl( p->AID );
  10079. if( bl == nullptr ){
  10080. return;
  10081. }
  10082. switch (bl->type) {
  10083. case BL_MOB:
  10084. case BL_PC:
  10085. clif_parse_ActionRequest_sub( *sd, DMG_REPEAT, bl->id, gettick() );
  10086. break;
  10087. case BL_NPC:
  10088. #ifdef RENEWAL
  10089. 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
  10090. clif_msg(sd, MSI_BUSY);
  10091. break;
  10092. }
  10093. #endif
  10094. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10095. struct npc_data* nd = (struct npc_data*)bl;
  10096. // Progressbar is running
  10097. if( nd->progressbar.timeout > 0 ){
  10098. return;
  10099. }
  10100. npc_click(sd,nd);
  10101. }
  10102. break;
  10103. }
  10104. }
  10105. /// Selection between buy/sell was made.
  10106. /// 00c5 <id>.L <type>.B (CZ_ACK_SELECT_DEALTYPE)
  10107. /// type:
  10108. /// 0 = buy
  10109. /// 1 = sell
  10110. void clif_parse_NpcBuySellSelected( int32 fd, map_session_data* sd ){
  10111. const PACKET_CZ_ACK_SELECT_DEALTYPE* p = reinterpret_cast<PACKET_CZ_ACK_SELECT_DEALTYPE*>( RFIFOP( fd, 0 ) );
  10112. if( sd == nullptr ){
  10113. return;
  10114. }
  10115. if (sd->state.trading)
  10116. return;
  10117. npc_buysellsel( sd, p->GID, p->type );
  10118. }
  10119. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10120. /// 00ca <result>.B
  10121. /// result:
  10122. /// 0 = "The deal has successfully completed."
  10123. /// 1 = "You do not have enough zeny."
  10124. /// 2 = "You are over your Weight Limit."
  10125. /// 3 = "Out of the maximum capacity, you have too many items."
  10126. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10127. /// 10 = "Props open-air store sales will be traded in RODEX"
  10128. /// 11 = "The exchange failed."
  10129. /// 12 = "The exchange was well done."
  10130. /// 13 = "The item is already sold and out of stock."
  10131. /// 14 = "There is not enough goods to exchange."
  10132. void clif_npc_buy_result( map_session_data* sd, e_purchase_result result ){
  10133. PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10134. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10135. p.result = (uint8)result;
  10136. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10137. }
  10138. /// Request to buy chosen items from npc shop.
  10139. /// 00c8 <packet len>.W { <amount>.W <name id>.W }* (CZ_PC_PURCHASE_ITEMLIST)
  10140. void clif_parse_NpcBuyListSend( int32 fd, map_session_data* sd ){
  10141. const PACKET_CZ_PC_PURCHASE_ITEMLIST *p = reinterpret_cast<PACKET_CZ_PC_PURCHASE_ITEMLIST*>( RFIFOP( fd, 0 ) );
  10142. uint16 n = ( p->packetLength - sizeof( *p ) ) / sizeof( p->items[0] );
  10143. e_purchase_result result;
  10144. if( sd->state.trading || !sd->npc_shopid )
  10145. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10146. else{
  10147. std::vector<s_npc_buy_list> items = {};
  10148. items.reserve( n );
  10149. for( uint16 i = 0; i < n; i++ ){
  10150. s_npc_buy_list item = {};
  10151. item.nameid = p->items[i].itemId;
  10152. item.qty = p->items[i].amount;
  10153. items.push_back( item );
  10154. }
  10155. result = npc_buylist( sd, items );
  10156. }
  10157. sd->npc_shopid = 0; //Clear shop data.
  10158. clif_npc_buy_result(sd, result);
  10159. }
  10160. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10161. /// 00cb <result>.B
  10162. /// result:
  10163. /// 0 = "The deal has successfully completed."
  10164. /// 1 = "The deal has failed."
  10165. void clif_npc_sell_result(map_session_data* sd, unsigned char result)
  10166. {
  10167. int32 fd = sd->fd;
  10168. WFIFOHEAD(fd,packet_len(0xcb));
  10169. WFIFOW(fd,0) = 0xcb;
  10170. WFIFOB(fd,2) = result;
  10171. WFIFOSET(fd,packet_len(0xcb));
  10172. }
  10173. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10174. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10175. void clif_parse_NpcSellListSend(int32 fd,map_session_data *sd)
  10176. {
  10177. int32 fail=0;
  10178. const PACKET_CZ_PC_SELL_ITEMLIST* p = reinterpret_cast<PACKET_CZ_PC_SELL_ITEMLIST*>( RFIFOP( fd, 0 ) );
  10179. int32 n = ( p->packetLength - sizeof( *p ) ) / sizeof( p->sellList[0] );
  10180. if (sd->state.trading || !sd->npc_shopid)
  10181. fail = 1;
  10182. else
  10183. fail = npc_selllist(sd, n, p->sellList);
  10184. sd->npc_shopid = 0; //Clear shop data.
  10185. clif_npc_sell_result(sd, fail);
  10186. }
  10187. /// Chatroom creation request.
  10188. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B (CZ_CREATE_CHATROOM)
  10189. /// type:
  10190. /// 0 = private
  10191. /// 1 = public
  10192. void clif_parse_CreateChatRoom( int32 fd, map_session_data* sd){
  10193. const PACKET_CZ_CREATE_CHATROOM* p = reinterpret_cast<PACKET_CZ_CREATE_CHATROOM*>( RFIFOP( fd, 0 ) );
  10194. if( sd == nullptr ){
  10195. return;
  10196. }
  10197. if( sd->sc.getSCE( SC_NOCHAT ) && sd->sc.getSCE( SC_NOCHAT )->val1&MANNER_NOROOM ){
  10198. return;
  10199. }
  10200. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10201. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 3 );
  10202. return;
  10203. }
  10204. if( npc_isnear(&sd->bl) ) {
  10205. // uncomment to send msg_txt.
  10206. //char output[150];
  10207. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10208. //clif_displaymessage(sd->fd, output);
  10209. clif_skill_fail( *sd, 1, USESKILL_FAIL_THERE_ARE_NPC_AROUND );
  10210. return;
  10211. }
  10212. if( p->packetSize < sizeof( *p ) ){
  10213. // invalid input
  10214. return;
  10215. }
  10216. char password[CHATROOM_PASS_SIZE];
  10217. safestrncpy( password, p->password, sizeof( password ) );
  10218. char title[CHATROOM_TITLE_SIZE];
  10219. safestrncpy( title, p->title, std::min<size_t>( sizeof( title ), p->packetSize - sizeof( *p ) + 1 ) );
  10220. chat_createpcchat( sd, title, password, p->limit, p->type != 0 );
  10221. }
  10222. /// Chatroom join request.
  10223. /// 00d9 <chat ID>.L <passwd>.8B (CZ_REQ_ENTER_ROOM)
  10224. void clif_parse_ChatAddMember(int32 fd, map_session_data* sd){
  10225. if( sd == nullptr ){
  10226. return;
  10227. }
  10228. const PACKET_CZ_REQ_ENTER_ROOM* p = reinterpret_cast<PACKET_CZ_REQ_ENTER_ROOM*>( RFIFOP( fd, 0 ) );
  10229. chat_joinchat( sd, p->chat_id, p->password );
  10230. }
  10231. /// Chatroom properties adjustment request.
  10232. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B (CZ_CHANGE_CHATROOM)
  10233. /// type:
  10234. /// 0 = private
  10235. /// 1 = public
  10236. void clif_parse_ChatRoomStatusChange(int32 fd, map_session_data* sd){
  10237. if( sd == nullptr ){
  10238. return;
  10239. }
  10240. const PACKET_CZ_CHANGE_CHATROOM* p = reinterpret_cast<PACKET_CZ_CHANGE_CHATROOM*>( RFIFOP( fd, 0 ) );
  10241. size_t len = p->packetSize - sizeof( *p );
  10242. if( len <= 0 )
  10243. return; // invalid input
  10244. char s_password[CHATROOM_PASS_SIZE];
  10245. char s_title[CHATROOM_TITLE_SIZE];
  10246. safestrncpy( s_password, p->password, sizeof( s_password ) );
  10247. // NOTE: assumes that safestrncpy will not access the len+1'th byte
  10248. safestrncpy( s_title, p->title, std::min<size_t>( len + 1, CHATROOM_TITLE_SIZE ) );
  10249. chat_changechatstatus( sd, s_title, s_password, p->limit, p->type );
  10250. }
  10251. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10252. /// 00e0 <role>.L <nick>.24B
  10253. /// role:
  10254. /// 0 = owner
  10255. /// 1 = normal
  10256. void clif_parse_ChangeChatOwner(int32 fd, map_session_data* sd)
  10257. {
  10258. //int32 role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10259. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10260. }
  10261. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10262. /// 00e2 <name>.24B
  10263. void clif_parse_KickFromChat(int32 fd,map_session_data *sd)
  10264. {
  10265. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10266. }
  10267. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10268. /// 00e3
  10269. void clif_parse_ChatLeave(int32 fd, map_session_data* sd)
  10270. {
  10271. chat_leavechat(sd,0);
  10272. }
  10273. // Handles notifying asker and rejecter of what has just ocurred.
  10274. // Type is used to determine the correct msg_txt to use
  10275. void clif_noask_sub( map_session_data& sd, map_session_data& tsd, int32 type ){
  10276. char output[CHAT_SIZE_MAX];
  10277. // Your request has been rejected by autoreject option.
  10278. clif_messagecolor( &sd.bl, color_table[COLOR_LIGHT_GREEN], msg_txt( &sd, 392 ), false, SELF );
  10279. // Notice that a request was rejected.
  10280. safesnprintf( output, CHAT_SIZE_MAX, msg_txt( &tsd, type ), sd.status.name );
  10281. clif_messagecolor( &tsd.bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10282. }
  10283. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10284. /// 00e4 <account id>.L
  10285. void clif_parse_TradeRequest(int32 fd,map_session_data *sd)
  10286. {
  10287. map_session_data *t_sd;
  10288. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10289. if(!sd->chatID && pc_cant_act(sd))
  10290. return; //You can trade while in a chatroom.
  10291. if(t_sd){
  10292. // @noask [LuzZza]
  10293. if(t_sd->state.noask) {
  10294. clif_noask_sub( *sd, *t_sd, 393 ); // Autorejected trade request from %s.
  10295. return;
  10296. }
  10297. if (t_sd->state.mail_writing) {
  10298. // Fake trading
  10299. clif_traderesponse(*sd,TRADE_ACK_BUSY);
  10300. return;
  10301. }
  10302. }
  10303. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10304. clif_skill_fail( *sd, 1 );
  10305. return;
  10306. }
  10307. trade_traderequest(sd,t_sd);
  10308. }
  10309. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10310. /// 00e6 <result>.B
  10311. /// result:
  10312. /// 3 = accepted
  10313. /// 4 = rejected
  10314. void clif_parse_TradeAck(int32 fd,map_session_data *sd)
  10315. {
  10316. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10317. }
  10318. /// Request to add an item to current trade.
  10319. /// 00e8 <index>.W <amount>.L (CZ_ADD_EXCHANGE_ITEM)
  10320. void clif_parse_TradeAddItem(int32 fd,map_session_data *sd)
  10321. {
  10322. if( sd == nullptr ){
  10323. return;
  10324. }
  10325. const PACKET_CZ_ADD_EXCHANGE_ITEM* p = reinterpret_cast<PACKET_CZ_ADD_EXCHANGE_ITEM*>( RFIFOP( fd, 0 ) );
  10326. if( p->index == 0 ){
  10327. trade_tradeaddzeny( sd, p->amount );
  10328. }else{
  10329. trade_tradeadditem( sd, server_index( p->index ), static_cast<int16>( p->amount ) );
  10330. }
  10331. }
  10332. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10333. /// 00eb
  10334. void clif_parse_TradeOk(int32 fd,map_session_data *sd)
  10335. {
  10336. trade_tradeok(sd);
  10337. }
  10338. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10339. /// 00ed
  10340. void clif_parse_TradeCancel(int32 fd,map_session_data *sd)
  10341. {
  10342. trade_tradecancel(sd);
  10343. }
  10344. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10345. /// 00ef
  10346. void clif_parse_TradeCommit(int32 fd,map_session_data *sd)
  10347. {
  10348. trade_tradecommit(sd);
  10349. }
  10350. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10351. /// 0118
  10352. void clif_parse_StopAttack(int32 fd,map_session_data *sd)
  10353. {
  10354. unit_stop_attack( &sd->bl );
  10355. sd->ud.state.attack_continue = 0;
  10356. }
  10357. /// Request to move an item from inventory to cart.
  10358. /// 0126 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_CART)
  10359. void clif_parse_PutItemToCart( int32 fd, map_session_data *sd ){
  10360. if (pc_istrading(sd) || !pc_iscarton(sd) || pc_cant_act2(sd))
  10361. return;
  10362. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10363. return;
  10364. const PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART* p = reinterpret_cast<PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART*>( RFIFOP( fd, 0 ) );
  10365. pc_putitemtocart( sd, server_index( p->index ), p->count);
  10366. }
  10367. /// Request to move an item from cart to inventory.
  10368. /// 0127 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_CART_TO_BODY)
  10369. void clif_parse_GetItemFromCart(int32 fd,map_session_data *sd)
  10370. {
  10371. if( sd == nullptr ){
  10372. return;
  10373. }
  10374. if (!pc_iscarton(sd) || pc_cant_act2(sd))
  10375. return;
  10376. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10377. return;
  10378. const PACKET_CZ_MOVE_ITEM_FROM_CART_TO_BODY* p = reinterpret_cast<PACKET_CZ_MOVE_ITEM_FROM_CART_TO_BODY*>( RFIFOP( fd, 0 ) );
  10379. pc_getitemfromcart( sd, server_index( p->index ), p->amount );
  10380. }
  10381. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10382. /// 012a
  10383. void clif_parse_RemoveOption(int32 fd,map_session_data *sd)
  10384. {
  10385. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10386. #ifdef NEW_CARTS
  10387. && sd->sc.getSCE(SC_PUSH_CART) )
  10388. pc_setcart(sd,0);
  10389. #else
  10390. )
  10391. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10392. #endif
  10393. else // priority to remove this option before we can clear cart
  10394. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10395. }
  10396. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10397. /// 097f <Length>.W <identity>.L <type>.B
  10398. void clif_SelectCart(map_session_data *sd) {
  10399. #if PACKETVER >= 20150826
  10400. int32 i = 0, carts = 3;
  10401. int32 fd = sd->fd;
  10402. WFIFOHEAD(fd,8 + carts);
  10403. WFIFOW(fd,0) = 0x97f;
  10404. WFIFOW(fd,2) = 8 + carts;
  10405. WFIFOL(fd,4) = sd->status.account_id;
  10406. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10407. for( i = 0; i < carts; i++ ) {
  10408. WFIFOB(fd,8 + i) = 10 + i;
  10409. }
  10410. WFIFOSET(fd,8 + carts);
  10411. #endif
  10412. }
  10413. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10414. /// 0980 <identity>.L <type>.B
  10415. void clif_parse_SelectCart(int32 fd,map_session_data *sd) {
  10416. #if PACKETVER >= 20150826
  10417. int32 type;
  10418. // Check identity
  10419. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10420. return;
  10421. type = (int32)RFIFOB(fd,6);
  10422. // Check type
  10423. if( type < 10 || type > 12 )
  10424. return;
  10425. pc_setcart(sd, type);
  10426. #endif
  10427. }
  10428. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10429. /// 01af <num>.W
  10430. void clif_parse_ChangeCart(int32 fd,map_session_data *sd)
  10431. {// TODO: State tracking?
  10432. int32 type;
  10433. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10434. return;
  10435. #ifdef RENEWAL
  10436. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10437. clif_msg(sd, MSI_BUSY);
  10438. return;
  10439. }
  10440. #endif
  10441. type = (int32)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10442. if(
  10443. #ifdef NEW_CARTS
  10444. #if PACKETVER >= 20191106
  10445. (type == 13 && sd->status.base_level > 100) ||
  10446. #endif
  10447. (type == 9 && sd->status.base_level > 130) ||
  10448. (type == 8 && sd->status.base_level > 120) ||
  10449. (type == 7 && sd->status.base_level > 110) ||
  10450. (type == 6 && sd->status.base_level > 100) ||
  10451. #endif
  10452. (type == 5 && sd->status.base_level > 90) ||
  10453. (type == 4 && sd->status.base_level > 80) ||
  10454. (type == 3 && sd->status.base_level > 65) ||
  10455. (type == 2 && sd->status.base_level > 40) ||
  10456. (type == 1))
  10457. pc_setcart(sd, type);
  10458. }
  10459. /// Request to increase status (CZ_STATUS_CHANGE).
  10460. /// 00bb <status id>.W <amount>.B
  10461. /// status id:
  10462. /// SP_STR ~ SP_LUK
  10463. /// amount:
  10464. /// Old clients always send 1 for this, even when using /str+ and the like.
  10465. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10466. void clif_parse_StatusUp(int32 fd,map_session_data *sd)
  10467. {
  10468. int32 increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10469. if( increase_amount < 0 ) {
  10470. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10471. fd, increase_amount);
  10472. }
  10473. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10474. }
  10475. /// Request to increase trait status.
  10476. /// 0b24 <status id>.W <amount>.W (CZ_ADVANCED_STATUS_CHANGE)
  10477. /// status id:
  10478. /// SP_POW ~ SP_CON
  10479. /// amount:
  10480. /// The amount to increase the trait status
  10481. void clif_parse_traitstatus_up( int32 fd, map_session_data *sd ){
  10482. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10483. const PACKET_CZ_ADVANCED_STATUS_CHANGE* p = reinterpret_cast<PACKET_CZ_ADVANCED_STATUS_CHANGE*>( RFIFOP( fd, 0 ) );
  10484. if( p->amount < 0 ){
  10485. 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 );
  10486. return;
  10487. }
  10488. pc_traitstatusup( sd, p->type, p->amount );
  10489. #endif
  10490. }
  10491. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10492. /// 0112 <skill id>.W
  10493. void clif_parse_SkillUp(int32 fd,map_session_data *sd)
  10494. {
  10495. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10496. }
  10497. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int32 target_id)
  10498. {
  10499. int32 lv;
  10500. if( !hd )
  10501. return;
  10502. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10503. clif_emotion( hd->bl, ET_THINK );
  10504. return;
  10505. }
  10506. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10507. target_id = hd->bl.id;
  10508. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10509. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10510. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10511. clif_emotion( hd->bl, ET_THINK );
  10512. if (hd->master)
  10513. clif_skill_fail( *hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10514. return;
  10515. }
  10516. lv = hom_checkskill(hd, skill_id);
  10517. if( skill_lv > lv )
  10518. skill_lv = lv;
  10519. if( skill_lv )
  10520. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10521. }
  10522. static void clif_parse_UseSkillToPos_homun(struct homun_data *hd, map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int16 x, int16 y, int32 skillmoreinfo)
  10523. {
  10524. int32 lv;
  10525. if( !hd )
  10526. return;
  10527. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10528. clif_emotion( hd->bl, ET_THINK );
  10529. return;
  10530. }
  10531. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10532. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10533. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10534. clif_emotion( hd->bl, ET_THINK );
  10535. if (hd->master)
  10536. clif_skill_fail( *hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10537. return;
  10538. }
  10539. #ifdef RENEWAL
  10540. if (hd->sc.getSCE(SC_BASILICA_CELL))
  10541. #else
  10542. if (hd->sc.getSCE(SC_BASILICA))
  10543. #endif
  10544. return;
  10545. lv = hom_checkskill(hd, skill_id);
  10546. if( skill_lv > lv )
  10547. skill_lv = lv;
  10548. if( skill_lv )
  10549. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10550. }
  10551. static void clif_parse_UseSkillToId_mercenary(s_mercenary_data *md, map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int32 target_id)
  10552. {
  10553. int32 lv;
  10554. if( !md )
  10555. return;
  10556. if( skill_isNotOk_mercenary(skill_id, *md) )
  10557. return;
  10558. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10559. target_id = md->bl.id;
  10560. if( md->ud.skilltimer != INVALID_TIMER )
  10561. {
  10562. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10563. }
  10564. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10565. return;
  10566. lv = mercenary_checkskill(md, skill_id);
  10567. if( skill_lv > lv )
  10568. skill_lv = lv;
  10569. if( skill_lv )
  10570. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10571. }
  10572. static void clif_parse_UseSkillToPos_mercenary(s_mercenary_data *md, map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int16 x, int16 y, int32 skillmoreinfo)
  10573. {
  10574. int32 lv;
  10575. if( !md )
  10576. return;
  10577. if( skill_isNotOk_mercenary(skill_id, *md) )
  10578. return;
  10579. if( md->ud.skilltimer != INVALID_TIMER )
  10580. return;
  10581. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10582. {
  10583. if (md->master)
  10584. clif_skill_fail( *md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10585. return;
  10586. }
  10587. #ifdef RENEWAL
  10588. if (md->sc.getSCE(SC_BASILICA_CELL))
  10589. #else
  10590. if (md->sc.getSCE(SC_BASILICA))
  10591. #endif
  10592. return;
  10593. lv = mercenary_checkskill(md, skill_id);
  10594. if( skill_lv > lv )
  10595. skill_lv = lv;
  10596. if( skill_lv )
  10597. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10598. }
  10599. void clif_parse_skill_toid( map_session_data* sd, uint16 skill_id, uint16 skill_lv, int32 target_id ){
  10600. if( sd == nullptr ){
  10601. return;
  10602. }
  10603. t_tick tick = gettick();
  10604. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10605. int32 inf = skill_get_inf(skill_id);
  10606. if (inf&INF_GROUND_SKILL || !inf)
  10607. return; //Using a ground/passive skill on a target? WRONG.
  10608. if (sd->state.block_action & PCBLOCK_SKILL) {
  10609. clif_msg(sd, MSI_BUSY);
  10610. return;
  10611. }
  10612. if( SKILL_CHK_HOMUN(skill_id) ) {
  10613. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10614. return;
  10615. }
  10616. if( SKILL_CHK_MERC(skill_id) ) {
  10617. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10618. return;
  10619. }
  10620. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10621. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10622. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10623. sd->idletime = last_tick;
  10624. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10625. sd->idletime_hom = last_tick;
  10626. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10627. sd->idletime_mer = last_tick;
  10628. if( sd->npc_id ){
  10629. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10630. #ifdef RENEWAL
  10631. clif_msg( sd, MSI_BUSY);
  10632. #endif
  10633. return;
  10634. }
  10635. }
  10636. if ((pc_cant_act2(sd) || sd->chatID) &&
  10637. skill_id != RK_REFRESH &&
  10638. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10639. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10640. return;
  10641. if( pc_issit(sd) )
  10642. return;
  10643. if( skill_isNotOk(skill_id, *sd) )
  10644. return;
  10645. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10646. target_id = sd->bl.id; // never trust the client
  10647. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10648. target_id = sd->bl.id;
  10649. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10650. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10651. return;
  10652. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10653. if( sd->skillitem != skill_id ) {
  10654. clif_skill_fail( *sd, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10655. return;
  10656. }
  10657. }
  10658. if( sd->sc.option&OPTION_COSTUME )
  10659. return;
  10660. #ifndef RENEWAL
  10661. if( sd->sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd->sc.getSCE(SC_BASILICA)->val4 != sd->bl.id) )
  10662. return; // On basilica only caster can use Basilica again to stop it.
  10663. #endif
  10664. if( sd->menuskill_id ) {
  10665. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10666. clif_menuskill_clear(sd); //Cancel pet capture.
  10667. }else if( sd->menuskill_id == SG_FEEL ){
  10668. clif_menuskill_clear( sd ); // Cancel selection
  10669. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10670. return; //Can't use skills while a menu is open.
  10671. }
  10672. if( sd->skillitem == skill_id ) {
  10673. if( skill_lv != sd->skillitemlv )
  10674. skill_lv = sd->skillitemlv;
  10675. if( !(inf&INF_SELF_SKILL) )
  10676. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10677. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10678. return;
  10679. }
  10680. sd->skillitem = sd->skillitemlv = 0;
  10681. if( SKILL_CHK_GUILD(skill_id) ) {
  10682. if (sd->guild != nullptr && (sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING))
  10683. skill_lv = guild_checkskill(sd->guild->guild, skill_id);
  10684. else
  10685. skill_lv = 0;
  10686. } else {
  10687. if( skill_id != ALL_EQSWITCH ){
  10688. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10689. }
  10690. }
  10691. pc_delinvincibletimer(sd);
  10692. if( skill_lv )
  10693. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10694. }
  10695. /// Request to use a targeted skill.
  10696. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10697. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10698. /// There are various variants of this packet, some of them have padding between fields.
  10699. void clif_parse_UseSkillToId( int32 fd, map_session_data *sd ){
  10700. // TODO: shuffle packet
  10701. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10702. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10703. }
  10704. /*==========================================
  10705. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10706. *------------------------------------------*/
  10707. static void clif_parse_UseSkillToPosSub( int32 fd, map_session_data& sd, uint16 skill_lv, uint16 skill_id, int16 x, int16 y, int32 skillmoreinfo ){
  10708. t_tick tick = gettick();
  10709. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10710. return; //Using a target skill on the ground? WRONG.
  10711. if (sd.state.block_action & PCBLOCK_SKILL) {
  10712. clif_msg(&sd, MSI_BUSY);
  10713. return;
  10714. }
  10715. if( SKILL_CHK_HOMUN(skill_id) ) {
  10716. clif_parse_UseSkillToPos_homun(sd.hd, &sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10717. return;
  10718. }
  10719. if( SKILL_CHK_MERC(skill_id) ) {
  10720. clif_parse_UseSkillToPos_mercenary(sd.md, &sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10721. return;
  10722. }
  10723. if( pc_hasprogress( &sd, WIP_DISABLE_SKILLITEM ) ){
  10724. #ifdef RENEWAL
  10725. clif_msg( &sd, MSI_BUSY);
  10726. #endif
  10727. return;
  10728. }
  10729. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10730. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10731. sd.idletime = last_tick;
  10732. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10733. sd.idletime_hom = last_tick;
  10734. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10735. sd.idletime_mer = last_tick;
  10736. if( skill_isNotOk(skill_id, sd) )
  10737. return;
  10738. if( skillmoreinfo != -1 ) {
  10739. if( pc_issit(&sd) ) {
  10740. clif_skill_fail( sd, skill_id );
  10741. return;
  10742. }
  10743. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10744. safestrncpy(sd.message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10745. }
  10746. if( sd.ud.skilltimer != INVALID_TIMER )
  10747. return;
  10748. if( DIFF_TICK(tick, sd.ud.canact_tick) < 0 ) {
  10749. if( sd.skillitem != skill_id ) {
  10750. clif_skill_fail( sd, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10751. return;
  10752. }
  10753. }
  10754. if( sd.sc.option&OPTION_COSTUME )
  10755. return;
  10756. #ifndef RENEWAL
  10757. if( sd.sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd.sc.getSCE(SC_BASILICA)->val4 != sd.bl.id) )
  10758. return; // On basilica only caster can use Basilica again to stop it.
  10759. #endif
  10760. if( sd.menuskill_id ) {
  10761. if( sd.menuskill_id == SA_TAMINGMONSTER ) {
  10762. clif_menuskill_clear(&sd); //Cancel pet capture.
  10763. }else if( sd.menuskill_id == SG_FEEL ){
  10764. clif_menuskill_clear( &sd ); // Cancel selection
  10765. } else if( sd.menuskill_id != SA_AUTOSPELL )
  10766. return; //Can't use skills while a menu is open.
  10767. }
  10768. pc_delinvincibletimer(&sd);
  10769. if( sd.skillitem == skill_id ) {
  10770. if( skill_lv != sd.skillitemlv )
  10771. skill_lv = sd.skillitemlv;
  10772. unit_skilluse_pos(&sd.bl, x, y, skill_id, skill_lv);
  10773. } else {
  10774. int32 lv;
  10775. sd.skillitem = sd.skillitemlv = 0;
  10776. if( (lv = pc_checkskill(&sd, skill_id)) > 0 ) {
  10777. if( skill_lv > lv )
  10778. skill_lv = lv;
  10779. unit_skilluse_pos(&sd.bl, x, y, skill_id,skill_lv);
  10780. }
  10781. }
  10782. }
  10783. /// Request to use a ground skill.
  10784. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10785. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10786. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10787. /// There are various variants of this packet, some of them have padding between fields.
  10788. void clif_parse_UseSkillToPos(int32 fd, map_session_data *sd)
  10789. {
  10790. if( sd == nullptr ){
  10791. return;
  10792. }
  10793. // TODO: shuffle packet
  10794. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10795. if (pc_cant_act(sd))
  10796. return;
  10797. if (pc_issit(sd))
  10798. return;
  10799. clif_parse_UseSkillToPosSub(fd, *sd,
  10800. RFIFOW(fd,info->pos[0]), //skill lv
  10801. RFIFOW(fd,info->pos[1]), //skill num
  10802. RFIFOW(fd,info->pos[2]), //pos x
  10803. RFIFOW(fd,info->pos[3]), //pos y
  10804. // TODO: find out what this is intended to do
  10805. //RFIFOB(fd, info->pos[4])
  10806. -1 //Skill more info.
  10807. );
  10808. }
  10809. /// Request to use a ground skill with text.
  10810. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10811. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10812. /// There are various variants of this packet, some of them have padding between fields.
  10813. void clif_parse_UseSkillToPosMoreInfo(int32 fd, map_session_data *sd)
  10814. {
  10815. if( sd == nullptr ){
  10816. return;
  10817. }
  10818. // TODO: shuffle packet
  10819. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10820. if (pc_cant_act(sd))
  10821. return;
  10822. if (pc_issit(sd))
  10823. return;
  10824. clif_parse_UseSkillToPosSub(fd, *sd,
  10825. RFIFOW(fd,info->pos[0]), //Skill lv
  10826. RFIFOW(fd,info->pos[1]), //Skill num
  10827. RFIFOW(fd,info->pos[2]), //pos x
  10828. RFIFOW(fd,info->pos[3]), //pos y
  10829. info->pos[4] //skill more info
  10830. );
  10831. }
  10832. /// Answer to map selection dialog.
  10833. /// 011b <skill id>.W <map name>.16B (CZ_SELECT_WARPPOINT)
  10834. void clif_parse_UseSkillMap(int32 fd, map_session_data* sd)
  10835. {
  10836. if( sd == nullptr ){
  10837. return;
  10838. }
  10839. sd->state.workinprogress = WIP_DISABLE_NONE;
  10840. const PACKET_CZ_SELECT_WARPPOINT* p = reinterpret_cast<PACKET_CZ_SELECT_WARPPOINT*>( RFIFOP( fd, 0 ) );
  10841. if( p->skill_id != sd->menuskill_id ){
  10842. return;
  10843. }
  10844. //It is possible to use teleport with the storage window open bugreport:8027
  10845. if( pc_cant_act( sd ) && !sd->state.storage_flag && p->skill_id != AL_TELEPORT ){
  10846. clif_menuskill_clear(sd);
  10847. return;
  10848. }
  10849. pc_delinvincibletimer(sd);
  10850. char map_name[MAP_NAME_LENGTH];
  10851. mapindex_getmapname( p->mapname, map_name );
  10852. skill_castend_map( sd, p->skill_id, map_name );
  10853. }
  10854. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10855. /// 011d
  10856. void clif_parse_RequestMemo(int32 fd,map_session_data *sd)
  10857. {
  10858. if (!pc_isdead(sd))
  10859. pc_memo(sd,-1);
  10860. }
  10861. /// Answer to pharmacy item selection dialog.
  10862. /// 018e <name id>.W { <material id>.W }*3 (CZ_REQMAKINGITEM)
  10863. void clif_parse_ProduceMix(int32 fd,map_session_data *sd){
  10864. if( sd == nullptr ){
  10865. return;
  10866. }
  10867. const PACKET_CZ_REQMAKINGITEM* p = reinterpret_cast<PACKET_CZ_REQMAKINGITEM*>( RFIFOP( fd, 0 ) );
  10868. switch( sd->menuskill_id ) {
  10869. case -1:
  10870. case AM_PHARMACY:
  10871. case RK_RUNEMASTERY:
  10872. case GC_RESEARCHNEWPOISON:
  10873. break;
  10874. default:
  10875. return;
  10876. }
  10877. if (pc_istrading(sd)) {
  10878. //Make it fail to avoid shop exploits where you sell something different than you see.
  10879. clif_skill_fail( *sd, sd->ud.skill_id );
  10880. clif_menuskill_clear(sd);
  10881. return;
  10882. }
  10883. int32 produce_idx;
  10884. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  10885. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  10886. clif_menuskill_clear(sd);
  10887. }
  10888. /// Answer to mixing item selection dialog.
  10889. /// 025b <mk type>.W <name id>.W (CZ_REQ_MAKINGITEM)
  10890. /// mk type:
  10891. /// 1 = cooking
  10892. /// 2 = arrow
  10893. /// 3 = elemental
  10894. /// 4 = GN_MIX_COOKING
  10895. /// 5 = GN_MAKEBOMB
  10896. /// 6 = GN_S_PHARMACY
  10897. /// 7 = MT_M_MACHINE - Unconfirmed
  10898. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  10899. void clif_parse_Cooking(int32 fd,map_session_data *sd) {
  10900. #if PACKETVER >= 20051010
  10901. if( sd == nullptr ){
  10902. return;
  10903. }
  10904. const PACKET_CZ_REQ_MAKINGITEM* p = reinterpret_cast<PACKET_CZ_REQ_MAKINGITEM*>( RFIFOP( fd, 0 ) );
  10905. int32 amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10906. int16 food_idx = -1;
  10907. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10908. return;
  10909. if (pc_istrading(sd)) {
  10910. //Make it fail to avoid shop exploits where you sell something different than you see.
  10911. clif_skill_fail( *sd, sd->ud.skill_id );
  10912. clif_menuskill_clear(sd);
  10913. return;
  10914. }
  10915. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  10916. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  10917. clif_menuskill_clear(sd);
  10918. #endif
  10919. }
  10920. /// Answer to repair weapon item selection dialog
  10921. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10922. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10923. void clif_parse_RepairItem( int32 fd, map_session_data *sd ){
  10924. if( sd == nullptr ){
  10925. return;
  10926. }
  10927. // Hercules has wrong date -> use correct one here
  10928. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10929. const PACKET_CZ_REQ_ITEMREPAIR2* p = reinterpret_cast<PACKET_CZ_REQ_ITEMREPAIR2*>( RFIFOP( fd, 0 ) );
  10930. #else
  10931. const PACKET_CZ_REQ_ITEMREPAIR1* p = reinterpret_cast<PACKET_CZ_REQ_ITEMREPAIR1*>( RFIFOP( fd, 0 ) );
  10932. #endif
  10933. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10934. return;
  10935. if (pc_istrading(sd)) {
  10936. //Make it fail to avoid shop exploits where you sell something different than you see.
  10937. clif_skill_fail( *sd, sd->ud.skill_id );
  10938. clif_menuskill_clear(sd);
  10939. return;
  10940. }
  10941. skill_repairweapon( *sd, p->item.index );
  10942. clif_menuskill_clear(sd);
  10943. }
  10944. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10945. /// 0222 <index>.L
  10946. void clif_parse_WeaponRefine( int32 fd, map_session_data *sd ){
  10947. if( sd == nullptr ){
  10948. return;
  10949. }
  10950. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10951. return;
  10952. if (pc_istrading(sd)) {
  10953. //Make it fail to avoid shop exploits where you sell something different than you see.
  10954. clif_skill_fail( *sd, sd->ud.skill_id );
  10955. clif_menuskill_clear(sd);
  10956. return;
  10957. }
  10958. skill_weaponrefine( *sd, server_index( RFIFOL( fd, 2 ) ) );
  10959. clif_menuskill_clear(sd);
  10960. }
  10961. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10962. /// 00b8 <npc id>.L <choice>.B
  10963. /// choice:
  10964. /// 1~254 = menu item
  10965. /// 255 = cancel
  10966. /// NOTE: If there were more than 254 items in the list, choice
  10967. /// overflows to choice%256.
  10968. void clif_parse_NpcSelectMenu(int32 fd,map_session_data *sd){
  10969. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10970. int32 npc_id = RFIFOL(fd,info->pos[0]);
  10971. uint8 select = RFIFOB(fd,info->pos[1]);
  10972. #ifdef SECURE_NPCTIMEOUT
  10973. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  10974. return;
  10975. #endif
  10976. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10977. TBL_NPC* nd = map_id2nd(npc_id);
  10978. 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);
  10979. clif_GM_kick(nullptr,sd);
  10980. return;
  10981. }
  10982. sd->npc_menu = select;
  10983. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  10984. sd->idletime = last_tick;
  10985. }
  10986. npc_scriptcont(sd,npc_id, false);
  10987. }
  10988. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10989. /// 00b9 <npc id>.L
  10990. void clif_parse_NpcNextClicked(int32 fd,map_session_data *sd)
  10991. {
  10992. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  10993. sd->idletime = last_tick;
  10994. }
  10995. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10996. }
  10997. /// NPC numeric input dialog value.
  10998. /// 0143 <npc id>.L <value>.L (CZ_INPUT_EDITDLG)
  10999. void clif_parse_NpcAmountInput(int32 fd,map_session_data *sd){
  11000. if( sd == nullptr ){
  11001. return;
  11002. }
  11003. const PACKET_CZ_INPUT_EDITDLG* p = reinterpret_cast<PACKET_CZ_INPUT_EDITDLG*>( RFIFOP( fd, 0 ) );
  11004. sd->npc_amount = p->value;
  11005. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11006. sd->idletime = last_tick;
  11007. }
  11008. npc_scriptcont( sd, p->GID, false );
  11009. }
  11010. /// NPC text input dialog value.
  11011. /// 01d5 <packet len>.W <npc id>.L <string>.?B (CZ_INPUT_EDITDLGSTR)
  11012. void clif_parse_NpcStringInput(int32 fd, map_session_data* sd){
  11013. if( sd == nullptr ){
  11014. return;
  11015. }
  11016. const PACKET_CZ_INPUT_EDITDLGSTR* p = reinterpret_cast<PACKET_CZ_INPUT_EDITDLGSTR*>( RFIFOP( fd, 0 ) );
  11017. size_t message_len = p->packetSize - sizeof( *p );
  11018. if( message_len <= 0 )
  11019. return; // invalid input
  11020. #if PACKETVER >= 20151001
  11021. message_len++;
  11022. #endif
  11023. safestrncpy( sd->npc_str, p->value, std::min<size_t>( message_len, CHATBOX_SIZE ) );
  11024. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11025. sd->idletime = last_tick;
  11026. }
  11027. npc_scriptcont( sd, p->GID, false );
  11028. }
  11029. /// NPC dialog 'close' click.
  11030. /// 0146 <npc id>.L (CZ_CLOSE_DIALOG)
  11031. void clif_parse_NpcCloseClicked(int32 fd,map_session_data *sd)
  11032. {
  11033. if( sd == nullptr ){
  11034. return;
  11035. }
  11036. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11037. return;
  11038. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11039. sd->idletime = last_tick;
  11040. }
  11041. const PACKET_CZ_CLOSE_DIALOG* p = reinterpret_cast<PACKET_CZ_CLOSE_DIALOG*>( RFIFOP( fd, 0 ) );
  11042. npc_scriptcont( sd, p->GID, true );
  11043. }
  11044. /// Answer to identify item selection dialog.
  11045. /// 0178 <index>.W (CZ_REQ_ITEMIDENTIFY)
  11046. /// index:
  11047. /// -1 = cancel
  11048. void clif_parse_ItemIdentify(int32 fd,map_session_data *sd) {
  11049. if (sd->menuskill_id != MC_IDENTIFY)
  11050. return;
  11051. const PACKET_CZ_REQ_ITEMIDENTIFY* p = reinterpret_cast<PACKET_CZ_REQ_ITEMIDENTIFY*>( RFIFOP( fd, 0 ) );
  11052. uint16 idx = server_index( p->index );
  11053. // Ignore the request
  11054. // - Invalid item index
  11055. // - Invalid item ID or item doesn't exist
  11056. // - Item is already identified
  11057. if ( idx >= MAX_INVENTORY ||
  11058. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == nullptr ||
  11059. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11060. sd->state.workinprogress = WIP_DISABLE_NONE;
  11061. clif_menuskill_clear(sd);
  11062. return;
  11063. }
  11064. skill_identify(sd, idx);
  11065. clif_menuskill_clear(sd);
  11066. }
  11067. /// Answer to arrow crafting item selection dialog.
  11068. /// 01ae <name id>.W (CZ_REQ_MAKINGARROW)
  11069. void clif_parse_SelectArrow(int32 fd,map_session_data *sd) {
  11070. if( sd == nullptr ){
  11071. return;
  11072. }
  11073. if (pc_istrading(sd)) {
  11074. //Make it fail to avoid shop exploits where you sell something different than you see.
  11075. clif_skill_fail( *sd, sd->ud.skill_id );
  11076. clif_menuskill_clear(sd);
  11077. return;
  11078. }
  11079. const PACKET_CZ_REQ_MAKINGARROW* p = reinterpret_cast<PACKET_CZ_REQ_MAKINGARROW*>( RFIFOP( fd, 0 ) );
  11080. switch (sd->menuskill_id) {
  11081. case AC_MAKINGARROW:
  11082. skill_arrow_create(sd,p->itemId);
  11083. break;
  11084. case SA_CREATECON:
  11085. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11086. break;
  11087. case GC_POISONINGWEAPON:
  11088. skill_poisoningweapon(*sd,p->itemId);
  11089. break;
  11090. case NC_MAGICDECOY:
  11091. skill_magicdecoy(*sd,p->itemId);
  11092. break;
  11093. }
  11094. clif_menuskill_clear(sd);
  11095. }
  11096. /// Answer to SA_AUTOSPELL skill selection dialog.
  11097. /// 01ce <skill id>.L (CZ_SELECTAUTOSPELL)
  11098. void clif_parse_AutoSpell(int32 fd,map_session_data *sd)
  11099. {
  11100. if (sd->menuskill_id != SA_AUTOSPELL)
  11101. return;
  11102. sd->state.workinprogress = WIP_DISABLE_NONE;
  11103. const PACKET_CZ_SELECTAUTOSPELL* p = reinterpret_cast<PACKET_CZ_SELECTAUTOSPELL*>( RFIFOP( fd, 0 ) );
  11104. skill_autospell( sd, static_cast<uint16>( p->skill_id ) );
  11105. clif_menuskill_clear(sd);
  11106. }
  11107. /// Request to display item carding/composition list.
  11108. /// 017a <card index>.W (CZ_REQ_ITEMCOMPOSITION_LIST)
  11109. void clif_parse_UseCard(int32 fd,map_session_data *sd)
  11110. {
  11111. if (sd->state.trading != 0)
  11112. return;
  11113. const PACKET_CZ_REQ_ITEMCOMPOSITION_LIST* p = reinterpret_cast<PACKET_CZ_REQ_ITEMCOMPOSITION_LIST*>( RFIFOP( fd, 0 ) );
  11114. uint16 idx = server_index( p->index );
  11115. if( idx >= MAX_INVENTORY ){
  11116. return;
  11117. }
  11118. clif_use_card( sd, idx );
  11119. }
  11120. /// Answer to carding/composing item selection dialog.
  11121. /// 017c <card index>.W <equip index>.W (CZ_REQ_ITEMCOMPOSITION)
  11122. void clif_parse_InsertCard(int32 fd,map_session_data *sd)
  11123. {
  11124. if( sd == nullptr ){
  11125. return;
  11126. }
  11127. if (sd->state.trading != 0)
  11128. return;
  11129. const PACKET_CZ_REQ_ITEMCOMPOSITION* p = reinterpret_cast<PACKET_CZ_REQ_ITEMCOMPOSITION*>( RFIFOP( fd, 0 ) );
  11130. uint16 card_idx = server_index( p->index_card );
  11131. uint16 equip_idx = server_index( p->index_equip );
  11132. if( card_idx >= MAX_INVENTORY ){
  11133. return;
  11134. }
  11135. if( equip_idx >= MAX_INVENTORY ){
  11136. return;
  11137. }
  11138. pc_insert_card( sd, card_idx, equip_idx );
  11139. }
  11140. /// Request of character's name by char ID.
  11141. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11142. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11143. /// There are various variants of this packet, some of them have padding between fields.
  11144. void clif_parse_SolveCharName(int32 fd, map_session_data *sd)
  11145. {
  11146. int32 charid;
  11147. // TODO: shuffle packet
  11148. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11149. map_reqnickdb(sd, charid);
  11150. }
  11151. /// /resetskill /resetstate.
  11152. /// Request to reset stats or skills.
  11153. /// 0197 <type>.W (CZ_RESET)
  11154. /// type:
  11155. /// 0 = state
  11156. /// 1 = skill
  11157. void clif_parse_ResetChar(int32 fd, map_session_data *sd) {
  11158. if( sd == nullptr ){
  11159. return;
  11160. }
  11161. const PACKET_CZ_RESET* p = reinterpret_cast<PACKET_CZ_RESET*>( RFIFOP( fd, 0 ) );
  11162. char cmd[CHAT_SIZE_MAX];
  11163. switch( p->type ){
  11164. case 0:
  11165. safesnprintf( cmd, sizeof( cmd ), "%cresetstat", atcommand_symbol );
  11166. break;
  11167. #if !(PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220203)
  11168. case 1:
  11169. safesnprintf( cmd, sizeof(cmd), "%cresetskill", atcommand_symbol );
  11170. break;
  11171. #endif
  11172. default:
  11173. return;
  11174. }
  11175. is_atcommand(fd, sd, cmd, 1);
  11176. }
  11177. /// /lb /nlb.
  11178. /// Request to broadcast a message on current map.
  11179. /// 019c <packet len>.W <text>.?B (CZ_LOCALBROADCAST)
  11180. void clif_parse_LocalBroadcast(int32 fd, map_session_data* sd)
  11181. {
  11182. if( sd == nullptr ){
  11183. return;
  11184. }
  11185. const PACKET_CZ_LOCALBROADCAST* p = reinterpret_cast<PACKET_CZ_LOCALBROADCAST*>( RFIFOP( fd, 0 ) );
  11186. size_t len = p->packetSize - sizeof( *p );
  11187. char msg[CHAT_SIZE_MAX];
  11188. safestrncpy( msg, p->message, std::min<size_t>( len, sizeof( msg ) ) );
  11189. char command[CHAT_SIZE_MAX];
  11190. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11191. is_atcommand(fd, sd, command, 1);
  11192. }
  11193. /// Request to move an item from inventory to storage.
  11194. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11195. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11196. /// There are various variants of this packet, some of them have padding between fields.
  11197. void clif_parse_MoveToKafra(int32 fd, map_session_data *sd)
  11198. {
  11199. int32 item_index, item_amount;
  11200. // TODO: shuffle packet
  11201. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11202. if (pc_istrading(sd))
  11203. return;
  11204. item_index = RFIFOW(fd,info->pos[0])-2;
  11205. item_amount = RFIFOL(fd,info->pos[1]);
  11206. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11207. return;
  11208. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11209. clif_msg( sd, MSI_SWAP_EQUIPITEM_UNREGISTER_FIRST );
  11210. return;
  11211. }
  11212. if (sd->state.storage_flag == 1)
  11213. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11214. else
  11215. if (sd->state.storage_flag == 2)
  11216. storage_guild_storageadd(sd, item_index, item_amount);
  11217. else if (sd->state.storage_flag == 3)
  11218. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11219. }
  11220. /// Request to move an item from storage to inventory.
  11221. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11222. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11223. /// There are various variants of this packet, some of them have padding between fields.
  11224. void clif_parse_MoveFromKafra(int32 fd,map_session_data *sd)
  11225. {
  11226. int32 item_index, item_amount;
  11227. // TODO: shuffle packet
  11228. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11229. item_index = RFIFOW(fd,info->pos[0])-1;
  11230. item_amount = RFIFOL(fd,info->pos[1]);
  11231. if (sd->state.storage_flag == 1)
  11232. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11233. else if(sd->state.storage_flag == 2)
  11234. storage_guild_storageget(sd, item_index, item_amount);
  11235. else if(sd->state.storage_flag == 3)
  11236. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11237. }
  11238. /// Request to move an item from cart to storage.
  11239. /// 0129 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_CART_TO_STORE)
  11240. void clif_parse_MoveToKafraFromCart(int32 fd, map_session_data *sd){
  11241. if( sd == nullptr ){
  11242. return;
  11243. }
  11244. if( sd->state.vending )
  11245. return;
  11246. if (!pc_iscarton(sd))
  11247. return;
  11248. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11249. return;
  11250. const PACKET_CZ_MOVE_ITEM_FROM_CART_TO_STORE* p = reinterpret_cast<PACKET_CZ_MOVE_ITEM_FROM_CART_TO_STORE*>( RFIFOP( fd, 0 ) );
  11251. uint16 idx = server_index( p->index );
  11252. if (sd->state.storage_flag == 1)
  11253. storage_storageaddfromcart( sd, &sd->storage, idx, p->amount );
  11254. else if (sd->state.storage_flag == 2)
  11255. storage_guild_storageaddfromcart( sd, idx, p->amount );
  11256. else if (sd->state.storage_flag == 3)
  11257. storage_storageaddfromcart( sd, &sd->premiumStorage, idx, p->amount );
  11258. }
  11259. /// Request to move an item from storage to cart.
  11260. /// 0128 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_CART)
  11261. void clif_parse_MoveFromKafraToCart(int32 fd, map_session_data *sd){
  11262. if( sd == nullptr ){
  11263. return;
  11264. }
  11265. if( sd->state.vending )
  11266. return;
  11267. if (!pc_iscarton(sd))
  11268. return;
  11269. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11270. return;
  11271. const PACKET_CZ_MOVE_ITEM_FROM_STORE_TO_CART* p = reinterpret_cast<PACKET_CZ_MOVE_ITEM_FROM_STORE_TO_CART*>( RFIFOP( fd, 0 ) );
  11272. uint16 idx = server_storage_index( p->index );
  11273. if (sd->state.storage_flag == 1)
  11274. storage_storagegettocart( sd, &sd->storage, idx, p->amount );
  11275. else
  11276. if (sd->state.storage_flag == 2)
  11277. storage_guild_storagegettocart( sd, idx, p->amount );
  11278. else if (sd->state.storage_flag == 3)
  11279. storage_storagegettocart( sd, &sd->premiumStorage, idx, p->amount );
  11280. }
  11281. /// Request to close storage (CZ_CLOSE_STORE).
  11282. /// 00f7
  11283. void clif_parse_CloseKafra(int32 fd, map_session_data *sd)
  11284. {
  11285. if( sd->state.storage_flag == 1 )
  11286. storage_storageclose(sd);
  11287. else
  11288. if( sd->state.storage_flag == 2 )
  11289. storage_guild_storageclose(sd);
  11290. else if( sd->state.storage_flag == 3 )
  11291. storage_premiumStorage_close(sd);
  11292. }
  11293. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11294. /// 023a <info>.W
  11295. /// info:
  11296. /// 0 = password has not been set yet
  11297. /// 1 = storage is password-protected
  11298. /// 8 = too many wrong passwords
  11299. /// ? = ignored
  11300. /// NOTE: This packet is only available on certain non-kRO clients.
  11301. void clif_storagepassword(map_session_data* sd, int16 info)
  11302. {
  11303. int32 fd = sd->fd;
  11304. WFIFOHEAD(fd,packet_len(0x23a));
  11305. WFIFOW(fd,0) = 0x23a;
  11306. WFIFOW(fd,2) = info;
  11307. WFIFOSET(fd,packet_len(0x23a));
  11308. }
  11309. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11310. /// 023b <type>.W <password>.16B <new password>.16B
  11311. /// type:
  11312. /// 2 = change password
  11313. /// 3 = check password
  11314. /// NOTE: This packet is only available on certain non-kRO clients.
  11315. void clif_parse_StoragePassword(int32 fd, map_session_data *sd){ //@TODO
  11316. // TODO: shuffle packet
  11317. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11318. // int32 type = RFIFOW(fd,info->pos[0]);
  11319. // char* password = RFIFOP(fd,info->pos[1]);
  11320. // char* new_password = RFIFOP(fd,info->pos[2]);
  11321. // storage_changepass(sd,password,new_password);
  11322. }
  11323. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11324. /// 023c <result>.W <error count>.W
  11325. /// result:
  11326. /// 4 = password change success
  11327. /// 5 = password change failure
  11328. /// 6 = password check success
  11329. /// 7 = password check failure
  11330. /// 8 = too many wrong passwords
  11331. /// ? = ignored
  11332. /// NOTE: This packet is only available on certain non-kRO clients.
  11333. void clif_storagepassword_result(map_session_data* sd, int16 result, int16 error_count)
  11334. {
  11335. int32 fd = sd->fd;
  11336. WFIFOHEAD(fd,packet_len(0x23c));
  11337. WFIFOW(fd,0) = 0x23c;
  11338. WFIFOW(fd,2) = result;
  11339. WFIFOW(fd,4) = error_count;
  11340. WFIFOSET(fd,packet_len(0x23c));
  11341. }
  11342. /// Party creation request
  11343. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11344. void clif_parse_CreateParty(int32 fd, map_session_data *sd){
  11345. if( sd == nullptr ){
  11346. return;
  11347. }
  11348. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11349. clif_displaymessage(fd, msg_txt(sd,227));
  11350. return;
  11351. }
  11352. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11353. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 4 );
  11354. return;
  11355. }
  11356. const PACKET_CZ_MAKE_GROUP* p = reinterpret_cast<PACKET_CZ_MAKE_GROUP*>( RFIFOP( fd, 0 ) );
  11357. char name[NAME_LENGTH];
  11358. safestrncpy( name, p->name, sizeof( name ) );
  11359. party_create( *sd, name, 0, 0 );
  11360. }
  11361. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11362. void clif_parse_CreateParty2(int32 fd, map_session_data *sd){
  11363. if( sd == nullptr ){
  11364. return;
  11365. }
  11366. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11367. clif_displaymessage(fd, msg_txt(sd,227));
  11368. return;
  11369. }
  11370. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11371. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 4 );
  11372. return;
  11373. }
  11374. const PACKET_CZ_MAKE_GROUP2* p = reinterpret_cast<PACKET_CZ_MAKE_GROUP2*>( RFIFOP( fd, 0 ) );
  11375. char name[NAME_LENGTH];
  11376. safestrncpy( name, p->name, sizeof( name ) );
  11377. party_create( *sd, name, p->item_pickup, p->item_share );
  11378. }
  11379. /// Party invitation request by account id
  11380. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11381. void clif_parse_PartyInvite( int32 fd, map_session_data *sd ){
  11382. if( sd == nullptr ){
  11383. return;
  11384. }
  11385. const PACKET_CZ_REQ_JOIN_GROUP* p = reinterpret_cast<PACKET_CZ_REQ_JOIN_GROUP*>( RFIFOP( fd, 0 ) );
  11386. party_invite( *sd, map_id2sd( p->AID ) );
  11387. }
  11388. /// Party invitation request by name
  11389. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11390. void clif_parse_PartyInvite2( int32 fd, map_session_data *sd ){
  11391. #if PACKETVER >= 20070227
  11392. if( sd == nullptr ){
  11393. return;
  11394. }
  11395. const PACKET_CZ_PARTY_JOIN_REQ* p = reinterpret_cast<PACKET_CZ_PARTY_JOIN_REQ*>( RFIFOP( fd, 0 ) );
  11396. char name[NAME_LENGTH];
  11397. safestrncpy( name, p->name, sizeof( name ) );
  11398. party_invite( *sd, map_nick2sd( name, false ) );
  11399. #endif
  11400. }
  11401. /// Party invitation reply
  11402. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11403. /// flag:
  11404. /// 0 = reject
  11405. /// 1 = accept
  11406. void clif_parse_ReplyPartyInvite( int32 fd, map_session_data *sd ){
  11407. if( sd == nullptr ){
  11408. return;
  11409. }
  11410. const PACKET_CZ_JOIN_GROUP* p = reinterpret_cast<PACKET_CZ_JOIN_GROUP*>( RFIFOP( fd, 0 ) );
  11411. party_reply_invite( *sd, p->party_id, p->flag );
  11412. }
  11413. /// Party invitation reply
  11414. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11415. /// flag:
  11416. /// 0 = reject
  11417. /// 1 = accept
  11418. void clif_parse_ReplyPartyInvite2( int32 fd, map_session_data *sd ){
  11419. #if PACKETVER >= 20070227
  11420. if( sd == nullptr ){
  11421. return;
  11422. }
  11423. const PACKET_CZ_PARTY_JOIN_REQ_ACK* p = reinterpret_cast<PACKET_CZ_PARTY_JOIN_REQ_ACK*>( RFIFOP( fd, 0 ) );
  11424. party_reply_invite( *sd, p->party_id, p->flag );
  11425. #endif
  11426. }
  11427. /// Request to leave party.
  11428. /// 0100 (CZ_REQ_LEAVE_GROUP)
  11429. void clif_parse_LeaveParty( int32 fd, map_session_data *sd ){
  11430. if( sd == nullptr ){
  11431. return;
  11432. }
  11433. //const PACKET_CZ_REQ_LEAVE_GROUP* p = reinterpret_cast<PACKET_CZ_REQ_LEAVE_GROUP*>( RFIFOP( fd, 0 ) );
  11434. party_leave( *sd, true );
  11435. }
  11436. /// Request to expel a party member.
  11437. /// 0103 <account id>.L <char name>.24B (CZ_REQ_EXPEL_GROUP_MEMBER)
  11438. void clif_parse_RemovePartyMember( int32 fd, map_session_data* sd ){
  11439. if( sd == nullptr ){
  11440. return;
  11441. }
  11442. const PACKET_CZ_REQ_EXPEL_GROUP_MEMBER* p = reinterpret_cast<PACKET_CZ_REQ_EXPEL_GROUP_MEMBER*>( RFIFOP( fd, 0 ) );
  11443. party_removemember( *sd, p->AID, p->name );
  11444. }
  11445. /// Request to change party options.
  11446. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11447. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11448. void clif_parse_PartyChangeOption(int32 fd, map_session_data *sd)
  11449. {
  11450. struct party_data *p;
  11451. int32 i,expflag;
  11452. int32 cmd = RFIFOW(fd,0);
  11453. struct s_packet_db* info = &packet_db[cmd];
  11454. if( !sd->status.party_id )
  11455. return;
  11456. p = party_search(sd->status.party_id);
  11457. if( p == nullptr )
  11458. return;
  11459. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11460. if( i == MAX_PARTY )
  11461. return; //Shouldn't happen
  11462. if( !p->party.member[i].leader )
  11463. return;
  11464. expflag = RFIFOL(fd,info->pos[0]);
  11465. if(cmd == 0x0102){ //Client can't change the item-field
  11466. party_changeoption(sd, expflag, p->party.item);
  11467. }
  11468. else {
  11469. int32 itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11470. party_changeoption(sd, expflag, itemflag);
  11471. }
  11472. }
  11473. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11474. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11475. void clif_parse_PartyMessage(int32 fd, map_session_data* sd){
  11476. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11477. // validate packet and retrieve name and message
  11478. if( !clif_process_message( sd, false, name, message, output ) )
  11479. return;
  11480. party_send_message(sd, output, strlen(output) + 1 );
  11481. }
  11482. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11483. /// 07da <account id>.L
  11484. void clif_parse_PartyChangeLeader(int32 fd, map_session_data* sd){
  11485. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),nullptr);
  11486. }
  11487. /// Party Booking in KRO [Spiria]
  11488. ///
  11489. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11490. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11491. void clif_parse_PartyBookingRegisterReq(int32 fd, map_session_data* sd){
  11492. // TODO: shuffle packet
  11493. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11494. int16 level = RFIFOW(fd,info->pos[0]);
  11495. int16 mapid = RFIFOW(fd,info->pos[1]);
  11496. int32 idxpbj = info->pos[2];
  11497. int16 job[MAX_PARTY_BOOKING_JOBS];
  11498. int32 i;
  11499. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11500. job[i] = RFIFOB(fd,idxpbj+i*2);
  11501. party_booking_register(sd, level, mapid, job);
  11502. }
  11503. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11504. /// 0803 <result>.W
  11505. /// result:
  11506. /// 0 = success
  11507. /// 1 = failure
  11508. /// 2 = already registered
  11509. void clif_PartyBookingRegisterAck(map_session_data *sd, int32 flag)
  11510. {
  11511. int32 fd = sd->fd;
  11512. WFIFOHEAD(fd,packet_len(0x803));
  11513. WFIFOW(fd,0) = 0x803;
  11514. WFIFOW(fd,2) = flag;
  11515. WFIFOSET(fd,packet_len(0x803));
  11516. }
  11517. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11518. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11519. void clif_parse_PartyBookingSearchReq(int32 fd, map_session_data* sd){
  11520. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11521. int16 level = RFIFOW(fd,info->pos[0]);
  11522. int16 mapid = RFIFOW(fd,info->pos[1]);
  11523. int16 job = RFIFOW(fd,info->pos[2]);
  11524. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11525. int16 resultcount = RFIFOW(fd,info->pos[4]);
  11526. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11527. }
  11528. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11529. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11530. /// more results:
  11531. /// 0 = no
  11532. /// 1 = yes
  11533. void clif_PartyBookingSearchAck(int32 fd, struct party_booking_ad_info** results, int32 count, bool more_result)
  11534. {
  11535. int32 i, j;
  11536. int32 size = sizeof(struct party_booking_ad_info); // structure size (48)
  11537. struct party_booking_ad_info *pb_ad;
  11538. WFIFOHEAD(fd,size*count + 5);
  11539. WFIFOW(fd,0) = 0x805;
  11540. WFIFOW(fd,2) = size*count + 5;
  11541. WFIFOB(fd,4) = more_result;
  11542. for(i=0; i<count; i++)
  11543. {
  11544. pb_ad = results[i];
  11545. WFIFOL(fd,i*size+5) = pb_ad->index;
  11546. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11547. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11548. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11549. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11550. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11551. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11552. }
  11553. WFIFOSET(fd,WFIFOW(fd,2));
  11554. }
  11555. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11556. /// 0806
  11557. void clif_parse_PartyBookingDeleteReq(int32 fd, map_session_data* sd)
  11558. {
  11559. if(party_booking_delete(sd))
  11560. clif_PartyBookingDeleteAck(sd, 0);
  11561. }
  11562. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11563. /// 0807 <result>.W
  11564. /// result:
  11565. /// 0 = success
  11566. /// 1 = success (auto-removed expired ad)
  11567. /// 2 = failure
  11568. /// 3 = nothing registered
  11569. void clif_PartyBookingDeleteAck(map_session_data* sd, int32 flag)
  11570. {
  11571. int32 fd = sd->fd;
  11572. WFIFOHEAD(fd,packet_len(0x807));
  11573. WFIFOW(fd,0) = 0x807;
  11574. WFIFOW(fd,2) = flag;
  11575. WFIFOSET(fd,packet_len(0x807));
  11576. }
  11577. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11578. /// 0808 { <job>.W }*6
  11579. void clif_parse_PartyBookingUpdateReq(int32 fd, map_session_data* sd)
  11580. {
  11581. int16 job[MAX_PARTY_BOOKING_JOBS];
  11582. int32 i;
  11583. int32 idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11584. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11585. job[i] = RFIFOW(fd,idxpbu+i*2);
  11586. party_booking_update(sd, job);
  11587. }
  11588. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11589. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11590. void clif_PartyBookingInsertNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11591. {
  11592. int32 i;
  11593. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11594. if(pb_ad == nullptr) return;
  11595. WBUFW(buf,0) = 0x809;
  11596. WBUFL(buf,2) = pb_ad->index;
  11597. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11598. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11599. WBUFW(buf,34) = pb_ad->p_detail.level;
  11600. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11601. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11602. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11603. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11604. }
  11605. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11606. /// 080a <index>.L { <job>.W }*6
  11607. void clif_PartyBookingUpdateNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11608. {
  11609. int32 i;
  11610. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11611. if(pb_ad == nullptr) return;
  11612. WBUFW(buf,0) = 0x80a;
  11613. WBUFL(buf,2) = pb_ad->index;
  11614. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11615. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11616. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11617. }
  11618. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11619. /// 080b <index>.L
  11620. void clif_PartyBookingDeleteNotify(map_session_data* sd, int32 index)
  11621. {
  11622. uint8 buf[6];
  11623. WBUFW(buf,0) = 0x80b;
  11624. WBUFL(buf,2) = index;
  11625. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11626. }
  11627. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11628. /// 012e
  11629. void clif_parse_CloseVending(int32 fd, map_session_data* sd)
  11630. {
  11631. vending_closevending(sd);
  11632. }
  11633. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11634. /// 0130 <account id>.L
  11635. void clif_parse_VendingListReq(int32 fd, map_session_data* sd)
  11636. {
  11637. if( sd->npc_id ) {// using an NPC
  11638. return;
  11639. }
  11640. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11641. }
  11642. /// Shop item(s) purchase request.
  11643. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }* (CZ_PC_PURCHASE_ITEMLIST_FROMMC)
  11644. void clif_parse_PurchaseReq(int32 fd, map_session_data* sd){
  11645. const PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC* p = reinterpret_cast<PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC*>( RFIFOP( fd, 0 ) );
  11646. vending_purchasereq( sd, p->AID, sd->vended_id, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] ) );
  11647. // whether it fails or not, the buy window is closed
  11648. sd->vended_id = 0;
  11649. }
  11650. /// Shop item(s) purchase request.
  11651. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }* (CZ_PC_PURCHASE_ITEMLIST_FROMMC2)
  11652. void clif_parse_PurchaseReq2(int32 fd, map_session_data* sd){
  11653. #if PACKETVER >= 20100105
  11654. const PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2* p = reinterpret_cast<PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2*>( RFIFOP( fd, 0 ) );
  11655. vending_purchasereq( sd, p->AID, p->UniqueID, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] ) );
  11656. // whether it fails or not, the buy window is closed
  11657. sd->vended_id = 0;
  11658. #endif
  11659. }
  11660. /// Confirm or cancel the shop preparation window.
  11661. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11662. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11663. /// result:
  11664. /// 0 = canceled
  11665. /// 1 = open
  11666. void clif_parse_OpenVending(int32 fd, map_session_data* sd){
  11667. if( sd == nullptr ){
  11668. return;
  11669. }
  11670. int32 cmd = RFIFOW(fd,0);
  11671. struct s_packet_db* info = &packet_db[cmd];
  11672. int16 len = (int16)RFIFOW(fd,info->pos[0]);
  11673. const char* message = RFIFOCP(fd,info->pos[1]);
  11674. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11675. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11676. len -= 84;
  11677. }
  11678. else { //(CZ_REQ_OPENSTORE2)
  11679. bool flag;
  11680. len -= 85;
  11681. flag = RFIFOB(fd,info->pos[2]) != 0;
  11682. if (!flag) {
  11683. sd->state.prevend = 0;
  11684. sd->state.workinprogress = WIP_DISABLE_NONE;
  11685. }
  11686. }
  11687. if( sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM )
  11688. return;
  11689. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11690. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11691. return;
  11692. }
  11693. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11694. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11695. return;
  11696. }
  11697. if( message[0] == '\0' ) // invalid input
  11698. return;
  11699. vending_openvending(*sd, message, data, len/8, nullptr);
  11700. }
  11701. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11702. /// 0165 <char id>.L <guild name>.24B
  11703. void clif_parse_CreateGuild(int32 fd,map_session_data *sd){
  11704. //int32 charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11705. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11706. name[NAME_LENGTH-1] = '\0';
  11707. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11708. clif_displaymessage(fd, msg_txt(sd,228));
  11709. return;
  11710. }
  11711. if(sd->clan){
  11712. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11713. return;
  11714. }
  11715. guild_create( *sd, name );
  11716. }
  11717. /// Request for guild window interface permissions
  11718. /// 014d (CZ_REQ_GUILD_MENUINTERFACE)
  11719. static void clif_parse_GuildCheckMaster(int32 fd, map_session_data *sd){
  11720. if(sd == nullptr)
  11721. return;
  11722. clif_guild_masterormember(*sd);
  11723. }
  11724. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11725. /// 014f <type>.L
  11726. /// type:
  11727. /// 0 = basic info
  11728. /// 1 = member manager
  11729. /// 2 = positions
  11730. /// 3 = skills
  11731. /// 4 = expulsion list
  11732. /// 5 = unknown (GM_ALLGUILDLIST)
  11733. /// 6 = notice
  11734. void clif_parse_GuildRequestInfo(int32 fd, map_session_data *sd)
  11735. {
  11736. int32 type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11737. if( !sd->status.guild_id && !sd->bg_id )
  11738. return;
  11739. switch( type )
  11740. {
  11741. case 0: // Basic Information Guild, hostile alliance information
  11742. clif_guild_basicinfo( *sd );
  11743. clif_guild_allianceinfo(*sd);
  11744. clif_guild_castle_list(*sd);
  11745. break;
  11746. case 1: // Members list, list job title
  11747. clif_guild_positionnamelist(sd);
  11748. clif_guild_memberlist( *sd );
  11749. break;
  11750. case 2: // List job title, title information list
  11751. clif_guild_positionnamelist(sd);
  11752. clif_guild_positioninfolist(*sd);
  11753. break;
  11754. case 3: // Skill list
  11755. clif_guild_skillinfo( *sd );
  11756. break;
  11757. case 4: // Expulsion list
  11758. clif_guild_expulsionlist(*sd);
  11759. break;
  11760. default:
  11761. ShowError("clif: guild request info: unknown type %d\n", type);
  11762. break;
  11763. }
  11764. }
  11765. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11766. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11767. void clif_parse_GuildChangePositionInfo(int32 fd, map_session_data *sd)
  11768. {
  11769. int32 i;
  11770. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11771. int32 len = RFIFOW(fd,info->pos[0]);
  11772. int32 idxgpos = info->pos[1];
  11773. if(!sd->state.gmaster_flag)
  11774. return;
  11775. for(i = idxgpos; i < len; i += 40 ){
  11776. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11777. }
  11778. }
  11779. /// Request to update the position of guild members.
  11780. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }* (CZ_REQ_CHANGE_MEMBERPOS)
  11781. void clif_parse_GuildChangeMemberPosition( int32 fd, map_session_data *sd ){
  11782. if(!sd->state.gmaster_flag)
  11783. return;
  11784. const PACKET_CZ_REQ_CHANGE_MEMBERPOS* p = reinterpret_cast<PACKET_CZ_REQ_CHANGE_MEMBERPOS*>( RFIFOP( fd, 0 ) );
  11785. int16 entries = ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] );
  11786. for( int16 i = 0; i < entries; i++ ){
  11787. const PACKET_CZ_REQ_CHANGE_MEMBERPOS_sub& entry = p->list[i];
  11788. // Guild leadership change
  11789. if( entry.position == 0 ){
  11790. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11791. clif_msg( sd, MSI_IMPOSSIBLE_CHANGE_GUILD_MASTER_IN_SIEGE_TIME );
  11792. return;
  11793. }
  11794. if( battle_config.guild_leaderchange_delay && DIFF_TICK( time( nullptr ),sd->guild->guild.last_leader_change ) < battle_config.guild_leaderchange_delay ){
  11795. clif_msg( sd, MSI_IMPOSSIBLE_CHANGE_GUILD_MASTER_NOT_TIME );
  11796. return;
  11797. }
  11798. guild_gm_change( sd->status.guild_id, entry.CID );
  11799. // No further entries will be processed - the requesting player lost his guild master status
  11800. return;
  11801. }else if( entry.position > 0 ){
  11802. guild_change_memberposition( sd->status.guild_id, entry.AID, entry.CID, entry.position );
  11803. }
  11804. }
  11805. }
  11806. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11807. /// 0151 <guild id>.L
  11808. void clif_parse_GuildRequestEmblem(int32 fd,map_session_data *sd)
  11809. {
  11810. int32 guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11811. auto g = guild_search(guild_id);
  11812. if (g)
  11813. clif_guild_emblem(*sd, g->guild);
  11814. }
  11815. /// Validates data of a guild emblem (compressed bitmap)
  11816. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11817. EMBVALIDATE_SUCCESS = 0,
  11818. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11819. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of inter_config.emblem_transparency_limit
  11820. };
  11821. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11822. {
  11823. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11824. unsigned long buf_len = sizeof(buf);
  11825. int32 offset = 0;
  11826. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11827. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11828. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11829. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11830. ))
  11831. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11832. if(inter_config.emblem_transparency_limit != 100) {
  11833. int32 i, transcount = 1, tmp[3];
  11834. for(i = offset; i < buf_len-1; i++) {
  11835. int32 j = i%3;
  11836. tmp[j] = RBUFL(buf,i);
  11837. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11838. transcount++;
  11839. }
  11840. if(((transcount*300)/(buf_len-offset)) > inter_config.emblem_transparency_limit) //convert in % to chk
  11841. return EMBVALIDATE_ERR_TRANSPARENCY;
  11842. }
  11843. return EMBVALIDATE_SUCCESS;
  11844. }
  11845. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11846. /// 0153 <packet len>.W <emblem data>.?B
  11847. void clif_parse_GuildChangeEmblem(int32 fd,map_session_data *sd){
  11848. if( sd == nullptr ){
  11849. return;
  11850. }
  11851. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11852. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11853. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11854. int32 emb_val=0;
  11855. if( !emblem_len || !sd->state.gmaster_flag )
  11856. return;
  11857. if(!(inter_config.emblem_woe_change) && is_agit_start() ){
  11858. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11859. return;
  11860. }
  11861. emb_val = clif_validate_emblem(emblem, emblem_len);
  11862. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11863. 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);
  11864. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11865. return;
  11866. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11867. char output[128];
  11868. safesnprintf(output,sizeof(output),msg_txt(sd,387),inter_config.emblem_transparency_limit);
  11869. 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"
  11870. return;
  11871. }
  11872. guild_change_emblem( *sd, emblem_len, (const char*)emblem );
  11873. }
  11874. /// Request to update the guild emblem id
  11875. /// 0b46 <guild id>.L <version>.L
  11876. void clif_parse_GuildChangeEmblem2(int32 fd, map_session_data* sd) {
  11877. if( sd == nullptr ){
  11878. return;
  11879. }
  11880. #if PACKETVER >= 20190724
  11881. const PACKET_CZ_REQ_ADD_NEW_EMBLEM* p = reinterpret_cast<PACKET_CZ_REQ_ADD_NEW_EMBLEM*>( RFIFOP( fd, 0 ) );
  11882. auto &g = sd->guild;
  11883. if (!g || g->guild.guild_id != p->guild_id)
  11884. return;
  11885. if (!sd->state.gmaster_flag)
  11886. return;
  11887. if (!inter_config.emblem_woe_change && is_agit_start()) {
  11888. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  11889. return;
  11890. }
  11891. guild_change_emblem_version( *sd, p->version );
  11892. #endif
  11893. }
  11894. /// Guild notice update request (CZ_GUILD_NOTICE).
  11895. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11896. void clif_parse_GuildChangeNotice(int32 fd, map_session_data* sd){
  11897. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11898. int32 guild_id = RFIFOL(fd,info->pos[0]);
  11899. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11900. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11901. if(!sd->state.gmaster_flag)
  11902. return;
  11903. // compensate for some client defects when using multilanguage mode
  11904. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11905. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11906. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11907. guild_change_notice(sd, guild_id, msg1, msg2);
  11908. }
  11909. /// Guild invite request.
  11910. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L (CZ_REQ_JOIN_GUILD)
  11911. void clif_parse_GuildInvite( int32 fd,map_session_data *sd ){
  11912. if( sd == nullptr ){
  11913. return;
  11914. }
  11915. const PACKET_CZ_REQ_JOIN_GUILD* p = reinterpret_cast<PACKET_CZ_REQ_JOIN_GUILD*>( RFIFOP( fd, 0 ) );
  11916. guild_invite( *sd, map_id2sd( p->AID ) );
  11917. }
  11918. /// Guild invite request (/guildinvite)
  11919. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11920. void clif_parse_GuildInvite2( int32 fd, map_session_data *sd ){
  11921. #if PACKETVER >= 20120410
  11922. if( sd == nullptr ){
  11923. return;
  11924. }
  11925. const PACKET_CZ_REQ_JOIN_GUILD2* p = reinterpret_cast<PACKET_CZ_REQ_JOIN_GUILD2*>( RFIFOP( fd, 0 ) );
  11926. char nick[NAME_LENGTH] = {0};
  11927. safestrncpy( nick, p->name, NAME_LENGTH );
  11928. guild_invite( *sd, map_nick2sd( nick, false ) );
  11929. #endif
  11930. }
  11931. /// Answer to guild invitation.
  11932. /// 016b <guild id>.L <answer>.L (CZ_JOIN_GUILD)
  11933. /// answer:
  11934. /// 0 = refuse
  11935. /// 1 = accept
  11936. void clif_parse_GuildReplyInvite( int32 fd, map_session_data *sd ){
  11937. if( sd == nullptr ){
  11938. return;
  11939. }
  11940. const PACKET_CZ_JOIN_GUILD* p = reinterpret_cast<PACKET_CZ_JOIN_GUILD*>( RFIFOP( fd, 0 ) );
  11941. guild_reply_invite( *sd, p->guild_id, p->answer );
  11942. }
  11943. /// Request to leave guild.
  11944. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B (CZ_REQ_LEAVE_GUILD)
  11945. void clif_parse_GuildLeave(int32 fd,map_session_data *sd){
  11946. if( sd == nullptr ){
  11947. return;
  11948. }
  11949. const PACKET_CZ_REQ_LEAVE_GUILD* p = reinterpret_cast<PACKET_CZ_REQ_LEAVE_GUILD*>( RFIFOP( fd, 0 ) );
  11950. guild_leave( *sd, p->guild_id, p->AID, p->CID, p->message );
  11951. }
  11952. /// Request to expel a member of a guild.
  11953. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B (CZ_REQ_BAN_GUILD)
  11954. void clif_parse_GuildExpulsion(int32 fd,map_session_data *sd){
  11955. if( sd == nullptr ){
  11956. return;
  11957. }
  11958. const PACKET_CZ_REQ_BAN_GUILD* p = reinterpret_cast<PACKET_CZ_REQ_BAN_GUILD*>( RFIFOP( fd, 0 ) );
  11959. guild_expulsion( *sd, p->guild_id, p->AID, p->CID, p->message );
  11960. }
  11961. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11962. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11963. void clif_parse_GuildMessage(int32 fd, map_session_data* sd){
  11964. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11965. // validate packet and retrieve name and message
  11966. if( !clif_process_message( sd, false, name, message, output ) )
  11967. return;
  11968. if( sd->bg_id )
  11969. bg_send_message(sd, output, strlen(output) );
  11970. else
  11971. guild_send_message(sd, output, strlen(output) );
  11972. }
  11973. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11974. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11975. void clif_parse_GuildRequestAlliance(int32 fd, map_session_data *sd)
  11976. {
  11977. map_session_data *t_sd;
  11978. if(!sd->state.gmaster_flag)
  11979. return;
  11980. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11981. clif_displaymessage(fd, msg_txt(sd,228));
  11982. return;
  11983. }
  11984. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11985. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11986. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11987. // @noask [LuzZza]
  11988. if(t_sd && t_sd->state.noask) {
  11989. clif_noask_sub( *sd, *t_sd, 396 ); // Autorejected alliance request from %s.
  11990. return;
  11991. }
  11992. guild_reqalliance(sd,t_sd);
  11993. }
  11994. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11995. /// 0172 <inviter account id>.L <answer>.L
  11996. /// answer:
  11997. /// 0 = refuse
  11998. /// 1 = accept
  11999. void clif_parse_GuildReplyAlliance(int32 fd, map_session_data *sd){
  12000. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12001. guild_reply_reqalliance(sd,
  12002. RFIFOL(fd,info->pos[0]),
  12003. RFIFOL(fd,info->pos[1]));
  12004. }
  12005. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12006. /// 0183 <opponent guild id>.L <relation>.L
  12007. /// relation:
  12008. /// 0 = Ally
  12009. /// 1 = Enemy
  12010. void clif_parse_GuildDelAlliance(int32 fd, map_session_data *sd){
  12011. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12012. if(!sd->state.gmaster_flag)
  12013. return;
  12014. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12015. clif_displaymessage(fd, msg_txt(sd,228));
  12016. return;
  12017. }
  12018. guild_delalliance(sd,
  12019. RFIFOL(fd,info->pos[0]),
  12020. RFIFOL(fd,info->pos[1]));
  12021. }
  12022. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12023. /// 0180 <account id>.L
  12024. void clif_parse_GuildOpposition(int32 fd, map_session_data *sd)
  12025. {
  12026. map_session_data *t_sd;
  12027. if(!sd->state.gmaster_flag)
  12028. return;
  12029. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12030. clif_displaymessage(fd, msg_txt(sd,228));
  12031. return;
  12032. }
  12033. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12034. // @noask [LuzZza]
  12035. if(t_sd && t_sd->state.noask) {
  12036. clif_noask_sub( *sd, *t_sd, 397 ); // Autorejected opposition request from %s.
  12037. return;
  12038. }
  12039. guild_opposition(sd,t_sd);
  12040. }
  12041. /// Request to delete own guild.
  12042. /// 015d <key>.40B (CZ_REQ_DISORGANIZE_GUILD)
  12043. /// key:
  12044. /// now guild name; might have been (intended) email, since the
  12045. /// field name and size is same as the one in CH_DELETE_CHAR.
  12046. void clif_parse_GuildBreak( int32 fd, map_session_data *sd ){
  12047. if( sd == nullptr ){
  12048. return;
  12049. }
  12050. const PACKET_CZ_REQ_DISORGANIZE_GUILD* p = reinterpret_cast<PACKET_CZ_REQ_DISORGANIZE_GUILD*>( RFIFOP( fd, 0 ) );
  12051. guild_break( *sd, p->key );
  12052. }
  12053. /// Pet
  12054. ///
  12055. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12056. /// 01a1 <type>.B
  12057. /// type:
  12058. /// 0 = pet information
  12059. /// 1 = feed
  12060. /// 2 = performance
  12061. /// 3 = return to egg
  12062. /// 4 = unequip accessory
  12063. void clif_parse_PetMenu(int32 fd, map_session_data *sd){
  12064. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12065. }
  12066. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12067. /// 019f <id>.L
  12068. void clif_parse_CatchPet(int32 fd, map_session_data *sd){
  12069. pet_catch_process_end(*sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12070. }
  12071. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12072. /// 01a7 <index>.W
  12073. void clif_parse_SelectEgg(int32 fd, map_session_data *sd){
  12074. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12075. return;
  12076. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12077. clif_menuskill_clear(sd);
  12078. }
  12079. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12080. /// 01a9 <data>.L
  12081. /// data:
  12082. /// is either emotion (@see enum emotion_type) or a compound value
  12083. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12084. /// entry (given in parentheses) in data\pettalktable.xml
  12085. /// act id:
  12086. /// 0 = feeding
  12087. /// 1 = hunting
  12088. /// 2 = danger
  12089. /// 3 = dead
  12090. /// 4 = normal (stand)
  12091. /// 5 = special performance (perfor_s)
  12092. /// 6 = level up (levelup)
  12093. /// 7 = performance 1 (perfor_1)
  12094. /// 8 = performance 2 (perfor_2)
  12095. /// 9 = performance 3 (perfor_3)
  12096. /// 10 = log-in greeting (connect)
  12097. /// hungry value:
  12098. /// 0 = very hungry (hungry)
  12099. /// 1 = hungry (bit_hungry)
  12100. /// 2 = satisfied (noting)
  12101. /// 3 = stuffed (full)
  12102. /// 4 = full (so_full)
  12103. void clif_parse_SendEmotion(int32 fd, map_session_data *sd)
  12104. {
  12105. if(sd->pd)
  12106. clif_pet_emotion( *sd->pd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]) );
  12107. }
  12108. /// Request to change pet's name (CZ_RENAME_PET).
  12109. /// 01a5 <name>.24B
  12110. void clif_parse_ChangePetName(int32 fd, map_session_data *sd)
  12111. {
  12112. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12113. }
  12114. /// /kill (CZ_DISCONNECT_CHARACTER).
  12115. /// Request to disconnect a character.
  12116. /// 00cc <account id>.L
  12117. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12118. void clif_parse_GMKick(int32 fd, map_session_data *sd)
  12119. {
  12120. struct block_list *target;
  12121. int32 tid;
  12122. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12123. target = map_id2bl(tid);
  12124. if (!target) {
  12125. clif_GM_kickack(sd, 0);
  12126. return;
  12127. }
  12128. switch (target->type) {
  12129. case BL_PC:
  12130. {
  12131. char command[NAME_LENGTH+6];
  12132. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(*target));
  12133. is_atcommand(fd, sd, command, 1);
  12134. }
  12135. break;
  12136. /**
  12137. * This one does not invoke any atcommand, so we need to check for permissions.
  12138. */
  12139. case BL_MOB:
  12140. {
  12141. char command[100];
  12142. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12143. clif_GM_kickack(sd, 0);
  12144. return;
  12145. }
  12146. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(*target), status_get_class(target));
  12147. log_atcommand(sd, command);
  12148. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12149. }
  12150. break;
  12151. case BL_NPC:
  12152. {
  12153. struct npc_data* nd = (struct npc_data *)target;
  12154. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12155. npc_unload_duplicates(nd);
  12156. npc_unload(nd,true);
  12157. npc_read_event_script();
  12158. }
  12159. }
  12160. break;
  12161. default:
  12162. clif_GM_kickack(sd, 0);
  12163. }
  12164. }
  12165. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12166. /// Request to disconnect all characters.
  12167. /// 00ce
  12168. void clif_parse_GMKickAll(int32 fd, map_session_data* sd) {
  12169. char cmd[15];
  12170. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12171. is_atcommand(fd, sd, cmd, 1);
  12172. }
  12173. /// /remove (CZ_REMOVE_AID).
  12174. /// Request to warp to a character with given login ID.
  12175. /// 01ba <account name>.24B
  12176. /// /shift (CZ_SHIFT).
  12177. /// Request to warp to a character with given name.
  12178. /// 01bb <char name>.24B
  12179. void clif_parse_GMShift(int32 fd, map_session_data *sd)
  12180. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12181. char *player_name;
  12182. char command[NAME_LENGTH+8];
  12183. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12184. player_name[NAME_LENGTH-1] = '\0';
  12185. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12186. is_atcommand(fd, sd, command, 1);
  12187. }
  12188. /// /remove (CZ_REMOVE_AID_SSO).
  12189. /// Request to warp to a character with given account ID.
  12190. /// 0843 <account id>.L
  12191. void clif_parse_GMRemove2(int32 fd, map_session_data* sd)
  12192. {
  12193. uint32 account_id;
  12194. map_session_data* pl_sd;
  12195. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12196. if( (pl_sd = map_id2sd(account_id)) != nullptr ) {
  12197. char command[NAME_LENGTH+8];
  12198. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12199. is_atcommand(fd, sd, command, 1);
  12200. }
  12201. }
  12202. /// /recall (CZ_RECALL).
  12203. /// Request to summon a player with given login ID to own position.
  12204. /// 01bc <account name>.24B
  12205. /// /summon (CZ_RECALL_GID).
  12206. /// Request to summon a player with given name to own position.
  12207. /// 01bd <char name>.24B
  12208. void clif_parse_GMRecall(int32 fd, map_session_data *sd)
  12209. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12210. char *player_name;
  12211. char command [NAME_LENGTH+8];
  12212. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12213. player_name[NAME_LENGTH-1] = '\0';
  12214. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12215. is_atcommand(fd, sd, command, 1);
  12216. }
  12217. /// /recall (CZ_RECALL_SSO).
  12218. /// Request to summon a player with given account ID to own position.
  12219. /// 0842 <account id>.L
  12220. void clif_parse_GMRecall2(int32 fd, map_session_data* sd)
  12221. {
  12222. uint32 account_id;
  12223. map_session_data* pl_sd;
  12224. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12225. if( (pl_sd = map_id2sd(account_id)) != nullptr ) {
  12226. char command[NAME_LENGTH+8];
  12227. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12228. is_atcommand(fd, sd, command, 1);
  12229. }
  12230. }
  12231. /// /item /monster (CZ_ITEM_CREATE).
  12232. /// Request to execute GM commands.
  12233. /// Usage:
  12234. /// /item n - summon n monster or acquire n item/s
  12235. /// /item money - grants 2147483647 zenies
  12236. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12237. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12238. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12239. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12240. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12241. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12242. /// 013f <item/mob name>.24B
  12243. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12244. void clif_parse_GM_Item_Monster(int32 fd, map_session_data *sd)
  12245. {
  12246. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12247. StringBuf command;
  12248. char *str;
  12249. //#if PACKETVER >= 20131218
  12250. // char str[100];
  12251. //#else
  12252. // char str[24];
  12253. //#endif
  12254. str = RFIFOCP(fd,info->pos[0]);
  12255. if (!str || str[0] == '\0')
  12256. return;
  12257. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12258. return;
  12259. trim(str);
  12260. // Zeny
  12261. if( strcmpi(str, "money") == 0 ) {
  12262. StringBuf_Init(&command);
  12263. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12264. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12265. StringBuf_Destroy(&command);
  12266. return;
  12267. }
  12268. std::shared_ptr<item_data> id = item_db.searchname( str );
  12269. // Item
  12270. if( id ){
  12271. StringBuf_Init(&command);
  12272. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12273. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12274. }else{
  12275. if (id->flag.guid)
  12276. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12277. else
  12278. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12279. }
  12280. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12281. StringBuf_Destroy(&command);
  12282. return;
  12283. }
  12284. // Monster
  12285. if (pc_can_use_command(sd, "monster", COMMAND_ATCOMMAND)) {
  12286. // If AegisName matches exactly, summon that monster (official behavior)
  12287. std::shared_ptr<s_mob_db> mob = mobdb_search_aegisname(str);
  12288. // Otherwise, search for monster with that ID or name (rAthena added behavior)
  12289. if (mob == nullptr) {
  12290. // Check for ID first as this is faster; if search string is not a number it will return 0
  12291. int32 mob_id = util::strtoint32def(str);
  12292. if (mob_id == 0 || mobdb_checkid(mob_id) == 0) {
  12293. mob_id = mobdb_searchname(str);
  12294. if (mob_id != 0) {
  12295. mob = mob_db.find(mob_id);
  12296. }
  12297. }
  12298. else
  12299. mob = mob_db.find(mob_id);
  12300. }
  12301. // Call corresponding atcommand when a valid monster was found
  12302. if (mob != nullptr) {
  12303. char command[CHAT_SIZE_MAX];
  12304. safesnprintf(command, sizeof(command), "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12305. is_atcommand(fd, sd, command, 1);
  12306. return;
  12307. }
  12308. }
  12309. }
  12310. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12311. /// 019d <effect state>.L
  12312. /// effect state:
  12313. /// TODO: Any OPTION_* ?
  12314. void clif_parse_GMHide(int32 fd, map_session_data *sd) {
  12315. char cmd[6];
  12316. //int32 eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12317. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12318. is_atcommand(fd, sd, cmd, 1);
  12319. }
  12320. /// /resetcooltime
  12321. /// 0a88 (CZ_CMD_RESETCOOLTIME).
  12322. void clif_parse_gm_resetcooltime( int32 fd, map_session_data* sd ){
  12323. #if PACKETVER_MAIN_NUM >= 20160622 || PACKETVER_RE_NUM >= 20160622 || defined(PACKETVER_ZERO)
  12324. const PACKET_CZ_CMD_RESETCOOLTIME* p = reinterpret_cast<const PACKET_CZ_CMD_RESETCOOLTIME*>( RFIFOP( fd, 0 ) );
  12325. char cmd[CHAT_SIZE_MAX];
  12326. safesnprintf(cmd,sizeof(cmd),"%cresetcooltime",atcommand_symbol);
  12327. is_atcommand(fd, sd, cmd, 1);
  12328. #endif
  12329. }
  12330. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12331. /// 0149 <account id>.L <type>.B <value>.W
  12332. /// type:
  12333. /// 0 = positive points
  12334. /// 1 = negative points
  12335. /// 2 = self mute (+10 minutes)
  12336. void clif_parse_GMReqNoChat(int32 fd,map_session_data *sd)
  12337. {
  12338. int32 id, type, value;
  12339. map_session_data *dstsd;
  12340. char command[NAME_LENGTH+15];
  12341. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12342. id = RFIFOL(fd,info->pos[0]);
  12343. type = RFIFOB(fd,info->pos[1]);
  12344. value = RFIFOW(fd,info->pos[2]);
  12345. if( type == 0 )
  12346. value = -value;
  12347. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12348. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12349. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12350. return;
  12351. dstsd = map_id2sd(id);
  12352. if( dstsd == nullptr )
  12353. return;
  12354. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12355. is_atcommand(fd, sd, command, 1);
  12356. }
  12357. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12358. /// GM adjustment of a player's manner value by -60.
  12359. /// 0212 <char name>.24B
  12360. void clif_parse_GMRc(int32 fd, map_session_data* sd)
  12361. {
  12362. char command[NAME_LENGTH+15];
  12363. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12364. name[NAME_LENGTH-1] = '\0';
  12365. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12366. is_atcommand(fd, sd, command, 1);
  12367. }
  12368. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12369. /// 01e0 <account id>.L <account name>.24B
  12370. void clif_account_name(int32 fd, uint32 account_id, const char* accname)
  12371. {
  12372. WFIFOHEAD(fd,packet_len(0x1e0));
  12373. WFIFOW(fd,0) = 0x1e0;
  12374. WFIFOL(fd,2) = account_id;
  12375. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12376. WFIFOSET(fd,packet_len(0x1e0));
  12377. }
  12378. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12379. /// 01df <account id>.L
  12380. //! TODO: Figure out how does this actually work
  12381. void clif_parse_GMReqAccountName(int32 fd, map_session_data *sd)
  12382. {
  12383. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12384. /*
  12385. char query[30];
  12386. safesnprintf(query,sizeof(query),"%d", account_id);
  12387. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12388. */
  12389. clif_account_name(fd, account_id, "");
  12390. }
  12391. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12392. /// GM single cell type change request.
  12393. /// 0198 <x>.W <y>.W <type>.W
  12394. /// type:
  12395. /// 0 = not walkable
  12396. /// 1 = walkable
  12397. void clif_parse_GMChangeMapType(int32 fd, map_session_data *sd)
  12398. {
  12399. int32 x,y,type;
  12400. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12401. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12402. return;
  12403. x = RFIFOW(fd,info->pos[0]);
  12404. y = RFIFOW(fd,info->pos[1]);
  12405. type = RFIFOW(fd,info->pos[2]);
  12406. map_setgatcell(sd->bl.m,x,y,type);
  12407. clif_changemapcell( sd->bl.m, x, y, type, ALL_SAMEMAP, &sd->bl );
  12408. //FIXME: once players leave the map, the client 'forgets' this information.
  12409. }
  12410. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12411. /// Request to allow/deny whispers from a nick.
  12412. /// 00cf <nick>.24B <type>.B
  12413. /// type:
  12414. /// 0 = (/ex nick) deny speech from nick
  12415. /// 1 = (/in nick) allow speech from nick
  12416. void clif_parse_PMIgnore(int32 fd, map_session_data* sd)
  12417. {
  12418. char* nick;
  12419. uint8 type;
  12420. int32 i;
  12421. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12422. nick = RFIFOCP(fd,info->pos[0]);
  12423. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12424. type = RFIFOB(fd,info->pos[1]);
  12425. if( type == 0 ) { // Add name to ignore list (block)
  12426. if (strcmp(wisp_server_name, nick) == 0) {
  12427. clif_wisexin(sd, type, 1); // fail
  12428. return;
  12429. }
  12430. // try to find a free spot, while checking for duplicates at the same time
  12431. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12432. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12433. clif_wisexin(sd, type, 2); // too many blocks
  12434. return;
  12435. }
  12436. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12437. clif_wisexin(sd, type, 0); // Aegis reports success.
  12438. return;
  12439. }
  12440. //Insert in position i
  12441. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12442. } else { // Remove name from ignore list (unblock)
  12443. // find entry
  12444. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12445. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[0] == '\0' ) { //Not found
  12446. clif_wisexin(sd, type, 1); // fail
  12447. return;
  12448. }
  12449. // move everything one place down to overwrite removed entry
  12450. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12451. // wipe last entry
  12452. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12453. }
  12454. clif_wisexin(sd, type, 0); // success
  12455. }
  12456. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12457. /// Request to allow/deny all whispers.
  12458. /// 00d0 <type>.B
  12459. /// type:
  12460. /// 0 = (/exall) deny all speech
  12461. /// 1 = (/inall) allow all speech
  12462. void clif_parse_PMIgnoreAll(int32 fd, map_session_data *sd)
  12463. {
  12464. int32 type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12465. if( type == 0 ) {// Deny all
  12466. if( sd->state.ignoreAll ) {
  12467. flag = 1; // fail
  12468. } else {
  12469. sd->state.ignoreAll = 1;
  12470. flag = 0; // success
  12471. }
  12472. } else {//Unblock everyone
  12473. if( sd->state.ignoreAll ) {
  12474. sd->state.ignoreAll = 0;
  12475. flag = 0; // success
  12476. } else {
  12477. if (sd->ignore[0].name[0] != '\0')
  12478. { //Wipe the ignore list.
  12479. memset(sd->ignore, 0, sizeof(sd->ignore));
  12480. flag = 0; // success
  12481. } else {
  12482. flag = 1; // fail
  12483. }
  12484. }
  12485. }
  12486. clif_wisall(sd, type, flag);
  12487. }
  12488. /// Whisper ignore list (ZC_WHISPER_LIST).
  12489. /// 00d4 <packet len>.W { <char name>.24B }*
  12490. void clif_PMIgnoreList(map_session_data* sd)
  12491. {
  12492. int32 i, fd = sd->fd;
  12493. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12494. WFIFOW(fd,0) = 0xd4;
  12495. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12496. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12497. }
  12498. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12499. WFIFOSET(fd,WFIFOW(fd,2));
  12500. }
  12501. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12502. /// 00d3
  12503. void clif_parse_PMIgnoreList(int32 fd,map_session_data *sd)
  12504. {
  12505. clif_PMIgnoreList(sd);
  12506. }
  12507. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12508. /// 01e7
  12509. void clif_parse_NoviceDoriDori(int32 fd, map_session_data *sd)
  12510. {
  12511. if (sd->state.doridori) return;
  12512. switch (sd->class_&MAPID_UPPERMASK) {
  12513. case MAPID_SOUL_LINKER:
  12514. case MAPID_STAR_GLADIATOR:
  12515. case MAPID_TAEKWON:
  12516. if (!sd->state.rest)
  12517. break;
  12518. [[fallthrough]];
  12519. case MAPID_SUPER_NOVICE:
  12520. case MAPID_SUPER_BABY:
  12521. case MAPID_SUPER_NOVICE_E:
  12522. case MAPID_SUPER_BABY_E:
  12523. sd->state.doridori=1;
  12524. break;
  12525. }
  12526. }
  12527. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12528. /// 01ed
  12529. /// Note: This packet is caused by 7 lines of any text, followed by
  12530. /// the prayer and an another line of any text. The prayer is
  12531. /// defined by lines 790~793 in data\msgstringtable.txt
  12532. /// "Dear angel, can you hear my voice?"
  12533. /// "I am" (space separated player name) "Super Novice~"
  12534. /// "Help me out~ Please~ T_T"
  12535. void clif_parse_NoviceExplosionSpirits(int32 fd, map_session_data *sd)
  12536. {
  12537. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12538. t_exp next = pc_nextbaseexp(sd);
  12539. if( next ) {
  12540. int32 percent = (int32)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12541. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12542. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12543. clif_skill_nodamage(&sd->bl, sd->bl, MO_EXPLOSIONSPIRITS, 5); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12544. }
  12545. }
  12546. }
  12547. }
  12548. /// Friends List
  12549. ///
  12550. /// Toggles a single friend online/offline.
  12551. /// 0206 <account id>.L <char id>.L <state>.B (ZC_FRIENDS_STATE)
  12552. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221 (ZC_FRIENDS_STATE)
  12553. /// state:
  12554. /// 0 = online
  12555. /// 1 = offline
  12556. void clif_friendslist_toggle( map_session_data& sd, const s_friend& f, bool online ){
  12557. PACKET_ZC_FRIENDS_STATE p = {};
  12558. p.packetType = HEADER_ZC_FRIENDS_STATE;
  12559. p.AID = f.account_id;
  12560. p.CID = f.char_id;
  12561. p.offline = !online;
  12562. #if PACKETVER_MAIN_NUM >= 20180307 || PACKETVER_RE_NUM >= 20180221 || PACKETVER_ZERO_NUM >= 20180328
  12563. safestrncpy( p.name, f.name, sizeof( p.name ) );
  12564. #endif
  12565. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  12566. }
  12567. // Subfunction called from clif_foreachclient to toggle friends on/off
  12568. int32 clif_friendslist_toggle_sub( map_session_data* tsd, va_list ap ){
  12569. uint32 account_id = va_arg( ap, uint32 );
  12570. uint32 char_id = va_arg( ap, uint32 );
  12571. bool online = va_arg( ap, int32 ) != 0;
  12572. // Seek friend.
  12573. for( const s_friend& their_friend : tsd->status.friends ){
  12574. // Cancel early
  12575. if( their_friend.char_id == 0 ){
  12576. break;
  12577. }
  12578. if( their_friend.account_id != account_id ){
  12579. continue;
  12580. }
  12581. if( their_friend.char_id != char_id ){
  12582. continue;
  12583. }
  12584. clif_friendslist_toggle( *tsd, their_friend, online );
  12585. return 1;
  12586. }
  12587. // Not found
  12588. return 0;
  12589. }
  12590. /// Sends the whole friends list.
  12591. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }* (ZC_FRIENDS_LIST)
  12592. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221 (ZC_FRIENDS_LIST)
  12593. void clif_friendslist_send( map_session_data& sd ){
  12594. PACKET_ZC_FRIENDS_LIST* p = reinterpret_cast<PACKET_ZC_FRIENDS_LIST*>( packet_buffer );
  12595. p->packetType = HEADER_ZC_FRIENDS_LIST;
  12596. p->PacketLength = sizeof( *p );
  12597. for( int32 i = 0, c = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12598. PACKET_ZC_FRIENDS_LIST_sub& f = p->friends[c];
  12599. f.AID = sd.status.friends[i].account_id;
  12600. f.CID = sd.status.friends[i].char_id;
  12601. #if !( PACKETVER_MAIN_NUM >= 20180307 || PACKETVER_RE_NUM >= 20180221 || PACKETVER_ZERO_NUM >= 20180328 ) || PACKETVER >= 20200902
  12602. safestrncpy( f.name, sd.status.friends[i].name, sizeof( f.name ) );
  12603. #endif
  12604. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( f ) );
  12605. c++;
  12606. }
  12607. clif_send( p, p->PacketLength, &sd.bl, SELF );
  12608. // Sending the online players
  12609. for( const s_friend& my_friend : sd.status.friends ){
  12610. // Cancel early
  12611. if( my_friend.char_id == 0 ){
  12612. break;
  12613. }
  12614. if( map_charid2sd( my_friend.char_id ) ){
  12615. clif_friendslist_toggle( sd, my_friend, true );
  12616. }
  12617. }
  12618. }
  12619. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12620. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12621. /// result:
  12622. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12623. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12624. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12625. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12626. void clif_friendslist_reqack(map_session_data *sd, map_session_data *f_sd, int32 type)
  12627. {
  12628. int32 fd;
  12629. nullpo_retv(sd);
  12630. fd = sd->fd;
  12631. WFIFOHEAD(fd,packet_len(0x209));
  12632. WFIFOW(fd,0) = 0x209;
  12633. WFIFOW(fd,2) = type;
  12634. if (f_sd) {
  12635. WFIFOL(fd,4) = f_sd->status.account_id;
  12636. WFIFOL(fd,8) = f_sd->status.char_id;
  12637. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12638. }
  12639. WFIFOSET(fd, packet_len(0x209));
  12640. }
  12641. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12642. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12643. void clif_friendlist_req(map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12644. {
  12645. int32 fd = sd->fd;
  12646. WFIFOHEAD(fd,packet_len(0x207));
  12647. WFIFOW(fd,0) = 0x207;
  12648. WFIFOL(fd,2) = account_id;
  12649. WFIFOL(fd,6) = char_id;
  12650. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12651. WFIFOSET(fd,packet_len(0x207));
  12652. }
  12653. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12654. /// 0202 <name>.24B
  12655. void clif_parse_FriendsListAdd(int32 fd, map_session_data *sd)
  12656. {
  12657. map_session_data *f_sd;
  12658. int32 i;
  12659. // TODO: shuffle packet
  12660. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12661. // Friend doesn't exist (no player with this name)
  12662. if (f_sd == nullptr) {
  12663. clif_displaymessage(fd, msg_txt(sd,3));
  12664. return;
  12665. }
  12666. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12667. return;
  12668. }
  12669. // ensure that the request player's friend list is not full
  12670. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12671. if( i == MAX_FRIENDS ){
  12672. clif_friendslist_reqack(sd, f_sd, 2);
  12673. return;
  12674. }
  12675. // @noask [LuzZza]
  12676. if(f_sd->state.noask) {
  12677. clif_noask_sub( *sd, *f_sd, 398 ); // Autorejected friend request from %s.
  12678. return;
  12679. }
  12680. // Friend already exists
  12681. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12682. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12683. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12684. return;
  12685. }
  12686. }
  12687. f_sd->friend_req = sd->status.char_id;
  12688. sd->friend_req = f_sd->status.char_id;
  12689. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12690. }
  12691. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12692. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12693. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12694. /// reply:
  12695. /// 0 = rejected
  12696. /// 1 = accepted
  12697. void clif_parse_FriendsListReply(int32 fd, map_session_data *sd)
  12698. {
  12699. map_session_data *f_sd;
  12700. uint32 account_id;
  12701. char reply;
  12702. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12703. account_id = RFIFOL(fd,info->pos[0]);
  12704. //char_id = RFIFOL(fd,info->pos[1]);
  12705. #if PACKETVER < 6
  12706. reply = RFIFOB(fd,info->pos[2]);
  12707. #else
  12708. reply = RFIFOL(fd,info->pos[2]);
  12709. #endif
  12710. if( sd->bl.id == account_id ) {// adding oneself as friend
  12711. return;
  12712. }
  12713. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12714. if (f_sd == nullptr)
  12715. return;
  12716. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12717. clif_friendslist_reqack(f_sd, sd, 1);
  12718. else {
  12719. int32 i;
  12720. // Find an empty slot
  12721. for (i = 0; i < MAX_FRIENDS; i++)
  12722. if (f_sd->status.friends[i].char_id == 0)
  12723. break;
  12724. if (i == MAX_FRIENDS) {
  12725. clif_friendslist_reqack(f_sd, sd, 2);
  12726. return;
  12727. }
  12728. f_sd->status.friends[i].account_id = sd->status.account_id;
  12729. f_sd->status.friends[i].char_id = sd->status.char_id;
  12730. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12731. clif_friendslist_reqack(f_sd, sd, 0);
  12732. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12733. if (battle_config.friend_auto_add) {
  12734. // Also add f_sd to sd's friendlist.
  12735. for (i = 0; i < MAX_FRIENDS; i++) {
  12736. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12737. return; //No need to add anything.
  12738. if (sd->status.friends[i].char_id == 0)
  12739. break;
  12740. }
  12741. if (i == MAX_FRIENDS) {
  12742. clif_friendslist_reqack(sd, f_sd, 2);
  12743. return;
  12744. }
  12745. sd->status.friends[i].account_id = f_sd->status.account_id;
  12746. sd->status.friends[i].char_id = f_sd->status.char_id;
  12747. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12748. clif_friendslist_reqack(sd, f_sd, 0);
  12749. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12750. }
  12751. }
  12752. }
  12753. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12754. /// 0203 <account id>.L <char id>.L
  12755. void clif_parse_FriendsListRemove(int32 fd, map_session_data *sd)
  12756. {
  12757. map_session_data *f_sd = nullptr;
  12758. uint32 account_id, char_id;
  12759. int32 i, j;
  12760. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12761. account_id = RFIFOL(fd,info->pos[0]);
  12762. char_id = RFIFOL(fd,info->pos[1]);
  12763. // Search friend
  12764. for (i = 0; i < MAX_FRIENDS &&
  12765. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12766. if (i == MAX_FRIENDS) {
  12767. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12768. return;
  12769. }
  12770. //remove from friend's list first
  12771. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12772. for (i = 0; i < MAX_FRIENDS &&
  12773. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12774. if (i != MAX_FRIENDS) {
  12775. // move all chars up
  12776. for(j = i + 1; j < MAX_FRIENDS; j++)
  12777. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12778. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12779. //should the guy be notified of some message? we should add it here if so
  12780. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12781. WFIFOW(f_sd->fd,0) = 0x20a;
  12782. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12783. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12784. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12785. }
  12786. } else { //friend not online -- ask char server to delete from his friendlist
  12787. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12788. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12789. return;
  12790. }
  12791. }
  12792. // We can now delete from original requester
  12793. for (i = 0; i < MAX_FRIENDS &&
  12794. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12795. // move all chars up
  12796. for(j = i + 1; j < MAX_FRIENDS; j++)
  12797. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12798. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12799. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12800. WFIFOHEAD(fd,packet_len(0x20a));
  12801. WFIFOW(fd,0) = 0x20a;
  12802. WFIFOL(fd,2) = account_id;
  12803. WFIFOL(fd,6) = char_id;
  12804. WFIFOSET(fd, packet_len(0x20a));
  12805. }
  12806. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12807. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12808. void clif_PVPInfo(map_session_data* sd)
  12809. {
  12810. int32 fd = sd->fd;
  12811. WFIFOHEAD(fd,packet_len(0x210));
  12812. WFIFOW(fd,0) = 0x210;
  12813. WFIFOL(fd,2) = sd->status.char_id;
  12814. WFIFOL(fd,6) = sd->status.account_id;
  12815. WFIFOL(fd,10) = sd->pvp_won; // times won
  12816. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12817. WFIFOL(fd,18) = sd->pvp_point;
  12818. WFIFOSET(fd, packet_len(0x210));
  12819. }
  12820. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12821. /// 020f <char id>.L <account id>.L
  12822. void clif_parse_PVPInfo(int32 fd,map_session_data *sd)
  12823. {
  12824. // TODO: Is there a way to use this on an another player (char/acc id)?
  12825. //int32 cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12826. //int32 aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12827. clif_PVPInfo(sd);
  12828. }
  12829. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12830. /// 0254 <which>.B
  12831. /// which: (unused atm for security purpose)
  12832. /// 0 = sun
  12833. /// 1 = moon
  12834. /// 2 = star
  12835. void clif_parse_FeelSaveOk(int32 fd,map_session_data *sd)
  12836. {
  12837. int32 i;
  12838. //int32 wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12839. if (sd->menuskill_id != SG_FEEL)
  12840. return;
  12841. i = sd->menuskill_val-1;
  12842. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12843. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12844. sd->feel_map[i].m = sd->bl.m;
  12845. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12846. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12847. // clif_misceffect2(&sd->bl, 0x1b0);
  12848. // clif_misceffect2(&sd->bl, 0x21f);
  12849. clif_feel_info(sd, i, 0);
  12850. clif_menuskill_clear(sd);
  12851. }
  12852. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12853. /// 0253 <which>.B
  12854. /// which:
  12855. /// 0 = sun
  12856. /// 1 = moon
  12857. /// 2 = star
  12858. void clif_feel_req(int32 fd, map_session_data *sd, uint16 skill_lv)
  12859. {
  12860. WFIFOHEAD(fd,packet_len(0x253));
  12861. WFIFOW(fd,0)=0x253;
  12862. WFIFOB(fd,2)=TOB(skill_lv-1);
  12863. WFIFOSET(fd, packet_len(0x253));
  12864. sd->menuskill_id = SG_FEEL;
  12865. sd->menuskill_val = skill_lv;
  12866. }
  12867. /// Request to change homunculus' name (CZ_RENAME_MER).
  12868. /// 0231 <name>.24B
  12869. void clif_parse_ChangeHomunculusName(int32 fd, map_session_data *sd){
  12870. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12871. }
  12872. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12873. /// 0234 <id>.L
  12874. void clif_parse_HomMoveToMaster(int32 fd, map_session_data *sd){
  12875. int32 id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12876. struct block_list *bl = nullptr;
  12877. struct unit_data *ud = nullptr;
  12878. if( sd->md && sd->md->bl.id == id )
  12879. bl = &sd->md->bl;
  12880. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12881. bl = &sd->hd->bl; // Moving Homunculus
  12882. else
  12883. return;
  12884. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12885. ud = unit_bl2ud(bl);
  12886. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12887. }
  12888. /// Request to move homunculus/mercenary.
  12889. /// 0232 <id>.L <position data>.3B (CZ_REQUEST_MOVENPC)
  12890. void clif_parse_HomMoveTo(int32 fd, map_session_data *sd){
  12891. #if PACKETVER >= 20050425
  12892. const PACKET_CZ_REQUEST_MOVENPC* p = reinterpret_cast<const PACKET_CZ_REQUEST_MOVENPC*>( RFIFOP( fd, 0 ) );
  12893. struct block_list *bl = nullptr;
  12894. int16 x, y;
  12895. RBUFPOS( p->PosDir, 0, &x, &y, nullptr );
  12896. if( sd->md && sd->md->bl.id == p->GID )
  12897. bl = &sd->md->bl; // Moving Mercenary
  12898. else if( hom_is_active(sd->hd) && sd->hd->bl.id == p->GID )
  12899. bl = &sd->hd->bl; // Moving Homunculus
  12900. else
  12901. return;
  12902. if (x < 0 || y < 0 || (x == bl->x && y == bl->y))
  12903. return;
  12904. unit_walktoxy(bl, x, y, 4);
  12905. #endif
  12906. }
  12907. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12908. /// 0233 <id>.L <target id>.L <action>.B
  12909. /// action:
  12910. /// always 0
  12911. void clif_parse_HomAttack(int32 fd,map_session_data *sd)
  12912. {
  12913. struct block_list *bl = nullptr;
  12914. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12915. int32 id = RFIFOL(fd,info->pos[0]);
  12916. int32 target_id = RFIFOL(fd,info->pos[1]);
  12917. int32 action_type = RFIFOB(fd,info->pos[2]);
  12918. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12919. bl = &sd->hd->bl;
  12920. else if( sd->md && sd->md->bl.id == id )
  12921. bl = &sd->md->bl;
  12922. else return;
  12923. unit_attack(bl, target_id, action_type != 0);
  12924. }
  12925. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12926. /// 022d <type>.W <command>.B
  12927. /// type:
  12928. /// always 0
  12929. /// command:
  12930. /// 0 = homunculus information
  12931. /// 1 = feed
  12932. /// 2 = delete
  12933. void clif_parse_HomMenu(int32 fd, map_session_data *sd)
  12934. { //[orn]
  12935. int32 cmd = RFIFOW(fd,0);
  12936. //int32 type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12937. if(!hom_is_active(sd->hd))
  12938. return;
  12939. // TODO: shuffle packet
  12940. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12941. }
  12942. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12943. /// 0292
  12944. void clif_parse_AutoRevive(int32 fd, map_session_data *sd)
  12945. {
  12946. pc_revive_item(sd);
  12947. }
  12948. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12949. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12950. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12951. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12952. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12953. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12954. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12955. void clif_check(int32 fd, map_session_data* pl_sd)
  12956. {
  12957. WFIFOHEAD(fd,packet_len(0x214));
  12958. WFIFOW(fd, 0) = 0x214;
  12959. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12960. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12961. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12962. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12963. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12964. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12965. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12966. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12967. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12968. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12969. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12970. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12971. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12972. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12973. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12974. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12975. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12976. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12977. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12978. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12979. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12980. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12981. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12982. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12983. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12984. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12985. WFIFOSET(fd,packet_len(0x214));
  12986. }
  12987. /// /check (CZ_REQ_STATUS_GM).
  12988. /// Request character's status values.
  12989. /// 0213 <char name>.24B
  12990. void clif_parse_Check(int32 fd, map_session_data *sd)
  12991. {
  12992. char charname[NAME_LENGTH];
  12993. map_session_data* pl_sd;
  12994. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12995. return;
  12996. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12997. if( ( pl_sd = map_nick2sd(charname,false) ) == nullptr || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12998. {
  12999. return;
  13000. }
  13001. clif_check(fd, pl_sd);
  13002. }
  13003. /// MAIL SYSTEM
  13004. /// By Zephyrus
  13005. ///
  13006. /// Notification about the result of adding an item to mail
  13007. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  13008. /// result:
  13009. /// 0 = success
  13010. /// 1 = failure
  13011. /// 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)
  13012. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  13013. /// result:
  13014. /// 0 = success
  13015. /// 1 = over weight
  13016. /// 2 = fatal error
  13017. void clif_Mail_setattachment( map_session_data* sd, int32 index, int32 amount, uint8 flag ){
  13018. int32 fd = sd->fd;
  13019. #if PACKETVER < 20150513
  13020. WFIFOHEAD(fd,packet_len(0x255));
  13021. WFIFOW(fd,0) = 0x255;
  13022. WFIFOW(fd,2) = index;
  13023. WFIFOB(fd,4) = flag;
  13024. WFIFOSET(fd,packet_len(0x255));
  13025. #else
  13026. PACKET_ZC_ACK_ADD_ITEM_RODEX p = {};
  13027. if( flag ){
  13028. memset( &p, 0, sizeof( p ) );
  13029. }else{
  13030. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13031. p.index = index;
  13032. p.count = amount;
  13033. p.itemId = client_nameid( item->nameid );
  13034. p.type = itemtype( item->nameid );
  13035. p.IsIdentified = item->identify ? 1 : 0;
  13036. p.IsDamaged = item->attribute ? 1 : 0;
  13037. p.refiningLevel = item->refine;
  13038. clif_addcards( &p.slot, item );
  13039. clif_add_random_options( p.optionData, *item );
  13040. p.weight = 0;
  13041. for( int32 i = 0; i < MAIL_MAX_ITEM; i++ ){
  13042. if( sd->mail.item[i].nameid == 0 ){
  13043. continue;
  13044. }
  13045. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13046. }
  13047. p.favorite = ( item->favorite != 0 ) ? 1 : 0;
  13048. p.location = pc_equippoint( sd, server_index( index ) );
  13049. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13050. p.grade = item->enchantgrade;
  13051. #endif
  13052. }
  13053. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13054. p.result = flag;
  13055. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13056. #endif
  13057. }
  13058. /// Notification about the result of retrieving a mail attachment
  13059. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13060. /// result:
  13061. /// 0 = success
  13062. /// 1 = failure
  13063. /// 2 = too many items
  13064. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13065. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13066. void clif_mail_getattachment(map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13067. #if PACKETVER < 20150513
  13068. int32 fd = sd->fd;
  13069. WFIFOHEAD(fd,packet_len(0x245));
  13070. WFIFOW(fd,0) = 0x245;
  13071. WFIFOB(fd,2) = result;
  13072. WFIFOSET(fd,packet_len(0x245));
  13073. #else
  13074. switch( type ){
  13075. case MAIL_ATT_ITEM:
  13076. case MAIL_ATT_ZENY:
  13077. break;
  13078. default:
  13079. return;
  13080. }
  13081. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13082. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13083. p.MailID = msg->id;
  13084. p.opentype = msg->type;
  13085. p.result = result;
  13086. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13087. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13088. #endif
  13089. }
  13090. /// Notification about the result of sending a mail
  13091. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13092. /// result:
  13093. /// 0 = success
  13094. /// 1 = recipinent does not exist
  13095. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13096. void clif_Mail_send(map_session_data* sd, enum mail_send_result result){
  13097. #if PACKETVER < 20150513
  13098. int32 fd = sd->fd;
  13099. WFIFOHEAD(fd,packet_len(0x249));
  13100. WFIFOW(fd,0) = 0x249;
  13101. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13102. WFIFOSET(fd,packet_len(0x249));
  13103. #else
  13104. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13105. p.PacketType = rodexwriteresult;
  13106. p.result = result;
  13107. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13108. #endif
  13109. }
  13110. /// Notification about the result of deleting a mail.
  13111. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13112. /// result:
  13113. /// 0 = success
  13114. /// 1 = failure
  13115. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13116. void clif_mail_delete( map_session_data* sd, struct mail_message *msg, bool success ){
  13117. #if PACKETVER < 20150513
  13118. int32 fd = sd->fd;
  13119. WFIFOHEAD(fd, packet_len(0x257));
  13120. WFIFOW(fd,0) = 0x257;
  13121. WFIFOL(fd,2) = msg->id;
  13122. WFIFOW(fd,6) = !success;
  13123. WFIFOSET(fd, packet_len(0x257));
  13124. #else
  13125. // This is only a success notification
  13126. if( success ){
  13127. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13128. p.PacketType = rodexdelete;
  13129. p.opentype = msg->type;
  13130. p.MailID = msg->id;
  13131. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13132. }
  13133. #endif
  13134. }
  13135. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13136. /// 0274 <mail id>.L <result>.W
  13137. /// result:
  13138. /// 0 = success
  13139. /// 1 = failure
  13140. void clif_Mail_return(int32 fd, int32 mail_id, int16 fail)
  13141. {
  13142. WFIFOHEAD(fd,packet_len(0x274));
  13143. WFIFOW(fd,0) = 0x274;
  13144. WFIFOL(fd,2) = mail_id;
  13145. WFIFOW(fd,6) = fail;
  13146. WFIFOSET(fd,packet_len(0x274));
  13147. }
  13148. /// Notification about new mail.
  13149. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13150. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13151. void clif_Mail_new(map_session_data* sd, int32 mail_id, const char *sender, const char *title){
  13152. #if PACKETVER < 20150513
  13153. int32 fd = sd->fd;
  13154. WFIFOHEAD(fd,packet_len(0x24a));
  13155. WFIFOW(fd,0) = 0x24a;
  13156. WFIFOL(fd,2) = mail_id;
  13157. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13158. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13159. WFIFOSET(fd,packet_len(0x24a));
  13160. #else
  13161. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13162. p.PacketType = rodexicon;
  13163. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13164. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13165. #endif
  13166. }
  13167. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13168. /// 0260 <type>.L
  13169. /// type:
  13170. /// 0 = open
  13171. /// 1 = close
  13172. void clif_Mail_window(int32 fd, int32 flag)
  13173. {
  13174. WFIFOHEAD(fd,packet_len(0x260));
  13175. WFIFOW(fd,0) = 0x260;
  13176. WFIFOL(fd,2) = flag;
  13177. WFIFOSET(fd,packet_len(0x260));
  13178. }
  13179. /// Lists mails stored in inbox.
  13180. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13181. /// read:
  13182. /// 0 = unread
  13183. /// 1 = read
  13184. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13185. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13186. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13187. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13188. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13189. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13190. void clif_Mail_refreshinbox(map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13191. #if PACKETVER < 20150513
  13192. int32 fd = sd->fd;
  13193. struct mail_data *md = &sd->mail.inbox;
  13194. struct mail_message *msg;
  13195. int32 len, i, j;
  13196. len = 8 + (73 * md->amount);
  13197. WFIFOHEAD(fd,len);
  13198. WFIFOW(fd,0) = 0x240;
  13199. WFIFOW(fd,2) = len;
  13200. WFIFOL(fd,4) = md->amount;
  13201. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13202. {
  13203. msg = &md->msg[i];
  13204. if (msg->id < 1)
  13205. continue;
  13206. WFIFOL(fd,8+73*j) = msg->id;
  13207. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13208. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13209. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13210. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13211. j++;
  13212. }
  13213. WFIFOSET(fd,len);
  13214. if( md->full ) {// TODO: is this official?
  13215. char output[100];
  13216. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13217. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13218. }
  13219. #else
  13220. int32 fd = sd->fd;
  13221. struct mail_data *md = &sd->mail.inbox;
  13222. struct mail_message *msg;
  13223. int32 i, j, k, offset, titleLength;
  13224. uint8 mailType, amount, remaining;
  13225. uint32 now = (uint32)time(nullptr);
  13226. #if PACKETVER >= 20170419
  13227. int32 cmd = 0xac2;
  13228. #elif PACKETVER >= 20160601
  13229. int32 cmd = 0xa7d;
  13230. #else
  13231. int32 cmd = 0x9f0;
  13232. #endif
  13233. if( battle_config.mail_daily_count ){
  13234. mail_refresh_remaining_amount(sd);
  13235. }
  13236. #if PACKETVER >= 20170419
  13237. // Always send all
  13238. i = md->amount;
  13239. #else
  13240. // If a starting mail id was sent
  13241. if( mailID != 0 ){
  13242. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13243. // Unknown mail
  13244. if( i == md->amount ){
  13245. // Ignore the request for now
  13246. return; // TODO: Should we just show the first page instead?
  13247. }
  13248. // It was actually the oldest/first mail, there is no further page
  13249. if( i == 0 ){
  13250. return;
  13251. }
  13252. // We actually want the next/older mail
  13253. i -= 1;
  13254. }else{
  13255. i = md->amount;
  13256. }
  13257. #endif
  13258. // Count the remaining mails from the starting mail or the beginning
  13259. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13260. for( j = i, remaining = 0; j >= 0; j-- ){
  13261. msg = &md->msg[j];
  13262. if (msg->id < 1)
  13263. continue;
  13264. #if PACKETVER < 20170419
  13265. if (msg->type != type)
  13266. continue;
  13267. #endif
  13268. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13269. continue;
  13270. remaining++;
  13271. }
  13272. #if PACKETVER >= 20170419
  13273. // Always send all
  13274. amount = remaining;
  13275. #else
  13276. if( remaining > MAIL_PAGE_SIZE ){
  13277. amount = MAIL_PAGE_SIZE;
  13278. }else{
  13279. amount = remaining;
  13280. }
  13281. #endif
  13282. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13283. WFIFOW(fd, 0) = cmd;
  13284. #if PACKETVER >= 20170419
  13285. WFIFOB(fd, 4) = 1; // Unknown
  13286. offset = 5;
  13287. #else
  13288. WFIFOB(fd, 4) = type;
  13289. WFIFOB(fd, 5) = amount;
  13290. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13291. offset = 7;
  13292. #endif
  13293. for( amount = 0; i >= 0; i-- ){
  13294. msg = &md->msg[i];
  13295. if (msg->id < 1)
  13296. continue;
  13297. #if PACKETVER < 20170419
  13298. if (msg->type != type)
  13299. continue;
  13300. #endif
  13301. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13302. continue;
  13303. #if PACKETVER >= 20170419
  13304. WFIFOB(fd, offset) = msg->type;
  13305. offset += 1;
  13306. #endif
  13307. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13308. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13309. mailType = MAIL_TYPE_TEXT; // Normal letter
  13310. if( msg->zeny > 0 ){
  13311. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13312. }
  13313. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13314. if( msg->item[k].nameid > 0 ){
  13315. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13316. break;
  13317. }
  13318. }
  13319. #if PACKETVER >= 20170419
  13320. // If it came from an npc?
  13321. if( !msg->send_id ){
  13322. mailType |= MAIL_TYPE_NPC;
  13323. }
  13324. #endif
  13325. WFIFOB(fd, offset + 9) = mailType;
  13326. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13327. #if PACKETVER < 20170419
  13328. // How much time has passed since you received the mail
  13329. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13330. offset += 4;
  13331. #endif
  13332. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13333. if( msg->scheduled_deletion > 0 ){
  13334. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13335. }else{
  13336. // Fake the scheduled deletion to one year in the future
  13337. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13338. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13339. }
  13340. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13341. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13342. offset += 40 + titleLength;
  13343. }
  13344. WFIFOW(fd, 2) = (int16)offset;
  13345. WFIFOSET(fd, offset);
  13346. #endif
  13347. }
  13348. /// Mail inbox list request.
  13349. /// 023f (CZ_MAIL_GET_LIST)
  13350. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13351. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13352. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13353. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13354. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13355. void clif_parse_Mail_refreshinbox(int32 fd, map_session_data *sd){
  13356. if( mail_invalid_operation( sd ) ){
  13357. return;
  13358. }
  13359. #if PACKETVER < 20150513
  13360. struct mail_data* md = &sd->mail.inbox;
  13361. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13362. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13363. else
  13364. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13365. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13366. mail_removezeny(sd, false);
  13367. #else
  13368. int32 cmd = RFIFOW(fd, 0);
  13369. #if PACKETVER < 20170419
  13370. uint8 openType = RFIFOB(fd, 2);
  13371. uint64 mailId = RFIFOQ(fd, 3);
  13372. #else
  13373. uint8 openType;
  13374. uint64 mailId = RFIFOQ(fd, 2);
  13375. int32 i;
  13376. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13377. if( i == MAIL_MAX_INBOX ){
  13378. openType = MAIL_INBOX_NORMAL;
  13379. mailId = 0;
  13380. }else{
  13381. openType = sd->mail.inbox.msg[i].type;
  13382. mailId = 0;
  13383. }
  13384. #endif
  13385. switch( openType ){
  13386. case MAIL_INBOX_NORMAL:
  13387. case MAIL_INBOX_ACCOUNT:
  13388. case MAIL_INBOX_RETURNED:
  13389. break;
  13390. default:
  13391. // Unknown type: ignore request
  13392. return;
  13393. }
  13394. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13395. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13396. return;
  13397. }
  13398. // If it is not a next page request
  13399. if( cmd != 0x9ee ){
  13400. mailId = 0;
  13401. }
  13402. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13403. #endif
  13404. }
  13405. /// Opens a mail
  13406. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13407. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13408. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13409. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13410. /// { }*n
  13411. // TODO: Packet description => for repeated block
  13412. void clif_Mail_read( map_session_data *sd, int32 mail_id ){
  13413. int32 i, fd = sd->fd;
  13414. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13415. if( i == MAIL_MAX_INBOX ) {
  13416. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13417. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13418. return;
  13419. } else {
  13420. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13421. struct item *item;
  13422. int16 msg_len;
  13423. msg_len = static_cast<decltype(msg_len)>( strlen(msg->body) );
  13424. if( msg_len == 0 ) {
  13425. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13426. msg_len = static_cast<decltype(msg_len)>( strlen(msg->body) );
  13427. }
  13428. #if PACKETVER < 20150513
  13429. item = &msg->item[0];
  13430. int16 len = 101 + msg_len;
  13431. WFIFOHEAD(fd,len);
  13432. WFIFOW(fd,0) = 0x242;
  13433. WFIFOW(fd,2) = len;
  13434. WFIFOL(fd,4) = msg->id;
  13435. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13436. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13437. WFIFOL(fd,72) = 0;
  13438. WFIFOL(fd,76) = msg->zeny;
  13439. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13440. if( item->nameid && data != nullptr ) {
  13441. WFIFOL(fd,80) = item->amount;
  13442. WFIFOW(fd,84) = client_nameid( item->nameid );
  13443. WFIFOW(fd,86) = itemtype( item->nameid );
  13444. WFIFOB(fd,88) = item->identify;
  13445. WFIFOB(fd,89) = item->attribute;
  13446. WFIFOB(fd,90) = item->refine;
  13447. WFIFOW(fd,91) = item->card[0];
  13448. WFIFOW(fd,93) = item->card[1];
  13449. WFIFOW(fd,95) = item->card[2];
  13450. WFIFOW(fd,97) = item->card[3];
  13451. } else // no item, set all to zero
  13452. memset(WFIFOP(fd,80), 0x00, 19);
  13453. WFIFOB(fd,99) = (unsigned char)msg_len;
  13454. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13455. WFIFOSET(fd,len);
  13456. #else
  13457. msg_len += 1; // Zero Termination
  13458. PACKET_ZC_ACK_READ_RODEX* p = reinterpret_cast<PACKET_ZC_ACK_READ_RODEX*>( packet_buffer );
  13459. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13460. p->PacketLength = sizeof( *p );
  13461. p->opentype = msg->type;
  13462. p->MailID = msg->id;
  13463. p->TextcontentsLength = static_cast<decltype(p->TextcontentsLength)>( msg_len );
  13464. p->zeny = msg->zeny;
  13465. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13466. p->PacketLength += p->TextcontentsLength;
  13467. p->ItemCnt = 0;
  13468. for( int32 j = 0; j < MAIL_MAX_ITEM; j++ ){
  13469. item = &msg->item[j];
  13470. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13471. if( item->nameid > 0 && item->amount > 0 && data != nullptr ){
  13472. PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = reinterpret_cast<PACKET_ZC_ACK_READ_RODEX_SUB*>( WBUFP( p, p->PacketLength ) );
  13473. mailitem->ITID = client_nameid( item->nameid );
  13474. mailitem->count = item->amount;
  13475. mailitem->type = itemtype( item->nameid );
  13476. mailitem->IsIdentified = item->identify ? 1 : 0;
  13477. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13478. mailitem->refiningLevel = item->refine;
  13479. mailitem->location = pc_equippoint_sub( sd, data.get() );
  13480. mailitem->viewSprite = data->look;
  13481. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13482. clif_addcards( &mailitem->slot, item );
  13483. clif_add_random_options( mailitem->option_data, *item );
  13484. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13485. mailitem->grade = item->enchantgrade;
  13486. #endif
  13487. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( *mailitem ) );
  13488. p->ItemCnt++;
  13489. }
  13490. }
  13491. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13492. #endif
  13493. if (msg->status == MAIL_UNREAD) {
  13494. msg->status = MAIL_READ;
  13495. intif_Mail_read(mail_id);
  13496. clif_parse_Mail_refreshinbox(fd, sd);
  13497. sd->mail.inbox.unread--;
  13498. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13499. }
  13500. }
  13501. }
  13502. /// Request to open a mail.
  13503. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13504. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13505. void clif_parse_Mail_read(int32 fd, map_session_data *sd){
  13506. #if PACKETVER < 20150513
  13507. int32 mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13508. #else
  13509. //uint8 openType = RFIFOB(fd, 2);
  13510. int32 mail_id = (int32)RFIFOQ(fd, 3);
  13511. #endif
  13512. if( mail_id <= 0 )
  13513. return;
  13514. if( mail_invalid_operation(sd) )
  13515. return;
  13516. clif_Mail_read(sd, mail_id);
  13517. }
  13518. /// Allow a player to begin writing a mail
  13519. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13520. void clif_send_Mail_beginwrite_ack( map_session_data *sd, char* name, bool success ){
  13521. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13522. p.PacketType = rodexopenwrite;
  13523. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13524. p.result = success;
  13525. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13526. }
  13527. /// Request to start writing a mail
  13528. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13529. void clif_parse_Mail_beginwrite( int32 fd, map_session_data *sd ){
  13530. char name[NAME_LENGTH];
  13531. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13532. if( mail_invalid_operation( sd ) ){
  13533. return;
  13534. }
  13535. if( sd->state.storage_flag || sd->state.mail_writing || sd->state.trading ){
  13536. clif_send_Mail_beginwrite_ack(sd, name, false);
  13537. return;
  13538. }
  13539. mail_clear(sd);
  13540. sd->state.mail_writing = true;
  13541. clif_send_Mail_beginwrite_ack(sd, name,true);
  13542. }
  13543. /// Notification that the client cancelled writing a mail
  13544. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13545. void clif_parse_Mail_cancelwrite( int32 fd, map_session_data *sd ){
  13546. sd->state.mail_writing = false;
  13547. }
  13548. /// Give the client information about the recipient, if available
  13549. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13550. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13551. void clif_Mail_Receiver_Ack( map_session_data* sd, uint32 char_id, int16 class_, uint32 level, const char* name ){
  13552. #if PACKETVER >= 20141119
  13553. PACKET_ZC_CHECKNAME p = { 0 };
  13554. p.PacketType = HEADER_ZC_CHECKNAME;
  13555. p.CharId = char_id;
  13556. p.Class = class_;
  13557. p.BaseLevel = level;
  13558. #if PACKETVER >= 20160302
  13559. strncpy(p.Name, name, NAME_LENGTH);
  13560. #endif
  13561. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13562. #endif
  13563. }
  13564. /// Request information about the recipient
  13565. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13566. void clif_parse_Mail_Receiver_Check(int32 fd, map_session_data *sd) {
  13567. #if PACKETVER >= 20140423
  13568. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13569. const PACKET_CZ_CHECKNAME2* p = reinterpret_cast<PACKET_CZ_CHECKNAME2*>( RFIFOP( fd, 0 ) );
  13570. #else
  13571. const PACKET_CZ_CHECKNAME1* p = reinterpret_cast<PACKET_CZ_CHECKNAME1*>( RFIFOP( fd, 0 ) );
  13572. #endif
  13573. static char name[NAME_LENGTH];
  13574. if( mail_invalid_operation( sd ) ){
  13575. return;
  13576. }
  13577. safestrncpy(name, p->Name, NAME_LENGTH);
  13578. intif_mail_checkreceiver(sd, name);
  13579. #endif
  13580. }
  13581. /// Request to receive mail's attachment.
  13582. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13583. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13584. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13585. void clif_parse_Mail_getattach( int32 fd, map_session_data *sd ){
  13586. int32 i;
  13587. struct mail_message* msg;
  13588. #if PACKETVER < 20150513
  13589. int32 mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13590. int32 attachment = MAIL_ATT_ALL;
  13591. #else
  13592. uint16 packet_id = RFIFOW(fd, 0);
  13593. int32 mail_id = (int32)RFIFOQ(fd, 2);
  13594. //int32 openType = RFIFOB(fd, 10);
  13595. int32 attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13596. #endif
  13597. if( !chrif_isconnected() )
  13598. return;
  13599. if( mail_id <= 0 )
  13600. return;
  13601. if( mail_invalid_operation(sd) )
  13602. return;
  13603. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13604. if( i == MAIL_MAX_INBOX )
  13605. return;
  13606. msg = &sd->mail.inbox.msg[i];
  13607. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13608. attachment &= ~MAIL_ATT_ZENY;
  13609. }
  13610. if( attachment&MAIL_ATT_ITEM ){
  13611. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13612. // No items were found
  13613. if( i == MAIL_MAX_ITEM ){
  13614. attachment &= ~MAIL_ATT_ITEM;
  13615. }
  13616. }
  13617. // Either no attachment requested at all or there are no zeny or items in the mail
  13618. if( attachment == MAIL_ATT_NONE ){
  13619. return;
  13620. }
  13621. if( attachment&MAIL_ATT_ZENY ){
  13622. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13623. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13624. return;
  13625. }else{
  13626. // Store the pending zeny (required for the "retrieve all" feature)
  13627. sd->mail.pending_zeny += msg->zeny;
  13628. // To make sure another request fails
  13629. msg->zeny = 0;
  13630. }
  13631. }
  13632. if( attachment&MAIL_ATT_ITEM ){
  13633. int32 slots = 0, totalweight = 0;
  13634. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13635. struct item* item = &msg->item[i];
  13636. if( item->nameid > 0 && item->amount > 0 ){
  13637. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13638. if(data == nullptr)
  13639. continue;
  13640. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13641. case CHKADDITEM_NEW:
  13642. slots += data->inventorySlotNeeded( item->amount );
  13643. break;
  13644. case CHKADDITEM_OVERAMOUNT:
  13645. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13646. return;
  13647. }
  13648. totalweight += data->weight * item->amount;
  13649. }
  13650. }
  13651. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13652. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13653. return;
  13654. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13655. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13656. return;
  13657. }
  13658. // To make sure another request fails
  13659. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13660. // Store the pending weight (required for the "retrieve all" feature)
  13661. sd->mail.pending_weight += totalweight;
  13662. // Store the pending slots (required for the "retrieve all" feature)
  13663. sd->mail.pending_slots += slots;
  13664. }
  13665. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13666. }
  13667. /// Request to delete a mail.
  13668. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13669. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13670. void clif_parse_Mail_delete(int32 fd, map_session_data *sd){
  13671. #if PACKETVER < 20150513
  13672. int32 mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13673. #else
  13674. //int32 openType = RFIFOB(fd, 2);
  13675. int32 mail_id = (int32)RFIFOQ(fd, 3);
  13676. #endif
  13677. int32 i, j;
  13678. if( !chrif_isconnected() )
  13679. return;
  13680. if( mail_id <= 0 )
  13681. return;
  13682. if( mail_invalid_operation(sd) )
  13683. return;
  13684. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13685. if (i < MAIL_MAX_INBOX) {
  13686. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13687. // can't delete mail without removing zeny first
  13688. if( msg->zeny > 0 ){
  13689. clif_mail_delete(sd, msg, false);
  13690. return;
  13691. }
  13692. // can't delete mail without removing attachment(s) first
  13693. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13694. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13695. clif_mail_delete(sd, msg, false);
  13696. return;
  13697. }
  13698. }
  13699. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13700. sd->mail.inbox.unread--;
  13701. clif_Mail_new(sd,0,nullptr,nullptr);
  13702. }
  13703. }
  13704. }
  13705. /// Request to return a mail.
  13706. /// 0273 <mail id>.L <receive name>.24B (CZ_REQ_MAIL_RETURN)
  13707. void clif_parse_Mail_return(int32 fd, map_session_data *sd){
  13708. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13709. const PACKET_CZ_RODEX_RETURN* p = reinterpret_cast<PACKET_CZ_RODEX_RETURN*>( RFIFOP( fd, 0 ) );
  13710. //ShowDump( p, sizeof( p ) );
  13711. int32 mail_id = p->msgId;
  13712. // not supported for now
  13713. return;
  13714. #else
  13715. int32 mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13716. #endif
  13717. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13718. int32 i;
  13719. if( mail_id <= 0 )
  13720. return;
  13721. if( mail_invalid_operation(sd) )
  13722. return;
  13723. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13724. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13725. intif_Mail_return(sd->status.char_id, mail_id);
  13726. else
  13727. clif_Mail_return(sd->fd, mail_id, 1);
  13728. }
  13729. /// Request to add an item or Zeny to mail.
  13730. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13731. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13732. void clif_parse_Mail_setattach(int32 fd, map_session_data *sd){
  13733. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13734. uint16 idx = RFIFOW(fd,info->pos[0]);
  13735. #if PACKETVER < 20150513
  13736. int32 amount = RFIFOL(fd,info->pos[1]);
  13737. #else
  13738. int32 amount = RFIFOW(fd,info->pos[1]);
  13739. #endif
  13740. unsigned char flag;
  13741. if( !chrif_isconnected() )
  13742. return;
  13743. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13744. return;
  13745. if (sd->inventory_data[server_index(idx)] == nullptr)
  13746. return;
  13747. if( mail_invalid_operation( sd ) ){
  13748. return;
  13749. }
  13750. flag = mail_setitem(sd, idx, amount);
  13751. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13752. clif_msg( sd, MSI_SWAP_EQUIPITEM_UNREGISTER_FIRST );
  13753. }else{
  13754. clif_Mail_setattachment(sd,idx,amount,flag);
  13755. }
  13756. }
  13757. /// Remove an item from a mail
  13758. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13759. void clif_mail_removeitem( map_session_data* sd, bool success, int32 index, int32 amount ){
  13760. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13761. p.PacketType = rodexremoveitem;
  13762. p.result = success;
  13763. p.index = index;
  13764. p.cnt = amount;
  13765. int32 total = 0;
  13766. for( int32 i = 0; i < MAIL_MAX_ITEM; i++ ){
  13767. if( sd->mail.item[i].nameid == 0 ){
  13768. break;
  13769. }
  13770. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13771. }
  13772. p.weight = total;
  13773. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13774. }
  13775. /// Request to reset mail item and/or Zeny
  13776. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13777. /// type:
  13778. /// 0 = reset all
  13779. /// 1 = remove item
  13780. /// 2 = remove zeny
  13781. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13782. void clif_parse_Mail_winopen(int32 fd, map_session_data *sd)
  13783. {
  13784. #if PACKETVER < 20150513
  13785. int32 type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13786. if (type == 0 || type == 1)
  13787. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13788. if (type == 0 || type == 2)
  13789. mail_removezeny(sd, false);
  13790. #else
  13791. uint16 index = RFIFOW(fd, 2);
  13792. uint16 count = RFIFOW(fd, 4);
  13793. mail_removeitem(sd,0,index,count);
  13794. #endif
  13795. }
  13796. /// Request to send mail
  13797. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13798. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13799. /// 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)
  13800. void clif_parse_Mail_send(int32 fd, map_session_data *sd){
  13801. #if PACKETVER < 20150513
  13802. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13803. if( !chrif_isconnected() )
  13804. return;
  13805. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13806. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13807. return;
  13808. }
  13809. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13810. #else
  13811. uint16 length = RFIFOW(fd, 2);
  13812. if( length < 0x3e ){
  13813. ShowWarning("Too short...\n");
  13814. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13815. return;
  13816. }
  13817. if( mail_invalid_operation( sd ) ){
  13818. return;
  13819. }
  13820. // Forged request without a begin writing packet?
  13821. if( !sd->state.mail_writing ){
  13822. return; // Ignore it
  13823. }
  13824. char receiver[NAME_LENGTH];
  13825. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13826. // char sender[NAME_LENGTH];
  13827. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13828. uint64 zeny = RFIFOQ(fd, 52);
  13829. uint16 titleLength = RFIFOW(fd, 60);
  13830. uint16 textLength = RFIFOW(fd, 62);
  13831. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13832. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13833. char title[MAIL_TITLE_LENGTH];
  13834. char text[MAIL_BODY_LENGTH];
  13835. #if PACKETVER <= 20160330
  13836. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13837. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13838. #else
  13839. // 64 = <char id>.L
  13840. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13841. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13842. #endif
  13843. if( zeny > 0 ){
  13844. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13845. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13846. return;
  13847. }
  13848. }
  13849. mail_send(sd, receiver, title, text, realTextLength);
  13850. #endif
  13851. }
  13852. /// AUCTION SYSTEM
  13853. /// By Zephyrus
  13854. ///
  13855. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13856. /// 025f <type>.L
  13857. /// type:
  13858. /// 0 = open
  13859. /// 1 = close
  13860. void clif_Auction_openwindow(map_session_data *sd)
  13861. {
  13862. int32 fd = sd->fd;
  13863. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13864. return;
  13865. if( !battle_config.feature_auction )
  13866. return;
  13867. WFIFOHEAD(fd,packet_len(0x25f));
  13868. WFIFOW(fd,0) = 0x25f;
  13869. WFIFOL(fd,2) = 0;
  13870. WFIFOSET(fd,packet_len(0x25f));
  13871. }
  13872. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13873. /// 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 }*
  13874. void clif_Auction_results(map_session_data *sd, int16 count, int16 pages, uint8 *buf)
  13875. {
  13876. int32 i, fd = sd->fd, len = sizeof(struct auction_data);
  13877. struct auction_data auction;
  13878. WFIFOHEAD(fd,12 + (count * 83));
  13879. WFIFOW(fd,0) = 0x252;
  13880. WFIFOW(fd,2) = 12 + (count * 83);
  13881. WFIFOL(fd,4) = pages;
  13882. WFIFOL(fd,8) = count;
  13883. for( i = 0; i < count; i++ ) {
  13884. int32 k = 12 + (i * 83);
  13885. memcpy(&auction, RBUFP(buf,i * len), len);
  13886. WFIFOL(fd,k) = auction.auction_id;
  13887. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13888. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  13889. WFIFOL(fd,30+k) = auction.type;
  13890. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13891. WFIFOB(fd,36+k) = auction.item.identify;
  13892. WFIFOB(fd,37+k) = auction.item.attribute;
  13893. WFIFOB(fd,38+k) = auction.item.refine;
  13894. WFIFOW(fd,39+k) = auction.item.card[0];
  13895. WFIFOW(fd,41+k) = auction.item.card[1];
  13896. WFIFOW(fd,43+k) = auction.item.card[2];
  13897. WFIFOW(fd,45+k) = auction.item.card[3];
  13898. WFIFOL(fd,47+k) = auction.price;
  13899. WFIFOL(fd,51+k) = auction.buynow;
  13900. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13901. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13902. }
  13903. WFIFOSET(fd,WFIFOW(fd,2));
  13904. }
  13905. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13906. /// 0256 <index>.W <result>.B
  13907. /// result:
  13908. /// 0 = success
  13909. /// 1 = failure
  13910. static void clif_Auction_setitem(int32 fd, int32 index, bool fail)
  13911. {
  13912. WFIFOHEAD(fd,packet_len(0x256));
  13913. WFIFOW(fd,0) = 0x256;
  13914. WFIFOW(fd,2) = index;
  13915. WFIFOB(fd,4) = fail;
  13916. WFIFOSET(fd,packet_len(0x256));
  13917. }
  13918. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13919. /// 024b <type>.W
  13920. /// type:
  13921. /// 0 = create (any other action in auction window)
  13922. /// 1 = cancel (cancel pressed on register tab)
  13923. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13924. void clif_parse_Auction_cancelreg(int32 fd, map_session_data *sd){
  13925. //int32 type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13926. if( sd->auction.amount > 0 )
  13927. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13928. sd->auction.amount = 0;
  13929. }
  13930. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13931. /// 024c <index>.W <count>.L
  13932. void clif_parse_Auction_setitem(int32 fd, map_session_data *sd){
  13933. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13934. int32 idx = RFIFOW(fd,info->pos[0]) - 2;
  13935. int32 amount = RFIFOL(fd,info->pos[1]); // Always 1
  13936. if( !battle_config.feature_auction )
  13937. return;
  13938. if( sd->auction.amount > 0 )
  13939. sd->auction.amount = 0;
  13940. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13941. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13942. return;
  13943. }
  13944. 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.
  13945. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13946. return;
  13947. }
  13948. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[idx].nameid);
  13949. 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) )
  13950. { // Consumable or pets are not allowed
  13951. clif_Auction_setitem(sd->fd, idx, true);
  13952. return;
  13953. }
  13954. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13955. !sd->inventory.u.items_inventory[idx].identify ||
  13956. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13957. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13958. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13959. clif_Auction_setitem(sd->fd, idx, true);
  13960. return;
  13961. }
  13962. sd->auction.index = idx;
  13963. sd->auction.amount = amount;
  13964. clif_Auction_setitem(fd, idx + 2, false);
  13965. }
  13966. /// Result from an auction action (ZC_AUCTION_RESULT).
  13967. /// 0250 <result>.B
  13968. /// result:
  13969. /// 0 = You have failed to bid into the auction
  13970. /// 1 = You have successfully bid in the auction
  13971. /// 2 = The auction has been canceled
  13972. /// 3 = An auction with at least one bidder cannot be canceled
  13973. /// 4 = You cannot register more than 5 items in an auction at a time
  13974. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13975. /// 6 = You have won the auction
  13976. /// 7 = You have failed to win the auction
  13977. /// 8 = You do not have enough Zeny
  13978. /// 9 = You cannot place more than 5 bids at a time
  13979. void clif_Auction_message(int32 fd, unsigned char flag)
  13980. {
  13981. WFIFOHEAD(fd,packet_len(0x250));
  13982. WFIFOW(fd,0) = 0x250;
  13983. WFIFOB(fd,2) = flag;
  13984. WFIFOSET(fd,packet_len(0x250));
  13985. }
  13986. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13987. /// 025e <result>.W
  13988. /// result:
  13989. /// 0 = You have ended the auction
  13990. /// 1 = You cannot end the auction
  13991. /// 2 = Auction ID is incorrect
  13992. void clif_Auction_close(int32 fd, unsigned char flag)
  13993. {
  13994. WFIFOHEAD(fd,packet_len(0x25e));
  13995. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13996. WFIFOW(fd,2) = flag;
  13997. WFIFOSET(fd,packet_len(0x25e));
  13998. }
  13999. /// Request to add an auction.
  14000. /// 024d <now money>.L <max money>.L <delete hour>.W (CZ_AUCTION_ADD)
  14001. void clif_parse_Auction_register( int32 fd, map_session_data* sd ){
  14002. #if PACKETVER >= 20050808
  14003. const PACKET_CZ_AUCTION_ADD* p = reinterpret_cast<PACKET_CZ_AUCTION_ADD*>( RFIFOP( fd, 0 ) );
  14004. struct auction_data auction;
  14005. if( !battle_config.feature_auction )
  14006. return;
  14007. auction.price = p->now_money;
  14008. auction.buynow = p->max_money;
  14009. auction.hours = p->hours;
  14010. // Invalid Situations...
  14011. if( sd->auction.amount < 1 ) {
  14012. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  14013. return;
  14014. }
  14015. if( auction.price >= auction.buynow ) {
  14016. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  14017. return;
  14018. }
  14019. if( auction.hours < 1 || auction.hours > 48 ) {
  14020. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14021. return;
  14022. }
  14023. // Auction checks...
  14024. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14025. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14026. clif_Auction_message(fd, 2); // The auction has been canceled
  14027. return;
  14028. }
  14029. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14030. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14031. return;
  14032. }
  14033. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14034. auction.buynow = battle_config.auction_maximumprice;
  14035. if( auction.price >= auction.buynow )
  14036. auction.price = auction.buynow - 1;
  14037. }
  14038. auction.auction_id = 0;
  14039. auction.seller_id = sd->status.char_id;
  14040. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14041. auction.buyer_id = 0;
  14042. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14043. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14044. {
  14045. clif_Auction_message(fd, 2); // The auction has been canceled
  14046. return;
  14047. }
  14048. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[sd->auction.index].nameid);
  14049. if( id == nullptr )
  14050. { // Just in case
  14051. clif_Auction_message(fd, 2); // The auction has been canceled
  14052. return;
  14053. }
  14054. safestrncpy(auction.item_name, id->ename.c_str(), sizeof(auction.item_name));
  14055. auction.type = id->type;
  14056. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14057. auction.item.amount = 1;
  14058. auction.timestamp = 0;
  14059. if( !intif_Auction_register(&auction) )
  14060. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14061. else
  14062. {
  14063. int32 zeny = auction.hours*battle_config.auction_feeperhour;
  14064. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14065. sd->auction.amount = 0;
  14066. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION);
  14067. }
  14068. #endif
  14069. }
  14070. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14071. /// 024e <auction id>.L
  14072. void clif_parse_Auction_cancel(int32 fd, map_session_data *sd){
  14073. uint32 auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14074. intif_Auction_cancel(sd->status.char_id, auction_id);
  14075. }
  14076. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14077. /// 025d <auction id>.L
  14078. void clif_parse_Auction_close(int32 fd, map_session_data *sd){
  14079. uint32 auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14080. intif_Auction_close(sd->status.char_id, auction_id);
  14081. }
  14082. /// Places a bid on an auction.
  14083. /// 024f <auction id>.L <money>.L (CZ_AUCTION_BUY)
  14084. void clif_parse_Auction_bid( int32 fd, map_session_data* sd ){
  14085. #if PACKETVER >= 20050718
  14086. const PACKET_CZ_AUCTION_BUY* p = reinterpret_cast<PACKET_CZ_AUCTION_BUY*>( RFIFOP( fd, 0 ) );
  14087. if( !pc_can_give_items(sd) ){
  14088. clif_displaymessage( sd->fd, msg_txt( sd, 246 ) ); // Your GM level doesn't authorize you to perform this action.
  14089. return;
  14090. }
  14091. // Check if char server is down (bugreport:1138)
  14092. if( CheckForCharServer() ){
  14093. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14094. return;
  14095. }
  14096. if( pc_payzeny( sd, p->money, LOG_TYPE_AUCTION ) != 0 ){
  14097. clif_Auction_message( fd, 8 ); // You do not have enough zeny
  14098. return;
  14099. }
  14100. intif_Auction_bid( sd->status.char_id, sd->status.name, p->auction_id, p->money );
  14101. #endif
  14102. }
  14103. /// Auction Search.
  14104. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W (CZ_AUCTION_ITEM_SEARCH)
  14105. /// search type:
  14106. /// 0 = armor
  14107. /// 1 = weapon
  14108. /// 2 = card
  14109. /// 3 = misc
  14110. /// 4 = name search
  14111. /// 5 = auction id search
  14112. void clif_parse_Auction_search(int32 fd, map_session_data* sd){
  14113. #if PACKETVER >= 20051107
  14114. const PACKET_CZ_AUCTION_ITEM_SEARCH* p = reinterpret_cast<PACKET_CZ_AUCTION_ITEM_SEARCH*>( RFIFOP( fd, 0 ) );
  14115. if( !battle_config.feature_auction )
  14116. return;
  14117. clif_parse_Auction_cancelreg(fd, sd);
  14118. char search_text[NAME_LENGTH];
  14119. safestrncpy( search_text, p->text, sizeof( search_text ) );
  14120. intif_Auction_requestlist( sd->status.char_id, p->type, p->auction_id, search_text, p->page );
  14121. #endif
  14122. }
  14123. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14124. /// 025c <type>.W
  14125. /// type:
  14126. /// 0 = sell (own auctions)
  14127. /// 1 = buy (own bids)
  14128. void clif_parse_Auction_buysell(int32 fd, map_session_data* sd)
  14129. {
  14130. int16 type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14131. if( !battle_config.feature_auction )
  14132. return;
  14133. clif_parse_Auction_cancelreg(fd, sd);
  14134. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14135. }
  14136. /// CASH/POINT SHOP
  14137. ///
  14138. void clif_cashshop_open( map_session_data* sd, int32 tab ){
  14139. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14140. nullpo_retv( sd );
  14141. PACKET_ZC_SE_CASHSHOP_OPEN p = {};
  14142. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14143. p.cashPoints = sd->cashPoints;
  14144. p.kafraPoints = sd->kafraPoints;
  14145. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14146. p.tab = tab;
  14147. #endif
  14148. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14149. #endif
  14150. }
  14151. void clif_parse_cashshop_open_request( int32 fd, map_session_data* sd ){
  14152. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14153. nullpo_retv( sd );
  14154. int32 tab = 0;
  14155. #if PACKETVER >= 20191224
  14156. const PACKET_CZ_SE_CASHSHOP_OPEN2* p = reinterpret_cast<PACKET_CZ_SE_CASHSHOP_OPEN2*>( RFIFOP( fd, 0 ) );
  14157. tab = p->tab;
  14158. #endif
  14159. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14160. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14161. return;
  14162. }
  14163. sd->state.cashshop_open = true;
  14164. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14165. clif_cashshop_open( sd, tab );
  14166. #endif
  14167. }
  14168. void clif_parse_cashshop_close( int32 fd, map_session_data* sd ){
  14169. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14170. sd->state.cashshop_open = false;
  14171. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14172. // No need to do anything here
  14173. #endif
  14174. }
  14175. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14176. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14177. void clif_parse_CashShopReqTab(int32 fd, map_session_data *sd) {
  14178. #if PACKETVER_MAIN_NUM >= 20100824 || PACKETVER_RE_NUM >= 20100824 || defined(PACKETVER_ZERO)
  14179. const PACKET_CZ_REQ_SE_CASH_TAB_CODE* p_in = reinterpret_cast<PACKET_CZ_REQ_SE_CASH_TAB_CODE*>( RFIFOP( fd, 0 ) );
  14180. // TODO: most likely wrong answer packet. Most likely HEADER_ZC_ACK_SE_CASH_ITEM_LIST (0x847) would be correct [Lemongrass]
  14181. // [4144] packet exists only in 2011 and was dropped after
  14182. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14183. std::shared_ptr<s_cash_item_tab> tab = cash_shop_db.find( static_cast<e_cash_shop_tab>( p_in->tab ) );
  14184. if( tab == nullptr ){
  14185. return;
  14186. }
  14187. // Skip empty tabs, the client only expects filled ones
  14188. if( tab->items.empty() ){
  14189. return;
  14190. }
  14191. #if !(PACKETVER_SUPPORTS_SALES)
  14192. if( tab->tab == CASHSHOP_TAB_SALE ){
  14193. return;
  14194. }
  14195. #endif
  14196. PACKET_ZC_ACK_SE_CASH_ITEM_LIST2* p = reinterpret_cast<PACKET_ZC_ACK_SE_CASH_ITEM_LIST2*>( packet_buffer );
  14197. p->packetType = HEADER_ZC_ACK_SE_CASH_ITEM_LIST2;
  14198. p->packetLength = sizeof( *p );
  14199. p->tab = tab->tab;
  14200. p->count = 0;
  14201. for( std::shared_ptr<s_cash_item> item : tab->items ){
  14202. p->items[p->count].itemId = client_nameid( item->nameid );
  14203. p->items[p->count].price = item->price;
  14204. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  14205. p->count++;
  14206. }
  14207. clif_send( p, p->packetLength, &sd->bl, SELF );
  14208. #endif
  14209. #endif
  14210. }
  14211. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14212. void clif_cashshop_list( map_session_data& sd ){
  14213. for( const auto& pair : cash_shop_db ){
  14214. std::shared_ptr<s_cash_item_tab> tab = pair.second;
  14215. // Skip empty tabs, the client only expects filled ones
  14216. if( tab->items.empty() ){
  14217. continue;
  14218. }
  14219. #if !(PACKETVER_SUPPORTS_SALES)
  14220. if( tab->tab == CASHSHOP_TAB_SALE ){
  14221. continue;
  14222. }
  14223. #endif
  14224. PACKET_ZC_ACK_SCHEDULER_CASHITEM* p = reinterpret_cast<PACKET_ZC_ACK_SCHEDULER_CASHITEM*>( packet_buffer );
  14225. p->packetType = HEADER_ZC_ACK_SCHEDULER_CASHITEM;
  14226. p->packetLength = sizeof( *p );
  14227. p->count = 0;
  14228. p->tabNum = tab->tab;
  14229. for( std::shared_ptr<s_cash_item> item : tab->items ){
  14230. p->items[p->count].itemId = client_nameid( item->nameid );
  14231. p->items[p->count].price = item->price;
  14232. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14233. struct item_data* id = itemdb_search( item->nameid );
  14234. if( id == nullptr ){
  14235. p->items[p->count].location = 0;
  14236. p->items[p->count].viewSprite = 0;
  14237. }else{
  14238. p->items[p->count].location = pc_equippoint_sub( &sd, id );
  14239. p->items[p->count].viewSprite = id->look;
  14240. }
  14241. #endif
  14242. p->count++;
  14243. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  14244. if( ( static_cast<size_t>( p->packetLength ) + sizeof( p->items[0] ) ) >= INT16_MAX ){
  14245. // Send current data
  14246. clif_send( p, p->packetLength, &sd.bl, SELF );
  14247. // Start a new packet
  14248. p->count = 0;
  14249. p->packetLength = sizeof( *p );
  14250. }
  14251. }
  14252. clif_send( p, p->packetLength, &sd.bl, SELF );
  14253. }
  14254. }
  14255. void clif_parse_cashshop_list_request( int32 fd, map_session_data* sd ){
  14256. if( !sd->status.cashshop_sent ) {
  14257. clif_cashshop_list( *sd );
  14258. #if PACKETVER_SUPPORTS_SALES
  14259. sale_notify_login(sd);
  14260. #endif
  14261. sd->status.cashshop_sent = true;
  14262. }
  14263. }
  14264. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14265. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14266. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14267. void clif_cashshop_show( map_session_data& sd, npc_data& nd ){
  14268. sd.npc_shopid = nd.bl.id;
  14269. int32 cost[2] = { 0, 0 };
  14270. npc_shop_currency_type( &sd, &nd, cost, true );
  14271. PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = reinterpret_cast<PACKET_ZC_PC_CASH_POINT_ITEMLIST*>( packet_buffer );
  14272. p->packetType = HEADER_ZC_PC_CASH_POINT_ITEMLIST;
  14273. p->packetLength = sizeof( *p );
  14274. p->cashPoints = cost[0];
  14275. #if PACKETVER >= 20070711
  14276. p->kafraPoints = cost[1];
  14277. #endif
  14278. for( int32 i = 0; i < nd.u.shop.count; i++ ) {
  14279. struct item_data* id = itemdb_search( nd.u.shop.shop_item[i].nameid );
  14280. p->items[i].price = nd.u.shop.shop_item[i].value;
  14281. p->items[i].discountPrice = nd.u.shop.shop_item[i].value; // Discount Price
  14282. p->items[i].itemType = itemtype( id->nameid );
  14283. p->items[i].itemId = client_nameid( id->nameid );
  14284. #ifdef ENABLE_OLD_CASHSHOP_PREVIEW_PATCH
  14285. p->items[i].location = pc_equippoint_sub( &sd, id );
  14286. p->items[i].viewSprite = id->look;
  14287. memset( p->items[i].unused, 0, sizeof( p->items[i].unused ) );
  14288. #endif
  14289. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  14290. }
  14291. clif_send( p, p->packetLength, &sd.bl, SELF );
  14292. }
  14293. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14294. /// 0289 <cash point>.L <error>.W
  14295. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14296. /// error:
  14297. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14298. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14299. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14300. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14301. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14302. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14303. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14304. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14305. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14306. void clif_cashshop_ack(map_session_data* sd, int32 error)
  14307. {
  14308. int32 fd, cost[2] = { 0, 0 };
  14309. struct npc_data *nd;
  14310. nullpo_retv(sd);
  14311. fd = sd->fd;
  14312. nd = map_id2nd(sd->npc_shopid);
  14313. npc_shop_currency_type(sd, nd, cost, false);
  14314. WFIFOHEAD(fd, packet_len(0x289));
  14315. WFIFOW(fd,0) = 0x289;
  14316. WFIFOL(fd,2) = cost[0];
  14317. #if PACKETVER < 20070711
  14318. WFIFOW(fd,6) = TOW(error);
  14319. #else
  14320. WFIFOL(fd,6) = cost[1];
  14321. WFIFOW(fd,10) = TOW(error);
  14322. #endif
  14323. WFIFOSET(fd, packet_len(0x289));
  14324. }
  14325. void clif_cashshop_result( map_session_data *sd, t_itemid item_id, uint16 result ){
  14326. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14327. nullpo_retv( sd );
  14328. PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet = {};
  14329. packet.packetType = HEADER_ZC_SE_PC_BUY_CASHITEM_RESULT;
  14330. if( item_id != 0 ){
  14331. packet.itemId = client_nameid( item_id );
  14332. }else{
  14333. packet.itemId = 0;
  14334. }
  14335. packet.result = result;
  14336. packet.cashPoints = sd->cashPoints;
  14337. packet.kafraPoints = sd->kafraPoints;
  14338. clif_send( &packet, sizeof( packet ), &sd->bl, SELF );
  14339. #endif
  14340. }
  14341. /// Request to buy item(s) from cash shop.
  14342. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14343. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14344. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14345. void clif_parse_npccashshop_buy( int32 fd, map_session_data *sd ){
  14346. nullpo_retv( sd );
  14347. if( sd->state.trading || !sd->npc_shopid ){
  14348. clif_cashshop_ack( sd, 1 );
  14349. return;
  14350. }
  14351. const PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = reinterpret_cast<PACKET_CZ_PC_BUY_CASH_POINT_ITEM*>( RFIFOP( fd, 0 ) );
  14352. #if PACKETVER < 20070711
  14353. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14354. #elif PACKETVER < 20101116
  14355. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14356. #else
  14357. int32 s_itl = sizeof( p->items[0] );
  14358. if( p->packetLength < sizeof( *p ) || p->packetLength != sizeof( *p ) + p->count * s_itl ){
  14359. ShowWarning( "Player %u sent incorrect cash shop buy packet (len %u:%" PRIdPTR ")!\n", sd->status.char_id, p->packetLength, sizeof( *p ) + p->count * s_itl );
  14360. return;
  14361. }
  14362. std::vector<s_npc_buy_list> item_list = {};
  14363. item_list.reserve( p->count );
  14364. for( int32 i = 0; i < p->count; i++ ){
  14365. s_npc_buy_list item = {};
  14366. item.nameid = p->items[i].itemId;
  14367. item.qty = p->items[i].amount;
  14368. item_list.push_back( item );
  14369. }
  14370. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14371. #endif
  14372. }
  14373. /// Request to buy item(s) from cash shop.
  14374. /// 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)
  14375. void clif_parse_cashshop_buy( int32 fd, map_session_data *sd ){
  14376. const PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = reinterpret_cast<PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*>( RFIFOP( fd, 0 ) );
  14377. int32 s_itl = sizeof( p->items[0] );
  14378. if( p->packetLength < sizeof( *p ) || p->packetLength != sizeof( *p ) + p->count * s_itl ){
  14379. ShowWarning( "Player %u sent incorrect cash shop buy packet (len %u:%" PRIdPTR ")!\n", sd->status.char_id, p->packetLength, sizeof( *p ) + p->count * s_itl );
  14380. return;
  14381. }
  14382. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14383. }
  14384. /// Adoption System
  14385. ///
  14386. /// Adoption message (ZC_BABYMSG).
  14387. /// 0216 <msg>.L
  14388. /// msg:
  14389. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14390. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14391. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14392. void clif_Adopt_reply(map_session_data *sd, int32 type)
  14393. {
  14394. int32 fd = sd->fd;
  14395. WFIFOHEAD(fd,6);
  14396. WFIFOW(fd,0) = 0x216;
  14397. WFIFOL(fd,2) = type;
  14398. WFIFOSET(fd,6);
  14399. }
  14400. /// Adoption confirmation (ZC_REQ_BABY).
  14401. /// 01f6 <account id>.L <char id>.L <name>.B
  14402. void clif_Adopt_request(map_session_data *sd, map_session_data *src, int32 p_id)
  14403. {
  14404. int32 fd = sd->fd;
  14405. WFIFOHEAD(fd,34);
  14406. WFIFOW(fd,0) = 0x1f6;
  14407. WFIFOL(fd,2) = src->status.account_id;
  14408. WFIFOL(fd,6) = p_id;
  14409. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14410. WFIFOSET(fd,34);
  14411. }
  14412. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14413. /// 01f9 <account id>.L
  14414. void clif_parse_Adopt_request(int32 fd, map_session_data *sd)
  14415. {
  14416. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14417. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14418. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14419. {
  14420. tsd->adopt_invite = sd->status.account_id;
  14421. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14422. }
  14423. }
  14424. /// Answer to adopt confirmation.
  14425. /// 01f7 <account id>.L <char id>.L <answer>.L (CZ_JOIN_BABY)
  14426. /// answer:
  14427. /// 0 = rejected
  14428. /// 1 = accepted
  14429. void clif_parse_Adopt_reply(int32 fd, map_session_data *sd){
  14430. const PACKET_CZ_JOIN_BABY* p = reinterpret_cast<PACKET_CZ_JOIN_BABY*>( RFIFOP( fd, 0 ) );
  14431. // Check if the adoption was accepted
  14432. if( p->accepted == 0 ){
  14433. sd->adopt_invite = 0;
  14434. return;
  14435. }
  14436. map_session_data* father_sd = map_id2sd( p->father_AID );
  14437. // The father has to be online
  14438. if( father_sd == nullptr ){
  14439. sd->adopt_invite = 0;
  14440. return;
  14441. }
  14442. map_session_data* mother_sd = map_id2sd( p->mother_AID );
  14443. // The mother has to be online
  14444. if( mother_sd == nullptr ){
  14445. sd->adopt_invite = 0;
  14446. return;
  14447. }
  14448. if( sd->adopt_invite != father_sd->status.account_id ){
  14449. sd->adopt_invite = 0;
  14450. return;
  14451. }
  14452. sd->adopt_invite = 0;
  14453. pc_adoption( father_sd, mother_sd, sd );
  14454. }
  14455. /// Convex Mirror
  14456. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B (ZC_BOSS_INFO)
  14457. /// infoType:
  14458. /// BOSS_INFO_NOT = No boss on this map.
  14459. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14460. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14461. /// BOSS_INFO_DEAD = Boss is dead.
  14462. void clif_bossmapinfo( map_session_data& sd, mob_data* md, e_bossmap_info flag ){
  14463. PACKET_ZC_BOSS_INFO p = {};
  14464. p.packetType = HEADER_ZC_BOSS_INFO;
  14465. p.type = flag;
  14466. switch (flag) {
  14467. case BOSS_INFO_NOT:
  14468. // No data required
  14469. break;
  14470. case BOSS_INFO_ALIVE_WITHMSG:
  14471. [[fallthrough]];
  14472. case BOSS_INFO_ALIVE:
  14473. p.x = md->bl.x;
  14474. p.y = md->bl.y;
  14475. break;
  14476. case BOSS_INFO_DEAD: {
  14477. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14478. uint32 seconds;
  14479. int32 hours, minutes;
  14480. seconds = (uint32)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14481. hours = seconds / (60 * 60);
  14482. seconds = seconds - (60 * 60 * hours);
  14483. minutes = seconds / 60;
  14484. p.minHours = hours;
  14485. p.minMinutes = minutes;
  14486. break;
  14487. }
  14488. }
  14489. if( md != nullptr ){
  14490. safestrncpy( p.name, md->db->jname.c_str(), sizeof( p.name ) );
  14491. }
  14492. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  14493. }
  14494. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14495. /// 02d6 <account id>.L
  14496. void clif_parse_ViewPlayerEquip(int32 fd, map_session_data* sd)
  14497. {
  14498. int32 aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14499. map_session_data* tsd = map_id2sd(aid);
  14500. if (!tsd)
  14501. return;
  14502. if (sd->bl.m != tsd->bl.m)
  14503. return;
  14504. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14505. clif_viewequip_ack( *sd, *tsd );
  14506. else
  14507. clif_msg(sd, MSI_OPEN_EQUIPEDITEM_REFUSED);
  14508. }
  14509. /// Request to a configuration.
  14510. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14511. /// type: see enum e_config_type
  14512. /// flag:
  14513. /// false = disabled
  14514. /// true = enabled
  14515. void clif_parse_configuration( int32 fd, map_session_data* sd ){
  14516. int32 cmd = RFIFOW(fd,0);
  14517. int32 type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14518. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14519. switch( type ){
  14520. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14521. sd->status.show_equip = flag;
  14522. break;
  14523. case CONFIG_CALL:
  14524. sd->status.disable_call = flag;
  14525. break;
  14526. case CONFIG_PET_AUTOFEED:
  14527. // Player can not click this if he does not have a pet
  14528. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14529. return;
  14530. }
  14531. sd->pd->pet.autofeed = flag;
  14532. break;
  14533. case CONFIG_HOMUNCULUS_AUTOFEED:
  14534. // Player can not click this if he does not have a homunculus or it is vaporized
  14535. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14536. return;
  14537. }
  14538. sd->hd->homunculus.autofeed = flag;
  14539. break;
  14540. default:
  14541. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14542. return;
  14543. }
  14544. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14545. }
  14546. /// Request to change party invitation tick.
  14547. /// 02C8 <enabled>.B (CZ_PARTY_CONFIG)
  14548. /// value:
  14549. /// 0 = disabled (triggered by /accept)
  14550. /// 1 = enabled (triggered by /refuse)
  14551. void clif_parse_PartyTick( int32 fd, map_session_data* sd ){
  14552. const PACKET_CZ_PARTY_CONFIG* p = reinterpret_cast<PACKET_CZ_PARTY_CONFIG*>( RFIFOP( fd, 0 ) );
  14553. sd->status.disable_partyinvite = p->refuseInvite;
  14554. clif_partyinvitationstate( *sd );
  14555. }
  14556. /// Questlog System [Kevin] [Inkfish]
  14557. ///
  14558. /**
  14559. * Safe check to init packet len & quest num for player.
  14560. * @param def_len
  14561. * @param info_len Length of each quest info.
  14562. * @param avail_quests Avail quests that player has.
  14563. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14564. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14565. **/
  14566. static void clif_quest_len(int32 def_len, int32 info_len, int32 avail_quests, int32 *limit_out, int32 *len_out) {
  14567. (*limit_out) = (0xFFFF - def_len) / info_len;
  14568. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14569. (*len_out) = ((*limit_out) * info_len) + def_len;
  14570. }
  14571. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14572. std::string race_name;
  14573. switch( objective->race ){
  14574. case RC_FORMLESS: race_name = "Formless"; break;
  14575. case RC_UNDEAD: race_name = "Undead"; break;
  14576. case RC_BRUTE: race_name = "Brute"; break;
  14577. case RC_PLANT: race_name = "Plant"; break;
  14578. case RC_INSECT: race_name = "Insect"; break;
  14579. case RC_FISH: race_name = "Fish"; break;
  14580. case RC_DEMON: race_name = "Demon"; break;
  14581. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14582. case RC_ANGEL: race_name = "Angel"; break;
  14583. case RC_DRAGON: race_name = "Dragon"; break;
  14584. default:
  14585. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14586. [[fallthrough]];
  14587. case RC_ALL: race_name = ""; break;
  14588. }
  14589. std::string size_name;
  14590. switch( objective->size ){
  14591. case SZ_SMALL: size_name = "Small"; break;
  14592. case SZ_MEDIUM: size_name = "Medium"; break;
  14593. case SZ_BIG: size_name = "Large"; break;
  14594. default:
  14595. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14596. [[fallthrough]];
  14597. case SZ_ALL: size_name = ""; break;
  14598. }
  14599. std::string ele_name;
  14600. switch( objective->element ){
  14601. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14602. case ELE_WATER: ele_name = "Water Element"; break;
  14603. case ELE_EARTH: ele_name = "Earth Element"; break;
  14604. case ELE_FIRE: ele_name = "Fire Element"; break;
  14605. case ELE_WIND: ele_name = "Wind Element"; break;
  14606. case ELE_POISON: ele_name = "Poison Element"; break;
  14607. case ELE_HOLY: ele_name = "Holy Element"; break;
  14608. case ELE_DARK: ele_name = "Shadow Element"; break;
  14609. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14610. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14611. default:
  14612. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14613. [[fallthrough]];
  14614. case ELE_ALL: ele_name = ""; break;
  14615. }
  14616. std::string str;
  14617. if( !objective->map_name.empty() ){
  14618. str += objective->map_name;
  14619. }
  14620. if( !race_name.empty() ){
  14621. if( !str.empty() ){
  14622. str += ", ";
  14623. }
  14624. str += race_name;
  14625. }
  14626. if( !size_name.empty() ){
  14627. if( !str.empty() ){
  14628. str += ", ";
  14629. }
  14630. str += size_name;
  14631. }
  14632. if( !ele_name.empty() ){
  14633. if( !str.empty() ){
  14634. str += ", ";
  14635. }
  14636. str += ele_name;
  14637. }
  14638. return str;
  14639. }
  14640. /// Sends list of all quest states
  14641. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14642. /// 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)
  14643. /// 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)
  14644. void clif_quest_send_list(map_session_data *sd)
  14645. {
  14646. nullpo_retv(sd);
  14647. int32 fd = sd->fd;
  14648. int32 i;
  14649. int32 offset = 8;
  14650. int32 limit = 0;
  14651. #if PACKETVER >= 20141022
  14652. #if PACKETVER >= 20150513
  14653. int32 size = 22 + NAME_LENGTH;
  14654. #else
  14655. int32 size = 10 + NAME_LENGTH;
  14656. #endif
  14657. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14658. WFIFOHEAD(fd,i);
  14659. #if PACKETVER >= 20150513
  14660. WFIFOW(fd, 0) = 0x9f8;
  14661. #else
  14662. WFIFOW(fd, 0) = 0x97a;
  14663. #endif
  14664. WFIFOL(fd, 4) = limit;
  14665. for (i = 0; i < limit; i++) {
  14666. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14667. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14668. offset += 4;
  14669. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14670. offset++;
  14671. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14672. offset += 4;
  14673. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14674. offset += 4;
  14675. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14676. offset += 2;
  14677. if (!qi->objectives.empty()) {
  14678. std::shared_ptr<s_mob_db> mob;
  14679. for (int32 j = 0; j < qi->objectives.size(); j++) {
  14680. mob = mob_db.find(qi->objectives[j]->mob_id);
  14681. e_race race = qi->objectives[j]->race;
  14682. e_size size = qi->objectives[j]->size;
  14683. e_element element = qi->objectives[j]->element;
  14684. #if PACKETVER >= 20150513
  14685. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14686. offset += 4;
  14687. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14688. offset += 4;
  14689. #endif
  14690. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14691. offset += 4;
  14692. #if PACKETVER >= 20150513
  14693. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14694. offset += 2;
  14695. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14696. offset += 2;
  14697. #endif
  14698. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14699. offset += 2;
  14700. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14701. offset += 2;
  14702. if (mob && qi->objectives[j]->mob_id > 0)
  14703. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14704. else
  14705. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14706. offset += NAME_LENGTH;
  14707. }
  14708. }
  14709. }
  14710. WFIFOW(fd, 2) = offset;
  14711. WFIFOSET(fd, offset);
  14712. #else
  14713. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14714. WFIFOHEAD(fd,i);
  14715. WFIFOW(fd, 0) = 0x2b1;
  14716. WFIFOL(fd, 4) = limit;
  14717. for (i = 0; i < limit; i++) {
  14718. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14719. offset += 4;
  14720. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14721. offset += 1;
  14722. }
  14723. WFIFOW(fd, 2) = offset;
  14724. WFIFOSET(fd, offset);
  14725. #endif
  14726. }
  14727. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14728. /// 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
  14729. void clif_quest_send_mission(map_session_data *sd)
  14730. {
  14731. nullpo_retv(sd);
  14732. int32 fd = sd->fd;
  14733. int32 limit = 0;
  14734. int32 len = sd->avail_quests*104+8;
  14735. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14736. WFIFOHEAD(fd, len);
  14737. WFIFOW(fd, 0) = 0x2b2;
  14738. WFIFOW(fd, 2) = len;
  14739. WFIFOL(fd, 4) = limit;
  14740. for (int32 i = 0; i < limit; i++) {
  14741. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14742. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14743. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14744. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14745. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14746. for (int32 j = 0 ; j < qi->objectives.size(); j++) {
  14747. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14748. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14749. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14750. if (mob && qi->objectives[j]->mob_id > 0)
  14751. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14752. else
  14753. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14754. }
  14755. }
  14756. WFIFOSET(fd, len);
  14757. }
  14758. /// Notification about a new quest
  14759. /// 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)
  14760. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14761. /// 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)
  14762. void clif_quest_add(map_session_data *sd, struct quest *qd)
  14763. {
  14764. nullpo_retv(sd);
  14765. nullpo_retv(qd);
  14766. int32 fd = sd->fd;
  14767. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14768. if (!qi)
  14769. return;
  14770. #if PACKETVER >= 20150513
  14771. int32 cmd = 0x9f9;
  14772. #else
  14773. int32 cmd = 0x2b3;
  14774. #endif
  14775. WFIFOHEAD(fd, packet_len(cmd));
  14776. WFIFOW(fd, 0) = cmd;
  14777. WFIFOL(fd, 2) = qd->quest_id;
  14778. WFIFOB(fd, 6) = qd->state;
  14779. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14780. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14781. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14782. for (int32 i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14783. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14784. e_race race = qi->objectives[i]->race;
  14785. e_size size = qi->objectives[i]->size;
  14786. e_element element = qi->objectives[i]->element;
  14787. #if PACKETVER >= 20150513
  14788. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14789. offset += 4;
  14790. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14791. offset += 4;
  14792. #endif
  14793. 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
  14794. offset += 4;
  14795. #if PACKETVER >= 20150513
  14796. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14797. offset += 2;
  14798. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14799. offset += 2;
  14800. #endif
  14801. WFIFOW(fd, offset) = qd->count[i];
  14802. offset += 2;
  14803. if (mob && qi->objectives[i]->mob_id > 0)
  14804. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14805. else
  14806. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14807. offset += NAME_LENGTH;
  14808. }
  14809. WFIFOSET(fd, packet_len(cmd));
  14810. #if PACKETVER >= 20150513
  14811. int16 len;
  14812. len = static_cast<decltype(len)>( 4 + qi->objectives.size() * 12 );
  14813. WFIFOHEAD(fd, len);
  14814. WFIFOW(fd, 0) = 0x8fe;
  14815. WFIFOW(fd, 2) = len;
  14816. for (int32 i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14817. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14818. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  14819. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  14820. WFIFOW(fd, offset + 10) = qd->count[i];
  14821. }
  14822. WFIFOSET(fd, len);
  14823. #endif
  14824. }
  14825. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14826. /// 02b4 <quest id>.L
  14827. void clif_quest_delete(map_session_data *sd, int32 quest_id)
  14828. {
  14829. int32 fd = sd->fd;
  14830. WFIFOHEAD(fd, packet_len(0x2b4));
  14831. WFIFOW(fd, 0) = 0x2b4;
  14832. WFIFOL(fd, 2) = quest_id;
  14833. WFIFOSET(fd, packet_len(0x2b4));
  14834. }
  14835. /// Notification of an update to the hunting mission counter
  14836. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14837. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14838. void clif_quest_update_objective(map_session_data *sd, struct quest *qd)
  14839. {
  14840. int32 fd = sd->fd;
  14841. int32 offset = 6;
  14842. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14843. int16 len;
  14844. len = static_cast<decltype(len)>( qi->objectives.size() * 12 + 6 );
  14845. #if PACKETVER >= 20150513
  14846. int32 cmd = 0x9fa;
  14847. #else
  14848. int32 cmd = 0x2b5;
  14849. #endif
  14850. WFIFOHEAD(fd, len);
  14851. WFIFOW(fd, 0) = cmd;
  14852. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  14853. for (int32 i = 0; i < qi->objectives.size(); i++) {
  14854. WFIFOL(fd, offset) = qd->quest_id;
  14855. offset += 4;
  14856. #if PACKETVER >= 20150513
  14857. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14858. offset += 4;
  14859. #else
  14860. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14861. offset += 4;
  14862. #endif
  14863. WFIFOW(fd, offset) = qi->objectives[i]->count;
  14864. offset += 2;
  14865. WFIFOW(fd, offset) = qd->count[i];
  14866. offset += 2;
  14867. }
  14868. WFIFOW(fd, 2) = offset;
  14869. WFIFOSET(fd, offset);
  14870. }
  14871. /// Request to change the state of a quest.
  14872. /// 02b6 <quest id>.L <active>.B (CZ_ACTIVE_QUEST)
  14873. void clif_parse_questStateAck( int32 fd, map_session_data* sd ){
  14874. #if PACKETVER >= 20070622
  14875. const PACKET_CZ_ACTIVE_QUEST* p = reinterpret_cast<PACKET_CZ_ACTIVE_QUEST*>( RFIFOP( fd, 0 ) );
  14876. quest_update_status( sd, p->quest_id, ( p->active != 0 ) ? Q_ACTIVE : Q_INACTIVE );
  14877. #endif
  14878. }
  14879. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14880. /// 02b7 <quest id>.L <active>.B
  14881. void clif_quest_update_status(map_session_data *sd, int32 quest_id, bool active)
  14882. {
  14883. int32 fd = sd->fd;
  14884. WFIFOHEAD(fd, packet_len(0x2b7));
  14885. WFIFOW(fd, 0) = 0x2b7;
  14886. WFIFOL(fd, 2) = quest_id;
  14887. WFIFOB(fd, 6) = active;
  14888. WFIFOSET(fd, packet_len(0x2b7));
  14889. }
  14890. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14891. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14892. /// effect:
  14893. /// 0 = none
  14894. /// 1 = exclamation mark icon
  14895. /// 2 = question mark icon
  14896. /// color:
  14897. /// 0 = yellow
  14898. /// 1 = orange
  14899. /// 2 = green
  14900. /// 3 = purple
  14901. void clif_quest_show_event(map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14902. {
  14903. #if PACKETVER >= 20090218
  14904. nullpo_retv(sd);
  14905. nullpo_retv(bl);
  14906. int32 fd = sd->fd;
  14907. WFIFOHEAD(fd, packet_len(0x446));
  14908. WFIFOW(fd, 0) = 0x446;
  14909. WFIFOL(fd, 2) = bl->id;
  14910. WFIFOW(fd, 6) = bl->x;
  14911. WFIFOW(fd, 8) = bl->y;
  14912. WFIFOW(fd, 10) = effect;
  14913. WFIFOW(fd, 12) = color;
  14914. WFIFOSET(fd, packet_len(0x446));
  14915. #endif
  14916. }
  14917. /// Mercenary System
  14918. ///
  14919. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14920. /// 02a2 <var id>.W <value>.L
  14921. void clif_mercenary_updatestatus(map_session_data *sd, int32 type)
  14922. {
  14923. s_mercenary_data *md;
  14924. struct status_data *status;
  14925. int32 fd;
  14926. if( !clif_session_isValid(sd) || (md = sd->md) == nullptr )
  14927. return;
  14928. fd = sd->fd;
  14929. status = &md->battle_status;
  14930. WFIFOHEAD(fd,packet_len(0x2a2));
  14931. WFIFOW(fd,0) = 0x2a2;
  14932. WFIFOW(fd,2) = type;
  14933. switch( type ) {
  14934. case SP_ATK1:
  14935. {
  14936. int32 atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14937. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14938. }
  14939. break;
  14940. case SP_MATK1:
  14941. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14942. break;
  14943. case SP_HIT:
  14944. WFIFOL(fd,4) = status->hit;
  14945. break;
  14946. case SP_CRITICAL:
  14947. WFIFOL(fd,4) = status->cri/10;
  14948. break;
  14949. case SP_DEF1:
  14950. WFIFOL(fd,4) = status->def;
  14951. break;
  14952. case SP_MDEF1:
  14953. WFIFOL(fd,4) = status->mdef;
  14954. break;
  14955. case SP_MERCFLEE:
  14956. WFIFOL(fd,4) = status->flee;
  14957. break;
  14958. case SP_ASPD:
  14959. WFIFOL(fd,4) = status->amotion;
  14960. break;
  14961. case SP_HP:
  14962. WFIFOL(fd,4) = status->hp;
  14963. break;
  14964. case SP_MAXHP:
  14965. WFIFOL(fd,4) = status->max_hp;
  14966. break;
  14967. case SP_SP:
  14968. WFIFOL(fd,4) = status->sp;
  14969. break;
  14970. case SP_MAXSP:
  14971. WFIFOL(fd,4) = status->max_sp;
  14972. break;
  14973. case SP_MERCKILLS:
  14974. WFIFOL(fd,4) = md->mercenary.kill_count;
  14975. break;
  14976. case SP_MERCFAITH:
  14977. WFIFOL(fd,4) = mercenary_get_faith(md);
  14978. break;
  14979. }
  14980. WFIFOSET(fd,packet_len(0x2a2));
  14981. }
  14982. /// Mercenary base status data (ZC_MER_INIT).
  14983. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14984. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14985. /// <calls>.L <kills>.L <atk range>.W
  14986. void clif_mercenary_info(map_session_data *sd)
  14987. {
  14988. int32 fd;
  14989. s_mercenary_data *md;
  14990. struct status_data *status;
  14991. int32 atk;
  14992. if( !clif_session_isValid(sd) || (md = sd->md) == nullptr )
  14993. return;
  14994. fd = sd->fd;
  14995. status = &md->battle_status;
  14996. WFIFOHEAD(fd,packet_len(0x29b));
  14997. WFIFOW(fd,0) = 0x29b;
  14998. WFIFOL(fd,2) = md->bl.id;
  14999. // Mercenary shows ATK as a random value between ATK ~ ATK2
  15000. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  15001. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  15002. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  15003. WFIFOW(fd,10) = status->hit;
  15004. WFIFOW(fd,12) = status->cri/10;
  15005. WFIFOW(fd,14) = status->def;
  15006. WFIFOW(fd,16) = status->mdef;
  15007. WFIFOW(fd,18) = status->flee;
  15008. WFIFOW(fd,20) = status->amotion;
  15009. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  15010. WFIFOW(fd,46) = md->db->lv;
  15011. WFIFOL(fd,48) = status->hp;
  15012. WFIFOL(fd,52) = status->max_hp;
  15013. WFIFOL(fd,56) = status->sp;
  15014. WFIFOL(fd,60) = status->max_sp;
  15015. WFIFOL(fd,64) = client_tick(time(nullptr) + (mercenary_get_lifetime(md) / 1000));
  15016. WFIFOW(fd,68) = mercenary_get_faith(md);
  15017. WFIFOL(fd,70) = mercenary_get_calls(md);
  15018. WFIFOL(fd,74) = md->mercenary.kill_count;
  15019. WFIFOW(fd,78) = md->battle_status.rhw.range;
  15020. WFIFOSET(fd,packet_len(0x29b));
  15021. }
  15022. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  15023. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  15024. void clif_mercenary_skillblock(map_session_data *sd)
  15025. {
  15026. s_mercenary_data *md;
  15027. int32 fd, len = 4;
  15028. if( sd == nullptr || (md = sd->md) == nullptr )
  15029. return;
  15030. fd = sd->fd;
  15031. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15032. WFIFOW(fd,0) = 0x29d;
  15033. for (const auto &it : md->db->skill) {
  15034. uint16 id = it.first;
  15035. if (!SKILL_CHK_MERC(id))
  15036. continue;
  15037. uint16 lv = it.second;
  15038. WFIFOW(fd,len) = id;
  15039. WFIFOL(fd,len+2) = skill_get_inf(id);
  15040. WFIFOW(fd,len+6) = lv;
  15041. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15042. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15043. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15044. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15045. len += 37;
  15046. }
  15047. WFIFOW(fd,2) = len;
  15048. WFIFOSET(fd,len);
  15049. }
  15050. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15051. /// 029f <command>.B
  15052. /// 1 = mercenary information
  15053. /// 2 = delete
  15054. void clif_parse_mercenary_action(int32 fd, map_session_data* sd)
  15055. {
  15056. int32 option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15057. if( sd->md == nullptr )
  15058. return;
  15059. if( option == 2 ) mercenary_delete(sd->md, 2);
  15060. }
  15061. /// Notification about the remaining time of a rental item.
  15062. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15063. void clif_rental_time( map_session_data* sd, t_itemid nameid, int32 seconds ){
  15064. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15065. PACKET_ZC_CASH_TIME_COUNTER p = {};
  15066. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15067. p.itemId = client_nameid( nameid );
  15068. p.seconds = seconds;
  15069. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15070. }
  15071. /// Deletes a rental item from client's inventory.
  15072. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15073. void clif_rental_expired( map_session_data* sd, int32 index, t_itemid nameid ){
  15074. // '<ItemName>' item has been deleted from the Inventory
  15075. PACKET_ZC_CASH_ITEM_DELETE p = {};
  15076. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15077. p.index = client_index( index );
  15078. p.itemId = client_nameid( nameid );
  15079. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15080. }
  15081. /// Book Reading (ZC_READ_BOOK).
  15082. /// 0294 <book id>.L <page>.L
  15083. void clif_readbook(int32 fd, int32 book_id, int32 page)
  15084. {
  15085. WFIFOHEAD(fd,packet_len(0x294));
  15086. WFIFOW(fd,0) = 0x294;
  15087. WFIFOL(fd,2) = book_id;
  15088. WFIFOL(fd,6) = page;
  15089. WFIFOSET(fd,packet_len(0x294));
  15090. }
  15091. /// Battlegrounds
  15092. ///
  15093. /// Updates HP bar of a camp member.
  15094. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15095. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15096. void clif_bg_hp(map_session_data *sd) {
  15097. #if PACKETVER < 20140613
  15098. unsigned char buf[34];
  15099. const int32 cmd = 0x2e0;
  15100. #else
  15101. unsigned char buf[14];
  15102. const int32 cmd = 0xa0e;
  15103. #endif
  15104. nullpo_retv(sd);
  15105. WBUFW(buf,0) = cmd;
  15106. WBUFL(buf,2) = sd->status.account_id;
  15107. #if PACKETVER < 20140613
  15108. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15109. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15110. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15111. WBUFW(buf,32) = 100;
  15112. } else {
  15113. WBUFW(buf,30) = sd->battle_status.hp;
  15114. WBUFW(buf,32) = sd->battle_status.max_hp;
  15115. }
  15116. #else
  15117. if( sd->battle_status.max_hp > INT32_MAX ) {
  15118. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15119. WBUFL(buf,10) = 100;
  15120. } else {
  15121. WBUFL(buf,6) = sd->battle_status.hp;
  15122. WBUFL(buf,10) = sd->battle_status.max_hp;
  15123. }
  15124. #endif
  15125. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15126. }
  15127. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15128. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15129. void clif_bg_xy(map_session_data *sd)
  15130. {
  15131. unsigned char buf[36];
  15132. nullpo_retv(sd);
  15133. WBUFW(buf,0)=0x2df;
  15134. WBUFL(buf,2)=sd->status.account_id;
  15135. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15136. WBUFW(buf,30)=sd->status.class_;
  15137. WBUFW(buf,32)=sd->bl.x;
  15138. WBUFW(buf,34)=sd->bl.y;
  15139. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15140. }
  15141. void clif_bg_xy_remove(map_session_data *sd)
  15142. {
  15143. unsigned char buf[36];
  15144. nullpo_retv(sd);
  15145. WBUFW(buf,0)=0x2df;
  15146. WBUFL(buf,2)=sd->status.account_id;
  15147. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15148. WBUFW(buf,30)=0;
  15149. WBUFW(buf,32)=-1;
  15150. WBUFW(buf,34)=-1;
  15151. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15152. }
  15153. /// Notifies clients of a battleground message.
  15154. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15155. void clif_bg_message( struct s_battleground_data *bg, int32 src_id, const char *name, const char *mes, size_t len ){
  15156. map_session_data *sd = bg_getavailablesd( bg );
  15157. if( sd == nullptr ){
  15158. return;
  15159. }
  15160. // limit length
  15161. len = zmin( len + 1, CHAT_SIZE_MAX );
  15162. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15163. WBUFW(buf,0) = 0x2dc;
  15164. WBUFW(buf,2) = static_cast<int16>( len + NAME_LENGTH + 8 );
  15165. WBUFL(buf,4) = src_id;
  15166. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15167. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15168. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15169. }
  15170. /// Validates and processes battlechat messages.
  15171. /// All messages that are sent after enabling battleground chat with /battlechat.
  15172. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15173. void clif_parse_BattleChat(int32 fd, map_session_data* sd){
  15174. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15175. if( !clif_process_message( sd, false, name, message, output ) )
  15176. return;
  15177. bg_send_message(sd, output, strlen(output) );
  15178. }
  15179. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15180. /// 02de <camp A points>.W <camp B points>.W
  15181. void clif_bg_updatescore(int16 m)
  15182. {
  15183. struct block_list bl;
  15184. unsigned char buf[6];
  15185. struct map_data *mapdata = map_getmapdata(m);
  15186. bl.id = 0;
  15187. bl.type = BL_NUL;
  15188. bl.m = m;
  15189. WBUFW(buf,0) = 0x2de;
  15190. WBUFW(buf,2) = mapdata->bgscore_lion;
  15191. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15192. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15193. }
  15194. void clif_bg_updatescore_single(map_session_data *sd)
  15195. {
  15196. int32 fd;
  15197. nullpo_retv(sd);
  15198. fd = sd->fd;
  15199. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15200. WFIFOHEAD(fd,packet_len(0x2de));
  15201. WFIFOW(fd,0) = 0x2de;
  15202. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15203. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15204. WFIFOSET(fd,packet_len(0x2de));
  15205. }
  15206. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15207. /// 02dd <account id>.L <name>.24B <camp>.W
  15208. void clif_sendbgemblem_area(map_session_data *sd)
  15209. {
  15210. unsigned char buf[33];
  15211. nullpo_retv(sd);
  15212. WBUFW(buf, 0) = 0x2dd;
  15213. WBUFL(buf,2) = sd->bl.id;
  15214. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15215. WBUFW(buf,30) = sd->bg_id;
  15216. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15217. }
  15218. void clif_sendbgemblem_single(int32 fd, map_session_data *sd)
  15219. {
  15220. nullpo_retv(sd);
  15221. WFIFOHEAD(fd,32);
  15222. WFIFOW(fd,0) = 0x2dd;
  15223. WFIFOL(fd,2) = sd->bl.id;
  15224. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15225. WFIFOW(fd,30) = sd->bg_id;
  15226. WFIFOSET(fd,packet_len(0x2dd));
  15227. }
  15228. /// Battlegrounds queue incoming apply request from client.
  15229. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15230. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15231. void clif_parse_bg_queue_apply_request(int32 fd, map_session_data *sd)
  15232. {
  15233. if (!battle_config.feature_bgqueue)
  15234. return;
  15235. nullpo_retv(sd);
  15236. int16 type = RFIFOW(fd,2);
  15237. char name[NAME_LENGTH];
  15238. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15239. if (sd->bg_queue_id > 0) {
  15240. //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);
  15241. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15242. return;
  15243. } else if (type == 1) // Solo
  15244. bg_queue_join_solo(name, sd);
  15245. else if (type == 2) // Party
  15246. bg_queue_join_party(name, sd);
  15247. else if (type == 4) // Guild
  15248. bg_queue_join_guild(name, sd);
  15249. else {
  15250. 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);
  15251. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15252. return;
  15253. }
  15254. }
  15255. /// Outgoing battlegrounds queue apply result.
  15256. /// Result types: @see e_bg_queue_apply_ack
  15257. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15258. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, map_session_data *sd)
  15259. {
  15260. nullpo_retv(sd);
  15261. int32 fd = sd->fd;
  15262. WFIFOHEAD(fd, packet_len(0x8d8));
  15263. WFIFOW(fd,0) = 0x8d8;
  15264. WFIFOB(fd,2) = result;
  15265. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15266. WFIFOSET(fd, packet_len(0x8d8));
  15267. }
  15268. /// Outgoing battlegrounds queue apply notification.
  15269. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15270. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15271. void clif_bg_queue_apply_notify(const char *name, map_session_data *sd)
  15272. {
  15273. nullpo_retv(sd);
  15274. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15275. if (queue == nullptr) {
  15276. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15277. return;
  15278. }
  15279. int32 fd = sd->fd;
  15280. WFIFOHEAD(fd, packet_len(0x8d9));
  15281. WFIFOW(fd,0) = 0x8d9;
  15282. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15283. WFIFOL(fd,2+NAME_LENGTH) = static_cast<int32>( queue->teama_members.size() + queue->teamb_members.size() );
  15284. WFIFOSET(fd, packet_len(0x8d9));
  15285. }
  15286. /// Battlegrounds queue outgoing cancel result.
  15287. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15288. void clif_bg_queue_cancel_result(bool success, const char *name, map_session_data *sd)
  15289. {
  15290. nullpo_retv(sd);
  15291. int32 fd = sd->fd;
  15292. WFIFOHEAD(fd, packet_len(0x8d8));
  15293. WFIFOW(fd,0) = 0x8db;
  15294. WFIFOB(fd,2) = success;
  15295. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15296. WFIFOSET(fd, packet_len(0x8d8));
  15297. }
  15298. /// Battlegrounds queue incoming cancel request from client.
  15299. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15300. void clif_parse_bg_queue_cancel_request(int32 fd, map_session_data *sd)
  15301. {
  15302. if (!battle_config.feature_bgqueue)
  15303. return;
  15304. nullpo_retv(sd);
  15305. bool success;
  15306. if (sd->bg_queue_id > 0) {
  15307. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15308. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15309. 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.
  15310. else
  15311. success = bg_queue_leave(sd);
  15312. } else {
  15313. 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);
  15314. success = false;
  15315. }
  15316. char name[NAME_LENGTH];
  15317. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15318. clif_bg_queue_cancel_result(success, name, sd);
  15319. }
  15320. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15321. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15322. void clif_bg_queue_lobby_notify(const char *name, map_session_data *sd)
  15323. {
  15324. nullpo_retv(sd);
  15325. int32 fd = sd->fd;
  15326. WFIFOHEAD(fd, packet_len(0x8df));
  15327. WFIFOW(fd,0) = 0x8df;
  15328. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15329. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15330. WFIFOSET(fd, packet_len(0x8df));
  15331. }
  15332. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15333. /// Result types: 1(Accept), 2(Decline).
  15334. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15335. void clif_parse_bg_queue_lobby_reply(int32 fd, map_session_data *sd)
  15336. {
  15337. nullpo_retv(sd);
  15338. if(sd->bg_queue_id > 0) {
  15339. uint8 result = RFIFOB(fd, 2);
  15340. if(result == 1) { // Accept
  15341. bg_queue_on_accept_invite(sd);
  15342. } else if(result == 2) { // Decline
  15343. bg_queue_leave(sd);
  15344. clif_bg_queue_entry_init(sd);
  15345. }
  15346. }
  15347. }
  15348. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15349. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15350. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, map_session_data *sd)
  15351. {
  15352. nullpo_retv(sd);
  15353. int32 fd = sd->fd;
  15354. WFIFOHEAD(fd, packet_len(0x8e1));
  15355. WFIFOW(fd,0) = 0x8e1;
  15356. WFIFOB(fd,2) = result;
  15357. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15358. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15359. WFIFOSET(fd, packet_len(0x8e1));
  15360. }
  15361. /// Battlegrounds queue incoming queue number request from client.
  15362. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15363. void clif_parse_bg_queue_request_queue_number(int32 fd, map_session_data *sd)
  15364. {
  15365. nullpo_retv(sd);
  15366. char name[NAME_LENGTH];
  15367. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15368. clif_bg_queue_apply_notify(name, sd);
  15369. }
  15370. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15371. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15372. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15373. void clif_bg_queue_entry_init(map_session_data *sd)
  15374. {
  15375. nullpo_retv(sd);
  15376. PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15377. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15378. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15379. }
  15380. /// Custom Fonts (ZC_NOTIFY_FONT).
  15381. /// 02ef <account_id>.L <font id>.W
  15382. void clif_font(map_session_data *sd)
  15383. {
  15384. #if PACKETVER >= 20080102
  15385. unsigned char buf[8];
  15386. nullpo_retv(sd);
  15387. WBUFW(buf,0) = 0x2ef;
  15388. WBUFL(buf,2) = sd->bl.id;
  15389. WBUFW(buf,6) = sd->status.font;
  15390. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15391. #endif
  15392. }
  15393. /// Required to start the instancing information window on Client
  15394. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15395. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15396. void clif_instance_create( int32 instance_id, size_t num ){
  15397. #if PACKETVER >= 20071128
  15398. map_session_data *sd = nullptr;
  15399. enum send_target target = PARTY;
  15400. unsigned char buf[65];
  15401. instance_getsd(instance_id, sd, &target);
  15402. if (!sd)
  15403. return;
  15404. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15405. if (!db)
  15406. return;
  15407. WBUFW(buf,0) = 0x2cb;
  15408. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15409. WBUFW( buf, 63 ) = static_cast<int16>( num );
  15410. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15411. #endif
  15412. }
  15413. /// To announce Instancing queue creation if no maps available
  15414. /// S 0x2cc <Standby Position>.W
  15415. void clif_instance_changewait(int32 instance_id, int32 num)
  15416. {
  15417. #if PACKETVER >= 20071128
  15418. map_session_data *sd = nullptr;
  15419. enum send_target target = PARTY;
  15420. unsigned char buf[4];
  15421. instance_getsd(instance_id, sd, &target);
  15422. if (!sd)
  15423. return;
  15424. WBUFW(buf,0) = 0x2cc;
  15425. WBUFW(buf,2) = num;
  15426. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15427. #endif
  15428. return;
  15429. }
  15430. /// Notify the current status to members
  15431. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15432. void clif_instance_status(int32 instance_id, uint32 limit1, uint32 limit2)
  15433. {
  15434. #if PACKETVER >= 20071128
  15435. map_session_data *sd = nullptr;
  15436. enum send_target target = PARTY;
  15437. unsigned char buf[71];
  15438. instance_getsd(instance_id, sd, &target);
  15439. if (!sd)
  15440. return;
  15441. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15442. if (!db)
  15443. return;
  15444. WBUFW(buf,0) = 0x2cd;
  15445. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15446. WBUFL(buf,63) = limit1;
  15447. WBUFL(buf,67) = limit2;
  15448. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15449. #endif
  15450. return;
  15451. }
  15452. /// Notify a status change to members
  15453. /// S 0x2ce <Message ID>.L
  15454. /// 0 = Notification (EnterLimitDate update?)
  15455. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15456. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15457. /// 3 = The Memorial Dungeon has been removed.
  15458. /// 4 = Create failure (removes the instance window)
  15459. void clif_instance_changestatus(int32 instance_id, e_instance_notify type, uint32 limit)
  15460. {
  15461. #if PACKETVER >= 20071128
  15462. map_session_data *sd = nullptr;
  15463. enum send_target target = PARTY;
  15464. unsigned char buf[10];
  15465. instance_getsd(instance_id, sd, &target);
  15466. if (!sd)
  15467. return;
  15468. WBUFW(buf,0) = 0x2ce;
  15469. WBUFL(buf,2) = type;
  15470. WBUFL(buf,6) = limit;
  15471. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15472. #endif
  15473. return;
  15474. }
  15475. /// Destroy an instance from the status window
  15476. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15477. void clif_parse_MemorialDungeonCommand(int32 fd, map_session_data *sd)
  15478. {
  15479. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15480. return;
  15481. const PACKET_CZ_MEMORIALDUNGEON_COMMAND* p = reinterpret_cast<PACKET_CZ_MEMORIALDUNGEON_COMMAND*>( RFIFOP( fd, 0 ) );
  15482. switch (p->command) {
  15483. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15484. instance_destroy_command(sd);
  15485. break;
  15486. }
  15487. }
  15488. void clif_instance_info( map_session_data& sd ){
  15489. if( sd.instance_id > 0 ){
  15490. instance_reqinfo( &sd, sd.instance_id );
  15491. }
  15492. if( sd.status.party_id > 0 ){
  15493. struct party_data* p = party_search( sd.status.party_id );
  15494. if( p != nullptr && p->instance_id > 0 ){
  15495. instance_reqinfo( &sd, p->instance_id );
  15496. }
  15497. }
  15498. if( sd.guild != nullptr && sd.guild->instance_id > 0 ){
  15499. instance_reqinfo( &sd, sd.guild->instance_id );
  15500. }
  15501. if( sd.clan != nullptr && sd.clan->instance_id > 0 ){
  15502. instance_reqinfo( &sd, sd.clan->instance_id );
  15503. }
  15504. }
  15505. /// Notifies clients about item picked up by a party member.
  15506. /// 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)
  15507. void clif_party_show_picker( map_session_data* sd, struct item* item_data ){
  15508. #if PACKETVER >= 20071002
  15509. nullpo_retv( sd );
  15510. nullpo_retv( item_data );
  15511. struct item_data* id = itemdb_search( item_data->nameid );
  15512. PACKET_ZC_ITEM_PICKUP_PARTY p = {};
  15513. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15514. p.AID = sd->status.account_id;
  15515. p.itemId = client_nameid( item_data->nameid );
  15516. p.identified = item_data->identify;
  15517. p.damaged = item_data->attribute;
  15518. p.refine = item_data->refine;
  15519. clif_addcards( &p.slot, item_data );
  15520. p.location = id->equip; // equip location
  15521. p.itemType = itemtype( id->nameid ); // item type
  15522. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15523. p.grade = item_data->enchantgrade;
  15524. #endif
  15525. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15526. #endif
  15527. }
  15528. /** Display gained exp.
  15529. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15530. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15531. * amount: INT32_MIN ~ INT32_MAX
  15532. * var id:
  15533. * SP_BASEEXP, SP_JOBEXP
  15534. * exp type:
  15535. * 0 = normal exp gained/lost
  15536. * 1 = quest exp gained/lost
  15537. * @param sd Player
  15538. * @param exp EXP value gained/loss
  15539. * @param type SP_BASEEXP, SP_JOBEXP
  15540. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15541. * @param lost True:if losing EXP
  15542. */
  15543. void clif_displayexp(map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15544. {
  15545. int32 fd;
  15546. int32 offset;
  15547. #if PACKETVER >= 20170830
  15548. int32 cmd = 0xacc;
  15549. #else
  15550. int32 cmd = 0x7f6;
  15551. #endif
  15552. nullpo_retv(sd);
  15553. fd = sd->fd;
  15554. WFIFOHEAD(fd, packet_len(cmd));
  15555. WFIFOW(fd,0) = cmd;
  15556. WFIFOL(fd,2) = sd->bl.id;
  15557. #if PACKETVER >= 20170830
  15558. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15559. offset = 4;
  15560. #else
  15561. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15562. offset = 0;
  15563. #endif
  15564. WFIFOW(fd,10+offset) = type;
  15565. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15566. WFIFOSET(fd,packet_len(cmd));
  15567. }
  15568. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15569. /// type:
  15570. /// 0 = Displays 'value' for 5 seconds.
  15571. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15572. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15573. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15574. /// value:
  15575. /// 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).
  15576. void clif_showdigit(map_session_data* sd, unsigned char type, int32 value)
  15577. {
  15578. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15579. WFIFOW(sd->fd,0) = 0x1b1;
  15580. WFIFOB(sd->fd,2) = type;
  15581. WFIFOL(sd->fd,3) = value;
  15582. WFIFOSET(sd->fd, packet_len(0x1b1));
  15583. }
  15584. /// Notification of the state of client command /effect.
  15585. /// 021d <state>.L (CZ_LESSEFFECT)
  15586. /// state:
  15587. /// 0 = Full effects
  15588. /// 1 = Reduced effects
  15589. ///
  15590. /// NOTE: The state is used on Aegis for sending skill unit packet
  15591. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15592. /// whenever possible. Due to the way the decision check is
  15593. /// constructed, this state tracking was rendered useless,
  15594. /// as the only skill unit, that is sent with 0x1c9 is
  15595. /// Graffiti.
  15596. void clif_parse_LessEffect(int32 fd, map_session_data* sd){
  15597. #if PACKETVER >= 20041115
  15598. const PACKET_CZ_LESSEFFECT* p = reinterpret_cast<PACKET_CZ_LESSEFFECT*>( RFIFOP( fd, 0 ) );
  15599. sd->state.lesseffect = p->state != 0;
  15600. #endif
  15601. }
  15602. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15603. void clif_parse_ItemListWindowSelected(int32 fd, map_session_data* sd) {
  15604. if( sd == nullptr ){
  15605. return;
  15606. }
  15607. // TODO: shuffle packet
  15608. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15609. int32 n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15610. int32 type = RFIFOL(fd,info->pos[1]);
  15611. int32 flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15612. uint16* item_list = (uint16*)RFIFOP(fd,info->pos[3]);
  15613. if( sd->state.trading || sd->npc_shopid )
  15614. return;
  15615. if( flag == 0 || n == 0) {
  15616. clif_menuskill_clear(sd);
  15617. return; // Canceled by player.
  15618. }
  15619. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15620. clif_menuskill_clear(sd);
  15621. return; // Prevent hacking.
  15622. }
  15623. switch( type ) {
  15624. case 0: // Change Material
  15625. skill_changematerial(sd,n,item_list);
  15626. break;
  15627. case 1: // Level 1: Pure to Rough
  15628. case 2: // Level 2: Rough to Pure
  15629. skill_elementalanalysis(*sd,n,type,item_list);
  15630. break;
  15631. }
  15632. clif_menuskill_clear(sd);
  15633. return;
  15634. }
  15635. /*==========================================
  15636. * Elemental System
  15637. *==========================================*/
  15638. /// Notifies client of a change in an elemental's status parameter.
  15639. /// 0x81e <type>.W <value>.L (ZC_EL_PAR_CHANGE)
  15640. void clif_elemental_updatestatus(map_session_data& sd, _sp type) {
  15641. #if PACKETVER >= 20100309
  15642. if (sd.ed == nullptr)
  15643. return;
  15644. PACKET_ZC_EL_PAR_CHANGE p = {};
  15645. p.packetType = HEADER_ZC_EL_PAR_CHANGE;
  15646. p.type = static_cast<decltype(p.type)>(type);
  15647. status_data* status = &sd.ed->battle_status;
  15648. switch( type ) {
  15649. case SP_HP:
  15650. p.value = static_cast<decltype(p.value)>(status->hp);
  15651. break;
  15652. case SP_MAXHP:
  15653. p.value = static_cast<decltype(p.value)>(status->max_hp);
  15654. break;
  15655. case SP_SP:
  15656. p.value = static_cast<decltype(p.value)>(status->sp);
  15657. break;
  15658. case SP_MAXSP:
  15659. p.value = static_cast<decltype(p.value)>(status->max_sp);
  15660. break;
  15661. }
  15662. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  15663. #endif
  15664. }
  15665. void clif_elemental_info(map_session_data *sd) {
  15666. int32 fd;
  15667. s_elemental_data *ed;
  15668. struct status_data *status;
  15669. if( !clif_session_isValid(sd) || (ed = sd->ed) == nullptr )
  15670. return;
  15671. fd = sd->fd;
  15672. status = &ed->battle_status;
  15673. WFIFOHEAD(fd,22);
  15674. WFIFOW(fd, 0) = 0x81d;
  15675. WFIFOL(fd, 2) = ed->bl.id;
  15676. WFIFOL(fd, 6) = status->hp;
  15677. WFIFOL(fd,10) = status->max_hp;
  15678. WFIFOL(fd,14) = status->sp;
  15679. WFIFOL(fd,18) = status->max_sp;
  15680. WFIFOSET(fd,22);
  15681. }
  15682. /// Buying Store System
  15683. ///
  15684. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15685. /// 0810 <slots>.B
  15686. void clif_buyingstore_open(map_session_data* sd)
  15687. {
  15688. int32 fd = sd->fd;
  15689. WFIFOHEAD(fd,packet_len(0x810));
  15690. WFIFOW(fd,0) = 0x810;
  15691. WFIFOB(fd,2) = sd->buyingstore.slots;
  15692. WFIFOSET(fd,packet_len(0x810));
  15693. }
  15694. /// Request to create a buying store.
  15695. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }* (CZ_REQ_OPEN_BUYING_STORE)
  15696. /// result:
  15697. /// 0 = cancel
  15698. /// 1 = open
  15699. static void clif_parse_ReqOpenBuyingStore( int32 fd, map_session_data* sd ){
  15700. const PACKET_CZ_REQ_OPEN_BUYING_STORE* p = reinterpret_cast<PACKET_CZ_REQ_OPEN_BUYING_STORE*>( RFIFOP( fd, 0 ) );
  15701. // TODO: Make this check global for all variable length packets.
  15702. // minimum packet length
  15703. if( p->packetLength < sizeof( *p ) ){
  15704. ShowError( "clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%" PRIdPTR ", length=%u, account_id=%d).\n", sizeof( *p ), p->packetLength, sd->bl.id );
  15705. return;
  15706. }
  15707. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15708. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15709. return;
  15710. }
  15711. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15712. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15713. return;
  15714. }
  15715. char storename[MESSAGE_SIZE];
  15716. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15717. // so that buyingstore_create knows, how many elements it has access to
  15718. int32 packet_len = p->packetLength - sizeof( *p );
  15719. if( packet_len % sizeof( p->items[0] ) ){
  15720. ShowError( "clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%" PRIdPTR ")\n", packet_len, sd->bl.id, sizeof( p->items[0] ) );
  15721. return;
  15722. }
  15723. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( p->items[0] ), nullptr );
  15724. }
  15725. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15726. /// 0812 <result>.W <total weight>.L
  15727. /// result:
  15728. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15729. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15730. /// 8 = "No sale (purchase) information available." (0x705)
  15731. /// ? = nothing
  15732. void clif_buyingstore_open_failed(map_session_data* sd, uint16 result, uint32 weight)
  15733. {
  15734. int32 fd = sd->fd;
  15735. WFIFOHEAD(fd,packet_len(0x812));
  15736. WFIFOW(fd,0) = 0x812;
  15737. WFIFOW(fd,2) = result;
  15738. WFIFOL(fd,4) = weight;
  15739. WFIFOSET(fd,packet_len(0x812));
  15740. }
  15741. /// Notification, that the requested buying store was created.
  15742. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }* (ZC_MYITEMLIST_BUYING_STORE)
  15743. void clif_buyingstore_myitemlist( map_session_data& sd ){
  15744. #if PACKETVER >= 20100309
  15745. PACKET_ZC_MYITEMLIST_BUYING_STORE* p = reinterpret_cast<PACKET_ZC_MYITEMLIST_BUYING_STORE*>( packet_buffer );
  15746. p->packetType = HEADER_ZC_MYITEMLIST_BUYING_STORE;
  15747. p->packetLength = sizeof( *p );
  15748. p->AID = sd.bl.id;
  15749. p->zenyLimit = sd.buyingstore.zenylimit;
  15750. for( int32 i = 0; i < sd.buyingstore.slots; i++ ){
  15751. PACKET_ZC_MYITEMLIST_BUYING_STORE_sub& entry = p->items[i];
  15752. entry.price = sd.buyingstore.items[i].price;
  15753. entry.amount = sd.buyingstore.items[i].amount;
  15754. entry.itemType = itemtype( sd.buyingstore.items[i].nameid );
  15755. entry.itemId = client_nameid( sd.buyingstore.items[i].nameid );
  15756. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  15757. }
  15758. clif_send( p, p->packetLength, &sd.bl, SELF );
  15759. #endif
  15760. }
  15761. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15762. /// 0814 <account id>.L <store name>.80B
  15763. void clif_buyingstore_entry( map_session_data& sd, struct block_list* tbl ){
  15764. #if PACKETVER >= 20100420
  15765. enum send_target target;
  15766. if( tbl == nullptr ){
  15767. tbl = &sd.bl;
  15768. target = AREA_WOS;
  15769. }else{
  15770. target = SELF;
  15771. }
  15772. PACKET_ZC_BUYING_STORE_ENTRY p = {};
  15773. p.packetType = HEADER_ZC_BUYING_STORE_ENTRY;
  15774. p.makerAID = sd.status.account_id;
  15775. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  15776. clif_send( &p, sizeof( p ), tbl, target );
  15777. #endif
  15778. }
  15779. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15780. /// 0815
  15781. static void clif_parse_ReqCloseBuyingStore(int32 fd, map_session_data* sd)
  15782. {
  15783. buyingstore_close(sd);
  15784. }
  15785. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15786. /// 0816 <account id>.L
  15787. void clif_buyingstore_disappear_entry( map_session_data& sd, struct block_list* tbl ){
  15788. #if PACKETVER >= 20100309
  15789. enum send_target target;
  15790. if( tbl == nullptr ){
  15791. tbl = &sd.bl;
  15792. target = AREA_WOS;
  15793. }else{
  15794. target = SELF;
  15795. }
  15796. PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY p = {};
  15797. p.packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY;
  15798. p.makerAID = sd.status.account_id;
  15799. clif_send( &p, sizeof( p ), tbl, target );
  15800. #endif
  15801. }
  15802. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15803. /// 0817 <account id>.L
  15804. static void clif_parse_ReqClickBuyingStore(int32 fd, map_session_data* sd)
  15805. {
  15806. uint32 account_id;
  15807. // TODO: shuffle packet
  15808. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15809. buyingstore_open(sd, account_id);
  15810. }
  15811. /// Sends buying store item list.
  15812. /// 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)
  15813. void clif_buyingstore_itemlist( map_session_data& sd, map_session_data& pl_sd ){
  15814. #if PACKETVER >= 20100309
  15815. PACKET_ZC_ACK_ITEMLIST_BUYING_STORE* p = reinterpret_cast<PACKET_ZC_ACK_ITEMLIST_BUYING_STORE*>( packet_buffer );
  15816. p->packetType = HEADER_ZC_ACK_ITEMLIST_BUYING_STORE;
  15817. p->packetLength = sizeof( *p );
  15818. p->AID = pl_sd.bl.id;
  15819. p->storeId = pl_sd.buyer_id;
  15820. p->zenyLimit = pl_sd.buyingstore.zenylimit;
  15821. for( int32 i = 0; i < pl_sd.buyingstore.slots; i++ ){
  15822. PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub& entry = p->items[i];
  15823. entry.price = pl_sd.buyingstore.items[i].price;
  15824. entry.amount = pl_sd.buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15825. entry.itemType = itemtype(pl_sd.buyingstore.items[i].nameid);
  15826. entry.itemId = client_nameid( pl_sd.buyingstore.items[i].nameid );
  15827. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  15828. }
  15829. clif_send( p, p->packetLength, &sd.bl, SELF );
  15830. #endif
  15831. }
  15832. /// Request to sell items to a buying store.
  15833. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15834. static void clif_parse_ReqTradeBuyingStore( int32 fd, map_session_data* sd ){
  15835. const PACKET_CZ_REQ_TRADE_BUYING_STORE* p = reinterpret_cast<PACKET_CZ_REQ_TRADE_BUYING_STORE*>( RFIFOP( fd, 0 ) );
  15836. // minimum packet length
  15837. if( p->packetLength < sizeof( *p ) ){
  15838. ShowError( "clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%" PRIdPTR ", length=%u, account_id=%d).\n", sizeof( *p ), p->packetLength, sd->bl.id );
  15839. return;
  15840. }
  15841. // so that buyingstore_trade knows, how many elements it has access to
  15842. int32 packet_len = p->packetLength - sizeof( *p );
  15843. if( packet_len % sizeof( p->items[0] ) ){
  15844. 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( p->items[0] ) );
  15845. return;
  15846. }
  15847. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( p->items[0] ) );
  15848. }
  15849. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15850. /// 081a <result>.W
  15851. /// result:
  15852. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15853. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15854. /// ? = nothing
  15855. void clif_buyingstore_trade_failed_buyer(map_session_data* sd, int16 result)
  15856. {
  15857. int32 fd = sd->fd;
  15858. WFIFOHEAD(fd,packet_len(0x81a));
  15859. WFIFOW(fd,0) = 0x81a;
  15860. WFIFOW(fd,2) = result;
  15861. WFIFOSET(fd,packet_len(0x81a));
  15862. }
  15863. /// Updates the zeny limit and an item in the buying store item list.
  15864. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15865. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15866. void clif_buyingstore_update_item( map_session_data* sd, t_itemid nameid, uint16 amount, uint32 char_id, int32 zeny ){
  15867. PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p = {};
  15868. p.packetType = buyingStoreUpdateItemType;
  15869. p.itemId = client_nameid( nameid );
  15870. p.amount = amount;
  15871. p.zenyLimit = sd->buyingstore.zenylimit;
  15872. #if PACKETVER >= 20141016
  15873. p.zeny = zeny;
  15874. p.charId = char_id; // GID
  15875. p.updateTime = (int32)time(nullptr);
  15876. #endif
  15877. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15878. }
  15879. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15880. /// 081c <index>.W <amount>.W <price>.L
  15881. /// message:
  15882. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15883. ///
  15884. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15885. void clif_buyingstore_delete_item(map_session_data* sd, int16 index, uint16 amount, int32 price)
  15886. {
  15887. int32 fd = sd->fd;
  15888. WFIFOHEAD(fd,packet_len(0x81c));
  15889. WFIFOW(fd,0) = 0x81c;
  15890. WFIFOW(fd,2) = client_index( index );
  15891. WFIFOW(fd,4) = amount;
  15892. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15893. WFIFOSET(fd,packet_len(0x81c));
  15894. }
  15895. /// Notifies the seller, that a buying store trade failed.
  15896. /// 0824 <result>.W <name id>.W (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER)
  15897. /// result:
  15898. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15899. /// 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)
  15900. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15901. /// ? = nothing
  15902. void clif_buyingstore_trade_failed_seller( map_session_data* sd, int16 result, t_itemid nameid ){
  15903. PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p = {};
  15904. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  15905. p.result = result;
  15906. p.itemId = client_nameid( nameid );
  15907. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15908. }
  15909. /// Search Store Info System
  15910. ///
  15911. /// Request to search for stores.
  15912. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }* (CZ_SEARCH_STORE_INFO)
  15913. /// type:
  15914. /// 0 = Vending
  15915. /// 1 = Buying Store
  15916. ///
  15917. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15918. /// amount of card slots. If the client does not know about the item it
  15919. /// cannot be searched.
  15920. static void clif_parse_SearchStoreInfo( int32 fd, map_session_data *sd ){
  15921. if (!battle_config.feature_search_stores)
  15922. return;
  15923. const PACKET_CZ_SEARCH_STORE_INFO* p = reinterpret_cast<PACKET_CZ_SEARCH_STORE_INFO*>( RFIFOP( fd, 0 ) );
  15924. // minimum packet length
  15925. if( p->packetLength < sizeof( *p ) ){
  15926. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected length=%" PRIdPTR ", length=%u, account_id=%d).\n", sizeof( *p ), p->packetLength, sd->bl.id );
  15927. return;
  15928. }
  15929. // check, if there is enough data for the claimed count of items
  15930. int32 packet_len = p->packetLength - sizeof( *p );
  15931. if( packet_len % sizeof( p->items[0] ) ){
  15932. ShowError( "clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%" PRIdPTR ")\n", packet_len, sd->bl.id, sizeof( p->items[0] ) );
  15933. return;
  15934. }
  15935. int32 count = packet_len / sizeof( p->items[0] );
  15936. if( count < p->itemsCount + p->cardsCount ){
  15937. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  15938. return;
  15939. }
  15940. if ( p->searchType > SEARCHTYPE_BUYING_STORE ) {
  15941. ShowError( "clif_parse_SearchStoreInfo: Invalid search type %u (account_id=%d).\n", p->searchType, sd->bl.id );
  15942. return;
  15943. }
  15944. if ( p->minPrice > battle_config.vending_max_value ) {
  15945. ShowError( "clif_parse_SearchStoreInfo: Invalid min price %u (account_id=%d).\n", p->minPrice, sd->bl.id );
  15946. return;
  15947. }
  15948. if ( p->maxPrice > battle_config.vending_max_value ) {
  15949. ShowError( "clif_parse_SearchStoreInfo: Invalid max price %u (account_id=%d).\n", p->maxPrice, sd->bl.id );
  15950. return;
  15951. }
  15952. searchstore_query( *sd, static_cast<e_searchstore_searchtype>(p->searchType), p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  15953. }
  15954. /// Results for a store search request.
  15955. /// 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 }* (ZC_SEARCH_STORE_INFO_ACK)
  15956. /// is first page:
  15957. /// 0 = appends to existing results
  15958. /// 1 = clears previous results before displaying this result set
  15959. /// is next page:
  15960. /// 0 = no "next" label
  15961. /// 1 = "next" label to retrieve more results
  15962. void clif_search_store_info_ack( map_session_data& sd ){
  15963. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  15964. if (!battle_config.feature_search_stores)
  15965. return;
  15966. uint32 start = sd.searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  15967. uint32 end = umin( static_cast<uint32>( sd.searchstore.items.size() ), start + SEARCHSTORE_RESULTS_PER_PAGE );
  15968. PACKET_ZC_SEARCH_STORE_INFO_ACK* p = reinterpret_cast<PACKET_ZC_SEARCH_STORE_INFO_ACK*>( packet_buffer );
  15969. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  15970. p->packetLength = sizeof( *p );
  15971. p->firstPage = !sd.searchstore.pages;
  15972. p->nextPage = searchstore_querynext( sd );
  15973. p->usesCount = static_cast<decltype(p->usesCount)>( std::min<decltype(sd.searchstore.uses)>( sd.searchstore.uses, std::numeric_limits<decltype(p->usesCount)>::max() ) );
  15974. for( int32 i = 0, count = 0; i < end - start; i++ ){
  15975. std::shared_ptr<s_search_store_info_item> ssitem = sd.searchstore.items[start + i];
  15976. if( ssitem == nullptr ){
  15977. continue;
  15978. }
  15979. PACKET_ZC_SEARCH_STORE_INFO_ACK_sub& entry = p->items[count];
  15980. entry.storeId = ssitem->store_id;
  15981. entry.AID = ssitem->account_id;
  15982. safestrncpy( entry.shopName, ssitem->store_name, MESSAGE_SIZE );
  15983. entry.itemId = client_nameid( ssitem->nameid );
  15984. entry.itemType = itemtype( ssitem->nameid );
  15985. entry.price = ssitem->price;
  15986. entry.amount = ssitem->amount;
  15987. entry.refine = ssitem->refine;
  15988. // make-up an item for clif_addcards
  15989. struct item it = {};
  15990. for( int32 j = 0; j < MAX_SLOTS; j++ ){
  15991. it.card[j] = ssitem->card[j];
  15992. }
  15993. it.nameid = ssitem->nameid;
  15994. it.amount = ssitem->amount;
  15995. clif_addcards( &entry.slot, &it );
  15996. #if PACKETVER >= 20150226
  15997. clif_add_random_options( entry.option_data, it );
  15998. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15999. entry.grade = ssitem->enchantgrade;
  16000. #endif
  16001. #endif
  16002. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  16003. count++;
  16004. }
  16005. clif_send( p, p->packetLength, &sd.bl, SELF );
  16006. #endif
  16007. }
  16008. /// Notification of failure when searching for stores.
  16009. /// 0837 <reason>.B (ZC_SEARCH_STORE_INFO_FAILED)
  16010. void clif_search_store_info_failed(map_session_data& sd, e_searchstore_failure reason){
  16011. #if PACKETVER_MAIN_NUM >= 20100601 || PACKETVER_RE_NUM >= 20100601 || defined(PACKETVER_ZERO)
  16012. if (!battle_config.feature_search_stores)
  16013. return;
  16014. PACKET_ZC_SEARCH_STORE_INFO_FAILED packet{};
  16015. packet.packetType = HEADER_ZC_SEARCH_STORE_INFO_FAILED;
  16016. packet.reason = static_cast<decltype(packet.reason)>(reason);
  16017. clif_send(&packet, sizeof(packet), &sd.bl, SELF);
  16018. #endif
  16019. }
  16020. /// Request to display next page of results.
  16021. /// 0838 (CZ_SEARCH_STORE_INFO_NEXT_PAGE)
  16022. static void clif_parse_SearchStoreInfoNextPage(int32 fd, map_session_data* sd){
  16023. if (!battle_config.feature_search_stores)
  16024. return;
  16025. searchstore_next(*sd);
  16026. }
  16027. /// Opens the search store window.
  16028. /// 083a <effect>.W <remaining uses>.B (ZC_OPEN_SEARCH_STORE_INFO)
  16029. void clif_open_search_store_info(map_session_data& sd){
  16030. #if PACKETVER_MAIN_NUM >= 20100701 || PACKETVER_RE_NUM >= 20100701 || defined(PACKETVER_ZERO)
  16031. if (!battle_config.feature_search_stores)
  16032. return;
  16033. PACKET_ZC_OPEN_SEARCH_STORE_INFO packet{};
  16034. packet.packetType = HEADER_ZC_OPEN_SEARCH_STORE_INFO;
  16035. packet.effect = static_cast<decltype(packet.effect)>(sd.searchstore.effect);
  16036. #if PACKETVER_MAIN_NUM >= 20100701 || PACKETVER_RE_NUM >= 20100701 || defined(PACKETVER_ZERO)
  16037. packet.remainingUses = static_cast<decltype(packet.remainingUses)>( std::min<decltype(sd.searchstore.uses)>( sd.searchstore.uses, std::numeric_limits<decltype(packet.remainingUses)>::max() ) );
  16038. #endif
  16039. clif_send(&packet, sizeof(packet), &sd.bl, SELF);
  16040. #endif
  16041. }
  16042. /// Request to close the store search window.
  16043. /// 083b (CZ_CLOSE_SEARCH_STORE_INFO)
  16044. static void clif_parse_CloseSearchStoreInfo(int32 fd, map_session_data* sd){
  16045. if (!battle_config.feature_search_stores)
  16046. return;
  16047. searchstore_close(*sd);
  16048. }
  16049. /// Request to invoke catalog effect on a store from search results.
  16050. /// 083c <account id>.L <store id>.L <nameid>.W (CZ_SSILIST_ITEM_CLICK)
  16051. static void clif_parse_SearchStoreInfoListItemClick( int32 fd, map_session_data* sd ){
  16052. if (!battle_config.feature_search_stores)
  16053. return;
  16054. const PACKET_CZ_SSILIST_ITEM_CLICK* p = reinterpret_cast<PACKET_CZ_SSILIST_ITEM_CLICK*>( RFIFOP( fd, 0 ) );
  16055. searchstore_click( *sd, p->AID, p->storeId, p->itemId );
  16056. }
  16057. /// Notification of the store position on current map.
  16058. /// 083d <xPos>.W <yPos>.W (ZC_SSILIST_ITEM_CLICK_ACK)
  16059. void clif_search_store_info_click_ack(map_session_data& sd, int16 x, int16 y){
  16060. #if PACKETVER_MAIN_NUM >= 20100608 || PACKETVER_RE_NUM >= 20100608 || defined(PACKETVER_ZERO)
  16061. if (!battle_config.feature_search_stores)
  16062. return;
  16063. PACKET_ZC_SSILIST_ITEM_CLICK_ACK packet{};
  16064. packet.packetType = HEADER_ZC_SSILIST_ITEM_CLICK_ACK;
  16065. packet.x = x;
  16066. packet.y = y;
  16067. clif_send(&packet, sizeof(packet), &sd.bl, SELF);
  16068. #endif
  16069. }
  16070. /// Parse function for packet debugging.
  16071. void clif_parse_debug(int32 fd,map_session_data *sd)
  16072. {
  16073. int16 packet_len;
  16074. // clif_parse ensures, that there is at least 2 bytes of data
  16075. uint16 cmd = RFIFOW(fd,0);
  16076. if( sd ) {
  16077. packet_len = packet_db[cmd].len;
  16078. if( packet_len == 0 )
  16079. {// unknown
  16080. packet_len = static_cast<decltype(packet_len)>( RFIFOREST(fd) );
  16081. }
  16082. else if( packet_len == -1 )
  16083. {// variable length
  16084. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16085. }
  16086. 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);
  16087. }
  16088. else
  16089. {
  16090. packet_len = static_cast<decltype(packet_len)>( RFIFOREST(fd) );
  16091. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16092. }
  16093. ShowDump(RFIFOP(fd,0), packet_len);
  16094. }
  16095. /*==========================================
  16096. * Server tells client to display a window similar to Magnifier (item) one
  16097. * Server populates the window with avilable elemental converter options according to player's inventory
  16098. *------------------------------------------*/
  16099. void clif_elementalconverter_list( map_session_data& sd ){
  16100. PACKET_ZC_MAKINGARROW_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGARROW_LIST*>( packet_buffer );
  16101. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16102. p->packetLength = sizeof( *p );
  16103. int32 count = 0;
  16104. for( int32 i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16105. if( skill_can_produce_mix( &sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16106. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16107. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  16108. count++;
  16109. }
  16110. }
  16111. clif_send( p, p->packetLength, &sd.bl, SELF );
  16112. if( count > 0 ){
  16113. sd.menuskill_id = SA_CREATECON;
  16114. sd.menuskill_val = count;
  16115. }
  16116. }
  16117. /**
  16118. * Rune Knight
  16119. **/
  16120. void clif_millenniumshield( block_list& bl, int16 shields ){
  16121. #if PACKETVER >= 20081126
  16122. PACKET_ZC_MILLENNIUMSHIELD packet{};
  16123. packet.packetType = HEADER_ZC_MILLENNIUMSHIELD;
  16124. packet.aid = bl.id;
  16125. packet.num = shields;
  16126. packet.state = 0;
  16127. clif_send( &packet, sizeof( packet ), &bl, AREA );
  16128. #endif
  16129. }
  16130. /**
  16131. * Mechanic
  16132. **/
  16133. /*==========================================
  16134. * Magic Decoy Material List
  16135. *------------------------------------------*/
  16136. void clif_magicdecoy_list( map_session_data& sd, uint16 skill_lv, int16 x, int16 y ){
  16137. PACKET_ZC_MAKINGARROW_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGARROW_LIST*>( packet_buffer );
  16138. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16139. p->packetLength = sizeof( *p );
  16140. size_t count = 0;
  16141. for( size_t i = 0; i < MAX_INVENTORY; i++ ){
  16142. if( itemdb_group.item_exists( IG_ELEMENT, sd.inventory.u.items_inventory[i].nameid ) ){
  16143. p->items[count].itemId = client_nameid( sd.inventory.u.items_inventory[i].nameid );
  16144. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  16145. count++;
  16146. }
  16147. }
  16148. if( count > 0 ){
  16149. clif_send( p, p->packetLength, &sd.bl, SELF );
  16150. sd.menuskill_id = NC_MAGICDECOY;
  16151. sd.menuskill_val = skill_lv;
  16152. sd.sc.comet_x = x;
  16153. sd.sc.comet_y = y;
  16154. }else{
  16155. clif_skill_fail( sd, NC_MAGICDECOY );
  16156. }
  16157. }
  16158. /*==========================================
  16159. * Guillotine Cross Poisons List
  16160. *------------------------------------------*/
  16161. void clif_poison_list( map_session_data& sd, uint16 skill_lv ){
  16162. PACKET_ZC_MAKINGARROW_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGARROW_LIST*>( packet_buffer );
  16163. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16164. p->packetLength = sizeof( *p );
  16165. size_t count = 0;
  16166. for( size_t i = 0; i < MAX_INVENTORY; i++ ){
  16167. if( itemdb_group.item_exists( IG_POISON, sd.inventory.u.items_inventory[i].nameid ) ){
  16168. p->items[count].itemId = client_nameid( sd.inventory.u.items_inventory[i].nameid );
  16169. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  16170. count++;
  16171. }
  16172. }
  16173. if( count > 0 ){
  16174. clif_send( p, p->packetLength, &sd.bl, SELF );
  16175. sd.menuskill_id = GC_POISONINGWEAPON;
  16176. sd.menuskill_val = skill_lv;
  16177. }else{
  16178. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON );
  16179. }
  16180. }
  16181. /// 0442 <Length>.W <why>.L { <Skill_Id>.W }* (ZC_SKILL_SELECT_REQUEST).
  16182. void clif_autoshadowspell_list( map_session_data& sd ){
  16183. #if PACKETVER >= 20081210
  16184. if( sd.menuskill_id == SC_AUTOSHADOWSPELL )
  16185. return;
  16186. PACKET_ZC_SKILL_SELECT_REQUEST* p = reinterpret_cast<PACKET_ZC_SKILL_SELECT_REQUEST*>( packet_buffer );
  16187. p->packetType = HEADER_ZC_SKILL_SELECT_REQUEST;
  16188. p->packetLength = sizeof( *p );
  16189. p->flag = 1; // enum PACKET_ZC_SKILL_SELECT_REQUEST::enumWHY::WHY_SC_AUTOSHADOWSPELL = 0x1
  16190. size_t count = 0;
  16191. for( size_t i = 0; i < MAX_SKILL; i++ ){
  16192. if( sd.status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd.status.skill[i].id > 0 &&
  16193. skill_get_inf2(sd.status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16194. {
  16195. p->skillIds[count] = sd.status.skill[i].id;
  16196. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->skillIds[0] ) );
  16197. count++;
  16198. }
  16199. }
  16200. if( count > 0 ) {
  16201. clif_send( p, p->packetLength, &sd.bl, SELF );
  16202. sd.menuskill_id = SC_AUTOSHADOWSPELL;
  16203. sd.menuskill_val = static_cast<decltype(sd.menuskill_val)>( count );
  16204. } else {
  16205. status_change_end( &sd.bl, SC_STOP );
  16206. clif_skill_fail( sd, SC_AUTOSHADOWSPELL, USESKILL_FAIL_IMITATION_SKILL_NONE );
  16207. }
  16208. #endif
  16209. }
  16210. /*===========================================
  16211. * Skill list for Four Elemental Analysis
  16212. * and Change Material skills.
  16213. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16214. *------------------------------------------*/
  16215. int32 clif_skill_itemlistwindow( map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16216. #if PACKETVER >= 20090922
  16217. int32 fd = sd->fd;
  16218. nullpo_ret(sd);
  16219. sd->menuskill_id = skill_id; // To prevent hacking.
  16220. sd->menuskill_val = skill_lv;
  16221. if( skill_id == GN_CHANGEMATERIAL )
  16222. skill_lv = 0; // Changematerial
  16223. WFIFOHEAD(fd, packet_len(0x7e3));
  16224. WFIFOW(fd,0) = 0x7e3;
  16225. WFIFOL(fd,2) = skill_lv;
  16226. WFIFOL(fd,4) = 0;
  16227. WFIFOSET(fd, packet_len(0x7e3));
  16228. #endif
  16229. return 1;
  16230. }
  16231. /*==========================================
  16232. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16233. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16234. *------------------------------------------*/
  16235. void clif_parse_SkillSelectMenu(int32 fd, map_session_data *sd) {
  16236. #if PACKETVER >= 20081210
  16237. if( sd == nullptr ){
  16238. return;
  16239. }
  16240. const PACKET_CZ_SKILL_SELECT_RESPONSE* p = reinterpret_cast<PACKET_CZ_SKILL_SELECT_RESPONSE*>( RFIFOP( fd, 0 ) );
  16241. if (sd->menuskill_id == SA_AUTOSPELL) {
  16242. sd->state.workinprogress = WIP_DISABLE_NONE;
  16243. skill_autospell(sd, p->selectedSkillId);
  16244. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16245. if (pc_istrading(sd)) {
  16246. clif_skill_fail( *sd, sd->ud.skill_id );
  16247. clif_menuskill_clear(sd);
  16248. return;
  16249. }
  16250. skill_select_menu(*sd, p->selectedSkillId);
  16251. } else
  16252. return;
  16253. clif_menuskill_clear(sd);
  16254. #endif
  16255. }
  16256. /// Kagerou/Oboro amulet spirit.
  16257. /// 08cf <id>.L <type>.W <num>.W (ZC_SPIRITS_ATTRIBUTE)
  16258. void clif_spiritcharm( map_session_data& sd ){
  16259. #if PACKETVER >= 20111102
  16260. PACKET_ZC_SPIRITS_ATTRIBUTE packet{};
  16261. packet.packetType = HEADER_ZC_SPIRITS_ATTRIBUTE;
  16262. packet.aid = sd.bl.id;
  16263. packet.spiritsType = static_cast<decltype(packet.spiritsType)>(sd.spiritcharm_type);
  16264. packet.num = static_cast<decltype(packet.num)>(sd.spiritcharm);
  16265. clif_send( &packet, sizeof( packet ), &sd.bl, AREA );
  16266. #endif
  16267. }
  16268. /// Move Item from or to Personal Tab
  16269. /// 0907 <index>.W <type>.B (CZ_INVENTORY_TAB)
  16270. /// type:
  16271. /// 0 = move item to personal tab
  16272. /// 1 = move item to normal tab
  16273. void clif_parse_MoveItem( int32 fd, map_session_data* sd ){
  16274. // TODO: Check for correct packet version
  16275. #if PACKETVER >= 20120410
  16276. /* can't move while dead. */
  16277. if(pc_isdead(sd)) {
  16278. return;
  16279. }
  16280. const PACKET_CZ_INVENTORY_TAB* p = reinterpret_cast<PACKET_CZ_INVENTORY_TAB*>( RFIFOP( fd, 0 ) );
  16281. uint16 index = server_index( p->index );
  16282. if( index >= MAX_INVENTORY ){
  16283. return;
  16284. }
  16285. if ( sd->inventory.u.items_inventory[index].favorite != 0 && p->favorite == true )
  16286. sd->inventory.u.items_inventory[index].favorite = 0;
  16287. else if( p->favorite == false )
  16288. sd->inventory.u.items_inventory[index].favorite = 1;
  16289. else
  16290. return;/* nothing to do. */
  16291. clif_favorite_item( *sd, index );
  16292. #endif
  16293. }
  16294. /// Items that are in favorite tab of inventory.
  16295. /// 0908 <index>.W <favorite>.B (ZC_INVENTORY_TAB)
  16296. static void clif_favorite_item( map_session_data& sd, uint16 index ){
  16297. // TODO: Check for correct packet version
  16298. #if PACKETVER >= 20111122
  16299. PACKET_ZC_INVENTORY_TAB p = {};
  16300. p.packetType = HEADER_ZC_INVENTORY_TAB;
  16301. p.index = client_index( index );
  16302. p.favorite = ( sd.inventory.u.items_inventory[index].favorite == 1 ) ? false : true;
  16303. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16304. #endif
  16305. }
  16306. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16307. void clif_snap( struct block_list *bl, int16 x, int16 y ) {
  16308. unsigned char buf[10];
  16309. WBUFW(buf,0) = 0x8d2;
  16310. WBUFL(buf,2) = bl->id;
  16311. WBUFW(buf,6) = x;
  16312. WBUFW(buf,8) = y;
  16313. if( disguised(bl) )
  16314. {
  16315. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16316. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16317. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16318. } else
  16319. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16320. }
  16321. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16322. void clif_monster_hp_bar( struct mob_data* md, int32 fd ) {
  16323. #if PACKETVER >= 20120404
  16324. WFIFOHEAD(fd,packet_len(0x977));
  16325. WFIFOW(fd,0) = 0x977;
  16326. WFIFOL(fd,2) = md->bl.id;
  16327. WFIFOL(fd,6) = md->status.hp;
  16328. WFIFOL(fd,10) = md->status.max_hp;
  16329. WFIFOSET(fd,packet_len(0x977));
  16330. #endif
  16331. }
  16332. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16333. void __attribute__ ((unused)) clif_parse_dull(int32 fd, map_session_data *sd) {
  16334. return;
  16335. }
  16336. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16337. /// 0979 <world name>.24B <char name>.24B
  16338. void clif_ackworldinfo(map_session_data* sd) {
  16339. int32 fd;
  16340. nullpo_retv(sd);
  16341. fd = sd->fd;
  16342. WFIFOHEAD(fd,packet_len(0x979));
  16343. WFIFOW(fd,0)=0x979;
  16344. //AID -> world name ?
  16345. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16346. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16347. WFIFOSET(fd,packet_len(0x979));
  16348. }
  16349. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16350. /// 0978 <AID>.L
  16351. void clif_parse_reqworldinfo(int32 fd,map_session_data *sd) {
  16352. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16353. if(sd)
  16354. clif_ackworldinfo(sd);
  16355. }
  16356. static void clif_loadConfirm( map_session_data *sd ){
  16357. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16358. nullpo_retv( sd );
  16359. PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16360. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16361. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16362. clif_instance_info( *sd );
  16363. #endif
  16364. }
  16365. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16366. /// 0447
  16367. void clif_parse_blocking_playcancel( int32 fd, map_session_data *sd ){
  16368. clif_loadConfirm( sd );
  16369. int32 mf = map_getmapflag(sd->bl.m, MF_SPECIALPOPUP);
  16370. if (mf > 0) {
  16371. clif_specialpopup(*sd, mf);
  16372. }
  16373. }
  16374. /// req world info (CZ_CLIENT_VERSION)
  16375. /// 044A <version>.L
  16376. void clif_parse_client_version(int32 fd, map_session_data *sd) {
  16377. //if(sd)
  16378. ;
  16379. }
  16380. /// Ranking list
  16381. /// ranking pointlist { <name>.24B }*10 { <point>.L }*10
  16382. void clif_sub_ranklist( RANKLIST& ranklist, e_rank rankingtype ){
  16383. struct fame_list* list;
  16384. size_t i;
  16385. size_t size = std::min<size_t>( ARRAYLENGTH( ranklist.names ), MAX_FAME_LIST );
  16386. switch( rankingtype ){
  16387. case RANK_BLACKSMITH:
  16388. list = smith_fame_list;
  16389. break;
  16390. case RANK_ALCHEMIST:
  16391. list = chemist_fame_list;
  16392. break;
  16393. case RANK_TAEKWON:
  16394. list = taekwon_fame_list;
  16395. break;
  16396. case RANK_KILLER:
  16397. // Currently not supported
  16398. list = nullptr;
  16399. size = 0;
  16400. break;
  16401. default:
  16402. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16403. return;
  16404. }
  16405. for( i = 0; i < size; i++ ){
  16406. ranklist.points[i] = list[i].fame;
  16407. if( list[i].id == 0 ){
  16408. safestrncpy( ranklist.names[i], "None", sizeof( ranklist.names[0] ) );
  16409. continue;
  16410. }
  16411. if( strcmp( list[i].name, "-" ) != 0 ){
  16412. safestrncpy( ranklist.names[i], list[i].name, sizeof( ranklist.names[0] ) );
  16413. continue;
  16414. }
  16415. const char* name = map_charid2nick( list[i].id );
  16416. if( name != nullptr ){
  16417. safestrncpy( ranklist.names[i], name, sizeof( ranklist.names[0] ) );
  16418. }else{
  16419. safestrncpy( ranklist.names[i], list[i].name, sizeof( ranklist.names[0] ) );
  16420. }
  16421. }
  16422. size = ARRAYLENGTH( ranklist.names );
  16423. for( ; i < size; i++ ){
  16424. safestrncpy( ranklist.names[i], "Unavailable", sizeof( ranklist.names[0] ) );
  16425. ranklist.points[i] = 0;
  16426. }
  16427. }
  16428. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16429. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16430. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16431. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16432. /// 097d <RankingType>.W { <name>.24B }*10 { <point>.L }*10 <mypoint>L (ZC_ACK_RANKING)
  16433. /// 0af6 <RankingType>.W { <CID>.L }*10 { <point>.L }*10 <mypoint>L (ZC_ACK_RANKING2)
  16434. void clif_ranklist( map_session_data& sd, e_rank rankingtype ){
  16435. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190703 || PACKETVER_ZERO_NUM >= 20190724
  16436. PACKET_ZC_ACK_RANKING2 p = {};
  16437. p.packetType = HEADER_ZC_ACK_RANKING2;
  16438. p.type = rankingtype;
  16439. struct fame_list* list;
  16440. size_t i;
  16441. size_t size = std::min<size_t>( ARRAYLENGTH( p.CIDs ), MAX_FAME_LIST );
  16442. switch( rankingtype ){
  16443. case RANK_BLACKSMITH:
  16444. list = smith_fame_list;
  16445. break;
  16446. case RANK_ALCHEMIST:
  16447. list = chemist_fame_list;
  16448. break;
  16449. case RANK_TAEKWON:
  16450. list = taekwon_fame_list;
  16451. break;
  16452. case RANK_KILLER:
  16453. // Currently not supported
  16454. list = nullptr;
  16455. size = 0;
  16456. break;
  16457. default:
  16458. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16459. return;
  16460. }
  16461. for( i = 0; i < size; i++ ){
  16462. p.CIDs[i] = list[i].id;
  16463. p.points[i] = list[i].fame;
  16464. }
  16465. size = ARRAYLENGTH( p.CIDs );
  16466. for( ; i < size; i++ ){
  16467. p.CIDs[i] = 0;
  16468. p.points[i] = 0;
  16469. }
  16470. switch( sd.class_&MAPID_UPPERMASK ){
  16471. case MAPID_BLACKSMITH:
  16472. case MAPID_ALCHEMIST:
  16473. case MAPID_TAEKWON:
  16474. p.mypoints = sd.status.fame;
  16475. break;
  16476. default:
  16477. p.mypoints = 0;
  16478. break;
  16479. }
  16480. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16481. #elif PACKETVER_MAIN_NUM >= 20130605 || PACKETVER_RE_NUM >= 20130529 || defined(PACKETVER_ZERO)
  16482. PACKET_ZC_ACK_RANKING p = {};
  16483. p.packetType = HEADER_ZC_ACK_RANKING;
  16484. p.type = rankingtype;
  16485. clif_sub_ranklist( p.list, rankingtype );
  16486. switch( sd.class_&MAPID_UPPERMASK ){
  16487. case MAPID_BLACKSMITH:
  16488. case MAPID_ALCHEMIST:
  16489. case MAPID_TAEKWON:
  16490. p.mypoints = sd.status.fame;
  16491. break;
  16492. default:
  16493. p.mypoints = 0;
  16494. break;
  16495. }
  16496. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16497. #else
  16498. switch( rankingtype ){
  16499. case RANK_BLACKSMITH: {
  16500. #if PACKETVER >= 20041108
  16501. PACKET_ZC_BLACKSMITH_RANK p = {};
  16502. p.packetType = HEADER_ZC_BLACKSMITH_RANK;
  16503. clif_sub_ranklist( p.list, RANK_BLACKSMITH );
  16504. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16505. #endif
  16506. } break;
  16507. case RANK_ALCHEMIST: {
  16508. #if PACKETVER >= 20041108
  16509. PACKET_ZC_ALCHEMIST_RANK p = {};
  16510. p.packetType = HEADER_ZC_ALCHEMIST_RANK;
  16511. clif_sub_ranklist( p.list, RANK_ALCHEMIST );
  16512. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16513. #endif
  16514. } break;
  16515. case RANK_TAEKWON: {
  16516. #if PACKETVER >= 20050328
  16517. PACKET_ZC_TAEKWON_RANK p = {};
  16518. p.packetType = HEADER_ZC_TAEKWON_RANK;
  16519. clif_sub_ranklist( p.list, RANK_TAEKWON );
  16520. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16521. #endif
  16522. } break;
  16523. case RANK_KILLER: {
  16524. #if PACKETVER >= 20050328
  16525. PACKET_ZC_KILLER_RANK p = {};
  16526. p.packetType = HEADER_ZC_KILLER_RANK;
  16527. clif_sub_ranklist( p.list, RANK_KILLER );
  16528. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16529. #endif
  16530. } break;
  16531. default:
  16532. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16533. return;
  16534. }
  16535. #endif
  16536. }
  16537. /// Request for the blacksmith ranklist.
  16538. /// /blacksmith command sends this packet to the server.
  16539. /// 0217 (CZ_BLACKSMITH_RANK)
  16540. void clif_parse_ranklist_blacksmith( int32 fd, map_session_data* sd ){
  16541. #if PACKETVER >= 20041108
  16542. const PACKET_CZ_BLACKSMITH_RANK* p = reinterpret_cast<PACKET_CZ_BLACKSMITH_RANK*>( RFIFOP( fd, 0 ) );
  16543. clif_ranklist( *sd, RANK_BLACKSMITH );
  16544. #endif
  16545. }
  16546. /// Request for the alchemist ranklist.
  16547. /// /alchemist command sends this packet to the server.
  16548. /// 0218 (CZ_ALCHEMIST_RANK)
  16549. void clif_parse_ranklist_alchemist( int32 fd, map_session_data* sd ){
  16550. #if PACKETVER >= 20041108
  16551. const PACKET_CZ_ALCHEMIST_RANK* p = reinterpret_cast<PACKET_CZ_ALCHEMIST_RANK*>( RFIFOP( fd, 0 ) );
  16552. clif_ranklist( *sd, RANK_ALCHEMIST );
  16553. #endif
  16554. }
  16555. /// Request for the taekwon ranklist.
  16556. /// /taekwon command sends this packet to the server.
  16557. /// 0225 (CZ_TAEKWON_RANK)
  16558. void clif_parse_ranklist_taekwon( int32 fd, map_session_data* sd ){
  16559. #if PACKETVER >= 20050328
  16560. const PACKET_CZ_TAEKWON_RANK* p = reinterpret_cast<PACKET_CZ_TAEKWON_RANK*>( RFIFOP( fd, 0 ) );
  16561. clif_ranklist( *sd, RANK_TAEKWON );
  16562. #endif
  16563. }
  16564. /// Request for the killer ranklist.
  16565. /// /pk command sends this packet to the server.
  16566. /// 0237 (CZ_KILLER_RANK)
  16567. void clif_parse_ranklist_killer( int32 fd, map_session_data* sd ){
  16568. #if PACKETVER >= 20050530
  16569. const PACKET_CZ_KILLER_RANK* p = reinterpret_cast<PACKET_CZ_KILLER_RANK*>( RFIFOP( fd, 0 ) );
  16570. clif_ranklist( *sd, RANK_KILLER );
  16571. #endif
  16572. }
  16573. ///
  16574. /// 097c <type>.W (CZ_REQ_RANKING)
  16575. /// type
  16576. /// 0: /blacksmith
  16577. /// 1: /alchemist
  16578. /// 2: /taekwon
  16579. /// 3: /pk
  16580. void clif_parse_ranklist( int fd, map_session_data* sd ){
  16581. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502
  16582. const PACKET_CZ_REQ_RANKING* p = reinterpret_cast<PACKET_CZ_REQ_RANKING*>( RFIFOP( fd, 0 ) );
  16583. switch( p->type ){
  16584. case RANK_BLACKSMITH:
  16585. case RANK_ALCHEMIST:
  16586. case RANK_TAEKWON:
  16587. case RANK_KILLER:
  16588. break;
  16589. default:
  16590. return;
  16591. }
  16592. clif_ranklist( *sd, static_cast<e_rank>( p->type ) );
  16593. #endif
  16594. }
  16595. /// Updates the fame rank points for the given ranking.
  16596. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16597. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16598. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16599. /// 0236 <points>.L <total points>.L (ZC_KILLER_POINT)
  16600. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16601. void clif_update_rankingpoint( map_session_data& sd, e_rank rankingtype, uint32 point ){
  16602. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502
  16603. PACKET_ZC_UPDATE_RANKING_POINT p = {};
  16604. p.packetType = HEADER_ZC_UPDATE_RANKING_POINT;
  16605. p.type = rankingtype;
  16606. p.points = point;
  16607. p.points_total = sd.status.fame;
  16608. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16609. #else
  16610. switch(rankingtype){
  16611. case RANK_BLACKSMITH: {
  16612. #if PACKETVER >= 20041108
  16613. PACKET_ZC_BLACKSMITH_POINT p = {};
  16614. p.packetType = HEADER_ZC_BLACKSMITH_POINT;
  16615. p.points = point;
  16616. p.points_total = sd.status.fame;
  16617. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16618. #endif
  16619. } break;
  16620. case RANK_ALCHEMIST: {
  16621. #if PACKETVER >= 20041108
  16622. PACKET_ZC_ALCHEMIST_POINT p = {};
  16623. p.packetType = HEADER_ZC_ALCHEMIST_POINT;
  16624. p.points = point;
  16625. p.points_total = sd.status.fame;
  16626. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16627. #endif
  16628. } break;
  16629. case RANK_TAEKWON: {
  16630. #if PACKETVER >= 20050328
  16631. PACKET_ZC_TAEKWON_POINT p = {};
  16632. p.packetType = HEADER_ZC_TAEKWON_POINT;
  16633. p.points = point;
  16634. p.points_total = sd.status.fame;
  16635. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16636. #endif
  16637. } break;
  16638. case RANK_KILLER: {
  16639. #if PACKETVER >= 20050530
  16640. PACKET_ZC_KILLER_POINT p = {};
  16641. p.packetType = HEADER_ZC_KILLER_POINT;
  16642. p.points = point;
  16643. p.points_total = sd.status.fame;
  16644. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16645. #endif
  16646. } break;
  16647. default:
  16648. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16649. return;
  16650. }
  16651. #endif
  16652. }
  16653. /**
  16654. * Transmit personal information to player. (rates)
  16655. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16656. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16657. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16658. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16659. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16660. * FIXME!
  16661. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16662. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16663. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16664. */
  16665. #ifdef VIP_ENABLE
  16666. void clif_display_pinfo( map_session_data& sd ){
  16667. #if PACKETVER_MAIN_NUM >= 20110627 || PACKETVER_RE_NUM >= 20110628 || defined(PACKETVER_ZERO)
  16668. // 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]
  16669. int32 details_bexp[PINFO_MAX], details_drop[PINFO_MAX], details_penalty[PINFO_MAX];
  16670. /**
  16671. * EXP
  16672. */
  16673. //0:PCRoom
  16674. details_bexp[PINFO_BASIC] = map_getmapflag( sd.bl.m, MF_BEXP );
  16675. if (details_bexp[PINFO_BASIC] == 100 || !details_bexp[PINFO_BASIC])
  16676. details_bexp[PINFO_BASIC] = 0;
  16677. else {
  16678. if (details_bexp[PINFO_BASIC] < 100) {
  16679. details_bexp[PINFO_BASIC] = 100 - details_bexp[PINFO_BASIC];
  16680. details_bexp[PINFO_BASIC] = 0 - details_bexp[PINFO_BASIC];
  16681. } else
  16682. details_bexp[PINFO_BASIC] = details_bexp[PINFO_BASIC] - 100;
  16683. }
  16684. //1:Premium
  16685. if( pc_isvip( &sd ) ){
  16686. details_bexp[PINFO_PREMIUM] = battle_config.vip_base_exp_increase * battle_config.base_exp_rate / 100;
  16687. if (details_bexp[PINFO_PREMIUM] < 0)
  16688. details_bexp[PINFO_PREMIUM] = 0 - details_bexp[PINFO_PREMIUM];
  16689. } else
  16690. details_bexp[PINFO_PREMIUM] = 0;
  16691. //2:Server
  16692. details_bexp[PINFO_SERVER] = battle_config.base_exp_rate;
  16693. if (details_bexp[PINFO_SERVER] == 100)
  16694. details_bexp[PINFO_SERVER] = 0;
  16695. else {
  16696. if (details_bexp[PINFO_SERVER] < 100) {
  16697. details_bexp[PINFO_SERVER] = 100 - details_bexp[PINFO_SERVER];
  16698. details_bexp[PINFO_SERVER] = 0 - details_bexp[PINFO_SERVER];
  16699. } else
  16700. details_bexp[PINFO_SERVER] = details_bexp[PINFO_SERVER] - 100;
  16701. }
  16702. //3:TPLUS
  16703. details_bexp[PINFO_CAFE] = 0;
  16704. /**
  16705. * Drop rate
  16706. */
  16707. //0:PCRoom
  16708. details_drop[PINFO_BASIC] = 0;
  16709. //1:Premium
  16710. if( pc_isvip( &sd ) ){
  16711. details_drop[PINFO_PREMIUM] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16712. if (details_drop[PINFO_PREMIUM] < 0)
  16713. details_drop[PINFO_PREMIUM] = 0 - details_drop[PINFO_PREMIUM];
  16714. } else
  16715. details_drop[PINFO_PREMIUM] = 0;
  16716. //2:Server
  16717. details_drop[PINFO_SERVER] = battle_config.item_rate_common;
  16718. if (details_drop[PINFO_SERVER] == 100)
  16719. details_drop[PINFO_SERVER] = 0;
  16720. else {
  16721. if (details_drop[PINFO_SERVER] < 100) {
  16722. details_drop[PINFO_SERVER] = 100 - details_drop[PINFO_SERVER];
  16723. details_drop[PINFO_SERVER] = 0 - details_drop[PINFO_SERVER];
  16724. } else
  16725. details_drop[PINFO_SERVER] = details_drop[PINFO_SERVER] - 100;
  16726. }
  16727. //3:TPLUS
  16728. details_drop[PINFO_CAFE] = 0;
  16729. /**
  16730. * Penalty rate
  16731. */
  16732. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16733. //0:PCRoom
  16734. details_penalty[PINFO_BASIC] = 0;
  16735. //1:Premium
  16736. if( pc_isvip( &sd ) ){
  16737. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base;
  16738. if (details_penalty[PINFO_PREMIUM] == 100)
  16739. details_penalty[PINFO_PREMIUM] = 0;
  16740. else {
  16741. if (details_penalty[PINFO_PREMIUM] < 100) {
  16742. details_penalty[PINFO_PREMIUM] = 100 - details_penalty[PINFO_PREMIUM];
  16743. details_penalty[PINFO_PREMIUM] = 0 - details_penalty[PINFO_PREMIUM];
  16744. } else
  16745. details_penalty[PINFO_PREMIUM] = details_penalty[PINFO_PREMIUM] - 100;
  16746. }
  16747. if (battle_config.death_penalty_base > battle_config.vip_exp_penalty_base)
  16748. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base - battle_config.death_penalty_base;
  16749. } else
  16750. details_penalty[PINFO_PREMIUM] = 0;
  16751. //2:Server
  16752. details_penalty[PINFO_SERVER] = battle_config.death_penalty_base;
  16753. if (details_penalty[PINFO_SERVER] == 100)
  16754. details_penalty[PINFO_SERVER] = 0;
  16755. else {
  16756. if (details_penalty[PINFO_SERVER] < 100) {
  16757. details_penalty[PINFO_SERVER] = 100 - details_penalty[PINFO_SERVER];
  16758. details_penalty[PINFO_SERVER] = 0 - details_penalty[PINFO_SERVER];
  16759. } else
  16760. details_penalty[PINFO_SERVER] = details_penalty[PINFO_SERVER] - 100;
  16761. }
  16762. //3:TPLUS
  16763. details_penalty[PINFO_CAFE] = 0;
  16764. PACKET_ZC_PERSONAL_INFOMATION* p = reinterpret_cast<PACKET_ZC_PERSONAL_INFOMATION*>( packet_buffer );
  16765. p->packetType = HEADER_ZC_PERSONAL_INFOMATION;
  16766. p->length = sizeof( *p );
  16767. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16768. p->total_exp = 100 * 1000;
  16769. p->total_death = 100 * 1000;
  16770. p->total_drop = 100 * 1000;
  16771. #else
  16772. p->total_exp = 100;
  16773. p->total_death = 100;
  16774. p->total_drop = 100;
  16775. #endif
  16776. for( int32 i = PINFO_BASIC; i < PINFO_MAX; i++ ){
  16777. p->details[i].type = i; // infotype 0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16778. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16779. p->details[i].exp = details_bexp[i] * 1000;
  16780. p->details[i].death = details_penalty[i] * 1000;
  16781. p->details[i].drop = details_drop[i] * 1000;
  16782. #else
  16783. p->details[i].exp = details_bexp[i];
  16784. p->details[i].death = details_penalty[i];
  16785. p->details[i].drop = details_drop[i];
  16786. #endif
  16787. p->total_exp += p->details[i].exp;
  16788. p->total_death += p->details[i].death;
  16789. p->total_drop += p->details[i].drop;
  16790. p->length += static_cast<decltype(p->length)>( sizeof( p->details[0] ) );
  16791. }
  16792. clif_send( p, p->length, &sd.bl, SELF );
  16793. #endif
  16794. }
  16795. #endif
  16796. void clif_parse_GMFullStrip(int32 fd, map_session_data *sd) {
  16797. char cmd[30];
  16798. int32 t_aid = RFIFOL(fd,2);
  16799. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16800. is_atcommand(fd, sd, cmd, 1);
  16801. }
  16802. /**
  16803. * Marks Crimson Marker target on mini-map to the caster
  16804. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16805. * @param fd
  16806. * @param bl Crimson Marker target
  16807. **/
  16808. void clif_crimson_marker( map_session_data& sd, struct block_list& bl, bool remove ){
  16809. #if PACKETVER_MAIN_NUM >= 20130731 || PACKETVER_RE_NUM >= 20130707 || defined(PACKETVER_ZERO)
  16810. PACKET_ZC_C_MARKERINFO p = {};
  16811. p.PacketType = HEADER_ZC_C_MARKERINFO;
  16812. p.AID = bl.id;
  16813. if( remove ){
  16814. p.xPos = -1;
  16815. p.yPos = -1;
  16816. }else{
  16817. p.xPos = bl.x;
  16818. p.yPos = bl.y;
  16819. }
  16820. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16821. #endif
  16822. }
  16823. /**
  16824. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16825. **/
  16826. void clif_notify_bindOnEquip( map_session_data& sd, int16 index ){
  16827. #if PACKETVER >= 20070227
  16828. PACKET_ZC_NOTIFY_BIND_ON_EQUIP p = {};
  16829. p.packetType = HEADER_ZC_NOTIFY_BIND_ON_EQUIP;
  16830. p.index = client_index( index );
  16831. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16832. #endif
  16833. }
  16834. /**
  16835. * [Ind/Hercules]
  16836. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16837. **/
  16838. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16839. char buf[256];
  16840. size_t len;
  16841. nullpo_retv(bl);
  16842. if(!message)
  16843. return;
  16844. len = strlen(message)+1;
  16845. if( len > sizeof(buf)-8 ) {
  16846. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16847. len = sizeof(buf)-8;
  16848. }
  16849. WBUFW(buf,0) = 0x8b3;
  16850. WBUFW(buf,2) = (uint16)(len+8);
  16851. WBUFL(buf,4) = bl->id;
  16852. safestrncpy(WBUFCP(buf,8), message, len);
  16853. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16854. }
  16855. /**
  16856. * [Ind/Hercules]
  16857. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16858. **/
  16859. void clif_party_leaderchanged(map_session_data *sd, int32 prev_leader_aid, int32 new_leader_aid) {
  16860. unsigned char buf[10];
  16861. nullpo_retv(sd);
  16862. WBUFW(buf,0) = 0x7fc;
  16863. WBUFL(buf,2) = prev_leader_aid;
  16864. WBUFL(buf,6) = new_leader_aid;
  16865. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16866. }
  16867. /**
  16868. * Sends a clan message to a player
  16869. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16870. **/
  16871. void clif_clan_message( struct clan& clan, const char *mes, size_t len ){
  16872. #if PACKETVER >= 20131223
  16873. map_session_data* sd = clan_getavailablesd( clan );
  16874. if( len == 0 ){
  16875. return;
  16876. }
  16877. PACKET_ZC_NOTIFY_CLAN_CHAT* p = reinterpret_cast<PACKET_ZC_NOTIFY_CLAN_CHAT*>( packet_buffer );
  16878. // Maximum message length = size of our packet buffer minus fixed size of the packet and 1 byte zero termination
  16879. static size_t len_max = sizeof( packet_buffer ) - sizeof( *p ) - 1;
  16880. // Is the length bigger than the maximum message length
  16881. if( len > len_max ){
  16882. ShowWarning( "clif_clan_message: Truncated message '%s' (len=%" PRIuPTR ", max=%" PRIuPTR ", clan_id=%d).\n", mes, len, len_max, clan.id );
  16883. len = len_max;
  16884. }
  16885. p->PacketType = HEADER_ZC_NOTIFY_CLAN_CHAT;
  16886. p->PacketLength = sizeof( *p );
  16887. // 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
  16888. safestrncpy( p->MemberName, "", sizeof( p->MemberName ) );
  16889. safestrncpy( p->Message, mes, len + 1 );
  16890. p->PacketLength += static_cast<decltype(p->PacketLength)>( len + 1 );
  16891. clif_send( p, p->PacketLength, &sd->bl, CLAN );
  16892. #endif
  16893. }
  16894. /**
  16895. * Parses a clan message from a player.
  16896. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16897. **/
  16898. void clif_parse_clan_chat( int32 fd, map_session_data* sd ){
  16899. #if PACKETVER >= 20131223
  16900. if( sd == nullptr ){
  16901. return;
  16902. }
  16903. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16904. // validate packet and retrieve name and message
  16905. if( !clif_process_message(sd, false, name, message, output ) )
  16906. return;
  16907. clan_send_message( *sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16908. #endif
  16909. }
  16910. /**
  16911. * Sends the basic clan informations to the client.
  16912. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16913. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16914. **/
  16915. void clif_clan_basicinfo( map_session_data& sd ){
  16916. #if PACKETVER_MAIN_NUM >= 20130626 || PACKETVER_RE_NUM >= 20130605 || defined(PACKETVER_ZERO)
  16917. struct clan* clan = sd.clan;
  16918. if( clan == nullptr ){
  16919. return;
  16920. }
  16921. PACKET_ZC_CLANINFO* p = reinterpret_cast<PACKET_ZC_CLANINFO*>( packet_buffer );
  16922. p->PacketType = HEADER_ZC_CLANINFO;
  16923. p->PacketLength = sizeof( *p );
  16924. p->ClanID = clan->id;
  16925. safestrncpy( p->ClanName, clan->name, sizeof( p->ClanName ) );
  16926. safestrncpy( p->MasterName, clan->master, sizeof( p->MasterName ) );
  16927. mapindex_getmapname_ext( clan->map, p->Map );
  16928. p->AllyCount = clan_get_alliance_count( *clan, 0 );
  16929. p->AntagonistCount = clan_get_alliance_count( *clan, 1 );
  16930. for( int32 flag = 0; flag < 2; flag++ ){
  16931. for( int32 i = 0; i < MAX_CLANALLIANCE; i++ ){
  16932. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16933. char* name = reinterpret_cast<char*>( WBUFP( p, p->PacketLength ) );
  16934. safestrncpy( name, clan->alliance[i].name, NAME_LENGTH );
  16935. p->PacketLength += static_cast<decltype(p->PacketLength)>( NAME_LENGTH );
  16936. }
  16937. }
  16938. }
  16939. clif_send( p, p->PacketLength, &sd.bl, SELF );
  16940. #endif
  16941. }
  16942. /**
  16943. * Updates the online and maximum player count of a clan.
  16944. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16945. **/
  16946. void clif_clan_onlinecount( struct clan& clan ){
  16947. #if PACKETVER >= 20131223
  16948. map_session_data* sd = clan_getavailablesd( clan );
  16949. if( sd == nullptr){
  16950. return;
  16951. }
  16952. PACKET_ZC_NOTIFY_CLAN_CONNECTINFO p = {};
  16953. p.PacketType = HEADER_ZC_NOTIFY_CLAN_CONNECTINFO;
  16954. p.NumConnect = clan.connect_member;
  16955. p.NumTotal = clan.max_member;
  16956. clif_send( &p, sizeof( p ), &sd->bl, CLAN );
  16957. #endif
  16958. }
  16959. /**
  16960. * Notifies the client that the player has left his clan.
  16961. * 0989 (ZC_ACK_CLAN_LEAVE)
  16962. **/
  16963. void clif_clan_leave( map_session_data& sd ){
  16964. #if PACKETVER >= 20131223
  16965. PACKET_ZC_ACK_CLAN_LEAVE p = {};
  16966. p.PacketType = HEADER_ZC_ACK_CLAN_LEAVE;
  16967. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16968. #endif
  16969. }
  16970. /**
  16971. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16972. * 0A2F <result>.B <title_id>.L
  16973. */
  16974. void clif_change_title_ack(map_session_data *sd, unsigned char result, unsigned long title_id)
  16975. {
  16976. #if PACKETVER >= 20150513
  16977. int32 fd;
  16978. nullpo_retv(sd);
  16979. if (!clif_session_isValid(sd))
  16980. return;
  16981. fd = sd->fd;
  16982. WFIFOHEAD(fd, packet_len(0xa2f));
  16983. WFIFOW(fd, 0) = 0xa2f;
  16984. WFIFOB(fd, 2) = result;
  16985. WFIFOL(fd, 3) = title_id;
  16986. WFIFOSET(fd, packet_len(0xa2f));
  16987. #endif
  16988. }
  16989. /**
  16990. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16991. * 0A2E <title_id>.L
  16992. */
  16993. void clif_parse_change_title(int32 fd, map_session_data *sd)
  16994. {
  16995. int32 title_id;
  16996. nullpo_retv(sd);
  16997. title_id = RFIFOL(fd, 2);
  16998. if( title_id == sd->status.title_id ){
  16999. // It is exactly the same as the old one
  17000. return;
  17001. }else if( title_id <= 0 ){
  17002. sd->status.title_id = 0;
  17003. }else{
  17004. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  17005. clif_change_title_ack(sd, 1, title_id);
  17006. return;
  17007. }
  17008. sd->status.title_id = title_id;
  17009. }
  17010. clif_name_area(&sd->bl);
  17011. clif_change_title_ack(sd, 0, title_id);
  17012. }
  17013. #ifdef DUMP_UNKNOWN_PACKET
  17014. void DumpUnknown(int32 fd,TBL_PC *sd,int32 cmd,int32 packet_len)
  17015. {
  17016. const char* packet_txt = "save/packet.txt";
  17017. FILE* fp;
  17018. time_t time_server;
  17019. struct tm *datetime;
  17020. char datestr[512];
  17021. time(&time_server); // get time in seconds since 1/1/1970
  17022. datetime = localtime(&time_server); // convert seconds in structure
  17023. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  17024. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  17025. if( ( fp = fopen( packet_txt , "a" ) ) != nullptr ) {
  17026. if( sd ) {
  17027. 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);
  17028. } else {
  17029. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17030. }
  17031. WriteDump(fp, RFIFOP(fd,0), packet_len);
  17032. fprintf(fp, "\n");
  17033. fclose(fp);
  17034. } else {
  17035. ShowError("Failed to write '%s'.\n", packet_txt);
  17036. // Dump on console instead
  17037. if( sd ) {
  17038. 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);
  17039. } else {
  17040. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  17041. }
  17042. ShowDump(RFIFOP(fd,0), packet_len);
  17043. }
  17044. }
  17045. #endif
  17046. /// Roulette System
  17047. /// Author: Yommy
  17048. void roulette_generate_bonus( map_session_data& sd ){
  17049. if( battle_config.feature_roulette_bonus_reward && sd.roulette.bonusItemID == 0 ){
  17050. int32 next_stage = 0;
  17051. if( sd.roulette_point.bronze > 0 ){
  17052. next_stage = 0;
  17053. }else if( sd.roulette_point.silver > 9 ){
  17054. next_stage = 2;
  17055. }else if( sd.roulette_point.gold > 9 ){
  17056. next_stage = 4;
  17057. }
  17058. // Get bonus item stage only from current stage or higher
  17059. int32 reward_stage = rnd_value( next_stage, MAX_ROULETTE_LEVEL - 1 );
  17060. sd.roulette.bonusItemID = rd.nameid[reward_stage][rnd()%rd.items[reward_stage]];
  17061. }else{
  17062. sd.roulette.bonusItemID = 0;
  17063. }
  17064. }
  17065. /// Opens the roulette window
  17066. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  17067. void clif_roulette_open( map_session_data* sd ){
  17068. nullpo_retv( sd );
  17069. roulette_generate_bonus( *sd );
  17070. struct packet_roulette_open_ack p;
  17071. p.PacketType = 0xa1a;
  17072. p.Result = 0; // result
  17073. p.Serial = 0; // serial
  17074. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  17075. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  17076. p.AdditionItemID = sd->roulette.bonusItemID;
  17077. p.GoldPoint = sd->roulette_point.gold;
  17078. p.SilverPoint = sd->roulette_point.silver;
  17079. p.BronzePoint = sd->roulette_point.bronze;
  17080. sd->state.roulette_open = true;
  17081. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17082. }
  17083. /// Request to open the roulette window
  17084. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  17085. void clif_parse_roulette_open( int32 fd, map_session_data* sd ){
  17086. nullpo_retv(sd);
  17087. if (!battle_config.feature_roulette) {
  17088. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17089. return;
  17090. }
  17091. clif_roulette_open(sd);
  17092. }
  17093. /// Sends the info about the available roulette rewards to the client
  17094. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  17095. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  17096. void clif_roulette_info( map_session_data* sd ){
  17097. nullpo_retv(sd);
  17098. struct packet_roulette_info_ack p;
  17099. p.PacketType = rouletteinfoackType;
  17100. p.PacketLength = sizeof(p);
  17101. p.RouletteSerial = 1;
  17102. for( int32 i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  17103. for( int32 j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  17104. p.ItemInfo[count].Row = i;
  17105. p.ItemInfo[count].Position = j;
  17106. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  17107. p.ItemInfo[count].Count = rd.qty[i][j];
  17108. #if PACKETVER >= 20180511
  17109. p.ItemInfo[count].unused = 0;
  17110. #endif
  17111. count++;
  17112. }
  17113. }
  17114. clif_send( &p, sizeof(p), &sd->bl, SELF );
  17115. }
  17116. /// Request the roulette reward data
  17117. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  17118. void clif_parse_roulette_info( int32 fd, map_session_data* sd ){
  17119. nullpo_retv(sd);
  17120. if (!battle_config.feature_roulette) {
  17121. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17122. return;
  17123. }
  17124. clif_roulette_info(sd);
  17125. }
  17126. /// Notification of the client that the roulette window was closed
  17127. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  17128. void clif_parse_roulette_close( int32 fd, map_session_data* sd ){
  17129. nullpo_retv(sd);
  17130. if (!battle_config.feature_roulette) {
  17131. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17132. return;
  17133. }
  17134. sd->state.roulette_open = false;
  17135. }
  17136. /// Response to a item reward request
  17137. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  17138. static void clif_roulette_recvitem_ack(map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  17139. #if PACKETVER >= 20141016
  17140. nullpo_retv(sd);
  17141. struct packet_roulette_itemrecv_ack p;
  17142. p.PacketType = roulettercvitemackType;
  17143. p.Result = type;
  17144. p.AdditionItemID = sd->roulette.bonusItemID;
  17145. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17146. #endif
  17147. }
  17148. /**
  17149. * Claim roulette reward
  17150. * @param sd Player
  17151. * @return 0:Success
  17152. **/
  17153. static uint8 clif_roulette_getitem(map_session_data *sd) {
  17154. struct item it;
  17155. uint8 res = 1;
  17156. uint16 factor = 1;
  17157. nullpo_retr(1, sd);
  17158. if (sd->roulette.prizeIdx < 0)
  17159. return RECV_ITEM_FAILED;
  17160. memset(&it, 0, sizeof(it));
  17161. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  17162. it.identify = 1;
  17163. if( sd->roulette.bonusItemID != 0 ){
  17164. if( sd->roulette.bonusItemID == it.nameid && battle_config.feature_roulette_bonus_reward && !( rd.flag[sd->roulette.prizeStage][sd->roulette.prizeIdx]&1 ) ){
  17165. factor = 2;
  17166. // Reset the Bonus Item to trigger new calculation
  17167. sd->roulette.bonusItemID = 0;
  17168. }else{
  17169. for( int32 i = 0; i < MAX_ROULETTE_LEVEL && sd->roulette.bonusItemID != 0; i++ ){
  17170. for( int32 j = 0; j < MAX_ROULETTE_COLUMNS - i && sd->roulette.bonusItemID != 0; j++ ){
  17171. if( rd.nameid[i][j] == sd->roulette.bonusItemID ){
  17172. // 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
  17173. if( sd->roulette.prizeStage >= i ){
  17174. // Reset the Bonus Item to trigger new calculation and to cancel the loops
  17175. sd->roulette.bonusItemID = 0;
  17176. }
  17177. }
  17178. }
  17179. }
  17180. }
  17181. }
  17182. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx] * factor, LOG_TYPE_ROULETTE)) == 0) {
  17183. ; // onSuccess
  17184. }
  17185. if( sd->roulette.bonusItemID == 0 ){
  17186. roulette_generate_bonus( *sd );
  17187. }
  17188. sd->roulette.claimPrize = false;
  17189. sd->roulette.prizeStage = 0;
  17190. sd->roulette.prizeIdx = -1;
  17191. sd->roulette.stage = 0;
  17192. return res;
  17193. }
  17194. /// Update Roulette window with current stats
  17195. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17196. void clif_roulette_generate( map_session_data *sd, unsigned char result, int16 stage, int16 prizeIdx, t_itemid bonusItemID ){
  17197. nullpo_retv( sd );
  17198. struct packet_roulette_generate_ack p;
  17199. p.PacketType = roulettgenerateackType;
  17200. p.Result = result;
  17201. p.Step = stage;
  17202. p.Idx = prizeIdx;
  17203. p.AdditionItemID = battle_config.feature_roulette_bonus_reward ? bonusItemID : 0;
  17204. p.RemainGold = sd->roulette_point.gold;
  17205. p.RemainSilver = sd->roulette_point.silver;
  17206. p.RemainBronze = sd->roulette_point.bronze;
  17207. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17208. }
  17209. /// Request to start the roulette
  17210. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17211. void clif_parse_roulette_generate( int32 fd, map_session_data* sd ){
  17212. enum GENERATE_ROULETTE_ACK result;
  17213. nullpo_retv(sd);
  17214. if (!battle_config.feature_roulette) {
  17215. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17216. return;
  17217. }
  17218. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17219. return;
  17220. }
  17221. // Player has not claimed his prize yet
  17222. if( sd->roulette.claimPrize ){
  17223. clif_roulette_getitem( sd );
  17224. }
  17225. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17226. // Make sure everything is reset
  17227. sd->roulette.stage = 0;
  17228. sd->roulette.claimPrize = false;
  17229. sd->roulette.prizeStage = 0;
  17230. sd->roulette.prizeIdx = -1;
  17231. }
  17232. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17233. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17234. }else{
  17235. if (!sd->roulette.stage) {
  17236. if (sd->roulette_point.bronze > 0) {
  17237. sd->roulette_point.bronze -= 1;
  17238. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17239. } else if (sd->roulette_point.silver > 9) {
  17240. sd->roulette_point.silver -= 10;
  17241. sd->roulette.stage = 2;
  17242. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17243. } else if (sd->roulette_point.gold > 9) {
  17244. sd->roulette_point.gold -= 10;
  17245. sd->roulette.stage = 4;
  17246. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17247. }
  17248. }
  17249. sd->roulette.prizeStage = sd->roulette.stage;
  17250. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17251. sd->roulette.claimPrize = true;
  17252. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17253. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17254. result = GENERATE_ROULETTE_LOSING;
  17255. sd->roulette.stage = 0;
  17256. }else{
  17257. result = GENERATE_ROULETTE_SUCCESS;
  17258. sd->roulette.stage++;
  17259. }
  17260. }
  17261. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx), sd->roulette.bonusItemID);
  17262. }
  17263. /// Request to claim a prize
  17264. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17265. void clif_parse_roulette_item( int32 fd, map_session_data* sd ){
  17266. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17267. nullpo_retv(sd);
  17268. if (!battle_config.feature_roulette) {
  17269. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17270. return;
  17271. }
  17272. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17273. return;
  17274. }
  17275. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17276. switch (clif_roulette_getitem(sd)) {
  17277. case ADDITEM_SUCCESS:
  17278. type = RECV_ITEM_SUCCESS;
  17279. break;
  17280. case ADDITEM_INVALID:
  17281. case ADDITEM_OVERITEM:
  17282. case ADDITEM_OVERAMOUNT:
  17283. type = RECV_ITEM_OVERCOUNT;
  17284. break;
  17285. case ADDITEM_OVERWEIGHT:
  17286. type = RECV_ITEM_OVERWEIGHT;
  17287. break;
  17288. case ADDITEM_STACKLIMIT:
  17289. default:
  17290. type = RECV_ITEM_FAILED;
  17291. break;
  17292. }
  17293. }
  17294. clif_roulette_recvitem_ack(sd,type);
  17295. }
  17296. /// MERGE ITEM
  17297. /**
  17298. * Acknowledge the client about item merger result
  17299. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17300. * @param fd
  17301. * @param sd
  17302. **/
  17303. void clif_merge_item_ack( map_session_data &sd, enum MERGE_ITEM_ACK type, uint16 index = 0, uint16 count = 0 ){
  17304. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17305. PACKET_ZC_ACK_MERGE_ITEM p = {};
  17306. p.packetType = HEADER_ZC_ACK_MERGE_ITEM;
  17307. if( type == MERGE_ITEM_SUCCESS ){
  17308. p.index = client_index( index );
  17309. }else{
  17310. p.index = index;
  17311. }
  17312. p.amount = count;
  17313. p.reason = type;
  17314. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17315. #endif
  17316. }
  17317. /**
  17318. * Check if item has the pair to be merged
  17319. * @param sd
  17320. * @param it Item
  17321. * @return True if has pair, False if not
  17322. **/
  17323. static bool clif_merge_item_has_pair(map_session_data *sd, struct item *it) {
  17324. struct item *it_;
  17325. uint16 i;
  17326. nullpo_retr(false, sd);
  17327. 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);
  17328. if (i < MAX_INVENTORY)
  17329. return true;
  17330. return false;
  17331. }
  17332. /**
  17333. * Check if item can be merged
  17334. * @param id Item Data
  17335. * @param it Item
  17336. * @return True if can be merged, False if not
  17337. **/
  17338. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17339. if (!id || !it)
  17340. return false;
  17341. if (id->type == IT_CASH)
  17342. return false;
  17343. if (!itemdb_isstackable2(id))
  17344. return false;
  17345. if (itemdb_isspecial(it->card[0]))
  17346. return false;
  17347. if (!it->unique_id)
  17348. return false;
  17349. return true;
  17350. }
  17351. /**
  17352. * Open available item to be merged.
  17353. * Only show 1 item in 1 process.
  17354. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17355. * @param sd
  17356. **/
  17357. void clif_merge_item_open( map_session_data& sd ){
  17358. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17359. PACKET_ZC_MERGE_ITEM_OPEN* p = reinterpret_cast<PACKET_ZC_MERGE_ITEM_OPEN*>( packet_buffer );
  17360. p->packetType = HEADER_ZC_MERGE_ITEM_OPEN;
  17361. p->packetLen = sizeof( *p );
  17362. int32 n = 0;
  17363. // Get entries
  17364. for( int32 i = 0; i < MAX_INVENTORY; i++ ){
  17365. struct item* it = &sd.inventory.u.items_inventory[i];
  17366. if( !clif_merge_item_check( sd.inventory_data[i], it ) ){
  17367. continue;
  17368. }
  17369. if( clif_merge_item_has_pair( &sd, it ) ){
  17370. p->items[n++].index = client_index( i );
  17371. p->packetLen += static_cast<decltype(p->packetLen)>( sizeof( p->items[0] ) );
  17372. }
  17373. }
  17374. // No item need to be merged
  17375. if( n < 2 ){
  17376. clif_msg( &sd, MSI_NOT_EXIST_MERGE_ITEM );
  17377. return;
  17378. }
  17379. clif_send( p, p->packetLen, &sd.bl, SELF );
  17380. #endif
  17381. }
  17382. /**
  17383. * Process item merge request.
  17384. * 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17385. * @param fd
  17386. * @param sd
  17387. **/
  17388. void clif_parse_merge_item_req( int32 fd, map_session_data* sd ){
  17389. const PACKET_CZ_REQ_MERGE_ITEM* p = reinterpret_cast<PACKET_CZ_REQ_MERGE_ITEM*>( RFIFOP( fd, 0 ) );
  17390. int32 count = ( p->packetLength - sizeof( *p ) ) / sizeof( p->indices[0] );
  17391. // No item need to be merged
  17392. if( count < 2 ){
  17393. clif_msg( sd, MSI_NOT_EXIST_MERGE_ITEM );
  17394. return;
  17395. }
  17396. uint16 idx_main = server_index( p->indices[0] );
  17397. if( idx_main >= MAX_INVENTORY ){
  17398. return;
  17399. }
  17400. if( !clif_merge_item_check( sd->inventory_data[idx_main], &sd->inventory.u.items_inventory[idx_main] ) ){
  17401. clif_msg( sd, MSI_NOT_EXIST_MERGE_ITEM );
  17402. return;
  17403. }
  17404. // Ensure each index only comes once
  17405. std::unordered_set<uint16> indices;
  17406. for( int32 i = 1; i < count; i++ ){
  17407. uint16 idx = server_index( p->indices[i] );
  17408. if( idx >= MAX_INVENTORY ){
  17409. return;
  17410. }
  17411. if( sd->inventory_data[idx] == nullptr ){
  17412. return;
  17413. }
  17414. // Check if it is the same item
  17415. if( sd->inventory_data[idx]->nameid != sd->inventory_data[idx_main]->nameid ){
  17416. return;
  17417. }
  17418. if( !clif_merge_item_check( sd->inventory_data[idx], &sd->inventory.u.items_inventory[idx] ) ){
  17419. clif_msg( sd, MSI_NOT_EXIST_MERGE_ITEM );
  17420. return;
  17421. }
  17422. indices.insert( idx );
  17423. }
  17424. if( indices.empty() ){
  17425. clif_msg( sd, MSI_NOT_EXIST_MERGE_ITEM );
  17426. return;
  17427. }
  17428. uint32 total_amount = sd->inventory.u.items_inventory[idx_main].amount;
  17429. for( uint16 idx : indices ){
  17430. total_amount += sd->inventory.u.items_inventory[idx].amount;
  17431. }
  17432. uint16 stack = sd->inventory_data[idx_main]->stack.amount;
  17433. if( stack == 0 ){
  17434. stack = MAX_AMOUNT;
  17435. }
  17436. if( total_amount >= stack ){
  17437. clif_merge_item_ack( *sd, MERGE_ITEM_FAILED_MAX_COUNT );
  17438. return;
  17439. }
  17440. // Merrrrge!!!!
  17441. for( uint16 idx : indices ){
  17442. uint16 amount = sd->inventory.u.items_inventory[idx].amount;
  17443. log_pick_pc( sd, LOG_TYPE_MERGE_ITEM, -amount, &sd->inventory.u.items_inventory[idx] );
  17444. memset( &sd->inventory.u.items_inventory[idx], 0, sizeof( sd->inventory.u.items_inventory[0] ) );
  17445. sd->inventory_data[idx] = nullptr;
  17446. clif_delitem( *sd, idx, amount, 0 );
  17447. }
  17448. sd->inventory.u.items_inventory[idx_main].amount = total_amount;
  17449. clif_merge_item_ack( *sd, MERGE_ITEM_SUCCESS, idx_main, total_amount );
  17450. }
  17451. /**
  17452. * Cancel item merge
  17453. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17454. * @param fd
  17455. * @param sd
  17456. **/
  17457. void clif_parse_merge_item_cancel(int32 fd, map_session_data* sd) {
  17458. return; // Nothing todo yet
  17459. }
  17460. static std::string clif_hide_name(const char* original_name)
  17461. {
  17462. std::string censored(original_name);
  17463. size_t hide = zmin(battle_config.broadcast_hide_name, censored.length() - 1);
  17464. censored.replace(censored.length() - hide, hide, hide, '*');
  17465. return censored;
  17466. }
  17467. /**
  17468. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17469. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17470. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17471. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17472. **/
  17473. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17474. char name[NAME_LENGTH];
  17475. if( battle_config.broadcast_hide_name ){
  17476. std::string dispname = clif_hide_name(char_name);
  17477. safestrncpy(name, dispname.c_str(), sizeof(name));
  17478. }else{
  17479. safestrncpy( name, char_name, sizeof( name ) );
  17480. }
  17481. switch( type ){
  17482. case ITEMOBTAIN_TYPE_BOXITEM:
  17483. #if PACKETVER >= 20091201
  17484. {
  17485. PACKET_ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN_item p = {};
  17486. p.PacketType = package_item_announceType;
  17487. p.PacketLength = sizeof( p );
  17488. p.type = type;
  17489. p.ItemID = client_nameid( nameid );
  17490. p.len = NAME_LENGTH;
  17491. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17492. p.boxItemID_len = (int8)sizeof( p.BoxItemID );
  17493. p.BoxItemID = client_nameid( container );
  17494. #if PACKETVER_MAIN_NUM >= 20220518 || PACKETVER_ZERO_NUM >= 20220518
  17495. p.refineLevel_len = (int8)sizeof( p.refineLevel );
  17496. p.refineLevel = 0; // TODO: implement
  17497. #endif
  17498. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17499. }
  17500. #endif
  17501. break;
  17502. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17503. case ITEMOBTAIN_TYPE_NPC:
  17504. {
  17505. struct packet_item_drop_announce p;
  17506. p.PacketType = item_drop_announceType;
  17507. p.type = type;
  17508. p.ItemID = client_nameid( nameid );
  17509. p.len = NAME_LENGTH;
  17510. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17511. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17512. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17513. p.monsterNameLen = NAME_LENGTH;
  17514. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17515. }else{
  17516. p.monsterNameLen = 0;
  17517. p.monsterName[0] = '\0';
  17518. }
  17519. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17520. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17521. #else
  17522. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17523. #endif
  17524. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17525. }
  17526. break;
  17527. }
  17528. }
  17529. /// Open the dress room window.
  17530. /// 0A02 <view>.W (ZC_DRESSROOM_OPEN)
  17531. void clif_dressing_room( map_session_data& sd ){
  17532. #if PACKETVER >= 20140212
  17533. PACKET_ZC_DRESSROOM_OPEN p = {};
  17534. p.packetType = HEADER_ZC_DRESSROOM_OPEN;
  17535. p.view = 0; // Ignored
  17536. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17537. #endif
  17538. }
  17539. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17540. /// 0A35 <result>.W
  17541. void clif_parse_Oneclick_Itemidentify(int32 fd, map_session_data *sd) {
  17542. #if PACKETVER >= 20150513
  17543. int16 idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17544. // Ignore the request
  17545. // - Invalid item index
  17546. // - Invalid item ID or item doesn't exist
  17547. // - Item is already identified
  17548. if (idx < 0 || idx >= MAX_INVENTORY ||
  17549. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == nullptr ||
  17550. sd->inventory.u.items_inventory[idx].identify)
  17551. return;
  17552. // Ignore the request - No magnifiers in inventory
  17553. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17554. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17555. return;
  17556. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17557. return;
  17558. skill_identify(sd, idx);
  17559. #endif
  17560. }
  17561. /// Starts navigation to the given target on client side
  17562. void clif_navigateTo(map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17563. #if PACKETVER >= 20111010
  17564. int32 fd = sd->fd;
  17565. WFIFOHEAD(fd,27);
  17566. WFIFOW(fd,0) = 0x08e2;
  17567. // How detailed will our navigation be?
  17568. if( mob_id > 0 ){
  17569. x = 0;
  17570. y = 0;
  17571. WFIFOB(fd,2) = 3; // monster with destination field
  17572. }else if( x > 0 && y > 0 ){
  17573. WFIFOB(fd,2) = 0; // with coordinates
  17574. }else{
  17575. x = 0;
  17576. y = 0;
  17577. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17578. }
  17579. // Which services can be used for transportation?
  17580. WFIFOB(fd,3) = flag;
  17581. // If this flag is set, the navigation window will not be opened up
  17582. WFIFOB(fd,4) = hideWindow;
  17583. // Target map
  17584. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17585. // Target x
  17586. WFIFOW(fd,21) = x;
  17587. // Target y
  17588. WFIFOW(fd,23) = y;
  17589. // Target monster ID
  17590. WFIFOW(fd,25) = mob_id;
  17591. WFIFOSET(fd,27);
  17592. #endif
  17593. }
  17594. /// Send hat effects to the client.
  17595. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W } (ZC_EQUIPMENT_EFFECT)
  17596. void clif_hat_effects( map_session_data& sd, block_list& bl, enum send_target target ){
  17597. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17598. map_session_data *tsd;
  17599. block_list* tbl;
  17600. if( target == SELF ){
  17601. tsd = BL_CAST(BL_PC,&bl);
  17602. tbl = &sd.bl;
  17603. }else{
  17604. tsd = &sd;
  17605. tbl = &bl;
  17606. }
  17607. if( tsd == nullptr ){
  17608. return;
  17609. }
  17610. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->getMapFlag(MF_NOCOSTUME) ){
  17611. return;
  17612. }
  17613. PACKET_ZC_EQUIPMENT_EFFECT* p = reinterpret_cast<PACKET_ZC_EQUIPMENT_EFFECT*>( packet_buffer );
  17614. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17615. p->packetLength = sizeof( *p );
  17616. p->aid = tsd->bl.id;
  17617. p->status = 1;
  17618. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17619. p->effects[i] = tsd->hatEffects[i];
  17620. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->effects[0] ) );
  17621. }
  17622. clif_send( p, p->packetLength, tbl, target );
  17623. #endif
  17624. }
  17625. /// Send a single hat effect to the client.
  17626. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W } (ZC_EQUIPMENT_EFFECT)
  17627. void clif_hat_effect_single( map_session_data& sd, uint16 effectId, bool enable ){
  17628. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17629. PACKET_ZC_EQUIPMENT_EFFECT* p = reinterpret_cast<PACKET_ZC_EQUIPMENT_EFFECT*>( packet_buffer );
  17630. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17631. p->packetLength = sizeof( *p );
  17632. p->aid = sd.bl.id;
  17633. p->status = enable;
  17634. p->effects[0] = effectId;
  17635. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->effects[0] ) );
  17636. clif_send( p, p->packetLength, &sd.bl, AREA );
  17637. #endif
  17638. }
  17639. /// Notify the client that a sale has started
  17640. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17641. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17642. #if PACKETVER_SUPPORTS_SALES
  17643. PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p = {};
  17644. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17645. p.itemId = client_nameid( sale_item->nameid );
  17646. p.remainingTime = (uint32)(sale_item->end - time(nullptr)); // time in S
  17647. clif_send( &p, sizeof( p ), bl, target );
  17648. #endif
  17649. }
  17650. /// Notify the client that a sale has ended
  17651. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17652. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17653. #if PACKETVER_SUPPORTS_SALES
  17654. PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p = {};
  17655. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17656. p.itemId = client_nameid( sale_item->nameid );
  17657. clif_send( &p, sizeof( p ), bl, target );
  17658. #endif
  17659. }
  17660. /// Update the remaining amount of a sale item.
  17661. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17662. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17663. #if PACKETVER_SUPPORTS_SALES
  17664. PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p = {};
  17665. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17666. p.itemId = client_nameid( sale_item->nameid );
  17667. p.amount = sale_item->amount;
  17668. clif_send( &p, sizeof( p ), bl, target );
  17669. #endif
  17670. }
  17671. /// The client requested a refresh of the current remaining count of a sale item
  17672. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17673. void clif_parse_sale_refresh( int32 fd, map_session_data* sd ){
  17674. #if PACKETVER_SUPPORTS_SALES
  17675. const PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = reinterpret_cast<PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*>( RFIFOP( fd, 0 ) );
  17676. struct sale_item_data* sale;
  17677. if( p->AID != sd->status.account_id ){
  17678. return;
  17679. }
  17680. sale = sale_find_item( p->itemId, true );
  17681. if( sale == nullptr ){
  17682. return;
  17683. }
  17684. clif_sale_amount(sale, &sd->bl, SELF);
  17685. #endif
  17686. }
  17687. /// Opens the sale administration window on the client
  17688. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17689. void clif_sale_open( map_session_data* sd ){
  17690. #if PACKETVER_SUPPORTS_SALES
  17691. nullpo_retv(sd);
  17692. if( sd->state.sale_open ){
  17693. return;
  17694. }
  17695. sd->state.sale_open = true;
  17696. int32 fd = sd->fd;
  17697. WFIFOHEAD(fd, 2);
  17698. WFIFOW(fd, 0) = 0x9b5;
  17699. WFIFOSET(fd, 2);
  17700. #endif
  17701. }
  17702. /// Client request to open the sale administration window.
  17703. /// This is sent by /limitedsale
  17704. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17705. void clif_parse_sale_open( int32 fd, map_session_data* sd ){
  17706. #if PACKETVER_SUPPORTS_SALES
  17707. nullpo_retv(sd);
  17708. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17709. return;
  17710. }
  17711. char command[CHAT_SIZE_MAX];
  17712. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17713. is_atcommand(fd, sd, command, 1);
  17714. #endif
  17715. }
  17716. /// Closes the sale administration window on the client.
  17717. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17718. void clif_sale_close(map_session_data* sd) {
  17719. #if PACKETVER_SUPPORTS_SALES
  17720. nullpo_retv(sd);
  17721. if( !sd->state.sale_open ){
  17722. return;
  17723. }
  17724. sd->state.sale_open = false;
  17725. int32 fd = sd->fd;
  17726. WFIFOHEAD(fd, 2);
  17727. WFIFOW(fd, 0) = 0x9bd;
  17728. WFIFOSET(fd, 2);
  17729. #endif
  17730. }
  17731. /// Client request to close the sale administration window.
  17732. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17733. void clif_parse_sale_close(int32 fd, map_session_data* sd) {
  17734. #if PACKETVER_SUPPORTS_SALES
  17735. nullpo_retv(sd);
  17736. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17737. return;
  17738. }
  17739. clif_sale_close(sd);
  17740. #endif
  17741. }
  17742. /// Reply to a item search request for item sale administration.
  17743. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17744. void clif_sale_search_reply( map_session_data* sd, std::shared_ptr<s_cash_item> item ){
  17745. #if PACKETVER_SUPPORTS_SALES
  17746. PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p = {};
  17747. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17748. if( item != nullptr ){
  17749. p.result = 0;
  17750. p.itemId = client_nameid( item->nameid );
  17751. p.price = item->price;
  17752. }else{
  17753. p.result = 1;
  17754. p.itemId = 0;
  17755. p.price = 0;
  17756. }
  17757. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17758. #endif
  17759. }
  17760. /// Search request for an item sale administration.
  17761. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17762. void clif_parse_sale_search( int32 fd, map_session_data* sd ){
  17763. #if PACKETVER_SUPPORTS_SALES
  17764. char item_name[ITEM_NAME_LENGTH];
  17765. nullpo_retv(sd);
  17766. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17767. return;
  17768. }
  17769. if( !sd->state.sale_open ){
  17770. return;
  17771. }
  17772. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17773. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17774. // not found
  17775. if( id == nullptr ){
  17776. clif_sale_search_reply( sd, nullptr );
  17777. return;
  17778. }
  17779. clif_sale_search_reply( sd, cash_shop_db.findItemInTab( CASHSHOP_TAB_SALE, id->nameid ) );
  17780. #endif
  17781. }
  17782. /// Reply if an item was successfully put on sale or not.
  17783. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17784. void clif_sale_add_reply( map_session_data* sd, enum e_sale_add_result result ){
  17785. #if PACKETVER_SUPPORTS_SALES
  17786. int32 fd = sd->fd;
  17787. WFIFOHEAD(fd, 4);
  17788. WFIFOW(fd, 0) = 0x9af;
  17789. WFIFOW(fd, 2) = (uint16)result;
  17790. WFIFOSET(fd, 4);
  17791. #endif
  17792. }
  17793. /// A client request to put an item on sale.
  17794. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17795. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17796. void clif_parse_sale_add( int32 fd, map_session_data* sd ){
  17797. #if PACKETVER_SUPPORTS_SALES
  17798. nullpo_retv( sd );
  17799. const PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = reinterpret_cast<PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*>( RFIFOP( fd, 0 ) );
  17800. if( p->AID != sd->status.account_id ){
  17801. return;
  17802. }
  17803. if( !sd->state.sale_open ){
  17804. return;
  17805. }
  17806. time_t endTime = p->startTime + p->hours * 60 * 60;
  17807. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17808. #endif
  17809. }
  17810. /// Reply to an item removal from sale.
  17811. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17812. void clif_sale_remove_reply( map_session_data* sd, bool failed ){
  17813. #if PACKETVER_SUPPORTS_SALES
  17814. int32 fd = sd->fd;
  17815. WFIFOHEAD(fd, 4);
  17816. WFIFOW(fd, 0) = 0x9b1;
  17817. WFIFOW(fd, 2) = failed;
  17818. WFIFOSET(fd, 4);
  17819. #endif
  17820. }
  17821. /// Request to remove an item from sale.
  17822. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17823. void clif_parse_sale_remove( int32 fd, map_session_data* sd ){
  17824. #if PACKETVER_SUPPORTS_SALES
  17825. nullpo_retv( sd );
  17826. const PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = reinterpret_cast<PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*>( RFIFOP( fd, 0 ) );
  17827. if( p->AID != sd->status.account_id ){
  17828. return;
  17829. }
  17830. if( !sd->state.sale_open ){
  17831. return;
  17832. }
  17833. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17834. #endif
  17835. }
  17836. /// Achievement System
  17837. /// Author: Luxuri, Aleos
  17838. /**
  17839. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17840. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17841. */
  17842. void clif_achievement_list_all(map_session_data *sd)
  17843. {
  17844. nullpo_retv(sd);
  17845. if (!battle_config.feature_achievement) {
  17846. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17847. return;
  17848. }
  17849. int32 count = sd->achievement_data.count; // All achievements should be sent to the client
  17850. if (count == 0)
  17851. return;
  17852. int32 len = (50 * count) + 22;
  17853. int32 fd = sd->fd;
  17854. int32 *info = achievement_level(sd, true);
  17855. WFIFOHEAD(fd,len);
  17856. WFIFOW(fd, 0) = 0xa23;
  17857. WFIFOW(fd, 2) = len;
  17858. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17859. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17860. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17861. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17862. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17863. for (int32 i = 0; i < count; i++) {
  17864. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17865. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17866. for (int32 j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17867. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17868. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17869. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17870. }
  17871. WFIFOSET(fd, len);
  17872. }
  17873. /**
  17874. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17875. * 0a24 <ACHPoint>.L
  17876. */
  17877. void clif_achievement_update(map_session_data *sd, struct achievement *ach, int32 count)
  17878. {
  17879. nullpo_retv(sd);
  17880. if (!battle_config.feature_achievement) {
  17881. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17882. return;
  17883. }
  17884. int32 fd = sd->fd;
  17885. int32 *info = achievement_level(sd, true);
  17886. WFIFOHEAD(fd, packet_len(0xa24));
  17887. WFIFOW(fd, 0) = 0xa24;
  17888. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17889. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17890. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17891. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17892. if (ach) {
  17893. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17894. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17895. for (int32 i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17896. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17897. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17898. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17899. } else
  17900. memset(WFIFOP(fd, 16), 0, 40);
  17901. WFIFOSET(fd, packet_len(0xa24));
  17902. }
  17903. /**
  17904. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17905. * 0a25 <achievementID>.L
  17906. */
  17907. void clif_parse_AchievementCheckReward(int32 fd, map_session_data *sd)
  17908. {
  17909. nullpo_retv(sd);
  17910. if( sd->achievement_data.save )
  17911. intif_achievement_save(sd);
  17912. achievement_check_reward(sd, RFIFOL(fd,2));
  17913. }
  17914. /**
  17915. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17916. * 0a26 <result>.W <achievementID>.L
  17917. */
  17918. void clif_achievement_reward_ack(int32 fd, unsigned char result, int32 achievement_id)
  17919. {
  17920. WFIFOHEAD(fd, packet_len(0xa26));
  17921. WFIFOW(fd, 0) = 0xa26;
  17922. WFIFOB(fd, 2) = result;
  17923. WFIFOL(fd, 3) = achievement_id;
  17924. WFIFOSET(fd, packet_len(0xa26));
  17925. }
  17926. /// Process the pet evolution request
  17927. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17928. void clif_parse_pet_evolution( int32 fd, map_session_data *sd ){
  17929. #if PACKETVER >= 20141008
  17930. const PACKET_CZ_PET_EVOLUTION* p = reinterpret_cast<PACKET_CZ_PET_EVOLUTION*>( RFIFOP( fd, 0 ) );
  17931. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17932. if (!pet) {
  17933. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17934. return;
  17935. }
  17936. pet_evolution(sd, pet->class_);
  17937. #endif
  17938. }
  17939. /// Sends the result of the evolution to the client.
  17940. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17941. void clif_pet_evolution_result( map_session_data* sd, e_pet_evolution_result result ){
  17942. #if PACKETVER >= 20141008
  17943. int32 fd = sd->fd;
  17944. WFIFOHEAD(fd, packet_len(0x9fc));
  17945. WFIFOW(fd, 0) = 0x9fc;
  17946. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17947. WFIFOSET(fd, packet_len(0x9fc));
  17948. #endif
  17949. }
  17950. /*
  17951. * This packet is sent by /changedress or /nocosplay
  17952. *
  17953. * 0ae8
  17954. */
  17955. void clif_parse_changedress( int32 fd, map_session_data* sd ){
  17956. #if PACKETVER >= 20180103
  17957. char command[CHAT_SIZE_MAX];
  17958. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17959. is_atcommand( fd, sd, command, 1 );
  17960. #endif
  17961. }
  17962. /// Opens an UI window of the given type and initializes it with the given data
  17963. /// 0AE2 <type>.B <data>.L
  17964. void clif_ui_open( map_session_data& sd, enum out_ui_type ui_type, int32 data ){
  17965. #if PACKETVER >= 20151202
  17966. // If the UI requires state tracking
  17967. switch( ui_type ){
  17968. case OUT_UI_STYLIST:
  17969. sd.state.stylist_open = true;
  17970. break;
  17971. case OUT_UI_ENCHANTGRADE:
  17972. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  17973. sd.state.enchantgrade_open = true;
  17974. break;
  17975. #else
  17976. return;
  17977. #endif
  17978. }
  17979. PACKET_ZC_UI_OPEN p = {};
  17980. p.PacketType = HEADER_ZC_UI_OPEN;
  17981. p.UIType = ui_type;
  17982. #if PACKETVER >= 20171122
  17983. p.data = data;
  17984. #endif
  17985. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17986. #endif
  17987. }
  17988. /// Request to open an UI window of the given type
  17989. /// 0A68 <type>.B
  17990. void clif_parse_open_ui( int32 fd, map_session_data* sd ){
  17991. switch( RFIFOB(fd,2) ){
  17992. case IN_UI_ATTENDANCE:
  17993. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17994. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17995. }else if( pc_attendance_enabled() ){
  17996. clif_ui_open( *sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17997. }else{
  17998. clif_msg_color( sd, MSI_CHECK_ATTENDANCE_NOT_EVENT, color_table[COLOR_RED] );
  17999. }
  18000. break;
  18001. #if PACKETVER >= 20160316
  18002. case IN_UI_MACRO_REGISTER:
  18003. clif_ui_open(*sd, OUT_UI_CAPTCHA, 0);
  18004. break;
  18005. case IN_UI_MACRO_DETECTOR:
  18006. clif_ui_open(*sd, OUT_UI_MACRO, 0);
  18007. break;
  18008. #endif
  18009. }
  18010. }
  18011. /// Response for attedance request
  18012. /// 0AF0 <unknown>.L <data>.L
  18013. void clif_attendence_response( map_session_data *sd, int32 data ){
  18014. nullpo_retv(sd);
  18015. int32 fd = sd->fd;
  18016. WFIFOHEAD(fd,packet_len(0xAF0));
  18017. WFIFOW(fd,0) = 0xAF0;
  18018. WFIFOL(fd,2) = 0;
  18019. WFIFOL(fd,6) = data;
  18020. WFIFOSET(fd,packet_len(0xAF0));
  18021. }
  18022. /// Request from the client to retrieve today's attendance reward
  18023. /// 0AEF
  18024. void clif_parse_attendance_request( int32 fd, map_session_data* sd ){
  18025. pc_attendance_claim_reward(sd);
  18026. }
  18027. /// Send out the percentage of weight that causes it to be displayed in red.
  18028. /// 0ADE <percentage>.L
  18029. void clif_weight_limit( map_session_data* sd ){
  18030. #if PACKETVER >= 20171025
  18031. nullpo_retv(sd);
  18032. int32 fd = sd->fd;
  18033. WFIFOHEAD(fd, packet_len(0xADE));
  18034. WFIFOW(fd, 0) = 0xADE;
  18035. #ifdef RENEWAL
  18036. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  18037. #else
  18038. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  18039. #endif
  18040. WFIFOSET(fd, packet_len(0xADE));
  18041. #endif
  18042. }
  18043. enum e_private_airship_response : uint32{
  18044. PRIVATEAIRSHIP_OK,
  18045. PRIVATEAIRSHIP_RETRY,
  18046. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  18047. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  18048. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  18049. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  18050. };
  18051. /// Send out the response to a private airship request
  18052. /// 0A4A <response>.L
  18053. void clif_private_airship_response( map_session_data* sd, enum e_private_airship_response response ){
  18054. #if PACKETVER >= 20180321
  18055. nullpo_retv( sd );
  18056. int32 fd = sd->fd;
  18057. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  18058. WFIFOW( fd, 0 ) = 0xA4A;
  18059. WFIFOL( fd, 2 ) = response;
  18060. WFIFOSET( fd, packet_len( 0xA4A ) );
  18061. #endif
  18062. }
  18063. /// Parses a request for a private airship
  18064. /// 0A49 <mapname>.16B <itemid>.W
  18065. void clif_parse_private_airship_request( int32 fd, map_session_data* sd ){
  18066. #if PACKETVER >= 20180321
  18067. // Check if the feature is enabled
  18068. if( !battle_config.feature_privateairship ){
  18069. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  18070. return;
  18071. }
  18072. // Check if the player is allowed to warp from the source map
  18073. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  18074. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  18075. return;
  18076. }
  18077. const PACKET_CZ_PRIVATE_AIRSHIP_REQUEST* p = reinterpret_cast<PACKET_CZ_PRIVATE_AIRSHIP_REQUEST*>( RFIFOP( fd, 0 ) );
  18078. char mapname[MAP_NAME_LENGTH_EXT];
  18079. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  18080. int16 mapindex = mapindex_name2id( mapname );
  18081. // Check if we know the mapname
  18082. if( mapindex < 0 ){
  18083. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18084. return;
  18085. }
  18086. int16 mapid = map_mapindex2mapid( mapindex );
  18087. // Check if the map is available on this server
  18088. if( mapid < 0 ){
  18089. // TODO: add multi map-server support, cant validate the mapflags of the other server
  18090. return;
  18091. }
  18092. // Check if the player tried to warp to the map he is on
  18093. if( sd->bl.m == mapid ){
  18094. // This is blocked by the client, but just to be sure
  18095. return;
  18096. }
  18097. // This can only be a hack, so we prevent it
  18098. if( map_getmapdata( mapid )->instance_id ){
  18099. // Ignore requests to warp directly into a running instance
  18100. return;
  18101. }
  18102. // Check if the player is allowed to warp to the target map
  18103. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  18104. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  18105. return;
  18106. }
  18107. t_itemid item_id = p->ItemID;
  18108. // Check if the item sent by the client is known to us
  18109. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  18110. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  18111. return;
  18112. }
  18113. int32 idx = pc_search_inventory( sd, item_id );
  18114. // Check if the player has the item at all
  18115. if( idx < 0 ){
  18116. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  18117. return;
  18118. }
  18119. // Delete the chosen item
  18120. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  18121. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  18122. return;
  18123. }
  18124. // Warp the player to a random spot on the destination map
  18125. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  18126. #endif
  18127. }
  18128. /// Sends out the usage history of the guild storage
  18129. /// 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
  18130. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  18131. void clif_guild_storage_log( map_session_data& sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  18132. #if PACKETVER >= 20140205
  18133. PACKET_ZC_ACK_GUILDSTORAGE_LOG* p = reinterpret_cast<PACKET_ZC_ACK_GUILDSTORAGE_LOG*>( packet_buffer );
  18134. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  18135. p->PacketLength = sizeof( *p );
  18136. p->result = result;
  18137. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  18138. p->amount = (uint16)log.size();
  18139. for( int32 i = 0; i < log.size(); i++ ){
  18140. PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub& item = p->items[i];
  18141. struct guild_log_entry& entry = log[i];
  18142. item.id = entry.id;
  18143. item.itemId = client_nameid( entry.item.nameid );
  18144. item.amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  18145. item.action = entry.amount > 0; // action = true(put), false(get)
  18146. item.refine = entry.item.refine;
  18147. item.uniqueId = entry.item.unique_id;
  18148. item.IsIdentified = entry.item.identify;
  18149. item.itemType = itemtype( entry.item.nameid );
  18150. clif_addcards( &item.slot, &entry.item );
  18151. safestrncpy( item.name, entry.name, NAME_LENGTH );
  18152. safestrncpy( item.time, entry.time, NAME_LENGTH );
  18153. item.attribute = entry.item.attribute;
  18154. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof ( item ) );
  18155. }
  18156. }else{
  18157. p->amount = 0;
  18158. }
  18159. clif_send( p, p->PacketLength, &sd.bl, SELF );
  18160. #endif
  18161. }
  18162. /// Activates the client camera info or updates the client camera with the given values.
  18163. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18164. void clif_camerainfo( map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18165. #if PACKETVER >= 20160525
  18166. int32 fd = sd->fd;
  18167. WFIFOHEAD(fd, packet_len(0xa78));
  18168. WFIFOW(fd, 0) = 0xa78;
  18169. WFIFOB(fd, 2) = show;
  18170. WFIFOF(fd, 3) = range;
  18171. WFIFOF(fd, 7) = rotation;
  18172. WFIFOF(fd, 11) = latitude;
  18173. WFIFOSET(fd, packet_len(0xa78));
  18174. #endif
  18175. }
  18176. /// Activates or deactives the client camera info or updates the camera settings.
  18177. /// This packet is triggered by /viewpointvalue or /setcamera
  18178. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18179. void clif_parse_camerainfo( int32 fd, map_session_data* sd ){
  18180. char command[CHAT_SIZE_MAX];
  18181. // /viewpointvalue
  18182. if( RFIFOB( fd, 2 ) == 1 ){
  18183. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18184. // /setcamera
  18185. }else{
  18186. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18187. }
  18188. is_atcommand( fd, sd, command, 1 );
  18189. }
  18190. /// Send the full list of items in the equip switch window
  18191. /// 0a9b <length>.W { <index>.W <position>.L }*
  18192. void clif_equipswitch_list( map_session_data* sd ){
  18193. #if PACKETVER >= 20170208
  18194. int32 fd = sd->fd;
  18195. int32 offset, i, position;
  18196. WFIFOW(fd, 0) = 0xa9b;
  18197. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18198. int16 index = sd->equip_switch_index[i];
  18199. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18200. WFIFOW(fd, offset) = index + 2;
  18201. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18202. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18203. offset += 6;
  18204. }
  18205. }
  18206. WFIFOW(fd, 2) = offset;
  18207. WFIFOSET(fd, offset);
  18208. #endif
  18209. }
  18210. /// Acknowledgement for removing an equip to the equip switch window
  18211. /// 0a9a <index>.W <position.>.L <failure>.W
  18212. void clif_equipswitch_remove( map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18213. #if PACKETVER >= 20170208
  18214. int32 fd = sd->fd;
  18215. WFIFOHEAD(fd, packet_len(0xa9a));
  18216. WFIFOW(fd, 0) = 0xa9a;
  18217. WFIFOW(fd, 2) = index + 2;
  18218. WFIFOL(fd, 4) = pos;
  18219. WFIFOW(fd, 8) = failed;
  18220. WFIFOSET(fd, packet_len(0xa9a));
  18221. #endif
  18222. }
  18223. /// Request to remove an equip from the equip switch window
  18224. /// 0a99 <index>.W <position>.L <= 20170502
  18225. /// 0a99 <index>.W
  18226. void clif_parse_equipswitch_remove( int32 fd, map_session_data* sd ){
  18227. #if PACKETVER >= 20170208
  18228. uint16 index = RFIFOW(fd, 2) - 2;
  18229. bool removed = false;
  18230. if( !battle_config.feature_equipswitch ){
  18231. return;
  18232. }
  18233. // Check if the index is valid
  18234. if( index >= MAX_INVENTORY ){
  18235. return;
  18236. }
  18237. pc_equipswitch_remove( sd, index );
  18238. #endif
  18239. }
  18240. /// Acknowledgement for adding an equip to the equip switch window
  18241. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18242. /// 0a98 <index>.W <position.>.L <flag>.W
  18243. void clif_equipswitch_add( map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18244. #if PACKETVER >= 20170208
  18245. int32 fd = sd->fd;
  18246. WFIFOHEAD(fd, packet_len(0xa98));
  18247. WFIFOW(fd, 0) = 0xa98;
  18248. WFIFOW(fd, 2) = index + 2;
  18249. WFIFOL(fd, 4) = pos;
  18250. #if PACKETVER <= 20170502
  18251. WFIFOL(fd, 8) = flag;
  18252. #else
  18253. WFIFOW(fd, 8) = flag;
  18254. #endif
  18255. WFIFOSET(fd,packet_len(0xa98));
  18256. #endif
  18257. }
  18258. /// Request to add an equip to the equip switch window
  18259. /// 0a97 <index>.W <position>.L
  18260. void clif_parse_equipswitch_add( int32 fd, map_session_data* sd ){
  18261. #if PACKETVER >= 20170208
  18262. uint16 index = RFIFOW(fd, 2) - 2;
  18263. uint32 position = RFIFOL(fd, 4);
  18264. if( !battle_config.feature_equipswitch ){
  18265. return;
  18266. }
  18267. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18268. return;
  18269. }
  18270. if( sd->state.trading || sd->npc_shopid ){
  18271. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18272. return;
  18273. }
  18274. if( sd->inventory_data[index]->type == IT_AMMO ){
  18275. position = EQP_AMMO;
  18276. }
  18277. pc_equipitem( sd, index, position, true );
  18278. #endif
  18279. }
  18280. /// Acknowledgement packet for the full equip switch
  18281. /// 0a9d <failed>.W
  18282. void clif_equipswitch_reply( map_session_data* sd, bool failed ){
  18283. #if PACKETVER >= 20170208
  18284. int32 fd = sd->fd;
  18285. WFIFOHEAD(fd, packet_len(0xa9d));
  18286. WFIFOW(fd, 0) = 0xa9d;
  18287. WFIFOW(fd, 2) = failed;
  18288. WFIFOSET(fd, packet_len(0xa9d));
  18289. #endif
  18290. }
  18291. /// Request to do a full equip switch
  18292. /// 0a9c
  18293. void clif_parse_equipswitch_request( int32 fd, map_session_data* sd ){
  18294. #if PACKETVER >= 20170208
  18295. int32 i;
  18296. t_tick tick = gettick();
  18297. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18298. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18299. // Client will not let you send a request
  18300. return;
  18301. }
  18302. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18303. if( !battle_config.feature_equipswitch ){
  18304. return;
  18305. }
  18306. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18307. if( i == EQI_MAX ){
  18308. // client will show: "There is no item to replace." and should not even come here
  18309. clif_equipswitch_reply( sd, false );
  18310. return;
  18311. }
  18312. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18313. return;
  18314. }
  18315. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18316. #endif
  18317. }
  18318. /// Request to do a single equip switch
  18319. /// 0ace <index>.W
  18320. void clif_parse_equipswitch_request_single( int32 fd, map_session_data* sd ){
  18321. #if PACKETVER >= 20170502
  18322. uint16 index = RFIFOW(fd, 2) - 2;
  18323. if( !battle_config.feature_equipswitch ){
  18324. return;
  18325. }
  18326. // Check if the index is valid
  18327. if( index >= MAX_INVENTORY ){
  18328. return;
  18329. }
  18330. // Check if the item exists
  18331. if (sd->inventory_data[index] == nullptr)
  18332. return;
  18333. // Check if the item was already added to equip switch
  18334. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18335. if( sd->npc_id ){
  18336. #ifdef RENEWAL
  18337. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18338. clif_msg( sd, MSI_BUSY);
  18339. return;
  18340. }
  18341. #endif
  18342. if( !sd->npc_item_flag ){
  18343. return;
  18344. }
  18345. }
  18346. pc_equipswitch( sd, index );
  18347. return;
  18348. }
  18349. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18350. #endif
  18351. }
  18352. void clif_parse_StartUseSkillToId( int32 fd, map_session_data* sd ){
  18353. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18354. const PACKET_CZ_USE_SKILL_START* p = reinterpret_cast<PACKET_CZ_USE_SKILL_START*>( RFIFOP( fd, 0 ) );
  18355. // Only rolling cutter is supported for now
  18356. if( p->skillId != GC_ROLLINGCUTTER ){
  18357. return;
  18358. }
  18359. // Already running - cant happen on officials, since only one skill is supported
  18360. if( sd->skill_keep_using.skill_id != 0 ){
  18361. return;
  18362. }
  18363. sd->skill_keep_using.tid = INVALID_TIMER;
  18364. sd->skill_keep_using.skill_id = p->skillId;
  18365. sd->skill_keep_using.level = p->skillLv;
  18366. sd->skill_keep_using.target = p->targetId;
  18367. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18368. #endif
  18369. }
  18370. void clif_parse_StopUseSkillToId( int32 fd, map_session_data* sd ){
  18371. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18372. const PACKET_CZ_USE_SKILL_END* p = reinterpret_cast<PACKET_CZ_USE_SKILL_END*>( RFIFOP( fd, 0 ) );
  18373. // Not running
  18374. if( sd->skill_keep_using.skill_id == 0 ){
  18375. return;
  18376. }
  18377. #if 0
  18378. // Hack
  18379. if( p->skillId != sd->skill_keep_using.skill_id ){
  18380. return;
  18381. }
  18382. #endif
  18383. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18384. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18385. sd->skill_keep_using.tid = INVALID_TIMER;
  18386. }
  18387. sd->skill_keep_using.skill_id = 0;
  18388. sd->skill_keep_using.level = 0;
  18389. sd->skill_keep_using.target = 0;
  18390. #endif
  18391. }
  18392. void clif_ping( map_session_data* sd ){
  18393. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18394. nullpo_retv( sd );
  18395. int32 fd = sd->fd;
  18396. if( !session_isActive( fd ) ){
  18397. return;
  18398. }
  18399. PACKET_ZC_PING_LIVE p = {};
  18400. p.packetType = HEADER_ZC_PING_LIVE;
  18401. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18402. #endif
  18403. }
  18404. int32 clif_ping_timer_sub( map_session_data *sd, va_list ap ){
  18405. nullpo_ret( sd );
  18406. int32 fd = sd->fd;
  18407. if( !session_isActive( fd ) ){
  18408. return 0;
  18409. }
  18410. t_tick tick = va_arg( ap, t_tick );
  18411. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18412. clif_ping( sd );
  18413. }
  18414. return 0;
  18415. }
  18416. TIMER_FUNC( clif_ping_timer ){
  18417. map_foreachpc( clif_ping_timer_sub, gettick() );
  18418. return 0;
  18419. }
  18420. /**
  18421. * Opens the refine UI on the designated client.
  18422. * 0aa0
  18423. */
  18424. void clif_refineui_open( map_session_data* sd ){
  18425. #if PACKETVER >= 20161012
  18426. nullpo_retv( sd );
  18427. PACKET_ZC_OPEN_REFINING_UI p = {};
  18428. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18429. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18430. sd->state.refineui_open = true;
  18431. #endif
  18432. }
  18433. /**
  18434. * Parses cancel/close of the refine UI on client side.
  18435. * 0aa4
  18436. */
  18437. void clif_parse_refineui_close( int32 fd, map_session_data* sd ){
  18438. #if PACKETVER >= 20161012
  18439. sd->state.refineui_open = false;
  18440. #endif
  18441. }
  18442. /**
  18443. * Adds the selected item into the refine UI and sends the possible materials
  18444. * to the client.
  18445. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18446. */
  18447. void clif_refineui_info( map_session_data* sd, uint16 index ){
  18448. #if PACKETVER >= 20161012
  18449. int32 fd = sd->fd;
  18450. // Get the item db reference
  18451. struct item_data* id = sd->inventory_data[index];
  18452. // No item data was found
  18453. if( id == nullptr ){
  18454. return;
  18455. }
  18456. // Check the inventory
  18457. struct item* item = &sd->inventory.u.items_inventory[index];
  18458. // No item was found at the given index
  18459. if( item == nullptr ){
  18460. return;
  18461. }
  18462. // Check if the item is identified
  18463. if( !item->identify ){
  18464. return;
  18465. }
  18466. // Check if the item is broken
  18467. if( item->attribute ){
  18468. return;
  18469. }
  18470. PACKET_ZC_REFINING_MATERIAL_LIST* p = reinterpret_cast<PACKET_ZC_REFINING_MATERIAL_LIST*>( packet_buffer );
  18471. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18472. p->packetLength = sizeof( *p );
  18473. p->itemIndex = client_index( index );
  18474. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18475. // No possibilities were found
  18476. if( info == nullptr ){
  18477. p->blacksmithBlessing = 0;
  18478. }else{
  18479. p->blacksmithBlessing = static_cast<decltype(p->blacksmithBlessing)>( info->blessing_amount );
  18480. for( uint16 i = REFINE_COST_NORMAL, count = 0; i < REFINE_COST_MAX; i++ ){
  18481. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18482. if( cost == nullptr ){
  18483. continue;
  18484. }
  18485. PACKET_ZC_REFINING_MATERIAL_LIST_SUB& entry = p->req[count];
  18486. entry.itemId = client_nameid( cost->nameid );
  18487. entry.chance = static_cast<decltype(entry.chance)>( cost->chance / 100 );
  18488. entry.zeny = cost->zeny;
  18489. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  18490. count++;
  18491. }
  18492. }
  18493. clif_send( p, p->packetLength, &sd->bl, SELF );
  18494. #endif
  18495. }
  18496. /**
  18497. * Client request to add an item to the refine UI.
  18498. * 0aa1 <index>.W
  18499. */
  18500. void clif_parse_refineui_add( int32 fd, map_session_data* sd ){
  18501. #if PACKETVER >= 20161012
  18502. const PACKET_CZ_REFINING_SELECT_ITEM* p = reinterpret_cast<PACKET_CZ_REFINING_SELECT_ITEM*>( RFIFOP( fd, 0 ) );
  18503. uint16 index = server_index( p->index );
  18504. // Check if the refine UI is open
  18505. if( !sd->state.refineui_open ){
  18506. return;
  18507. }
  18508. // Check if the index is valid
  18509. if( index >= MAX_INVENTORY ){
  18510. return;
  18511. }
  18512. // Send out the requirements for the refine process
  18513. clif_refineui_info( sd, index );
  18514. #endif
  18515. }
  18516. /**
  18517. * Client requests to try to refine an item.
  18518. * 0aa3 <index>.W <material>.W <catalyst>.B
  18519. */
  18520. void clif_parse_refineui_refine( int32 fd, map_session_data* sd ){
  18521. #if PACKETVER >= 20161012
  18522. const PACKET_CZ_REQ_REFINING* p = reinterpret_cast<PACKET_CZ_REQ_REFINING*>( RFIFOP( fd, 0 ) );
  18523. uint16 index = server_index( p->index );
  18524. t_itemid material = p->itemId;
  18525. int16 j;
  18526. // Check if the refine UI is open
  18527. if( !sd->state.refineui_open ){
  18528. return;
  18529. }
  18530. // Check if the index is valid
  18531. if( index >= MAX_INVENTORY ){
  18532. return;
  18533. }
  18534. // Get the item db reference
  18535. struct item_data* id = sd->inventory_data[index];
  18536. // No item data was found
  18537. if( id == nullptr ){
  18538. return;
  18539. }
  18540. // Check the inventory
  18541. struct item* item = &sd->inventory.u.items_inventory[index];
  18542. // No item was found at the given index
  18543. if( item == nullptr ){
  18544. return;
  18545. }
  18546. // Check if the item is identified
  18547. if( !item->identify ){
  18548. return;
  18549. }
  18550. // Check if the item is broken
  18551. if( item->attribute ){
  18552. return;
  18553. }
  18554. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18555. // No refine possible
  18556. if( info == nullptr ){
  18557. return;
  18558. }
  18559. // No possibilities were found
  18560. if( info->costs.empty() ){
  18561. return;
  18562. }
  18563. // Check if the player has the selected material
  18564. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18565. return;
  18566. }
  18567. int16 blacksmith_index = -1;
  18568. uint16 blacksmith_amount = 0;
  18569. // Check if the player has enough blacksmith blessings
  18570. if( p->blacksmithBlessing != 0 ){
  18571. blacksmith_amount = info->blessing_amount;
  18572. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18573. if( blacksmith_amount == 0 ){
  18574. return;
  18575. }
  18576. // Check if the player has blacksmith blessings
  18577. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18578. return;
  18579. }
  18580. // Check if the player has enough blacksmith blessings
  18581. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18582. return;
  18583. }
  18584. }
  18585. std::shared_ptr<s_refine_cost> cost = nullptr;
  18586. for( const auto& pair : info->costs ){
  18587. if( pair.second->nameid == material ){
  18588. cost = pair.second;
  18589. break;
  18590. }
  18591. }
  18592. // The material was not in the list of possible materials
  18593. if( cost == nullptr ){
  18594. return;
  18595. }
  18596. // Try to pay for the refine
  18597. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME ) ){
  18598. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18599. return;
  18600. }
  18601. // Delete the required material
  18602. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18603. return;
  18604. }
  18605. // Delete the required blacksmith blessings
  18606. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18607. return;
  18608. }
  18609. // Try to refine the item
  18610. if( cost->chance >= ( rnd() % 10000 ) ){
  18611. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18612. // Success
  18613. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18614. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18615. clif_misceffect( sd->bl, NOTIFYEFFECT_REFINE_SUCCESS );
  18616. clif_refine( *sd, index, ITEMREFINING_SUCCESS );
  18617. if (info->broadcast_success) {
  18618. clif_broadcast_refine_result(*sd, item->nameid, item->refine, true);
  18619. }
  18620. if( id->type == IT_WEAPON ){
  18621. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18622. }
  18623. clif_refineui_info( sd, index );
  18624. }else{
  18625. // Failure
  18626. if (info->broadcast_failure) {
  18627. clif_broadcast_refine_result(*sd, item->nameid, item->refine, false);
  18628. }
  18629. // Blacksmith blessings were used to prevent breaking and downgrading
  18630. if( blacksmith_amount > 0 ){
  18631. clif_refine( *sd, index, ITEMREFINING_FAILURE2 );
  18632. clif_refineui_info( sd, index );
  18633. // Delete the item if it is breakable
  18634. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18635. clif_refine( *sd, index, ITEMREFINING_FAILURE );
  18636. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18637. // Downgrade the item if necessary
  18638. }else if( cost->downgrade_amount > 0 ){
  18639. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18640. clif_refine( *sd, index, ITEMREFINING_DOWNGRADE );
  18641. clif_refineui_info(sd, index);
  18642. // Only show failure, but dont do anything
  18643. }else{
  18644. clif_refine( *sd, index, ITEMREFINING_FAILURE2 );
  18645. clif_refineui_info( sd, index );
  18646. }
  18647. clif_misceffect( sd->bl, NOTIFYEFFECT_REFINE_FAILURE );
  18648. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18649. }
  18650. #endif
  18651. }
  18652. void clif_unequipall_reply( map_session_data* sd, bool failed ){
  18653. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18654. PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18655. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18656. p.result = failed;
  18657. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18658. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18659. }
  18660. void clif_parse_unequipall( int32 fd, map_session_data* sd ){
  18661. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18662. if( pc_cant_act( sd ) ){
  18663. clif_unequipall_reply( sd, true );
  18664. return;
  18665. }
  18666. const PACKET_CZ_REQ_TAKEOFF_EQUIP_ALL* p = reinterpret_cast<PACKET_CZ_REQ_TAKEOFF_EQUIP_ALL*>( RFIFOP( fd, 0 ) );
  18667. #if PACKETVER_MAIN_NUM >= 20230906
  18668. uint32 location = p->location;
  18669. int32 max = EQI_MAX;
  18670. #else
  18671. uint32 location = 0xFFFFFFFF;
  18672. int32 max = EQI_COSTUME_HEAD_TOP;
  18673. #endif
  18674. for( int32 i = 0; i < max; i++ ){
  18675. if( sd->equip_index[i] >= 0 && ( location & equip_bitmask[i] ) != 0 ){
  18676. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18677. }
  18678. }
  18679. clif_unequipall_reply( sd, false );
  18680. #endif
  18681. }
  18682. void clif_stylist_response( map_session_data* sd, bool failed ){
  18683. #if PACKETVER >= 20151104
  18684. PACKET_ZC_STYLE_CHANGE_RES p = {};
  18685. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18686. p.flag = failed;
  18687. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18688. if( !failed ){
  18689. sd->state.stylist_open = false;
  18690. }
  18691. #endif
  18692. }
  18693. bool clif_parse_stylist_buy_sub( map_session_data* sd, _look look, int16 index ){
  18694. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18695. if( list == nullptr ){
  18696. return false;
  18697. }
  18698. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18699. if( entry == nullptr ){
  18700. return false;
  18701. }
  18702. std::shared_ptr<s_stylist_costs> costs;
  18703. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18704. costs = entry->doram;
  18705. }else{
  18706. costs = entry->human;
  18707. }
  18708. if( costs == nullptr ){
  18709. return false;
  18710. }
  18711. if( sd->status.zeny < costs->price ){
  18712. return false;
  18713. }
  18714. int16 inventoryIndex = -1;
  18715. if( costs->requiredItem != 0 ){
  18716. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18717. if( inventoryIndex < 0 ){
  18718. // No other option
  18719. if( costs->requiredItemBox == 0 ){
  18720. return false;
  18721. }
  18722. // Check if the box that contains the item is in the inventory
  18723. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18724. // The box containing the item also does not exist
  18725. if( inventoryIndex < 0 ){
  18726. return false;
  18727. }
  18728. }
  18729. }else if( costs->requiredItemBox != 0 ){
  18730. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18731. if( inventoryIndex < 0 ){
  18732. return false;
  18733. }
  18734. }
  18735. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18736. return false;
  18737. }
  18738. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER ) != 0 ){
  18739. return false;
  18740. }
  18741. switch( look ){
  18742. case LOOK_HAIR:
  18743. case LOOK_HAIR_COLOR:
  18744. case LOOK_CLOTHES_COLOR:
  18745. case LOOK_BODY2:
  18746. pc_changelook( sd, look, entry->value );
  18747. break;
  18748. case LOOK_HEAD_BOTTOM:
  18749. case LOOK_HEAD_MID:
  18750. case LOOK_HEAD_TOP: {
  18751. struct mail_message msg = {};
  18752. msg.dest_id = sd->status.char_id;
  18753. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18754. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18755. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18756. msg.item[0].nameid = entry->value;
  18757. msg.item[0].identify = 1;
  18758. msg.item[0].amount = 1;
  18759. msg.status = MAIL_NEW;
  18760. msg.type = MAIL_INBOX_NORMAL;
  18761. msg.timestamp = time( nullptr );
  18762. intif_Mail_send( 0, &msg );
  18763. } break;
  18764. }
  18765. return true;
  18766. }
  18767. void clif_parse_stylist_buy( int32 fd, map_session_data* sd ){
  18768. #if PACKETVER >= 20151104
  18769. #if PACKETVER >= 20180516
  18770. const PACKET_CZ_REQ_STYLE_CHANGE2* p = reinterpret_cast<PACKET_CZ_REQ_STYLE_CHANGE2*>( RFIFOP( fd, 0 ) );
  18771. #else
  18772. const PACKET_CZ_REQ_STYLE_CHANGE* p = reinterpret_cast<PACKET_CZ_REQ_STYLE_CHANGE*>( RFIFOP( fd, 0 ) );
  18773. #endif
  18774. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18775. clif_stylist_response( sd, true );
  18776. return;
  18777. }
  18778. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18779. clif_stylist_response( sd, true );
  18780. return;
  18781. }
  18782. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18783. clif_stylist_response( sd, true );
  18784. return;
  18785. }
  18786. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18787. clif_stylist_response( sd, true );
  18788. return;
  18789. }
  18790. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18791. clif_stylist_response( sd, true );
  18792. return;
  18793. }
  18794. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18795. clif_stylist_response( sd, true );
  18796. return;
  18797. }
  18798. #if PACKETVER >= 20180516
  18799. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18800. clif_stylist_response( sd, true );
  18801. return;
  18802. }
  18803. #endif
  18804. clif_stylist_response( sd, false );
  18805. #endif
  18806. }
  18807. void clif_parse_stylist_close( int32 fd, map_session_data* sd ){
  18808. #if PACKETVER >= 20151104
  18809. sd->state.stylist_open = false;
  18810. #endif
  18811. }
  18812. void clif_inventory_expansion_info( map_session_data* sd ){
  18813. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18814. nullpo_retv( sd );
  18815. PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18816. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18817. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18818. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18819. #endif
  18820. }
  18821. enum class e_inventory_expansion_response : uint8{
  18822. ASK_CONFIRMATION = 0,
  18823. FAILED,
  18824. BUSY,
  18825. MISSING_ITEM,
  18826. MAXIMUM_REACHED
  18827. };
  18828. void clif_inventory_expansion_response( map_session_data* sd, e_inventory_expansion_response response ){
  18829. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18830. nullpo_retv( sd );
  18831. PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18832. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18833. p.result = (uint8)response;
  18834. p.itemId = sd->state.inventory_expansion_confirmation;
  18835. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18836. #endif
  18837. }
  18838. void clif_parse_inventory_expansion_request( int32 fd, map_session_data* sd ){
  18839. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18840. // Check if player is dead or busy with other stuff
  18841. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18842. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18843. return;
  18844. }
  18845. // Check if the player already reached the maximum
  18846. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18847. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18848. return;
  18849. }
  18850. static std::map<t_itemid, uint16> items = {
  18851. // The order of entries in this list defines which will be used first
  18852. // This order and the usable items are hardcoded into the client
  18853. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18854. { ITEMID_INVENTORY_EX_EVT, 10 },
  18855. { ITEMID_INVENTORY_EX_DIS, 10 },
  18856. { ITEMID_INVENTORY_EX, 10 },
  18857. };
  18858. int16 index = -1;
  18859. bool found_over_limit = false;
  18860. for( const auto& entry : items ){
  18861. // Check if the player has the required item
  18862. index = pc_search_inventory( sd, entry.first );
  18863. // Found an item
  18864. if( index >= 0 ){
  18865. // Check if the player would exceed the maximum
  18866. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18867. found_over_limit = true;
  18868. }else{
  18869. found_over_limit = false;
  18870. sd->state.inventory_expansion_confirmation = entry.first;
  18871. sd->state.inventory_expansion_amount = entry.second;
  18872. break;
  18873. }
  18874. }
  18875. }
  18876. // Check if an item was found
  18877. if( sd->state.inventory_expansion_confirmation == 0 ){
  18878. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18879. return;
  18880. }
  18881. // Check if an item would have been found, but the player would exceed the maximum
  18882. if( found_over_limit ){
  18883. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18884. return;
  18885. }
  18886. // The player met all requirements => ask him for confirmation
  18887. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18888. #endif
  18889. }
  18890. enum class e_inventory_expansion_result : uint8{
  18891. SUCCESS = 0,
  18892. FAILED,
  18893. BUSY,
  18894. MISSING_ITEM,
  18895. MAXIMUM_REACHED
  18896. };
  18897. void clif_inventory_expansion_result( map_session_data* sd, e_inventory_expansion_result result ){
  18898. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18899. nullpo_retv( sd );
  18900. PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18901. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18902. p.result = (uint8)result;
  18903. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18904. // Reset the state tracking
  18905. sd->state.inventory_expansion_confirmation = 0;
  18906. sd->state.inventory_expansion_amount = 0;
  18907. #endif
  18908. }
  18909. void clif_parse_inventory_expansion_confirm( int32 fd, map_session_data* sd ){
  18910. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18911. if( sd->state.inventory_expansion_confirmation == 0 ){
  18912. return;
  18913. }
  18914. // Check if player is dead
  18915. if( pc_isdead( sd ) ){
  18916. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18917. return;
  18918. }
  18919. // Check if the player already reached the maximum
  18920. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18921. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18922. return;
  18923. }
  18924. // Check if the player has the required item
  18925. int32 index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18926. // The player did not have the item anymore
  18927. if( index < 0 ){
  18928. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18929. return;
  18930. }
  18931. // Check if the player would exceed the maximum
  18932. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18933. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18934. return;
  18935. }
  18936. // Delete the required item
  18937. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18938. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  18939. return;
  18940. }
  18941. // Increase the slots
  18942. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  18943. // Save player data (slots) and inventory data (removed item)
  18944. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  18945. // Inform the player of success
  18946. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  18947. clif_inventory_expansion_info( sd );
  18948. #endif
  18949. }
  18950. void clif_parse_inventory_expansion_reject( int32 fd, map_session_data* sd ){
  18951. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18952. sd->state.inventory_expansion_confirmation = 0;
  18953. sd->state.inventory_expansion_amount = 0;
  18954. #endif
  18955. }
  18956. void clif_barter_open( map_session_data& sd, struct npc_data& nd ){
  18957. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18958. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  18959. return;
  18960. }
  18961. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18962. if( barter == nullptr ){
  18963. return;
  18964. }
  18965. sd.state.barter_open = true;
  18966. PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = reinterpret_cast<PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*>( packet_buffer );
  18967. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  18968. p->packetLength = sizeof( *p );
  18969. int16 count = 0;
  18970. for( const auto& itemPair : barter->items ){
  18971. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18972. if( id == nullptr ){
  18973. continue;
  18974. }
  18975. PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub& item = p->list[count];
  18976. item.nameid = client_nameid( id->nameid );
  18977. item.type = itemtype( id->nameid );
  18978. if( itemPair.second->stockLimited ){
  18979. item.amount = itemPair.second->stock;
  18980. }else{
  18981. item.amount = -1;
  18982. }
  18983. item.weight = id->weight;
  18984. item.index = itemPair.second->index;
  18985. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18986. item.viewSprite = id->look;
  18987. item.location = pc_equippoint_sub( &sd, id.get() );
  18988. #endif
  18989. // Use a loop if someone did not start with index 0
  18990. for( const auto& requirementPair : itemPair.second->requirements ){
  18991. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  18992. item.currencyNameid = client_nameid( requirement->nameid );
  18993. item.currencyAmount = requirement->amount;
  18994. // It is a normal barter, cancel after first entry
  18995. break;
  18996. }
  18997. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( item ) );
  18998. count++;
  18999. }
  19000. clif_send( p, p->packetLength, &sd.bl, SELF );
  19001. #endif
  19002. }
  19003. void clif_parse_barter_close( int32 fd, map_session_data* sd ){
  19004. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19005. if( sd->state.barter_open ){
  19006. sd->npc_shopid = 0;
  19007. sd->state.barter_open = false;
  19008. }
  19009. #endif
  19010. }
  19011. void clif_parse_barter_buy( int32 fd, map_session_data* sd ){
  19012. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  19013. // No shop open
  19014. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  19015. return;
  19016. }
  19017. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19018. // Unknown shop
  19019. if( nd == nullptr ){
  19020. return;
  19021. }
  19022. // Not a barter
  19023. if( nd->subtype != NPCTYPE_BARTER ){
  19024. return;
  19025. }
  19026. // It is an extended barter
  19027. if( nd->u.barter.extended ){
  19028. return;
  19029. }
  19030. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19031. if( barter == nullptr ){
  19032. return;
  19033. }
  19034. const PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = reinterpret_cast<PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*>( RFIFOP( fd, 0 ) );
  19035. uint16 entries = ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] );
  19036. // Empty purchase list
  19037. if( entries == 0 ){
  19038. return;
  19039. }
  19040. std::vector<s_barter_purchase> purchases;
  19041. purchases.reserve( entries );
  19042. // Make sure each shop index and target item id is only used once
  19043. for( int32 i = 0; i < entries; i++ ){
  19044. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19045. // Invalid shop index
  19046. if( item == nullptr ){
  19047. return;
  19048. }
  19049. for( int32 j = i + 1; j < entries; j++ ){
  19050. // Same shop index
  19051. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19052. return;
  19053. }
  19054. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19055. // Invalid shop index
  19056. if( item2 == nullptr ){
  19057. return;
  19058. }
  19059. // Same target item id
  19060. if( item->nameid == item2->nameid ){
  19061. return;
  19062. }
  19063. }
  19064. s_barter_purchase purchase = {};
  19065. purchase.item = item;
  19066. purchase.amount = p->list[i].amount;
  19067. purchases.push_back( purchase );
  19068. }
  19069. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19070. #endif
  19071. }
  19072. void clif_barter_extended_open( map_session_data& sd, struct npc_data& nd ){
  19073. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19074. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  19075. return;
  19076. }
  19077. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  19078. if( barter == nullptr ){
  19079. return;
  19080. }
  19081. sd.state.barter_extended_open = true;
  19082. PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = reinterpret_cast<PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*>( packet_buffer );
  19083. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  19084. p->packetLength = sizeof( *p );
  19085. p->items_count = 0;
  19086. for( const auto& itemPair : barter->items ){
  19087. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  19088. if( id == nullptr ){
  19089. continue;
  19090. }
  19091. // Needs dynamic calculation, because of variable currencies
  19092. PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = reinterpret_cast<PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*>( WBUFP( p, p->packetLength ) );
  19093. item->nameid = client_nameid( id->nameid );
  19094. item->type = itemtype( id->nameid );
  19095. if( itemPair.second->stockLimited ){
  19096. item->amount = itemPair.second->stock;
  19097. }else{
  19098. item->amount = -1;
  19099. }
  19100. item->weight = id->weight;
  19101. item->index = itemPair.second->index;
  19102. item->zeny = itemPair.second->price;
  19103. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  19104. item->viewSprite = id->look;
  19105. item->location = pc_equippoint_sub( &sd, id.get() );
  19106. #endif
  19107. // Because of a MSVS bug, the currencies have been defined with a fixed array entry, which has to be substracted
  19108. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( *item ) - sizeof( item->currencies ) );
  19109. p->items_count++;
  19110. item->currency_count = 0;
  19111. for( const auto& requirementPair : itemPair.second->requirements ){
  19112. // Needs dynamic calculation, because of variable currencies
  19113. PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = reinterpret_cast<PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*>( WBUFP( p, p->packetLength ) );
  19114. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  19115. req->nameid = requirement->nameid;
  19116. if( requirement->refine >= 0 ){
  19117. req->refine_level = requirement->refine;
  19118. }else{
  19119. req->refine_level = 0;
  19120. }
  19121. req->amount = requirement->amount;
  19122. req->type = itemtype( requirement->nameid );
  19123. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( *req ) );
  19124. item->currency_count++;
  19125. }
  19126. }
  19127. clif_send( p, p->packetLength, &sd.bl, SELF );
  19128. #endif
  19129. }
  19130. void clif_parse_barter_extended_close( int32 fd, map_session_data* sd ){
  19131. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19132. if( sd->state.barter_extended_open ){
  19133. sd->npc_shopid = 0;
  19134. sd->state.barter_extended_open = false;
  19135. }
  19136. #endif
  19137. }
  19138. void clif_parse_barter_extended_buy( int32 fd, map_session_data* sd ){
  19139. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  19140. // No shop open
  19141. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  19142. return;
  19143. }
  19144. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  19145. // Unknown shop
  19146. if( nd == nullptr ){
  19147. return;
  19148. }
  19149. // Not a barter
  19150. if( nd->subtype != NPCTYPE_BARTER ){
  19151. return;
  19152. }
  19153. // Not an extended barter
  19154. if( !nd->u.barter.extended ){
  19155. return;
  19156. }
  19157. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19158. if( barter == nullptr ){
  19159. return;
  19160. }
  19161. const PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = reinterpret_cast<PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*>( RFIFOP( fd, 0 ) );
  19162. uint16 entries = ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] );
  19163. // Empty purchase list
  19164. if( entries == 0 ){
  19165. return;
  19166. }
  19167. std::vector<s_barter_purchase> purchases;
  19168. purchases.reserve( entries );
  19169. // Make sure each shop index and target item id is only used once
  19170. for( int32 i = 0; i < entries; i++ ){
  19171. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19172. // Invalid shop index
  19173. if( item == nullptr ){
  19174. return;
  19175. }
  19176. for( int32 j = i + 1; j < entries; j++ ){
  19177. // Same shop index
  19178. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19179. return;
  19180. }
  19181. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19182. // Invalid shop index
  19183. if( item2 == nullptr ){
  19184. return;
  19185. }
  19186. // Same target item id
  19187. if( item->nameid == item2->nameid ){
  19188. return;
  19189. }
  19190. }
  19191. s_barter_purchase purchase = {};
  19192. purchase.item = item;
  19193. purchase.amount = p->list[i].amount;
  19194. purchases.push_back( purchase );
  19195. }
  19196. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19197. #endif
  19198. }
  19199. void clif_summon_init(struct mob_data& md) {
  19200. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19201. struct block_list* master_bl = battle_get_master(&md.bl);
  19202. if( master_bl == nullptr ){
  19203. return;
  19204. }
  19205. PACKET_ZC_SUMMON_HP_INIT p = {};
  19206. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19207. p.summonAID = md.bl.id;
  19208. p.CurrentHP = md.status.hp;
  19209. p.MaxHP = md.status.max_hp;
  19210. clif_send( &p, sizeof( p ), master_bl, SELF );
  19211. #endif
  19212. }
  19213. void clif_summon_hp_bar(struct mob_data& md) {
  19214. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19215. struct block_list* master_bl = battle_get_master(&md.bl);
  19216. if( master_bl == nullptr ){
  19217. return;
  19218. }
  19219. PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19220. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19221. p.summonAID = md.bl.id;
  19222. p.VarId = SP_HP; // HP parameter
  19223. p.Value = md.status.hp;
  19224. clif_send( &p, sizeof( p ), master_bl, SELF );
  19225. #endif
  19226. }
  19227. void clif_laphine_synthesis_open( map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19228. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19229. nullpo_retv( sd );
  19230. sd->state.laphine_synthesis = synthesis->item_id;
  19231. PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19232. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19233. p.itemId = client_nameid( synthesis->item_id );
  19234. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19235. #endif
  19236. }
  19237. void clif_parse_laphine_synthesis_close( int32 fd, map_session_data* sd ){
  19238. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19239. sd->state.laphine_synthesis = 0;
  19240. #endif
  19241. }
  19242. enum e_laphine_synthesis_result : int16{
  19243. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19244. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19245. LAPHINE_SYNTHESIS_ITEM = 7
  19246. };
  19247. void clif_laphine_synthesis_result( map_session_data* sd, enum e_laphine_synthesis_result result ){
  19248. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19249. nullpo_retv( sd );
  19250. PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19251. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19252. p.result = result;
  19253. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19254. #endif
  19255. }
  19256. void clif_parse_laphine_synthesis( int32 fd, map_session_data* sd ){
  19257. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19258. if( sd->state.laphine_synthesis == 0 ){
  19259. return;
  19260. }
  19261. const PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = reinterpret_cast<PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*>( RFIFOP( fd, 0 ) );
  19262. if( sd->state.laphine_synthesis != p->itemId ){
  19263. return;
  19264. }
  19265. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19266. if( synthesis == nullptr ){
  19267. return;
  19268. }
  19269. size_t count = ( p->packetLength - sizeof( PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19270. // Player sent more or less than actually required
  19271. if( count != synthesis->requiredRequirements ){
  19272. return;
  19273. }
  19274. // Check for duplicates
  19275. for( size_t i = 0; i < count; i++ ){
  19276. for( size_t j = i + 1; j < count; j++ ){
  19277. if( p->items[i].index == p->items[j].index ){
  19278. return;
  19279. }
  19280. }
  19281. }
  19282. for( size_t i = 0; i < count; i++ ){
  19283. int16 index = server_index( p->items[i].index );
  19284. if( index >= MAX_INVENTORY ){
  19285. return;
  19286. }
  19287. if( sd->inventory_data[index] == nullptr ){
  19288. return;
  19289. }
  19290. struct item* item = &sd->inventory.u.items_inventory[index];
  19291. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19292. if( requirement == nullptr ){
  19293. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19294. return;
  19295. }
  19296. if( p->items[i].count != requirement->amount ){
  19297. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19298. return;
  19299. }
  19300. if( item->amount < requirement->amount ){
  19301. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19302. return;
  19303. }
  19304. if( item->refine < synthesis->minimumRefine ){
  19305. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19306. return;
  19307. }
  19308. if( item->refine > synthesis->maximumRefine ){
  19309. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19310. return;
  19311. }
  19312. if( item->equip != 0 ){
  19313. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19314. return;
  19315. }
  19316. if( item->equipSwitch != 0 ){
  19317. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19318. return;
  19319. }
  19320. }
  19321. // If triggered from item
  19322. if( sd->itemid == sd->state.laphine_synthesis ){
  19323. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19324. if( index < 0 ){
  19325. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19326. return;
  19327. }
  19328. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19329. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19330. return;
  19331. }
  19332. }
  19333. }
  19334. for( size_t i = 0; i < count; i++ ){
  19335. int16 index = server_index( p->items[i].index );
  19336. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19337. return;
  19338. }
  19339. }
  19340. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, *sd );
  19341. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19342. #endif
  19343. }
  19344. void clif_laphine_upgrade_open( map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19345. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19346. nullpo_retv( sd );
  19347. sd->state.laphine_upgrade = upgrade->item_id;
  19348. PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19349. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19350. p.itemId = client_nameid( upgrade->item_id );
  19351. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19352. #endif
  19353. }
  19354. void clif_parse_laphine_upgrade_close( int32 fd, map_session_data* sd ){
  19355. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19356. sd->state.laphine_upgrade = 0;
  19357. #endif
  19358. }
  19359. void clif_laphine_upgrade_result( map_session_data *sd, bool failed ){
  19360. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19361. PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19362. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19363. p.result = failed;
  19364. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19365. #endif
  19366. }
  19367. static void clif_item_preview( map_session_data *sd, int16 index ){
  19368. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19369. nullpo_retv( sd );
  19370. struct item* item = &sd->inventory.u.items_inventory[index];
  19371. PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19372. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19373. p.index = client_index( index );
  19374. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19375. p.isDamaged = item->attribute != 0;
  19376. #endif
  19377. p.refiningLevel = item->refine;
  19378. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19379. p.grade = item->enchantgrade;
  19380. #endif
  19381. clif_addcards( &p.slot, item );
  19382. clif_add_random_options( p.option_data, *item );
  19383. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19384. #endif
  19385. }
  19386. void clif_parse_laphine_upgrade( int32 fd, map_session_data* sd ){
  19387. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19388. if( sd->state.laphine_upgrade == 0 ){
  19389. return;
  19390. }
  19391. const PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = reinterpret_cast<PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*>( RFIFOP( fd, 0 ) );
  19392. if( sd->state.laphine_upgrade != p->itemId ){
  19393. return;
  19394. }
  19395. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19396. if( upgrade == nullptr ){
  19397. return;
  19398. }
  19399. uint16 index = server_index( p->index );
  19400. if( index >= MAX_INVENTORY ){
  19401. return;
  19402. }
  19403. if( sd->inventory_data[index] == nullptr ){
  19404. return;
  19405. }
  19406. struct item* item = &sd->inventory.u.items_inventory[index];
  19407. // Not a valid target item
  19408. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19409. clif_laphine_upgrade_result( sd, true );
  19410. return;
  19411. }
  19412. // If target item is not identified
  19413. if( item->identify == 0 ){
  19414. clif_laphine_upgrade_result( sd, true );
  19415. return;
  19416. }
  19417. // If target item is equipped
  19418. if( item->equip != 0 ){
  19419. clif_laphine_upgrade_result( sd, true );
  19420. return;
  19421. }
  19422. // If target item is in equipswitch
  19423. if( item->equipSwitch != 0 ){
  19424. clif_laphine_upgrade_result( sd, true );
  19425. return;
  19426. }
  19427. // Check minimum refine requirement
  19428. if( item->refine < upgrade->minimumRefine ){
  19429. clif_laphine_upgrade_result( sd, true );
  19430. return;
  19431. }
  19432. // Check maximum refine requirement
  19433. if( item->refine > upgrade->maximumRefine ){
  19434. clif_laphine_upgrade_result( sd, true );
  19435. return;
  19436. }
  19437. // If no cards are allowed
  19438. if( !upgrade->cardsAllowed ){
  19439. for( int32 i = 0; i < MAX_SLOTS; i++ ){
  19440. if( item->card[i] != 0 ){
  19441. clif_laphine_upgrade_result( sd, true );
  19442. return;
  19443. }
  19444. }
  19445. }
  19446. // If random options are required
  19447. if( upgrade->requiredRandomOptions > 0 ){
  19448. int32 i;
  19449. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19450. if( item->option[i].id != 0 ){
  19451. break;
  19452. }
  19453. }
  19454. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19455. clif_laphine_upgrade_result( sd, true );
  19456. return;
  19457. }
  19458. }
  19459. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19460. if( index2 < 0 ){
  19461. clif_laphine_upgrade_result( sd, true );
  19462. return;
  19463. }
  19464. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19465. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19466. return;
  19467. }
  19468. }
  19469. // Log removal of item
  19470. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19471. // Visually remove it from the client
  19472. clif_delitem( *sd, index, 1, 0 );
  19473. // Apply the random options
  19474. if( upgrade->randomOptionGroup != nullptr ){
  19475. upgrade->randomOptionGroup->apply( *item );
  19476. }
  19477. // Change the refine rate if needed
  19478. if( upgrade->resultRefine > 0 ){
  19479. // Absolute refine level change
  19480. item->refine = max( item->refine, upgrade->resultRefine );
  19481. }else if( upgrade->resultRefineMaximum > 0 ){
  19482. // If a minimum is specified it can also downgrade
  19483. if( upgrade->resultRefineMinimum ){
  19484. item->refine = static_cast<uint8>( rnd_value<uint16>( upgrade->resultRefineMinimum, upgrade->resultRefineMaximum ) );
  19485. }else{
  19486. // Otherwise it can only be upgraded until the maximum, but not downgraded
  19487. item->refine = static_cast<uint8>( rnd_value<uint16>( item->refine, upgrade->resultRefineMaximum ) );
  19488. }
  19489. }else if( upgrade->resultRefineMinimum > 0 ){
  19490. // No maximum has been specified, so it can be anything between minimum and MAX_REFINE
  19491. item->refine = static_cast<uint8>( rnd_value<uint16>( upgrade->resultRefineMinimum, MAX_REFINE ) );
  19492. }
  19493. // Log retrieving the item again -> with the new options
  19494. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19495. // Make it visible for the client again
  19496. clif_additem( sd, index, 1, 0 );
  19497. // Open a preview of the item
  19498. clif_item_preview( sd, index );
  19499. // Tell the client we are done
  19500. clif_laphine_upgrade_result( sd, false );
  19501. #endif
  19502. }
  19503. void clif_enchantgrade_add( map_session_data& sd, uint16 index = UINT16_MAX, std::shared_ptr<s_enchantgradelevel> gradeLevel = nullptr ){
  19504. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19505. PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST* p = reinterpret_cast<PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST*>( packet_buffer );
  19506. p->PacketType = HEADER_ZC_GRADE_ENCHANT_MATERIAL_LIST;
  19507. p->PacketLength = sizeof( *p );
  19508. if( index < UINT16_MAX ){
  19509. p->index = client_index( index );
  19510. p->success_chance = gradeLevel->chances[sd.inventory.u.items_inventory[index].refine] / 100;
  19511. p->blessing_info.id = client_nameid( gradeLevel->catalyst.item );
  19512. p->blessing_info.amount = gradeLevel->catalyst.amountPerStep;
  19513. p->blessing_info.max_blessing = gradeLevel->catalyst.maximumSteps;
  19514. p->blessing_info.bonus = gradeLevel->catalyst.chanceIncrease / 100;
  19515. // Not displayed by client
  19516. p->protect_itemid = 0;
  19517. p->protect_amount = 0;
  19518. int32 i = 0;
  19519. for( const auto& pair : gradeLevel->options ){
  19520. GRADE_ENCHANT_MATERIAL& mat = p->material_info[i];
  19521. std::shared_ptr<s_enchantgradeoption> option = pair.second;
  19522. mat.nameid = client_nameid( option->item );
  19523. mat.amount = option->amount;
  19524. mat.price = option->zeny;
  19525. mat.downgrade = option->downgrade_amount > 0;
  19526. mat.breakable = option->breaking_rate > 0;
  19527. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( mat ) );
  19528. i++;
  19529. }
  19530. }else{
  19531. p->index = -1;
  19532. p->success_chance = 0;
  19533. p->blessing_info.id = 0;
  19534. p->blessing_info.amount = 0;
  19535. p->blessing_info.max_blessing = 0;
  19536. p->blessing_info.bonus = 0;
  19537. p->protect_itemid = 0;
  19538. p->protect_amount = 0;
  19539. }
  19540. clif_send( p, p->PacketLength, &sd.bl, SELF );
  19541. #endif
  19542. }
  19543. void clif_parse_enchantgrade_add( int32 fd, map_session_data* sd ){
  19544. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19545. nullpo_retv( sd );
  19546. if( !sd->state.enchantgrade_open ){
  19547. return;
  19548. }
  19549. const PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT* p = reinterpret_cast<PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT*>( RFIFOP( fd, 0 ) );
  19550. uint16 index = server_index( p->index );
  19551. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19552. return;
  19553. }
  19554. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19555. // Unsupported item type - no answer, because client should have actually prevented this request
  19556. if( enchantgrade == nullptr ){
  19557. return;
  19558. }
  19559. // Item can't be enhanced
  19560. if( !sd->inventory_data[index]->flag.gradable ){
  19561. return;
  19562. }
  19563. uint16 level = 0;
  19564. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19565. level = sd->inventory_data[index]->weapon_level;
  19566. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19567. level = sd->inventory_data[index]->armor_level;
  19568. }
  19569. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19570. // Cannot upgrade this weapon or armor level
  19571. if( enchantgradelevels == enchantgrade->levels.end() ){
  19572. clif_enchantgrade_add( *sd );
  19573. return;
  19574. }
  19575. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19576. // Cannot increase enchantgrade any further - no answer, because client should have actually prevented this request
  19577. if( enchantgradelevel == nullptr ){
  19578. return;
  19579. }
  19580. clif_enchantgrade_add( *sd, index, enchantgradelevel );
  19581. #endif
  19582. }
  19583. /// <summary>
  19584. /// Sends the result for trying to enchant an item
  19585. /// </summary>
  19586. /// <param name="sd">The player session</param>
  19587. /// <param name="index">The target item</param>
  19588. /// <param name="result">
  19589. /// 0= The grade has been successfully upgraded.
  19590. /// 1= Refinement failed.
  19591. /// 2= The refine level has decreased.
  19592. /// 3= Equipment destroyed.
  19593. /// 4= The equipment is protected.
  19594. /// </param>
  19595. void clif_enchantgrade_result( map_session_data& sd, uint16 index, e_enchantgrade_result result ){
  19596. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19597. PACKET_ZC_GRADE_ENCHANT_ACK p = {};
  19598. p.PacketType = HEADER_ZC_GRADE_ENCHANT_ACK;
  19599. p.index = client_index( index );
  19600. p.grade = sd.inventory.u.items_inventory[index].enchantgrade;
  19601. p.result = result;
  19602. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19603. #endif
  19604. }
  19605. void clif_enchantgrade_announce( map_session_data& sd, struct item& item, bool success ){
  19606. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19607. PACKET_ZC_GRADE_ENCHANT_BROADCAST_RESULT p = {};
  19608. p.packetType = HEADER_ZC_GRADE_ENCHANT_BROADCAST_RESULT;
  19609. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  19610. p.itemId = client_nameid( item.nameid );
  19611. p.grade = item.enchantgrade;
  19612. p.status = success;
  19613. clif_send( &p, sizeof( p ), nullptr, ALL_CLIENT );
  19614. #endif
  19615. }
  19616. void clif_parse_enchantgrade_start( int32 fd, map_session_data* sd ){
  19617. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19618. nullpo_retv( sd );
  19619. if( !sd->state.enchantgrade_open ){
  19620. return;
  19621. }
  19622. const PACKET_CZ_GRADE_ENCHANT_REQUEST* p = reinterpret_cast<PACKET_CZ_GRADE_ENCHANT_REQUEST*>( RFIFOP( fd, 0 ) );
  19623. uint16 index = server_index( p->index );
  19624. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19625. return;
  19626. }
  19627. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19628. // Unsupported item type - no answer
  19629. if( enchantgrade == nullptr ){
  19630. return;
  19631. }
  19632. uint16 level = 0;
  19633. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19634. level = sd->inventory_data[index]->weapon_level;
  19635. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19636. level = sd->inventory_data[index]->armor_level;
  19637. }
  19638. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19639. // Cannot upgrade this weapon or armor level - no answer
  19640. if( enchantgradelevels == enchantgrade->levels.end() ){
  19641. return;
  19642. }
  19643. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19644. // Cannot increase enchantgrade any further - no answer
  19645. if( enchantgradelevel == nullptr ){
  19646. return;
  19647. }
  19648. uint16 totalChance = enchantgradelevel->chances[sd->inventory.u.items_inventory[index].refine];
  19649. // No chance to increase the enchantgrade
  19650. if( totalChance == 0 ){
  19651. return;
  19652. }
  19653. std::shared_ptr<s_enchantgradeoption> option = util::map_find( enchantgradelevel->options, (uint16)p->material_index );
  19654. // Unknown option id - no answer
  19655. if( option == nullptr ){
  19656. return;
  19657. }
  19658. // Not enough zeny
  19659. if( sd->status.zeny < option->zeny ){
  19660. return;
  19661. }
  19662. uint16 steps = min( p->blessing_amount, enchantgradelevel->catalyst.maximumSteps );
  19663. std::unordered_map<uint16, uint16> requiredItems;
  19664. if( p->blessing_flag ){
  19665. // If the catalysator item is the same as the option item build the sum of amounts
  19666. if( enchantgradelevel->catalyst.item == option->item ){
  19667. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps + option->amount;
  19668. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19669. if( index < 0 ){
  19670. return;
  19671. }
  19672. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19673. return;
  19674. }
  19675. requiredItems[index] = amount;
  19676. }else{
  19677. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps;
  19678. // Check catalysator item
  19679. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19680. if( index < 0 ){
  19681. return;
  19682. }
  19683. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19684. return;
  19685. }
  19686. requiredItems[index] = amount;
  19687. // Check option item
  19688. index = pc_search_inventory( sd, option->item );
  19689. if( index < 0 ){
  19690. return;
  19691. }
  19692. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19693. return;
  19694. }
  19695. requiredItems[index] = option->amount;
  19696. }
  19697. totalChance += steps * enchantgradelevel->catalyst.chanceIncrease;
  19698. }else{
  19699. // Check option item
  19700. int16 index = pc_search_inventory( sd, option->item );
  19701. if( index < 0 ){
  19702. return;
  19703. }
  19704. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19705. return;
  19706. }
  19707. requiredItems[index] = option->amount;
  19708. }
  19709. // All items should be there, start deleting
  19710. for( const auto& pair : requiredItems ){
  19711. if( pc_delitem( sd, pair.first, pair.second, 0, 0, LOG_TYPE_ENCHANTGRADE ) != 0 ){
  19712. return;
  19713. }
  19714. }
  19715. if( pc_payzeny( sd, option->zeny, LOG_TYPE_ENCHANTGRADE ) > 0 ){
  19716. return;
  19717. }
  19718. if( rnd()%10000 < totalChance ){
  19719. // Log removal of item
  19720. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19721. // Increase enchantgrade
  19722. sd->inventory.u.items_inventory[index].enchantgrade = min( sd->inventory.u.items_inventory[index].enchantgrade + 1, MAX_ENCHANTGRADE );
  19723. // On successful enchantgrade increase the refine is reset
  19724. sd->inventory.u.items_inventory[index].refine = 0;
  19725. // Log retrieving the item again -> with the new refine and enchantgrade
  19726. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19727. // Show success
  19728. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_SUCCESS );
  19729. // Check if it has to be announced
  19730. if( enchantgradelevel->announceSuccess ){
  19731. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], true );
  19732. }
  19733. }else{
  19734. // Check if it has to be announced (has to be done before deleting the item from inventory)
  19735. if( enchantgradelevel->announceFail ){
  19736. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], false );
  19737. }
  19738. // Delete the item if it is breakable
  19739. if( option->breaking_rate > 0 && ( rnd() % 10000 ) < option->breaking_rate ){
  19740. // Delete the item
  19741. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_ENCHANTGRADE );
  19742. // Show failure
  19743. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_BREAK );
  19744. // Downgrade the item if necessary
  19745. }else if( option->downgrade_amount > 0 ){
  19746. // Log removal of item
  19747. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19748. // Decrease refine level
  19749. sd->inventory.u.items_inventory[index].refine = cap_value( sd->inventory.u.items_inventory[index].refine - option->downgrade_amount, 0, MAX_REFINE );
  19750. // Log retrieving the item again -> with the new refine
  19751. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19752. // Show downgrade
  19753. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_DOWNGRADE );
  19754. // Only show failure, but dont do anything
  19755. }else{
  19756. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_FAILED );
  19757. }
  19758. }
  19759. #endif
  19760. }
  19761. void clif_parse_enchantgrade_close( int32 fd, map_session_data* sd ){
  19762. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19763. nullpo_retv( sd );
  19764. sd->state.enchantgrade_open = false;
  19765. #endif
  19766. }
  19767. void clif_reputation_type( map_session_data& sd, int64 type, int64 points ){
  19768. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19769. PACKET_ZC_REPUTE_INFO* p = reinterpret_cast<PACKET_ZC_REPUTE_INFO*>( packet_buffer );
  19770. p->packetType = HEADER_ZC_REPUTE_INFO;
  19771. p->packetLength = sizeof( *p );
  19772. p->success = true;
  19773. PACKET_ZC_REPUTE_INFO_sub& entry = p->list[0];
  19774. entry.type = type;
  19775. entry.points = points;
  19776. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  19777. clif_send( p, p->packetLength, &sd.bl, SELF );
  19778. #endif
  19779. }
  19780. void clif_reputation_list( map_session_data& sd ){
  19781. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19782. PACKET_ZC_REPUTE_INFO* p = reinterpret_cast<PACKET_ZC_REPUTE_INFO*>( packet_buffer );
  19783. p->packetType = HEADER_ZC_REPUTE_INFO;
  19784. p->packetLength = sizeof( *p );
  19785. p->success = true;
  19786. size_t index = 0;
  19787. for( const auto& entry : reputation_db ){
  19788. std::shared_ptr<s_reputation> reputation = entry.second;
  19789. PACKET_ZC_REPUTE_INFO_sub& list_entry = p->list[index];
  19790. list_entry.type = reputation->id;
  19791. list_entry.points = pc_readreg2( &sd, reputation->variable.c_str() );
  19792. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( list_entry ) );
  19793. index++;
  19794. }
  19795. clif_send( p, p->packetLength, &sd.bl, SELF );
  19796. #endif
  19797. }
  19798. void clif_item_reform_open( map_session_data& sd, t_itemid item ){
  19799. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19800. PACKET_ZC_OPEN_REFORM_UI p = {};
  19801. p.PacketType = HEADER_ZC_OPEN_REFORM_UI;
  19802. p.ITID = item;
  19803. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19804. sd.state.item_reform = item;
  19805. #endif
  19806. }
  19807. void clif_parse_item_reform_close( int32 fd, map_session_data* sd ){
  19808. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19809. sd->state.item_reform = 0;
  19810. #endif
  19811. }
  19812. void clif_item_reform_result( map_session_data& sd, uint16 index, uint8 result ){
  19813. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19814. PACKET_ZC_ITEM_REFORM_ACK p = {};
  19815. p.PacketType = HEADER_ZC_ITEM_REFORM_ACK;
  19816. p.index = client_index( index );
  19817. p.result = result;
  19818. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19819. if( result == 0 ){
  19820. // Client closes the window on success
  19821. sd.state.item_reform = 0;
  19822. }
  19823. #endif
  19824. }
  19825. void clif_parse_item_reform_start( int32 fd, map_session_data* sd ){
  19826. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19827. // Not opened
  19828. if( sd->state.item_reform == 0 ){
  19829. return;
  19830. }
  19831. const PACKET_CZ_ITEM_REFORM* p = reinterpret_cast<PACKET_CZ_ITEM_REFORM*>( RFIFOP( fd, 0 ) );
  19832. // Item mismatch
  19833. if( p->ITID != sd->state.item_reform ){
  19834. return;
  19835. }
  19836. uint16 index = server_index( p->index );
  19837. if( index >= MAX_INVENTORY ){
  19838. return;
  19839. }
  19840. if( sd->inventory_data[index] == nullptr ){
  19841. return;
  19842. }
  19843. std::shared_ptr<s_item_reform> reform = item_reform_db.find( sd->state.item_reform );
  19844. if( reform == nullptr ){
  19845. return;
  19846. }
  19847. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19848. std::shared_ptr<s_item_reform_base> base = util::umap_find( reform->base_items, selected_item.nameid );
  19849. if( base == nullptr ){
  19850. return;
  19851. }
  19852. // If target item is not identified
  19853. if( selected_item.identify == 0 ){
  19854. return;
  19855. }
  19856. // If target item is equipped
  19857. if( selected_item.equip != 0 ){
  19858. return;
  19859. }
  19860. // Check minimum refine requirement
  19861. if( selected_item.refine < base->minimumRefine ){
  19862. return;
  19863. }
  19864. // Check maximum refine requirement
  19865. if( selected_item.refine > base->maximumRefine ){
  19866. return;
  19867. }
  19868. // If no cards are allowed
  19869. if( !base->cardsAllowed ){
  19870. for( int32 i = 0; i < MAX_SLOTS; i++ ){
  19871. if( selected_item.card[i] != 0 ){
  19872. return;
  19873. }
  19874. }
  19875. }
  19876. // If random options are required
  19877. if( base->requiredRandomOptions > 0 ){
  19878. int32 i;
  19879. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19880. if( selected_item.option[i].id != 0 ){
  19881. break;
  19882. }
  19883. }
  19884. if( ( i + 1 ) < base->requiredRandomOptions ){
  19885. return;
  19886. }
  19887. }
  19888. std::unordered_map<uint16, uint16> materials;
  19889. // Check if all materials exist
  19890. for( const auto& material : base->materials ){
  19891. int16 material_index = pc_search_inventory( sd, material.first );
  19892. if( material_index < 0 ){
  19893. return;
  19894. }
  19895. if( sd->inventory.u.items_inventory[material_index].amount < material.second ){
  19896. return;
  19897. }
  19898. materials[material_index] = material.second;
  19899. }
  19900. // Remove the material
  19901. for( const auto& material : materials ){
  19902. if( pc_delitem( sd, material.first, material.second, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19903. return;
  19904. }
  19905. }
  19906. // If triggered from item
  19907. if( sd->itemid == sd->state.item_reform && pc_delitem( sd, sd->itemindex, 1, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19908. return;
  19909. }
  19910. // Log removal of item
  19911. log_pick_pc( sd, LOG_TYPE_REFORM, -1, &selected_item );
  19912. // Visually remove it from the client
  19913. clif_delitem( *sd, index, 1, 0 );
  19914. // Apply the random options
  19915. if( base->randomOptionGroup != nullptr ){
  19916. base->randomOptionGroup->apply( selected_item );
  19917. }
  19918. // Change the refine rate if needed
  19919. if( base->refineChange != 0 ){
  19920. selected_item.refine = cap_value( selected_item.refine + base->refineChange, 0, MAX_REFINE );
  19921. }
  19922. // Remove all cards and socket enchants
  19923. if( base->clearSlots ){
  19924. for( int32 i = 0; i < MAX_SLOTS; i++ ){
  19925. selected_item.card[i] = 0;
  19926. }
  19927. }
  19928. // Remove the current enchantgrade
  19929. if( base->removeEnchantgrade ){
  19930. selected_item.enchantgrade = 0;
  19931. }
  19932. // Finally change the item id
  19933. selected_item.nameid = base->resultItemId;
  19934. // Link inventory data cache to the new item
  19935. sd->inventory_data[index] = itemdb_search( base->resultItemId );
  19936. // Log retrieving the item again -> with the new options
  19937. log_pick_pc( sd, LOG_TYPE_REFORM, 1, &selected_item );
  19938. // Make it visible for the client again
  19939. clif_additem( sd, index, 1, 0 );
  19940. clif_item_reform_result( *sd, index, 0 );
  19941. #endif
  19942. }
  19943. void clif_enchantwindow_open( map_session_data& sd, uint64 clientLuaIndex ){
  19944. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19945. // Hardcoded clientside check
  19946. if( sd.weight > ( ( sd.max_weight * 70 ) / 100 ) ){
  19947. clif_msg_color( &sd, MSI_ENCHANT_FAILED_OVER_WEIGHT, color_table[COLOR_RED] );
  19948. sd.state.item_enchant_index = 0;
  19949. return;
  19950. }
  19951. PACKET_ZC_UI_OPEN_V3 p = {};
  19952. p.packetType = HEADER_ZC_UI_OPEN_V3;
  19953. p.type = OUT_UI_ENCHANT;
  19954. p.data = clientLuaIndex;
  19955. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19956. sd.state.item_enchant_index = clientLuaIndex;
  19957. #endif
  19958. }
  19959. void clif_enchantwindow_result( map_session_data& sd, bool success, t_itemid enchant = 0 ){
  19960. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19961. PACKET_ZC_RESPONSE_ENCHANT p = {};
  19962. p.PacketType = HEADER_ZC_RESPONSE_ENCHANT;
  19963. if( success ){
  19964. p.msgId = MSI_ENCHANT_SUCCESS;
  19965. }else{
  19966. p.msgId = MSI_ENCHANT_FAILED;
  19967. }
  19968. p.ITID = enchant;
  19969. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19970. sd.state.item_enchant_index = 0;
  19971. #endif
  19972. }
  19973. bool clif_parse_enchant_basecheck( struct item& selected_item, std::shared_ptr<s_item_enchant> enchant ){
  19974. if( selected_item.equip != 0 ){
  19975. return false;
  19976. }
  19977. if( selected_item.equipSwitch != 0 ){
  19978. return false;
  19979. }
  19980. if( selected_item.attribute != 0 ){
  19981. return false;
  19982. }
  19983. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  19984. return false;
  19985. }
  19986. if( selected_item.refine < enchant->minimumRefine ){
  19987. return false;
  19988. }
  19989. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  19990. return false;
  19991. }
  19992. if( !enchant->allowRandomOptions ){
  19993. for( const s_item_randomoption& option : selected_item.option ){
  19994. if( option.id != 0 ){
  19995. return false;
  19996. }
  19997. }
  19998. }
  19999. return true;
  20000. }
  20001. void clif_parse_enchantwindow_general( int32 fd, map_session_data* sd ){
  20002. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20003. const PACKET_CZ_REQUEST_RANDOM_ENCHANT* p = reinterpret_cast<PACKET_CZ_REQUEST_RANDOM_ENCHANT*>( RFIFOP( fd, 0 ) );
  20004. if( sd->state.item_enchant_index != p->enchant_group ){
  20005. return;
  20006. }
  20007. uint16 index = server_index( p->index );
  20008. if( index >= MAX_INVENTORY ){
  20009. return;
  20010. }
  20011. if( sd->inventory_data[index] == nullptr ){
  20012. return;
  20013. }
  20014. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20015. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20016. if( enchant == nullptr ){
  20017. return;
  20018. }
  20019. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20020. return;
  20021. }
  20022. uint16 slot = MAX_SLOTS;
  20023. for( uint16 nextSlot : enchant->order ){
  20024. if( selected_item.card[nextSlot] == 0 ){
  20025. slot = nextSlot;
  20026. break;
  20027. }
  20028. }
  20029. if( slot == MAX_SLOTS ){
  20030. return;
  20031. }
  20032. if( slot < sd->inventory_data[index]->slots ){
  20033. return;
  20034. }
  20035. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20036. if( enchant_slot == nullptr ){
  20037. return;
  20038. }
  20039. std::shared_ptr<s_item_enchant_normal> enchants_for_enchantgrade = util::umap_find( enchant_slot->normal.enchants, (uint16)selected_item.enchantgrade );
  20040. if( enchants_for_enchantgrade == nullptr ){
  20041. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 829 ), false, SELF); // Enchanting is not possible for your item's enchant grade.
  20042. clif_enchantwindow_result( *sd, false );
  20043. return;
  20044. }
  20045. if( sd->status.zeny < enchant_slot->normal.zeny ){
  20046. return;
  20047. }
  20048. std::unordered_map<uint16, uint16> materials;
  20049. for( const auto& entry : enchant_slot->normal.materials ){
  20050. int16 idx = pc_search_inventory( sd, entry.first );
  20051. if( idx < 0 ){
  20052. return;
  20053. }
  20054. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20055. return;
  20056. }
  20057. materials[idx] = entry.second;
  20058. }
  20059. if( pc_payzeny( sd, enchant_slot->normal.zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20060. return;
  20061. }
  20062. for( const auto& entry : materials ){
  20063. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20064. return;
  20065. }
  20066. }
  20067. uint32 chance = enchant_slot->normal.chance;
  20068. for( int32 i = 0; i <= MAX_ENCHANTGRADE; i++ ){
  20069. chance += enchant_slot->normal.enchantgradeChanceIncrease[i];
  20070. }
  20071. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20072. clif_enchantwindow_result( *sd, false );
  20073. return;
  20074. }
  20075. // Log removal of item
  20076. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20077. size_t maximum = 3 * enchant_slot->normal.enchants.size();
  20078. bool enchanted = false;
  20079. for( int32 i = 0; i < maximum; i++ ){
  20080. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  20081. if( rnd_value( 0, 10000 ) < normal_enchant->chance ){
  20082. selected_item.card[slot] = normal_enchant->item_id;
  20083. enchanted = true;
  20084. break;
  20085. }
  20086. }
  20087. if( !enchanted ){
  20088. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  20089. selected_item.card[slot] = normal_enchant->item_id;
  20090. }
  20091. // Log retrieving the item again -> with the new enchant
  20092. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20093. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20094. #endif
  20095. }
  20096. void clif_parse_enchantwindow_perfect( int32 fd, map_session_data* sd ){
  20097. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20098. const PACKET_CZ_REQUEST_PERFECT_ENCHANT* p = reinterpret_cast<PACKET_CZ_REQUEST_PERFECT_ENCHANT*>( RFIFOP( fd, 0 ) );
  20099. if( sd->state.item_enchant_index != p->enchant_group ){
  20100. return;
  20101. }
  20102. uint16 index = server_index( p->index );
  20103. if( index >= MAX_INVENTORY ){
  20104. return;
  20105. }
  20106. if( sd->inventory_data[index] == nullptr ){
  20107. return;
  20108. }
  20109. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20110. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20111. if( enchant == nullptr ){
  20112. return;
  20113. }
  20114. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20115. return;
  20116. }
  20117. uint16 slot = MAX_SLOTS;
  20118. for( uint16 nextSlot : enchant->order ){
  20119. if( selected_item.card[nextSlot] == 0 ){
  20120. slot = nextSlot;
  20121. break;
  20122. }
  20123. }
  20124. if( slot == MAX_SLOTS ){
  20125. return;
  20126. }
  20127. if( slot < sd->inventory_data[index]->slots ){
  20128. return;
  20129. }
  20130. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20131. if( enchant_slot == nullptr ){
  20132. return;
  20133. }
  20134. std::shared_ptr<s_item_enchant_perfect> perfect_enchant = util::umap_find( enchant_slot->perfect.enchants, p->ITID );
  20135. if( perfect_enchant == nullptr ){
  20136. return;
  20137. }
  20138. if( sd->status.zeny < perfect_enchant->zeny ){
  20139. return;
  20140. }
  20141. std::unordered_map<uint16, uint16> materials;
  20142. for( const auto& entry : perfect_enchant->materials ){
  20143. int16 idx = pc_search_inventory( sd, entry.first );
  20144. if( idx < 0 ){
  20145. return;
  20146. }
  20147. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20148. return;
  20149. }
  20150. materials[idx] = entry.second;
  20151. }
  20152. if( pc_payzeny( sd, perfect_enchant->zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20153. return;
  20154. }
  20155. for( const auto& entry : materials ){
  20156. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20157. return;
  20158. }
  20159. }
  20160. // Log removal of item
  20161. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20162. selected_item.card[slot] = perfect_enchant->item_id;
  20163. // Log retrieving the item again -> with the new enchant
  20164. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20165. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20166. #endif
  20167. }
  20168. void clif_parse_enchantwindow_upgrade( int32 fd, map_session_data* sd ){
  20169. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20170. const PACKET_CZ_REQUEST_UPGRADE_ENCHANT* p = reinterpret_cast<PACKET_CZ_REQUEST_UPGRADE_ENCHANT*>( RFIFOP( fd, 0 ) );
  20171. if( sd->state.item_enchant_index != p->enchant_group ){
  20172. return;
  20173. }
  20174. uint16 index = server_index( p->index );
  20175. if( index >= MAX_INVENTORY ){
  20176. return;
  20177. }
  20178. if( sd->inventory_data[index] == nullptr ){
  20179. return;
  20180. }
  20181. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20182. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20183. if( enchant == nullptr ){
  20184. return;
  20185. }
  20186. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20187. return;
  20188. }
  20189. uint16 slot = p->slot;
  20190. if( slot >= MAX_SLOTS ){
  20191. return;
  20192. }
  20193. if( slot < sd->inventory_data[index]->slots ){
  20194. return;
  20195. }
  20196. if( selected_item.card[slot] == 0 ){
  20197. return;
  20198. }
  20199. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20200. if( enchant_slot == nullptr ){
  20201. return;
  20202. }
  20203. std::shared_ptr<s_item_enchant_upgrade> upgrade = util::umap_find( enchant_slot->upgrade.enchants, selected_item.card[slot] );
  20204. if( upgrade == nullptr ){
  20205. return;
  20206. }
  20207. if( sd->status.zeny < upgrade->zeny ){
  20208. return;
  20209. }
  20210. std::unordered_map<uint16, uint16> materials;
  20211. for( const auto& entry : upgrade->materials ){
  20212. int16 idx = pc_search_inventory( sd, entry.first );
  20213. if( idx < 0 ){
  20214. return;
  20215. }
  20216. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20217. return;
  20218. }
  20219. materials[idx] = entry.second;
  20220. }
  20221. if( pc_payzeny( sd, upgrade->zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20222. return;
  20223. }
  20224. for( const auto& entry : materials ){
  20225. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20226. return;
  20227. }
  20228. }
  20229. // Log removal of item
  20230. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20231. selected_item.card[slot] = upgrade->upgrade_item_id;
  20232. // Log retrieving the item again -> with the new enchant
  20233. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20234. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20235. #endif
  20236. }
  20237. void clif_parse_enchantwindow_reset( int32 fd, map_session_data* sd ){
  20238. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20239. const PACKET_CZ_REQUEST_RESET_ENCHANT* p = reinterpret_cast<PACKET_CZ_REQUEST_RESET_ENCHANT*>( RFIFOP( fd, 0 ) );
  20240. if( sd->state.item_enchant_index != p->enchant_group ){
  20241. return;
  20242. }
  20243. uint16 index = server_index( p->index );
  20244. if( index >= MAX_INVENTORY ){
  20245. return;
  20246. }
  20247. if( sd->inventory_data[index] == nullptr ){
  20248. return;
  20249. }
  20250. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20251. if( selected_item.equip != 0 ){
  20252. return;
  20253. }
  20254. if( selected_item.equipSwitch != 0 ){
  20255. return;
  20256. }
  20257. if( selected_item.attribute != 0 ){
  20258. return;
  20259. }
  20260. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20261. if( enchant == nullptr ){
  20262. return;
  20263. }
  20264. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20265. return;
  20266. }
  20267. if( selected_item.refine < enchant->minimumRefine ){
  20268. return;
  20269. }
  20270. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20271. return;
  20272. }
  20273. bool is_enchanted = false;
  20274. for( int32 i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20275. if( selected_item.card[i] != 0 ){
  20276. is_enchanted = true;
  20277. break;
  20278. }
  20279. }
  20280. if( !is_enchanted ){
  20281. return;
  20282. }
  20283. if( sd->status.zeny < enchant->reset.zeny ){
  20284. return;
  20285. }
  20286. std::unordered_map<uint16, uint16> materials;
  20287. for( const auto& entry : enchant->reset.materials ){
  20288. int16 idx = pc_search_inventory( sd, entry.first );
  20289. if( idx < 0 ){
  20290. return;
  20291. }
  20292. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20293. return;
  20294. }
  20295. materials[idx] = entry.second;
  20296. }
  20297. if( pc_payzeny( sd, enchant->reset.zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20298. return;
  20299. }
  20300. for( const auto& entry : materials ){
  20301. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20302. return;
  20303. }
  20304. }
  20305. uint32 chance = enchant->reset.chance;
  20306. if( chance == 0 ){
  20307. return;
  20308. }
  20309. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20310. clif_enchantwindow_result( *sd, false );
  20311. return;
  20312. }
  20313. // Log removal of item
  20314. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20315. for( int32 i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20316. selected_item.card[i] = 0;
  20317. }
  20318. // Log retrieving the item again -> with the new enchant
  20319. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20320. clif_enchantwindow_result( *sd, true );
  20321. #endif
  20322. }
  20323. void clif_parse_enchantwindow_close( int32 fd, map_session_data* sd ){
  20324. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20325. sd->state.item_enchant_index = 0;
  20326. #endif
  20327. }
  20328. void clif_parse_itempackage_select( int32 fd, map_session_data* sd ){
  20329. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220316
  20330. const PACKET_CZ_USE_PACKAGEITEM* p = reinterpret_cast<PACKET_CZ_USE_PACKAGEITEM*>( RFIFOP( fd, 0 ) );
  20331. if( p->AID != sd->status.account_id ){
  20332. return;
  20333. }
  20334. uint16 index = server_index( p->index );
  20335. if( index >= MAX_INVENTORY ){
  20336. return;
  20337. }
  20338. if( sd->inventory_data[index] == nullptr ){
  20339. return;
  20340. }
  20341. if( sd->inventory_data[index]->nameid != p->itemID ){
  20342. return;
  20343. }
  20344. if( sd->inventory_data[index]->elv > sd->status.base_level ){
  20345. return;
  20346. }
  20347. std::shared_ptr<s_item_package> package = item_package_db.find( p->itemID );
  20348. if( package == nullptr ){
  20349. return;
  20350. }
  20351. std::shared_ptr<s_item_package_group> group = util::umap_find( package->groups, p->BoxIndex );
  20352. if( group == nullptr ){
  20353. return;
  20354. }
  20355. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_PACKAGE ) != 0 ){
  20356. return;
  20357. }
  20358. for( const auto& entry : group->items ){
  20359. struct item item = {};
  20360. item.nameid = entry.second->item_id;
  20361. item.identify = 1;
  20362. item.refine = (char)entry.second->refine;
  20363. if( entry.second->rentalhours ){
  20364. item.expire_time = (uint32)( time( nullptr ) + entry.second->rentalhours * 3600 );
  20365. }
  20366. // Check if it is a pet egg
  20367. std::shared_ptr<s_pet_db> pet = pet_db_search( item.nameid, PET_EGG );
  20368. if( pet != nullptr ){
  20369. for( int32 i = 0; i < entry.second->amount; i++ ){
  20370. pet_create_egg( sd, item.nameid );
  20371. }
  20372. }else if( entry.second->amount > 1 && ( !itemdb_isstackable( item.nameid ) || item.expire_time > 0 ) ){
  20373. for( int32 i = 0; i < entry.second->amount; i++ ){
  20374. // New random options on each iteration
  20375. if( entry.second->randomOptionGroup != nullptr ){
  20376. entry.second->randomOptionGroup->apply( item );
  20377. }
  20378. pc_additem( sd, &item, 1, LOG_TYPE_PACKAGE );
  20379. }
  20380. }else{
  20381. if( entry.second->randomOptionGroup != nullptr ){
  20382. entry.second->randomOptionGroup->apply( item );
  20383. }
  20384. pc_additem( sd, &item, entry.second->amount, LOG_TYPE_PACKAGE );
  20385. }
  20386. }
  20387. #endif
  20388. }
  20389. void clif_broadcast_refine_result(map_session_data& sd, t_itemid itemId, int8 level, bool success)
  20390. {
  20391. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  20392. PACKET_ZC_BROADCAST_ITEMREFINING_RESULT p{};
  20393. p.packetType = HEADER_ZC_BROADCAST_ITEMREFINING_RESULT;
  20394. p.itemId = itemId;
  20395. p.refine_level = level;
  20396. p.status = (int8)success;
  20397. if (battle_config.broadcast_hide_name) {
  20398. std::string dispname = clif_hide_name(sd.status.name);
  20399. safestrncpy(p.name, dispname.c_str(), sizeof(p.name));
  20400. }
  20401. else {
  20402. safestrncpy(p.name, sd.status.name, sizeof(p.name));
  20403. }
  20404. clif_send(&p, sizeof(p), &sd.bl, ALL_CLIENT);
  20405. #endif
  20406. }
  20407. void clif_parse_captcha_register(int32 fd, map_session_data *sd) {
  20408. #if PACKETVER >= 20160316
  20409. nullpo_retv(sd);
  20410. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20411. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20412. return;
  20413. }
  20414. const PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR* p = reinterpret_cast<PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR*>( RFIFOP( fd, 0 ) );
  20415. pc_macro_captcha_register(*sd, p->imageSize, p->answer);
  20416. #endif
  20417. }
  20418. void clif_captcha_upload_request(map_session_data &sd) {
  20419. #if PACKETVER >= 20160330
  20420. PACKET_ZC_ACK_UPLOAD_MACRO_DETECTOR p = {};
  20421. p.PacketType = HEADER_ZC_ACK_UPLOAD_MACRO_DETECTOR;
  20422. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20423. if (sd.captcha_upload.cd != nullptr) {
  20424. p.captchaFlag = 0;
  20425. } else {
  20426. p.captchaFlag = 1;
  20427. }
  20428. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20429. #endif
  20430. }
  20431. void clif_parse_captcha_upload(int32 fd, map_session_data *sd) {
  20432. #if PACKETVER >= 20160316
  20433. nullpo_retv(sd);
  20434. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20435. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20436. return;
  20437. }
  20438. const PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA* p = reinterpret_cast<PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA*>( RFIFOP( fd, 0 ) );
  20439. int16 upload_size = p->PacketLength - sizeof( * p );
  20440. if (upload_size < 1 || upload_size > MAX_CAPTCHA_CHUNK_SIZE)
  20441. return;
  20442. if (sd->captcha_upload.upload_size + upload_size > sd->captcha_upload.cd->image_size)
  20443. return;
  20444. pc_macro_captcha_register_upload(*sd, upload_size, p->imageData);
  20445. #endif
  20446. }
  20447. void clif_captcha_upload_end(map_session_data &sd) {
  20448. #if PACKETVER >= 20160330
  20449. PACKET_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA p = {};
  20450. p.PacketType = HEADER_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA;
  20451. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20452. #endif
  20453. }
  20454. void clif_parse_captcha_preview_request(int32 fd, map_session_data *sd) {
  20455. #if PACKETVER >= 20160323
  20456. nullpo_retv(sd);
  20457. if (!(pc_has_permission(sd, PC_PERM_MACRO_REGISTER) && pc_has_permission(sd, PC_PERM_MACRO_DETECT))) {
  20458. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20459. return;
  20460. }
  20461. const PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR* p = reinterpret_cast<PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR*>( RFIFOP( fd, 0 ) );
  20462. clif_captcha_preview_response(*sd, captcha_db.find(p->captchaID));
  20463. #endif
  20464. }
  20465. void clif_captcha_preview_response(map_session_data &sd, std::shared_ptr<s_captcha_data> cd) {
  20466. #if PACKETVER >= 20160330
  20467. PACKET_ZC_ACK_PREVIEW_MACRO_DETECTOR p = {};
  20468. p.PacketType = HEADER_ZC_ACK_PREVIEW_MACRO_DETECTOR;
  20469. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20470. if (cd == nullptr) {
  20471. p.captchaFlag = 1;
  20472. p.imageSize = 0;
  20473. } else {
  20474. p.captchaFlag = 0;
  20475. p.imageSize = cd->image_size;
  20476. }
  20477. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20478. if (cd != nullptr) {
  20479. for (uint16 offset = 0; offset < cd->image_size;) {
  20480. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20481. PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA* p2 = reinterpret_cast<PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA*>( packet_buffer );
  20482. p2->PacketType = HEADER_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA;
  20483. p2->PacketLength = sizeof( *p2 );
  20484. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20485. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20486. p2->PacketLength += static_cast<decltype(p2->PacketLength)>( chunk_size );
  20487. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20488. offset += chunk_size;
  20489. }
  20490. }
  20491. #endif
  20492. }
  20493. void clif_macro_detector_request(map_session_data &sd) {
  20494. #if PACKETVER >= 20160330
  20495. std::shared_ptr<s_captcha_data> cd = sd.macro_detect.cd;
  20496. if (cd == nullptr) {
  20497. return;
  20498. }
  20499. // Send preview initialization request to the client.
  20500. PACKET_ZC_APPLY_MACRO_DETECTOR p = {};
  20501. p.PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR;
  20502. p.imageSize = cd->image_size;
  20503. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20504. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20505. for (uint16 offset = 0; offset < cd->image_size;) {
  20506. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20507. PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA* p2 = reinterpret_cast<PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA*>( packet_buffer );
  20508. p2->PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR_CAPTCHA;
  20509. p2->PacketLength = sizeof( *p2 );
  20510. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20511. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20512. p2->PacketLength += static_cast<decltype(p2->PacketLength)>( chunk_size );
  20513. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20514. offset += chunk_size;
  20515. }
  20516. #endif
  20517. }
  20518. void clif_macro_detector_request_show(map_session_data &sd) {
  20519. #if PACKETVER >= 20160330
  20520. PACKET_ZC_REQ_ANSWER_MACRO_DETECTOR p = {};
  20521. p.PacketType = HEADER_ZC_REQ_ANSWER_MACRO_DETECTOR;
  20522. p.retryCount = sd.macro_detect.retry;
  20523. p.timeout = battle_config.macro_detection_timeout;
  20524. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20525. #endif
  20526. }
  20527. void clif_parse_macro_detector_download_ack(int32 fd, map_session_data *sd) {
  20528. #if PACKETVER >= 20160316
  20529. nullpo_retv(sd);
  20530. if (sd->macro_detect.retry != 0) {
  20531. //const PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA* p = reinterpret_cast<PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA*>( RFIFOP( fd, 0 ) );
  20532. clif_macro_detector_request_show(*sd);
  20533. }
  20534. #endif
  20535. }
  20536. void clif_parse_macro_detector_answer(int32 fd, map_session_data *sd) {
  20537. #if PACKETVER >= 20160316
  20538. nullpo_retv(sd);
  20539. const PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR* p = reinterpret_cast<PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR*>( RFIFOP( fd, 0 ) );
  20540. pc_macro_detector_process_answer(*sd, p->answer);
  20541. #endif
  20542. }
  20543. void clif_macro_detector_status(map_session_data &sd, e_macro_detect_status stype) {
  20544. #if PACKETVER >= 20160330
  20545. PACKET_ZC_CLOSE_MACRO_DETECTOR p = {};
  20546. p.PacketType = HEADER_ZC_CLOSE_MACRO_DETECTOR;
  20547. p.status = stype;
  20548. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20549. #endif
  20550. }
  20551. void clif_parse_macro_reporter_select(int32 fd, map_session_data *sd) {
  20552. #if PACKETVER >= 20160330
  20553. nullpo_retv(sd);
  20554. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20555. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20556. return;
  20557. }
  20558. const PACKET_CZ_REQ_PLAYER_AID_IN_RANGE* p = reinterpret_cast<PACKET_CZ_REQ_PLAYER_AID_IN_RANGE*>( RFIFOP( fd, 0 ) );
  20559. pc_macro_reporter_area_select(*sd, p->xPos, p->yPos, p->RadiusRange);
  20560. #endif
  20561. }
  20562. void clif_macro_reporter_select(map_session_data &sd, const std::vector<uint32> &aid_list) {
  20563. #if PACKETVER >= 20160330
  20564. PACKET_ZC_ACK_PLAYER_AID_IN_RANGE* p = reinterpret_cast<PACKET_ZC_ACK_PLAYER_AID_IN_RANGE*>( packet_buffer );
  20565. p->PacketType = HEADER_ZC_ACK_PLAYER_AID_IN_RANGE;
  20566. p->PacketLength = sizeof( *p );
  20567. for (size_t i = 0; i < aid_list.size(); i++){
  20568. p->AID[i] = aid_list[static_cast<int32>(i)];
  20569. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( p->AID[0] ) );
  20570. }
  20571. clif_send(p, p->PacketLength, &sd.bl, SELF);
  20572. #endif
  20573. }
  20574. void clif_parse_macro_reporter_ack(int32 fd, map_session_data *sd) {
  20575. #if PACKETVER >= 20160316
  20576. nullpo_retv(sd);
  20577. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20578. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20579. return;
  20580. }
  20581. const PACKET_CZ_REQ_APPLY_MACRO_DETECTOR* p = reinterpret_cast<PACKET_CZ_REQ_APPLY_MACRO_DETECTOR*>( RFIFOP( fd, 0 ) );
  20582. map_session_data *tsd = map_id2sd(p->AID);
  20583. if (tsd == nullptr) {
  20584. clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
  20585. return;
  20586. }
  20587. if (tsd->macro_detect.retry != 0) {
  20588. clif_macro_reporter_status(*sd, MCR_INPROGRESS);
  20589. return;
  20590. }
  20591. if (captcha_db.empty()) {
  20592. clif_macro_reporter_status(*sd, MCR_NO_DATA);
  20593. return;
  20594. }
  20595. pc_macro_reporter_process(*tsd, sd->status.account_id);
  20596. clif_macro_reporter_status(*sd, MCR_MONITORING);
  20597. #endif
  20598. }
  20599. void clif_macro_reporter_status(map_session_data &sd, e_macro_report_status stype) {
  20600. #if PACKETVER >= 20160330
  20601. PACKET_ZC_ACK_APPLY_MACRO_DETECTOR p = {};
  20602. p.PacketType = HEADER_ZC_ACK_APPLY_MACRO_DETECTOR;
  20603. p.status = stype;
  20604. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20605. #endif
  20606. }
  20607. void clif_dynamicnpc_result( map_session_data& sd, e_dynamicnpc_result result ){
  20608. #if PACKETVER_MAIN_NUM >= 20140430 || PACKETVER_RE_NUM >= 20140430 || defined(PACKETVER_ZERO)
  20609. PACKET_ZC_DYNAMICNPC_CREATE_RESULT p = {};
  20610. p.PacketType = HEADER_ZC_DYNAMICNPC_CREATE_RESULT;
  20611. p.result = result;
  20612. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20613. #endif
  20614. }
  20615. void clif_partybooking_ask( map_session_data* sd, map_session_data* joining_sd ){
  20616. #if PACKETVER >= 20191204
  20617. PACKET_ZC_PARTY_REQ_MASTER_TO_JOIN p = {};
  20618. p.packetType = HEADER_ZC_PARTY_REQ_MASTER_TO_JOIN;
  20619. p.CID = joining_sd->status.char_id;
  20620. p.AID = joining_sd->status.account_id;
  20621. safestrncpy( p.name, joining_sd->status.name, NAME_LENGTH );
  20622. p.x = joining_sd->status.base_level;
  20623. p.y = joining_sd->status.class_;
  20624. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20625. #endif
  20626. }
  20627. void clif_parse_partybooking_join( int32 fd, map_session_data* sd ){
  20628. #if PACKETVER >= 20191204
  20629. const PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN* p = reinterpret_cast<PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN*>( RFIFOP( fd, 0 ) );
  20630. // Character is already in a party
  20631. if( sd->status.party_id != 0 ){
  20632. return;
  20633. }
  20634. map_session_data* tsd = map_charid2sd( p->CID );
  20635. // Target player is offline
  20636. if( tsd == nullptr ){
  20637. return;
  20638. }
  20639. if( tsd->status.account_id != p->AID ){
  20640. return;
  20641. }
  20642. struct s_party_booking_requirement requirement;
  20643. if( !party_booking_load( tsd->status.account_id, tsd->status.char_id, &requirement ) ){
  20644. return;
  20645. }
  20646. if( sd->status.base_level < requirement.minimum_level ){
  20647. return;
  20648. }
  20649. if( sd->status.base_level > requirement.maximum_level ){
  20650. return;
  20651. }
  20652. // Already requested to join this party
  20653. if( util::vector_exists( tsd->party_booking_requests, sd->status.char_id ) ){
  20654. return;
  20655. }
  20656. // Store information that the player tried to join the party
  20657. tsd->party_booking_requests.push_back( sd->status.char_id );
  20658. clif_partybooking_ask( tsd, sd );
  20659. #endif
  20660. }
  20661. void clif_partybooking_reply( map_session_data* sd, map_session_data* party_leader_sd, bool accepted ){
  20662. #if PACKETVER >= 20191204
  20663. PACKET_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER p = {};
  20664. if( party_leader_sd->status.party_id == 0 ){
  20665. return;
  20666. }
  20667. struct party_data* party = party_search( party_leader_sd->status.party_id );
  20668. if( party == nullptr ){
  20669. return;
  20670. }
  20671. p.packetType = HEADER_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER;
  20672. safestrncpy( p.player_name, party_leader_sd->status.name, NAME_LENGTH );
  20673. safestrncpy( p.party_name, party->party.name, NAME_LENGTH );
  20674. p.AID = party_leader_sd->status.account_id;
  20675. p.refused = !accepted;
  20676. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20677. #endif
  20678. }
  20679. void clif_parse_partybooking_reply( int32 fd, map_session_data* sd ){
  20680. #if PACKETVER >= 20191204
  20681. const PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN* p = reinterpret_cast<PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN*>( RFIFOP( fd, 0 ) );
  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. // Check if the player even requested to join the party
  20691. if( !util::vector_exists( sd->party_booking_requests, p->CID ) ){
  20692. return;
  20693. }
  20694. util::vector_erase_if_exists( sd->party_booking_requests, p->CID );
  20695. // Only party leaders can reply
  20696. if( !party_isleader( sd ) ){
  20697. return;
  20698. }
  20699. struct party_data* party = party_search( sd->status.party_id );
  20700. if( party == nullptr ){
  20701. return;
  20702. }
  20703. if( party->instance_id > 0 && battle_config.instance_block_invite ){
  20704. return;
  20705. }
  20706. if( p->accept ){
  20707. party_join( *tsd, sd->status.party_id );
  20708. }
  20709. clif_partybooking_reply( tsd, sd, p->accept );
  20710. #endif
  20711. }
  20712. /// /resetskill.
  20713. /// Request to skills.
  20714. /// 0bb1 <type>.W <unknown>.B (CZ_RESET_SKILL)
  20715. void clif_parse_reset_skill( int32 fd, map_session_data* sd ){
  20716. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220203
  20717. const PACKET_CZ_RESET_SKILL* p = reinterpret_cast<PACKET_CZ_RESET_SKILL*>( RFIFOP( fd, 0 ) );
  20718. char cmd[CHAT_SIZE_MAX];
  20719. safesnprintf( cmd, sizeof( cmd ), "%cresetskill", atcommand_symbol );
  20720. is_atcommand( fd, sd, cmd, 1 );
  20721. #endif
  20722. }
  20723. void clif_set_dialog_align(map_session_data& sd, int32 npcid, e_say_dialog_align align)
  20724. {
  20725. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20726. PACKET_ZC_DIALOG_TEXT_ALIGN p = {};
  20727. p.PacketType = HEADER_ZC_DIALOG_TEXT_ALIGN;
  20728. p.align = align;
  20729. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20730. #endif // PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20731. }
  20732. void clif_set_npc_window_size(map_session_data& sd, int32 width, int32 height)
  20733. {
  20734. #if PACKETVER_MAIN_NUM >= 20220504
  20735. PACKET_ZC_DIALOG_WINDOW_SIZE p = {};
  20736. p.PacketType = HEADER_ZC_DIALOG_WINDOW_SIZE;
  20737. p.width = width;
  20738. p.height = height;
  20739. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20740. #endif // PACKETVER_MAIN_NUM >= 20220504
  20741. }
  20742. void clif_set_npc_window_pos(map_session_data& sd, int32 x, int32 y)
  20743. {
  20744. #if PACKETVER_MAIN_NUM >= 20220504
  20745. PACKET_ZC_DIALOG_WINDOW_POS p = {};
  20746. p.PacketType = HEADER_ZC_DIALOG_WINDOW_POS;
  20747. p.x = x;
  20748. p.y = y;
  20749. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20750. #endif // PACKETVER_MAIN_NUM >= 20220504
  20751. }
  20752. void clif_set_npc_window_pos_percent(map_session_data& sd, int32 x, int32 y)
  20753. {
  20754. #if PACKETVER_MAIN_NUM >= 20220504
  20755. PACKET_ZC_DIALOG_WINDOW_POS2 p = {};
  20756. p.PacketType = HEADER_ZC_DIALOG_WINDOW_POS2;
  20757. p.x = x;
  20758. p.y = y;
  20759. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20760. #endif // PACKETVER_MAIN_NUM >= 20220504
  20761. }
  20762. /// Displays a special popup.
  20763. /// Works only if player moved from one map to another.
  20764. /// 0bbe <popup id>.L (ZC_SPECIALPOPUP)
  20765. void clif_specialpopup(map_session_data& sd, int32 id ){
  20766. #if PACKETVER >= 20221005
  20767. PACKET_ZC_SPECIALPOPUP p = {};
  20768. p.PacketType = HEADER_ZC_SPECIALPOPUP;
  20769. p.ppId = id;
  20770. clif_send( &p, sizeof( p ), &sd.bl, SELF);
  20771. #endif
  20772. }
  20773. /// 0c0c <result>.W (ZC_GM_CHECKER)
  20774. void clif_macro_checker( map_session_data& sd, e_macro_checker_result result ){
  20775. #if PACKETVER_MAIN_NUM >= 20240502
  20776. PACKET_ZC_GM_CHECKER p = {};
  20777. p.packetType = HEADER_ZC_GM_CHECKER;
  20778. p.result = result;
  20779. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20780. #endif
  20781. }
  20782. /// /macrochecker <mapname>
  20783. /// 0c0b <mapname>.16B (CZ_GM_CHECKER)
  20784. void clif_parse_macro_checker( int32 fd, map_session_data* sd ){
  20785. #if PACKETVER_MAIN_NUM >= 20240502
  20786. if( !pc_can_use_command(sd, "macrochecker", COMMAND_ATCOMMAND)) {
  20787. return;
  20788. }
  20789. const PACKET_CZ_GM_CHECKER* p = reinterpret_cast<PACKET_CZ_GM_CHECKER*>( RFIFOP( fd, 0 ) );
  20790. char command[CHAT_SIZE_MAX];
  20791. char mapname[MAP_NAME_LENGTH_EXT];
  20792. safestrncpy( mapname, p->mapname, sizeof( mapname ) );
  20793. safesnprintf( command, sizeof( command ),"%cmacrochecker %s", atcommand_symbol, mapname );
  20794. is_atcommand( sd->fd, sd, command, 1 );
  20795. #endif
  20796. }
  20797. /*==========================================
  20798. * Main client packet processing function
  20799. *------------------------------------------*/
  20800. static int32 clif_parse(int32 fd)
  20801. {
  20802. int32 cmd, packet_len;
  20803. TBL_PC* sd;
  20804. int32 pnum;
  20805. #ifdef PACKET_OBFUSCATION
  20806. int32 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 = nullptr;
  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, nullptr));
  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 ((int32)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 != nullptr ) {
  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 == nullptr && 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)(int32, map_session_data *), ... ){
  20923. va_list argp;
  20924. int32 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. int32 offset = va_arg(argp, int32);
  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 int32 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( int32 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. }