clif.cpp 739 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370
  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 "trade.hpp"
  56. #include "unit.hpp"
  57. #include "vending.hpp"
  58. using namespace rathena;
  59. static inline uint32 client_tick( t_tick tick ){
  60. return (uint32)tick;
  61. }
  62. #if PACKETVER >= 20170830
  63. static inline int64 client_exp(t_exp exp) {
  64. return (int64)u64min(exp, MAX_EXP);
  65. }
  66. #else
  67. static inline int32 client_exp(t_exp exp) {
  68. return (int32)u64min(exp, MAX_EXP);
  69. }
  70. #endif
  71. /* for clif_clearunit_delayed */
  72. static struct eri *delay_clearunit_ers;
  73. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  74. unsigned long color_table[COLOR_MAX];
  75. #include "clif_obfuscation.hpp"
  76. static bool clif_session_isValid(map_session_data *sd);
  77. static void clif_loadConfirm( map_session_data *sd );
  78. static void clif_favorite_item( map_session_data& sd, uint16 index );
  79. #if PACKETVER >= 20150513
  80. enum mail_type {
  81. MAIL_TYPE_TEXT = 0x0,
  82. MAIL_TYPE_ZENY = 0x2,
  83. MAIL_TYPE_ITEM = 0x4,
  84. MAIL_TYPE_NPC = 0x8
  85. };
  86. #endif
  87. enum e_inventory_type{
  88. INVTYPE_INVENTORY = 0,
  89. INVTYPE_CART = 1,
  90. INVTYPE_STORAGE = 2,
  91. INVTYPE_GUILD_STORAGE = 3,
  92. };
  93. /** Converts item type to display it on client if necessary.
  94. * @param nameid: Item ID
  95. * @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
  96. */
  97. static inline int itemtype(t_itemid nameid) {
  98. 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
  99. int type = id->type;
  100. if( type == IT_SHADOWGEAR ) {
  101. if( id->equip&EQP_SHADOW_WEAPON )
  102. return IT_WEAPON;
  103. else
  104. return IT_ARMOR;
  105. }
  106. return ( type == IT_PETEGG ) ? IT_ARMOR : type;
  107. }
  108. // TODO: doc
  109. static inline uint16 client_index( uint16 server_index ){
  110. return server_index + 2;
  111. }
  112. static inline uint16 server_index( uint16 client_index ){
  113. return client_index - 2;
  114. }
  115. static inline uint16 client_storage_index( uint16 server_index ){
  116. return server_index + 1;
  117. }
  118. static inline uint16 server_storage_index( uint16 client_index ){
  119. return client_index - 1;
  120. }
  121. static inline uint32 disguised_bl_id( uint32 bl_id ){
  122. // Casting to prevent a compiler warning
  123. return -((int32)bl_id);
  124. }
  125. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  126. static inline uint32 client_nameid( t_itemid server_nameid ){
  127. t_itemid view = itemdb_viewid( server_nameid );
  128. if( view > 0 ){
  129. return view;
  130. }else{
  131. return server_nameid;
  132. }
  133. }
  134. #else
  135. static inline uint16 client_nameid( t_itemid server_nameid ){
  136. t_itemid view = itemdb_viewid( server_nameid );
  137. if( view > 0 ){
  138. if( view > UINT16_MAX ){
  139. return (uint16)UNKNOWN_ITEM_ID;
  140. }
  141. return (uint16)view;
  142. }else{
  143. if( server_nameid > UINT16_MAX ){
  144. return (uint16)UNKNOWN_ITEM_ID;
  145. }
  146. return (uint16)server_nameid;
  147. }
  148. }
  149. #endif
  150. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  151. p += pos;
  152. p[0] = (uint8)(x>>2);
  153. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  154. p[2] = (uint8)((y<<4) | (dir&0xf));
  155. }
  156. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  157. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  158. p += pos;
  159. p[0] = (uint8)(x0>>2);
  160. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  161. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  162. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  163. p[4] = (uint8)y1;
  164. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  165. }
  166. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  167. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  168. }
  169. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  170. p += pos;
  171. if( x ) {
  172. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  173. }
  174. if( y ) {
  175. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  176. }
  177. if( dir ) {
  178. dir[0] = ( p[2] & 0x0f );
  179. }
  180. }
  181. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  182. p += pos;
  183. if( x0 ) {
  184. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  185. }
  186. if( y0 ) {
  187. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  188. }
  189. if( x1 ) {
  190. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  191. }
  192. if( y1 ) {
  193. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  194. }
  195. if( sx0 ) {
  196. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  197. }
  198. if( sy0 ) {
  199. sy0[0] = ( p[5] & 0x0f ) >> 0;
  200. }
  201. }
  202. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  203. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  204. }
  205. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  206. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  207. }
  208. //To idenfity disguised characters.
  209. static inline bool disguised(struct block_list* bl) {
  210. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  211. }
  212. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  213. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  214. if( len > max )
  215. len = max;
  216. mes[len-1] = '\0';
  217. return len;
  218. }
  219. static char map_ip_str[128];
  220. static uint32 map_ip;
  221. static uint32 bind_ip = INADDR_ANY;
  222. static uint16 map_port = 5121;
  223. static bool clif_ally_only = false;
  224. int map_fd;
  225. static int clif_parse (int fd);
  226. /*==========================================
  227. * Ip setting of map-server
  228. *------------------------------------------*/
  229. int clif_setip(const char* ip) {
  230. char ip_str[16];
  231. map_ip = host2ip(ip);
  232. if (!map_ip) {
  233. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  234. return 0;
  235. }
  236. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  237. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  238. return 1;
  239. }
  240. void clif_setbindip(const char* ip)
  241. {
  242. bind_ip = host2ip(ip);
  243. if (bind_ip) {
  244. char ip_str[16];
  245. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  246. } else {
  247. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  248. }
  249. }
  250. /*==========================================
  251. * Sets map port to 'port'
  252. * is run from map.cpp upon loading map server configuration
  253. *------------------------------------------*/
  254. void clif_setport(uint16 port)
  255. {
  256. map_port = port;
  257. }
  258. /*==========================================
  259. * Returns map server IP
  260. *------------------------------------------*/
  261. uint32 clif_getip(void)
  262. {
  263. return map_ip;
  264. }
  265. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  266. uint32 clif_refresh_ip(void)
  267. {
  268. uint32 new_ip;
  269. new_ip = host2ip(map_ip_str);
  270. if (new_ip && new_ip != map_ip) {
  271. map_ip = new_ip;
  272. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  273. return map_ip;
  274. }
  275. return 0;
  276. }
  277. /*==========================================
  278. * Returns map port which is set by clif_setport()
  279. *------------------------------------------*/
  280. uint16 clif_getport(void)
  281. {
  282. return map_port;
  283. }
  284. #if PACKETVER >= 20071106
  285. static inline unsigned char clif_bl_type(struct block_list *bl, bool walking) {
  286. switch (bl->type) {
  287. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  288. case BL_ITEM: return 0x2; //ITEM_TYPE
  289. case BL_SKILL: return 0x3; //SKILL_TYPE
  290. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  291. case BL_MOB:
  292. if( pcdb_checkid( status_get_viewdata( bl )->class_ ) ){
  293. return 0x0; //PC_TYPE
  294. }else{
  295. switch( ( (mob_data*)bl )->special_state.ai ){
  296. case AI_ABR:
  297. return 0xd; //NPC_ABR_TYPE
  298. case AI_BIONIC:
  299. return 0xe; //NPC_BIONIC_TYPE
  300. default:
  301. return 0x5; //NPC_MOB_TYPE
  302. }
  303. }
  304. case BL_NPC:
  305. // From 2017-07-26 on NPC type units can also use player sprites.
  306. // There is one exception and this is if they are walking.
  307. // Since walking NPCs are not supported on official servers, the client does not know how to handle it.
  308. #if PACKETVER >= 20170726
  309. if (pcdb_checkid( status_get_viewdata( bl )->class_ ) && walking)
  310. return 0x0;
  311. else if (mobdb_checkid( status_get_viewdata( bl )->class_ )) // FIXME: categorize NPCs able to walk
  312. return 0xC;
  313. else
  314. return 0x6;
  315. #else
  316. return pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x6; //NPC_EVT_TYPE
  317. #endif
  318. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  319. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  320. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  321. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  322. default: return 0x1; //NPC_TYPE
  323. }
  324. }
  325. #endif
  326. static bool clif_session_isValid(map_session_data *sd) {
  327. return ( sd != nullptr && session_isActive(sd->fd) );
  328. }
  329. /*==========================================
  330. * sub process of clif_send
  331. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  332. * In order to send area-wise packets, such as:
  333. * - AREA : everyone nearby your area
  334. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  335. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  336. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  337. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  338. *------------------------------------------*/
  339. static int clif_send_sub(struct block_list *bl, va_list ap)
  340. {
  341. struct block_list *src_bl;
  342. map_session_data *sd;
  343. unsigned char *buf;
  344. int len, type, fd;
  345. nullpo_ret(bl);
  346. nullpo_ret(sd = (map_session_data *)bl);
  347. // Don't send to disconnected clients.
  348. if( !session_isActive( fd = sd->fd ) ){
  349. return 0;
  350. }
  351. buf = va_arg(ap,unsigned char*);
  352. len = va_arg(ap,int);
  353. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  354. type = va_arg(ap,int);
  355. switch(type) {
  356. case AREA_WOS:
  357. if (bl == src_bl)
  358. return 0;
  359. break;
  360. case AREA_WOC:
  361. if (sd->chatID || bl == src_bl)
  362. return 0;
  363. break;
  364. case AREA_WOSC:
  365. {
  366. if(src_bl->type == BL_PC) {
  367. map_session_data *ssd = (map_session_data *)src_bl;
  368. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  369. return 0;
  370. }
  371. else if(src_bl->type == BL_NPC) {
  372. struct npc_data *nd = (struct npc_data *)src_bl;
  373. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  374. return 0;
  375. }
  376. }
  377. break;
  378. }
  379. if( src_bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)src_bl ), *sd ) ){
  380. // Do not send anything
  381. return 0;
  382. }
  383. /* unless visible, hold it here */
  384. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  385. !sd->sc.getSCE(SC_INTRAVISION) && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  386. return 0;
  387. WFIFOHEAD(fd, len);
  388. if (WFIFOP(fd,0) == buf) {
  389. ShowError("WARNING: Invalid use of clif_send function\n");
  390. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  391. ShowError(" Please correct your code.\n");
  392. // don't send to not move the pointer of the packet for next sessions in the loop
  393. //WFIFOSET(fd,0);//## TODO is this ok?
  394. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  395. return 0;
  396. }
  397. memcpy(WFIFOP(fd,0), buf, len);
  398. WFIFOSET(fd,len);
  399. return 0;
  400. }
  401. /*==========================================
  402. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  403. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  404. *------------------------------------------*/
  405. int clif_send(const void* buf, int len, struct block_list* bl, enum send_target type)
  406. {
  407. int i;
  408. map_session_data *sd, *tsd;
  409. struct party_data *p = nullptr;
  410. std::shared_ptr<s_battleground_data> bg;
  411. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  412. struct s_mapiterator* iter;
  413. if( type != ALL_CLIENT )
  414. nullpo_ret(bl);
  415. sd = BL_CAST(BL_PC, bl);
  416. switch(type) {
  417. case ALL_CLIENT: //All player clients.
  418. iter = mapit_getallusers();
  419. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  420. if( session_isActive( fd = tsd->fd ) ){
  421. WFIFOHEAD( fd, len );
  422. memcpy( WFIFOP( fd, 0 ), buf, len );
  423. WFIFOSET( fd, len );
  424. }
  425. }
  426. mapit_free(iter);
  427. break;
  428. case ALL_SAMEMAP: //All players on the same map
  429. iter = mapit_getallusers();
  430. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  431. if( bl->m == tsd->bl.m && session_isActive( fd = tsd->fd ) ){
  432. WFIFOHEAD( fd, len );
  433. memcpy( WFIFOP( fd, 0 ), buf, len );
  434. WFIFOSET( fd, len );
  435. }
  436. }
  437. mapit_free(iter);
  438. break;
  439. case AREA:
  440. case AREA_WOSC:
  441. if (sd && bl->prev == nullptr) //Otherwise source misses the packet.[Skotlex]
  442. clif_send (buf, len, bl, SELF);
  443. [[fallthrough]];
  444. case AREA_WOC:
  445. case AREA_WOS:
  446. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  447. BL_PC, buf, len, bl, type);
  448. break;
  449. case AREA_CHAT_WOC:
  450. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  451. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  452. break;
  453. case CHAT:
  454. case CHAT_WOS:
  455. {
  456. struct chat_data *cd;
  457. if (sd) {
  458. cd = (struct chat_data*)map_id2bl(sd->chatID);
  459. } else if (bl->type == BL_CHAT) {
  460. cd = (struct chat_data*)bl;
  461. } else break;
  462. if (cd == nullptr)
  463. break;
  464. for(i = 0; i < cd->users; i++) {
  465. if (type == CHAT_WOS && cd->usersd[i] == sd)
  466. continue;
  467. if( session_isActive( fd = cd->usersd[i]->fd ) ){
  468. WFIFOHEAD(fd,len);
  469. memcpy(WFIFOP(fd,0), buf, len);
  470. WFIFOSET(fd,len);
  471. }
  472. }
  473. }
  474. break;
  475. case PARTY_AREA:
  476. case PARTY_AREA_WOS:
  477. x0 = bl->x - AREA_SIZE;
  478. y0 = bl->y - AREA_SIZE;
  479. x1 = bl->x + AREA_SIZE;
  480. y1 = bl->y + AREA_SIZE;
  481. [[fallthrough]];
  482. case PARTY:
  483. case PARTY_WOS:
  484. case PARTY_SAMEMAP:
  485. case PARTY_SAMEMAP_WOS:
  486. if (sd && sd->status.party_id)
  487. p = party_search(sd->status.party_id);
  488. if (p) {
  489. for(i=0;i<MAX_PARTY;i++){
  490. if( (sd = p->data[i].sd) == nullptr )
  491. continue;
  492. if( !session_isActive( fd = sd->fd ) )
  493. continue;
  494. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  495. continue;
  496. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  497. continue;
  498. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  499. continue;
  500. WFIFOHEAD(fd, len);
  501. memcpy(WFIFOP(fd, 0), buf, len);
  502. WFIFOSET(fd, len);
  503. }
  504. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  505. break;
  506. iter = mapit_getallusers();
  507. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  508. if( tsd->partyspy == p->party.party_id && session_isActive( fd = tsd->fd ) ){
  509. WFIFOHEAD( fd, len );
  510. memcpy( WFIFOP( fd, 0 ), buf, len );
  511. WFIFOSET( tsd->fd, len );
  512. }
  513. }
  514. mapit_free(iter);
  515. }
  516. break;
  517. case DUEL:
  518. case DUEL_WOS:
  519. if (!sd || !sd->duel_group) break; //Invalid usage.
  520. iter = mapit_getallusers();
  521. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  522. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  523. continue;
  524. if( sd->duel_group == tsd->duel_group && session_isActive( fd = tsd->fd ) ){
  525. WFIFOHEAD( fd, len );
  526. memcpy( WFIFOP( fd, 0 ), buf, len );
  527. WFIFOSET( fd, len );
  528. }
  529. }
  530. mapit_free(iter);
  531. break;
  532. case SELF:
  533. if( clif_session_isValid(sd) ){
  534. fd = sd->fd;
  535. WFIFOHEAD(fd,len);
  536. memcpy(WFIFOP(fd,0), buf, len);
  537. WFIFOSET(fd,len);
  538. }
  539. break;
  540. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  541. case GUILD_AREA:
  542. case GUILD_AREA_WOS:
  543. x0 = bl->x - AREA_SIZE;
  544. y0 = bl->y - AREA_SIZE;
  545. x1 = bl->x + AREA_SIZE;
  546. y1 = bl->y + AREA_SIZE;
  547. [[fallthrough]];
  548. case GUILD_SAMEMAP:
  549. case GUILD_SAMEMAP_WOS:
  550. case GUILD:
  551. case GUILD_WOS:
  552. case GUILD_NOBG: {
  553. if (!sd || !sd->status.guild_id || !sd->guild)
  554. break;
  555. const auto &g = sd->guild->guild;
  556. for(i = 0; i < g.max_member; i++) {
  557. if( (sd = g.member[i].sd) != nullptr ){
  558. if( !session_isActive( fd = sd->fd ) )
  559. continue;
  560. if( type == GUILD_NOBG && sd->bg_id )
  561. continue;
  562. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  563. continue;
  564. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  565. continue;
  566. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  567. continue;
  568. WFIFOHEAD(fd,len);
  569. memcpy(WFIFOP(fd,0), buf, len);
  570. WFIFOSET(fd,len);
  571. }
  572. }
  573. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  574. break;
  575. iter = mapit_getallusers();
  576. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  577. if( tsd->guildspy == g.guild_id && session_isActive( fd = tsd->fd ) ){
  578. WFIFOHEAD( fd, len );
  579. memcpy( WFIFOP( fd, 0 ), buf, len );
  580. WFIFOSET( fd, len );
  581. }
  582. }
  583. mapit_free(iter);
  584. break;
  585. }
  586. case BG_AREA:
  587. case BG_AREA_WOS:
  588. x0 = bl->x - AREA_SIZE;
  589. y0 = bl->y - AREA_SIZE;
  590. x1 = bl->x + AREA_SIZE;
  591. y1 = bl->y + AREA_SIZE;
  592. [[fallthrough]];
  593. case BG_SAMEMAP:
  594. case BG_SAMEMAP_WOS:
  595. case BG:
  596. case BG_WOS:
  597. if( sd && sd->bg_id > 0 && (bg = util::umap_find(bg_team_db, sd->bg_id)))
  598. {
  599. for (const auto &member : bg->members) {
  600. if( ( sd = member.sd ) == nullptr || !session_isActive( fd = sd->fd ) )
  601. continue;
  602. if(sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  603. continue;
  604. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  605. continue;
  606. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  607. continue;
  608. WFIFOHEAD(fd,len);
  609. memcpy(WFIFOP(fd,0), buf, len);
  610. WFIFOSET(fd,len);
  611. }
  612. }
  613. break;
  614. case CLAN:
  615. if( sd && sd->clan ){
  616. struct clan* clan = sd->clan;
  617. for( i = 0; i < clan->max_member; i++ ){
  618. if( ( sd = clan->members[i] ) == nullptr || !session_isActive( fd = sd->fd ) ){
  619. continue;
  620. }
  621. WFIFOHEAD(fd,len);
  622. memcpy(WFIFOP(fd,0), buf, len);
  623. WFIFOSET(fd,len);
  624. }
  625. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  626. break;
  627. iter = mapit_getallusers();
  628. while( ( tsd = (map_session_data*)mapit_next( iter ) ) != nullptr ){
  629. if( tsd->clanspy == clan->id && session_isActive( fd = tsd->fd ) ){
  630. WFIFOHEAD(fd, len);
  631. memcpy(WFIFOP(fd, 0), buf, len);
  632. WFIFOSET(fd, len);
  633. }
  634. }
  635. mapit_free(iter);
  636. }
  637. break;
  638. default:
  639. ShowError("clif_send: Unrecognized type %d\n",type);
  640. return -1;
  641. }
  642. return 0;
  643. }
  644. /// Notifies the client, that it's connection attempt was accepted.
  645. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  646. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  647. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  648. void clif_authok(map_session_data *sd)
  649. {
  650. PACKET_ZC_ACCEPT_ENTER packet{};
  651. packet.packetType = HEADER_ZC_ACCEPT_ENTER;
  652. packet.startTime = client_tick(gettick());
  653. WBUFPOS(packet.posDir, 0, sd->bl.x, sd->bl.y, sd->ud.dir);
  654. packet.xSize = 5; // ignored
  655. packet.ySize = 5; // ignored
  656. #if PACKETVER >= 20080102
  657. packet.font = sd->status.font;
  658. #endif
  659. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  660. packet.sex = sd->status.sex;
  661. #endif
  662. clif_send(&packet, sizeof(packet), &sd->bl, SELF);
  663. }
  664. /// Notifies the client, that it's connection attempt was refused.
  665. /// 0074 <error code>.B (ZC_REFUSE_ENTER)
  666. /// error code:
  667. /// 0 = client type mismatch
  668. /// 1 = ID mismatch
  669. /// 2 = mobile - out of available time
  670. /// 3 = mobile - already logged in
  671. /// 4 = mobile - waiting state
  672. void clif_authrefuse(int fd, uint8 error_code)
  673. {
  674. PACKET_ZC_REFUSE_ENTER packet{};
  675. packet.packetType = HEADER_ZC_REFUSE_ENTER;
  676. packet.errorCode = error_code;
  677. socket_send<PACKET_ZC_REFUSE_ENTER>(fd, packet);
  678. }
  679. /// Notifies the client of a ban or forced disconnect.
  680. /// 0081 <error code>.B (SC_NOTIFY_BAN)
  681. /// error code:
  682. /// 0 = BAN_UNFAIR
  683. /// 1 = server closed -> MsgStringTable[4]
  684. /// 2 = ID already logged in -> MsgStringTable[5]
  685. /// 3 = timeout/too much lag -> MsgStringTable[241]
  686. /// 4 = server full -> MsgStringTable[264]
  687. /// 5 = underaged -> MsgStringTable[305]
  688. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  689. /// 9 = too many connections from this ip -> MsgStringTable[529]
  690. /// 10 = out of available time paid for -> MsgStringTable[530]
  691. /// 11 = BAN_PAY_SUSPEND
  692. /// 12 = BAN_PAY_CHANGE
  693. /// 13 = BAN_PAY_WRONGIP
  694. /// 14 = BAN_PAY_PNGAMEROOM
  695. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  696. /// 16 = BAN_JAPAN_REFUSE1
  697. /// 17 = BAN_JAPAN_REFUSE2
  698. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  699. /// 100 = BAN_PC_IP_UNFAIR
  700. /// 101 = BAN_PC_IP_COUNT_ALL
  701. /// 102 = BAN_PC_IP_COUNT
  702. /// 103 = BAN_GRAVITY_MEM_AGREE
  703. /// 104 = BAN_GAME_MEM_AGREE
  704. /// 105 = BAN_HAN_VALID
  705. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  706. /// 107 = BAN_OVER_CHARACTER_LIST
  707. /// 108 = BAN_IP_BLOCK
  708. /// 109 = BAN_INVALID_PWD_CNT
  709. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  710. /// ? = disconnected -> MsgStringTable[3]
  711. void clif_authfail_fd(int fd, int type)
  712. {
  713. if (!session_isValid(fd) || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  714. return;
  715. PACKET_SC_NOTIFY_BAN packet{};
  716. packet.packetType = HEADER_SC_NOTIFY_BAN;
  717. packet.errorCode = static_cast<uint8>(type);
  718. socket_send<PACKET_SC_NOTIFY_BAN>(fd, packet);
  719. set_eof(fd);
  720. }
  721. /// Notifies the client, whether it can disconnect and change servers.
  722. /// 00b3 <type>.B (ZC_RESTART_ACK)
  723. /// type:
  724. /// 1 = disconnect, char-select
  725. /// ? = nothing
  726. void clif_charselectok(int id, uint8 ok)
  727. {
  728. map_session_data* sd = map_id2sd(id);
  729. if (sd == nullptr)
  730. return;
  731. PACKET_ZC_RESTART_ACK packet{};
  732. packet.packetType = HEADER_ZC_RESTART_ACK;
  733. packet.type = ok;
  734. clif_send( &packet, sizeof( packet ), &sd->bl, SELF );
  735. }
  736. /// Makes an item appear on the ground.
  737. /// 009E <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  738. /// 084B <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  739. /// 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)
  740. void clif_dropflooritem( struct flooritem_data* fitem, bool canShowEffect ){
  741. nullpo_retv(fitem);
  742. if( fitem->item.nameid == 0 ){
  743. return;
  744. }
  745. struct packet_dropflooritem p;
  746. p.PacketType = dropflooritemType;
  747. p.ITAID = fitem->bl.id;
  748. p.ITID = client_nameid( fitem->item.nameid );
  749. #if PACKETVER >= 20130000 /* not sure date */
  750. p.type = itemtype( fitem->item.nameid );
  751. #endif
  752. p.IsIdentified = fitem->item.identify ? 1 : 0;
  753. p.xPos = fitem->bl.x;
  754. p.yPos = fitem->bl.y;
  755. p.subX = fitem->subx;
  756. p.subY = fitem->suby;
  757. p.count = fitem->item.amount;
  758. #if defined(PACKETVER_ZERO) || PACKETVER >= 20180418
  759. if( canShowEffect ){
  760. uint8 dropEffect = itemdb_dropeffect( fitem->item.nameid );
  761. if( dropEffect > 0 ){
  762. p.showdropeffect = 1;
  763. p.dropeffectmode = dropEffect - 1;
  764. }else if (battle_config.rndopt_drop_pillar != 0){
  765. uint8 optionCount = 0;
  766. for (uint8 i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  767. if (fitem->item.option[i].id != 0) {
  768. optionCount++;
  769. }
  770. }
  771. if (optionCount > 0) {
  772. p.showdropeffect = 1;
  773. if (optionCount == 1)
  774. p.dropeffectmode = DROPEFFECT_BLUE_PILLAR - 1;
  775. else if (optionCount == 2)
  776. p.dropeffectmode = DROPEFFECT_YELLOW_PILLAR - 1;
  777. else
  778. p.dropeffectmode = DROPEFFECT_PURPLE_PILLAR - 1;
  779. } else {
  780. p.showdropeffect = 0;
  781. p.dropeffectmode = DROPEFFECT_NONE;
  782. }
  783. } else {
  784. p.showdropeffect = 0;
  785. p.dropeffectmode = DROPEFFECT_NONE;
  786. }
  787. }else{
  788. p.showdropeffect = 0;
  789. p.dropeffectmode = DROPEFFECT_NONE;
  790. }
  791. #endif
  792. clif_send( &p, sizeof(p), &fitem->bl, AREA );
  793. }
  794. /// Makes an item disappear from the ground.
  795. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  796. void clif_clearflooritem( flooritem_data& fitem, map_session_data* tsd ){
  797. PACKET_ZC_ITEM_DISAPPEAR packet{};
  798. packet.packetType = HEADER_ZC_ITEM_DISAPPEAR;
  799. packet.itemAid = fitem.bl.id;
  800. if( tsd == nullptr ){
  801. clif_send(&packet, sizeof(PACKET_ZC_ITEM_DISAPPEAR), &fitem.bl, AREA);
  802. } else {
  803. clif_send(&packet, sizeof(PACKET_ZC_ITEM_DISAPPEAR), &tsd->bl, SELF );
  804. }
  805. }
  806. /// Makes a unit (char, npc, mob, homun) disappear to one client.
  807. /// 0080 <id>.L <type>.B (ZC_NOTIFY_VANISH)
  808. /// type:
  809. /// 0 = out of sight
  810. /// 1 = died
  811. /// 2 = logged out
  812. /// 3 = teleport
  813. /// 4 = trickdead
  814. void clif_clearunit_single( uint32 GID, clr_type type, map_session_data& tsd ){
  815. PACKET_ZC_NOTIFY_VANISH packet{};
  816. packet.packetType = HEADER_ZC_NOTIFY_VANISH;
  817. packet.gid = GID;
  818. packet.type = static_cast<decltype(packet.type)>(type);
  819. clif_send( &packet, sizeof( packet ), &tsd.bl, SELF );
  820. }
  821. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area.
  822. /// 0080 <id>.L <type>.B (ZC_NOTIFY_VANISH)
  823. /// type:
  824. /// 0 = out of sight
  825. /// 1 = died
  826. /// 2 = logged out
  827. /// 3 = teleport
  828. /// 4 = trickdead
  829. void clif_clearunit_area( block_list& bl, clr_type type ){
  830. PACKET_ZC_NOTIFY_VANISH packet{};
  831. packet.packetType = HEADER_ZC_NOTIFY_VANISH;
  832. packet.gid = bl.id;
  833. packet.type = static_cast<uint8>(type);
  834. clif_send(&packet, sizeof(PACKET_ZC_NOTIFY_VANISH), &bl, type == CLR_DEAD ? AREA : AREA_WOS);
  835. if(disguised(&bl)) {
  836. packet.gid = disguised_bl_id( bl.id );
  837. clif_send(&packet, sizeof(PACKET_ZC_NOTIFY_VANISH), &bl, SELF);
  838. }
  839. }
  840. /// Used to make monsters with player-sprites disappear after dying
  841. /// like normal monsters, because the client does not remove those
  842. /// automatically.
  843. static TIMER_FUNC(clif_clearunit_delayed_sub){
  844. struct block_list *bl = (struct block_list *)data;
  845. if( bl != nullptr ){
  846. clif_clearunit_area( *bl, (clr_type)id );
  847. ers_free( delay_clearunit_ers, bl );
  848. }
  849. return 0;
  850. }
  851. void clif_clearunit_delayed(struct block_list* bl, clr_type type, t_tick tick)
  852. {
  853. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  854. tbl->next = nullptr;
  855. tbl->prev = nullptr;
  856. tbl->id = bl->id;
  857. tbl->m = bl->m;
  858. tbl->x = bl->x;
  859. tbl->y = bl->y;
  860. tbl->type = BL_NUL;
  861. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  862. }
  863. void clif_get_weapon_view(map_session_data* sd, t_itemid *rhand, t_itemid *lhand)
  864. {
  865. if(sd->sc.option&OPTION_COSTUME)
  866. {
  867. *rhand = *lhand = 0;
  868. return;
  869. }
  870. #if PACKETVER < 4
  871. *rhand = sd->status.weapon;
  872. *lhand = sd->status.shield;
  873. #else
  874. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  875. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  876. {
  877. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  878. if (id->view_id > 0)
  879. *rhand = id->view_id;
  880. else
  881. *rhand = id->nameid;
  882. } else
  883. *rhand = 0;
  884. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  885. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  886. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  887. {
  888. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  889. if (id->view_id > 0)
  890. *lhand = id->view_id;
  891. else
  892. *lhand = id->nameid;
  893. } else
  894. *lhand = 0;
  895. #endif
  896. }
  897. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  898. static int clif_setlevel_sub(int lv) {
  899. if( lv < battle_config.max_lv ) {
  900. ;
  901. } else if( lv < battle_config.aura_lv ) {
  902. lv = battle_config.max_lv - 1;
  903. } else {
  904. lv = battle_config.max_lv;
  905. }
  906. return lv;
  907. }
  908. static int clif_setlevel(struct block_list* bl) {
  909. int lv = status_get_lv(bl);
  910. if( battle_config.client_limit_unit_lv&bl->type )
  911. return clif_setlevel_sub(lv);
  912. switch( bl->type ) {
  913. case BL_NPC:
  914. case BL_PET:
  915. // npcs and pets do not have level
  916. return 0;
  917. }
  918. return lv;
  919. }
  920. /*==========================================
  921. * Prepares 'unit standing/spawning' packet
  922. *------------------------------------------*/
  923. static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target target, struct block_list* tbl ){
  924. nullpo_retv( bl );
  925. map_session_data* sd = BL_CAST( BL_PC, bl );
  926. status_change* sc = status_get_sc( bl );
  927. struct view_data* vd = status_get_viewdata( bl );
  928. int g_id = status_get_guild_id( bl );
  929. #if PACKETVER < 20091103
  930. if( !pcdb_checkid( vd->class_ ) ){
  931. struct packet_idle_unit2 p;
  932. p.PacketType = idle_unit2Type;
  933. #if PACKETVER >= 20071106
  934. p.objecttype = clif_bl_type( bl, walking );
  935. #endif
  936. p.GID = bl->id;
  937. p.speed = status_get_speed( bl );
  938. p.bodyState = ( sc ) ? sc->opt1 : 0;
  939. p.healthState = ( sc ) ? sc->opt2 : 0;
  940. p.effectState = ( sc ) ? sc->option : 0;
  941. p.job = vd->class_;
  942. p.head = vd->hair_style;
  943. p.weapon = vd->weapon;
  944. p.accessory = vd->head_bottom;
  945. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  946. // The hell, why flags work like this?
  947. p.shield = status_get_emblem_id( bl );
  948. p.accessory2 = GetWord( g_id, 1 );
  949. p.accessory3 = GetWord( g_id, 0 );
  950. }else{
  951. p.shield = vd->shield;
  952. p.accessory2 = vd->head_top;
  953. p.accessory3 = vd->head_mid;
  954. }
  955. p.headpalette = vd->hair_color;
  956. p.bodypalette = vd->cloth_color;
  957. p.headDir = ( sd )? sd->head_dir : 0;
  958. p.GUID = g_id;
  959. p.GEmblemVer = status_get_emblem_id( bl );
  960. p.honor = ( sd ) ? sd->status.manner : 0;
  961. p.virtue = ( sc ) ? sc->opt3 : 0;
  962. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  963. p.sex = vd->sex;
  964. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  965. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  966. p.state = vd->dead_sit;
  967. p.clevel = clif_setlevel( bl );
  968. clif_send( &p, sizeof( p ), tbl, target );
  969. return;
  970. }
  971. #endif
  972. struct packet_idle_unit p;
  973. p.PacketType = idle_unitType;
  974. #if PACKETVER >= 20091103
  975. p.PacketLength = sizeof(p);
  976. p.objecttype = clif_bl_type( bl, walking );
  977. #endif
  978. #if PACKETVER >= 20131223
  979. p.AID = bl->id;
  980. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  981. #else
  982. p.GID = bl->id;
  983. #endif
  984. p.speed = status_get_speed(bl);
  985. p.bodyState = (sc) ? sc->opt1 : 0;
  986. p.healthState = (sc) ? sc->opt2 : 0;
  987. // npc option changed?
  988. if( tbl && tbl->type == BL_PC && bl->type == BL_NPC ){
  989. map_session_data* sd = (map_session_data*)tbl;
  990. struct npc_data* nd = (struct npc_data*)bl;
  991. int option = (sc) ? sc->option : 0;
  992. if( !nd->vd.dead_sit ){
  993. if( std::find( sd->cloaked_npc.begin(), sd->cloaked_npc.end(), nd->bl.id ) != sd->cloaked_npc.end() ){
  994. option ^= OPTION_CLOAK;
  995. }
  996. }
  997. p.effectState = option;
  998. }else{
  999. p.effectState = (sc) ? sc->option : 0;
  1000. }
  1001. p.job = vd->class_;
  1002. p.head = vd->hair_style;
  1003. p.weapon = vd->weapon;
  1004. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1005. p.shield = vd->shield;
  1006. #endif
  1007. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1008. // The hell, why flags work like this?
  1009. p.accessory = status_get_emblem_id( bl );
  1010. p.accessory2 = GetWord( g_id, 1 );
  1011. p.accessory3 = GetWord( g_id, 0 );
  1012. }else{
  1013. p.accessory = vd->head_bottom;
  1014. p.accessory2 = vd->head_top;
  1015. p.accessory3 = vd->head_mid;
  1016. }
  1017. p.headpalette = vd->hair_color;
  1018. p.bodypalette = vd->cloth_color;
  1019. p.headDir = (sd)? sd->head_dir : 0;
  1020. #if PACKETVER >= 20101124
  1021. p.robe = vd->robe;
  1022. #endif
  1023. p.GUID = g_id;
  1024. p.GEmblemVer = status_get_emblem_id( bl );
  1025. p.honor = (sd) ? sd->status.manner : 0;
  1026. p.virtue = (sc) ? sc->opt3 : 0;
  1027. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1028. p.sex = vd->sex;
  1029. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1030. p.xSize = p.ySize = (sd) ? 5 : 0;
  1031. p.state = vd->dead_sit;
  1032. p.clevel = clif_setlevel( bl );
  1033. #if PACKETVER >= 20080102
  1034. p.font = (sd) ? sd->status.font : 0;
  1035. #endif
  1036. #if PACKETVER >= 20120221
  1037. 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 ) ) ){
  1038. p.maxHP = status_get_max_hp(bl);
  1039. p.HP = status_get_hp(bl);
  1040. }else{
  1041. p.maxHP = -1;
  1042. p.HP = -1;
  1043. }
  1044. if( bl->type == BL_MOB ){
  1045. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1046. }else if( bl->type == BL_PET ){
  1047. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1048. }else{
  1049. p.isBoss = BOSSTYPE_NONE;
  1050. }
  1051. #endif
  1052. #if PACKETVER >= 20150513
  1053. p.body = vd->body_style;
  1054. #endif
  1055. /* Might be earlier, this is when the named item bug began */
  1056. #if PACKETVER >= 20131223
  1057. safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
  1058. #endif
  1059. clif_send( &p, sizeof( p ), tbl, target );
  1060. // if disguised, send to self
  1061. if( disguised( bl ) ){
  1062. #if PACKETVER >= 20091103
  1063. p.objecttype = pcdb_checkid( status_get_viewdata( bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1064. #if PACKETVER >= 20131223
  1065. p.AID = disguised_bl_id( bl->id );
  1066. #else
  1067. p.GID = disguised_bl_id( bl->id );
  1068. #endif
  1069. #else
  1070. p.GID = disguised_bl_id( bl->id );
  1071. #endif
  1072. clif_send(&p, sizeof(p), bl, SELF);
  1073. }
  1074. }
  1075. static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
  1076. nullpo_retv( bl );
  1077. map_session_data* sd = BL_CAST( BL_PC, bl );
  1078. status_change* sc = status_get_sc( bl );
  1079. struct view_data* vd = status_get_viewdata( bl );
  1080. int g_id = status_get_guild_id( bl );
  1081. #if PACKETVER < 20091103
  1082. if( !pcdb_checkid( vd->class_ ) ){
  1083. struct packet_spawn_unit2 p;
  1084. p.PacketType = spawn_unit2Type;
  1085. #if PACKETVER >= 20071106
  1086. p.objecttype = clif_bl_type( bl, false );
  1087. #endif
  1088. p.GID = bl->id;
  1089. p.speed = status_get_speed( bl );
  1090. p.bodyState = ( sc ) ? sc->opt1 : 0;
  1091. p.healthState = ( sc ) ? sc->opt2 : 0;
  1092. p.effectState = ( sc ) ? sc->option : 0;
  1093. p.head = vd->hair_style;
  1094. p.weapon = vd->weapon;
  1095. p.accessory = vd->head_bottom;
  1096. p.job = vd->class_;
  1097. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1098. // The hell, why flags work like this?
  1099. p.shield = status_get_emblem_id( bl );
  1100. p.accessory2 = GetWord( g_id, 1 );
  1101. p.accessory3 = GetWord( g_id, 0 );
  1102. }else{
  1103. p.shield = vd->shield;
  1104. p.accessory2 = vd->head_top;
  1105. p.accessory3 = vd->head_mid;
  1106. }
  1107. p.headpalette = vd->hair_color;
  1108. p.bodypalette = vd->cloth_color;
  1109. p.headDir = ( sd ) ? sd->head_dir : 0;
  1110. p.isPKModeON = ( sd && sd->status.karma ) ? 1 : 0;
  1111. p.sex = vd->sex;
  1112. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1113. p.xSize = p.ySize = ( sd ) ? 5 : 0;
  1114. clif_send( &p, sizeof( p ), bl, target );
  1115. return;
  1116. }
  1117. #endif
  1118. struct packet_spawn_unit p;
  1119. p.PacketType = spawn_unitType;
  1120. #if PACKETVER >= 20091103
  1121. p.PacketLength = sizeof(p);
  1122. p.objecttype = clif_bl_type( bl, false );
  1123. #endif
  1124. #if PACKETVER >= 20131223
  1125. p.AID = bl->id;
  1126. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1127. #else
  1128. p.GID = bl->id;
  1129. #endif
  1130. p.speed = status_get_speed( bl );
  1131. p.bodyState = (sc) ? sc->opt1 : 0;
  1132. p.healthState = (sc) ? sc->opt2 : 0;
  1133. p.effectState = (sc) ? sc->option : 0;
  1134. p.job = vd->class_;
  1135. p.head = vd->hair_style;
  1136. p.weapon = vd->weapon;
  1137. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1138. p.shield = vd->shield;
  1139. #endif
  1140. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG ){
  1141. // The hell, why flags work like this?
  1142. p.accessory = status_get_emblem_id( bl );
  1143. p.accessory2 = GetWord( g_id, 1 );
  1144. p.accessory3 = GetWord( g_id, 0 );
  1145. }else{
  1146. p.accessory = vd->head_bottom;
  1147. p.accessory2 = vd->head_top;
  1148. p.accessory3 = vd->head_mid;
  1149. }
  1150. p.headpalette = vd->hair_color;
  1151. p.bodypalette = vd->cloth_color;
  1152. p.headDir = (sd)? sd->head_dir : 0;
  1153. #if PACKETVER >= 20101124
  1154. p.robe = vd->robe;
  1155. #endif
  1156. p.GUID = g_id;
  1157. p.GEmblemVer = status_get_emblem_id( bl );
  1158. p.honor = (sd) ? sd->status.manner : 0;
  1159. p.virtue = (sc) ? sc->opt3 : 0;
  1160. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1161. p.sex = vd->sex;
  1162. WBUFPOS( &p.PosDir[0], 0, bl->x, bl->y, unit_getdir( bl ) );
  1163. p.xSize = p.ySize = (sd) ? 5 : 0;
  1164. p.clevel = clif_setlevel( bl );
  1165. #if PACKETVER >= 20080102
  1166. p.font = (sd) ? sd->status.font : 0;
  1167. #endif
  1168. #if PACKETVER >= 20120221
  1169. 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 ) ) ){
  1170. p.maxHP = status_get_max_hp( bl );
  1171. p.HP = status_get_hp( bl );
  1172. }else{
  1173. p.maxHP = -1;
  1174. p.HP = -1;
  1175. }
  1176. if( bl->type == BL_MOB ){
  1177. p.isBoss = ( (mob_data*)bl )->get_bosstype();
  1178. }else if( bl->type == BL_PET ){
  1179. p.isBoss = ( (pet_data*)bl )->db->get_bosstype();
  1180. }else{
  1181. p.isBoss = BOSSTYPE_NONE;
  1182. }
  1183. #endif
  1184. #if PACKETVER >= 20150513
  1185. p.body = vd->body_style;
  1186. #endif
  1187. /* Might be earlier, this is when the named item bug began */
  1188. #if PACKETVER >= 20131223
  1189. safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
  1190. #endif
  1191. if( disguised( bl ) ){
  1192. nullpo_retv( sd );
  1193. if( sd->status.class_ != sd->disguise ){
  1194. clif_send( &p, sizeof( p ), bl, target );
  1195. }
  1196. #if PACKETVER >= 20091103
  1197. p.objecttype = pcdb_checkid( status_get_viewdata(bl)->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1198. #if PACKETVER >= 20131223
  1199. p.AID = disguised_bl_id( bl->id );
  1200. #else
  1201. p.GID = disguised_bl_id( bl->id );
  1202. #endif
  1203. #else
  1204. p.GID = disguised_bl_id( bl->id );
  1205. #endif
  1206. clif_send( &p, sizeof( p ), bl, SELF );
  1207. }else{
  1208. clif_send( &p, sizeof( p ), bl, target );
  1209. }
  1210. }
  1211. /*==========================================
  1212. * Prepares 'unit walking' packet
  1213. *------------------------------------------*/
  1214. static void clif_set_unit_walking( struct block_list& bl, map_session_data* tsd, struct unit_data& ud, enum send_target target ){
  1215. struct packet_unit_walking p;
  1216. p.PacketType = unit_walkingType;
  1217. #if PACKETVER >= 20091103
  1218. p.PacketLength = sizeof(p);
  1219. #endif
  1220. #if PACKETVER >= 20071106
  1221. p.objecttype = clif_bl_type( &bl, true );
  1222. #endif
  1223. map_session_data* sd = BL_CAST(BL_PC, &bl);
  1224. #if PACKETVER >= 20131223
  1225. p.AID = bl.id;
  1226. p.GID = (sd) ? sd->status.char_id : 0; // CCODE
  1227. #else
  1228. p.GID = bl.id;
  1229. #endif
  1230. p.speed = status_get_speed( &bl );
  1231. status_change* sc = status_get_sc( &bl );
  1232. p.bodyState = (sc) ? sc->opt1 : 0;
  1233. p.healthState = (sc) ? sc->opt2 : 0;
  1234. p.effectState = (sc) ? sc->option : 0;
  1235. struct view_data* vd = status_get_viewdata( &bl );
  1236. p.job = vd->class_;
  1237. p.head = vd->hair_style;
  1238. p.weapon = vd->weapon;
  1239. p.accessory = vd->head_bottom;
  1240. p.moveStartTime = client_tick(gettick());
  1241. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  1242. p.shield = vd->shield;
  1243. #endif
  1244. p.accessory2 = vd->head_top;
  1245. p.accessory3 = vd->head_mid;
  1246. p.headpalette = vd->hair_color;
  1247. p.bodypalette = vd->cloth_color;
  1248. p.headDir = (sd) ? sd->head_dir : 0;
  1249. #if PACKETVER >= 20101124
  1250. p.robe = vd->robe;
  1251. #endif
  1252. p.GUID = status_get_guild_id( &bl );
  1253. p.GEmblemVer = status_get_emblem_id( &bl );
  1254. p.honor = (sd) ? sd->status.manner : 0;
  1255. p.virtue = (sc) ? sc->opt3 : 0;
  1256. p.isPKModeON = (sd && sd->status.karma) ? 1 : 0;
  1257. p.sex = vd->sex;
  1258. WBUFPOS2( &p.MoveData[0], 0, bl.x, bl.y, ud.to_x, ud.to_y, 8, 8 );
  1259. p.xSize = p.ySize = (sd) ? 5 : 0;
  1260. p.clevel = clif_setlevel( &bl );
  1261. #if PACKETVER >= 20080102
  1262. p.font = (sd) ? sd->status.font : 0;
  1263. #endif
  1264. #if PACKETVER >= 20120221
  1265. 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 ) ) ){
  1266. p.maxHP = status_get_max_hp( &bl );
  1267. p.HP = status_get_hp( &bl );
  1268. } else {
  1269. p.maxHP = -1;
  1270. p.HP = -1;
  1271. }
  1272. if( bl.type == BL_MOB ){
  1273. p.isBoss = reinterpret_cast<mob_data*>( &bl )->get_bosstype();
  1274. }else if( bl.type == BL_PET ){
  1275. p.isBoss = reinterpret_cast<pet_data*>( &bl )->db->get_bosstype();
  1276. }else{
  1277. p.isBoss = BOSSTYPE_NONE;
  1278. }
  1279. #endif
  1280. #if PACKETVER >= 20150513
  1281. p.body = vd->body_style;
  1282. #endif
  1283. /* Might be earlier, this is when the named item bug began */
  1284. #if PACKETVER >= 20131223
  1285. safestrncpy(p.name, status_get_name( &bl ), NAME_LENGTH);
  1286. #endif
  1287. clif_send( &p, sizeof(p), tsd ? &tsd->bl : &bl, target );
  1288. // if disguised, send the info to self
  1289. if( disguised( &bl ) ){
  1290. #if PACKETVER >= 20091103
  1291. p.objecttype = pcdb_checkid( status_get_viewdata( &bl )->class_ ) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1292. #if PACKETVER >= 20131223
  1293. p.AID = disguised_bl_id( bl.id );
  1294. #else
  1295. p.GID = disguised_bl_id( bl.id );
  1296. #endif
  1297. #else
  1298. p.GID = disguised_bl_id( bl.id );
  1299. #endif
  1300. clif_send(&p, sizeof(p), &bl, SELF);
  1301. }
  1302. }
  1303. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1304. /// 01b0 <id>.L <type>.B <value>.L
  1305. /// type:
  1306. /// unused
  1307. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, map_session_data *sd)
  1308. {
  1309. nullpo_retv(bl);
  1310. if(!pcdb_checkid(class_))
  1311. {// player classes yield missing sprites
  1312. unsigned char buf[16];
  1313. WBUFW(buf,0)=0x1b0;
  1314. WBUFL(buf,2)=bl->id;
  1315. WBUFB(buf,6)=type;
  1316. WBUFL(buf,7)=class_;
  1317. clif_send(buf,packet_len(0x1b0),(sd == nullptr ? bl : &(sd->bl)),target);
  1318. }
  1319. }
  1320. void clif_servantball( map_session_data& sd, struct block_list* target, enum send_target send_target ){
  1321. struct 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. struct 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. int 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. int 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 (vd->head_bottom)
  1525. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1526. break;
  1527. }
  1528. return 0;
  1529. }
  1530. /// Sends information about owned homunculus to the client . [orn]
  1531. /// 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)
  1532. /// 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)
  1533. void clif_hominfo( map_session_data *sd, struct homun_data *hd, int flag ){
  1534. #if PACKETVER_MAIN_NUM >= 20101005 || PACKETVER_RE_NUM >= 20080827 || defined(PACKETVER_ZERO)
  1535. nullpo_retv( sd );
  1536. nullpo_retv( hd );
  1537. struct status_data *status = &hd->battle_status;
  1538. struct PACKET_ZC_PROPERTY_HOMUN p;
  1539. p.packetType = HEADER_ZC_PROPERTY_HOMUN;
  1540. safestrncpy( p.name, hd->homunculus.name, sizeof( p.name ) );
  1541. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1542. 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 );
  1543. p.level = hd->homunculus.level;
  1544. p.hunger = hd->homunculus.hunger;
  1545. p.intimacy = hd->homunculus.intimacy / 100;
  1546. #if !(PACKETVER_MAIN_NUM >= 20190619 || PACKETVER_RE_NUM >= 20190605 || PACKETVER_ZERO_NUM >= 20190626)
  1547. p.itemId = 0; // equip id
  1548. #endif
  1549. p.atk2 = cap_value( status->rhw.atk2 + status->batk, 0, INT16_MAX );
  1550. p.matk = i16min( status->matk_max, INT16_MAX ); //FIXME capping to INT16 here is too late
  1551. p.hit = status->hit;
  1552. if( battle_config.hom_setting&HOMSET_DISPLAY_LUK ){
  1553. p.crit = status->luk / 3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1554. }else{
  1555. p.crit = status->cri / 10;
  1556. }
  1557. #ifdef RENEWAL
  1558. p.def = status->def + status->def2;
  1559. p.mdef = status->mdef + status->mdef2;
  1560. #else
  1561. p.def = status->def + status->vit;
  1562. p.mdef = status->mdef;
  1563. #endif
  1564. p.flee = status->flee;
  1565. p.amotion = (flag) ? 0 : status->amotion;
  1566. #if PACKETVER >= 20141016
  1567. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1568. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1569. if( status->max_hp > ( INT32_MAX / 100 ) ){
  1570. p.hp = status->hp / ( status->max_hp / 100 );
  1571. p.maxHp = 100;
  1572. }else{
  1573. p.hp = status->hp;
  1574. p.maxHp = status->max_hp;
  1575. }
  1576. #else
  1577. if( status->max_hp > INT16_MAX ){
  1578. p.hp = status->hp / ( status->max_hp / 100 );
  1579. p.maxHp = 100;
  1580. }else{
  1581. p.hp = status->hp;
  1582. p.maxHp = status->max_hp;
  1583. }
  1584. #endif
  1585. if( status->max_sp > INT16_MAX ){
  1586. p.sp = status->sp / ( status->max_sp / 100 );
  1587. p.maxSp = 100;
  1588. }else{
  1589. p.sp = status->sp;
  1590. p.maxSp = status->max_sp;
  1591. }
  1592. #if PACKETVER_MAIN_NUM >= 20210303 || PACKETVER_RE_NUM >= 20211103
  1593. p.exp = hd->homunculus.exp;
  1594. p.expNext = hd->exp_next;
  1595. #else
  1596. p.exp = (uint32)hd->homunculus.exp;
  1597. p.expNext = (uint32)hd->exp_next;
  1598. #endif
  1599. switch( hom_class2type( hd->homunculus.class_ ) ){
  1600. case HT_REG:
  1601. case HT_EVO:
  1602. if( hd->homunculus.level >= battle_config.hom_max_level ){
  1603. p.expNext = 0;
  1604. }
  1605. break;
  1606. case HT_S:
  1607. if( hd->homunculus.level >= battle_config.hom_S_max_level ){
  1608. p.expNext = 0;
  1609. }
  1610. break;
  1611. }
  1612. p.skillPoints = hd->homunculus.skillpts;
  1613. p.range = status_get_range( &hd->bl );
  1614. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  1615. #endif
  1616. }
  1617. /// Notification about a change in homunuculus' state.
  1618. /// 0230 <type>.B <state>.B <id>.L <data>.L (ZC_CHANGESTATE_MER)
  1619. /// type:
  1620. /// unused
  1621. /// state:
  1622. /// 0 = pre-init
  1623. /// 1 = intimacy
  1624. /// 2 = hunger
  1625. /// 3 = accessory?
  1626. /// ? = ignored
  1627. void clif_send_homdata( homun_data& hd, e_hom_state2 state ){
  1628. #if PACKETVER >= 20050523
  1629. if( hd.master == nullptr ){
  1630. return;
  1631. }
  1632. uint32 param;
  1633. switch( state ){
  1634. case SP_ACK:
  1635. param = 0;
  1636. break;
  1637. case SP_INTIMATE:
  1638. // TODO: Why is something like this here? [Lemongrass]
  1639. if( hd.homunculus.class_ == hd.homunculusDB->evo_class && hom_intimacy_intimacy2grade( hd.homunculus.intimacy ) >= HOMGRADE_LOYAL ){
  1640. hom_calc_skilltree( &hd );
  1641. }
  1642. param = hd.homunculus.intimacy / 100;
  1643. break;
  1644. case SP_HUNGRY:
  1645. param = hd.homunculus.hunger;
  1646. break;
  1647. default:
  1648. return;
  1649. }
  1650. PACKET_ZC_CHANGESTATE_MER packet{};
  1651. packet.packetType = HEADER_ZC_CHANGESTATE_MER;
  1652. packet.type = 0;
  1653. packet.state = state;
  1654. packet.gid = hd.bl.id;
  1655. packet.data = param;
  1656. clif_send( &packet, sizeof( packet ), &hd.master->bl, SELF );
  1657. #endif
  1658. }
  1659. void clif_homskillinfoblock( homun_data& hd ){
  1660. #if PACKETVER >= 20050530
  1661. map_session_data* sd = hd.master;
  1662. if( sd == nullptr ){
  1663. return;
  1664. }
  1665. PACKET_ZC_HOSKILLINFO_LIST* packet = reinterpret_cast<PACKET_ZC_HOSKILLINFO_LIST*>(packet_buffer);
  1666. packet->packetType = HEADER_ZC_HOSKILLINFO_LIST;
  1667. packet->packetLength = sizeof( *packet );
  1668. for(int i = 0, count = 0; i < MAX_HOMUNSKILL; i++) {
  1669. int id = hd.homunculus.hskill[i].id;
  1670. if (id != 0) {
  1671. int combo = (hd.homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1672. short idx = hom_skill_get_index(id);
  1673. if (idx == -1)
  1674. continue;
  1675. packet->skills[count].id = id;
  1676. packet->skills[count].inf = (combo) ? INF_SELF_SKILL : skill_get_inf(id);
  1677. packet->skills[count].unknown = 0;
  1678. packet->skills[count].level = hd.homunculus.hskill[idx].lv;
  1679. packet->skills[count].sp = skill_get_sp(id,hd.homunculus.hskill[idx].lv);
  1680. packet->skills[count].range = skill_get_range2(&hd.bl,id,hd.homunculus.hskill[idx].lv,false);
  1681. safestrncpy(packet->skills[count].name, skill_get_name(id), NAME_LENGTH);
  1682. 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;
  1683. packet->packetLength += sizeof( packet->skills[0] );
  1684. count++;
  1685. }
  1686. }
  1687. clif_send( packet, packet->packetLength, &sd->bl, SELF );
  1688. #endif
  1689. }
  1690. void clif_homskillup( homun_data& hd, uint16 skill_id ){
  1691. #if PACKETVER >= 20050531
  1692. short idx = hom_skill_get_index( skill_id );
  1693. if( idx == -1 ){
  1694. return;
  1695. }
  1696. map_session_data* sd = hd.master;
  1697. if( sd == nullptr ){
  1698. return;
  1699. }
  1700. PACKET_ZC_HOSKILLINFO_UPDATE packet{};
  1701. packet.packetType = HEADER_ZC_HOSKILLINFO_UPDATE;
  1702. packet.skill_id = skill_id;
  1703. packet.Level = hd.homunculus.hskill[idx].lv;
  1704. packet.SP = skill_get_sp(skill_id,hd.homunculus.hskill[idx].lv);
  1705. packet.AttackRange = skill_get_range2(&hd.bl,skill_id,hd.homunculus.hskill[idx].lv,false);
  1706. 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;
  1707. clif_send( &packet, sizeof( packet ), &sd->bl, SELF );
  1708. #endif
  1709. }
  1710. /// Result of request to feed a homun/merc.
  1711. /// 022f <result>.B <name id>.W (ZC_FEED_MER)
  1712. /// result:
  1713. /// 0 = failure
  1714. /// 1 = success
  1715. void clif_hom_food( map_session_data& sd, int32 foodid, bool success ){
  1716. PACKET_ZC_FEED_MER packet{};
  1717. packet.packetType = HEADER_ZC_FEED_MER;
  1718. packet.result = success;
  1719. packet.itemId = client_nameid( foodid );
  1720. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1721. }
  1722. /// Notifies the client, that it is walking.
  1723. /// 0087 <walk start time>.L <walk data>.6B (ZC_NOTIFY_PLAYERMOVE)
  1724. void clif_walkok( map_session_data& sd ){
  1725. PACKET_ZC_NOTIFY_PLAYERMOVE packet{};
  1726. packet.packetType = HEADER_ZC_NOTIFY_PLAYERMOVE;
  1727. packet.moveStartTime = client_tick(gettick());
  1728. WBUFPOS2(packet.moveData, 0, sd.bl.x, sd.bl.y, sd.ud.to_x, sd.ud.to_y, 8, 8);
  1729. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1730. }
  1731. /// Notifies clients in an area, that an other visible object is walking.
  1732. /// Note: unit must not be self
  1733. void clif_move( struct unit_data& ud )
  1734. {
  1735. struct block_list* bl = ud.bl;
  1736. struct view_data* vd = status_get_viewdata(bl);
  1737. if (bl == nullptr || vd == nullptr)
  1738. return;
  1739. // This performance check is needed to keep GM-hidden objects from being notified to bots.
  1740. if (vd->class_ == JT_INVISIBLE)
  1741. return;
  1742. // Hide NPC from Maya Purple card
  1743. if (clif_npc_mayapurple(bl))
  1744. return;
  1745. status_change* sc = nullptr;
  1746. if ((sc = status_get_sc(bl)) && sc->option & (OPTION_HIDE | OPTION_CLOAK | OPTION_INVISIBLE | OPTION_CHASEWALK))
  1747. clif_ally_only = true;
  1748. clif_set_unit_walking( *bl, nullptr, ud, AREA_WOS );
  1749. if (vd->cloth_color)
  1750. clif_refreshlook(bl, bl->id, LOOK_CLOTHES_COLOR, vd->cloth_color, AREA_WOS);
  1751. if (vd->body_style)
  1752. clif_refreshlook(bl, bl->id, LOOK_BODY2, vd->body_style, AREA_WOS);
  1753. switch (bl->type) {
  1754. case BL_PC:
  1755. {
  1756. map_session_data* sd = reinterpret_cast<map_session_data*>( bl );
  1757. if (sd->state.size == SZ_BIG) // tiny/big players [Valaris]
  1758. clif_specialeffect(&sd->bl, EF_GIANTBODY2, AREA);
  1759. else if (sd->state.size == SZ_MEDIUM)
  1760. clif_specialeffect(&sd->bl, EF_BABYBODY2, AREA);
  1761. if (sd->status.robe)
  1762. clif_refreshlook(bl, bl->id, LOOK_ROBE, sd->status.robe, AREA);
  1763. }
  1764. break;
  1765. case BL_MOB:
  1766. {
  1767. mob_data* md = reinterpret_cast<mob_data*>( bl );
  1768. if (md->special_state.size == SZ_BIG) // tiny/big mobs [Valaris]
  1769. clif_specialeffect(&md->bl, EF_GIANTBODY2, AREA);
  1770. else if (md->special_state.size == SZ_MEDIUM)
  1771. clif_specialeffect(&md->bl, EF_BABYBODY2, AREA);
  1772. }
  1773. break;
  1774. case BL_PET:
  1775. if (vd->head_bottom) // needed to display pet equip properly
  1776. clif_pet_equip_area(BL_CAST(BL_PET, bl));
  1777. break;
  1778. }
  1779. clif_ally_only = false;
  1780. }
  1781. /*==========================================
  1782. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1783. *------------------------------------------*/
  1784. static TIMER_FUNC(clif_delayquit){
  1785. map_session_data *sd = nullptr;
  1786. //Remove player from map server
  1787. if ((sd = map_id2sd(id)) != nullptr && sd->fd == 0) //Should be a disconnected player.
  1788. map_quit(sd);
  1789. return 0;
  1790. }
  1791. /*==========================================
  1792. *
  1793. *------------------------------------------*/
  1794. void clif_quitsave(int fd,map_session_data *sd) {
  1795. if (!battle_config.prevent_logout ||
  1796. sd->canlog_tick == 0 ||
  1797. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1798. map_quit(sd);
  1799. else if (session_isValid(sd->fd)) {
  1800. //Disassociate session from player (session is deleted after this function was called)
  1801. //And set a timer to make him quit later.
  1802. session[sd->fd]->session_data = nullptr;
  1803. sd->fd = 0;
  1804. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1805. }
  1806. }
  1807. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1808. /// 0091 <map name>.16B <x>.W <y>.W
  1809. void clif_changemap( map_session_data& sd, short m, uint16 x, uint16 y ){
  1810. PACKET_ZC_NPCACK_MAPMOVE packet{};
  1811. packet.packetType = HEADER_ZC_NPCACK_MAPMOVE;
  1812. mapindex_getmapname_ext(map_mapid2mapname(m), packet.mapName);
  1813. packet.xPos = x;
  1814. packet.yPos = y;
  1815. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1816. }
  1817. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1818. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1819. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE_DOMAIN)
  1820. void clif_changemapserver( map_session_data& sd, const char* map, uint16 x, uint16 y, uint32 ip, uint16 port ){
  1821. PACKET_ZC_NPCACK_SERVERMOVE packet{};
  1822. packet.packetType = HEADER_ZC_NPCACK_SERVERMOVE;
  1823. mapindex_getmapname_ext(map, packet.mapName);
  1824. packet.xPos = x;
  1825. packet.yPos = y;
  1826. packet.ip = htonl(ip);
  1827. packet.port = ntows(htons(port)); // [!] LE byte order here [!]
  1828. #if PACKETVER >= 20170315
  1829. safestrncpy( packet.domain, "", sizeof( packet.domain ) );
  1830. #endif
  1831. #ifdef DEBUG
  1832. 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 );
  1833. #endif
  1834. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1835. }
  1836. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1837. /// This function combines both calls and allows to simplify the calling code
  1838. void clif_blown(struct block_list *bl)
  1839. {
  1840. clif_slide(bl, bl->x, bl->y);
  1841. clif_fixpos( *bl );
  1842. }
  1843. /// Visually moves(slides) a character to x,y. If the target cell
  1844. /// isn't walkable, the char doesn't move at all. If the char is
  1845. /// sitting it will stand up.
  1846. /// 0088 <id>.L <x>.W <y>.W (ZC_STOPMOVE)
  1847. void clif_fixpos( block_list& bl ){
  1848. PACKET_ZC_STOPMOVE packet = {};
  1849. packet.packetType = HEADER_ZC_STOPMOVE;
  1850. packet.AID = bl.id;
  1851. packet.xPos = bl.x;
  1852. packet.yPos = bl.y;
  1853. clif_send( &packet, sizeof( packet ), &bl, AREA);
  1854. if( disguised( &bl ) ){
  1855. packet.AID = disguised_bl_id( bl.id );
  1856. clif_send( &packet, sizeof( packet ), &bl, SELF );
  1857. }
  1858. }
  1859. /// Displays the buy/sell dialog of an NPC shop.
  1860. /// 00c4 <shop id>.L (ZC_SELECT_DEALTYPE)
  1861. void clif_npcbuysell( map_session_data& sd, npc_data& nd ){
  1862. PACKET_ZC_SELECT_DEALTYPE packet{};
  1863. packet.packetType = HEADER_ZC_SELECT_DEALTYPE;
  1864. packet.npcId = nd.bl.id;
  1865. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  1866. }
  1867. /// Presents list of items, that can be bought in an NPC shop.
  1868. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }* (ZC_PC_PURCHASE_ITEMLIST)
  1869. void clif_buylist( map_session_data& sd, npc_data& nd ){
  1870. PACKET_ZC_PC_PURCHASE_ITEMLIST* p = reinterpret_cast<PACKET_ZC_PC_PURCHASE_ITEMLIST*>( packet_buffer );
  1871. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST;
  1872. p->packetLength = sizeof( *p );
  1873. for( int i = 0, count = 0, discount = npc_shop_discount( &nd ); i < nd.u.shop.count; i++ ){
  1874. int val = nd.u.shop.shop_item[i].value;
  1875. p->items[count].price = val;
  1876. p->items[count].discountPrice = ( discount ) ? pc_modifybuyvalue( &sd, val ) : val;
  1877. p->items[count].itemType = itemtype( nd.u.shop.shop_item[i].nameid );
  1878. p->items[count].itemId = client_nameid( nd.u.shop.shop_item[i].nameid );
  1879. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1880. std::shared_ptr<item_data> id = item_db.find(nd.u.shop.shop_item[i].nameid);
  1881. p->items[count].viewSprite = id->look;
  1882. p->items[count].location = pc_equippoint_sub( &sd, id.get() );
  1883. #endif
  1884. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  1885. count++;
  1886. }
  1887. clif_send( p, p->packetLength, &sd.bl, SELF );
  1888. }
  1889. /// Presents list of items, that can be sold to an NPC shop.
  1890. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }* (ZC_PC_SELL_ITEMLIST)
  1891. void clif_selllist( map_session_data& sd){
  1892. if( !sd.npc_shopid ){
  1893. return;
  1894. }
  1895. npc_data* nd = map_id2nd( sd.npc_shopid );
  1896. if( nd == nullptr ){
  1897. return;
  1898. }
  1899. PACKET_ZC_PC_SELL_ITEMLIST *packet = reinterpret_cast<PACKET_ZC_PC_SELL_ITEMLIST*>(packet_buffer);
  1900. packet->packetType = HEADER_ZC_PC_SELL_ITEMLIST;
  1901. packet->packetLength = sizeof( *packet );
  1902. for( int i = 0, c = 0; i < MAX_INVENTORY; i++ ){
  1903. if( sd.inventory.u.items_inventory[i].nameid <= 0 ){
  1904. continue;
  1905. }
  1906. if( sd.inventory_data[i] == nullptr ){
  1907. continue;
  1908. }
  1909. if( !pc_can_sell_item( &sd, &sd.inventory.u.items_inventory[i], nd->subtype ) ){
  1910. continue;
  1911. }
  1912. int price;
  1913. if( battle_config.rental_item_novalue && sd.inventory.u.items_inventory[i].expire_time ){
  1914. price = 0;
  1915. }else{
  1916. price = sd.inventory_data[i]->value_sell;
  1917. if( price < 0 ){
  1918. continue;
  1919. }
  1920. }
  1921. packet->items[c].index = client_index(i);
  1922. packet->items[c].price = price;
  1923. packet->items[c].overcharge = pc_modifysellvalue( &sd, price );
  1924. packet->packetLength += sizeof( packet->items[0] );
  1925. c++;
  1926. }
  1927. clif_send( packet, packet->packetLength, &sd.bl, SELF );
  1928. }
  1929. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1930. /// 09d4
  1931. void clif_parse_NPCShopClosed(int fd, map_session_data *sd) {
  1932. // TODO: State tracking?
  1933. sd->npc_shopid = 0;
  1934. }
  1935. /**
  1936. * Presents list of items, that can be sold to a Market shop.
  1937. * @author: Ind and Yommy
  1938. **/
  1939. /// 0x9d5 <packet len>.W { <name id>.W <type>.B <price>.L <qty>.L <weight>.W }* (ZC_NPC_MARKET_OPEN)
  1940. void clif_npc_market_open(map_session_data *sd, struct npc_data *nd) {
  1941. #if PACKETVER >= 20131223
  1942. nullpo_retv( sd );
  1943. nullpo_retv( nd );
  1944. if( sd->state.trading ){
  1945. return;
  1946. }
  1947. int fd = sd->fd;
  1948. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + nd->u.shop.count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  1949. struct PACKET_ZC_NPC_MARKET_OPEN *p = (struct PACKET_ZC_NPC_MARKET_OPEN *)WFIFOP( fd, 0 );
  1950. p->packetType = HEADER_ZC_NPC_MARKET_OPEN;
  1951. int count = 0;
  1952. for( int i = 0; i < nd->u.shop.count; i++ ){
  1953. struct npc_item_list *item = &nd->u.shop.shop_item[i];
  1954. if( !item->nameid ){
  1955. continue;
  1956. }
  1957. std::shared_ptr<item_data> id = item_db.find(item->nameid);
  1958. if( !id ){
  1959. continue;
  1960. }
  1961. p->list[count].nameid = client_nameid( item->nameid );
  1962. p->list[count].type = itemtype( item->nameid );
  1963. p->list[count].price = item->value;
  1964. p->list[count].qty = item->qty;
  1965. p->list[count].weight = id->weight;
  1966. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  1967. p->list[count].location = pc_equippoint_sub( sd, id.get() );
  1968. #endif
  1969. count++;
  1970. }
  1971. p->packetLength = static_cast<decltype(p->packetLength)>( sizeof( struct PACKET_ZC_NPC_MARKET_OPEN ) + count * sizeof( struct PACKET_ZC_NPC_MARKET_OPEN_sub ) );
  1972. WFIFOSET( fd, p->packetLength );
  1973. sd->state.trading = 1;
  1974. #endif
  1975. }
  1976. /// Closes the Market shop window.
  1977. void clif_parse_NPCMarketClosed(int fd, map_session_data *sd) {
  1978. nullpo_retv(sd);
  1979. sd->npc_shopid = 0;
  1980. sd->state.trading = 0;
  1981. }
  1982. /// Purchase item from Market shop.
  1983. /// 0x9d7 <packet len>.W <count>.B { <name id>.W <qty>.W <price>.L }* (ZC_NPC_MARKET_PURCHASE_RESULT)
  1984. void clif_npc_market_purchase_ack( map_session_data& sd, e_purchase_result res, std::vector<s_npc_buy_list>& list ){
  1985. #if PACKETVER >= 20131223
  1986. struct npc_data *nd = map_id2nd( sd.npc_shopid );
  1987. if( nd == nullptr ){
  1988. return;
  1989. }
  1990. PACKET_ZC_NPC_MARKET_PURCHASE_RESULT* p = reinterpret_cast<PACKET_ZC_NPC_MARKET_PURCHASE_RESULT*>( packet_buffer );
  1991. p->PacketType = HEADER_ZC_NPC_MARKET_PURCHASE_RESULT;
  1992. p->PacketLength = sizeof( struct PACKET_ZC_NPC_MARKET_PURCHASE_RESULT );
  1993. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190814
  1994. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 0 : -1 );
  1995. #else
  1996. p->result = ( res == e_purchase_result::PURCHASE_SUCCEED ? 1 : 0 );
  1997. #endif
  1998. if( res == e_purchase_result::PURCHASE_SUCCEED ){
  1999. for( int i = 0, j, count = 0; i < list.size(); i++ ){
  2000. ARR_FIND( 0, nd->u.shop.count, j, list[i].nameid == nd->u.shop.shop_item[j].nameid );
  2001. // Not found
  2002. if( j == nd->u.shop.count ){
  2003. continue;
  2004. }
  2005. p->list[count].ITID = client_nameid( list[i].nameid );
  2006. p->list[count].qty = list[i].qty;
  2007. p->list[count].price = nd->u.shop.shop_item[j].value;
  2008. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( p->list[0] ) );
  2009. count++;
  2010. }
  2011. }
  2012. clif_send( p, p->PacketLength, &sd.bl, SELF );
  2013. #endif
  2014. }
  2015. /// Purchase item from Market shop.
  2016. /// 0x9d6 <len>.W { <name id>.W <qty>.L } (CZ_NPC_MARKET_PURCHASE)
  2017. void clif_parse_NPCMarketPurchase(int fd, map_session_data *sd) {
  2018. #if PACKETVER >= 20131223
  2019. nullpo_retv( sd );
  2020. if( !sd->npc_shopid ){
  2021. return;
  2022. }
  2023. const struct PACKET_CZ_NPC_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  2024. int count = ( p->PacketLength - sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_MARKET_PURCHASE_sub );
  2025. std::vector<s_npc_buy_list> items;
  2026. items.reserve( count );
  2027. for( int i = 0; i < count; i++ ){
  2028. s_npc_buy_list item = {};
  2029. item.nameid = p->list[i].ITID;
  2030. item.qty = p->list[i].qty;
  2031. items.push_back( item );
  2032. }
  2033. e_purchase_result res = npc_buylist( sd, items );
  2034. clif_npc_market_purchase_ack( *sd, res, items );
  2035. #endif
  2036. }
  2037. /// Displays an NPC dialog message.
  2038. /// 00b4 <packet len>.W <npc id>.L <message>.?B (ZC_SAY_DIALOG)
  2039. /// Client behavior (dialog window):
  2040. /// - disable mouse targeting
  2041. /// - open the dialog window
  2042. /// - set npcid of dialog window (0 by default)
  2043. /// - if set to clear on next mes, clear contents
  2044. /// - append this text
  2045. void clif_scriptmes( map_session_data& sd, uint32 npcid, const char *mes ){
  2046. PACKET_ZC_SAY_DIALOG* p = reinterpret_cast<PACKET_ZC_SAY_DIALOG*>( packet_buffer );
  2047. int16 length = (int16)( strlen( mes ) + 1 );
  2048. p->PacketType = HEADER_ZC_SAY_DIALOG;
  2049. p->PacketLength = sizeof( *p ) + length;
  2050. p->NpcID = npcid;
  2051. safestrncpy( p->message, mes, length );
  2052. clif_send( p, p->PacketLength, &sd.bl, SELF );
  2053. }
  2054. /// Adds a 'next' button to an NPC dialog.
  2055. /// 00b5 <npc id>.L (ZC_WAIT_DIALOG)
  2056. /// Client behavior (dialog window):
  2057. /// - disable mouse targeting
  2058. /// - open the dialog window
  2059. /// - add 'next' button
  2060. /// When 'next' is pressed:
  2061. /// - 00B9 <npcid of dialog window>.L
  2062. /// - set to clear on next mes
  2063. /// - remove 'next' button
  2064. void clif_scriptnext( map_session_data& sd, uint32 npcid ){
  2065. struct PACKET_ZC_WAIT_DIALOG p = {};
  2066. p.PacketType = HEADER_ZC_WAIT_DIALOG;
  2067. p.NpcID = npcid;
  2068. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2069. }
  2070. /// Adds a 'close' button to an NPC dialog.
  2071. /// 00b6 <npc id>.L (ZC_CLOSE_DIALOG)
  2072. /// Client behavior:
  2073. /// - if dialog window is open:
  2074. /// - remove 'next' button
  2075. /// - add 'close' button
  2076. /// - else:
  2077. /// - enable mouse targeting
  2078. /// - close the dialog window
  2079. /// - close the menu window
  2080. /// When 'close' is pressed:
  2081. /// - enable mouse targeting
  2082. /// - close the dialog window
  2083. /// - close the menu window
  2084. /// - 0146 <npcid of dialog window>.L
  2085. void clif_scriptclose( map_session_data& sd, uint32 npcid ){
  2086. PACKET_ZC_CLOSE_DIALOG packet{};
  2087. packet.packetType = HEADER_ZC_CLOSE_DIALOG;
  2088. packet.npcId = npcid;
  2089. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2090. }
  2091. /**
  2092. * Close script when player is idle
  2093. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  2094. * @author [Ind/Hercules]
  2095. * @param sd : player pointer
  2096. * @param npcid : npc gid to close
  2097. */
  2098. void clif_scriptclear( map_session_data& sd, int npcid ){
  2099. struct PACKET_ZC_CLEAR_DIALOG p = {};
  2100. p.packetType = HEADER_ZC_CLEAR_DIALOG;
  2101. p.GID = npcid;
  2102. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2103. }
  2104. void clif_sendfakenpc( map_session_data& sd, uint32 npcid ){
  2105. sd.state.using_fake_npc = 1;
  2106. // Code below is a copy of clif_set_unit_idle
  2107. struct packet_idle_unit p;
  2108. p.PacketType = idle_unitType;
  2109. #if PACKETVER >= 20091103
  2110. p.PacketLength = sizeof(p);
  2111. p.objecttype = 0x1; // NPC_TYPE
  2112. #endif
  2113. #if PACKETVER >= 20131223
  2114. p.AID = npcid;
  2115. p.GID = 0;
  2116. #else
  2117. p.GID = npcid;
  2118. #endif
  2119. p.speed = 0;
  2120. p.bodyState = 0;
  2121. p.healthState = 0;
  2122. p.effectState = 0;
  2123. p.job = JT_HIDDEN_NPC;
  2124. p.head = 0;
  2125. p.weapon = 0;
  2126. #if PACKETVER < 7 || PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  2127. p.shield = 0;
  2128. #endif
  2129. p.accessory = 0;
  2130. p.accessory2 = 0;
  2131. p.accessory3 = 0;
  2132. p.headpalette = 0;
  2133. p.bodypalette = 0;
  2134. p.headDir = 0;
  2135. #if PACKETVER >= 20101124
  2136. p.robe = 0;
  2137. #endif
  2138. p.GUID = 0;
  2139. p.GEmblemVer = 0;
  2140. p.honor = 0;
  2141. p.virtue = 0;
  2142. p.isPKModeON = 0;
  2143. p.sex = SEX_FEMALE;
  2144. WBUFPOS( &p.PosDir[0], 0, sd.bl.x, sd.bl.y, sd.ud.dir );
  2145. p.xSize = p.ySize = 5;
  2146. p.state = 0;
  2147. p.clevel = 0;
  2148. #if PACKETVER >= 20080102
  2149. p.font = 0;
  2150. #endif
  2151. #if PACKETVER >= 20120221
  2152. p.maxHP = -1;
  2153. p.HP = -1;
  2154. #endif
  2155. #if PACKETVER >= 20150513
  2156. p.body = 0;
  2157. #endif
  2158. /* Might be earlier, this is when the named item bug began */
  2159. #if PACKETVER >= 20131223
  2160. safestrncpy( p.name, "", NAME_LENGTH);
  2161. #endif
  2162. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  2163. }
  2164. /// Displays an NPC dialog menu.
  2165. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B (ZC_MENU_LIST)
  2166. /// Client behavior:
  2167. /// - disable mouse targeting
  2168. /// - close the menu window
  2169. /// - open the menu window
  2170. /// - add options to the menu (separated in the text by ":")
  2171. /// - set npcid of menu window
  2172. /// - if dialog window is open:
  2173. /// - remove 'next' button
  2174. /// When 'ok' is pressed:
  2175. /// - 00B8 <npcid of menu window>.L <selected option>.B
  2176. /// - close the menu window
  2177. /// When 'cancel' is pressed:
  2178. /// - 00B8 <npcid of menu window>.L <-1>.B
  2179. /// - enable mouse targeting
  2180. /// - close a bunch of windows...
  2181. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  2182. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  2183. /// TODO investigate behavior of other windows [FlavioJS]
  2184. void clif_scriptmenu( map_session_data& sd, uint32 npcid, const char* mes ){
  2185. struct block_list *bl = nullptr;
  2186. if (!sd.state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd.bl.m ||
  2187. bl->x<sd.bl.x-AREA_SIZE-1 || bl->x>sd.bl.x+AREA_SIZE+1 ||
  2188. bl->y<sd.bl.y-AREA_SIZE-1 || bl->y>sd.bl.y+AREA_SIZE+1))))
  2189. clif_sendfakenpc( sd, npcid );
  2190. // String length + 1 byte for zero termination
  2191. size_t mes_length = strlen( mes ) + 1;
  2192. PACKET_ZC_MENU_LIST* packet = reinterpret_cast<PACKET_ZC_MENU_LIST*>( packet_buffer );
  2193. packet->packetType = HEADER_ZC_MENU_LIST;
  2194. packet->packetLength = sizeof( PACKET_ZC_MENU_LIST );
  2195. packet->npcId = npcid;
  2196. safestrncpy( packet->menu, mes, mes_length );
  2197. packet->packetLength += static_cast<decltype(packet->packetLength)>( mes_length );
  2198. clif_send( packet, packet->packetLength, &sd.bl, SELF );
  2199. }
  2200. /// Displays an NPC dialog input box for numbers.
  2201. /// 0142 <npc id>.L (ZC_OPEN_EDITDLG)
  2202. /// Client behavior (inputnum window):
  2203. /// - if npcid exists in the client:
  2204. /// - open the inputnum window
  2205. /// - set npcid of inputnum window
  2206. /// When 'ok' is pressed:
  2207. /// - if inputnum window has text:
  2208. /// - if npcid exists in the client:
  2209. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2210. /// - close inputnum window
  2211. void clif_scriptinput( map_session_data& sd, uint32 npcid ){
  2212. struct block_list *bl = nullptr;
  2213. if (!sd.state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd.bl.m ||
  2214. bl->x<sd.bl.x-AREA_SIZE-1 || bl->x>sd.bl.x+AREA_SIZE+1 ||
  2215. bl->y<sd.bl.y-AREA_SIZE-1 || bl->y>sd.bl.y+AREA_SIZE+1))))
  2216. clif_sendfakenpc( sd, npcid );
  2217. PACKET_ZC_OPEN_EDITDLG packet{};
  2218. packet.packetType = HEADER_ZC_OPEN_EDITDLG;
  2219. packet.npcId = npcid;
  2220. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2221. }
  2222. /// Displays an NPC dialog input box for strings.
  2223. /// 01d4 <npc id>.L (ZC_OPEN_EDITDLGSTR)
  2224. /// Client behavior (inputstr window):
  2225. /// - if npcid is 0 or npcid exists in the client:
  2226. /// - open the inputstr window
  2227. /// - set npcid of inputstr window
  2228. /// When 'ok' is pressed:
  2229. /// - if inputstr window has text and isn't an insult(manner.txt):
  2230. /// - if npcid is 0 or npcid exists in the client:
  2231. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2232. /// - close inputstr window
  2233. void clif_scriptinputstr( map_session_data& sd, uint32 npcid ){
  2234. struct block_list *bl = nullptr;
  2235. if (!sd.state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd.bl.m ||
  2236. bl->x<sd.bl.x-AREA_SIZE-1 || bl->x>sd.bl.x+AREA_SIZE+1 ||
  2237. bl->y<sd.bl.y-AREA_SIZE-1 || bl->y>sd.bl.y+AREA_SIZE+1))))
  2238. clif_sendfakenpc( sd, npcid );
  2239. PACKET_ZC_OPEN_EDITDLGSTR packet{};
  2240. packet.packetType = HEADER_ZC_OPEN_EDITDLGSTR;
  2241. packet.npcId = npcid;
  2242. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2243. }
  2244. /// Marks a position on client's minimap.
  2245. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L (ZC_COMPASS)
  2246. /// npc id:
  2247. /// is ignored in the client
  2248. /// type:
  2249. /// 0 = display mark for 15 seconds
  2250. /// 1 = display mark until dead or teleported
  2251. /// 2 = remove mark
  2252. /// color:
  2253. /// 0x00RRGGBB
  2254. void clif_viewpoint( map_session_data& sd, uint32 npc_id, int type, uint16 x, uint16 y, int id, uint32 color ){
  2255. PACKET_ZC_COMPASS packet{};
  2256. packet.packetType = HEADER_ZC_COMPASS;
  2257. packet.npcId = npc_id;
  2258. packet.type = type;
  2259. packet.xPos = x;
  2260. packet.yPos = y;
  2261. packet.id = id;
  2262. packet.color = color;
  2263. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2264. }
  2265. /// Displays an illustration image.
  2266. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2267. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2268. /// type:
  2269. /// 0 = bottom left corner
  2270. /// 1 = bottom middle
  2271. /// 2 = bottom right corner
  2272. /// 3 = middle of screen, inside a movable window
  2273. /// 4 = middle of screen, movable with a close button, chrome-less
  2274. /// 255 = clear all displayed cutins
  2275. void clif_cutin( map_session_data& sd, const char* image, int type ){
  2276. PACKET_ZC_SHOW_IMAGE packet{};
  2277. packet.packetType = HEADER_ZC_SHOW_IMAGE;
  2278. safestrncpy(packet.image, image, sizeof(packet.image));
  2279. packet.type = type;
  2280. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2281. }
  2282. /*==========================================
  2283. * Fills in card data from the given item and into the buffer. [Skotlex]
  2284. *------------------------------------------*/
  2285. static void clif_addcards( struct EQUIPSLOTINFO* buf, struct item* item ){
  2286. nullpo_retv( buf );
  2287. // Blank data
  2288. if( item == nullptr ){
  2289. buf->card[0] = 0;
  2290. buf->card[1] = 0;
  2291. buf->card[2] = 0;
  2292. buf->card[3] = 0;
  2293. return;
  2294. }
  2295. // Pet eggs
  2296. if( item->card[0] == CARD0_PET ){
  2297. buf->card[0] = 0;
  2298. buf->card[1] = 0;
  2299. // Pet intimacy
  2300. // No idea when this was added exactly, but older clients have no problem if we send it anyway
  2301. buf->card[2] = item->card[3] >> 1;
  2302. // Pet renamed flag
  2303. buf->card[3] = item->card[3] & 1;
  2304. return;
  2305. }
  2306. // Forged/created items
  2307. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ){
  2308. buf->card[0] = item->card[0];
  2309. buf->card[1] = item->card[1];
  2310. buf->card[2] = item->card[2];
  2311. buf->card[3] = item->card[3];
  2312. return;
  2313. }
  2314. int i = 0, j;
  2315. // Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2316. if( MAX_SLOTS > 4 && ( j = itemdb_slots( item->nameid ) ) > 4 ){
  2317. i = rnd() % ( j - 3 ); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2318. }
  2319. // Normal items.
  2320. for( int k = 0; k < 4; k++, i++ ){
  2321. if( item->card[i] > 0 ){
  2322. buf->card[k] = client_nameid( item->card[i] );
  2323. }else{
  2324. buf->card[k] = 0;
  2325. }
  2326. }
  2327. }
  2328. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2329. /// A maximum of 5 random options can be supported.
  2330. static void clif_add_random_options( struct ItemOptions buf[MAX_ITEM_RDM_OPT], struct item& it ){
  2331. for( int i = 0; i < MAX_ITEM_RDM_OPT; i++ ){
  2332. if( it.option[i].id ){
  2333. buf[i].index = it.option[i].id; // OptIndex
  2334. buf[i].value = it.option[i].value; // Value
  2335. buf[i].param = it.option[i].param; // Param1
  2336. }else{
  2337. buf[i].index = 0;
  2338. buf[i].value = 0;
  2339. buf[i].param = 0;
  2340. }
  2341. }
  2342. #if MAX_ITEM_RDM_OPT < 5
  2343. for( ; i < 5; i++ ){
  2344. buf[i].index = 0; // OptIndex
  2345. buf[i].value = 0; // Value
  2346. buf[i].param = 0; // Param1
  2347. }
  2348. #endif
  2349. }
  2350. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2351. /// 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)
  2352. /// 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)
  2353. /// 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)
  2354. /// 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)
  2355. /// 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)
  2356. /// 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)
  2357. void clif_additem( map_session_data *sd, int n, int amount, unsigned char fail ){
  2358. nullpo_retv( sd );
  2359. int fd = sd->fd;
  2360. if( !session_isActive( fd ) ){
  2361. return;
  2362. }
  2363. struct PACKET_ZC_ITEM_PICKUP_ACK p;
  2364. if( fail ){
  2365. p = {};
  2366. }else{
  2367. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid == 0 || sd->inventory_data[n] == nullptr ){
  2368. return;
  2369. }
  2370. p.nameid = client_nameid( sd->inventory.u.items_inventory[n].nameid );
  2371. p.IsIdentified = sd->inventory.u.items_inventory[n].identify ? 1 : 0;
  2372. p.IsDamaged = ( sd->inventory.u.items_inventory[n].attribute ) != 0 ? 1 : 0;
  2373. p.refiningLevel =sd->inventory.u.items_inventory[n].refine;
  2374. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[n] );
  2375. p.location = pc_equippoint(sd,n);
  2376. p.type = itemtype( sd->inventory.u.items_inventory[n].nameid );
  2377. #if PACKETVER >= 20061218
  2378. p.HireExpireDate = sd->inventory.u.items_inventory[n].expire_time;
  2379. #if PACKETVER >= 20071002
  2380. /* why restrict the flag to non-stackable? because this is the only packet allows stackable to,
  2381. * show the color, and therefore it'd be inconsistent with the rest (aka it'd show yellow, you relog/refresh and boom its gone)
  2382. */
  2383. p.bindOnEquipType = sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable2( sd->inventory_data[n] ) ? 2 : sd->inventory_data[n]->flag.bindOnEquip ? 1 : 0;
  2384. #if PACKETVER >= 20150226
  2385. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[n] );
  2386. #if PACKETVER >= 20160921
  2387. p.favorite = ( sd->inventory.u.items_inventory[n].favorite != 0 ) ? 1 : 0;
  2388. p.look = sd->inventory_data[n]->look;
  2389. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2390. p.grade = sd->inventory.u.items_inventory[n].enchantgrade;
  2391. #endif
  2392. #endif
  2393. #endif
  2394. #endif
  2395. #endif
  2396. }
  2397. p.PacketType = HEADER_ZC_ITEM_PICKUP_ACK;
  2398. p.Index = client_index( n );
  2399. p.count = amount;
  2400. p.result = fail;
  2401. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  2402. }
  2403. /// Notifies the client, that an inventory item was deleted or dropped.
  2404. /// 00af <index>.W <amount>.W (ZC_ITEM_THROW_ACK)
  2405. void clif_dropitem( map_session_data& sd, int index, int amount ){
  2406. PACKET_ZC_ITEM_THROW_ACK packet{};
  2407. packet.packetType = HEADER_ZC_ITEM_THROW_ACK;
  2408. packet.index = client_index( index );
  2409. packet.count = amount;
  2410. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2411. }
  2412. /// Notifies the client, that an inventory item was deleted.
  2413. /// 07fa <delete type>.W <index>.W <amount>.W (ZC_DELETE_ITEM_FROM_BODY)
  2414. /// delete type:
  2415. /// 0 = Normal
  2416. /// 1 = Item used for a skill
  2417. /// 2 = Refine failed
  2418. /// 3 = Material changed
  2419. /// 4 = Moved to storage
  2420. /// 5 = Moved to cart
  2421. /// 6 = Item sold
  2422. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2423. void clif_delitem( map_session_data& sd, int index, int amount, short reason ){
  2424. #if PACKETVER >= 20091117
  2425. PACKET_ZC_DELETE_ITEM_FROM_BODY packet{};
  2426. packet.packetType = HEADER_ZC_DELETE_ITEM_FROM_BODY;
  2427. packet.deleteType = reason;
  2428. packet.index = client_index( index );
  2429. packet.count = amount;
  2430. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2431. #else
  2432. clif_dropitem( sd, index, amount );
  2433. #endif
  2434. }
  2435. static void clif_item_equip( short idx, struct EQUIPITEM_INFO *p, struct item *it, struct item_data *id, int eqp_pos ){
  2436. nullpo_retv( p );
  2437. nullpo_retv( it );
  2438. nullpo_retv( id );
  2439. p->index = idx;
  2440. p->ITID = client_nameid( it->nameid );
  2441. p->type = itemtype( it->nameid );
  2442. #if PACKETVER < 20120925
  2443. p->IsIdentified = it->identify ? 1 : 0;
  2444. #endif
  2445. p->location = eqp_pos;
  2446. p->WearState = it->equip;
  2447. #if PACKETVER < 20120925
  2448. p->IsDamaged = it->attribute != 0 ? 1 : 0;
  2449. #endif
  2450. p->RefiningLevel = it->refine;
  2451. clif_addcards( &p->slot, it );
  2452. #if PACKETVER >= 20071002
  2453. p->HireExpireDate = it->expire_time;
  2454. #endif
  2455. #if PACKETVER >= 20080102
  2456. p->bindOnEquipType = it->bound ? 2 : id->flag.bindOnEquip ? 1 : 0;
  2457. #endif
  2458. #if PACKETVER >= 20100629
  2459. // TODO: WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2460. p->wItemSpriteNumber = ( id->equip&EQP_VISIBLE ) ? id->look : 0;
  2461. #endif
  2462. #if PACKETVER >= 20120925
  2463. p->Flag.IsIdentified = it->identify ? 1 : 0;
  2464. p->Flag.IsDamaged = it->attribute ? 1 : 0;
  2465. p->Flag.PlaceETCTab = it->favorite ? 1 : 0;
  2466. p->Flag.SpareBits = 0;
  2467. #endif
  2468. #if PACKETVER >= 20150226
  2469. clif_add_random_options( p->option_data, *it );
  2470. // Client ingores the value anyway and recalculates it
  2471. p->option_count = 0;
  2472. #endif
  2473. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  2474. p->grade = it->enchantgrade;
  2475. #endif
  2476. }
  2477. static void clif_item_normal( short idx, struct NORMALITEM_INFO *p, struct item *i, struct item_data *id ){
  2478. nullpo_retv(p);
  2479. nullpo_retv(i);
  2480. nullpo_retv(id);
  2481. p->index = idx;
  2482. p->ITID = client_nameid( i->nameid );
  2483. p->type = itemtype( i->nameid );
  2484. #if PACKETVER < 20120925
  2485. p->IsIdentified = i->identify ? 1 : 0;
  2486. #endif
  2487. p->count = i->amount;
  2488. p->WearState = id->equip;
  2489. #if PACKETVER >= 5
  2490. clif_addcards( &p->slot, i );
  2491. #endif
  2492. #if PACKETVER >= 20080102
  2493. p->HireExpireDate = i->expire_time;
  2494. #endif
  2495. #if PACKETVER >= 20120925
  2496. p->Flag.IsIdentified = i->identify ? 1 : 0;
  2497. p->Flag.PlaceETCTab = ( i->favorite != 0 ) ? 1 : 0;
  2498. p->Flag.SpareBits = 0;
  2499. #endif
  2500. }
  2501. static void clif_inventoryStart( map_session_data *sd, e_inventory_type type, const char *name ){
  2502. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2503. nullpo_retv(sd);
  2504. nullpo_retv(name);
  2505. char buf[sizeof(struct PACKET_ZC_INVENTORY_START) + 24];
  2506. memset(buf, 0, sizeof(buf));
  2507. struct PACKET_ZC_INVENTORY_START *p = (struct PACKET_ZC_INVENTORY_START *)buf;
  2508. p->packetType = HEADER_ZC_INVENTORY_START;
  2509. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2510. p->invType = type;
  2511. #endif
  2512. #if PACKETVER_RE_NUM >= 20180919 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2513. int strLen = (int)safestrnlen(name, 24) + 1;
  2514. if (strLen > 24)
  2515. strLen = 24;
  2516. const int len = sizeof(struct PACKET_ZC_INVENTORY_START) + strLen;
  2517. p->packetLength = len;
  2518. safestrncpy(p->name, name, strLen);
  2519. #else
  2520. const int len = sizeof(struct PACKET_ZC_INVENTORY_START);
  2521. safestrncpy(p->name, name, NAME_LENGTH);
  2522. #endif
  2523. clif_send( p, len, &sd->bl, SELF );
  2524. #endif
  2525. }
  2526. static void clif_inventoryEnd( map_session_data *sd, e_inventory_type type ){
  2527. #if PACKETVER_RE_NUM >= 20180829 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2528. nullpo_retv(sd);
  2529. struct PACKET_ZC_INVENTORY_END p;
  2530. p.packetType = HEADER_ZC_INVENTORY_END;
  2531. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2532. p.invType = type;
  2533. #endif
  2534. p.flag = 0;
  2535. clif_send( &p, sizeof(p), &sd->bl, SELF );
  2536. #endif
  2537. }
  2538. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2539. void clif_inventorylist( map_session_data *sd ){
  2540. nullpo_retv( sd );
  2541. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2542. e_inventory_type type = INVTYPE_INVENTORY;
  2543. clif_inventoryStart( sd, type, "" );
  2544. #endif
  2545. static struct packet_itemlist_normal itemlist_normal;
  2546. static struct packet_itemlist_equip itemlist_equip;
  2547. int equip = 0;
  2548. int normal = 0;
  2549. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2550. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ){
  2551. continue;
  2552. }
  2553. // Non-stackable (Equippable)
  2554. if( !itemdb_isstackable2( sd->inventory_data[i] ) ){
  2555. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint( sd, i ) );
  2556. if( equip == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2557. itemlist_equip.PacketType = inventorylistequipType;
  2558. itemlist_equip.PacketLength = static_cast<decltype(itemlist_equip.PacketLength)>( ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip ) );
  2559. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2560. itemlist_equip.invType = type;
  2561. #endif
  2562. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2563. equip = 0;
  2564. }
  2565. // Stackable (Normal)
  2566. }else{
  2567. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->inventory.u.items_inventory[i], sd->inventory_data[i] );
  2568. if( normal == MAX_INVENTORY_ITEM_PACKET_NORMAL ){
  2569. itemlist_normal.PacketType = inventorylistnormalType;
  2570. itemlist_normal.PacketLength = static_cast<decltype(itemlist_normal.PacketLength)>( ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal ) );
  2571. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2572. itemlist_normal.invType = type;
  2573. #endif
  2574. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2575. normal = 0;
  2576. }
  2577. }
  2578. }
  2579. if( normal ){
  2580. itemlist_normal.PacketType = inventorylistnormalType;
  2581. itemlist_normal.PacketLength = static_cast<decltype(itemlist_normal.PacketLength)>( ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal ) );
  2582. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2583. itemlist_normal.invType = type;
  2584. #endif
  2585. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2586. }
  2587. if( sd->equip_index[EQI_AMMO] >= 0 )
  2588. clif_arrowequip( *sd );
  2589. if( equip ) {
  2590. itemlist_equip.PacketType = inventorylistequipType;
  2591. itemlist_equip.PacketLength = static_cast<decltype(itemlist_equip.PacketLength)>( ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip ) );
  2592. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2593. itemlist_equip.invType = type;
  2594. #endif
  2595. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2596. }
  2597. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2598. clif_inventoryEnd( sd, type );
  2599. #endif
  2600. /* on 20120925 onwards this is a field on clif_item_equip/normal */
  2601. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2602. for( int i = 0; i < MAX_INVENTORY; i++ ){
  2603. if( sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr )
  2604. continue;
  2605. if ( sd->inventory.u.items_inventory[i].favorite != 0 )
  2606. clif_favorite_item( *sd, i );
  2607. }
  2608. #endif
  2609. }
  2610. //Required when items break/get-repaired. Only sends equippable item list.
  2611. void clif_equiplist( map_session_data *sd ){
  2612. // TODO: implement again => only send equip part
  2613. clif_inventorylist( sd );
  2614. }
  2615. void clif_storagelist(map_session_data* sd, struct item* items, int items_length, const char *storename){
  2616. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2617. e_inventory_type type = INVTYPE_STORAGE;
  2618. clif_inventoryStart( sd, type, storename );
  2619. #endif
  2620. static struct ZC_STORE_ITEMLIST_NORMAL storage_itemlist_normal;
  2621. static struct ZC_STORE_ITEMLIST_EQUIP storage_itemlist_equip;
  2622. int equip = 0;
  2623. int normal = 0;
  2624. for( int i = 0; i < items_length; i++ ){
  2625. if( items[i].nameid == 0 ){
  2626. continue;
  2627. }
  2628. struct item_data* id = itemdb_search( items[i].nameid );
  2629. // Non-stackable (Equippable)
  2630. if( !itemdb_isstackable2( id ) ){
  2631. clif_item_equip( client_storage_index( i ), &storage_itemlist_equip.list[equip++], &items[i], id, pc_equippoint_sub( sd, id ) );
  2632. if( equip == MAX_STORAGE_ITEM_PACKET_EQUIP ){
  2633. storage_itemlist_equip.PacketType = storageListEquipType;
  2634. 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 ) );
  2635. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2636. storage_itemlist_equip.invType = type;
  2637. #elif PACKETVER >= 20120925
  2638. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2639. #endif
  2640. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2641. equip = 0;
  2642. }
  2643. // Stackable (Normal)
  2644. }else{
  2645. clif_item_normal( client_storage_index( i ), &storage_itemlist_normal.list[normal++], &items[i], id );
  2646. if( normal == MAX_STORAGE_ITEM_PACKET_NORMAL ){
  2647. storage_itemlist_normal.PacketType = storageListNormalType;
  2648. 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 ) );
  2649. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2650. storage_itemlist_normal.invType = type;
  2651. #elif PACKETVER >= 20120925
  2652. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2653. #endif
  2654. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2655. normal = 0;
  2656. }
  2657. }
  2658. }
  2659. if( normal ){
  2660. storage_itemlist_normal.PacketType = storageListNormalType;
  2661. 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 ) );
  2662. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2663. storage_itemlist_normal.invType = type;
  2664. #elif PACKETVER >= 20120925
  2665. safestrncpy( storage_itemlist_normal.name, storename, NAME_LENGTH );
  2666. #endif
  2667. clif_send( &storage_itemlist_normal, storage_itemlist_normal.PacketLength, &sd->bl, SELF );
  2668. }
  2669. if( equip ) {
  2670. storage_itemlist_equip.PacketType = storageListEquipType;
  2671. 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 ) );
  2672. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2673. storage_itemlist_equip.invType = type;
  2674. #elif PACKETVER >= 20120925
  2675. safestrncpy( storage_itemlist_equip.name, storename, NAME_LENGTH );
  2676. #endif
  2677. clif_send( &storage_itemlist_equip, storage_itemlist_equip.PacketLength, &sd->bl, SELF );
  2678. }
  2679. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2680. clif_inventoryEnd( sd, type );
  2681. #endif
  2682. }
  2683. void clif_cartlist( map_session_data *sd ){
  2684. nullpo_retv( sd );
  2685. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2686. e_inventory_type type = INVTYPE_CART;
  2687. clif_inventoryStart( sd, type, "" );
  2688. #endif
  2689. static struct packet_itemlist_normal itemlist_normal;
  2690. static struct packet_itemlist_equip itemlist_equip;
  2691. int normal = 0;
  2692. int equip = 0;
  2693. for( int i = 0; i < MAX_CART; i++ ){
  2694. if( sd->cart.u.items_cart[i].nameid == 0 ){
  2695. continue;
  2696. }
  2697. struct item_data* id = itemdb_search( sd->cart.u.items_cart[i].nameid );
  2698. // Non-stackable (Equippable)
  2699. if( !itemdb_isstackable2(id) ){
  2700. clif_item_equip( client_index( i ), &itemlist_equip.list[equip++], &sd->cart.u.items_cart[i], id, id->equip );
  2701. // Stackable (Normal)
  2702. }else{
  2703. clif_item_normal( client_index( i ), &itemlist_normal.list[normal++], &sd->cart.u.items_cart[i], id );
  2704. }
  2705. }
  2706. if( normal ){
  2707. itemlist_normal.PacketType = cartlistnormalType;
  2708. itemlist_normal.PacketLength = static_cast<decltype(itemlist_normal.PacketLength)>( ( sizeof( itemlist_normal ) - sizeof( itemlist_normal.list ) ) + ( sizeof( struct NORMALITEM_INFO ) * normal ) );
  2709. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2710. itemlist_normal.invType = type;
  2711. #endif
  2712. clif_send( &itemlist_normal, itemlist_normal.PacketLength, &sd->bl, SELF );
  2713. }
  2714. if( equip ){
  2715. itemlist_equip.PacketType = cartlistequipType;
  2716. itemlist_equip.PacketLength = static_cast<decltype(itemlist_equip.PacketLength)>( ( sizeof( itemlist_equip ) - sizeof( itemlist_equip.list ) ) + ( sizeof( struct EQUIPITEM_INFO ) * equip ) );
  2717. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2718. itemlist_equip.invType = type;
  2719. #endif
  2720. clif_send( &itemlist_equip, itemlist_equip.PacketLength, &sd->bl, SELF );
  2721. }
  2722. #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002
  2723. clif_inventoryEnd( sd, type );
  2724. #endif
  2725. }
  2726. /// Removes cart.
  2727. /// 012b (ZC_CARTOFF)
  2728. /// Client behaviour:
  2729. /// Closes the cart storage and removes all it's items from memory.
  2730. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2731. void clif_clearcart(int fd)
  2732. {
  2733. PACKET_ZC_CARTOFF packet{};
  2734. packet.packetType = HEADER_ZC_CARTOFF;
  2735. socket_send<PACKET_ZC_CARTOFF>(fd, packet);
  2736. }
  2737. /// Sends XY location to all other guild members
  2738. /// 01eb <account id>.L <x>.W <y>.W (ZC_NOTIFY_POSITION_TO_GUILDM)
  2739. void clif_guild_xy( map_session_data& sd ){
  2740. PACKET_ZC_NOTIFY_POSITION_TO_GUILDM packet{};
  2741. packet.packetType = HEADER_ZC_NOTIFY_POSITION_TO_GUILDM;
  2742. packet.aid = sd.status.account_id;
  2743. packet.xPos = sd.bl.x;
  2744. packet.yPos = sd.bl.y;
  2745. clif_send(&packet, sizeof(packet), &sd.bl, GUILD_SAMEMAP_WOS);
  2746. }
  2747. /// Sends XY location to a specific guild member
  2748. /// 01eb <account id>.L <x>.W <y>.W (ZC_NOTIFY_POSITION_TO_GUILDM)
  2749. void clif_guild_xy_single( map_session_data& sd, map_session_data& tsd ){
  2750. if( sd.bg_id ){
  2751. return;
  2752. }
  2753. PACKET_ZC_NOTIFY_POSITION_TO_GUILDM packet{};
  2754. packet.packetType = HEADER_ZC_NOTIFY_POSITION_TO_GUILDM;
  2755. packet.aid = sd.status.account_id;
  2756. packet.xPos = sd.bl.x;
  2757. packet.yPos = sd.bl.y;
  2758. clif_send( &packet, sizeof( packet ), &tsd.bl, SELF );
  2759. }
  2760. /// Removes XY location from all other guild members
  2761. /// 01eb <account id>.L <x>.W <y>.W (ZC_NOTIFY_POSITION_TO_GUILDM)
  2762. void clif_guild_xy_remove( map_session_data& sd ){
  2763. PACKET_ZC_NOTIFY_POSITION_TO_GUILDM packet{};
  2764. packet.packetType = HEADER_ZC_NOTIFY_POSITION_TO_GUILDM;
  2765. packet.aid = sd.status.account_id;
  2766. packet.xPos = -1;
  2767. packet.yPos = -1;
  2768. clif_send( &packet, sizeof( packet ), &sd.bl, GUILD_SAMEMAP_WOS );
  2769. }
  2770. /*==========================================
  2771. * Load castle list for guild UI. [Asheraf] / [Balfear]
  2772. *------------------------------------------*/
  2773. void clif_guild_castle_list(map_session_data& sd){
  2774. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2775. auto &g = sd.guild;
  2776. if (g == nullptr)
  2777. return;
  2778. int castle_count = guild_checkcastles(g->guild);
  2779. if( castle_count <= 0 ){
  2780. return;
  2781. }
  2782. PACKET_ZC_GUILD_AGIT_INFO* p = reinterpret_cast<PACKET_ZC_GUILD_AGIT_INFO*>( packet_buffer );
  2783. p->packetType = HEADER_ZC_GUILD_AGIT_INFO;
  2784. p->packetLength = sizeof( *p );
  2785. int i = 0;
  2786. for (const auto& gc : castle_db) {
  2787. if (gc.second->guild_id == g->guild.guild_id && gc.second->client_id) {
  2788. p->castle_list[i] = static_cast<int8>( gc.second->client_id );
  2789. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->castle_list[0] ) );
  2790. ++i;
  2791. }
  2792. }
  2793. clif_send(p, p->packetLength, &sd.bl, SELF);
  2794. #endif
  2795. }
  2796. /*==========================================
  2797. * Send castle info Economy/Defence. [Asheraf] / [Balfear]
  2798. *------------------------------------------*/
  2799. void clif_guild_castleinfo(map_session_data& sd, std::shared_ptr<guild_castle> castle ){
  2800. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2801. if( castle->client_id == 0 ){
  2802. return;
  2803. }
  2804. struct PACKET_ZC_REQ_ACK_AGIT_INVESTMENT p = {};
  2805. p.packetType = HEADER_ZC_REQ_ACK_AGIT_INVESTMENT;
  2806. p.castle_id = static_cast<int8>( castle->client_id );
  2807. p.economy = castle->economy;
  2808. p.defense = castle->defense;
  2809. clif_send(&p, sizeof(p), &sd.bl, SELF);
  2810. #endif
  2811. }
  2812. /*==========================================
  2813. * Show teleport request result. [Asheraf] / [Balfear]
  2814. *------------------------------------------*/
  2815. void clif_guild_castle_teleport_res(map_session_data& sd, enum e_siege_teleport_result result){
  2816. #if PACKETVER_MAIN_NUM >= 20190731 || PACKETVER_RE_NUM >= 20190717 || PACKETVER_ZERO_NUM >= 20190814
  2817. struct PACKET_ZC_REQ_ACK_MOVE_GUILD_AGIT p = {};
  2818. p.packetType = HEADER_ZC_REQ_ACK_MOVE_GUILD_AGIT;
  2819. p.result = static_cast<int16>( result );
  2820. clif_send(&p, sizeof(p), &sd.bl, SELF);
  2821. #endif
  2822. }
  2823. /*==========================================
  2824. * Request castle info. [Asheraf] / [Balfear]
  2825. *------------------------------------------*/
  2826. void clif_parse_guild_castle_info_request(int fd, map_session_data* sd){
  2827. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515
  2828. const struct PACKET_CZ_REQ_AGIT_INVESTMENT* p = (struct PACKET_CZ_REQ_AGIT_INVESTMENT*)RFIFOP(fd, 0);
  2829. auto &g = sd->guild;
  2830. if (g == nullptr)
  2831. return;
  2832. std::shared_ptr<guild_castle> gc = castle_db.find_by_clientid( p->castle_id );
  2833. if (gc == nullptr)
  2834. return;
  2835. if (gc->guild_id != g->guild.guild_id)
  2836. return;
  2837. clif_guild_castleinfo(*sd, gc);
  2838. #endif
  2839. }
  2840. /*==========================================
  2841. * Teleport to castle. [Asheraf] / [Balfear]
  2842. *------------------------------------------*/
  2843. void clif_parse_guild_castle_teleport_request(int fd, map_session_data* sd){
  2844. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190522 || PACKETVER_ZERO_NUM >= 20190515
  2845. const struct PACKET_CZ_REQ_MOVE_GUILD_AGIT* p = (struct PACKET_CZ_REQ_MOVE_GUILD_AGIT*)RFIFOP(fd, 0);
  2846. auto &g = sd->guild;
  2847. if (g == nullptr)
  2848. return;
  2849. std::shared_ptr<guild_castle> gc = castle_db.find_by_clientid( p->castle_id );
  2850. if (gc == nullptr)
  2851. return;
  2852. if (!gc->warp_enabled)
  2853. return;
  2854. if (gc->guild_id != g->guild.guild_id)
  2855. return;
  2856. if (map_getmapflag(sd->bl.m, MF_GVG_CASTLE)
  2857. || map_getmapflag(sd->bl.m, MF_NOTELEPORT)
  2858. || map_getmapflag(sd->bl.m, MF_NOWARP))
  2859. return;
  2860. uint32 zeny = gc->zeny;
  2861. switch( gc->type ){
  2862. case WOE_FIRST_EDITION:
  2863. if( agit_flag ){
  2864. zeny = gc->zeny_siege;
  2865. }
  2866. break;
  2867. case WOE_SECOND_EDITION:
  2868. if( agit2_flag ){
  2869. zeny = gc->zeny_siege;
  2870. }
  2871. break;
  2872. case WOE_THIRD_EDITION:
  2873. if( agit3_flag ){
  2874. zeny = gc->zeny_siege;
  2875. }
  2876. break;
  2877. }
  2878. if (zeny && pc_payzeny(sd, zeny, LOG_TYPE_OTHER)) {
  2879. clif_guild_castle_teleport_res(*sd, SIEGE_TP_NOT_ENOUGH_ZENY);
  2880. return;
  2881. }
  2882. pc_setpos(sd, gc->mapindex, gc->warp_x, gc->warp_y, CLR_OUTSIGHT);
  2883. #endif
  2884. }
  2885. /*==========================================
  2886. *
  2887. *------------------------------------------*/
  2888. static int clif_hpmeter_sub( struct block_list *bl, va_list ap ){
  2889. map_session_data* sd = va_arg( ap, map_session_data* );
  2890. map_session_data* tsd = BL_CAST( BL_PC, bl );
  2891. nullpo_ret(sd);
  2892. nullpo_ret(tsd);
  2893. if( pc_has_permission( tsd, PC_PERM_VIEW_HPMETER ) ){
  2894. clif_hpmeter_single( *tsd, sd->status.account_id, sd->battle_status.hp, sd->battle_status.max_hp );
  2895. }
  2896. return 0;
  2897. }
  2898. /*==========================================
  2899. * Server tells all players that are allowed to view HP bars
  2900. * and are nearby 'sd' that 'sd' hp bar was updated.
  2901. *------------------------------------------*/
  2902. static int clif_hpmeter(map_session_data *sd)
  2903. {
  2904. nullpo_ret(sd);
  2905. 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);
  2906. return 0;
  2907. }
  2908. /**
  2909. * Send HP bar update to others.
  2910. * @param sd: Player invoking update
  2911. */
  2912. void clif_update_hp(map_session_data &sd) {
  2913. if (map_getmapdata(sd.bl.m)->hpmeter_visible)
  2914. clif_hpmeter(&sd);
  2915. if (!battle_config.party_hp_mode && sd.status.party_id)
  2916. clif_party_hp( sd );
  2917. if (sd.bg_id)
  2918. clif_bg_hp(&sd);
  2919. }
  2920. /// Notifies client of a character parameter change.
  2921. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2922. static void clif_par_change(map_session_data& sd, uint16 varId, int count) {
  2923. PACKET_ZC_PAR_CHANGE packet{};
  2924. packet.PacketType = HEADER_ZC_PAR_CHANGE;
  2925. packet.varID = varId;
  2926. packet.count = count;
  2927. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2928. }
  2929. /// Notifies client of a character parameter change.
  2930. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2931. static void clif_longpar_change(map_session_data& sd, uint16 varId, int amount) {
  2932. PACKET_ZC_LONGPAR_CHANGE packet{};
  2933. packet.PacketType = HEADER_ZC_LONGPAR_CHANGE;
  2934. packet.varID = varId;
  2935. packet.amount = amount;
  2936. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2937. }
  2938. /// Notifies client of a character parameter change.
  2939. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2940. static void clif_zc_status_change(map_session_data& sd, uint16 status_id, uint8 value) {
  2941. PACKET_ZC_STATUS_CHANGE packet{};
  2942. packet.PacketType = HEADER_ZC_STATUS_CHANGE;
  2943. packet.statusID = status_id;
  2944. packet.value = value;
  2945. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2946. }
  2947. /// Notifies client of a character parameter change.
  2948. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2949. static void clif_cartcount( map_session_data& sd ){
  2950. PACKET_ZC_NOTIFY_CARTITEM_COUNTINFO packet{};
  2951. packet.PacketType = HEADER_ZC_NOTIFY_CARTITEM_COUNTINFO;
  2952. packet.curCount = sd.cart_num;
  2953. packet.maxCount = MAX_CART;
  2954. packet.curWeight = sd.cart_weight;
  2955. packet.maxWeight = sd.cart_weight_max;
  2956. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2957. }
  2958. /// Tells the client how far it is allowed to attack (weapon range)
  2959. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2960. static void clif_attackrange( map_session_data& sd, int16 range ){
  2961. PACKET_ZC_ATTACK_RANGE packet{};
  2962. packet.PacketType = HEADER_ZC_ATTACK_RANGE;
  2963. packet.currentAttRange = range;
  2964. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2965. }
  2966. /// Notifies client of a character parameter change.
  2967. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2968. static void clif_couplestatus(map_session_data& sd, uint32 status_type, int32 defaultStatus, int32 plusStatus) {
  2969. PACKET_ZC_COUPLESTATUS packet{};
  2970. packet.PacketType = HEADER_ZC_COUPLESTATUS;
  2971. packet.statusType = status_type;
  2972. packet.defaultStatus = defaultStatus;
  2973. packet.plusStatus = plusStatus;
  2974. clif_send(&packet, sizeof(packet), &sd.bl, SELF);
  2975. }
  2976. /// Notifies client of a character parameter change.
  2977. /// 0acb <var id>.W <value>.Q (ZC_LONGLONGPAR_CHANGE)
  2978. static void clif_longlongpar_change(map_session_data& sd, uint16 varId, int64 amount) {
  2979. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  2980. PACKET_ZC_LONGLONGPAR_CHANGE packet{};
  2981. packet.PacketType = HEADER_ZC_LONGLONGPAR_CHANGE;
  2982. packet.varID = varId;
  2983. packet.amount = amount;
  2984. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  2985. #endif
  2986. }
  2987. /// Notifies client of a character parameter change.
  2988. void clif_updatestatus( map_session_data& sd, enum _sp type ){
  2989. switch(type){
  2990. case SP_WEIGHT:
  2991. pc_updateweightstatus(&sd);
  2992. clif_par_change(sd, type, sd.weight);
  2993. break;
  2994. case SP_MAXWEIGHT:
  2995. clif_par_change(sd, type, sd.max_weight);
  2996. break;
  2997. case SP_SPEED:
  2998. clif_par_change(sd, type, sd.battle_status.speed);
  2999. break;
  3000. case SP_BASELEVEL:
  3001. clif_par_change(sd, type, sd.status.base_level);
  3002. break;
  3003. case SP_JOBLEVEL:
  3004. clif_par_change(sd, type, sd.status.job_level);
  3005. break;
  3006. case SP_KARMA:
  3007. // Adding this back, I wonder if the client intercepts this - [Lance]
  3008. clif_par_change(sd, type, sd.status.karma);
  3009. break;
  3010. case SP_MANNER:
  3011. clif_par_change(sd, type, sd.status.manner);
  3012. break;
  3013. case SP_STATUSPOINT:
  3014. clif_par_change(sd, type, sd.status.status_point);
  3015. break;
  3016. case SP_SKILLPOINT:
  3017. clif_par_change(sd, type, sd.status.skill_point);
  3018. break;
  3019. case SP_HIT:
  3020. clif_par_change(sd, type, sd.battle_status.hit);
  3021. break;
  3022. case SP_FLEE1:
  3023. clif_par_change(sd, type, sd.battle_status.flee);
  3024. break;
  3025. case SP_FLEE2:
  3026. clif_par_change(sd, type, sd.battle_status.flee2/10);
  3027. break;
  3028. case SP_MAXHP:
  3029. clif_par_change(sd, type, sd.battle_status.max_hp);
  3030. break;
  3031. case SP_MAXSP:
  3032. clif_par_change(sd, type, sd.battle_status.max_sp);
  3033. break;
  3034. case SP_HP:
  3035. // On officials the HP never go below 1, even if you die [Lemongrass]
  3036. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  3037. if (sd.battle_status.hp == 0) {
  3038. clif_par_change(sd, type, (sd.class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd.battle_status.max_hp/2);
  3039. } else {
  3040. clif_par_change(sd, type, sd.battle_status.hp);
  3041. }
  3042. break;
  3043. case SP_SP:
  3044. clif_par_change(sd, type, sd.battle_status.sp);
  3045. break;
  3046. case SP_ASPD:
  3047. clif_par_change(sd, type, sd.battle_status.amotion);
  3048. break;
  3049. case SP_ATK1:
  3050. clif_par_change(sd, type, pc_leftside_atk(&sd));
  3051. break;
  3052. case SP_DEF1:
  3053. clif_par_change(sd, type, pc_leftside_def(&sd));
  3054. break;
  3055. case SP_MDEF1:
  3056. clif_par_change(sd, type, pc_leftside_mdef(&sd));
  3057. break;
  3058. case SP_ATK2:
  3059. clif_par_change(sd, type, pc_rightside_atk(&sd));
  3060. break;
  3061. case SP_DEF2:
  3062. clif_par_change(sd, type, pc_rightside_def(&sd));
  3063. break;
  3064. case SP_MDEF2: {
  3065. //negative check (in case you have something like Berserk active)
  3066. int mdef2 = pc_rightside_mdef(&sd);
  3067. #ifndef RENEWAL
  3068. clif_par_change(sd, type, mdef2 < 0 ? 0 : mdef2);
  3069. #else
  3070. clif_par_change(sd, type, mdef2);
  3071. #endif
  3072. }
  3073. break;
  3074. case SP_CRITICAL:
  3075. clif_par_change(sd, type, sd.battle_status.cri/10);
  3076. break;
  3077. case SP_MATK1:
  3078. clif_par_change(sd, type, pc_rightside_matk(&sd));
  3079. break;
  3080. case SP_MATK2:
  3081. clif_par_change(sd, type, pc_leftside_matk(&sd));
  3082. break;
  3083. case SP_ZENY:
  3084. clif_longpar_change(sd, type, sd.status.zeny);
  3085. break;
  3086. #if PACKETVER >= 20170830
  3087. case SP_BASEEXP:
  3088. clif_longlongpar_change(sd, type, client_exp(sd.status.base_exp));
  3089. break;
  3090. case SP_JOBEXP:
  3091. clif_longlongpar_change(sd, type, client_exp(sd.status.job_exp));
  3092. break;
  3093. case SP_NEXTBASEEXP:
  3094. clif_longlongpar_change(sd, type, client_exp(pc_nextbaseexp(&sd)));
  3095. break;
  3096. case SP_NEXTJOBEXP:
  3097. clif_longlongpar_change(sd, type, client_exp(pc_nextjobexp(&sd)));
  3098. break;
  3099. #else
  3100. case SP_BASEEXP:
  3101. clif_par_change(sd, type, client_exp(sd.status.base_exp));
  3102. break;
  3103. case SP_JOBEXP:
  3104. clif_par_change(sd, type, client_exp(sd.status.job_exp));
  3105. break;
  3106. case SP_NEXTBASEEXP:
  3107. clif_par_change(sd, type, client_exp(pc_nextbaseexp(&sd)));
  3108. break;
  3109. case SP_NEXTJOBEXP:
  3110. clif_par_change(sd, type, client_exp(pc_nextjobexp(&sd)));
  3111. break;
  3112. #endif
  3113. /**
  3114. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  3115. **/
  3116. case SP_USTR:
  3117. case SP_UAGI:
  3118. case SP_UVIT:
  3119. case SP_UINT:
  3120. case SP_UDEX:
  3121. case SP_ULUK:
  3122. clif_zc_status_change(sd, static_cast<uint16>(type), static_cast<uint8>(pc_need_status_point(&sd, type-SP_USTR+SP_STR, 1)));
  3123. break;
  3124. case SP_ATTACKRANGE:
  3125. clif_attackrange( sd, sd.battle_status.rhw.range );
  3126. break;
  3127. case SP_STR:
  3128. clif_couplestatus(sd, type, sd.status.str, sd.battle_status.str - sd.status.str);
  3129. break;
  3130. case SP_AGI:
  3131. clif_couplestatus(sd, type, sd.status.agi, sd.battle_status.agi - sd.status.agi);
  3132. break;
  3133. case SP_VIT:
  3134. clif_couplestatus(sd, type, sd.status.vit, sd.battle_status.vit - sd.status.vit);
  3135. break;
  3136. case SP_INT:
  3137. clif_couplestatus(sd, type, sd.status.int_, sd.battle_status.int_ - sd.status.int_);
  3138. break;
  3139. case SP_DEX:
  3140. clif_couplestatus(sd, type, sd.status.dex, sd.battle_status.dex - sd.status.dex);
  3141. break;
  3142. case SP_LUK:
  3143. clif_couplestatus(sd, type, sd.status.luk, sd.battle_status.luk - sd.status.luk);
  3144. break;
  3145. case SP_CARTINFO:
  3146. clif_cartcount( sd );
  3147. break;
  3148. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  3149. case SP_AP:
  3150. clif_par_change( sd, SP_AP, sd.battle_status.ap );
  3151. break;
  3152. case SP_TRAITPOINT:
  3153. clif_par_change( sd, SP_TRAITPOINT, sd.status.trait_point );
  3154. break;
  3155. case SP_MAXAP:
  3156. clif_par_change( sd, SP_MAXAP, sd.battle_status.max_ap );
  3157. break;
  3158. case SP_POW:
  3159. clif_couplestatus( sd, SP_POW, sd.status.pow, sd.battle_status.pow - sd.status.pow );
  3160. break;
  3161. case SP_STA:
  3162. clif_couplestatus( sd, SP_STA, sd.status.sta, sd.battle_status.sta - sd.status.sta );
  3163. break;
  3164. case SP_WIS:
  3165. clif_couplestatus( sd, SP_WIS, sd.status.wis, sd.battle_status.wis - sd.status.wis );
  3166. break;
  3167. case SP_SPL:
  3168. clif_couplestatus( sd, SP_SPL, sd.status.spl, sd.battle_status.spl - sd.status.spl );
  3169. break;
  3170. case SP_CON:
  3171. clif_couplestatus( sd, SP_CON, sd.status.con, sd.battle_status.con - sd.status.con );
  3172. break;
  3173. case SP_CRT:
  3174. clif_couplestatus( sd, SP_CRT, sd.status.crt, sd.battle_status.crt - sd.status.crt );
  3175. break;
  3176. case SP_UPOW:
  3177. case SP_USTA:
  3178. case SP_UWIS:
  3179. case SP_USPL:
  3180. case SP_UCON:
  3181. case SP_UCRT:
  3182. clif_zc_status_change( sd, static_cast<uint16>( type ), static_cast<uint8>( pc_need_trait_point( &sd, type - SP_UPOW + SP_POW, 1 ) ) );
  3183. break;
  3184. case SP_PATK:
  3185. clif_par_change( sd, SP_PATK, sd.battle_status.patk );
  3186. break;
  3187. case SP_SMATK:
  3188. clif_par_change( sd, SP_SMATK, sd.battle_status.smatk );
  3189. break;
  3190. case SP_RES:
  3191. clif_par_change( sd, SP_RES, sd.battle_status.res );
  3192. break;
  3193. case SP_MRES:
  3194. clif_par_change( sd, SP_MRES, sd.battle_status.mres );
  3195. break;
  3196. case SP_HPLUS:
  3197. clif_par_change( sd, SP_HPLUS, sd.battle_status.hplus );
  3198. break;
  3199. case SP_CRATE:
  3200. clif_par_change( sd, SP_CRATE, sd.battle_status.crate );
  3201. break;
  3202. #else
  3203. case SP_AP:
  3204. case SP_TRAITPOINT:
  3205. case SP_MAXAP:
  3206. case SP_POW:
  3207. case SP_STA:
  3208. case SP_WIS:
  3209. case SP_SPL:
  3210. case SP_CON:
  3211. case SP_CRT:
  3212. case SP_UPOW:
  3213. case SP_USTA:
  3214. case SP_UWIS:
  3215. case SP_USPL:
  3216. case SP_UCON:
  3217. case SP_UCRT:
  3218. case SP_PATK:
  3219. case SP_SMATK:
  3220. case SP_RES:
  3221. case SP_MRES:
  3222. case SP_HPLUS:
  3223. case SP_CRATE:
  3224. // 4th job status are not supported by older clients
  3225. return;
  3226. #endif
  3227. default:
  3228. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3229. return;
  3230. }
  3231. // Additional update packets that should be sent right after
  3232. switch( type ){
  3233. case SP_BASELEVEL:
  3234. if( sd.status.party_id ){
  3235. struct party_data* p;
  3236. int i;
  3237. if( ( p = party_search( sd.status.party_id ) ) != nullptr ){
  3238. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd.status.char_id);
  3239. if( i < MAX_PARTY ){
  3240. p->party.member[i].lv = sd.status.base_level;
  3241. clif_party_job_and_level( sd );
  3242. }
  3243. }
  3244. }
  3245. break;
  3246. case SP_HP:
  3247. clif_update_hp( sd );
  3248. break;
  3249. }
  3250. }
  3251. /// Notifies client of a parameter change of an another player.
  3252. /// 01ab <account id>.L <var id>.W <value>.L (ZC_PAR_CHANGE_USER)
  3253. /// var id:
  3254. /// SP_MANNER
  3255. /// ?
  3256. void clif_changemanner( map_session_data& sd ) {
  3257. PACKET_ZC_PAR_CHANGE_USER packet{};
  3258. packet.packetType = HEADER_ZC_PAR_CHANGE_USER;
  3259. packet.gid = sd.bl.id;
  3260. packet.type = static_cast<decltype(packet.type)>(SP_MANNER);
  3261. packet.value = sd.status.manner;
  3262. clif_send( &packet, sizeof( packet ), &sd.bl, AREA_WOS );
  3263. }
  3264. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3265. /// 01d7 <id>.L <type>.B <value1>.W <value2>.W (ZC_SPRITE_CHANGE2)
  3266. void clif_sprite_change( struct block_list *bl, int id, int type, int val, int val2, enum send_target target ){
  3267. struct PACKET_ZC_SPRITE_CHANGE p;
  3268. p.packetType = sendLookType;
  3269. p.AID = id;
  3270. p.type = type;
  3271. p.val = val;
  3272. #if PACKETVER >= 4
  3273. p.val2 = val2;
  3274. #endif
  3275. clif_send( &p, sizeof( p ), bl, target );
  3276. }
  3277. /// Updates sprite/style properties of an object.
  3278. void clif_changelook(struct block_list *bl, int type, int val) {
  3279. map_session_data* sd;
  3280. status_change* sc;
  3281. struct view_data* vd;
  3282. enum send_target target = AREA;
  3283. int val2 = 0;
  3284. nullpo_retv(bl);
  3285. sd = BL_CAST(BL_PC, bl);
  3286. sc = status_get_sc(bl);
  3287. vd = status_get_viewdata(bl);
  3288. if( vd ) //temp hack to let Warp Portal change appearance
  3289. switch(type) {
  3290. case LOOK_WEAPON:
  3291. if (sd) {
  3292. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3293. val = vd->weapon;
  3294. }
  3295. else
  3296. vd->weapon = val;
  3297. break;
  3298. case LOOK_SHIELD:
  3299. if (sd) {
  3300. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3301. val = vd->shield;
  3302. }
  3303. else
  3304. vd->shield = val;
  3305. break;
  3306. case LOOK_BASE:
  3307. if (!sd)
  3308. break;
  3309. if ( val == JT_INVISIBLE )
  3310. return;
  3311. if (sd->sc.option&OPTION_COSTUME)
  3312. vd->weapon = vd->shield = 0;
  3313. if (!vd->cloth_color)
  3314. break;
  3315. if (sd) {
  3316. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3317. vd->cloth_color = 0;
  3318. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3319. vd->cloth_color = 0;
  3320. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3321. vd->cloth_color = 0;
  3322. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3323. vd->cloth_color = 0;
  3324. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3325. vd->cloth_color = 0;
  3326. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3327. vd->body_style = 0;
  3328. }
  3329. break;
  3330. case LOOK_HAIR:
  3331. vd->hair_style = val;
  3332. break;
  3333. case LOOK_HEAD_BOTTOM:
  3334. vd->head_bottom = val;
  3335. break;
  3336. case LOOK_HEAD_TOP:
  3337. vd->head_top = val;
  3338. break;
  3339. case LOOK_HEAD_MID:
  3340. vd->head_mid = val;
  3341. break;
  3342. case LOOK_HAIR_COLOR:
  3343. vd->hair_color = val;
  3344. break;
  3345. case LOOK_CLOTHES_COLOR:
  3346. if (val && sd) {
  3347. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3348. val = 0;
  3349. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3350. val = 0;
  3351. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3352. val = 0;
  3353. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3354. val = 0;
  3355. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3356. val = 0;
  3357. }
  3358. vd->cloth_color = val;
  3359. break;
  3360. case LOOK_SHOES:
  3361. #if PACKETVER > 3
  3362. if (sd) {
  3363. int n;
  3364. if((n = sd->equip_index[EQI_SHOES]) >= 0 && sd->inventory_data[n]) {
  3365. if(sd->inventory_data[n]->view_id > 0)
  3366. val = sd->inventory_data[n]->view_id;
  3367. else
  3368. val = sd->inventory.u.items_inventory[n].nameid;
  3369. } else
  3370. val = 0;
  3371. }
  3372. #endif
  3373. //Shoes? No packet uses this....
  3374. break;
  3375. case LOOK_BODY:
  3376. // unknown purpose
  3377. break;
  3378. case LOOK_ROBE:
  3379. #if PACKETVER < 20110111
  3380. return;
  3381. #else
  3382. vd->robe = val;
  3383. #endif
  3384. break;
  3385. case LOOK_BODY2:
  3386. #if PACKETVER < 20150513
  3387. return;
  3388. #else
  3389. if (val && sd && sd->sc.option&OPTION_COSTUME)
  3390. val = 0;
  3391. vd->body_style = val;
  3392. #endif
  3393. break;
  3394. }
  3395. // prevent leaking the presence of GM-hidden objects
  3396. if( sc && sc->option&OPTION_INVISIBLE )
  3397. target = SELF;
  3398. #if PACKETVER < 4
  3399. if (target != SELF && bl->type == BL_NPC && (((TBL_NPC*)bl)->is_invisible))
  3400. target = SELF;
  3401. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3402. #else
  3403. if (bl->type != BL_NPC) {
  3404. if (type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3405. type = LOOK_WEAPON;
  3406. val = (vd ? vd->weapon : 0);
  3407. val2 = (vd ? vd->shield : 0);
  3408. }
  3409. if (disguised(bl)) {
  3410. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3411. clif_sprite_change(bl, disguised_bl_id(bl->id), type, val, val2, SELF);
  3412. } else
  3413. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3414. } else
  3415. unit_refresh(bl);
  3416. #endif
  3417. }
  3418. //Sends a change-base-look packet required for traps as they are triggered.
  3419. void clif_changetraplook(struct block_list *bl,int val) {
  3420. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3421. }
  3422. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3423. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3424. clif_sprite_change(bl, id, type, val, 0, target);
  3425. }
  3426. /// Character status (ZC_STATUS).
  3427. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3428. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3429. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3430. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3431. void clif_initialstatus( map_session_data& sd ) {
  3432. PACKET_ZC_STATUS packet{};
  3433. packet.packetType = HEADER_ZC_STATUS;
  3434. packet.point = min(sd.status.status_point, INT16_MAX);
  3435. packet.str = min(sd.status.str, UINT8_MAX);
  3436. packet.standardStr = pc_need_status_point( &sd, SP_STR, 1 );
  3437. packet.agi = min(sd.status.agi, UINT8_MAX);
  3438. packet.standardAgi = pc_need_status_point( &sd, SP_AGI,1 );
  3439. packet.vit = min(sd.status.vit, UINT8_MAX);
  3440. packet.standardVit = pc_need_status_point( &sd, SP_VIT,1 );
  3441. packet.int_ = min(sd.status.int_, UINT8_MAX);
  3442. packet.standardInt = pc_need_status_point( &sd, SP_INT,1 );
  3443. packet.dex = min(sd.status.dex, UINT8_MAX);
  3444. packet.standardDex = pc_need_status_point( &sd, SP_DEX,1 );
  3445. packet.luk = min(sd.status.luk, UINT8_MAX);
  3446. packet.standardLuk = pc_need_status_point( &sd, SP_LUK,1 );
  3447. packet.attPower = pc_leftside_atk( &sd );
  3448. packet.refiningPower = pc_rightside_atk( &sd );
  3449. packet.max_mattPower = pc_rightside_matk( &sd );
  3450. packet.min_mattPower = pc_leftside_matk( &sd );
  3451. packet.itemdefPower = pc_leftside_def( &sd );
  3452. packet.plusdefPower = pc_rightside_def( &sd );
  3453. packet.mdefPower = pc_leftside_mdef( &sd );
  3454. #ifdef RENEWAL
  3455. packet.plusmdefPower = pc_rightside_mdef( &sd );
  3456. #else
  3457. // Negative check for Frenzy'ed characters.
  3458. packet.plusmdefPower = std::max( pc_rightside_mdef( &sd ), 0 );
  3459. #endif
  3460. packet.hitSuccessValue = sd.battle_status.hit;
  3461. packet.avoidSuccessValue = sd.battle_status.flee;
  3462. packet.plusAvoidSuccessValue = sd.battle_status.flee2 / 10;
  3463. packet.criticalSuccessValue = sd.battle_status.cri / 10;
  3464. packet.ASPD = sd.battle_status.amotion;
  3465. packet.plusASPD = 0;
  3466. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3467. clif_updatestatus(sd, SP_STR);
  3468. clif_updatestatus(sd, SP_AGI);
  3469. clif_updatestatus(sd, SP_VIT);
  3470. clif_updatestatus(sd, SP_INT);
  3471. clif_updatestatus(sd, SP_DEX);
  3472. clif_updatestatus(sd, SP_LUK);
  3473. clif_updatestatus(sd, SP_ATTACKRANGE);
  3474. clif_updatestatus(sd, SP_ASPD);
  3475. #ifdef RENEWAL
  3476. clif_updatestatus(sd, SP_POW);
  3477. clif_updatestatus(sd, SP_STA);
  3478. clif_updatestatus(sd, SP_WIS);
  3479. clif_updatestatus(sd, SP_SPL);
  3480. clif_updatestatus(sd, SP_CON);
  3481. clif_updatestatus(sd, SP_CRT);
  3482. clif_updatestatus(sd, SP_PATK);
  3483. clif_updatestatus(sd, SP_SMATK);
  3484. clif_updatestatus(sd, SP_RES);
  3485. clif_updatestatus(sd, SP_MRES);
  3486. clif_updatestatus(sd, SP_HPLUS);
  3487. clif_updatestatus(sd, SP_CRATE);
  3488. clif_updatestatus(sd, SP_TRAITPOINT);
  3489. clif_updatestatus(sd, SP_AP);
  3490. clif_updatestatus(sd, SP_MAXAP);
  3491. clif_updatestatus(sd, SP_UPOW);
  3492. clif_updatestatus(sd, SP_USTA);
  3493. clif_updatestatus(sd, SP_UWIS);
  3494. clif_updatestatus(sd, SP_USPL);
  3495. clif_updatestatus(sd, SP_UCON);
  3496. clif_updatestatus(sd, SP_UCRT);
  3497. #endif
  3498. }
  3499. /// Marks an ammunition item in inventory as equipped.
  3500. /// 013c <index>.W (ZC_EQUIP_ARROW)
  3501. void clif_arrowequip( map_session_data& sd ) {
  3502. #if PACKETVER >= 20121128
  3503. clif_status_change(&sd.bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INFINITE_TICK, 0, 0, 0);
  3504. #endif
  3505. PACKET_ZC_EQUIP_ARROW packet{};
  3506. packet.packetType = HEADER_ZC_EQUIP_ARROW;
  3507. // Inventory index of the arrow
  3508. packet.index = client_index( sd.equip_index[EQI_AMMO] );
  3509. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3510. }
  3511. /// Ammunition action message.
  3512. /// 013b <type>.W (ZC_ACTION_FAILURE)
  3513. /// type:
  3514. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3515. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3516. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3517. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3518. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3519. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3520. void clif_arrow_fail( map_session_data& sd, e_action_failure type ) {
  3521. PACKET_ZC_ACTION_FAILURE packet{};
  3522. packet.packetType = HEADER_ZC_ACTION_FAILURE;
  3523. packet.type = static_cast<decltype(packet.type)>(type);
  3524. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3525. }
  3526. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3527. /// 01ad <packet len>.W { <name id>.W }*
  3528. void clif_arrow_create_list( map_session_data& sd ){
  3529. PACKET_ZC_MAKINGARROW_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGARROW_LIST*>( packet_buffer );
  3530. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  3531. p->packetLength = sizeof( *p );
  3532. int count = 0;
  3533. for (const auto &it : skill_arrow_db) {
  3534. t_itemid nameid = it.second->nameid;
  3535. if( !item_db.exists( nameid ) ){
  3536. continue;
  3537. }
  3538. int index = pc_search_inventory( &sd, nameid );
  3539. if( index < 0 ){
  3540. continue;
  3541. }
  3542. if( sd.inventory.u.items_inventory[index].equip ){
  3543. continue;
  3544. }
  3545. if( !sd.inventory.u.items_inventory[index].identify ){
  3546. continue;
  3547. }
  3548. p->items[count].itemId = client_nameid( nameid );
  3549. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  3550. count++;
  3551. }
  3552. clif_send( p, p->packetLength, &sd.bl, SELF );
  3553. if( count > 0 ){
  3554. sd.menuskill_id = AC_MAKINGARROW;
  3555. sd.menuskill_val = count;
  3556. }
  3557. }
  3558. /// Notifies the client, about the result of an status change request.
  3559. /// 00bc <status id>.W <result>.B <value>.B (ZC_STATUS_CHANGE_ACK)
  3560. /// status id:
  3561. /// SP_STR ~ SP_LUK and SP_POW ~ SP_CRT
  3562. /// result:
  3563. /// 0 = failure
  3564. /// 1 = success
  3565. void clif_statusupack( map_session_data& sd, int32 type, bool success, int32 val ) {
  3566. PACKET_ZC_STATUS_CHANGE_ACK packet{};
  3567. packet.packetType = HEADER_ZC_STATUS_CHANGE_ACK;
  3568. packet.sp = static_cast<decltype(packet.sp)>(type);
  3569. packet.ok = success;
  3570. packet.value = cap_value(val, 0, UINT8_MAX);
  3571. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3572. }
  3573. /// Notifies the client about the result of a request to equip an item.
  3574. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3575. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3576. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3577. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3578. /// @ok: //inversed forv2 v5
  3579. /// 0 = failure
  3580. /// 1 = success
  3581. /// 2 = failure due to low level
  3582. void clif_equipitemack( map_session_data& sd, uint8 flag, int index, int pos ){
  3583. struct PACKET_ZC_REQ_WEAR_EQUIP_ACK p = {};
  3584. p.PacketType = HEADER_ZC_REQ_WEAR_EQUIP_ACK;
  3585. p.index = client_index( index );
  3586. p.wearLocation = pos;
  3587. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20100629
  3588. if( flag == ITEM_EQUIP_ACK_OK && sd.inventory_data[index]->equip&EQP_VISIBLE ){
  3589. p.wItemSpriteNumber = sd.inventory_data[index]->look;
  3590. }else{
  3591. p.wItemSpriteNumber = 0;
  3592. }
  3593. #endif
  3594. p.result = flag;
  3595. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  3596. }
  3597. /// Notifies the client about the result of a request to take off an item.
  3598. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3599. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3600. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3601. /// @ok : //inversed for v2 v5
  3602. /// 0 = failure
  3603. /// 1 = success
  3604. void clif_unequipitemack(map_session_data *sd,int n,int pos,int ok)
  3605. {
  3606. int fd, header, offs = 0;
  3607. #if PACKETVER >= 20130000
  3608. header = 0x99a;
  3609. ok = ok ? 0 : 1;
  3610. #elif PACKETVER >= 20110824
  3611. header = 0x8d1;
  3612. ok = ok ? 0 : 1;
  3613. #else
  3614. header = 0xac;
  3615. #endif
  3616. nullpo_retv(sd);
  3617. fd=sd->fd;
  3618. WFIFOHEAD(fd, packet_len(header));
  3619. WFIFOW(fd,offs+0) = header;
  3620. WFIFOW(fd,offs+2) = n+2;
  3621. #if PACKETVER >= 20130000
  3622. WFIFOL(fd,offs+4) = pos;
  3623. offs += 2;
  3624. #else
  3625. WFIFOW(fd,offs+4) = pos;
  3626. #endif
  3627. WFIFOB(fd,offs+6) = ok;
  3628. WFIFOSET(fd, packet_len(header));
  3629. }
  3630. /// Notifies clients in the area about an special/visual effect.
  3631. /// 019b <id>.L <effect id>.L (ZC_NOTIFY_EFFECT)
  3632. /// effect id:
  3633. /// 0 = base level up
  3634. /// 1 = job level up
  3635. /// 2 = refine failure
  3636. /// 3 = refine success
  3637. /// 4 = game over
  3638. /// 5 = pharmacy success
  3639. /// 6 = pharmacy failure
  3640. /// 7 = base level up (super novice)
  3641. /// 8 = job level up (super novice)
  3642. /// 9 = base level up (taekwon)
  3643. void clif_misceffect( block_list& bl, e_notify_effect type ){
  3644. PACKET_ZC_NOTIFY_EFFECT packet{};
  3645. packet.packetType = HEADER_ZC_NOTIFY_EFFECT;
  3646. packet.aid = bl.id;
  3647. packet.effectId = static_cast<decltype(packet.effectId)>(type);
  3648. clif_send( &packet, sizeof( packet ), &bl, AREA );
  3649. }
  3650. /// Notifies clients in the area of a state change.
  3651. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3652. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3653. void clif_changeoption_target( struct block_list* bl, struct block_list* target ){
  3654. nullpo_retv( bl );
  3655. status_change* sc = status_get_sc( bl );
  3656. //How can an option change if there's no sc?
  3657. if( sc == nullptr ){
  3658. return;
  3659. }
  3660. map_session_data* sd = BL_CAST( BL_PC, bl );
  3661. struct PACKET_ZC_STATE_CHANGE p;
  3662. p.packetType = HEADER_ZC_STATE_CHANGE;
  3663. p.AID = bl->id;
  3664. p.bodyState = sc->opt1;
  3665. p.healthState = sc->opt2;
  3666. p.effectState = sc->option;
  3667. p.isPKModeON = sd ? sd->status.karma : false;
  3668. if( target == nullptr ){
  3669. if( disguised( bl ) ){
  3670. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  3671. p.AID = disguised_bl_id( p.AID );
  3672. clif_send( &p, sizeof( p ), bl, SELF );
  3673. p.AID = disguised_bl_id( p.AID );
  3674. p.effectState = OPTION_INVISIBLE;
  3675. clif_send( &p, sizeof( p ), bl, SELF );
  3676. }else{
  3677. clif_send( &p, sizeof( p ), bl, AREA );
  3678. }
  3679. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3680. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3681. if( sc->getSCE(SC_PROVOKE) ){
  3682. const struct TimerData *td = get_timer( sc->getSCE(SC_PROVOKE)->timer );
  3683. clif_status_change( bl, status_db.getIcon(SC_PROVOKE), 1, ( !td ? INFINITE_TICK : DIFF_TICK( td->tick, gettick() ) ), 0, 0, 0 );
  3684. }
  3685. }else{
  3686. if( disguised( bl ) ){
  3687. p.AID = disguised_bl_id( p.AID );
  3688. clif_send( &p, sizeof( p ), target, SELF );
  3689. p.AID = disguised_bl_id( p.AID );
  3690. p.effectState = OPTION_INVISIBLE;
  3691. clif_send( &p, sizeof( p ), target, SELF );
  3692. }else{
  3693. clif_send( &p, sizeof( p ), target, SELF );
  3694. }
  3695. }
  3696. }
  3697. /// Displays status change effects on NPCs/monsters.
  3698. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L (ZC_NPC_SHOWEFST_UPDATE)
  3699. void clif_changeoption2( block_list& bl ){
  3700. status_change *sc = status_get_sc(&bl);
  3701. if (!sc)
  3702. return; //How can an option change if there's no sc?
  3703. PACKET_ZC_NPC_SHOWEFST_UPDATE packet{};
  3704. packet.packetType = HEADER_ZC_NPC_SHOWEFST_UPDATE;
  3705. packet.gid = bl.id;
  3706. packet.effectState = sc->option;
  3707. packet.level = clif_setlevel(&bl);
  3708. packet.showEFST = sc->opt3;
  3709. if (disguised(&bl)) {
  3710. clif_send( &packet, sizeof( packet ), &bl, AREA_WOS );
  3711. packet.gid = disguised_bl_id( bl.id );
  3712. clif_send( &packet, sizeof( packet ), &bl, SELF );
  3713. packet.gid = bl.id;
  3714. packet.effectState = OPTION_INVISIBLE;
  3715. clif_send( &packet, sizeof( packet ), &bl, SELF );
  3716. } else {
  3717. clif_send( &packet, sizeof( packet ), &bl, AREA );
  3718. }
  3719. }
  3720. /// Notifies the client about the result of an item use request.
  3721. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3722. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3723. void clif_useitemack( map_session_data *sd, int index, int amount, bool ok ){
  3724. nullpo_retv( sd );
  3725. int fd = sd->fd;
  3726. if( !session_isActive( fd ) ){
  3727. return;
  3728. }
  3729. if( index < 0 || index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3730. return;
  3731. }
  3732. struct PACKET_ZC_USE_ITEM_ACK p;
  3733. p.packetType = useItemAckType;
  3734. p.index = index + 2;
  3735. #if PACKETVER > 3
  3736. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3737. p.AID = sd->bl.id;
  3738. #endif
  3739. p.amount = amount;
  3740. p.result = ok;
  3741. if( !ok ){
  3742. clif_send( &p, sizeof(p), &sd->bl, SELF );
  3743. }else{
  3744. clif_send( &p, sizeof(p), &sd->bl, AREA );
  3745. }
  3746. }
  3747. /// Inform client whether chatroom creation was successful or not.
  3748. /// 00d6 <flag>.B (ZC_ACK_CREATE_CHATROOM)
  3749. /// flag:
  3750. /// 0 = Room has been successfully created (opens chat room)
  3751. /// 1 = Room limit exceeded
  3752. /// 2 = Same room already exists
  3753. void clif_createchat( map_session_data& sd, e_create_chatroom flag ){
  3754. PACKET_ZC_ACK_CREATE_CHATROOM packet{};
  3755. packet.packetType = HEADER_ZC_ACK_CREATE_CHATROOM;
  3756. packet.flag = static_cast<decltype(packet.flag)>(flag);
  3757. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3758. }
  3759. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3760. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3761. /// type:
  3762. /// 0 = private (password protected)
  3763. /// 1 = public
  3764. /// 2 = arena (npc waiting room)
  3765. /// 3 = PK zone (non-clickable)
  3766. void clif_dispchat(struct chat_data* cd, int fd)
  3767. {
  3768. unsigned char buf[128];
  3769. uint8 type;
  3770. if( cd == nullptr || cd->owner == nullptr )
  3771. return;
  3772. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3773. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3774. : 1;
  3775. WBUFW(buf, 0) = 0xd7;
  3776. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3777. WBUFL(buf, 4) = cd->owner->id;
  3778. WBUFL(buf, 8) = cd->bl.id;
  3779. WBUFW(buf,12) = cd->limit;
  3780. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3781. WBUFB(buf,16) = type;
  3782. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3783. if( session_isActive(fd) ) {
  3784. WFIFOHEAD(fd,WBUFW(buf,2));
  3785. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3786. WFIFOSET(fd,WBUFW(buf,2));
  3787. } else {
  3788. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3789. }
  3790. }
  3791. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3792. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3793. /// type:
  3794. /// 0 = private (password protected)
  3795. /// 1 = public
  3796. /// 2 = arena (npc waiting room)
  3797. /// 3 = PK zone (non-clickable)
  3798. void clif_changechatstatus(struct chat_data* cd)
  3799. {
  3800. unsigned char buf[128];
  3801. uint8 type;
  3802. if( cd == nullptr || cd->usersd[0] == nullptr )
  3803. return;
  3804. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3805. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3806. : 1;
  3807. WBUFW(buf, 0) = 0xdf;
  3808. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3809. WBUFL(buf, 4) = cd->owner->id;
  3810. WBUFL(buf, 8) = cd->bl.id;
  3811. WBUFW(buf,12) = cd->limit;
  3812. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3813. WBUFB(buf,16) = type;
  3814. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3815. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3816. }
  3817. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3818. /// 00d8 <chat id>.L
  3819. void clif_clearchat(struct chat_data *cd,int fd)
  3820. {
  3821. unsigned char buf[32];
  3822. nullpo_retv(cd);
  3823. WBUFW(buf,0) = 0xd8;
  3824. WBUFL(buf,2) = cd->bl.id;
  3825. if( session_isActive(fd) ) {
  3826. WFIFOHEAD(fd,packet_len(0xd8));
  3827. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3828. WFIFOSET(fd,packet_len(0xd8));
  3829. } else {
  3830. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3831. }
  3832. }
  3833. /// Displays messages regarding join chat failures.
  3834. /// 00da <result>.B (ZC_REFUSE_ENTER_ROOM)
  3835. /// result:
  3836. /// 0 = room full
  3837. /// 1 = wrong password
  3838. /// 2 = kicked
  3839. /// 3 = success (no message)
  3840. /// 4 = no enough zeny
  3841. /// 5 = too low level
  3842. /// 6 = too high level
  3843. /// 7 = unsuitable job class
  3844. void clif_joinchatfail( map_session_data& sd, e_refuse_enter_room result ){
  3845. PACKET_ZC_REFUSE_ENTER_ROOM packet{};
  3846. packet.packetType = HEADER_ZC_REFUSE_ENTER_ROOM;
  3847. packet.result = static_cast<decltype(packet.result)>(result);
  3848. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  3849. }
  3850. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3851. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3852. /// role:
  3853. /// 0 = owner (menu)
  3854. /// 1 = normal
  3855. void clif_joinchatok(map_session_data *sd,struct chat_data* cd)
  3856. {
  3857. int fd;
  3858. int i,t;
  3859. nullpo_retv(sd);
  3860. nullpo_retv(cd);
  3861. fd = sd->fd;
  3862. if (!session_isActive(fd))
  3863. return;
  3864. t = (int)(cd->owner->type == BL_NPC);
  3865. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3866. WFIFOW(fd, 0) = 0xdb;
  3867. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3868. WFIFOL(fd, 4) = cd->bl.id;
  3869. if(cd->owner->type == BL_NPC){
  3870. WFIFOL(fd, 30) = 1;
  3871. WFIFOL(fd, 8) = 0;
  3872. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3873. for (i = 0; i < cd->users; i++) {
  3874. WFIFOL(fd, 8+(i+1)*28) = 1;
  3875. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3876. }
  3877. }else{
  3878. for (i = 0; i < cd->users; i++) {
  3879. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3880. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3881. }
  3882. }
  3883. WFIFOSET(fd, WFIFOW(fd, 2));
  3884. }
  3885. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3886. /// 00dc <users>.W <name>.24B
  3887. void clif_addchat(struct chat_data* cd,map_session_data *sd)
  3888. {
  3889. unsigned char buf[29];
  3890. nullpo_retv(sd);
  3891. nullpo_retv(cd);
  3892. WBUFW(buf, 0) = 0xdc;
  3893. WBUFW(buf, 2) = cd->users;
  3894. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3895. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3896. }
  3897. /// Announce the new owner (ZC_ROLE_CHANGE).
  3898. /// 00e1 <role>.L <nick>.24B
  3899. /// role:
  3900. /// 0 = owner (menu)
  3901. /// 1 = normal
  3902. void clif_changechatowner(struct chat_data* cd, map_session_data* sd)
  3903. {
  3904. unsigned char buf[64];
  3905. nullpo_retv(sd);
  3906. nullpo_retv(cd);
  3907. WBUFW(buf, 0) = 0xe1;
  3908. WBUFL(buf, 2) = 1;
  3909. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3910. WBUFW(buf,30) = 0xe1;
  3911. WBUFL(buf,32) = 0;
  3912. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3913. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3914. }
  3915. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3916. /// 00dd <users>.W <nick>.24B <flag>.B
  3917. /// flag:
  3918. /// 0 = left
  3919. /// 1 = kicked
  3920. void clif_leavechat(struct chat_data* cd, map_session_data* sd, bool flag)
  3921. {
  3922. unsigned char buf[32];
  3923. nullpo_retv(sd);
  3924. nullpo_retv(cd);
  3925. WBUFW(buf, 0) = 0xdd;
  3926. WBUFW(buf, 2) = cd->users-1;
  3927. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3928. WBUFB(buf,28) = flag;
  3929. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3930. }
  3931. /// Opens a trade request window from char 'name'.
  3932. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3933. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3934. void clif_traderequest(map_session_data* sd, const char* name)
  3935. {
  3936. int fd = sd->fd;
  3937. #if PACKETVER < 6
  3938. WFIFOHEAD(fd,packet_len(0xe5));
  3939. WFIFOW(fd,0) = 0xe5;
  3940. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3941. WFIFOSET(fd,packet_len(0xe5));
  3942. #else
  3943. map_session_data* tsd = map_id2sd(sd->trade_partner);
  3944. if( !tsd ) return;
  3945. WFIFOHEAD(fd,packet_len(0x1f4));
  3946. WFIFOW(fd,0) = 0x1f4;
  3947. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3948. WFIFOL(fd,26) = tsd->status.char_id;
  3949. WFIFOW(fd,30) = tsd->status.base_level;
  3950. WFIFOSET(fd,packet_len(0x1f4));
  3951. #endif
  3952. }
  3953. /// Reply to a trade-request.
  3954. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3955. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3956. /// result:
  3957. /// 0 = Char is too far
  3958. /// 1 = Character does not exist
  3959. /// 2 = Trade failed
  3960. /// 3 = Accept
  3961. /// 4 = Cancel
  3962. /// 5 = Busy
  3963. void clif_tradestart(map_session_data* sd, uint8 type)
  3964. {
  3965. int fd = sd->fd;
  3966. map_session_data* tsd = map_id2sd(sd->trade_partner);
  3967. if( PACKETVER < 6 || !tsd ) {
  3968. WFIFOHEAD(fd,packet_len(0xe7));
  3969. WFIFOW(fd,0) = 0xe7;
  3970. WFIFOB(fd,2) = type;
  3971. WFIFOSET(fd,packet_len(0xe7));
  3972. } else {
  3973. WFIFOHEAD(fd,packet_len(0x1f5));
  3974. WFIFOW(fd,0) = 0x1f5;
  3975. WFIFOB(fd,2) = type;
  3976. WFIFOL(fd,3) = tsd->status.char_id;
  3977. WFIFOW(fd,7) = tsd->status.base_level;
  3978. WFIFOSET(fd,packet_len(0x1f5));
  3979. }
  3980. }
  3981. /// Notifies the client about an item from other player in current trade.
  3982. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3983. /// 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)
  3984. /// 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)
  3985. void clif_tradeadditem( map_session_data* sd, map_session_data* tsd, int index, int amount ){
  3986. nullpo_retv( sd );
  3987. nullpo_retv( tsd );
  3988. int fd = tsd->fd;
  3989. if( !session_isActive( fd ) ){
  3990. return;
  3991. }
  3992. struct PACKET_ZC_ADD_EXCHANGE_ITEM p;
  3993. if( index ){
  3994. index = server_index( index );
  3995. if( index >= MAX_INVENTORY || sd->inventory.u.items_inventory[index].nameid == 0 || sd->inventory_data[index] == nullptr ){
  3996. return;
  3997. }
  3998. p.itemId = client_nameid( sd->inventory.u.items_inventory[index].nameid );
  3999. #if PACKETVER >= 20100223
  4000. p.itemType = sd->inventory_data[index]->type;
  4001. #endif
  4002. p.identified = sd->inventory.u.items_inventory[index].identify;
  4003. p.damaged = sd->inventory.u.items_inventory[index].attribute;
  4004. p.refine = sd->inventory.u.items_inventory[index].refine;
  4005. clif_addcards( &p.slot, &sd->inventory.u.items_inventory[index] );
  4006. #if PACKETVER >= 20150226
  4007. clif_add_random_options( p.option_data, sd->inventory.u.items_inventory[index] );
  4008. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  4009. p.location = pc_equippoint_sub( sd, sd->inventory_data[index] );
  4010. p.look = sd->inventory_data[index]->look;
  4011. p.grade = sd->inventory.u.items_inventory[index].enchantgrade;
  4012. #endif
  4013. #endif
  4014. }else{
  4015. p = {};
  4016. }
  4017. p.packetType = HEADER_ZC_ADD_EXCHANGE_ITEM;
  4018. p.amount = amount;
  4019. clif_send( &p, sizeof( p ), &tsd->bl, SELF );
  4020. }
  4021. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  4022. /// 00ea <index>.W <result>.B
  4023. /// result:
  4024. /// 0 = success
  4025. /// 1 = overweight
  4026. /// 2 = trade canceled
  4027. void clif_tradeitemok(map_session_data& sd, int index, e_exitem_add_result result)
  4028. {
  4029. PACKET_ZC_ACK_ADD_EXCHANGE_ITEM p = {};
  4030. p.packetType = HEADER_ZC_ACK_ADD_EXCHANGE_ITEM;
  4031. p.index = client_index(index);
  4032. p.result = static_cast<uint8>(result);
  4033. clif_send(&p, sizeof(p), &sd.bl, SELF);
  4034. }
  4035. /// Notifies the client about finishing one side of the current trade.
  4036. /// 00ec <who>.B (ZC_CONCLUDE_EXCHANGE_ITEM)
  4037. /// who:
  4038. /// 0 = self
  4039. /// 1 = other player
  4040. void clif_tradedeal_lock( map_session_data& sd, bool who ){
  4041. PACKET_ZC_CONCLUDE_EXCHANGE_ITEM packet{};
  4042. packet.packetType = HEADER_ZC_CONCLUDE_EXCHANGE_ITEM;
  4043. packet.who = who;
  4044. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4045. }
  4046. /// Notifies the client about the trade being canceled.
  4047. /// 00ee (ZC_CANCEL_EXCHANGE_ITEM)
  4048. void clif_tradecancelled( map_session_data& sd ){
  4049. PACKET_ZC_CANCEL_EXCHANGE_ITEM packet{};
  4050. packet.packetType = HEADER_ZC_CANCEL_EXCHANGE_ITEM;
  4051. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4052. }
  4053. /// Result of a trade.
  4054. /// 00f0 <result>.B (ZC_EXEC_EXCHANGE_ITEM)
  4055. /// result:
  4056. /// 0 = success
  4057. /// 1 = failure
  4058. void clif_tradecompleted( map_session_data& sd ){
  4059. PACKET_ZC_EXEC_EXCHANGE_ITEM packet{};
  4060. packet.packetType = HEADER_ZC_EXEC_EXCHANGE_ITEM;
  4061. packet.result = 0;
  4062. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4063. }
  4064. /// Resets the trade window on the send side.
  4065. /// 00f1 (ZC_EXCHANGEITEM_UNDO)
  4066. /// NOTE: Unknown purpose. Items are not removed until the window is
  4067. /// refreshed (ex. by putting another item in there).
  4068. void clif_tradeundo( map_session_data& sd ){
  4069. PACKET_ZC_EXCHANGEITEM_UNDO packet{};
  4070. packet.packetType = HEADER_ZC_EXCHANGEITEM_UNDO;
  4071. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4072. }
  4073. /// Updates storage total amount.
  4074. /// 00f2 <current count>.W <max count>.W (ZC_NOTIFY_STOREITEM_COUNTINFO)
  4075. void clif_updatestorageamount( map_session_data& sd, uint16 amount, uint16 max_amount ){
  4076. PACKET_ZC_NOTIFY_STOREITEM_COUNTINFO packet{};
  4077. packet.packetType = HEADER_ZC_NOTIFY_STOREITEM_COUNTINFO;
  4078. packet.amount = amount;
  4079. packet.max_amount = max_amount;
  4080. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4081. }
  4082. /// Notifies the client of an item being added to the storage.
  4083. /// 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)
  4084. /// 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)
  4085. /// 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)
  4086. void clif_storageitemadded( map_session_data* sd, struct item* i, int index, int amount ){
  4087. nullpo_retv( sd );
  4088. nullpo_retv( i );
  4089. int fd = sd->fd;
  4090. if( !session_isActive( fd ) ){
  4091. return;
  4092. }
  4093. struct PACKET_ZC_ADD_ITEM_TO_STORE p;
  4094. p.packetType = HEADER_ZC_ADD_ITEM_TO_STORE; // Storage item added
  4095. p.index = client_storage_index( index ); // index
  4096. p.amount = amount; // amount
  4097. p.itemId = client_nameid( i->nameid ); // id
  4098. #if PACKETVER >= 5
  4099. p.itemType = itemtype( i->nameid ); //type
  4100. #endif
  4101. p.identified = i->identify; //identify flag
  4102. p.damaged = i->attribute; // attribute
  4103. p.refine = i->refine; //refine
  4104. clif_addcards( &p.slot, i );
  4105. #if PACKETVER_MAIN_NUM >= 20140813 || PACKETVER_RE_NUM >= 20140402 || defined(PACKETVER_ZERO)
  4106. clif_add_random_options( p.option_data, *i );
  4107. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20221024
  4108. p.grade = i->enchantgrade;
  4109. #endif
  4110. #endif
  4111. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4112. }
  4113. /// Notifies the client of an item being deleted from the storage.
  4114. /// 00f6 <index>.W <amount>.L (ZC_DELETE_ITEM_FROM_STORE)
  4115. void clif_storageitemremoved( map_session_data& sd, uint16 index, uint32 amount ){
  4116. PACKET_ZC_DELETE_ITEM_FROM_STORE packet{};
  4117. packet.packetType = HEADER_ZC_DELETE_ITEM_FROM_STORE;
  4118. packet.index = client_storage_index(index);
  4119. packet.amount = amount;
  4120. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4121. }
  4122. /// Closes storage.
  4123. /// 00f8 (ZC_CLOSE_STORE)
  4124. void clif_storageclose( map_session_data& sd ){
  4125. PACKET_ZC_CLOSE_STORE packet{};
  4126. packet.packetType = HEADER_ZC_CLOSE_STORE;
  4127. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4128. }
  4129. /// Notifies clients in an area of a player's souls.
  4130. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  4131. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  4132. /// 0b73 <id>.L <amount>.W (ZC_SOULENERGY)
  4133. void clif_soulball( map_session_data *sd, struct block_list* target, enum send_target send_target ){
  4134. #if PACKETVER_MAIN_NUM >= 20200414 || PACKETVER_RE_NUM >= 20200723 || PACKETVER_ZERO_NUM >= 20200506
  4135. struct PACKET_ZC_SOULENERGY p = {};
  4136. p.PacketType = HEADER_ZC_SOULENERGY;
  4137. #else
  4138. struct PACKET_ZC_SPIRITS p = {};
  4139. p.PacketType = HEADER_ZC_SPIRITS;
  4140. #endif
  4141. p.AID = sd->bl.id;
  4142. p.num = sd->soulball;
  4143. clif_send( &p, sizeof( p ), target == nullptr ? &sd->bl : target, send_target );
  4144. }
  4145. /*==========================================
  4146. * Server tells 'sd' player client the abouts of 'dstsd' player
  4147. *------------------------------------------*/
  4148. static void clif_getareachar_pc(map_session_data* sd,map_session_data* dstsd)
  4149. {
  4150. struct block_list *d_bl;
  4151. int i;
  4152. if( dstsd->chatID ) {
  4153. struct chat_data *cd = nullptr;
  4154. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4155. clif_dispchat(cd,sd->fd);
  4156. } else if( dstsd->state.vending )
  4157. clif_showvendingboard( *dstsd, SELF, &sd->bl );
  4158. else if( dstsd->state.buyingstore )
  4159. clif_buyingstore_entry( *dstsd, &sd->bl );
  4160. if(dstsd->spiritball > 0)
  4161. clif_spiritball( &dstsd->bl, &sd->bl, SELF );
  4162. clif_millenniumshield_single( *dstsd, *sd );
  4163. clif_spiritcharm_single( *dstsd, *sd );
  4164. if (dstsd->soulball > 0)
  4165. clif_soulball( dstsd, &sd->bl, SELF );
  4166. if (dstsd->servantball > 0)
  4167. clif_servantball( *dstsd, &sd->bl, SELF );
  4168. if (dstsd->abyssball > 0)
  4169. clif_abyssball( *dstsd, &sd->bl, SELF );
  4170. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4171. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4172. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4173. )
  4174. clif_hpmeter_single( *sd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp );
  4175. // display link (sd - dstsd) to sd
  4176. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4177. if( i < MAX_DEVOTION )
  4178. clif_devotion(&sd->bl, sd);
  4179. // display links (dstsd - devotees) to sd
  4180. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4181. if( i < MAX_DEVOTION )
  4182. clif_devotion(&dstsd->bl, sd);
  4183. // display link (dstsd - crusader) to sd
  4184. if( dstsd->sc.getSCE(SC_DEVOTION) && (d_bl = map_id2bl(dstsd->sc.getSCE(SC_DEVOTION)->val1)) != nullptr )
  4185. clif_devotion(d_bl, sd);
  4186. }
  4187. void clif_getareachar_unit( map_session_data* sd,struct block_list *bl ){
  4188. struct unit_data *ud;
  4189. struct view_data *vd;
  4190. bool option = false;
  4191. unsigned int option_val = 0;
  4192. vd = status_get_viewdata(bl);
  4193. if (!vd || vd->class_ == JT_INVISIBLE)
  4194. return;
  4195. // Hide NPC from Maya Purple card
  4196. if (clif_npc_mayapurple(bl))
  4197. return;
  4198. if( bl->type == BL_NPC && npc_is_hidden_dynamicnpc( *( (struct npc_data*)bl ), *sd ) ){
  4199. // Do not send anything
  4200. return;
  4201. }
  4202. ud = unit_bl2ud(bl);
  4203. if( ud && ud->walktimer != INVALID_TIMER ){
  4204. clif_set_unit_walking( *bl, sd, *ud, SELF );
  4205. }else{
  4206. clif_set_unit_idle( bl, false, SELF, &sd->bl );
  4207. }
  4208. if (vd->cloth_color)
  4209. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4210. if (vd->body_style)
  4211. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4212. switch (bl->type)
  4213. {
  4214. case BL_PC:
  4215. {
  4216. TBL_PC* tsd = (TBL_PC*)bl;
  4217. clif_getareachar_pc(sd, tsd);
  4218. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4219. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4220. else if(tsd->state.size==SZ_MEDIUM)
  4221. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4222. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4223. clif_sendbgemblem_single(sd->fd,tsd);
  4224. if ( tsd->status.robe )
  4225. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4226. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4227. clif_hat_effects( *sd, tsd->bl, SELF );
  4228. }
  4229. break;
  4230. case BL_MER: // Devotion Effects
  4231. if( ((TBL_MER*)bl)->devotion_flag )
  4232. clif_devotion(bl, sd);
  4233. break;
  4234. case BL_NPC:
  4235. {
  4236. TBL_NPC* nd = (TBL_NPC*)bl;
  4237. if( nd->chat_id )
  4238. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4239. if( nd->size == SZ_BIG )
  4240. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4241. else if( nd->size == SZ_MEDIUM )
  4242. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4243. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4244. clif_progressbar_npc(nd, sd);
  4245. }
  4246. break;
  4247. case BL_MOB:
  4248. {
  4249. TBL_MOB* md = (TBL_MOB*)bl;
  4250. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4251. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4252. else if(md->special_state.size==SZ_MEDIUM)
  4253. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4254. #if PACKETVER >= 20120404
  4255. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4256. int i;
  4257. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4258. if( md->dmglog[i].id == sd->status.char_id )
  4259. clif_monster_hp_bar(md, sd->fd);
  4260. }
  4261. #endif
  4262. }
  4263. break;
  4264. case BL_PET:
  4265. if (vd->head_bottom)
  4266. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4267. break;
  4268. }
  4269. }
  4270. //Modifies the type of damage according to status changes [Skotlex]
  4271. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4272. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4273. {
  4274. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4275. }
  4276. /*==========================================
  4277. * Estimates walk delay based on the damage criteria. [Skotlex]
  4278. *------------------------------------------*/
  4279. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4280. {
  4281. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4282. return 0;
  4283. if (bl->type == BL_PC) {
  4284. if (battle_config.pc_walk_delay_rate != 100)
  4285. delay = delay*battle_config.pc_walk_delay_rate/100;
  4286. } else
  4287. if (battle_config.walk_delay_rate != 100)
  4288. delay = delay*battle_config.walk_delay_rate/100;
  4289. if (div_ > 1) //Multi-hit skills mean higher delays.
  4290. delay += battle_config.multihit_delay*(div_-1);
  4291. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4292. }
  4293. /*========================================== [Playtester]
  4294. * Returns hallucination damage the client displays
  4295. *------------------------------------------*/
  4296. static int clif_hallucination_damage()
  4297. {
  4298. int digit = rnd() % 5 + 1;
  4299. switch (digit)
  4300. {
  4301. case 1:
  4302. return (rnd() % 10);
  4303. case 2:
  4304. return (rnd() % 100);
  4305. case 3:
  4306. return (rnd() % 1000);
  4307. case 4:
  4308. return (rnd() % 10000);
  4309. }
  4310. return (rnd() % 32767);
  4311. }
  4312. #define DEFAULT_ANIMATION_SPEED 432
  4313. /// Sends a 'damage' packet (src performs action on dst)
  4314. /// 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)
  4315. /// 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)
  4316. /// 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)
  4317. /// type:
  4318. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4319. /// 1 = pick up item
  4320. /// 2 = sit down
  4321. /// 3 = stand up
  4322. /// 4 = damage (endure)
  4323. /// 5 = (splash?)
  4324. /// 6 = (skill?)
  4325. /// 7 = (repeat damage?)
  4326. /// 8 = multi-hit damage
  4327. /// 9 = multi-hit damage (endure)
  4328. /// 10 = critical hit
  4329. /// 11 = lucky dodge
  4330. /// 12 = (touch skill?)
  4331. /// 13 = multi-hit critical
  4332. int clif_damage(struct block_list* src, struct block_list* dst, t_tick tick, int sdelay, int ddelay, int64 sdamage, int div, enum e_damage_type type, int64 sdamage2, bool spdamage)
  4333. {
  4334. unsigned char buf[34];
  4335. status_change *sc;
  4336. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4337. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4338. #if PACKETVER < 20071113
  4339. const int cmd = 0x8a;
  4340. int offset = 0;
  4341. #elif PACKETVER < 20131223
  4342. const int cmd = 0x2e1;
  4343. int offset = 2;
  4344. #else
  4345. const int cmd = 0x8c8;
  4346. int offset = 3;
  4347. #endif
  4348. nullpo_ret(src);
  4349. nullpo_ret(dst);
  4350. if (type != DMG_MULTI_HIT_CRITICAL)
  4351. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4352. sc = status_get_sc(dst);
  4353. if(sc && sc->count) {
  4354. if(sc->getSCE(SC_HALLUCINATION)) {
  4355. damage = clif_hallucination_damage();
  4356. if(damage2) damage2 = clif_hallucination_damage();
  4357. }
  4358. }
  4359. // Calculate what sdelay to send to the client so it applies damage at the same time as the server
  4360. if (battle_config.synchronize_damage && src->type == BL_MOB) {
  4361. // When a clif_damage packet is sent to the client it will also send "sdelay" (amotion) as value.
  4362. // The client however does not interpret this value as AttackMotion but incorrectly as an inverted
  4363. // animation speed modifier, with 432 standing for 1x animation speed.
  4364. // The client will ignore all values above 432, but lower values will speed up the animation.
  4365. // 216 for example means play the animation at double the speed. 108 is quadruple speed.
  4366. // Each monster has an attack animation and may define the frame in the attack animation on which
  4367. // it displays the damage and makes the target flinch / stop. If the damage frame is undefined,
  4368. // it instead displays the damage / flinch / stop at the beginning of the second to last frame.
  4369. // We define the time after which the damage frame shows at 1x speed as clientamotion.
  4370. uint16 clientamotion = std::max((uint16)1, status_get_clientamotion(src));
  4371. // Knowing when the damage frame happens in the animation allows us to synchronize the timing
  4372. // between client and server using the formula below.
  4373. sdelay = sdelay * DEFAULT_ANIMATION_SPEED / clientamotion;
  4374. // Hint: If amotion is larger than clientamotion this results in a value above 432 which makes the
  4375. // client display the attack at 1x speed. In this case we need to shorten the delay damage timer
  4376. // on the server to clientamotion ms instead (see battle_delay_damage).
  4377. sdelay = std::min(sdelay, DEFAULT_ANIMATION_SPEED);
  4378. }
  4379. WBUFW(buf,0) = cmd;
  4380. WBUFL(buf,2) = src->id;
  4381. WBUFL(buf,6) = dst->id;
  4382. WBUFL(buf,10) = client_tick(tick);
  4383. WBUFL(buf,14) = sdelay;
  4384. WBUFL(buf,18) = ddelay;
  4385. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4386. #if PACKETVER < 20071113
  4387. WBUFW(buf,22) = damage ? div : 0;
  4388. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4389. #else
  4390. WBUFL(buf, 22) = damage ? div : 0;
  4391. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4392. #endif
  4393. } else {
  4394. #if PACKETVER < 20071113
  4395. WBUFW(buf,22) = min(damage, INT16_MAX);
  4396. WBUFW(buf,27+offset) = damage2;
  4397. #else
  4398. WBUFL(buf,22) = damage;
  4399. WBUFL(buf,27+offset) = damage2;
  4400. #endif
  4401. }
  4402. #if PACKETVER >= 20131223
  4403. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4404. #endif
  4405. WBUFW(buf,24+offset) = div;
  4406. WBUFB(buf,26+offset) = type;
  4407. if(disguised(dst)) {
  4408. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4409. WBUFL(buf,6) = disguised_bl_id( dst->id );
  4410. clif_send(buf, packet_len(cmd), dst, SELF);
  4411. } else
  4412. clif_send(buf, packet_len(cmd), dst, AREA);
  4413. if(disguised(src)) {
  4414. WBUFL(buf,2) = disguised_bl_id( src->id );
  4415. if (disguised(dst))
  4416. WBUFL(buf,6) = dst->id;
  4417. #if PACKETVER < 20071113
  4418. if(damage > 0) WBUFW(buf,22) = -1;
  4419. if(damage2 > 0) WBUFW(buf,27) = -1;
  4420. #else
  4421. if(damage > 0) WBUFL(buf,22) = -1;
  4422. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4423. #endif
  4424. clif_send(buf,packet_len(cmd),src,SELF);
  4425. }
  4426. if(src == dst) {
  4427. unit_setdir(src, unit_getdir(src));
  4428. }
  4429. // In case this assignment is bypassed by DMG_MULTI_HIT_CRITICAL
  4430. type = clif_calc_delay(type, div, damage + damage2, ddelay);
  4431. //Return adjusted can't walk delay for further processing.
  4432. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4433. }
  4434. /*==========================================
  4435. * src picks up dst
  4436. *------------------------------------------*/
  4437. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4438. {
  4439. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4440. unsigned char buf[32];
  4441. nullpo_retv(src);
  4442. nullpo_retv(dst);
  4443. WBUFW(buf, 0) = 0x8a;
  4444. WBUFL(buf, 2) = src->id;
  4445. WBUFL(buf, 6) = dst->id;
  4446. WBUFB(buf,26) = 1;
  4447. clif_send(buf, packet_len(0x8a), src, AREA);
  4448. }
  4449. /*==========================================
  4450. * inform clients in area that `bl` is sitting
  4451. *------------------------------------------*/
  4452. void clif_sitting(struct block_list* bl)
  4453. {
  4454. unsigned char buf[32];
  4455. nullpo_retv(bl);
  4456. WBUFW(buf, 0) = 0x8a;
  4457. WBUFL(buf, 2) = bl->id;
  4458. WBUFB(buf,26) = 2;
  4459. clif_send(buf, packet_len(0x8a), bl, AREA);
  4460. if(disguised(bl)) {
  4461. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4462. clif_send(buf, packet_len(0x8a), bl, SELF);
  4463. }
  4464. }
  4465. /*==========================================
  4466. * inform clients in area that `bl` is standing
  4467. *------------------------------------------*/
  4468. void clif_standing(struct block_list* bl)
  4469. {
  4470. unsigned char buf[32];
  4471. nullpo_retv(bl);
  4472. WBUFW(buf, 0) = 0x8a;
  4473. WBUFL(buf, 2) = bl->id;
  4474. WBUFB(buf,26) = 3;
  4475. clif_send(buf, packet_len(0x8a), bl, AREA);
  4476. if(disguised(bl)) {
  4477. WBUFL(buf, 2) = disguised_bl_id( bl->id );
  4478. clif_send(buf, packet_len(0x8a), bl, SELF);
  4479. }
  4480. }
  4481. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4482. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4483. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4484. {
  4485. unsigned char buf[32];
  4486. WBUFW(buf,0) = 0x192;
  4487. WBUFW(buf,2) = x;
  4488. WBUFW(buf,4) = y;
  4489. WBUFW(buf,6) = type;
  4490. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4491. if( session_isActive(fd) )
  4492. {
  4493. WFIFOHEAD(fd,packet_len(0x192));
  4494. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4495. WFIFOSET(fd,packet_len(0x192));
  4496. }
  4497. else
  4498. {
  4499. struct block_list dummy_bl;
  4500. dummy_bl.type = BL_NUL;
  4501. dummy_bl.x = x;
  4502. dummy_bl.y = y;
  4503. dummy_bl.m = m;
  4504. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4505. }
  4506. }
  4507. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4508. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4509. void clif_getareachar_item( map_session_data* sd,struct flooritem_data* fitem ){
  4510. nullpo_retv( sd );
  4511. nullpo_retv( fitem );
  4512. struct PACKET_ZC_ITEM_ENTRY p;
  4513. p.packetType = HEADER_ZC_ITEM_ENTRY;
  4514. p.AID = fitem->bl.id;
  4515. p.itemId = client_nameid( fitem->item.nameid );
  4516. p.identify = fitem->item.identify;
  4517. p.x = fitem->bl.x;
  4518. p.y = fitem->bl.y;
  4519. p.amount = fitem->item.amount;
  4520. p.subX = fitem->subx;
  4521. p.subY = fitem->suby;
  4522. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  4523. }
  4524. /// Notifes client about Graffiti
  4525. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4526. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4527. unsigned char buf[128];
  4528. nullpo_retv(bl);
  4529. nullpo_retv(unit);
  4530. WBUFW(buf, 0) = 0x1c9;
  4531. WBUFL(buf, 2) = unit->bl.id;
  4532. WBUFL(buf, 6) = unit->group->src_id;
  4533. WBUFW(buf,10) = unit->bl.x;
  4534. WBUFW(buf,12) = unit->bl.y;
  4535. WBUFB(buf,14) = unit->group->unit_id;
  4536. WBUFB(buf,15) = 1;
  4537. WBUFB(buf,16) = 1;
  4538. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4539. clif_send(buf,packet_len(0x1c9),bl,target);
  4540. }
  4541. /// Notifies the client of a skill unit.
  4542. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4543. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4544. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4545. /// 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)
  4546. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4547. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4548. unsigned char buf[128];
  4549. nullpo_retv(bl);
  4550. nullpo_retv(unit);
  4551. if (bl->type == BL_PC)
  4552. fd = ((TBL_PC*)bl)->fd;
  4553. if (unit->group->state.guildaura)
  4554. return;
  4555. if (unit->group->state.song_dance&0x1 && unit->val2&(1 << UF_ENSEMBLE))
  4556. unit_id = unit->val2&(1 << UF_SONG) ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4557. else if (skill_get_unit_flag(unit->group->skill_id, UF_RANGEDSINGLEUNIT) && !(unit->val2 & (1 << UF_RANGEDSINGLEUNIT)))
  4558. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4559. else
  4560. unit_id = unit->group->unit_id;
  4561. if (!visible)
  4562. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4563. #if PACKETVER >= 3
  4564. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4565. clif_graffiti(bl, unit, target);
  4566. return;
  4567. }
  4568. #endif
  4569. #if PACKETVER <= 20120702
  4570. header = 0x011f;
  4571. //#if PACKETVER < 20110718
  4572. // header = 0x011f;
  4573. //#elif PACKETVER < 20121212
  4574. // header = 0x08c7;
  4575. #elif PACKETVER < 20130731
  4576. header = 0x099f;
  4577. #else
  4578. header = 0x09ca;
  4579. #endif
  4580. len = packet_len(header);
  4581. WBUFW(buf,pos) = header;
  4582. if (header != 0x011f) {
  4583. WBUFW(buf, pos+2) = len;
  4584. pos += 2;
  4585. }
  4586. WBUFL(buf,pos+2) = unit->bl.id;
  4587. WBUFL(buf,pos+6) = unit->group->src_id;
  4588. WBUFW(buf,pos+10) = unit->bl.x;
  4589. WBUFW(buf,pos+12) = unit->bl.y;
  4590. switch (header) {
  4591. case 0x011f:
  4592. WBUFB(buf,pos+14) = unit_id;
  4593. WBUFB(buf,pos+15) = visible;
  4594. break;
  4595. case 0x08c7:
  4596. WBUFB(buf,pos+14) = unit_id;
  4597. WBUFW(buf,pos+15) = unit->range;
  4598. WBUFB(buf,pos+17) = visible;
  4599. break;
  4600. case 0x099f:
  4601. WBUFL(buf,pos+14) = unit_id;
  4602. WBUFW(buf,pos+18) = unit->range;
  4603. WBUFB(buf,pos+20) = visible;
  4604. break;
  4605. case 0x09ca:
  4606. WBUFL(buf,pos+14) = unit_id;
  4607. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4608. WBUFB(buf,pos+19) = visible;
  4609. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4610. break;
  4611. }
  4612. clif_send(buf, len, bl, target);
  4613. if (unit->group->skill_id == WZ_ICEWALL)
  4614. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4615. }
  4616. /// 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)
  4617. void clif_skill_unit_test(struct block_list *bl, short x, short y, int unit_id, short range, short skill_lv) {
  4618. unsigned char buf[128];
  4619. nullpo_retv(bl);
  4620. WBUFW(buf, 0) = 0x09ca;
  4621. WBUFW(buf, 2) = packet_len(0x09ca);
  4622. WBUFL(buf, 4) = 1000;
  4623. WBUFL(buf, 8) = 2000;
  4624. WBUFW(buf, 12) = x;
  4625. WBUFW(buf, 14) = y;
  4626. WBUFL(buf, 16) = unit_id;
  4627. WBUFB(buf, 20) = (unsigned char)range;
  4628. WBUFB(buf, 21) = 1;
  4629. WBUFB(buf, 22) = (unsigned char)skill_lv;
  4630. clif_send(buf, packet_len(0x09ca), bl, AREA);
  4631. }
  4632. /// Server tells client to remove unit of id 'unit->bl.id'
  4633. /// 0120 <id>.L (ZC_SKILL_DISAPPEAR)
  4634. static void clif_clearchar_skillunit( skill_unit& unit, map_session_data& sd ){
  4635. PACKET_ZC_SKILL_DISAPPEAR packet{};
  4636. packet.packetType = HEADER_ZC_SKILL_DISAPPEAR;
  4637. packet.GID = unit.bl.id;
  4638. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  4639. if( unit.group && unit.group->skill_id == WZ_ICEWALL ){
  4640. clif_changemapcell( sd.fd, unit.bl.m, unit.bl.x, unit.bl.y, unit.val2, SELF );
  4641. }
  4642. }
  4643. /// Removes a skill unit.
  4644. /// 0120 <id>.L (ZC_SKILL_DISAPPEAR)
  4645. void clif_skill_delunit( skill_unit& unit ){
  4646. PACKET_ZC_SKILL_DISAPPEAR packet{};
  4647. packet.packetType = HEADER_ZC_SKILL_DISAPPEAR;
  4648. packet.GID = unit.bl.id;
  4649. clif_send( &packet, sizeof( packet ), &unit.bl, AREA );
  4650. }
  4651. /// Sent when an object gets ankle-snared.
  4652. /// 01ac <id>.L (ZC_SKILL_UPDATE)
  4653. /// Only affects units with class [139,153] client-side.
  4654. void clif_skillunit_update( block_list& bl ){
  4655. PACKET_ZC_SKILL_UPDATE packet{};
  4656. packet.packetType = HEADER_ZC_SKILL_UPDATE;
  4657. packet.GID = bl.id;
  4658. clif_send( &packet, sizeof( packet ), &bl, AREA );
  4659. }
  4660. /*==========================================
  4661. *
  4662. *------------------------------------------*/
  4663. static int clif_getareachar(struct block_list* bl,va_list ap)
  4664. {
  4665. map_session_data *sd;
  4666. nullpo_ret(bl);
  4667. sd=va_arg(ap,map_session_data*);
  4668. if (!clif_session_isValid(sd))
  4669. return 0;
  4670. switch(bl->type){
  4671. case BL_ITEM:
  4672. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4673. break;
  4674. case BL_SKILL:
  4675. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4676. break;
  4677. default:
  4678. if(&sd->bl == bl)
  4679. break;
  4680. clif_getareachar_unit(sd,bl);
  4681. break;
  4682. }
  4683. return 0;
  4684. }
  4685. /*==========================================
  4686. * tbl has gone out of view-size of bl
  4687. *------------------------------------------*/
  4688. int clif_outsight(struct block_list *bl,va_list ap)
  4689. {
  4690. struct block_list *tbl;
  4691. struct view_data *vd;
  4692. TBL_PC *sd, *tsd;
  4693. tbl=va_arg(ap,struct block_list*);
  4694. if(bl == tbl) return 0;
  4695. sd = BL_CAST(BL_PC, bl);
  4696. tsd = BL_CAST(BL_PC, tbl);
  4697. if (clif_session_isValid(tsd)) { //tsd has lost sight of the bl object.
  4698. nullpo_ret(bl);
  4699. switch(bl->type){
  4700. case BL_PC:
  4701. if(sd->vd.class_ != JT_INVISIBLE)
  4702. clif_clearunit_single( bl->id, CLR_OUTSIGHT, *tsd );
  4703. if(sd->chatID){
  4704. struct chat_data *cd;
  4705. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4706. if(cd->usersd[0]==sd)
  4707. clif_dispchat(cd,tsd->fd);
  4708. }
  4709. if(sd->state.vending)
  4710. clif_closevendingboard(bl,tsd->fd);
  4711. if(sd->state.buyingstore)
  4712. clif_buyingstore_disappear_entry( *sd, &tsd->bl );
  4713. break;
  4714. case BL_ITEM:
  4715. clif_clearflooritem( *reinterpret_cast<flooritem_data*>( bl ), tsd );
  4716. break;
  4717. case BL_SKILL:
  4718. clif_clearchar_skillunit( *((skill_unit *)bl), *tsd );
  4719. break;
  4720. case BL_NPC:
  4721. if(!(((TBL_NPC*)bl)->is_invisible))
  4722. clif_clearunit_single( bl->id, CLR_OUTSIGHT, *tsd );
  4723. break;
  4724. default:
  4725. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4726. clif_clearunit_single( bl->id, CLR_OUTSIGHT, *tsd );
  4727. break;
  4728. }
  4729. }
  4730. if (clif_session_isValid(sd)) { //sd is watching tbl go out of view.
  4731. nullpo_ret(tbl);
  4732. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4733. clif_clearchar_skillunit( *((skill_unit *)tbl), *sd );
  4734. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4735. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->is_invisible)))
  4736. clif_clearunit_single( tbl->id, CLR_OUTSIGHT, *sd );
  4737. }
  4738. return 0;
  4739. }
  4740. /*==========================================
  4741. * tbl has come into view of bl
  4742. *------------------------------------------*/
  4743. int clif_insight(struct block_list *bl,va_list ap)
  4744. {
  4745. struct block_list *tbl;
  4746. TBL_PC *sd, *tsd;
  4747. tbl=va_arg(ap,struct block_list*);
  4748. if (bl == tbl) return 0;
  4749. sd = BL_CAST(BL_PC, bl);
  4750. tsd = BL_CAST(BL_PC, tbl);
  4751. if (clif_session_isValid(tsd)) { //Tell tsd that bl entered into his view
  4752. switch(bl->type){
  4753. case BL_ITEM:
  4754. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4755. break;
  4756. case BL_SKILL:
  4757. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4758. break;
  4759. default:
  4760. clif_getareachar_unit(tsd,bl);
  4761. break;
  4762. }
  4763. }
  4764. if (clif_session_isValid(sd)) { //Tell sd that tbl walked into his view
  4765. clif_getareachar_unit(sd,tbl);
  4766. }
  4767. return 0;
  4768. }
  4769. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4770. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4771. void clif_skillinfoblock(map_session_data *sd)
  4772. {
  4773. int fd;
  4774. int i,len,id;
  4775. nullpo_retv(sd);
  4776. fd = sd->fd;
  4777. if (!session_isActive(fd))
  4778. return;
  4779. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4780. WFIFOW(fd,0) = 0x10f;
  4781. bool haveCallPartnerSkill = false;
  4782. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4783. {
  4784. if( (id = sd->status.skill[i].id) != 0 )
  4785. {
  4786. // workaround for bugreport:5348
  4787. if (len + 37 > 8192)
  4788. break;
  4789. // skip WE_CALLPARTNER and send it in special way
  4790. if (id == WE_CALLPARTNER) {
  4791. haveCallPartnerSkill = true;
  4792. continue;
  4793. }
  4794. WFIFOW(fd,len) = id;
  4795. WFIFOL(fd,len+2) = skill_get_inf(id);
  4796. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4797. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4798. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4799. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4800. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4801. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4802. else
  4803. WFIFOB(fd,len+36) = 0;
  4804. len += 37;
  4805. }
  4806. }
  4807. WFIFOW(fd,2)=len;
  4808. WFIFOSET(fd,len);
  4809. // adoption fix
  4810. if (haveCallPartnerSkill) {
  4811. clif_addskill(sd, WE_CALLPARTNER);
  4812. clif_skillinfo(sd, WE_CALLPARTNER, 0);
  4813. }
  4814. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4815. for ( ; i < MAX_SKILL; i++)
  4816. {
  4817. if( (id = sd->status.skill[i].id) != 0 && ( id != WE_CALLPARTNER || !haveCallPartnerSkill ) )
  4818. {
  4819. clif_addskill(sd, id);
  4820. clif_skillinfo(sd, id, 0);
  4821. }
  4822. }
  4823. }
  4824. /**
  4825. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4826. **/
  4827. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4828. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4829. void clif_addskill(map_session_data *sd, int skill_id)
  4830. {
  4831. nullpo_retv(sd);
  4832. int fd = sd->fd;
  4833. uint16 idx = skill_get_index(skill_id);
  4834. if (!session_isActive(fd) || !idx)
  4835. return;
  4836. if( sd->status.skill[idx].id <= 0 )
  4837. return;
  4838. WFIFOHEAD(fd, packet_len(0x111));
  4839. WFIFOW(fd,0) = 0x111;
  4840. WFIFOW(fd,2) = skill_id;
  4841. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4842. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4843. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4844. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4845. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4846. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4847. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4848. else
  4849. WFIFOB(fd,38) = 0;
  4850. WFIFOSET(fd,packet_len(0x111));
  4851. }
  4852. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4853. /// 0441 <skill id>.W
  4854. void clif_deleteskill(map_session_data *sd, int skill_id, bool skip_infoblock)
  4855. {
  4856. #if PACKETVER >= 20081217
  4857. nullpo_retv(sd);
  4858. int fd = sd->fd;
  4859. uint16 idx = skill_get_index(skill_id);
  4860. if (!session_isActive(fd) || !idx)
  4861. return;
  4862. WFIFOHEAD(fd,packet_len(0x441));
  4863. WFIFOW(fd,0) = 0x441;
  4864. WFIFOW(fd,2) = skill_id;
  4865. WFIFOSET(fd,packet_len(0x441));
  4866. #endif
  4867. #if PACKETVER_MAIN_NUM >= 20190807 || PACKETVER_RE_NUM >= 20190807 || PACKETVER_ZERO_NUM >= 20190918
  4868. if (!skip_infoblock)
  4869. #endif
  4870. clif_skillinfoblock(sd);
  4871. }
  4872. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4873. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4874. void clif_skillup(map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4875. nullpo_retv(sd);
  4876. int fd = sd->fd;
  4877. uint16 idx = skill_get_index(skill_id);
  4878. if (!session_isActive(fd) || !idx)
  4879. return;
  4880. WFIFOHEAD(fd, packet_len(0x10e));
  4881. WFIFOW(fd, 0) = 0x10e;
  4882. WFIFOW(fd, 2) = skill_id;
  4883. WFIFOW(fd, 4) = lv;
  4884. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4885. WFIFOW(fd, 8) = range;
  4886. WFIFOB(fd, 10) = upgradable;
  4887. WFIFOSET(fd, packet_len(0x10e));
  4888. }
  4889. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4890. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4891. void clif_skillinfo(map_session_data *sd,int skill_id, int inf)
  4892. {
  4893. nullpo_retv(sd);
  4894. const int fd = sd->fd;
  4895. uint16 idx = skill_get_index(skill_id);
  4896. if (!session_isActive(fd) || !idx)
  4897. return;
  4898. WFIFOHEAD(fd,packet_len(0x7e1));
  4899. WFIFOW(fd,0) = 0x7e1;
  4900. WFIFOW(fd,2) = skill_id;
  4901. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4902. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4903. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4904. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4905. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4906. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4907. else
  4908. WFIFOB(fd,14) = 0;
  4909. WFIFOSET(fd,packet_len(0x7e1));
  4910. }
  4911. void clif_skill_scale( struct block_list *bl, int src_id, int x, int y, uint16 skill_id, uint16 skill_lv, int casttime ){
  4912. #if PACKETVER >= 20151223
  4913. if( !battle_config.show_skill_scale ){
  4914. return;
  4915. }
  4916. struct PACKET_ZC_SKILL_SCALE p;
  4917. p.PacketType = skillscale;
  4918. p.AID = src_id;
  4919. p.skill_id = skill_id;
  4920. p.skill_lv = skill_lv;
  4921. p.x = x;
  4922. p.y = y;
  4923. p.casttime = casttime;
  4924. if( disguised( bl ) ){
  4925. clif_send( &p, sizeof( p ), bl, AREA_WOS );
  4926. p.AID = disguised_bl_id( bl->id );
  4927. clif_send( &p, sizeof( p ), bl, SELF );
  4928. }else{
  4929. clif_send( &p, sizeof( p ), bl, AREA );
  4930. }
  4931. #endif
  4932. }
  4933. /// Notifies clients in area, that an object is about to use a skill.
  4934. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4935. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4936. /// property:
  4937. /// 0 = Yellow cast aura
  4938. /// 1 = Water elemental cast aura
  4939. /// 2 = Earth elemental cast aura
  4940. /// 3 = Fire elemental cast aura
  4941. /// 4 = Wind elemental cast aura
  4942. /// 5 = Poison elemental cast aura
  4943. /// 6 = Holy elemental cast aura
  4944. /// ? = like 0
  4945. /// is disposable:
  4946. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4947. /// 1 = no text
  4948. void clif_skillcasting(struct block_list* bl, int src_id, int dst_id, int dst_x, int dst_y, uint16 skill_id, uint16 skill_lv, int property, int casttime)
  4949. {
  4950. #if PACKETVER < 20091124
  4951. const int cmd = 0x13e;
  4952. #else
  4953. const int cmd = 0x7fb;
  4954. #endif
  4955. unsigned char buf[32];
  4956. WBUFW(buf,0) = cmd;
  4957. WBUFL(buf,2) = src_id;
  4958. WBUFL(buf,6) = dst_id;
  4959. WBUFW(buf,10) = dst_x;
  4960. WBUFW(buf,12) = dst_y;
  4961. WBUFW(buf,14) = skill_id;
  4962. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4963. WBUFL(buf,20) = casttime;
  4964. #if PACKETVER >= 20091124
  4965. WBUFB(buf,24) = 0; // isDisposable
  4966. #endif
  4967. if (disguised(bl)) {
  4968. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4969. WBUFL(buf,2) = disguised_bl_id( src_id );
  4970. clif_send(buf,packet_len(cmd), bl, SELF);
  4971. } else
  4972. clif_send(buf,packet_len(cmd), bl, AREA);
  4973. if( skill_get_inf2( skill_id, INF2_SHOWSCALE ) ){
  4974. clif_skill_scale( bl, src_id, bl->x, bl->y, skill_id, skill_lv, casttime );
  4975. }
  4976. }
  4977. /// Notifies clients in area, that an object canceled casting.
  4978. /// 01b9 <id>.L (ZC_DISPEL)
  4979. void clif_skillcastcancel( block_list& bl ){
  4980. PACKET_ZC_DISPEL packet{};
  4981. packet.packetType = HEADER_ZC_DISPEL;
  4982. packet.gid = bl.id;
  4983. clif_send( &packet, sizeof(PACKET_ZC_DISPEL), &bl, AREA );
  4984. }
  4985. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4986. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4987. /// num (only used when skill id = NV_BASIC and cause = 0):
  4988. /// 0 = "skill failed" MsgStringTable[159]
  4989. /// 1 = "no emotions" MsgStringTable[160]
  4990. /// 2 = "no sit" MsgStringTable[161]
  4991. /// 3 = "no chat" MsgStringTable[162]
  4992. /// 4 = "no party" MsgStringTable[163]
  4993. /// 5 = "no shout" MsgStringTable[164]
  4994. /// 6 = "no PKing" MsgStringTable[165]
  4995. /// 7 = "no alligning" MsgStringTable[383]
  4996. /// ? = ignored
  4997. /// cause:
  4998. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4999. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  5000. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  5001. /// "skill failed" MsgStringTable[204] (otherwise)
  5002. /// ... = @see enum useskill_fail_cause
  5003. /// ? = ignored
  5004. ///
  5005. /// if(result!=0) doesn't display any of the previous messages
  5006. /// Note: when this packet is received an unknown flag is always set to 0,
  5007. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  5008. void clif_skill_fail( map_session_data& sd, uint16 skill_id, enum useskill_fail_cause cause, int btype, t_itemid itemId ){
  5009. if(battle_config.display_skill_fail&1)
  5010. return; //Disable all skill failed messages
  5011. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd.state.showdelay)
  5012. return; //Disable delay failed messages
  5013. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  5014. return;
  5015. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  5016. return;
  5017. struct PACKET_ZC_ACK_TOUSESKILL p;
  5018. p.packetType = HEADER_ZC_ACK_TOUSESKILL;
  5019. p.skillId = skill_id;
  5020. p.btype = btype;
  5021. p.itemId = itemId;
  5022. p.flag = 0; // 0 - failed
  5023. p.cause = cause;
  5024. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  5025. }
  5026. /// Skill cooldown display icon.
  5027. /// 043d <skill ID>.W <tick>.L (ZC_SKILL_POSTDELAY)
  5028. void clif_skill_cooldown( map_session_data &sd, uint16 skill_id, t_tick tick ){
  5029. #if PACKETVER_MAIN_NUM >= 20081112 || PACKETVER_RE_NUM >= 20081111 || defined(PACKETVER_ZERO)
  5030. PACKET_ZC_SKILL_POSTDELAY packet{};
  5031. packet.PacketType = HEADER_ZC_SKILL_POSTDELAY;
  5032. packet.SKID = skill_id;
  5033. packet.DelayTM = client_tick(tick);
  5034. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5035. #endif
  5036. }
  5037. /// Skill attack effect and damage.
  5038. /// 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)
  5039. /// 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)
  5040. int clif_skill_damage(struct block_list *src,struct block_list *dst,t_tick tick,int sdelay,int ddelay,int64 sdamage,int div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  5041. {
  5042. unsigned char buf[64];
  5043. status_change *sc;
  5044. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  5045. nullpo_ret(src);
  5046. nullpo_ret(dst);
  5047. type = clif_calc_delay(type,div,damage,ddelay);
  5048. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  5049. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5050. damage = clif_hallucination_damage();
  5051. }
  5052. #if PACKETVER < 3
  5053. WBUFW(buf,0)=0x114;
  5054. WBUFW(buf,2)=skill_id;
  5055. WBUFL(buf,4)=src->id;
  5056. WBUFL(buf,8)=dst->id;
  5057. WBUFL(buf,12)=client_tick(tick);
  5058. WBUFL(buf,16)=sdelay;
  5059. WBUFL(buf,20)=ddelay;
  5060. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5061. WBUFW(buf,24)=damage?div:0;
  5062. } else {
  5063. WBUFW(buf,24)=damage;
  5064. }
  5065. WBUFW(buf,26)=skill_lv;
  5066. WBUFW(buf,28)=div;
  5067. WBUFB(buf,30)=type;
  5068. if (disguised(dst)) {
  5069. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  5070. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5071. clif_send(buf,packet_len(0x114),dst,SELF);
  5072. } else
  5073. clif_send(buf,packet_len(0x114),dst,AREA);
  5074. if(disguised(src)) {
  5075. WBUFL(buf,4)=disguised_bl_id(src->id);
  5076. if (disguised(dst))
  5077. WBUFL(buf,8)=dst->id;
  5078. if(damage > 0)
  5079. WBUFW(buf,24)=-1;
  5080. clif_send(buf,packet_len(0x114),src,SELF);
  5081. }
  5082. #else
  5083. WBUFW(buf,0)=0x1de;
  5084. WBUFW(buf,2)=skill_id;
  5085. WBUFL(buf,4)=src->id;
  5086. WBUFL(buf,8)=dst->id;
  5087. WBUFL(buf,12)=client_tick(tick);
  5088. WBUFL(buf,16)=sdelay;
  5089. WBUFL(buf,20)=ddelay;
  5090. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5091. WBUFL(buf,24)=damage?div:0;
  5092. } else {
  5093. WBUFL(buf,24)=damage;
  5094. }
  5095. WBUFW(buf,28)=skill_lv;
  5096. WBUFW(buf,30)=div;
  5097. // For some reason, late 2013 and newer clients have
  5098. // a issue that causes players and monsters to endure
  5099. // type 6 (ACTION_SKILL) skills. So we have to do a small
  5100. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  5101. #if PACKETVER < 20131223
  5102. WBUFB(buf,32)=type;
  5103. #else
  5104. WBUFB(buf,32)=( type == DMG_SINGLE ) ? DMG_MULTI_HIT : type;
  5105. #endif
  5106. if (disguised(dst)) {
  5107. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  5108. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5109. clif_send(buf,packet_len(0x1de),dst,SELF);
  5110. } else
  5111. clif_send(buf,packet_len(0x1de),dst,AREA);
  5112. if(disguised(src)) {
  5113. WBUFL(buf,4)=disguised_bl_id(src->id);
  5114. if (disguised(dst))
  5115. WBUFL(buf,8)=dst->id;
  5116. if(damage > 0)
  5117. WBUFL(buf,24)=-1;
  5118. clif_send(buf,packet_len(0x1de),src,SELF);
  5119. }
  5120. #endif
  5121. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5122. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5123. }
  5124. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  5125. /// 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
  5126. /*
  5127. int clif_skill_damage2(struct block_list *src,struct block_list *dst,t_tick tick,int sdelay,int ddelay,int damage,int div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  5128. {
  5129. unsigned char buf[64];
  5130. status_change *sc;
  5131. nullpo_ret(src);
  5132. nullpo_ret(dst);
  5133. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  5134. type = clif_calc_delay(type,div,damage,ddelay);
  5135. sc = status_get_sc(dst);
  5136. if(sc && sc->count) {
  5137. if(sc->getSCE(SC_HALLUCINATION) && damage)
  5138. damage = clif_hallucination_damage();
  5139. }
  5140. WBUFW(buf,0)=0x115;
  5141. WBUFW(buf,2)=skill_id;
  5142. WBUFL(buf,4)=src->id;
  5143. WBUFL(buf,8)=dst->id;
  5144. WBUFL(buf,12)=client_tick(tick);
  5145. WBUFL(buf,16)=sdelay;
  5146. WBUFL(buf,20)=ddelay;
  5147. WBUFW(buf,24)=dst->x;
  5148. WBUFW(buf,26)=dst->y;
  5149. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  5150. WBUFW(buf,28)=damage?div:0;
  5151. } else {
  5152. WBUFW(buf,28)=damage;
  5153. }
  5154. WBUFW(buf,30)=skill_lv;
  5155. WBUFW(buf,32)=div;
  5156. WBUFB(buf,34)=type;
  5157. clif_send(buf,packet_len(0x115),src,AREA);
  5158. if(disguised(src)) {
  5159. WBUFL(buf,4)=disguised_bl_id(src->id);
  5160. if(damage > 0)
  5161. WBUFW(buf,28)=-1;
  5162. clif_send(buf,packet_len(0x115),src,SELF);
  5163. }
  5164. if (disguised(dst)) {
  5165. WBUFL(buf,8)=disguised_bl_id(dst->id);
  5166. if (disguised(src))
  5167. WBUFL(buf,4)=src->id;
  5168. else if(damage > 0)
  5169. WBUFW(buf,28)=-1;
  5170. clif_send(buf,packet_len(0x115),dst,SELF);
  5171. }
  5172. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  5173. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  5174. }
  5175. */
  5176. /// Non-damaging skill effect
  5177. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5178. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5179. bool clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, t_tick tick)
  5180. {
  5181. unsigned char buf[17];
  5182. #if PACKETVER < 20130731
  5183. const int cmd = 0x11a;
  5184. #else
  5185. const int cmd = 0x9cb;
  5186. #endif
  5187. int offset = 0;
  5188. bool success = ( tick != 0 );
  5189. nullpo_ret(dst);
  5190. WBUFW(buf,0) = cmd;
  5191. WBUFW(buf,2) = skill_id;
  5192. #if PACKETVER < 20130731
  5193. WBUFW(buf,4) = min(heal, INT16_MAX);
  5194. #else
  5195. WBUFL(buf,4) = min(heal, INT32_MAX);
  5196. offset += 2;
  5197. #endif
  5198. WBUFL(buf,6+offset) = dst->id;
  5199. WBUFL(buf,10+offset) = src ? src->id : 0;
  5200. WBUFB(buf,14+offset) = success;
  5201. if (disguised(dst)) {
  5202. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5203. WBUFL(buf,6+offset) = disguised_bl_id(dst->id);
  5204. clif_send(buf, packet_len(cmd), dst, SELF);
  5205. } else
  5206. clif_send(buf, packet_len(cmd), dst, AREA);
  5207. if(src && disguised(src)) {
  5208. WBUFL(buf,10+offset) = disguised_bl_id(src->id);
  5209. if (disguised(dst))
  5210. WBUFL(buf,6+offset) = dst->id;
  5211. clif_send(buf, packet_len(cmd), src, SELF);
  5212. }
  5213. return success;
  5214. }
  5215. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5216. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5217. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,t_tick tick)
  5218. {
  5219. unsigned char buf[32];
  5220. nullpo_retv(src);
  5221. WBUFW(buf,0)=0x117;
  5222. WBUFW(buf,2)=skill_id;
  5223. WBUFL(buf,4)=src->id;
  5224. WBUFW(buf,8)=val;
  5225. WBUFW(buf,10)=x;
  5226. WBUFW(buf,12)=y;
  5227. WBUFL(buf,14)=client_tick(tick);
  5228. if(disguised(src)) {
  5229. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5230. WBUFL(buf,4)=disguised_bl_id(src->id);
  5231. clif_send(buf,packet_len(0x117),src,SELF);
  5232. } else
  5233. clif_send(buf,packet_len(0x117),src,AREA);
  5234. }
  5235. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5236. /// 011c <skill id>.W { <map name>.16B }*4
  5237. void clif_skill_warppoint( map_session_data* sd, uint16 skill_id, uint16 skill_lv, const char* map1, const char* map2, const char* map3, const char* map4 ){
  5238. int fd;
  5239. nullpo_retv(sd);
  5240. fd = sd->fd;
  5241. WFIFOHEAD(fd,packet_len(0x11c));
  5242. WFIFOW(fd,0) = 0x11c;
  5243. WFIFOW(fd,2) = skill_id;
  5244. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5245. if( strcmp( "", map1 ) != 0 ){
  5246. mapindex_getmapname_ext( map1, WFIFOCP( fd, 4 ) );
  5247. }
  5248. if( strcmp( "", map2 ) != 0 ){
  5249. mapindex_getmapname_ext( map2, WFIFOCP( fd, 20 ) );
  5250. }
  5251. if( strcmp( "", map3 ) != 0 ){
  5252. mapindex_getmapname_ext( map3, WFIFOCP( fd, 36 ) );
  5253. }
  5254. if( strcmp( "", map4 ) != 0 ){
  5255. mapindex_getmapname_ext( map4, WFIFOCP( fd, 52 ) );
  5256. }
  5257. WFIFOSET(fd,packet_len(0x11c));
  5258. sd->menuskill_id = skill_id;
  5259. if (skill_id == AL_WARP) {
  5260. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5261. sd->state.workinprogress = WIP_DISABLE_ALL;
  5262. } else
  5263. sd->menuskill_val = skill_lv;
  5264. }
  5265. /// Memo message.
  5266. /// 011e <type>.B (ZC_ACK_REMEMBER_WARPPOINT)
  5267. /// type:
  5268. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5269. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5270. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5271. ///
  5272. /// @param sd Who receives the message
  5273. /// @param type What message
  5274. void clif_skill_memomessage( map_session_data& sd, e_ack_remember_warppoint_result result ){
  5275. PACKET_ZC_ACK_REMEMBER_WARPPOINT packet{};
  5276. packet.packetType = HEADER_ZC_ACK_REMEMBER_WARPPOINT;
  5277. packet.type = static_cast<decltype(packet.type)>(result);
  5278. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5279. }
  5280. /// Teleport message.
  5281. /// 0189 <type>.W (ZC_NOTIFY_MAPINFO)
  5282. /// type:
  5283. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5284. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5285. /// 2 = "This skill cannot be used in this area"
  5286. /// 3 = "This item cannot be used in this area"
  5287. ///
  5288. /// @param sd Who receives the message
  5289. /// @param type What message
  5290. void clif_skill_teleportmessage( map_session_data& sd, e_notify_mapinfo_result result ){
  5291. PACKET_ZC_NOTIFY_MAPINFO packet{};
  5292. packet.packetType = HEADER_ZC_NOTIFY_MAPINFO;
  5293. packet.type = static_cast<decltype(packet.type)>(result);
  5294. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5295. }
  5296. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5297. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5298. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5299. void clif_skill_estimation(map_session_data *sd,struct block_list *dst)
  5300. {
  5301. struct status_data *status;
  5302. unsigned char buf[64];
  5303. int i, fix;
  5304. nullpo_retv(sd);
  5305. nullpo_retv(dst);
  5306. if( dst->type != BL_MOB )
  5307. return;
  5308. status = status_get_status_data(dst);
  5309. WBUFW(buf, 0)=0x18c;
  5310. WBUFW(buf, 2)=status_get_class(dst);
  5311. WBUFW(buf, 4)=status_get_lv(dst);
  5312. WBUFW(buf, 6)=status->size;
  5313. WBUFL(buf, 8)=status->hp;
  5314. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5315. +(battle_config.estimation_type&2?status->def2:0);
  5316. WBUFW(buf,14)=status->race;
  5317. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5318. +(battle_config.estimation_type&2?status->mdef2:0);
  5319. WBUFW(buf,18)= status->def_ele;
  5320. for(i=0;i<9;i++)
  5321. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5322. WBUFB(buf,20+i)= (unsigned char)((fix=elemental_attribute_db.getAttribute(status->ele_lv, i+1, status->def_ele))<0?0:fix);
  5323. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5324. }
  5325. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5326. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5327. /// material id:
  5328. /// unused by the client
  5329. void clif_skill_produce_mix_list( map_session_data *sd, int skill_id, int trigger ){
  5330. nullpo_retv(sd);
  5331. int fd = sd->fd;
  5332. if( !session_isActive( fd ) ){
  5333. return;
  5334. }
  5335. if (sd->menuskill_id == skill_id)
  5336. return; //Avoid resending the menu twice or more times...
  5337. if (skill_id == GC_CREATENEWPOISON)
  5338. skill_id = GC_RESEARCHNEWPOISON;
  5339. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5340. struct PACKET_ZC_MAKABLEITEMLIST *p = (struct PACKET_ZC_MAKABLEITEMLIST *)WFIFOP( fd, 0 );
  5341. p->packetType = 0x18d;
  5342. int count = 0;
  5343. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5344. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5345. (skill_id <= 0 || skill_produce_db[i].req_skill == skill_id)
  5346. )
  5347. {
  5348. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5349. p->items[count].material[0] = 0;
  5350. p->items[count].material[1] = 0;
  5351. p->items[count].material[2] = 0;
  5352. count++;
  5353. }
  5354. }
  5355. p->packetLength = static_cast<decltype(p->packetLength)>( sizeof( struct PACKET_ZC_MAKABLEITEMLIST ) + count * sizeof( struct PACKET_ZC_MAKABLEITEMLIST_sub ) );
  5356. WFIFOSET( fd, p->packetLength );
  5357. if( count > 0 ){
  5358. sd->menuskill_id = skill_id;
  5359. sd->menuskill_val = trigger;
  5360. return;
  5361. }
  5362. }
  5363. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5364. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5365. /// mk type:
  5366. /// 1 = cooking
  5367. /// 2 = arrow
  5368. /// 3 = elemental
  5369. /// 4 = GN_MIX_COOKING
  5370. /// 5 = GN_MAKEBOMB
  5371. /// 6 = GN_S_PHARMACY
  5372. /// 7 = MT_M_MACHINE - Unconfirmed
  5373. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  5374. void clif_cooking_list( map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type ){
  5375. nullpo_retv( sd );
  5376. // Avoid resending the menu twice or more times...
  5377. if( sd->menuskill_id == skill_id ){
  5378. return;
  5379. }
  5380. int fd = sd->fd;
  5381. if( !session_isActive( fd ) ){
  5382. return;
  5383. }
  5384. WFIFOHEAD( fd, sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + MAX_SKILL_PRODUCE_DB * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5385. struct PACKET_ZC_MAKINGITEM_LIST *p = (struct PACKET_ZC_MAKINGITEM_LIST *)WFIFOP( fd, 0 );
  5386. p->packetType = 0x25a;
  5387. p->makeItem = list_type; // list type
  5388. int count = 0;
  5389. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  5390. if( !skill_can_produce_mix( sd, skill_produce_db[i].nameid, trigger, qty ) ){
  5391. continue;
  5392. }
  5393. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  5394. count++;
  5395. }
  5396. if( count > 0 || skill_id == AM_PHARMACY ){
  5397. p->packetLength = static_cast<decltype(p->packetLength)>( sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5398. WFIFOSET( fd, p->packetLength );
  5399. sd->menuskill_id = skill_id;
  5400. sd->menuskill_val = trigger;
  5401. sd->menuskill_val2 = qty; // amount.
  5402. }else{
  5403. clif_menuskill_clear(sd);
  5404. #if PACKETVER >= 20090922
  5405. clif_msg_skill( sd, skill_id, MSI_SKILL_INVENTORY_KINDCNT_OVER);
  5406. #else
  5407. p->packetLength = static_cast<decltype(p->packetLength)>( sizeof( struct PACKET_ZC_MAKINGITEM_LIST ) + count * sizeof( struct PACKET_ZC_MAKINGITEM_LIST_sub ) );
  5408. WFIFOSET( fd, p->packetLength );
  5409. #endif
  5410. }
  5411. }
  5412. /// Notifies clients of a status change.
  5413. /// 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)]
  5414. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5415. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5416. /// @param bl Sends packet to clients around this object
  5417. /// @param id ID of object that has this effect
  5418. /// @param type Status icon see enum efst_type
  5419. /// @param flag 1:Active, 0:Deactive
  5420. /// @param tick Duration in ms
  5421. /// @param val1
  5422. /// @param val2
  5423. /// @param val3
  5424. void clif_status_change_sub(struct block_list *bl, int id, int type, int flag, t_tick tick, int val1, int val2, int val3, enum send_target target_type)
  5425. {
  5426. unsigned char buf[32];
  5427. if (type == EFST_BLANK) //It shows nothing on the client...
  5428. return;
  5429. if (type == EFST_POSTDELAY && tick == 0)
  5430. return;
  5431. nullpo_retv(bl);
  5432. // Statuses with an infinite duration, but still needs a duration sent to display properly.
  5433. if (type == EFST_LUNARSTANCE || type == EFST_UNIVERSESTANCE || type == EFST_SUNSTANCE || type == EFST_STARSTANCE)
  5434. tick = 200;
  5435. #if PACKETVER >= 20120618
  5436. if (flag && battle_config.display_status_timers)
  5437. WBUFW(buf,0) = 0x983;
  5438. else
  5439. #elif PACKETVER >= 20090121
  5440. if (flag && battle_config.display_status_timers)
  5441. WBUFW(buf,0) = 0x43f;
  5442. else
  5443. #endif
  5444. WBUFW(buf,0) = 0x196;
  5445. WBUFW(buf,2) = type;
  5446. WBUFL(buf,4) = id;
  5447. WBUFB(buf,8) = flag;
  5448. #if PACKETVER >= 20120618
  5449. if (flag && battle_config.display_status_timers) {
  5450. if (tick <= 0)
  5451. tick = 9999; // this is indeed what official servers do
  5452. WBUFL(buf,9) = client_tick(tick);/* at this stage remain and total are the same value I believe */
  5453. WBUFL(buf,13) = client_tick(tick);
  5454. WBUFL(buf,17) = val1;
  5455. WBUFL(buf,21) = val2;
  5456. WBUFL(buf,25) = val3;
  5457. }
  5458. #elif PACKETVER >= 20090121
  5459. if (flag && battle_config.display_status_timers) {
  5460. if (tick <= 0)
  5461. tick = 9999; // this is indeed what official servers do
  5462. WBUFL(buf,9) = client_tick(tick);
  5463. WBUFL(buf,13) = val1;
  5464. WBUFL(buf,17) = val2;
  5465. WBUFL(buf,21) = val3;
  5466. }
  5467. #endif
  5468. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5469. }
  5470. /* Sends status effect to clients around the bl
  5471. * @param bl Object that has the effect
  5472. * @param type Status icon see enum efst_type
  5473. * @param flag 1:Active, 0:Deactive
  5474. * @param tick Duration in ms
  5475. * @param val1
  5476. * @param val2
  5477. * @param val3
  5478. */
  5479. void clif_status_change(struct block_list *bl, int type, int flag, t_tick tick, int val1, int val2, int val3) {
  5480. map_session_data *sd = nullptr;
  5481. if (type == EFST_BLANK) //It shows nothing on the client...
  5482. return;
  5483. if (type == EFST_POSTDELAY && tick == 0)
  5484. return;
  5485. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5486. return;
  5487. #if !( PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 )
  5488. // Older clients display normal riding icon.
  5489. if (type == EFST_MADOGEAR)
  5490. type = EFST_RIDING;
  5491. #endif
  5492. nullpo_retv(bl);
  5493. sd = BL_CAST(BL_PC, bl);
  5494. // Check if current bl type is in the returned bitmask and only send status changes that actually matter to the client
  5495. if (!(status_efst_get_bl_type(static_cast<efst_type>(type)) & bl->type))
  5496. return;
  5497. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5498. }
  5499. /**
  5500. * Send any active EFST to those around.
  5501. * @param tbl: Unit to send the packet to
  5502. * @param bl: Objects walking into view
  5503. * @param target: Client send type
  5504. */
  5505. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5506. unsigned char i;
  5507. struct sc_display_entry **sc_display;
  5508. unsigned char sc_display_count;
  5509. bool spheres_sent;
  5510. nullpo_retv(bl);
  5511. switch( bl->type ){
  5512. case BL_PC: {
  5513. map_session_data* sd = (map_session_data*)bl;
  5514. sc_display = sd->sc_display;
  5515. sc_display_count = sd->sc_display_count;
  5516. spheres_sent = !sd->state.connect_new;
  5517. }
  5518. break;
  5519. case BL_NPC: {
  5520. struct npc_data* nd = (struct npc_data*)bl;
  5521. sc_display = nd->sc_display;
  5522. sc_display_count = nd->sc_display_count;
  5523. spheres_sent = true;
  5524. }
  5525. break;
  5526. default:
  5527. return;
  5528. }
  5529. for (i = 0; i < sc_display_count; i++) {
  5530. enum sc_type type = sc_display[i]->type;
  5531. status_change *sc = status_get_sc(bl);
  5532. const struct TimerData *td = (sc && sc->getSCE(type) ? get_timer(sc->getSCE(type)->timer) : nullptr);
  5533. t_tick tick = 0;
  5534. if (td)
  5535. tick = DIFF_TICK(td->tick, gettick());
  5536. // Status changes that need special handling
  5537. switch( type ){
  5538. case SC_SPHERE_1:
  5539. case SC_SPHERE_2:
  5540. case SC_SPHERE_3:
  5541. case SC_SPHERE_4:
  5542. case SC_SPHERE_5:
  5543. if( spheres_sent ){
  5544. target = AREA_WOS;
  5545. }
  5546. break;
  5547. case SC_HELLS_PLANT:
  5548. if( sc && sc->getSCE(type) ){
  5549. tick = sc->getSCE(type)->val4;
  5550. }
  5551. break;
  5552. }
  5553. #if PACKETVER > 20120418
  5554. 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);
  5555. #else
  5556. 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);
  5557. #endif
  5558. }
  5559. }
  5560. /// Notifies the client when a player enters the screen with an active EFST.
  5561. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5562. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5563. void clif_efst_status_change(struct block_list *bl, int tid, enum send_target target, int type, t_tick tick, int val1, int val2, int val3) {
  5564. #if PACKETVER >= 20111108
  5565. unsigned char buf[32];
  5566. #if PACKETVER >= 20120618
  5567. const int cmd = 0x984;
  5568. #elif PACKETVER >= 20111108
  5569. const int cmd = 0x8ff;
  5570. #endif
  5571. int offset = 0;
  5572. if (type == EFST_BLANK)
  5573. return;
  5574. nullpo_retv(bl);
  5575. if (tick <= 0)
  5576. tick = 9999;
  5577. WBUFW(buf,offset + 0) = cmd;
  5578. WBUFL(buf,offset + 2) = tid;
  5579. WBUFW(buf,offset + 6) = type;
  5580. #if PACKETVER >= 20111108
  5581. WBUFL(buf,offset + 8) = client_tick(tick); // Set remaining status duration [exneval]
  5582. #if PACKETVER >= 20120618
  5583. WBUFL(buf,offset + 12) = client_tick(tick);
  5584. offset += 4;
  5585. #endif
  5586. WBUFL(buf,offset + 12) = val1;
  5587. WBUFL(buf,offset + 16) = val2;
  5588. WBUFL(buf,offset + 20) = val3;
  5589. #endif
  5590. clif_send(buf,packet_len(cmd),bl,target);
  5591. #endif
  5592. }
  5593. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5594. /// 008e <packet len>.W <message>.?B
  5595. void clif_displaymessage(const int fd, const char* mes)
  5596. {
  5597. nullpo_retv(mes);
  5598. if( session_isActive( fd ) ){
  5599. char *message, *line;
  5600. message = aStrdup(mes);
  5601. line = strtok(message, "\n");
  5602. while(line != nullptr) {
  5603. #if PACKETVER == 20141022
  5604. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5605. /** so we redirect to ZC_NPC_CHAT **/
  5606. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5607. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5608. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5609. if (len > 0) {
  5610. WFIFOHEAD(fd, 13 + len);
  5611. WFIFOW(fd, 0) = 0x2C1;
  5612. WFIFOW(fd, 2) = 13 + len;
  5613. WFIFOL(fd, 4) = 0;
  5614. WFIFOL(fd, 8) = color;
  5615. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5616. WFIFOSET(fd, WFIFOW(fd, 2));
  5617. }
  5618. #else
  5619. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5620. int16 len;
  5621. len = static_cast<decltype(len)>( strnlen(line, CHAT_SIZE_MAX) );
  5622. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5623. WFIFOHEAD(fd, 5 + len);
  5624. WFIFOW(fd,0) = 0x8e;
  5625. WFIFOW(fd,2) = 5 + len; // 4 + len + nullptr teminate
  5626. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5627. WFIFOSET(fd, 5 + len);
  5628. }
  5629. #endif
  5630. line = strtok(nullptr, "\n");
  5631. }
  5632. aFree(message);
  5633. }
  5634. }
  5635. /// Send broadcast message in yellow or blue without font formatting.
  5636. /// 009a <packet len>.W <message>.?B (ZC_BROADCAST)
  5637. void clif_broadcast(struct block_list* bl, const char* mes, size_t len, int type, enum send_target target)
  5638. {
  5639. nullpo_retv(mes);
  5640. if (len < 2)
  5641. return;
  5642. PACKET_ZC_BROADCAST* p = reinterpret_cast<PACKET_ZC_BROADCAST*>( packet_buffer );
  5643. p->packetType = HEADER_ZC_BROADCAST;
  5644. p->PacketLength = sizeof( *p );
  5645. if( ( type&BC_BLUE ) != 0 ){
  5646. // If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5647. const char* color = "blue";
  5648. size_t length = strlen( color );
  5649. strcpy( p->message, color );
  5650. p->PacketLength += static_cast<decltype(p->PacketLength)>( length );
  5651. strncpy( &p->message[length], mes, len );
  5652. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5653. }else if( ( type&BC_WOE ) != 0 ){
  5654. // If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5655. const char* color = "ssss";
  5656. size_t length = strlen( color );
  5657. strcpy( p->message, color );
  5658. p->PacketLength += static_cast<decltype(p->PacketLength)>( length );
  5659. strncpy( &p->message[length], mes, len );
  5660. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5661. }else{
  5662. strncpy( p->message, mes, len );
  5663. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5664. }
  5665. clif_send( p, p->PacketLength, bl, target );
  5666. }
  5667. /*==========================================
  5668. * Displays a message on a 'bl' to all it's nearby clients
  5669. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5670. *------------------------------------------*/
  5671. void clif_GlobalMessage( block_list& bl, const char* message, enum send_target target ){
  5672. nullpo_retv(message);
  5673. int16 len = (int16)( strlen( message ) + 1 );
  5674. if( len > CHAT_SIZE_MAX ) {
  5675. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%" PRId16 ").\n", message, len);
  5676. len = CHAT_SIZE_MAX;
  5677. }
  5678. PACKET_ZC_NOTIFY_CHAT* p = reinterpret_cast<PACKET_ZC_NOTIFY_CHAT*>( packet_buffer );
  5679. p->PacketType = HEADER_ZC_NOTIFY_CHAT;
  5680. p->PacketLength = sizeof( *p );
  5681. p->GID = bl.id;
  5682. safestrncpy( p->Message, message, len );
  5683. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5684. clif_send( p, p->PacketLength, &bl, target );
  5685. }
  5686. /// Send broadcast message with font formatting.
  5687. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B (ZC_BROADCAST2)
  5688. void clif_broadcast2(struct block_list* bl, const char* mes, size_t len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target)
  5689. {
  5690. nullpo_retv(mes);
  5691. if (len < 2)
  5692. return;
  5693. PACKET_ZC_BROADCAST2* p = reinterpret_cast<PACKET_ZC_BROADCAST2*>( packet_buffer );
  5694. p->packetType = HEADER_ZC_BROADCAST2;
  5695. p->PacketLength = sizeof( *p );
  5696. p->fontColor = fontColor;
  5697. p->fontType = fontType;
  5698. p->fontSize = fontSize;
  5699. p->fontAlign = fontAlign;
  5700. p->fontY = fontY;
  5701. strncpy( p->message, mes, len );
  5702. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  5703. clif_send( p, p->PacketLength, bl, target );
  5704. }
  5705. /*
  5706. * Display *msg to all *users in channel
  5707. */
  5708. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5709. DBIterator *iter;
  5710. map_session_data *user;
  5711. unsigned short msg_len = 0, len = 0;
  5712. unsigned char buf[CHAT_SIZE_MAX];
  5713. if (!channel || !msg)
  5714. return;
  5715. msg_len = (unsigned short)(strlen(msg) + 1);
  5716. if( msg_len > sizeof(buf)-12 ) {
  5717. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5718. msg_len = sizeof(buf)-12;
  5719. }
  5720. WBUFW(buf,0) = 0x2C1;
  5721. WBUFW(buf,2) = (len = msg_len + 12);
  5722. WBUFL(buf,4) = 0;
  5723. WBUFL(buf,8) = color;
  5724. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5725. iter = db_iterator(channel->users);
  5726. for( user = (map_session_data *)dbi_first(iter); dbi_exists(iter); user = (map_session_data *)dbi_next(iter) ) {
  5727. clif_send(buf, len, &user->bl, SELF);
  5728. }
  5729. dbi_destroy(iter);
  5730. }
  5731. /// Displays heal effect.
  5732. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5733. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5734. /// var id:
  5735. /// 5 = HP (SP_HP)
  5736. /// 7 = SP (SP_SP)
  5737. /// ? = ignored
  5738. void clif_heal( map_session_data& sd, int32 type, uint32 val ) {
  5739. PACKET_ZC_RECOVERY packet{};
  5740. packet.packetType = HEADER_ZC_RECOVERY;
  5741. packet.type = static_cast<decltype(packet.type)>(type);
  5742. packet.amount = std::min( static_cast<decltype(packet.amount)>( val ), std::numeric_limits<decltype(packet.amount)>::max() );
  5743. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5744. }
  5745. /// Displays resurrection effect.
  5746. /// 0148 <id>.L <type>.W (ZC_RESURRECTION)
  5747. /// type:
  5748. /// ignored
  5749. void clif_resurrection( block_list& bl ){
  5750. PACKET_ZC_RESURRECTION packet{};
  5751. packet.packetType = HEADER_ZC_RESURRECTION;
  5752. packet.gid = bl.id;
  5753. packet.type = 0;
  5754. clif_send( &packet, sizeof( packet ), &bl, AREA );
  5755. if (disguised(&bl)) {
  5756. clif_spawn(&bl);
  5757. }
  5758. }
  5759. /// Sets the map property
  5760. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5761. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5762. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5763. {
  5764. #if PACKETVER >= 20121010
  5765. short cmd = 0x99b;
  5766. unsigned char buf[8];
  5767. #else
  5768. short cmd = 0x199;
  5769. unsigned char buf[4];
  5770. #endif
  5771. WBUFW(buf,0)=cmd;
  5772. WBUFW(buf,2)=property;
  5773. #if PACKETVER >= 20121010
  5774. struct map_data *mapdata = map_getmapdata(bl->m);
  5775. map_session_data *sd = BL_CAST(BL_PC, bl);
  5776. WBUFL(buf,4) = ((mapdata->getMapFlag(MF_PVP) || (sd && sd->duel_group > 0))<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5777. ((mapdata->getMapFlag(MF_BATTLEGROUND) || mapdata_flag_gvg2(mapdata))<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5778. ((mapdata->getMapFlag(MF_BATTLEGROUND) || mapdata_flag_gvg2(mapdata))<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5779. ((mapdata->getMapFlag(MF_FORCEMINEFFECT) || mapdata_flag_gvg2(mapdata))<<3)| // USE_SIMPLE_EFFECT - Forces simpler skill effects, like /mineffect command
  5780. ((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
  5781. ((mapdata->getMapFlag(MF_PVP))<<5)| // COUNT_PK - Show the PvP counter
  5782. ((mapdata->getMapFlag(MF_PARTYLOCK))<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5783. ((mapdata->getMapFlag(MF_BATTLEGROUND))<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5784. ((mapdata->getMapFlag(MF_NOCOSTUME))<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5785. ((!mapdata->getMapFlag(MF_NOUSECART))<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5786. ((!mapdata->getMapFlag(MF_NOSUNMOONSTARMIRACLE))<<10); // SUNMOONSTAR_MIRACLE - Allows Star Gladiator's Miracle to activate
  5787. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5788. #endif
  5789. clif_send(buf,packet_len(cmd),bl,t);
  5790. }
  5791. /// Set the map type.
  5792. /// 01d6 <type>.W (ZC_NOTIFY_MAPPROPERTY2)
  5793. void clif_map_type( map_session_data& sd, e_map_type type ){
  5794. PACKET_ZC_NOTIFY_MAPPROPERTY2 packet{};
  5795. packet.packetType = HEADER_ZC_NOTIFY_MAPPROPERTY2;
  5796. packet.type = static_cast<decltype(packet.type)>(type);
  5797. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5798. }
  5799. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5800. /// 019a <id>.L <ranking>.L <total>.L
  5801. void clif_pvpset(map_session_data *sd,int pvprank,int pvpnum,int type)
  5802. {
  5803. if(type == 2) {
  5804. int fd = sd->fd;
  5805. WFIFOHEAD(fd,packet_len(0x19a));
  5806. WFIFOW(fd,0) = 0x19a;
  5807. WFIFOL(fd,2) = sd->bl.id;
  5808. WFIFOL(fd,6) = pvprank;
  5809. WFIFOL(fd,10) = pvpnum;
  5810. WFIFOSET(fd,packet_len(0x19a));
  5811. } else {
  5812. unsigned char buf[32];
  5813. WBUFW(buf,0) = 0x19a;
  5814. WBUFL(buf,2) = sd->bl.id;
  5815. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5816. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5817. else
  5818. WBUFL(buf,6) = pvprank;
  5819. WBUFL(buf,10) = pvpnum;
  5820. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5821. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5822. else if(!type)
  5823. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5824. else
  5825. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5826. }
  5827. }
  5828. /*==========================================
  5829. *
  5830. *------------------------------------------*/
  5831. void clif_map_property_mapall(int map_idx, enum map_property property)
  5832. {
  5833. struct block_list bl;
  5834. bl.id = 0;
  5835. bl.type = BL_NUL;
  5836. bl.m = map_idx;
  5837. clif_map_property( &bl, property, ALL_SAMEMAP );
  5838. }
  5839. /// Notifies the client about the result of a refine attempt.
  5840. /// 0188 <result>.W <index>.W <refine>.W (ZC_ACK_ITEMREFINING)
  5841. /// result:
  5842. /// 0 = success
  5843. /// 1 = failure
  5844. /// 2 = downgrade
  5845. /// 3 = failure (?)
  5846. void clif_refine( map_session_data& sd, uint16 index, e_ack_itemrefining result ){
  5847. PACKET_ZC_ACK_ITEMREFINING packet{};
  5848. packet.packetType = HEADER_ZC_ACK_ITEMREFINING;
  5849. packet.result = static_cast<decltype(packet.result)>(result);
  5850. packet.index = client_index( index );
  5851. packet.value = static_cast<decltype(packet.value)>( sd.inventory.u.items_inventory[index].refine );
  5852. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5853. }
  5854. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5855. /// 0223 <result>.L <nameid>.W
  5856. /// result:
  5857. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5858. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5859. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5860. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5861. void clif_upgrademessage( map_session_data* sd, int result, t_itemid item_id ){
  5862. struct PACKET_ZC_ACK_WEAPONREFINE p;
  5863. p.packetType = HEADER_ZC_ACK_WEAPONREFINE;
  5864. p.result = result;
  5865. p.itemId = client_nameid( item_id );
  5866. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  5867. }
  5868. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5869. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5870. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5871. void clif_wis_message(map_session_data* sd, const char* nick, const char* mes, size_t mes_len, int gmlvl){
  5872. PACKET_ZC_WHISPER* p = reinterpret_cast<PACKET_ZC_WHISPER*>( packet_buffer );
  5873. p->PacketType = HEADER_ZC_WHISPER;
  5874. p->PacketLength = sizeof( *p );
  5875. safestrncpy( p->sender, nick, NAME_LENGTH );
  5876. safestrncpy( p->message, mes, mes_len );
  5877. p->PacketLength += static_cast<decltype( p->PacketLength )>( mes_len );
  5878. #if PACKETVER >= 20091104
  5879. map_session_data* ssd = map_nick2sd(nick, false);
  5880. // If it is not a message from the server or a player from another map-server
  5881. if( ssd != nullptr ){
  5882. gmlvl = pc_get_group_level(ssd);
  5883. }
  5884. p->isAdmin = (gmlvl == 99) ? 1 : 0;
  5885. #if PACKETVER_MAIN_NUM >= 20131204 || PACKETVER_RE_NUM >= 20131120 || defined(PACKETVER_ZERO)
  5886. if( ssd != nullptr ){
  5887. p->senderGID = ssd->bl.id;
  5888. }else{
  5889. p->senderGID = 0;
  5890. }
  5891. #endif
  5892. #endif
  5893. clif_send( p, p->PacketLength, &sd->bl, SELF );
  5894. }
  5895. /// Inform the player about the result of his whisper action
  5896. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5897. /// 09df <result>.B <CID>.L (ZC_ACK_WHISPER02).
  5898. /// result:
  5899. /// 0 = success to send whisper
  5900. /// 1 = target character is not loged in
  5901. /// 2 = ignored by target
  5902. /// 3 = everyone ignored by target
  5903. void clif_wis_end( map_session_data& sd, e_ack_whisper result ){
  5904. PACKET_ZC_ACK_WHISPER packet{};
  5905. packet.packetType = HEADER_ZC_ACK_WHISPER;
  5906. packet.result = static_cast<decltype(packet.result)>(result);
  5907. #if PACKETVER >= 20131223
  5908. packet.CID = sd.status.char_id;
  5909. #endif
  5910. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5911. }
  5912. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5913. /// 0194 <char id>.L <name>.24B
  5914. /// 0af7 <flag>.W <char id>.L <name>.24B
  5915. void clif_solved_charname(int fd, int charid, const char* name)
  5916. {
  5917. #if PACKETVER >= 20180221
  5918. WFIFOHEAD(fd,packet_len(0xaf7));
  5919. WFIFOW(fd,0) = 0xaf7;
  5920. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5921. WFIFOL(fd,4) = charid;
  5922. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5923. WFIFOSET(fd,packet_len(0x0af7));
  5924. #else
  5925. WFIFOHEAD(fd,packet_len(0x194));
  5926. WFIFOW(fd,0)=0x194;
  5927. WFIFOL(fd,2)=charid;
  5928. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5929. WFIFOSET(fd,packet_len(0x194));
  5930. #endif
  5931. }
  5932. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5933. /// 017b <packet len>.W { <name id>.W }*
  5934. void clif_use_card(map_session_data *sd,int idx)
  5935. {
  5936. int i,c,ep;
  5937. int fd=sd->fd;
  5938. nullpo_retv(sd);
  5939. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5940. return;
  5941. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5942. return; //Avoid parsing invalid item indexes (no card/no item)
  5943. ep=sd->inventory_data[idx]->equip;
  5944. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5945. WFIFOW(fd,0)=0x17b;
  5946. for(i=c=0;i<MAX_INVENTORY;i++){
  5947. int j;
  5948. if(sd->inventory_data[i] == nullptr)
  5949. continue;
  5950. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5951. continue;
  5952. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5953. continue;
  5954. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5955. continue;
  5956. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5957. continue;
  5958. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5959. continue;
  5960. 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.
  5961. continue;
  5962. ARR_FIND( 0, sd->inventory_data[i]->slots, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5963. if( j == sd->inventory_data[i]->slots ) // No room
  5964. continue;
  5965. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5966. continue;
  5967. WFIFOW(fd,4+c*2)=i+2;
  5968. c++;
  5969. }
  5970. if( !c ) return; // no item is available for card insertion
  5971. WFIFOW(fd,2)=4+c*2;
  5972. WFIFOSET(fd,WFIFOW(fd,2));
  5973. }
  5974. /// Notifies the client about the result of item carding/composition.
  5975. /// 017d <equip index>.W <card index>.W <result>.B (ZC_ACK_ITEMCOMPOSITION)
  5976. /// result:
  5977. /// 0 = success
  5978. /// 1 = failure
  5979. void clif_insert_card( map_session_data& sd, int32 idx_equip, int32 idx_card, bool failure ){
  5980. PACKET_ZC_ACK_ITEMCOMPOSITION packet{};
  5981. packet.packetType = HEADER_ZC_ACK_ITEMCOMPOSITION;
  5982. packet.equipIndex = client_index( idx_equip );
  5983. packet.cardIndex = client_index( idx_card );
  5984. packet.result = failure;
  5985. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  5986. }
  5987. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5988. /// 0177 <packet len>.W { <index>.W }*
  5989. void clif_item_identify_list(map_session_data *sd)
  5990. {
  5991. int i,c;
  5992. int fd;
  5993. nullpo_retv(sd);
  5994. fd=sd->fd;
  5995. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5996. WFIFOW(fd,0)=0x177;
  5997. for(i=c=0;i<MAX_INVENTORY;i++){
  5998. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5999. WFIFOW(fd,c*2+4)=client_index(i);
  6000. c++;
  6001. }
  6002. }
  6003. if(c > 0) {
  6004. WFIFOW(fd,2)=c*2+4;
  6005. WFIFOSET(fd,WFIFOW(fd,2));
  6006. sd->menuskill_id = MC_IDENTIFY;
  6007. sd->menuskill_val = c;
  6008. sd->state.workinprogress = WIP_DISABLE_ALL;
  6009. }
  6010. }
  6011. /// Notifies the client about the result of a item identify request.
  6012. /// 0179 <index>.W <result>.B (ZC_ACK_ITEMIDENTIFY)
  6013. /// result:
  6014. /// 0 = success
  6015. /// 1 = failure
  6016. void clif_item_identified( map_session_data& sd, int32 idx, bool failure ){
  6017. PACKET_ZC_ACK_ITEMIDENTIFY packet{};
  6018. packet.packetType = HEADER_ZC_ACK_ITEMIDENTIFY;
  6019. packet.index = client_index( idx );
  6020. packet.result = failure;
  6021. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6022. }
  6023. /// Presents a list of items that can be repaired.
  6024. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_REPAIRITEMLIST)
  6025. void clif_item_repair_list( map_session_data& sd, map_session_data& dstsd, uint16 lv ){
  6026. PACKET_ZC_REPAIRITEMLIST* p = reinterpret_cast<PACKET_ZC_REPAIRITEMLIST*>( packet_buffer );
  6027. p->packetType = HEADER_ZC_REPAIRITEMLIST;
  6028. p->packetLength = sizeof( *p );
  6029. size_t c = 0;
  6030. for( size_t i = 0; i < MAX_INVENTORY; i++ ){
  6031. 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)){
  6032. p->items[c].index = static_cast<decltype( p->items[0].index )>( i );
  6033. p->items[c].itemId = client_nameid( dstsd.inventory.u.items_inventory[i].nameid );
  6034. p->items[c].refine = dstsd.inventory.u.items_inventory[i].refine;
  6035. clif_addcards( &p->items[c].slot, &dstsd.inventory.u.items_inventory[i] );
  6036. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  6037. c++;
  6038. }
  6039. }
  6040. if( c > 0 ){
  6041. clif_send( p, p->packetLength, &sd.bl, SELF );
  6042. sd.menuskill_id = BS_REPAIRWEAPON;
  6043. sd.menuskill_val = dstsd.bl.id;
  6044. sd.menuskill_val2 = lv;
  6045. }else{
  6046. clif_skill_fail( sd, sd.ud.skill_id );
  6047. }
  6048. }
  6049. /// Notifies the client about the result of a item repair request.
  6050. /// 01fe <index>.W <result>.B (ZC_ACK_ITEMREPAIR)
  6051. /// index:
  6052. /// ignored (inventory index)
  6053. /// result:
  6054. /// 0 = Item repair success.
  6055. /// 1 = Item repair failure.
  6056. void clif_item_repaireffect( map_session_data& sd, int32 idx, bool failure ){
  6057. PACKET_ZC_ACK_ITEMREPAIR packet{};
  6058. packet.packetType = HEADER_ZC_ACK_ITEMREPAIR;
  6059. packet.index = client_index( idx );
  6060. packet.result = failure;
  6061. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6062. }
  6063. /// Displays a message, that an equipment got damaged.
  6064. /// 02bb <equip location>.W <account id>.L (ZC_EQUIPITEM_DAMAGED)
  6065. void clif_item_damaged( map_session_data& sd, uint16 position ){
  6066. PACKET_ZC_EQUIPITEM_DAMAGED packet{};
  6067. packet.packetType = HEADER_ZC_EQUIPITEM_DAMAGED;
  6068. packet.equipLocation = position;
  6069. packet.GID = sd.bl.id;
  6070. // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  6071. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6072. }
  6073. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  6074. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6075. void clif_item_refine_list( map_session_data& sd ){
  6076. PACKET_ZC_NOTIFY_WEAPONITEMLIST* p = reinterpret_cast<PACKET_ZC_NOTIFY_WEAPONITEMLIST*>( packet_buffer );
  6077. p->packetType = HEADER_ZC_NOTIFY_WEAPONITEMLIST;
  6078. p->packetLength = sizeof( *p );
  6079. uint16 skill_lv = pc_checkskill( &sd, WS_WEAPONREFINE );
  6080. int refine_item[MAX_WEAPON_LEVEL];
  6081. refine_item[0] = pc_search_inventory( &sd, ITEMID_PHRACON );
  6082. refine_item[1] = pc_search_inventory( &sd, ITEMID_EMVERETARCON );
  6083. refine_item[2] = refine_item[3] = pc_search_inventory( &sd, ITEMID_ORIDECON );
  6084. #ifdef RENEWAL
  6085. refine_item[4] = -1;
  6086. #endif
  6087. int count = 0;
  6088. for( int i = 0; i < MAX_INVENTORY; i++ ){
  6089. if( sd.inventory.u.items_inventory[i].nameid > 0 && sd.inventory.u.items_inventory[i].refine < skill_lv &&
  6090. sd.inventory_data[i] != nullptr && sd.inventory_data[i]->type == IT_WEAPON &&
  6091. sd.inventory.u.items_inventory[i].identify && sd.inventory_data[i]->weapon_level >= 1 &&
  6092. refine_item[sd.inventory_data[i]->weapon_level - 1] != -1 && !( sd.inventory.u.items_inventory[i].equip & EQP_ARMS ) ){
  6093. p->items[count].index = client_index( i );
  6094. p->items[count].itemId = client_nameid( sd.inventory.u.items_inventory[i].nameid );
  6095. p->items[count].refine = sd.inventory.u.items_inventory[i].refine;
  6096. clif_addcards( &p->items[count].slot, &sd.inventory.u.items_inventory[i] );
  6097. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  6098. count++;
  6099. }
  6100. }
  6101. clif_send( p, p->packetLength, &sd.bl, SELF );
  6102. if( count > 0 ){
  6103. sd.menuskill_id = WS_WEAPONREFINE;
  6104. sd.menuskill_val = skill_lv;
  6105. }
  6106. }
  6107. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  6108. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  6109. void clif_item_skill( map_session_data *sd, uint16 skill_id, uint16 skill_lv ){
  6110. nullpo_retv( sd );
  6111. struct PACKET_ZC_AUTORUN_SKILL p;
  6112. p.packetType = HEADER_ZC_AUTORUN_SKILL;
  6113. p.skill_id = skill_id;
  6114. p.skill_type = skill_get_inf( skill_id );
  6115. p.skill_lv = skill_lv;
  6116. p.skill_sp = skill_get_sp( skill_id, skill_lv );
  6117. p.skill_range = skill_get_range2( &sd->bl, skill_id, skill_lv, false );
  6118. safestrncpy( p.skill_name, skill_get_name( skill_id ), NAME_LENGTH );
  6119. p.up_flag = false;
  6120. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6121. }
  6122. /// Adds an item to character's cart.
  6123. /// 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)
  6124. /// 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)
  6125. /// 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)
  6126. void clif_cart_additem( map_session_data *sd, int n, int amount ){
  6127. nullpo_retv( sd );
  6128. int fd = sd->fd;
  6129. if( !session_isActive( fd ) ){
  6130. return;
  6131. }
  6132. if( n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid == 0 ){
  6133. return;
  6134. }
  6135. struct PACKET_ZC_ADD_ITEM_TO_CART p;
  6136. p.packetType = HEADER_ZC_ADD_ITEM_TO_CART;
  6137. p.index = client_index( n );
  6138. p.amount = amount;
  6139. p.itemId = client_nameid( sd->cart.u.items_cart[n].nameid );
  6140. #if PACKETVER >= 5
  6141. p.itemType = itemdb_type( sd->cart.u.items_cart[n].nameid );
  6142. #endif
  6143. p.identified = sd->cart.u.items_cart[n].identify;
  6144. p.damaged = sd->cart.u.items_cart[n].attribute;
  6145. p.refine = sd->cart.u.items_cart[n].refine;
  6146. clif_addcards( &p.slot, &sd->cart.u.items_cart[n] );
  6147. #if PACKETVER >= 20150226
  6148. clif_add_random_options( p.option_data, sd->cart.u.items_cart[n] );
  6149. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6150. p.grade = sd->cart.u.items_cart[n].enchantgrade;
  6151. #endif
  6152. #endif
  6153. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6154. }
  6155. /// Acknowledge an item have been added to cart
  6156. /// 012c <result>.B (ZC_ACK_ADDITEM_TO_CART)
  6157. /// result:
  6158. /// 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  6159. /// 1 = ADDITEM_TO_CART_FAIL_COUNT
  6160. void clif_cart_additem_ack( map_session_data& sd, e_ack_additem_to_cart flag ){
  6161. PACKET_ZC_ACK_ADDITEM_TO_CART packet{};
  6162. packet.packetType = HEADER_ZC_ACK_ADDITEM_TO_CART;
  6163. packet.result = static_cast<decltype(packet.result)>(flag);
  6164. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6165. }
  6166. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6167. void clif_bank_open( map_session_data& sd ){
  6168. #if PACKETVER >= 20130717
  6169. struct PACKET_ZC_ACK_OPEN_BANKING p = {};
  6170. p.packetType = HEADER_ZC_ACK_OPEN_BANKING;
  6171. p.unknown = 0;
  6172. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6173. #endif
  6174. }
  6175. /*
  6176. * Request to Open the banking system
  6177. * 09B6 <aid>L (CZ_REQ_OPEN_BANKING)
  6178. */
  6179. void clif_parse_BankOpen(int fd, map_session_data* sd) {
  6180. #if PACKETVER >= 20130717
  6181. PACKET_CZ_REQ_OPEN_BANKING* p = (PACKET_CZ_REQ_OPEN_BANKING*)RFIFOP( fd, 0 );
  6182. //TODO check if preventing trade or stuff like that
  6183. //also mark something in case char ain't available for saving, should we check now ?
  6184. nullpo_retv(sd);
  6185. if( !battle_config.feature_banking ) {
  6186. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6187. return;
  6188. }
  6189. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6190. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6191. return;
  6192. }
  6193. else {
  6194. if(sd->status.account_id == p->AID){
  6195. sd->state.banking = 1;
  6196. //request save ?
  6197. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6198. //on succes open bank ?
  6199. clif_bank_open( *sd );
  6200. }
  6201. }
  6202. #endif
  6203. }
  6204. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6205. void clif_bank_close( map_session_data& sd ){
  6206. #if PACKETVER >= 20130717
  6207. struct PACKET_ZC_ACK_CLOSE_BANKING p = {};
  6208. p.packetType = HEADER_ZC_ACK_CLOSE_BANKING;
  6209. p.unknown = 0;
  6210. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6211. #endif
  6212. }
  6213. /*
  6214. * Request to close the banking system
  6215. * 09B8 <aid>L (CZ_REQ_CLOSE_BANKING)
  6216. */
  6217. void clif_parse_BankClose(int fd, map_session_data* sd) {
  6218. #if PACKETVER >= 20130717
  6219. PACKET_CZ_REQ_CLOSE_BANKING* p = (PACKET_CZ_REQ_CLOSE_BANKING*)RFIFOP( fd, 0 );
  6220. nullpo_retv(sd);
  6221. if( !battle_config.feature_banking ) {
  6222. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6223. //still allow to go trough to not stuck player if we have disable it while they was in
  6224. }
  6225. if(sd->status.account_id == p->AID){
  6226. sd->state.banking = 0;
  6227. clif_bank_close( *sd );
  6228. }
  6229. #endif
  6230. }
  6231. /*
  6232. * Display how much we got in bank (I suppose)
  6233. * 09A6 <Bank_Vault>Q <Reason>W (ZC_BANKING_CHECK)
  6234. */
  6235. void clif_Bank_Check( map_session_data& sd ){
  6236. #if PACKETVER >= 20130717
  6237. struct PACKET_ZC_BANKING_CHECK p = {};
  6238. p.packetType = HEADER_ZC_BANKING_CHECK;
  6239. p.money = sd.bank_vault;
  6240. p.reason = 0;
  6241. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6242. #endif
  6243. }
  6244. /*
  6245. * Requesting the data in bank
  6246. * 09AB <aid>L (CZ_REQ_BANKING_CHECK)
  6247. */
  6248. void clif_parse_BankCheck(int fd, map_session_data* sd) {
  6249. #if PACKETVER >= 20130717
  6250. PACKET_CZ_REQ_BANKING_CHECK* p = (PACKET_CZ_REQ_BANKING_CHECK*)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) //since we have it let check it for extra security
  6262. clif_Bank_Check( *sd );
  6263. }
  6264. #endif
  6265. }
  6266. /*
  6267. * Acknowledge of deposit some money in bank
  6268. 09A8 <Reason>W <Money>Q <balance>L (ZC_ACK_BANKING_DEPOSIT)
  6269. */
  6270. void clif_bank_deposit( map_session_data& sd, enum e_BANKING_DEPOSIT_ACK reason ){
  6271. #if PACKETVER >= 20130717
  6272. struct PACKET_ZC_ACK_BANKING_DEPOSIT p = {};
  6273. p.packetType = HEADER_ZC_ACK_BANKING_DEPOSIT;
  6274. p.money = sd.bank_vault;
  6275. p.zeny = sd.status.zeny;
  6276. p.reason = reason;
  6277. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6278. #endif
  6279. }
  6280. /*
  6281. * Request saving some money in bank
  6282. * @author : original [Yommy/Hercules]
  6283. * 09A7 <AID>L <Money>L (CZ_REQ_BANKING_DEPOSIT)
  6284. */
  6285. void clif_parse_BankDeposit(int fd, map_session_data* sd) {
  6286. #if PACKETVER >= 20130717
  6287. PACKET_CZ_REQ_BANKING_DEPOSIT* p = (PACKET_CZ_REQ_BANKING_DEPOSIT*)RFIFOP( fd, 0 );
  6288. nullpo_retv(sd);
  6289. if( !battle_config.feature_banking ) {
  6290. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6291. return;
  6292. }
  6293. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6294. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6295. return;
  6296. }
  6297. else {
  6298. if(sd->status.account_id == p->AID){
  6299. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,p->zeny));
  6300. clif_bank_deposit( *sd, reason );
  6301. }
  6302. }
  6303. #endif
  6304. }
  6305. /*
  6306. * Acknowledge of withdrawing some money from bank
  6307. * 09AA <Reason>W <Money>Q <balance>L (ZC_ACK_BANKING_WITHDRAW)
  6308. */
  6309. void clif_bank_withdraw( map_session_data& sd, enum e_BANKING_WITHDRAW_ACK reason ){
  6310. #if PACKETVER >= 20130717
  6311. struct PACKET_ZC_ACK_BANKING_WITHDRAW p = {};
  6312. p.packetType = HEADER_ZC_ACK_BANKING_WITHDRAW;
  6313. p.reason = reason;
  6314. p.money = sd.bank_vault;
  6315. p.zeny = sd.status.zeny;
  6316. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6317. #endif
  6318. }
  6319. /*
  6320. * Request Withdrawing some money from bank
  6321. * 09A9 <AID>L <Money>L (CZ_REQ_BANKING_WITHDRAW)
  6322. */
  6323. void clif_parse_BankWithdraw(int fd, map_session_data* sd) {
  6324. #if PACKETVER >= 20130717
  6325. PACKET_CZ_REQ_BANKING_WITHDRAW* p = (PACKET_CZ_REQ_BANKING_WITHDRAW*)RFIFOP( fd, 0 );
  6326. nullpo_retv(sd);
  6327. if( !battle_config.feature_banking ) {
  6328. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6329. return;
  6330. }
  6331. if( map_getmapflag( sd->bl.m, MF_NOBANK ) ){
  6332. clif_displaymessage( sd->fd, msg_txt( sd, 831 ) ); // You cannot use the Bank on this map.
  6333. return;
  6334. }
  6335. else {
  6336. if(sd->status.account_id == p->AID){
  6337. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,p->zeny));
  6338. clif_bank_withdraw( *sd, reason );
  6339. }
  6340. }
  6341. #endif
  6342. }
  6343. /// Deletes an item from character's cart.
  6344. /// 0125 <index>.W <amount>.L (ZC_DELETE_ITEM_FROM_CART)
  6345. void clif_cart_delitem( map_session_data& sd, int32 index, int32 amount ){
  6346. PACKET_ZC_DELETE_ITEM_FROM_CART packet{};
  6347. packet.packetType = HEADER_ZC_DELETE_ITEM_FROM_CART;
  6348. packet.index = client_index( index );
  6349. packet.amount = amount;
  6350. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6351. }
  6352. /// Opens the shop creation menu.
  6353. /// 012d <num>.W (ZC_OPENSTORE)
  6354. /// num:
  6355. /// number of allowed item slots
  6356. void clif_openvendingreq( map_session_data& sd, uint16 num ){
  6357. PACKET_ZC_OPENSTORE packet{};
  6358. packet.packetType = HEADER_ZC_OPENSTORE;
  6359. packet.num = num;
  6360. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6361. }
  6362. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6363. /// 0131 <owner id>.L <message>.80B
  6364. void clif_showvendingboard( map_session_data& sd, enum send_target target, struct block_list* tbl ){
  6365. if( tbl == nullptr ){
  6366. tbl = &sd.bl;
  6367. target = AREA_WOS;
  6368. }
  6369. struct PACKET_ZC_STORE_ENTRY p = {};
  6370. p.packetType = HEADER_ZC_STORE_ENTRY;
  6371. p.makerAID = sd.status.account_id;
  6372. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  6373. clif_send( &p, sizeof( p ), tbl, target );
  6374. }
  6375. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6376. /// 0132 <owner id>.L
  6377. void clif_closevendingboard(struct block_list* bl, int fd)
  6378. {
  6379. unsigned char buf[16];
  6380. nullpo_retv(bl);
  6381. WBUFW(buf,0) = 0x132;
  6382. WBUFL(buf,2) = bl->id;
  6383. if( session_isActive(fd) ) {
  6384. WFIFOHEAD(fd,packet_len(0x132));
  6385. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6386. WFIFOSET(fd,packet_len(0x132));
  6387. } else {
  6388. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6389. }
  6390. }
  6391. /// Sends a list of items in a shop.
  6392. /// 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)
  6393. /// 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)
  6394. void clif_vendinglist( map_session_data* sd, map_session_data* vsd ){
  6395. nullpo_retv( sd );
  6396. nullpo_retv( vsd );
  6397. nullpo_retv( vsd->vending );
  6398. int fd = sd->fd;
  6399. if( !session_isActive( fd ) ){
  6400. return;
  6401. }
  6402. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC ) + vsd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC_sub );
  6403. WFIFOHEAD( fd, len );
  6404. struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_ZC_PC_PURCHASE_ITEMLIST_FROMMC*)WFIFOP( fd, 0 );
  6405. p->packetType = HEADER_ZC_PC_PURCHASE_ITEMLIST_FROMMC;
  6406. p->packetLength = len;
  6407. p->AID = vsd->status.account_id;
  6408. #if PACKETVER >= 20100105
  6409. p->venderId = vsd->vender_id;
  6410. #endif
  6411. for( int i = 0; i < vsd->vend_num; i++ ){
  6412. int index = vsd->vending[i].index;
  6413. struct item_data* data = itemdb_search( vsd->cart.u.items_cart[index].nameid );
  6414. p->items[i].price = vsd->vending[i].value;
  6415. p->items[i].amount = vsd->vending[i].amount;
  6416. p->items[i].index = client_index( index );
  6417. p->items[i].itemType = itemtype( vsd->cart.u.items_cart[index].nameid );
  6418. p->items[i].itemId = client_nameid( vsd->cart.u.items_cart[index].nameid );
  6419. p->items[i].identified = vsd->cart.u.items_cart[index].identify;
  6420. p->items[i].damaged = vsd->cart.u.items_cart[index].attribute;
  6421. p->items[i].refine = vsd->cart.u.items_cart[index].refine;
  6422. clif_addcards( &p->items[i].slot, &vsd->cart.u.items_cart[index] );
  6423. #if PACKETVER >= 20150226
  6424. clif_add_random_options( p->items[i].option_data, vsd->cart.u.items_cart[index] );
  6425. #if PACKETVER >= 20160921
  6426. p->items[i].location = pc_equippoint_sub( sd, data );
  6427. p->items[i].viewSprite = data->look;
  6428. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6429. p->items[i].grade = vsd->cart.u.items_cart[index].enchantgrade;
  6430. #endif
  6431. #endif
  6432. #endif
  6433. }
  6434. WFIFOSET( fd, len );
  6435. }
  6436. /// Shop purchase failure.
  6437. /// 0135 <index>.W <amount>.W <result>.B (ZC_PC_PURCHASE_RESULT_FROMMC)
  6438. /// result:
  6439. /// 0 = success
  6440. /// 1 = not enough zeny
  6441. /// 2 = overweight
  6442. /// 4 = out of stock
  6443. /// 5 = "cannot use an npc shop while in a trade"
  6444. /// 6 = Because the store information was incorrect the item was not purchased.
  6445. /// 7 = No sales information.
  6446. void clif_buyvending( map_session_data& sd, uint16 index, uint16 amount, e_pc_purchase_result_frommc result ){
  6447. PACKET_ZC_PC_PURCHASE_RESULT_FROMMC packet{};
  6448. packet.packetType = HEADER_ZC_PC_PURCHASE_RESULT_FROMMC;
  6449. packet.index = client_index( index );
  6450. packet.amount = amount;
  6451. packet.result = static_cast<decltype(packet.result)>(result);
  6452. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6453. }
  6454. /// Show's vending player its list of items for sale.
  6455. /// 0a28 <result>.B (ZC_ACK_OPENSTORE2)
  6456. /// result:
  6457. /// 0 = Success
  6458. /// 1 = Failed
  6459. void clif_openvending_ack( map_session_data& sd, bool failure ){
  6460. #if PACKETVER >= 20141022
  6461. PACKET_ZC_ACK_OPENSTORE2 packet{};
  6462. packet.packetType = HEADER_ZC_ACK_OPENSTORE2;
  6463. packet.result = failure;
  6464. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6465. #endif
  6466. }
  6467. /// Shop creation success.
  6468. /// 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)
  6469. void clif_openvending( map_session_data* sd, int id, struct s_vending* vending ){
  6470. nullpo_retv( sd );
  6471. nullpo_retv( vending );
  6472. int fd = sd->fd;
  6473. if( !session_isActive( fd ) ){
  6474. return;
  6475. }
  6476. int len = sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST ) + sd->vend_num * sizeof( struct PACKET_ZC_PC_PURCHASE_MYITEMLIST_sub );
  6477. WFIFOHEAD( fd, len );
  6478. struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *p = (struct PACKET_ZC_PC_PURCHASE_MYITEMLIST *)WFIFOP( fd, 0 );
  6479. p->packetType = HEADER_ZC_PC_PURCHASE_MYITEMLIST;
  6480. p->packetLength = len;
  6481. p->AID = id;
  6482. for( int i = 0; i < sd->vend_num; i++ ) {
  6483. int index = vending[i].index;
  6484. p->items[i].price = vending[i].value;
  6485. p->items[i].index = client_index( index );
  6486. p->items[i].amount = vending[i].amount;
  6487. p->items[i].itemType = itemtype( sd->cart.u.items_cart[index].nameid );
  6488. p->items[i].itemId = client_nameid( sd->cart.u.items_cart[index].nameid );
  6489. p->items[i].identified = sd->cart.u.items_cart[index].identify;
  6490. p->items[i].damaged = sd->cart.u.items_cart[index].attribute;
  6491. p->items[i].refine = sd->cart.u.items_cart[index].refine;
  6492. clif_addcards( &p->items[i].slot, &sd->cart.u.items_cart[index] );
  6493. #if PACKETVER >= 20150226
  6494. clif_add_random_options( p->items[i].option_data, sd->cart.u.items_cart[index] );
  6495. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  6496. p->items[i].grade = sd->cart.u.items_cart[index].enchantgrade;
  6497. #endif
  6498. #endif
  6499. }
  6500. WFIFOSET( fd, len );
  6501. clif_openvending_ack( *sd, false );
  6502. }
  6503. /// Inform merchant that someone has bought an item.
  6504. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE)
  6505. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2)
  6506. void clif_vendingreport( map_session_data& sd, uint16 index, uint16 amount, uint32 char_id, int32 zeny ){
  6507. PACKET_ZC_DELETEITEM_FROM_MCSTORE packet{};
  6508. packet.packetType = HEADER_ZC_DELETEITEM_FROM_MCSTORE;
  6509. packet.index = client_index( index );
  6510. packet.amount = amount;
  6511. // TODO : not sure for client date [Napster]
  6512. #if PACKETVER >= 20141016
  6513. packet.buyerCID = char_id;
  6514. packet.date = client_tick( time(nullptr) );
  6515. packet.zeny = zeny;
  6516. #endif
  6517. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6518. }
  6519. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6520. /// 00fa <result>.B
  6521. /// result:
  6522. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6523. /// 1 = MsgStringTable[78]="party name already exists"
  6524. /// 2 = MsgStringTable[79]="already in a party"
  6525. /// 3 = cannot organize parties on this map
  6526. /// ? = nothing
  6527. void clif_party_created( map_session_data& sd, int result ){
  6528. struct PACKET_ZC_ACK_MAKE_GROUP p = {};
  6529. p.PacketType = HEADER_ZC_ACK_MAKE_GROUP;
  6530. p.result = result;
  6531. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6532. }
  6533. /// Adds new member to a party.
  6534. /// 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)
  6535. /// 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)
  6536. /// 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)
  6537. /// role:
  6538. /// 0 = leader
  6539. /// 1 = normal
  6540. /// state:
  6541. /// 0 = connected
  6542. /// 1 = disconnected
  6543. void clif_party_member_info( struct party_data& party, map_session_data& sd ){
  6544. int id = party_getmemberid( &party, &sd );
  6545. if( id < 0 ){
  6546. return;
  6547. }
  6548. struct PACKET_ZC_ADD_MEMBER_TO_GROUP p = {};
  6549. p.packetType = partymemberinfo;
  6550. p.AID = sd.status.account_id;
  6551. #if PACKETVER >= 20171207
  6552. p.GID = sd.status.char_id;
  6553. #endif
  6554. p.leader = ( party.party.member[id].leader != 0 ) ? 0 : 1;
  6555. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6556. p.class_ = sd.status.class_;
  6557. p.baseLevel = sd.status.base_level;
  6558. #endif
  6559. p.x = sd.bl.x;
  6560. p.y = sd.bl.y;
  6561. p.offline = ( party.party.member[id].online != 0 ) ? 0 : 1;
  6562. safestrncpy( p.partyName, party.party.name, sizeof( p.partyName ) );
  6563. safestrncpy( p.playerName, sd.status.name, sizeof( p.playerName ) );
  6564. mapindex_getmapname_ext( map_mapid2mapname( sd.bl.m ), p.mapName );
  6565. p.sharePickup = ( party.party.item&1 ) ? 1 : 0;
  6566. p.shareLoot = ( party.party.item&2 )? 1 : 0;
  6567. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6568. }
  6569. /// Sends party information (ZC_GROUP_LIST).
  6570. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6571. /// role:
  6572. /// 0 = leader
  6573. /// 1 = normal
  6574. /// state:
  6575. /// 0 = connected
  6576. /// 1 = disconnected
  6577. /// 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
  6578. void clif_party_info( struct party_data& party, map_session_data* sd ){
  6579. send_target target;
  6580. if( sd == nullptr ){
  6581. sd = party_getavailablesd( &party );
  6582. if( sd == nullptr ){
  6583. // Nobody is online to notify
  6584. return;
  6585. }
  6586. // Send to whole party
  6587. target = PARTY;
  6588. }else{
  6589. // Send only to self
  6590. target = SELF;
  6591. }
  6592. PACKET_ZC_GROUP_LIST* p = reinterpret_cast<PACKET_ZC_GROUP_LIST*>( packet_buffer );
  6593. p->packetType = partyinfo;
  6594. p->packetLen = sizeof( *p );
  6595. safestrncpy( p->partyName, party.party.name, sizeof( p->partyName ) );
  6596. for( int i = 0, c = 0; i < MAX_PARTY; i++ ){
  6597. struct party_member& m = party.party.member[i];
  6598. if( m.account_id == 0 ){
  6599. continue;
  6600. }
  6601. PACKET_ZC_GROUP_LIST_SUB& member = p->members[c];
  6602. member.AID = m.account_id;
  6603. #if PACKETVER >= 20171207
  6604. member.GID = m.char_id;
  6605. #endif
  6606. safestrncpy( member.playerName, m.name, sizeof( member.playerName ) );
  6607. mapindex_getmapname_ext( m.map, member.mapName );
  6608. member.leader = ( m.leader ) ? 0 : 1;
  6609. member.offline = ( m.online ) ? 0 : 1;
  6610. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6611. member.class_ = m.class_;
  6612. member.baseLevel = m.lv;
  6613. #endif
  6614. p->packetLen += static_cast<decltype(p->packetLen)>( sizeof( member ) );
  6615. c++;
  6616. }
  6617. clif_send( p, p->packetLen, &sd->bl, target );
  6618. }
  6619. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6620. /// 02c9 <flag>.B
  6621. /// flag:
  6622. /// 0 = allow party invites
  6623. /// 1 = auto-deny party invites
  6624. void clif_partyinvitationstate( map_session_data& sd ){
  6625. #if PACKETVER_MAIN_NUM >= 20070911 || defined(PACKETVER_RE) || PACKETVER_AD_NUM >= 20070911 || PACKETVER_SAK_NUM >= 20070904 || defined(PACKETVER_ZERO)
  6626. struct PACKET_ZC_PARTY_CONFIG p = {};
  6627. p.packetType = HEADER_ZC_PARTY_CONFIG;
  6628. p.denyPartyInvites = sd.status.disable_partyinvite;
  6629. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6630. #endif
  6631. }
  6632. /// Party invitation request.
  6633. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6634. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6635. void clif_party_invite( map_session_data& sd, map_session_data& tsd ){
  6636. struct party_data* party = party_search( sd.status.party_id );
  6637. if( party == nullptr ){
  6638. return;
  6639. }
  6640. struct PACKET_ZC_PARTY_JOIN_REQ p = {};
  6641. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ;
  6642. p.GRID = party->party.party_id;
  6643. safestrncpy( p.groupName, party->party.name, sizeof( p.groupName ) );
  6644. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6645. }
  6646. /// Party invite result.
  6647. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6648. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6649. /// result=0 : char is already in a party -> MsgStringTable[80]
  6650. /// result=1 : party invite was rejected -> MsgStringTable[81]
  6651. /// result=2 : party invite was accepted -> MsgStringTable[82]
  6652. /// result=3 : party is full -> MsgStringTable[83]
  6653. /// result=4 : char of the same account already joined the party -> MsgStringTable[608]
  6654. /// result=5 : char blocked party invite -> MsgStringTable[1324] (since 20070904)
  6655. /// result=7 : char is not online or doesn't exist -> MsgStringTable[71] (since 20070904)
  6656. /// result=8 : (%s) are currently in restricted map to join a party. -> MsgStringTable[1388] (since 20080527)
  6657. /// result=9 : Cannot join a party in this map. -> MsgStringTable[1871] (since 20110215)
  6658. /// result=10 : You cannot invite or withdraw while in memorial dungeon -> message: MSG_ID_BD3 (since 20161130)
  6659. /// result=11 : The character is a level that can not join the party -> message: MSG_ID_C9A (since 20170412)
  6660. void clif_party_invite_reply( map_session_data& sd, const char* nick, enum e_party_invite_reply reply ){
  6661. #if PACKETVER < 20070904
  6662. if( reply == PARTY_REPLY_OFFLINE ){
  6663. clif_displaymessage( sd.fd, msg_txt( &sd, 3 ) ); // Character not found.
  6664. return;
  6665. }
  6666. #endif
  6667. struct PACKET_ZC_PARTY_JOIN_REQ_ACK p = {};
  6668. p.PacketType = HEADER_ZC_PARTY_JOIN_REQ_ACK;
  6669. safestrncpy( p.characterName, nick, sizeof( p.characterName ) );
  6670. p.result = reply;
  6671. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6672. }
  6673. /// Updates party settings.
  6674. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6675. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6676. /// exp option:
  6677. /// 0 = exp sharing disabled
  6678. /// 1 = exp sharing enabled
  6679. /// 2 = cannot change exp sharing
  6680. ///
  6681. /// flag:
  6682. /// 0 = send to party
  6683. /// 1 = send to sd
  6684. void clif_party_option(struct party_data *p,map_session_data *sd,int flag)
  6685. {
  6686. unsigned char buf[16];
  6687. #if PACKETVER < 20090603
  6688. const int cmd = 0x101;
  6689. #else
  6690. const int cmd = 0x7d8;
  6691. #endif
  6692. nullpo_retv(p);
  6693. if(!sd && flag==0){
  6694. int i;
  6695. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6696. if (i < MAX_PARTY)
  6697. sd = p->data[i].sd;
  6698. }
  6699. if(!sd) return;
  6700. WBUFW(buf,0)=cmd;
  6701. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6702. #if PACKETVER >= 20090603
  6703. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6704. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6705. #endif
  6706. if(flag==0)
  6707. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6708. else
  6709. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6710. }
  6711. /**
  6712. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6713. * @param sd Send the notification for this player
  6714. * @param account_id Account ID of kicked member
  6715. * @param name Name of kicked member
  6716. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6717. * @param target Send target
  6718. **/
  6719. void clif_party_withdraw( map_session_data& sd, uint32 account_id, const char* name, enum e_party_member_withdraw result, enum send_target target ){
  6720. struct PACKET_ZC_DELETE_MEMBER_FROM_GROUP p = {};
  6721. p.PacketType = HEADER_ZC_DELETE_MEMBER_FROM_GROUP;
  6722. p.AID = account_id;
  6723. safestrncpy( p.characterName, name, sizeof( p.characterName ) );
  6724. p.result = result;
  6725. clif_send( &p, sizeof( p ), &sd.bl, target );
  6726. }
  6727. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6728. /// 0109 <packet len>.W <account id>.L <message>.?B
  6729. void clif_party_message( struct party_data& party, uint32 account_id, const char* mes, size_t len ){
  6730. map_session_data* sd = party_getavailablesd( &party );
  6731. if( sd == nullptr ){
  6732. return;
  6733. }
  6734. if (len > CHAT_SIZE_MAX) {
  6735. ShowWarning( "clif_party_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", party_id=%d).\n", mes, len, CHAT_SIZE_MAX, party.party.party_id );
  6736. len = CHAT_SIZE_MAX;
  6737. }
  6738. PACKET_ZC_NOTIFY_CHAT_PARTY* p = reinterpret_cast<PACKET_ZC_NOTIFY_CHAT_PARTY*>( packet_buffer );
  6739. p->PacketType = HEADER_ZC_NOTIFY_CHAT_PARTY;
  6740. p->PacketLength = sizeof( *p );
  6741. p->AID = account_id;
  6742. safestrncpy( p->chatMsg, mes, len );
  6743. p->PacketLength += static_cast<decltype(p->PacketLength)>( len );
  6744. clif_send( p, p->PacketLength, &sd->bl, PARTY );
  6745. }
  6746. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6747. /// 0107 <account id>.L <x>.W <y>.W
  6748. void clif_party_xy( map_session_data& sd ){
  6749. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6750. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6751. p.AID = sd.status.account_id;
  6752. p.xPos = sd.bl.x;
  6753. p.yPos = sd.bl.y;
  6754. clif_send( &p, sizeof( p ), &sd.bl, PARTY_SAMEMAP_WOS );
  6755. }
  6756. /*==========================================
  6757. * Sends x/y dot to a single fd. [Skotlex]
  6758. *------------------------------------------*/
  6759. void clif_party_xy_single( map_session_data& sd, map_session_data& tsd ){
  6760. struct PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p = {};
  6761. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  6762. p.AID = sd.status.account_id;
  6763. p.xPos = sd.bl.x;
  6764. p.yPos = sd.bl.y;
  6765. clif_send( &p, sizeof( p ), &tsd.bl, SELF );
  6766. }
  6767. /// Updates HP bar of a party member.
  6768. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6769. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6770. void clif_party_hp( map_session_data& sd ){
  6771. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6772. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6773. p.AID = sd.status.account_id;
  6774. #if PACKETVER < 20100119
  6775. // To correctly display the %hp bar. [Skotlex]
  6776. if( sd.battle_status.max_hp > INT16_MAX ){
  6777. p.hp = sd.battle_status.hp / ( sd.battle_status.max_hp / 100 );
  6778. p.maxhp = 100;
  6779. }else{
  6780. p.hp = sd.battle_status.hp;
  6781. p.maxhp = sd.battle_status.max_hp;
  6782. }
  6783. #else
  6784. p.hp = sd.battle_status.hp;
  6785. p.maxhp = sd.battle_status.max_hp;
  6786. #endif
  6787. clif_send( &p, sizeof( p ), &sd.bl, PARTY_AREA_WOS );
  6788. }
  6789. /// Notifies the party members of a character's death or revival.
  6790. /// 0AB2 <GID>.L <dead>.B
  6791. void clif_party_dead( map_session_data& sd ){
  6792. #if PACKETVER_MAIN_NUM >= 20170524 || PACKETVER_RE_NUM >= 20170502 || defined(PACKETVER_ZERO)
  6793. struct PACKET_ZC_GROUP_ISALIVE p = {};
  6794. p.packetType = HEADER_ZC_GROUP_ISALIVE;
  6795. p.AID = sd.status.account_id;
  6796. p.isDead = pc_isdead( &sd );
  6797. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6798. #endif
  6799. }
  6800. /// Updates the job and level of a party member
  6801. /// 0abd <account id>.L <job>.W <level>.W
  6802. void clif_party_job_and_level( map_session_data& sd ){
  6803. #if PACKETVER_MAIN_NUM >= 20170502 || PACKETVER_RE_NUM >= 20170419 || defined(PACKETVER_ZERO)
  6804. struct PACKET_ZC_NOTIFY_MEMBERINFO_TO_GROUPM p = {};
  6805. p.PacketType = HEADER_ZC_NOTIFY_MEMBERINFO_TO_GROUPM;
  6806. p.AID = sd.status.account_id;
  6807. p.job = sd.status.class_;
  6808. p.level = sd.status.base_level;
  6809. clif_send( &p, sizeof( p ), &sd.bl, PARTY );
  6810. #endif
  6811. }
  6812. /*==========================================
  6813. * Sends HP bar to a single fd. [Skotlex]
  6814. *------------------------------------------*/
  6815. void clif_hpmeter_single( map_session_data& sd, uint32 id, uint32 hp, uint32 maxhp ){
  6816. struct PACKET_ZC_NOTIFY_HP_TO_GROUPM p = {};
  6817. p.PacketType = HEADER_ZC_NOTIFY_HP_TO_GROUPM;
  6818. p.AID = id;
  6819. #if PACKETVER < 20100119
  6820. // To correctly display the %hp bar. [Skotlex]
  6821. if( maxhp > INT16_MAX ){
  6822. p.hp = hp / ( maxhp / 100 );
  6823. p.maxhp = 100;
  6824. }else{
  6825. p.hp = hp;
  6826. p.maxhp = maxhp;
  6827. }
  6828. #else
  6829. p.hp = hp;
  6830. p.maxhp = maxhp;
  6831. #endif
  6832. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  6833. }
  6834. /// Notifies the client, that it's attack target is too far.
  6835. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W (ZC_ATTACK_FAILURE_FOR_DISTANCE)
  6836. void clif_movetoattack( map_session_data& sd, block_list& bl ){
  6837. PACKET_ZC_ATTACK_FAILURE_FOR_DISTANCE packet{};
  6838. packet.PacketType = HEADER_ZC_ATTACK_FAILURE_FOR_DISTANCE;
  6839. packet.targetAID = bl.id;
  6840. packet.targetXPos = bl.x;
  6841. packet.targetYPos = bl.y;
  6842. packet.xPos = sd.bl.x;
  6843. packet.yPos = sd.bl.y;
  6844. packet.currentAttRange = sd.battle_status.rhw.range;
  6845. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6846. }
  6847. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6848. /// 018f <result>.W <name id>.W
  6849. /// result:
  6850. /// 0 = success
  6851. /// 1 = failure
  6852. /// 2 = success (alchemist)
  6853. /// 3 = failure (alchemist)
  6854. void clif_produceeffect(map_session_data* sd,int flag, t_itemid nameid){
  6855. nullpo_retv( sd );
  6856. clif_solved_charname( sd->fd, sd->status.char_id, sd->status.name );
  6857. struct PACKET_ZC_ACK_REQMAKINGITEM p;
  6858. p.packetType = HEADER_ZC_ACK_REQMAKINGITEM;
  6859. p.result = flag;
  6860. p.itemId = client_nameid( nameid );
  6861. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  6862. }
  6863. /// Initiates the pet taming process.
  6864. /// 019e (ZC_START_CAPTURE)
  6865. void clif_catch_process( map_session_data& sd ){
  6866. PACKET_ZC_START_CAPTURE packet{};
  6867. packet.PacketType = HEADER_ZC_START_CAPTURE;
  6868. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6869. }
  6870. /// Displays the result of a pet taming attempt.
  6871. /// 01a0 <result>.B (ZC_TRYCAPTURE_MONSTER)
  6872. /// 0 = failure
  6873. /// 1 = success
  6874. void clif_pet_roulette( map_session_data& sd, bool success ){
  6875. PACKET_ZC_TRYCAPTURE_MONSTER packet{};
  6876. packet.PacketType = HEADER_ZC_TRYCAPTURE_MONSTER;
  6877. packet.result = success;
  6878. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6879. }
  6880. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6881. /// 01a6 <packet len>.W { <index>.W }*
  6882. void clif_sendegg(map_session_data *sd)
  6883. {
  6884. int i,n=0,fd;
  6885. nullpo_retv(sd);
  6886. fd=sd->fd;
  6887. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6888. clif_displaymessage(fd, msg_txt(sd,666));
  6889. return;
  6890. }
  6891. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6892. WFIFOW(fd,0)=0x1a6;
  6893. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6894. if(sd->inventory.u.items_inventory[i].nameid == 0 || sd->inventory_data[i] == nullptr ||
  6895. sd->inventory_data[i]->type != IT_PETEGG ||
  6896. sd->inventory.u.items_inventory[i].amount <= 0)
  6897. continue;
  6898. WFIFOW(fd,n*2+4)=client_index(i);
  6899. n++;
  6900. }
  6901. WFIFOW(fd,2)=4+n*2;
  6902. WFIFOSET(fd,WFIFOW(fd,2));
  6903. sd->menuskill_id = SA_TAMINGMONSTER;
  6904. sd->menuskill_val = -1;
  6905. }
  6906. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6907. /// 01a4 <type>.B <id>.L <data>.L
  6908. /// type:
  6909. /// 0 = pre-init (data = 0)
  6910. /// 1 = intimacy (data = 0~4)
  6911. /// 2 = hunger (data = 0~4)
  6912. /// 3 = accessory
  6913. /// 4 = performance (data = 1~3: normal, 4: special)
  6914. /// 5 = hairstyle
  6915. /// 6 = close egg selection ui and update egg in inventory (PACKETVER >= 20180704)
  6916. ///
  6917. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6918. void clif_send_petdata(map_session_data* sd, struct pet_data* pd, int type, int param)
  6919. {
  6920. uint8 buf[16];
  6921. nullpo_retv(pd);
  6922. WBUFW(buf,0) = 0x1a4;
  6923. WBUFB(buf,2) = type;
  6924. WBUFL(buf,3) = pd->bl.id;
  6925. WBUFL(buf,7) = param;
  6926. if (sd)
  6927. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6928. else
  6929. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6930. }
  6931. /// Pet's base data (ZC_PROPERTY_PET).
  6932. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6933. void clif_send_petstatus(map_session_data *sd)
  6934. {
  6935. int fd;
  6936. struct s_pet *pet;
  6937. nullpo_retv(sd);
  6938. nullpo_retv(sd->pd);
  6939. fd=sd->fd;
  6940. pet = &sd->pd->pet;
  6941. WFIFOHEAD(fd,packet_len(0x1a2));
  6942. WFIFOW(fd,0)=0x1a2;
  6943. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6944. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6945. WFIFOW(fd,27)=pet->level;
  6946. WFIFOW(fd,29)=pet->hungry;
  6947. WFIFOW(fd,31)=pet->intimate;
  6948. WFIFOW(fd,33)=pet->equip;
  6949. #if PACKETVER >= 20081126
  6950. WFIFOW(fd,35)=pet->class_;
  6951. #endif
  6952. WFIFOSET(fd,packet_len(0x1a2));
  6953. }
  6954. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6955. /// 01aa <id>.L <data>.L
  6956. /// data:
  6957. /// @see CZ_PET_ACT.
  6958. void clif_pet_emotion(struct pet_data *pd,int param)
  6959. {
  6960. unsigned char buf[16];
  6961. nullpo_retv(pd);
  6962. memset(buf,0,packet_len(0x1aa));
  6963. WBUFW(buf,0)=0x1aa;
  6964. WBUFL(buf,2)=pd->bl.id;
  6965. WBUFL(buf,6)=param;
  6966. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6967. }
  6968. /// Result of request to feed a pet.
  6969. /// 01a3 <result>.B <name id>.W (ZC_FEED_PET)
  6970. /// result:
  6971. /// 0 = failure
  6972. /// 1 = success
  6973. void clif_pet_food( map_session_data& sd, int32 foodid, bool success ){
  6974. PACKET_ZC_FEED_PET packet{};
  6975. packet.packetType = HEADER_ZC_FEED_PET;
  6976. packet.result = success;
  6977. packet.itemId = client_nameid( foodid );
  6978. clif_send( &packet, sizeof( packet ), &sd.bl, SELF );
  6979. }
  6980. /// Send pet auto feed info.
  6981. void clif_pet_autofeed_status(map_session_data* sd, bool force) {
  6982. #if PACKETVER >= 20141008
  6983. nullpo_retv(sd);
  6984. if (force || battle_config.pet_autofeed_always) {
  6985. // Always send ON or OFF
  6986. if (sd->pd && battle_config.feature_pet_autofeed) {
  6987. clif_configuration(sd, CONFIG_PET_AUTOFEED, sd->pd->pet.autofeed);
  6988. }
  6989. else {
  6990. clif_configuration(sd, CONFIG_PET_AUTOFEED, false);
  6991. }
  6992. }
  6993. else {
  6994. // Only send when enabled
  6995. if (sd->pd && battle_config.feature_pet_autofeed && sd->pd->pet.autofeed) {
  6996. clif_configuration(sd, CONFIG_PET_AUTOFEED, true);
  6997. }
  6998. }
  6999. #endif
  7000. }
  7001. /// Presents a list of skills that can be auto-spelled.
  7002. /// 01cd { <skill id>.L }*7 (ZC_AUTOSPELLLIST)
  7003. void clif_autospell( map_session_data& sd, uint16 skill_lv ){
  7004. struct s_autospell_requirement{
  7005. uint16 skill_id;
  7006. uint16 required_autospell_skill_lv;
  7007. };
  7008. #ifdef RENEWAL
  7009. const std::vector<s_autospell_requirement> autospell_skills = {
  7010. { MG_FIREBOLT, 0 },
  7011. { MG_COLDBOLT, 0 },
  7012. { MG_LIGHTNINGBOLT, 0 },
  7013. { MG_SOULSTRIKE, 3 },
  7014. { MG_FIREBALL, 3 },
  7015. { WZ_EARTHSPIKE, 6 },
  7016. { MG_FROSTDIVER, 6 },
  7017. { MG_THUNDERSTORM, 9 },
  7018. { WZ_HEAVENDRIVE, 9 }
  7019. };
  7020. #else
  7021. const std::vector<s_autospell_requirement> autospell_skills = {
  7022. { MG_NAPALMBEAT, 0 },
  7023. { MG_COLDBOLT, 1 },
  7024. { MG_FIREBOLT, 1 },
  7025. { MG_LIGHTNINGBOLT, 1 },
  7026. { MG_SOULSTRIKE, 4 },
  7027. { MG_FIREBALL, 7 },
  7028. { MG_FROSTDIVER, 9 },
  7029. };
  7030. #endif
  7031. #if PACKETVER_MAIN_NUM >= 20181128 || PACKETVER_RE_NUM >= 20181031
  7032. PACKET_ZC_AUTOSPELLLIST* p = reinterpret_cast<PACKET_ZC_AUTOSPELLLIST*>( packet_buffer );
  7033. p->packetType = HEADER_ZC_AUTOSPELLLIST;
  7034. p->packetLength = sizeof( *p );
  7035. size_t count = 0;
  7036. for( const s_autospell_requirement& requirement : autospell_skills ){
  7037. if( skill_lv > requirement.required_autospell_skill_lv && pc_checkskill( &sd, requirement.skill_id ) ){
  7038. p->skills[count++] = requirement.skill_id;
  7039. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->skills[0] ) );
  7040. }
  7041. }
  7042. clif_send( p, p->packetLength, &sd.bl, SELF );
  7043. #elif PACKETVER_MAIN_NUM >= 20090406 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_SAK_NUM >= 20080618
  7044. PACKET_ZC_AUTOSPELLLIST p = {};
  7045. p.packetType = HEADER_ZC_AUTOSPELLLIST;
  7046. size_t count = 0;
  7047. for( const s_autospell_requirement& requirement : autospell_skills ){
  7048. if( count == ARRAYLENGTH( p.skills ) ){
  7049. break;
  7050. }
  7051. if( skill_lv > requirement.required_autospell_skill_lv && pc_checkskill( &sd, requirement.skill_id ) ){
  7052. p.skills[count++] = requirement.skill_id;
  7053. }else{
  7054. p.skills[count++] = 0;
  7055. }
  7056. }
  7057. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7058. #endif
  7059. sd.menuskill_id = SA_AUTOSPELL;
  7060. sd.menuskill_val = skill_lv;
  7061. }
  7062. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  7063. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  7064. void clif_devotion(struct block_list *src, map_session_data *tsd)
  7065. {
  7066. unsigned char buf[56];
  7067. nullpo_retv(src);
  7068. memset(buf,0,packet_len(0x1cf));
  7069. WBUFW(buf,0) = 0x1cf;
  7070. WBUFL(buf,2) = src->id;
  7071. if( src->type == BL_MER )
  7072. {
  7073. s_mercenary_data *md = BL_CAST(BL_MER,src);
  7074. if( md && md->master && md->devotion_flag )
  7075. WBUFL(buf,6) = md->master->bl.id;
  7076. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7077. }
  7078. else
  7079. {
  7080. int i;
  7081. map_session_data *sd = BL_CAST(BL_PC,src);
  7082. if( sd == nullptr )
  7083. return;
  7084. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7085. WBUFL(buf,6+4*i) = sd->devotion[i];
  7086. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7087. }
  7088. if( tsd )
  7089. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7090. else
  7091. clif_send(buf, packet_len(0x1cf), src, AREA);
  7092. }
  7093. /// Notifies the client of an object's spirits.
  7094. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7095. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7096. void clif_spiritball( struct block_list *bl, struct block_list* target, enum send_target send_target ){
  7097. nullpo_retv( bl );
  7098. struct PACKET_ZC_SPIRITS p = {};
  7099. p.PacketType = HEADER_ZC_SPIRITS;
  7100. p.AID = bl->id;
  7101. switch( bl->type ){
  7102. case BL_PC:
  7103. p.num = ( (map_session_data*)bl )->spiritball;
  7104. break;
  7105. case BL_HOM:
  7106. p.num = ( (struct homun_data*)bl )->homunculus.spiritball;
  7107. break;
  7108. }
  7109. clif_send( &p, sizeof( p ), target == nullptr ? bl : target, send_target );
  7110. }
  7111. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7112. /// 01d2 <account id>.L <delay>.L
  7113. void clif_combo_delay(struct block_list *bl,t_tick wait)
  7114. {
  7115. unsigned char buf[32];
  7116. nullpo_retv(bl);
  7117. WBUFW(buf,0)=0x1d2;
  7118. WBUFL(buf,2)=bl->id;
  7119. WBUFL(buf,6)=client_tick(wait);
  7120. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7121. }
  7122. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7123. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7124. /// flag:
  7125. /// 0 = inactive
  7126. /// 1 = active
  7127. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7128. {
  7129. unsigned char buf[32];
  7130. nullpo_retv(src);
  7131. WBUFW(buf,0)=0x1d1;
  7132. WBUFL(buf,2)=src->id;
  7133. WBUFL(buf,6)=dst_id;
  7134. WBUFL(buf,10)=active;
  7135. clif_send(buf,packet_len(0x1d1),src,AREA);
  7136. }
  7137. /// MVP effect (ZC_MVP).
  7138. /// 010c <account id>.L
  7139. void clif_mvp_effect(map_session_data *sd)
  7140. {
  7141. unsigned char buf[16];
  7142. nullpo_retv(sd);
  7143. WBUFW(buf,0)=0x10c;
  7144. WBUFL(buf,2)=sd->bl.id;
  7145. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7146. }
  7147. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7148. /// 010a <name id>.W
  7149. void clif_mvp_item( map_session_data *sd, t_itemid nameid ){
  7150. struct PACKET_ZC_MVP_GETTING_ITEM p;
  7151. p.packetType = HEADER_ZC_MVP_GETTING_ITEM;
  7152. p.itemId = client_nameid( nameid );
  7153. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  7154. }
  7155. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7156. /// 010b <exp>.L
  7157. void clif_mvp_exp(map_session_data *sd, t_exp exp) {
  7158. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7159. if (battle_config.mvp_exp_reward_message) {
  7160. char e_msg[CHAT_SIZE_MAX];
  7161. sprintf(e_msg, msg_txt(sd, 717), exp);
  7162. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7163. }
  7164. #else
  7165. int fd;
  7166. nullpo_retv(sd);
  7167. fd = sd->fd;
  7168. WFIFOHEAD(fd, packet_len(0x10b));
  7169. WFIFOW(fd,0) = 0x10b;
  7170. WFIFOL(fd,2) = (uint32)u64min( exp, MAX_EXP );
  7171. WFIFOSET(fd, packet_len(0x10b));
  7172. #endif
  7173. }
  7174. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7175. /// 010d
  7176. ///
  7177. /// "You are the MVP, but cannot obtain the reward because
  7178. /// you are overweight."
  7179. void clif_mvp_noitem(map_session_data* sd)
  7180. {
  7181. int fd = sd->fd;
  7182. WFIFOHEAD(fd,packet_len(0x10d));
  7183. WFIFOW(fd,0) = 0x10d;
  7184. WFIFOSET(fd,packet_len(0x10d));
  7185. }
  7186. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7187. /// 0167 <result>.B
  7188. /// result:
  7189. /// 0 = "Guild has been created."
  7190. /// 1 = "You are already in a Guild."
  7191. /// 2 = "That Guild Name already exists."
  7192. /// 3 = "You need the neccessary item to create a Guild."
  7193. void clif_guild_created(map_session_data *sd,int flag)
  7194. {
  7195. int fd;
  7196. nullpo_retv(sd);
  7197. fd=sd->fd;
  7198. WFIFOHEAD(fd,packet_len(0x167));
  7199. WFIFOW(fd,0)=0x167;
  7200. WFIFOB(fd,2)=flag;
  7201. WFIFOSET(fd,packet_len(0x167));
  7202. }
  7203. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7204. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7205. /// mode:
  7206. /// &0x01 = allow invite
  7207. /// &0x10 = allow expel
  7208. void clif_guild_belonginfo( map_session_data& sd ){
  7209. if( sd.guild == nullptr ){
  7210. return;
  7211. }
  7212. const auto &guild = sd.guild->guild;
  7213. int position = guild_getposition(sd);
  7214. if( position < 0 ){
  7215. return;
  7216. }
  7217. struct PACKET_ZC_UPDATE_GDID p = {};
  7218. p.PacketType = HEADER_ZC_UPDATE_GDID;
  7219. p.guildId = guild.guild_id;
  7220. p.emblemVersion = guild.emblem_id;
  7221. p.mode = guild.position[position].mode;
  7222. p.isMaster = ( sd.state.gmaster_flag == 1 );
  7223. p.interSid = 0; // InterSID (unknown purpose)
  7224. safestrncpy( p.guildName, guild.name, sizeof( p.guildName ) );
  7225. #if PACKETVER_MAIN_NUM >= 20220216
  7226. p.masterGID = guild.member[0].char_id;
  7227. #endif
  7228. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7229. }
  7230. /// Guild member login notice.
  7231. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7232. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7233. /// status:
  7234. /// 0 = offline
  7235. /// 1 = online
  7236. void clif_guild_memberlogin_notice(const struct mmo_guild &g,int idx,int flag)
  7237. {
  7238. unsigned char buf[64];
  7239. map_session_data* sd;
  7240. WBUFW(buf, 0)=0x1f2;
  7241. WBUFL(buf, 2)=g.member[idx].account_id;
  7242. WBUFL(buf, 6)=g.member[idx].char_id;
  7243. WBUFL(buf,10)=flag;
  7244. if( ( sd = g.member[idx].sd ) != nullptr )
  7245. {
  7246. WBUFW(buf,14) = sd->status.sex;
  7247. WBUFW(buf,16) = sd->status.hair;
  7248. WBUFW(buf,18) = sd->status.hair_color;
  7249. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7250. }
  7251. else if( ( sd = guild_getavailablesd(g) ) != nullptr )
  7252. {
  7253. WBUFW(buf,14) = 0;
  7254. WBUFW(buf,16) = 0;
  7255. WBUFW(buf,18) = 0;
  7256. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7257. }
  7258. }
  7259. // Function `clif_guild_memberlogin_notice` sends info about
  7260. // logins and logouts of a guild member to the rest members.
  7261. // But at the 1st time (after a player login or map changing)
  7262. // the client won't show the message.
  7263. // So I suggest use this function for sending "first-time-info"
  7264. // to some player on entering the game or changing location.
  7265. // At next time the client would always show the message.
  7266. // The function sends all the statuses in the single packet
  7267. // to economize traffic. [LuzZza]
  7268. void clif_guild_send_onlineinfo(map_session_data *sd)
  7269. {
  7270. unsigned char buf[14*128];
  7271. int i, count=0, p_len;
  7272. nullpo_retv(sd);
  7273. p_len = packet_len(0x16d);
  7274. auto &g = sd->guild;
  7275. if (!g)
  7276. return;
  7277. for(i=0; i<g->guild.max_member; i++) {
  7278. if(g->guild.member[i].account_id > 0 &&
  7279. g->guild.member[i].account_id != sd->status.account_id) {
  7280. WBUFW(buf,count*p_len) = 0x16d;
  7281. WBUFL(buf,count*p_len+2) = g->guild.member[i].account_id;
  7282. WBUFL(buf,count*p_len+6) = g->guild.member[i].char_id;
  7283. WBUFL(buf,count*p_len+10) = g->guild.member[i].online;
  7284. count++;
  7285. }
  7286. }
  7287. clif_send(buf, p_len*count, &sd->bl, SELF);
  7288. }
  7289. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7290. /// 014e <menu flag>.L
  7291. /// menu flag:
  7292. /// 0x00 = Basic Info (always on)
  7293. /// &0x01 = Member manager
  7294. /// &0x02 = Positions
  7295. /// &0x04 = Skills
  7296. /// &0x10 = Expulsion list
  7297. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7298. /// &0x80 = Notice
  7299. void clif_guild_masterormember(map_session_data *sd)
  7300. {
  7301. int fd;
  7302. nullpo_retv(sd);
  7303. fd=sd->fd;
  7304. WFIFOHEAD(fd,packet_len(0x14e));
  7305. WFIFOW(fd,0) = 0x14e;
  7306. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7307. WFIFOSET(fd,packet_len(0x14e));
  7308. }
  7309. /// Guild basic information (Territories [Valaris])
  7310. /// 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)
  7311. /// 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)
  7312. /// 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)
  7313. void clif_guild_basicinfo( map_session_data& sd ){
  7314. if( sd.guild == nullptr ){
  7315. return;
  7316. }
  7317. const auto &guild = sd.guild->guild;
  7318. struct PACKET_ZC_GUILD_INFO p = {};
  7319. p.PacketType = HEADER_ZC_GUILD_INFO;
  7320. p.GDID = guild.guild_id;
  7321. p.level = guild.guild_lv;
  7322. p.userNum = guild.connect_member;
  7323. p.maxUserNum = guild.max_member;
  7324. p.userAverageLevel = guild.average_lv;
  7325. p.exp = (uint32)cap_value( guild.exp, 0, MAX_GUILD_EXP );
  7326. p.maxExp = (uint32)cap_value( guild.next_exp, 0, MAX_GUILD_EXP );
  7327. p.point = 0; // Tax Points
  7328. p.honor = 0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7329. p.virtue = 0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7330. p.emblemVersion = guild.emblem_id;
  7331. safestrncpy( p.guildname, guild.name, sizeof( p.guildname ) );
  7332. safestrncpy( p.manageLand, msg_txt( &sd, 300 + guild_checkcastles( guild ) ), sizeof( p.manageLand ) );
  7333. p.zeny = 0;
  7334. #if PACKETVER >= 20200902
  7335. p.masterGID = guild.member[0].char_id; // leader
  7336. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7337. #elif PACKETVER_MAIN_NUM >= 20161019 || PACKETVER_RE_NUM >= 20160921 || defined(PACKETVER_ZERO)
  7338. p.masterGID = guild.member[0].char_id; // leader
  7339. #else
  7340. safestrncpy( p.masterName, guild.master, sizeof( p.masterName ) );
  7341. #endif
  7342. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  7343. }
  7344. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7345. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7346. void clif_guild_allianceinfo(map_session_data *sd)
  7347. {
  7348. int fd,i,c;
  7349. nullpo_retv(sd);
  7350. auto &g = sd->guild;
  7351. if (!g)
  7352. return;
  7353. fd = sd->fd;
  7354. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7355. WFIFOW(fd, 0)=0x14c;
  7356. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7357. struct guild_alliance *a=&g->guild.alliance[i];
  7358. if(a->guild_id>0){
  7359. WFIFOL(fd,c*32+4)=a->opposition;
  7360. WFIFOL(fd,c*32+8)=a->guild_id;
  7361. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7362. c++;
  7363. }
  7364. }
  7365. WFIFOW(fd, 2)=c*32+4;
  7366. WFIFOSET(fd,WFIFOW(fd,2));
  7367. }
  7368. /// Guild member manager information
  7369. /// 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)
  7370. /// state:
  7371. /// 0 = offline
  7372. /// 1 = online
  7373. /// memo:
  7374. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7375. /// 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)
  7376. void clif_guild_memberlist( map_session_data& sd ){
  7377. if( sd.guild == nullptr ){
  7378. return;
  7379. }
  7380. const auto &guild = sd.guild->guild;
  7381. PACKET_ZC_MEMBERMGR_INFO* p = reinterpret_cast<PACKET_ZC_MEMBERMGR_INFO*>( packet_buffer );
  7382. p->PacketType = HEADER_ZC_MEMBERMGR_INFO;
  7383. p->packetLength = sizeof( *p );
  7384. for( int i = 0, c = 0; i < guild.max_member; i++ ){
  7385. const auto &member = guild.member[i];
  7386. if( member.account_id == 0 ){
  7387. continue;
  7388. }
  7389. GUILD_MEMBER_INFO& member_info = p->guildMemberInfo[c];
  7390. member_info.AID = member.account_id;
  7391. member_info.GID = member.char_id;
  7392. member_info.head = member.hair;
  7393. member_info.headPalette = member.hair_color;
  7394. member_info.sex = member.gender;
  7395. member_info.job = member.class_;
  7396. member_info.level = member.lv;
  7397. member_info.contributionExp = (uint32)cap_value( member.exp, 0, MAX_GUILD_EXP );
  7398. member_info.currentState = member.online;
  7399. member_info.positionID = member.position;
  7400. #if PACKETVER >= 20200902
  7401. member_info.lastLoginTime = member.last_login;
  7402. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7403. #elif PACKETVER_MAIN_NUM >= 20161214 || PACKETVER_RE_NUM >= 20161130 || defined(PACKETVER_ZERO)
  7404. member_info.lastLoginTime = member.last_login;
  7405. #else
  7406. 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.
  7407. safestrncpy( member_info.char_name, member.name, sizeof( member_info.char_name ) );
  7408. #endif
  7409. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( member_info ) );
  7410. c++;
  7411. }
  7412. clif_send( p, p->packetLength, &sd.bl, SELF );
  7413. }
  7414. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7415. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7416. void clif_guild_positionnamelist(map_session_data *sd)
  7417. {
  7418. int i,fd;
  7419. nullpo_retv(sd);
  7420. auto &g = sd->guild;
  7421. if (!g)
  7422. return;
  7423. fd = sd->fd;
  7424. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7425. WFIFOW(fd, 0)=0x166;
  7426. for(i=0;i<MAX_GUILDPOSITION;i++){
  7427. WFIFOL(fd,i*28+4)=i;
  7428. safestrncpy(WFIFOCP(fd,i*28+8),g->guild.position[i].name,NAME_LENGTH);
  7429. }
  7430. WFIFOW(fd,2)=i*28+4;
  7431. WFIFOSET(fd,WFIFOW(fd,2));
  7432. }
  7433. /// Guild position information (ZC_POSITION_INFO).
  7434. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7435. /// mode:
  7436. /// &0x01 = allow invite
  7437. /// &0x10 = allow expel
  7438. /// ranking:
  7439. /// TODO
  7440. void clif_guild_positioninfolist(map_session_data *sd)
  7441. {
  7442. int i,fd;
  7443. nullpo_retv(sd);
  7444. auto &g = sd->guild;
  7445. if (!g)
  7446. return;
  7447. fd = sd->fd;
  7448. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7449. WFIFOW(fd, 0)=0x160;
  7450. for(i=0;i<MAX_GUILDPOSITION;i++){
  7451. struct guild_position *p=&g->guild.position[i];
  7452. WFIFOL(fd,i*16+ 4)=i;
  7453. WFIFOL(fd,i*16+ 8)=p->mode;
  7454. WFIFOL(fd,i*16+12)=i;
  7455. WFIFOL(fd,i*16+16)=p->exp_mode;
  7456. }
  7457. WFIFOW(fd, 2)=i*16+4;
  7458. WFIFOSET(fd,WFIFOW(fd,2));
  7459. }
  7460. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7461. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7462. /// mode:
  7463. /// &0x01 = allow invite
  7464. /// &0x10 = allow expel
  7465. /// ranking:
  7466. /// TODO
  7467. void clif_guild_positionchanged(const struct mmo_guild &g,int idx)
  7468. {
  7469. // FIXME: This packet is intended to update the clients after a
  7470. // commit of position info changes, not sending one packet per
  7471. // position.
  7472. map_session_data *sd;
  7473. unsigned char buf[128];
  7474. WBUFW(buf, 0)=0x174;
  7475. WBUFW(buf, 2)=44; // packet len
  7476. // GUILD_REG_POSITION_INFO{
  7477. WBUFL(buf, 4)=idx;
  7478. WBUFL(buf, 8)=g.position[idx].mode;
  7479. WBUFL(buf,12)=idx;
  7480. WBUFL(buf,16)=g.position[idx].exp_mode;
  7481. safestrncpy(WBUFCP(buf,20),g.position[idx].name,NAME_LENGTH);
  7482. // }*
  7483. if( (sd=guild_getavailablesd(g))!=nullptr )
  7484. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7485. }
  7486. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7487. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7488. void clif_guild_memberpositionchanged(const struct mmo_guild &g, int idx)
  7489. {
  7490. // FIXME: This packet is intended to update the clients after a
  7491. // commit of member position assignment changes, not sending one
  7492. // packet per position.
  7493. map_session_data *sd;
  7494. unsigned char buf[64];
  7495. WBUFW(buf, 0)=0x156;
  7496. WBUFW(buf, 2)=16; // packet len
  7497. // MEMBER_POSITION_INFO{
  7498. WBUFL(buf, 4)=g.member[idx].account_id;
  7499. WBUFL(buf, 8)=g.member[idx].char_id;
  7500. WBUFL(buf,12)=g.member[idx].position;
  7501. // }*
  7502. if( (sd=guild_getavailablesd(g))!=nullptr )
  7503. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7504. }
  7505. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7506. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7507. void clif_guild_emblem(const map_session_data &sd, const struct mmo_guild &g)
  7508. {
  7509. int fd = sd.fd;
  7510. if( g.emblem_len <= 0 )
  7511. return;
  7512. WFIFOHEAD(fd,g.emblem_len+12);
  7513. WFIFOW(fd,0)=0x152;
  7514. WFIFOW(fd,2)=g.emblem_len+12;
  7515. WFIFOL(fd,4)=g.guild_id;
  7516. WFIFOL(fd,8)=g.emblem_id;
  7517. memcpy(WFIFOP(fd,12),g.emblem_data,g.emblem_len);
  7518. WFIFOSET(fd,WFIFOW(fd,2));
  7519. }
  7520. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7521. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7522. /// 0b47 <guild id>.L <version>.L <unknown>.L
  7523. void clif_guild_emblem_area(struct block_list* bl)
  7524. {
  7525. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7526. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7527. PACKET_ZC_CHANGE_GUILD p{};
  7528. p.packetType = HEADER_ZC_CHANGE_GUILD;
  7529. p.guild_id = status_get_guild_id(bl);
  7530. p.emblem_id = status_get_emblem_id(bl);
  7531. p.AID = bl->id;
  7532. clif_send(&p, sizeof(p), bl, AREA_WOS);
  7533. }
  7534. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7535. /// 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 }*
  7536. void clif_guild_skillinfo(map_session_data* sd)
  7537. {
  7538. int fd;
  7539. int i,c;
  7540. nullpo_retv(sd);
  7541. auto &g = sd->guild;
  7542. if (!g)
  7543. return;
  7544. fd = sd->fd;
  7545. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7546. WFIFOW(fd,0) = 0x0162;
  7547. WFIFOW(fd,4) = g->guild.skill_point;
  7548. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7549. {
  7550. if(g->guild.skill[i].id > 0 && guild_check_skill_require(g->guild, g->guild.skill[i].id))
  7551. {
  7552. int id = g->guild.skill[i].id;
  7553. int p = 6 + c*37;
  7554. WFIFOW(fd,p+0) = id;
  7555. WFIFOL(fd,p+2) = skill_get_inf(id);
  7556. WFIFOW(fd,p+6) = g->guild.skill[i].lv;
  7557. WFIFOW(fd,p+8) = skill_get_sp(id, g->guild.skill[i].lv);
  7558. WFIFOW(fd,p+10) = skill_get_range(id, g->guild.skill[i].lv);
  7559. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7560. WFIFOB(fd,p+36)= (g->guild.skill[i].lv < guild_skill_get_max(id) && sd == g->guild.member[0].sd) ? 1 : 0;
  7561. c++;
  7562. }
  7563. }
  7564. WFIFOW(fd,2) = 6 + c*37;
  7565. WFIFOSET(fd,WFIFOW(fd,2));
  7566. }
  7567. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7568. /// 016f <subject>.60B <notice>.120B
  7569. void clif_guild_notice(map_session_data* sd)
  7570. {
  7571. nullpo_retv(sd);
  7572. auto &g = sd->guild;
  7573. int fd = sd->fd;
  7574. if ( !session_isActive(fd) )
  7575. return;
  7576. if(g->guild.mes1[0] == '\0' && g->guild.mes2[0] == '\0')
  7577. return;
  7578. WFIFOHEAD(fd,packet_len(0x16f));
  7579. WFIFOW(fd,0) = 0x16f;
  7580. memcpy(WFIFOP(fd,2), g->guild.mes1, MAX_GUILDMES1);
  7581. memcpy(WFIFOP(fd,62), g->guild.mes2, MAX_GUILDMES2);
  7582. WFIFOSET(fd,packet_len(0x16f));
  7583. }
  7584. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7585. /// 016a <guild id>.L <guild name>.24B
  7586. void clif_guild_invite(const map_session_data &sd, const struct mmo_guild &g)
  7587. {
  7588. int fd = sd.fd;
  7589. WFIFOHEAD(fd,packet_len(0x16a));
  7590. WFIFOW(fd,0)=0x16a;
  7591. WFIFOL(fd,2)=g.guild_id;
  7592. safestrncpy(WFIFOCP(fd,6),g.name,NAME_LENGTH);
  7593. WFIFOSET(fd,packet_len(0x16a));
  7594. }
  7595. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7596. /// 0169 <answer>.B
  7597. /// answer:
  7598. /// 0 = Already in guild.
  7599. /// 1 = Offer rejected.
  7600. /// 2 = Offer accepted.
  7601. /// 3 = Guild full.
  7602. void clif_guild_inviteack(map_session_data *sd,int flag)
  7603. {
  7604. int fd;
  7605. nullpo_retv(sd);
  7606. fd=sd->fd;
  7607. WFIFOHEAD(fd,packet_len(0x169));
  7608. WFIFOW(fd,0)=0x169;
  7609. WFIFOB(fd,2)=flag;
  7610. WFIFOSET(fd,packet_len(0x169));
  7611. }
  7612. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7613. /// 015a <char name>.24B <reason>.40B
  7614. void clif_guild_leave(map_session_data *sd,const char *name,const char *mes)
  7615. {
  7616. unsigned char buf[128];
  7617. nullpo_retv(sd);
  7618. WBUFW(buf, 0)=0x15a;
  7619. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7620. memcpy(WBUFP(buf,26),mes,40);
  7621. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7622. }
  7623. /// Notifies clients of a guild of an expelled member.
  7624. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7625. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7626. void clif_guild_expulsion(map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7627. {
  7628. unsigned char buf[128];
  7629. #if PACKETVER < 20100803
  7630. const unsigned short cmd = 0x15c;
  7631. #else
  7632. const unsigned short cmd = 0x839;
  7633. #endif
  7634. nullpo_retv(sd);
  7635. WBUFW(buf,0) = cmd;
  7636. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7637. safestrncpy(WBUFCP(buf,26), mes, 40);
  7638. #if PACKETVER < 20100803
  7639. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7640. #endif
  7641. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7642. }
  7643. /// Guild expulsion list (ZC_BAN_LIST).
  7644. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7645. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7646. void clif_guild_expulsionlist(map_session_data* sd)
  7647. {
  7648. #if PACKETVER < 20100803
  7649. const int offset = NAME_LENGTH*2+40;
  7650. #else
  7651. const int offset = NAME_LENGTH+40;
  7652. #endif
  7653. int fd, i, c = 0;
  7654. nullpo_retv(sd);
  7655. auto &g = sd->guild;
  7656. if (!g)
  7657. return;
  7658. fd = sd->fd;
  7659. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7660. WFIFOW(fd,0) = 0x163;
  7661. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7662. {
  7663. struct guild_expulsion* e = &g->guild.expulsion[i];
  7664. if( e->account_id > 0 )
  7665. {
  7666. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7667. #if PACKETVER < 20100803
  7668. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7669. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7670. #else
  7671. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7672. #endif
  7673. c++;
  7674. }
  7675. }
  7676. WFIFOW(fd,2) = 4 + c*offset;
  7677. WFIFOSET(fd,WFIFOW(fd,2));
  7678. }
  7679. /// Guild chat message (ZC_GUILD_CHAT).
  7680. /// 017f <packet len>.W <message>.?B
  7681. void clif_guild_message( const struct mmo_guild& g, uint32 account_id, const char* mes, size_t len ){
  7682. // TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7683. map_session_data *sd;
  7684. uint8 buf[256];
  7685. if( len == 0 )
  7686. {
  7687. return;
  7688. }
  7689. else if( len > sizeof(buf)-5 )
  7690. {
  7691. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", guild_id=%d).\n", mes, len, sizeof(buf)-5, g.guild_id);
  7692. len = sizeof(buf)-5;
  7693. }
  7694. WBUFW(buf, 0) = 0x17f;
  7695. WBUFW( buf, 2 ) = static_cast<int16>( len + 5 );
  7696. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7697. if ((sd = guild_getavailablesd(g)) != nullptr)
  7698. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7699. }
  7700. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7701. /// 0171 <inviter account id>.L <guild name>.24B
  7702. void clif_guild_reqalliance(map_session_data *sd,uint32 account_id,const char *name)
  7703. {
  7704. int fd;
  7705. nullpo_retv(sd);
  7706. fd=sd->fd;
  7707. WFIFOHEAD(fd,packet_len(0x171));
  7708. WFIFOW(fd,0)=0x171;
  7709. WFIFOL(fd,2)=account_id;
  7710. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7711. WFIFOSET(fd,packet_len(0x171));
  7712. }
  7713. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7714. /// 0173 <answer>.B
  7715. /// answer:
  7716. /// 0 = Already allied.
  7717. /// 1 = You rejected the offer.
  7718. /// 2 = You accepted the offer.
  7719. /// 3 = They have too any alliances.
  7720. /// 4 = You have too many alliances.
  7721. /// 5 = Alliances are disabled.
  7722. void clif_guild_allianceack(map_session_data *sd,int flag)
  7723. {
  7724. int fd;
  7725. nullpo_retv(sd);
  7726. fd=sd->fd;
  7727. WFIFOHEAD(fd,packet_len(0x173));
  7728. WFIFOW(fd,0)=0x173;
  7729. WFIFOL(fd,2)=flag;
  7730. WFIFOSET(fd,packet_len(0x173));
  7731. }
  7732. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7733. /// 0184 <other guild id>.L <relation>.L
  7734. /// relation:
  7735. /// 0 = Ally
  7736. /// 1 = Enemy
  7737. void clif_guild_delalliance(map_session_data *sd,int guild_id,int flag)
  7738. {
  7739. nullpo_retv(sd);
  7740. int fd = sd->fd;
  7741. if ( !session_isActive(fd) )
  7742. return;
  7743. WFIFOHEAD(fd,packet_len(0x184));
  7744. WFIFOW(fd,0)=0x184;
  7745. WFIFOL(fd,2)=guild_id;
  7746. WFIFOL(fd,6)=flag;
  7747. WFIFOSET(fd,packet_len(0x184));
  7748. }
  7749. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7750. /// 0181 <result>.B
  7751. /// result:
  7752. /// 0 = Antagonist has been set.
  7753. /// 1 = Guild has too many Antagonists.
  7754. /// 2 = Already set as an Antagonist.
  7755. /// 3 = Antagonists are disabled.
  7756. void clif_guild_oppositionack(map_session_data *sd,int flag)
  7757. {
  7758. int fd;
  7759. nullpo_retv(sd);
  7760. fd=sd->fd;
  7761. WFIFOHEAD(fd,packet_len(0x181));
  7762. WFIFOW(fd,0)=0x181;
  7763. WFIFOB(fd,2)=flag;
  7764. WFIFOSET(fd,packet_len(0x181));
  7765. }
  7766. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7767. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7768. /*
  7769. void clif_guild_allianceadded(struct guild *g,int idx)
  7770. {
  7771. unsigned char buf[64];
  7772. WBUFW(buf,0)=0x185;
  7773. WBUFL(buf,2)=g->alliance[idx].opposition;
  7774. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7775. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7776. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7777. }
  7778. */
  7779. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7780. /// 015e <reason>.L
  7781. /// 0 = success
  7782. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7783. /// 2 = there are still members in the guild
  7784. void clif_guild_broken(map_session_data *sd,int flag)
  7785. {
  7786. int fd;
  7787. nullpo_retv(sd);
  7788. fd=sd->fd;
  7789. WFIFOHEAD(fd,packet_len(0x15e));
  7790. WFIFOW(fd,0)=0x15e;
  7791. WFIFOL(fd,2)=flag;
  7792. WFIFOSET(fd,packet_len(0x15e));
  7793. }
  7794. /// Displays emotion on an object (ZC_EMOTION).
  7795. /// 00c0 <id>.L <type>.B
  7796. /// type:
  7797. /// enum emotion_type
  7798. void clif_emotion(struct block_list *bl,int type)
  7799. {
  7800. unsigned char buf[8];
  7801. nullpo_retv(bl);
  7802. WBUFW(buf,0)=0xc0;
  7803. WBUFL(buf,2)=bl->id;
  7804. WBUFB(buf,6)=type;
  7805. clif_send(buf,packet_len(0xc0),bl,AREA);
  7806. }
  7807. /// Displays the contents of a talkiebox trap.
  7808. /// 0191 <id>.L <contents>.80B (ZC_TALKBOX_CHATCONTENTS)
  7809. void clif_talkiebox( struct block_list* bl, const char* talkie ){
  7810. nullpo_retv( bl );
  7811. nullpo_retv( talkie );
  7812. struct PACKET_ZC_TALKBOX_CHATCONTENTS p;
  7813. p.PacketType = HEADER_ZC_TALKBOX_CHATCONTENTS;
  7814. p.aid = bl->id;
  7815. safestrncpy( p.message, talkie, TALKBOX_MESSAGE_SIZE );
  7816. clif_send( &p, sizeof( struct PACKET_ZC_TALKBOX_CHATCONTENTS ), bl, AREA );
  7817. }
  7818. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7819. /// 01ea <id>.L
  7820. void clif_wedding_effect(struct block_list *bl)
  7821. {
  7822. unsigned char buf[6];
  7823. nullpo_retv(bl);
  7824. WBUFW(buf,0) = 0x1ea;
  7825. WBUFL(buf,2) = bl->id;
  7826. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7827. }
  7828. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7829. /// 01e6 <partner name>.24B
  7830. void clif_callpartner(map_session_data& sd)
  7831. {
  7832. PACKET_ZC_COUPLENAME p = { 0 };
  7833. p.packetType = HEADER_ZC_COUPLENAME;
  7834. if( sd.status.partner_id ) {
  7835. map_session_data *p_sd = pc_get_partner(&sd);
  7836. if (p_sd != nullptr && !p_sd->state.autotrade)
  7837. safestrncpy(p.name, p_sd->status.name, NAME_LENGTH);
  7838. else
  7839. p.name[0] = 0;
  7840. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7841. p.name[0] = 0;
  7842. }
  7843. clif_send(&p, sizeof(p), &sd.bl, AREA);
  7844. }
  7845. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7846. /// 01e4
  7847. /// This packet while still implemented by the client is no longer being officially used.
  7848. /*
  7849. void clif_marriage_process(map_session_data *sd)
  7850. {
  7851. int fd;
  7852. nullpo_retv(sd);
  7853. fd=sd->fd;
  7854. WFIFOHEAD(fd,packet_len(0x1e4));
  7855. WFIFOW(fd,0)=0x1e4;
  7856. WFIFOSET(fd,packet_len(0x1e4));
  7857. }
  7858. */
  7859. /// Notice of divorce (ZC_DIVORCE).
  7860. /// 0205 <partner name>.24B
  7861. void clif_divorced(map_session_data* sd, const char* name)
  7862. {
  7863. int fd;
  7864. nullpo_retv(sd);
  7865. fd=sd->fd;
  7866. WFIFOHEAD(fd,packet_len(0x205));
  7867. WFIFOW(fd,0)=0x205;
  7868. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7869. WFIFOSET(fd, packet_len(0x205));
  7870. }
  7871. /// Marriage proposal (ZC_REQ_COUPLE).
  7872. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7873. /// This packet while still implemented by the client is no longer being officially used.
  7874. /*
  7875. void clif_marriage_proposal(int fd, map_session_data *sd, map_session_data* ssd)
  7876. {
  7877. nullpo_retv(sd);
  7878. WFIFOHEAD(fd,packet_len(0x1e2));
  7879. WFIFOW(fd,0) = 0x1e2;
  7880. WFIFOL(fd,2) = ssd->status.account_id;
  7881. WFIFOL(fd,6) = ssd->status.char_id;
  7882. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7883. WFIFOSET(fd, packet_len(0x1e2));
  7884. }
  7885. */
  7886. /*==========================================
  7887. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7888. *------------------------------------------*/
  7889. void clif_disp_message(struct block_list* src, const char* mes, size_t len, enum send_target target)
  7890. {
  7891. unsigned char buf[256];
  7892. if( len == 0 ) {
  7893. return;
  7894. } else if( len > sizeof(buf)-5 ) {
  7895. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%" PRIuPTR ", aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7896. len = sizeof(buf)-5;
  7897. }
  7898. WBUFW(buf, 0) = 0x17f;
  7899. WBUFW(buf, 2) = static_cast<int16>( len + 5 );
  7900. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7901. clif_send(buf, WBUFW(buf,2), src, target);
  7902. }
  7903. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7904. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7905. /// 00cd <result>.B
  7906. /// result:
  7907. /// 0 = failure
  7908. /// 1 = success
  7909. void clif_GM_kickack(map_session_data *sd, int id)
  7910. {
  7911. int fd;
  7912. nullpo_retv(sd);
  7913. fd = sd->fd;
  7914. WFIFOHEAD(fd,packet_len(0xcd));
  7915. WFIFOW(fd,0) = 0xcd;
  7916. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7917. WFIFOSET(fd, packet_len(0xcd));
  7918. }
  7919. void clif_GM_kick(map_session_data *sd, map_session_data *tsd)
  7920. {
  7921. nullpo_retv(tsd);
  7922. if (sd == nullptr)
  7923. tsd->state.keepshop = true;
  7924. if (session_isActive(tsd->fd))
  7925. clif_authfail_fd(tsd->fd, 15);
  7926. else
  7927. map_quit(tsd);
  7928. if (sd)
  7929. clif_GM_kickack(sd, tsd->status.account_id);
  7930. }
  7931. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7932. /// 014a <result>.L
  7933. /// result:
  7934. /// 0 = "A manner point has been successfully aligned."
  7935. /// 1 = MP_FAILURE_EXHAUST
  7936. /// 2 = MP_FAILURE_ALREADY_GIVING
  7937. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7938. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7939. /// 5 = "You got a good point from %s."
  7940. void clif_manner_message(map_session_data* sd, uint32 type)
  7941. {
  7942. int fd;
  7943. nullpo_retv(sd);
  7944. fd = sd->fd;
  7945. WFIFOHEAD(fd,packet_len(0x14a));
  7946. WFIFOW(fd,0) = 0x14a;
  7947. WFIFOL(fd,2) = type;
  7948. WFIFOSET(fd, packet_len(0x14a));
  7949. }
  7950. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7951. /// 014b <type>.B <GM name>.24B
  7952. /// type:
  7953. /// 0 = positive (unmute)
  7954. /// 1 = negative (mute)
  7955. void clif_GM_silence(map_session_data* sd, map_session_data* tsd, uint8 type)
  7956. {
  7957. int fd;
  7958. nullpo_retv(sd);
  7959. nullpo_retv(tsd);
  7960. fd = tsd->fd;
  7961. WFIFOHEAD(fd,packet_len(0x14b));
  7962. WFIFOW(fd,0) = 0x14b;
  7963. WFIFOB(fd,2) = type;
  7964. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7965. WFIFOSET(fd, packet_len(0x14b));
  7966. }
  7967. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7968. /// 00d1 <type>.B <result>.B
  7969. /// type:
  7970. /// 0 = /ex (deny)
  7971. /// 1 = /in (allow)
  7972. /// result:
  7973. /// 0 = success
  7974. /// 1 = failure
  7975. /// 2 = too many blocks
  7976. void clif_wisexin(map_session_data *sd,int type,int flag)
  7977. {
  7978. int fd;
  7979. nullpo_retv(sd);
  7980. fd=sd->fd;
  7981. WFIFOHEAD(fd,packet_len(0xd1));
  7982. WFIFOW(fd,0)=0xd1;
  7983. WFIFOB(fd,2)=type;
  7984. WFIFOB(fd,3)=flag;
  7985. WFIFOSET(fd,packet_len(0xd1));
  7986. }
  7987. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7988. /// 00d2 <type>.B <result>.B
  7989. /// type:
  7990. /// 0 = /exall (deny)
  7991. /// 1 = /inall (allow)
  7992. /// result:
  7993. /// 0 = success
  7994. /// 1 = failure
  7995. void clif_wisall(map_session_data *sd,int type,int flag)
  7996. {
  7997. int fd;
  7998. nullpo_retv(sd);
  7999. fd=sd->fd;
  8000. WFIFOHEAD(fd,packet_len(0xd2));
  8001. WFIFOW(fd,0)=0xd2;
  8002. WFIFOB(fd,2)=type;
  8003. WFIFOB(fd,3)=flag;
  8004. WFIFOSET(fd,packet_len(0xd2));
  8005. }
  8006. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  8007. /// 07fe <bgm>.24B
  8008. void clif_playBGM( map_session_data& sd, const char* name ){
  8009. #if PACKETVER_MAIN_NUM >= 20220504
  8010. PACKET_ZC_PLAY_NPC_BGM* p = reinterpret_cast<PACKET_ZC_PLAY_NPC_BGM*>( packet_buffer );
  8011. size_t length = strlen( name ) + 1;
  8012. p->PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8013. p->PacketLength = sizeof( *p );
  8014. p->playType = 0; // TODO: implement, send loop for the time being
  8015. safestrncpy( p->bgm, name, length );
  8016. p->PacketLength += static_cast<decltype(p->PacketLength)>( length );
  8017. clif_send( p, p->PacketLength, &sd.bl, SELF );
  8018. #elif PACKETVER >= 20091201
  8019. PACKET_ZC_PLAY_NPC_BGM p = {};
  8020. p.PacketType = HEADER_ZC_PLAY_NPC_BGM;
  8021. safestrncpy( p.bgm, name, sizeof( p.bgm ) );
  8022. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  8023. #endif
  8024. }
  8025. /// Plays/stops a wave sound (ZC_SOUND).
  8026. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  8027. /// file name:
  8028. /// relative to data\wav
  8029. /// act:
  8030. /// 0 = play (once)
  8031. /// 1 = play (repeat, does not work)
  8032. /// 2 = stops all sound instances of file name (does not work)
  8033. /// term:
  8034. /// unknown purpose, only relevant to act = 1
  8035. /// npc id:
  8036. /// The accustic direction of the sound is determined by the
  8037. /// relative position of the NPC to the player (3D sound).
  8038. void clif_soundeffect( struct block_list& bl, const char* name, int type, enum send_target target ){
  8039. struct PACKET_ZC_SOUND p = {};
  8040. p.PacketType = HEADER_ZC_SOUND;
  8041. safestrncpy( p.name, name, sizeof( p.name ) );
  8042. p.act = type;
  8043. p.term = 0; // TODO: implement
  8044. p.AID = bl.id;
  8045. clif_send( &p, sizeof( p ), &bl, target );
  8046. }
  8047. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8048. /// 01f3 <id>.L <effect id>.L
  8049. /// effect id:
  8050. /// @see doc/effect_list.txt
  8051. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8052. {
  8053. unsigned char buf[24];
  8054. nullpo_retv(bl);
  8055. memset(buf, 0, packet_len(0x1f3));
  8056. WBUFW(buf,0) = 0x1f3;
  8057. WBUFL(buf,2) = bl->id;
  8058. WBUFL(buf,6) = type;
  8059. clif_send(buf, packet_len(0x1f3), bl, target);
  8060. if (disguised(bl)) {
  8061. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8062. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8063. }
  8064. }
  8065. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8066. {
  8067. WFIFOHEAD(fd,10);
  8068. WFIFOW(fd,0) = 0x1f3;
  8069. WFIFOL(fd,2) = bl->id;
  8070. WFIFOL(fd,6) = type;
  8071. WFIFOSET(fd,10);
  8072. }
  8073. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8074. /// 0284 <id>.L <effect id>.L <num data>.L
  8075. /// effect id:
  8076. /// @see doc/effect_list.txt
  8077. /// num data:
  8078. /// effect-dependent value
  8079. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8080. {
  8081. uint8 buf[14];
  8082. WBUFW(buf,0) = 0x284;
  8083. WBUFL(buf,2) = bl->id;
  8084. WBUFL(buf,6) = effect_id;
  8085. WBUFL(buf,10) = num;
  8086. clif_send(buf, packet_len(0x284), bl, target);
  8087. if( disguised(bl) )
  8088. {
  8089. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8090. clif_send(buf, packet_len(0x284), bl, SELF);
  8091. }
  8092. }
  8093. void clif_specialeffect_remove(struct block_list* bl_src, int effect, enum send_target e_target, struct block_list* bl_target)
  8094. {
  8095. #if PACKETVER >= 20181002
  8096. nullpo_retv( bl_src );
  8097. nullpo_retv( bl_target );
  8098. struct PACKET_ZC_REMOVE_EFFECT p = {};
  8099. p.packetType = HEADER_ZC_REMOVE_EFFECT;
  8100. p.aid = bl_src->id;
  8101. p.effectId = effect;
  8102. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_target, e_target );
  8103. if( disguised(bl_src) )
  8104. {
  8105. p.aid = disguised_bl_id( bl_src->id );
  8106. clif_send( &p, sizeof( struct PACKET_ZC_REMOVE_EFFECT ), bl_src, SELF );
  8107. }
  8108. #endif
  8109. }
  8110. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8111. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8112. void clif_messagecolor_target(struct block_list *bl, unsigned long color, const char *msg, bool rgb2bgr, enum send_target type, map_session_data *sd) {
  8113. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8114. uint8 buf[CHAT_SIZE_MAX];
  8115. nullpo_retv(bl);
  8116. if (msg_len > sizeof(buf) - 12) {
  8117. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8118. msg_len = sizeof(buf) - 12;
  8119. }
  8120. if (rgb2bgr)
  8121. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8122. WBUFW(buf,0) = 0x2C1;
  8123. WBUFW(buf,2) = msg_len + 12;
  8124. WBUFL(buf,4) = bl->id;
  8125. WBUFL(buf,8) = color;
  8126. memcpy(WBUFCP(buf,12), msg, msg_len);
  8127. clif_send(buf, WBUFW(buf,2), (sd == nullptr ? bl : &(sd->bl)), type);
  8128. }
  8129. /**
  8130. * Notifies the client that the storage window is still open
  8131. *
  8132. * Should only be used in cases where the client closed the
  8133. * storage window without server's consent
  8134. */
  8135. void clif_refresh_storagewindow(map_session_data *sd) {
  8136. // Notify the client that the storage is open
  8137. if( sd->state.storage_flag == 1 ) {
  8138. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8139. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8140. clif_updatestorageamount(*sd, sd->storage.amount, sd->storage.max_amount);
  8141. }
  8142. // Notify the client that the gstorage is open otherwise it will
  8143. // remain locked forever and nobody will be able to access it
  8144. if( sd->state.storage_flag == 2 ) {
  8145. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8146. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8147. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8148. else {
  8149. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8150. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8151. clif_updatestorageamount(*sd, gstor->amount, gstor->max_amount);
  8152. }
  8153. }
  8154. // Notify the client that the premium storage is open
  8155. if (sd->state.storage_flag == 3) {
  8156. storage_sortitem(sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage));
  8157. clif_storagelist(sd, sd->premiumStorage.u.items_storage, ARRAYLENGTH(sd->premiumStorage.u.items_storage), storage_getName(sd->premiumStorage.stor_id));
  8158. clif_updatestorageamount(*sd, sd->premiumStorage.amount, sd->premiumStorage.max_amount);
  8159. }
  8160. }
  8161. // refresh the client's screen, getting rid of any effects
  8162. void clif_refresh(map_session_data *sd)
  8163. {
  8164. nullpo_retv(sd);
  8165. clif_changemap( *sd, sd->bl.m, sd->bl.x, sd->bl.y );
  8166. clif_inventorylist(sd);
  8167. clif_equipswitch_list(sd);
  8168. if(pc_iscarton(sd)) {
  8169. clif_cartlist(sd);
  8170. clif_updatestatus(*sd,SP_CARTINFO);
  8171. }
  8172. clif_updatestatus(*sd,SP_WEIGHT);
  8173. clif_updatestatus(*sd,SP_MAXWEIGHT);
  8174. clif_updatestatus(*sd,SP_STR);
  8175. clif_updatestatus(*sd,SP_AGI);
  8176. clif_updatestatus(*sd,SP_VIT);
  8177. clif_updatestatus(*sd,SP_INT);
  8178. clif_updatestatus(*sd,SP_DEX);
  8179. clif_updatestatus(*sd,SP_LUK);
  8180. #ifdef RENEWAL
  8181. clif_updatestatus(*sd,SP_POW);
  8182. clif_updatestatus(*sd,SP_STA);
  8183. clif_updatestatus(*sd,SP_WIS);
  8184. clif_updatestatus(*sd,SP_SPL);
  8185. clif_updatestatus(*sd,SP_CON);
  8186. clif_updatestatus(*sd,SP_CRT);
  8187. #endif
  8188. if (sd->spiritball)
  8189. clif_spiritball( &sd->bl, &sd->bl, SELF );
  8190. clif_millenniumshield_single( *sd, *sd );
  8191. clif_spiritcharm_single( *sd, *sd );
  8192. if (sd->soulball)
  8193. clif_soulball( sd, &sd->bl, SELF );
  8194. if (sd->servantball)
  8195. clif_servantball( *sd, &sd->bl, SELF );
  8196. if (sd->abyssball)
  8197. clif_abyssball( *sd, &sd->bl, SELF );
  8198. if (sd->vd.cloth_color)
  8199. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8200. if (sd->vd.body_style)
  8201. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8202. if(hom_is_active(sd->hd))
  8203. clif_send_homdata( *sd->hd, SP_ACK );
  8204. if( sd->md ) {
  8205. clif_mercenary_info(sd);
  8206. clif_mercenary_skillblock(sd);
  8207. }
  8208. if( sd->ed )
  8209. clif_elemental_info(sd);
  8210. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8211. clif_weather_check(sd);
  8212. if( sd->chatID )
  8213. chat_leavechat(sd,0);
  8214. if( sd->state.vending )
  8215. clif_openvending(sd, sd->bl.id, sd->vending);
  8216. if( pc_issit(sd) )
  8217. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8218. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8219. clif_clearunit_single( sd->bl.id, CLR_DEAD, *sd );
  8220. else
  8221. clif_changed_dir(&sd->bl, SELF);
  8222. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8223. //Issue #2143
  8224. //Cancel Trading State
  8225. if (sd->state.trading)
  8226. trade_tradecancel(sd);
  8227. //Cancel Buying/Selling State
  8228. if (sd->state.buyingstore)
  8229. buyingstore_close(sd);
  8230. mail_clear(sd);
  8231. clif_loadConfirm( sd );
  8232. if( disguised(&sd->bl) ) {/* refresh-da */
  8233. short disguise = sd->disguise;
  8234. pc_disguise(sd, 0);
  8235. pc_disguise(sd, disguise);
  8236. }
  8237. clif_refresh_storagewindow(sd);
  8238. }
  8239. /// Updates the object's (bl) name on client.
  8240. /// Used to update when a char leaves a party/guild. [Skotlex]
  8241. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8242. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8243. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8244. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8245. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8246. nullpo_retv( src );
  8247. nullpo_retv( bl );
  8248. switch( bl->type ){
  8249. case BL_PC: {
  8250. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8251. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8252. packet.gid = bl->id;
  8253. map_session_data *sd = (map_session_data *)bl;
  8254. //Requesting your own "shadow" name. [Skotlex]
  8255. if( src == bl && target == SELF && sd->disguise ){
  8256. packet.gid = -bl->id;
  8257. }
  8258. if( sd->fakename[0] ) {
  8259. safestrncpy( packet.name, sd->fakename, NAME_LENGTH );
  8260. clif_send( &packet, sizeof(packet), src, target );
  8261. return;
  8262. }
  8263. safestrncpy( packet.name, sd->status.name, NAME_LENGTH );
  8264. party_data *p = nullptr;
  8265. if( sd->status.party_id ){
  8266. p = party_search( sd->status.party_id );
  8267. }
  8268. // do not display party unless the player is also in a guild
  8269. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8270. safestrncpy( packet.party_name, p->party.name, NAME_LENGTH );
  8271. }
  8272. if( sd->guild ){
  8273. int position;
  8274. // Will get the position of the guild the player is in
  8275. position = guild_getposition(*sd);
  8276. safestrncpy( packet.guild_name, sd->guild->guild.name, NAME_LENGTH );
  8277. safestrncpy( packet.position_name, sd->guild->guild.position[position].name, NAME_LENGTH );
  8278. }else if( sd->clan ){
  8279. safestrncpy( packet.position_name, sd->clan->name, NAME_LENGTH );
  8280. }
  8281. #if PACKETVER_MAIN_NUM >= 20150225 || PACKETVER_RE_NUM >= 20141126 || defined( PACKETVER_ZERO )
  8282. packet.title_id = sd->status.title_id; // Title ID
  8283. #endif
  8284. clif_send(&packet, sizeof(packet), src, target);
  8285. }
  8286. break;
  8287. //[blackhole89]
  8288. case BL_HOM:
  8289. case BL_MER:
  8290. case BL_PET:
  8291. case BL_NPC:
  8292. case BL_ELEM: {
  8293. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8294. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8295. packet.gid = bl->id;
  8296. switch (bl->type) {
  8297. case BL_HOM:
  8298. memcpy(packet.name, ((TBL_HOM *)bl)->homunculus.name, NAME_LENGTH);
  8299. break;
  8300. case BL_MER:
  8301. memcpy(packet.name, ((TBL_MER *)bl)->db->name.c_str(), NAME_LENGTH);
  8302. break;
  8303. case BL_PET:
  8304. safestrncpy(packet.name, ((TBL_PET *)bl)->pet.name, NAME_LENGTH);
  8305. break;
  8306. case BL_NPC:
  8307. safestrncpy(packet.name, ((TBL_NPC *)bl)->name, NAME_LENGTH);
  8308. break;
  8309. case BL_ELEM:
  8310. safestrncpy(packet.name, ((TBL_ELEM *)bl)->db->name.c_str(), NAME_LENGTH);
  8311. break;
  8312. }
  8313. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8314. unit_data *ud = unit_bl2ud(bl);
  8315. if (ud != nullptr) {
  8316. memcpy(packet.title, ud->title, NAME_LENGTH);
  8317. packet.groupId = ud->group_id;
  8318. }
  8319. #endif
  8320. clif_send(&packet, sizeof(packet), src, target);
  8321. }
  8322. break;
  8323. case BL_MOB: {
  8324. mob_data *md = (mob_data *)bl;
  8325. if( md->guardian_data && md->guardian_data->guild_id ){
  8326. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8327. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8328. packet.gid = bl->id;
  8329. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8330. safestrncpy( packet.guild_name, md->guardian_data->guild_name, NAME_LENGTH );
  8331. safestrncpy( packet.position_name, md->guardian_data->castle->castle_name, NAME_LENGTH );
  8332. clif_send(&packet, sizeof(packet), src, target);
  8333. }else if( battle_config.show_mob_info ){
  8334. PACKET_ZC_ACK_REQNAMEALL packet = { 0 };
  8335. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL;
  8336. packet.gid = bl->id;
  8337. safestrncpy( packet.name, md->name, NAME_LENGTH );
  8338. char mobhp[50], *str_p = mobhp;
  8339. if( battle_config.show_mob_info&4 ){
  8340. str_p += sprintf( str_p, "Lv. %d | ", md->level );
  8341. }
  8342. if( battle_config.show_mob_info&1 ){
  8343. str_p += sprintf( str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp );
  8344. }
  8345. if( battle_config.show_mob_info&2 ){
  8346. str_p += sprintf( str_p, "HP: %u%% | ", get_percentage( md->status.hp, md->status.max_hp ) );
  8347. }
  8348. // Even thought mobhp ain't a name, we send it as one so the client can parse it. [Skotlex]
  8349. if( str_p != mobhp ){
  8350. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8351. safestrncpy( packet.party_name, mobhp, NAME_LENGTH );
  8352. }
  8353. clif_send(&packet, sizeof(packet), src, target);
  8354. } else {
  8355. PACKET_ZC_ACK_REQNAMEALL_NPC packet = { 0 };
  8356. packet.packet_id = HEADER_ZC_ACK_REQNAMEALL_NPC;
  8357. packet.gid = bl->id;
  8358. safestrncpy(packet.name, md->name, NAME_LENGTH);
  8359. #if PACKETVER_MAIN_NUM >= 20180207 || PACKETVER_RE_NUM >= 20171129 || PACKETVER_ZERO_NUM >= 20171130
  8360. unit_data *ud = unit_bl2ud(bl);
  8361. if (ud != nullptr) {
  8362. memcpy(packet.title, ud->title, NAME_LENGTH);
  8363. packet.groupId = ud->group_id;
  8364. }
  8365. #endif
  8366. clif_send(&packet, sizeof(packet), src, target);
  8367. }
  8368. }
  8369. break;
  8370. case BL_CHAT:
  8371. case BL_SKILL:
  8372. // Newer clients request this, but do not need an answer
  8373. return;
  8374. default:
  8375. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8376. return;
  8377. }
  8378. }
  8379. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8380. /// 01ff <id>.L <x>.W <y>.W
  8381. ///
  8382. /// Visually moves(instant) a character to x,y. The char moves even
  8383. /// when the target cell isn't walkable. If the char is sitting it
  8384. /// stays that way.
  8385. void clif_slide(struct block_list *bl, int x, int y)
  8386. {
  8387. unsigned char buf[10];
  8388. nullpo_retv(bl);
  8389. WBUFW(buf, 0) = 0x01ff;
  8390. WBUFL(buf, 2) = bl->id;
  8391. WBUFW(buf, 6) = x;
  8392. WBUFW(buf, 8) = y;
  8393. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8394. if( disguised(bl) )
  8395. {
  8396. WBUFL(buf,2) = disguised_bl_id(bl->id);
  8397. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8398. }
  8399. }
  8400. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8401. /// 008d <packet len>.W <id>.L <message>.?B
  8402. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8403. {
  8404. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8405. int16 len_mes;
  8406. len_mes = static_cast<decltype(len_mes)>( strlen(mes) + 1 ); //Account for \0
  8407. if (len_mes > sizeof(buf)-8) {
  8408. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8409. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8410. }
  8411. // send message to others
  8412. if (flag == AREA) {
  8413. WBUFW(buf,0) = 0x8d;
  8414. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8415. WBUFL(buf,4) = bl->id;
  8416. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8417. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8418. }
  8419. // send back message to the speaker
  8420. if( bl->type == BL_PC ) {
  8421. WBUFW(buf,0) = 0x8e;
  8422. WBUFW(buf, 2) = len_mes + 4;
  8423. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8424. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8425. }
  8426. }
  8427. /*==========================
  8428. * Minimap fix [Kevin]
  8429. * Remove dot from minimap
  8430. *--------------------------*/
  8431. void clif_party_xy_remove(map_session_data* sd)
  8432. {
  8433. nullpo_retv(sd);
  8434. PACKET_ZC_NOTIFY_POSITION_TO_GROUPM p{};
  8435. p.PacketType = HEADER_ZC_NOTIFY_POSITION_TO_GROUPM;
  8436. p.AID = sd->status.account_id;
  8437. p.xPos = -1;
  8438. p.yPos = -1;
  8439. clif_send(&p, sizeof(p), &sd->bl, PARTY_SAMEMAP_WOS);
  8440. }
  8441. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8442. /// 0215 <msg id>.L
  8443. /// msg id:
  8444. /// 0x15 = End all negative status (PA_GOSPEL)
  8445. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8446. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8447. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8448. /// 0x19 = All stats +20 (PA_GOSPEL)
  8449. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8450. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8451. /// 0x1e = DEF +25% (PA_GOSPEL)
  8452. /// 0x1f = ATK +100% (PA_GOSPEL)
  8453. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8454. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8455. /// ? = nothing
  8456. void clif_gospel_info(map_session_data *sd, int type)
  8457. {
  8458. int fd=sd->fd;
  8459. WFIFOHEAD(fd,packet_len(0x215));
  8460. WFIFOW(fd,0)=0x215;
  8461. WFIFOL(fd,2)=type;
  8462. WFIFOSET(fd, packet_len(0x215));
  8463. }
  8464. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8465. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8466. /// result:
  8467. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8468. /// star:
  8469. /// 0 = Place of the Sun
  8470. /// 1 = Place of the Moon
  8471. /// 2 = Place of the Stars
  8472. /// 1 = Star Gladiator %s's %s: <mapname>
  8473. /// star:
  8474. /// 0 = Place of the Sun
  8475. /// 1 = Place of the Moon
  8476. /// 2 = Place of the Stars
  8477. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8478. /// star:
  8479. /// 0 = Target of the Sun
  8480. /// 1 = Target of the Moon
  8481. /// 2 = Target of the Stars
  8482. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8483. /// star:
  8484. /// 0 = Monster of the Sun
  8485. /// 1 = Monster of the Moon
  8486. /// 2 = Monster of the Stars
  8487. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8488. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8489. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8490. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8491. /// 40 = Target HP : <monster_id used as HP>
  8492. void clif_starskill(map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8493. {
  8494. int fd = sd->fd;
  8495. WFIFOHEAD(fd,packet_len(0x20e));
  8496. WFIFOW(fd,0) = 0x20e;
  8497. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8498. WFIFOL(fd,26) = monster_id;
  8499. WFIFOB(fd,30) = star;
  8500. WFIFOB(fd,31) = result;
  8501. WFIFOSET(fd,packet_len(0x20e));
  8502. }
  8503. /*==========================================
  8504. * Info about Star Glaldiator save map [Komurka]
  8505. * type: 1: Information, 0: Map registered
  8506. *------------------------------------------*/
  8507. void clif_feel_info(map_session_data* sd, unsigned char feel_level, unsigned char type)
  8508. {
  8509. char mapname[MAP_NAME_LENGTH_EXT];
  8510. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8511. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8512. }
  8513. /*==========================================
  8514. * Info about Star Glaldiator hate mob [Komurka]
  8515. * type: 1: Register mob, 0: Information.
  8516. *------------------------------------------*/
  8517. void clif_hate_info(map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8518. {
  8519. if( pcdb_checkid(class_) ) {
  8520. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8521. } else if( mobdb_checkid(class_) ) {
  8522. clif_starskill(sd, mob_db.find(class_)->jname.c_str(), class_, hate_level, type ? 10 : 11);
  8523. } else {
  8524. ShowWarning("clif_hate_info: Received invalid class %d for this packet (char_id=%d, hate_level=%u, type=%u).\n", class_, sd->status.char_id, (unsigned int)hate_level, (unsigned int)type);
  8525. }
  8526. }
  8527. /*==========================================
  8528. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8529. *------------------------------------------*/
  8530. void clif_mission_info(map_session_data *sd, int mob_id, unsigned char progress)
  8531. {
  8532. clif_starskill(sd, mob_db.find(mob_id)->jname.c_str(), mob_id, progress, 20);
  8533. }
  8534. /*==========================================
  8535. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8536. *------------------------------------------*/
  8537. void clif_feel_hate_reset(map_session_data *sd)
  8538. {
  8539. clif_starskill(sd, "", 0, 0, 30);
  8540. }
  8541. /// Send out reply to configuration change
  8542. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8543. /// type: see enum e_config_type
  8544. /// value:
  8545. /// false = disabled
  8546. /// true = enabled
  8547. void clif_configuration( map_session_data* sd, enum e_config_type type, bool enabled ){
  8548. int fd;
  8549. nullpo_retv(sd);
  8550. fd = sd->fd;
  8551. WFIFOHEAD(fd, packet_len(0x2d9));
  8552. WFIFOW(fd, 0) = 0x2d9;
  8553. WFIFOL(fd, 2) = type;
  8554. WFIFOL(fd, 6) = enabled;
  8555. WFIFOSET(fd, packet_len(0x2d9));
  8556. }
  8557. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8558. /// 02da <open equip window>.B
  8559. /// open equip window:
  8560. /// 0 = disabled
  8561. /// 1 = enabled
  8562. void clif_equipcheckbox(map_session_data* sd)
  8563. {
  8564. int fd;
  8565. nullpo_retv(sd);
  8566. fd = sd->fd;
  8567. WFIFOHEAD(fd, packet_len(0x2da));
  8568. WFIFOW(fd, 0) = 0x2da;
  8569. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8570. WFIFOSET(fd, packet_len(0x2da));
  8571. }
  8572. /// Sends info about a player's equipped items.
  8573. /// 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)
  8574. /// 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)
  8575. /// 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)
  8576. /// 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)
  8577. /// 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)
  8578. /// 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)
  8579. void clif_viewequip_ack( map_session_data& sd, map_session_data& tsd ){
  8580. #if PACKETVER_AD_NUM >= 20071211 || PACKETVER_SAK_NUM >= 20071127 || PACKETVER_MAIN_NUM >= 20071211 || defined(PACKETVER_RE)
  8581. PACKET_ZC_EQUIPWIN_MICROSCOPE* p = reinterpret_cast<PACKET_ZC_EQUIPWIN_MICROSCOPE*>( packet_buffer );
  8582. p->PacketType = HEADER_ZC_EQUIPWIN_MICROSCOPE;
  8583. p->PacketLength = sizeof( *p );
  8584. safestrncpy( p->characterName, tsd.status.name, NAME_LENGTH );
  8585. p->job = tsd.status.class_;
  8586. p->head = tsd.vd.hair_style;
  8587. p->accessory = tsd.vd.head_bottom;
  8588. p->accessory2 = tsd.vd.head_mid;
  8589. p->accessory3 = tsd.vd.head_top;
  8590. #if PACKETVER >= 20110111
  8591. p->robe = tsd.vd.robe;
  8592. #endif
  8593. p->headpalette = tsd.vd.hair_color;
  8594. p->bodypalette = tsd.vd.cloth_color;
  8595. #if PACKETVER_MAIN_NUM >= 20180801 || PACKETVER_RE_NUM >= 20180801 || PACKETVER_ZERO_NUM >= 20180808
  8596. p->body2 = tsd.vd.body_style;
  8597. #endif
  8598. p->sex = tsd.vd.sex;
  8599. for( int i = 0, equip = 0; i < EQI_MAX; i++ ){
  8600. int k = tsd.equip_index[i];
  8601. if( k >= 0 ){
  8602. if( tsd.inventory.u.items_inventory[k].nameid == 0 || tsd.inventory_data[k] == nullptr ){ // Item doesn't exist
  8603. continue;
  8604. }
  8605. if( !tsd.inventory.u.items_inventory[k].equip ){
  8606. continue;
  8607. }
  8608. if( !itemdb_isequip2( tsd.inventory_data[k] ) ){ // Is not equippable
  8609. continue;
  8610. }
  8611. clif_item_equip( client_index( k ), &p->list[equip], &tsd.inventory.u.items_inventory[k], tsd.inventory_data[k], pc_equippoint( &tsd, k ) );
  8612. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( p->list[0] ) );
  8613. equip++;
  8614. }
  8615. }
  8616. clif_send( p, p->PacketLength, &sd.bl, SELF );
  8617. #endif
  8618. }
  8619. /// Display msgstringtable.txt string (ZC_MSG).
  8620. /// 0291 <message>.W
  8621. void clif_msg(map_session_data* sd, unsigned short id)
  8622. {
  8623. int fd;
  8624. nullpo_retv(sd);
  8625. fd = sd->fd;
  8626. WFIFOHEAD(fd, packet_len(0x291));
  8627. WFIFOW(fd, 0) = 0x291;
  8628. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8629. WFIFOSET(fd, packet_len(0x291));
  8630. }
  8631. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8632. /// 0x7e2 <message>.W <value>.L
  8633. void clif_msg_value(map_session_data* sd, unsigned short id, int value)
  8634. {
  8635. int fd = sd->fd;
  8636. WFIFOHEAD(fd, packet_len(0x7e2));
  8637. WFIFOW(fd,0) = 0x7e2;
  8638. WFIFOW(fd,2) = id;
  8639. WFIFOL(fd,4) = value;
  8640. WFIFOSET(fd, packet_len(0x7e2));
  8641. }
  8642. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8643. /// 07e6 <skill id>.W <msg id>.L
  8644. ///
  8645. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8646. /// "[SkillName] Message"
  8647. void clif_msg_skill(map_session_data* sd, uint16 skill_id, int msg_id)
  8648. {
  8649. int fd = sd->fd;
  8650. WFIFOHEAD(fd, packet_len(0x7e6));
  8651. WFIFOW(fd,0) = 0x7e6;
  8652. WFIFOW(fd,2) = skill_id;
  8653. WFIFOL(fd,4) = msg_id;
  8654. WFIFOSET(fd, packet_len(0x7e6));
  8655. }
  8656. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8657. /// 09cd <msg id>.W <color>.L
  8658. void clif_msg_color( map_session_data *sd, uint16 msg_id, uint32 color ){
  8659. nullpo_retv(sd);
  8660. int fd = sd->fd;
  8661. WFIFOHEAD(fd, packet_len(0x9cd));
  8662. WFIFOW(fd, 0) = 0x9cd;
  8663. WFIFOW(fd, 2) = msg_id;
  8664. WFIFOL(fd, 4) = color;
  8665. WFIFOSET(fd, packet_len(0x9cd));
  8666. }
  8667. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8668. /// Returns true if the packet was parsed successfully.
  8669. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8670. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8671. static bool clif_process_message(map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8672. const char* seperator = " : ";
  8673. int fd;
  8674. struct s_packet_db* info;
  8675. uint16 packetLength, inputLength;
  8676. const char *input, *name, *message;
  8677. size_t nameLength, messageLength;
  8678. fd = sd->fd;
  8679. info = &packet_db[RFIFOW(fd,0)];
  8680. packetLength = RFIFOW(fd,info->pos[0]);
  8681. input = RFIFOCP(fd,info->pos[1]);
  8682. // basic structure check for the 4-byte header
  8683. if( packetLength < 4 ){
  8684. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8685. return false;
  8686. }else{
  8687. inputLength = packetLength - 4;
  8688. }
  8689. // process <name> part of the packet
  8690. if( whisperFormat ) {
  8691. // name has fixed width
  8692. if( inputLength < NAME_LENGTH + 1 ) {
  8693. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8694. return false;
  8695. }
  8696. name = input;
  8697. // validate name
  8698. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8699. // only restriction is that the name must be zero-terminated
  8700. if( name[nameLength] != '\0' ) {
  8701. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8702. return false;
  8703. }
  8704. message = input + NAME_LENGTH;
  8705. messageLength = inputLength - NAME_LENGTH;
  8706. }else{
  8707. // name and message are separated by ' : '
  8708. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8709. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8710. // check if there's enough data provided
  8711. if( inputLength < nameLength + seperatorLength + 1 ){
  8712. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8713. return false;
  8714. }
  8715. name = input;
  8716. // validate name
  8717. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8718. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8719. {
  8720. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8721. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8722. set_eof(sd->fd); // Just kick them out to correct it.
  8723. return false;
  8724. }
  8725. message = input + nameLength + seperatorLength;
  8726. messageLength = inputLength - nameLength - seperatorLength;
  8727. }
  8728. #if PACKETVER < 20151001
  8729. // the declared length must match real length
  8730. if( messageLength != strnlen(message, messageLength)+1 ) {
  8731. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8732. return false;
  8733. }
  8734. // verify <message> part of the packet
  8735. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8736. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8737. return false;
  8738. }
  8739. #else
  8740. // No zero termination anymore
  8741. messageLength += 1;
  8742. #endif
  8743. // messages mustn't be too long
  8744. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8745. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8746. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8747. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8748. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8749. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8750. return false;
  8751. }
  8752. // If it is not a whisper message, set the name to the fakename of the player
  8753. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8754. strcpy( out_name, sd->fakename );
  8755. }else{
  8756. safestrncpy( out_name, name, nameLength + 1 );
  8757. }
  8758. safestrncpy( out_message, message, messageLength );
  8759. if( whisperFormat ){
  8760. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8761. out_full_message[nameLength] = '\0';
  8762. }else{
  8763. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8764. }
  8765. if( is_atcommand( fd, sd, out_message, 1 ) )
  8766. return false;
  8767. if (sd->sc.cant.chat || (sd->state.block_action & PCBLOCK_CHAT))
  8768. return false; //no "chatting" while muted.
  8769. if( battle_config.min_chat_delay ) { //[Skotlex]
  8770. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8771. return false;
  8772. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8773. }
  8774. if (battle_config.idletime_option&IDLE_CHAT)
  8775. sd->idletime = last_tick;
  8776. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_CHAT)
  8777. sd->idletime_hom = last_tick;
  8778. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_CHAT)
  8779. sd->idletime_mer = last_tick;
  8780. //achievement_update_objective(sd, AG_CHATTING, 1, 1); // !TODO: Confirm how this achievement is triggered
  8781. return true;
  8782. }
  8783. /**
  8784. * Displays a message if the player enters a PK Zone (during pk_mode)
  8785. * @param sd: Player data
  8786. */
  8787. inline void clif_pk_mode_message(map_session_data * sd)
  8788. {
  8789. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8790. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8791. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8792. char output[CHAT_SIZE_MAX];
  8793. // 1504: You've entered a PK Zone (safe until level %d).
  8794. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8795. battle_config.pk_min_level);
  8796. clif_showscript(&sd->bl, output, SELF);
  8797. } else {
  8798. // 1503: You've entered a PK Zone.
  8799. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8800. }
  8801. }
  8802. return;
  8803. }
  8804. // ---------------------
  8805. // clif_parse_wanttoconnect
  8806. // ---------------------
  8807. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8808. // error codes:
  8809. // 0 - Success
  8810. // 1 - Unknown packet_ver
  8811. // 2 - Invalid account_id
  8812. // 3 - Invalid char_id
  8813. // 4 - Invalid login_id1 (reserved)
  8814. // 5 - Invalid client_tick (reserved)
  8815. // 6 - Invalid sex
  8816. // Only the first 'invalid' error that appears is used.
  8817. static int clif_parse_WantToConnection_sub(int fd)
  8818. {
  8819. int value; //Value is used to temporarily store account/char_id/sex
  8820. //By default, start searching on the default one.
  8821. uint16 cmd = RFIFOW(fd, 0);
  8822. int16 packet_len;
  8823. packet_len = static_cast<decltype(packet_len)>( RFIFOREST( fd ) );
  8824. // FIXME: If the packet is not received at once, this will FAIL.
  8825. // Figure out, when it happens, that only part of the packet is
  8826. // received, or fix the function to be able to deal with that
  8827. // case.
  8828. if( packet_len != packet_db[cmd].len )
  8829. return 1; /* wrong length */
  8830. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8831. return 2; /* invalid account_id */
  8832. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8833. return 3; /* invalid char_id */
  8834. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8835. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8836. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8837. return 6; /* invalid sex */
  8838. else
  8839. return 0;
  8840. }
  8841. /// Request to connect to map-server.
  8842. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8843. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8844. /// There are various variants of this packet, some of them have padding between fields.
  8845. void clif_parse_WantToConnection(int fd, map_session_data* sd)
  8846. {
  8847. struct block_list* bl;
  8848. struct auth_node* node;
  8849. int cmd, account_id, char_id, login_id1, sex, err;
  8850. t_tick client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8851. if (sd) {
  8852. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8853. return;
  8854. }
  8855. cmd = RFIFOW(fd, 0);
  8856. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8857. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8858. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8859. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8860. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8861. err = clif_parse_WantToConnection_sub(fd);
  8862. if( err ){ // connection rejected
  8863. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8864. err == 1 ? "." :
  8865. err == 2 ? ", possibly for having an invalid account_id." :
  8866. err == 3 ? ", possibly for having an invalid char_id." :
  8867. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8868. err == 4 ? ", possibly for having an invalid login_id1." :
  8869. err == 5 ? ", possibly for having an invalid client_tick." :
  8870. */
  8871. err == 6 ? ", possibly for having an invalid sex." :
  8872. ". ERROR invalid error code"));
  8873. WFIFOHEAD(fd,packet_len(0x6a));
  8874. WFIFOW(fd,0) = 0x6a;
  8875. WFIFOB(fd,2) = err;
  8876. WFIFOSET(fd,packet_len(0x6a));
  8877. #ifdef DUMP_INVALID_PACKET
  8878. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8879. #endif
  8880. RFIFOSKIP(fd, RFIFOREST(fd));
  8881. set_eof(fd);
  8882. return;
  8883. }
  8884. if( !global_core->is_running() ){ // not allowed
  8885. clif_authfail_fd(fd,1);// server closed
  8886. return;
  8887. }
  8888. //Check for double login.
  8889. bl = map_id2bl(account_id);
  8890. if(bl && bl->type != BL_PC) {
  8891. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8892. WFIFOHEAD(fd,packet_len(0x6a));
  8893. WFIFOW(fd,0) = 0x6a;
  8894. WFIFOB(fd,2) = 3; // Rejected by server
  8895. WFIFOSET(fd,packet_len(0x6a));
  8896. set_eof(fd);
  8897. return;
  8898. }
  8899. if (bl ||
  8900. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8901. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8902. {
  8903. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8904. return;
  8905. }
  8906. CREATE(sd, TBL_PC, 1);
  8907. new(sd) map_session_data();
  8908. sd->fd = fd;
  8909. #ifdef PACKET_OBFUSCATION
  8910. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8911. #endif
  8912. session[fd]->session_data = sd;
  8913. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8914. #if PACKETVER < 20070521
  8915. WFIFOHEAD(fd,4);
  8916. WFIFOL(fd,0) = sd->bl.id;
  8917. WFIFOSET(fd,4);
  8918. #else
  8919. WFIFOHEAD(fd,packet_len(0x283));
  8920. WFIFOW(fd,0) = 0x283;
  8921. WFIFOL(fd,2) = sd->bl.id;
  8922. WFIFOSET(fd,packet_len(0x283));
  8923. #endif
  8924. chrif_authreq(sd,false);
  8925. }
  8926. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8927. /// 007d
  8928. void clif_parse_LoadEndAck(int fd,map_session_data *sd)
  8929. {
  8930. bool guild_notice = false;
  8931. if(sd->bl.prev != nullptr)
  8932. return;
  8933. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8934. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8935. //Let pc_reg_received or pc_scdata_received reinvoke this when ready.
  8936. sd->state.connect_new = 0;
  8937. return;
  8938. }
  8939. if (sd->state.rewarp) { //Rewarp player.
  8940. sd->state.rewarp = 0;
  8941. clif_changemap( *sd, sd->bl.m, sd->bl.x, sd->bl.y );
  8942. return;
  8943. }
  8944. sd->state.warping = 0;
  8945. // look
  8946. #if PACKETVER < 4
  8947. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8948. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8949. #else
  8950. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8951. #endif
  8952. pc_set_costume_view(sd);
  8953. if(sd->vd.cloth_color)
  8954. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8955. if(sd->vd.body_style)
  8956. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8957. // item
  8958. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8959. pc_checkitem(sd);
  8960. clif_equipswitch_list(sd);
  8961. // cart
  8962. if(pc_iscarton(sd)) {
  8963. clif_cartlist(sd);
  8964. clif_updatestatus(*sd,SP_CARTINFO);
  8965. }
  8966. // weight
  8967. clif_updatestatus(*sd,SP_WEIGHT);
  8968. clif_updatestatus(*sd,SP_MAXWEIGHT);
  8969. // guild
  8970. // (needs to go before clif_spawn() to show guild emblems correctly)
  8971. if(sd->status.guild_id)
  8972. guild_send_memberinfoshort(sd,1);
  8973. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  8974. if(battle_config.pc_invincible_time > 0) {
  8975. if(mapdata_flag_gvg(mapdata))
  8976. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8977. else
  8978. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8979. }
  8980. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  8981. map_spawnmobs(sd->bl.m);
  8982. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8983. mapdata->users_pvp++;
  8984. }
  8985. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8986. // reset the callshop flag if the player changes map
  8987. sd->state.callshop = 0;
  8988. if(map_addblock(&sd->bl))
  8989. return;
  8990. clif_spawn(&sd->bl);
  8991. // Party
  8992. // (needs to go after clif_spawn() to show hp bars correctly)
  8993. if(sd->status.party_id) {
  8994. party_send_movemap(sd);
  8995. clif_party_hp( *sd ); // Show hp after displacement [LuzZza]
  8996. }
  8997. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8998. if(!pc_isinvisible(sd) && mapdata->getMapFlag(MF_PVP)) {
  8999. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  9000. if (!mapdata->getMapFlag(MF_PVP_NOCALCRANK))
  9001. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  9002. sd->pvp_rank = 0;
  9003. sd->pvp_lastusers = 0;
  9004. sd->pvp_point = 5;
  9005. sd->pvp_won = 0;
  9006. sd->pvp_lost = 0;
  9007. }
  9008. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9009. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  9010. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  9011. else if (mapdata->getMapFlag(MF_GVG_DUNGEON))
  9012. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  9013. else if( mapdata_flag_gvg(mapdata) )
  9014. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  9015. else
  9016. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  9017. // info about nearby objects
  9018. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  9019. 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);
  9020. // pet
  9021. if( sd->pd ) {
  9022. if( battle_config.pet_no_gvg && mapdata_flag_gvg(mapdata) ) { //Return the pet to egg. [Skotlex]
  9023. clif_displaymessage(sd->fd, msg_txt(sd,666));
  9024. pet_return_egg( sd, sd->pd );
  9025. } else {
  9026. if(map_addblock(&sd->pd->bl))
  9027. return;
  9028. clif_spawn(&sd->pd->bl);
  9029. clif_send_petdata(sd,sd->pd,0,0);
  9030. clif_send_petstatus(sd);
  9031. // skill_unit_move(&sd->pd->bl,gettick(),1);
  9032. }
  9033. }
  9034. //homunculus [blackhole89]
  9035. if( hom_is_active(sd->hd) ) {
  9036. if(map_addblock(&sd->hd->bl))
  9037. return;
  9038. clif_spawn(&sd->hd->bl);
  9039. clif_send_homdata( *sd->hd, SP_ACK );
  9040. clif_hominfo(sd,sd->hd,1);
  9041. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  9042. clif_homskillinfoblock( *sd->hd );
  9043. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  9044. status_calc_bl(&sd->hd->bl, { SCB_SPEED }); //Homunc mimic their master's speed on each map change
  9045. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  9046. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  9047. }
  9048. if( sd->md ) {
  9049. if(map_addblock(&sd->md->bl))
  9050. return;
  9051. clif_spawn(&sd->md->bl);
  9052. clif_mercenary_info(sd);
  9053. clif_mercenary_skillblock(sd);
  9054. status_calc_bl(&sd->md->bl, { SCB_SPEED }); // Mercenary mimic their master's speed on each map change
  9055. }
  9056. if( sd->ed ) {
  9057. if (map_addblock(&sd->ed->bl))
  9058. return;
  9059. clif_spawn(&sd->ed->bl);
  9060. clif_elemental_info(sd);
  9061. clif_elemental_updatestatus(sd,SP_HP);
  9062. clif_hpmeter_single( *sd, sd->ed->bl.id, sd->ed->battle_status.hp, sd->ed->battle_status.max_hp );
  9063. clif_elemental_updatestatus(sd,SP_SP);
  9064. status_calc_bl(&sd->ed->bl, { SCB_SPEED }); //Elemental mimic their master's speed on each map change
  9065. }
  9066. if(sd->state.connect_new) {
  9067. int lv;
  9068. guild_notice = true;
  9069. clif_skillinfoblock(sd);
  9070. clif_hotkeys_send(sd,0);
  9071. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9072. clif_hotkeys_send(sd,1);
  9073. #endif
  9074. clif_updatestatus(*sd,SP_BASEEXP);
  9075. clif_updatestatus(*sd,SP_NEXTBASEEXP);
  9076. clif_updatestatus(*sd,SP_JOBEXP);
  9077. clif_updatestatus(*sd,SP_NEXTJOBEXP);
  9078. clif_updatestatus(*sd,SP_SKILLPOINT);
  9079. clif_initialstatus( *sd );
  9080. if (sd->sc.option&OPTION_FALCON)
  9081. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9082. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON))
  9083. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9084. else if (sd->sc.option&OPTION_WUGRIDER)
  9085. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9086. else if (sd->sc.getSCE(SC_ALL_RIDING))
  9087. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9088. if(sd->status.manner < 0)
  9089. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9090. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9091. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9092. if(sd->bl.m == sd->feel_map[0].m
  9093. || sd->bl.m == sd->feel_map[1].m
  9094. || sd->bl.m == sd->feel_map[2].m)
  9095. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9096. }
  9097. if(sd->pd && sd->pd->pet.intimate > 900)
  9098. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9099. if(hom_is_active(sd->hd))
  9100. hom_init_timers(sd->hd);
  9101. if (night_flag && mapdata->getMapFlag(MF_NIGHTENABLED)) {
  9102. sd->state.night = 1;
  9103. clif_status_load(&sd->bl, EFST_SKE, 1);
  9104. }
  9105. // Notify everyone that this char logged in [Skotlex].
  9106. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9107. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9108. npc_script_event( *sd, NPCE_LOGIN );
  9109. }
  9110. // Set facing direction before check below to update client
  9111. if (battle_config.spawn_direction)
  9112. unit_setdir(&sd->bl, sd->status.body_direction, false);
  9113. } else {
  9114. //For some reason the client "loses" these on warp/map-change.
  9115. clif_updatestatus(*sd,SP_STR);
  9116. clif_updatestatus(*sd,SP_AGI);
  9117. clif_updatestatus(*sd,SP_VIT);
  9118. clif_updatestatus(*sd,SP_INT);
  9119. clif_updatestatus(*sd,SP_DEX);
  9120. clif_updatestatus(*sd,SP_LUK);
  9121. #ifdef RENEWAL
  9122. clif_updatestatus(*sd,SP_POW);
  9123. clif_updatestatus(*sd,SP_STA);
  9124. clif_updatestatus(*sd,SP_WIS);
  9125. clif_updatestatus(*sd,SP_SPL);
  9126. clif_updatestatus(*sd,SP_CON);
  9127. clif_updatestatus(*sd,SP_CRT);
  9128. #endif
  9129. // abort currently running script
  9130. sd->state.using_fake_npc = 0;
  9131. sd->state.menu_or_input = 0;
  9132. sd->npc_menu = 0;
  9133. if(sd->npc_id)
  9134. npc_event_dequeue(sd);
  9135. }
  9136. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9137. clif_partyinvitationstate( *sd );
  9138. #if PACKETVER >= 20070918
  9139. clif_equipcheckbox(sd);
  9140. #endif
  9141. clif_pet_autofeed_status(sd,false);
  9142. clif_configuration( sd, CONFIG_CALL, sd->status.disable_call );
  9143. #if PACKETVER >= 20170920
  9144. if( battle_config.homunculus_autofeed_always ){
  9145. // Always send ON or OFF
  9146. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9147. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9148. }else{
  9149. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9150. }
  9151. }else{
  9152. // Only send when enabled
  9153. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9154. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9155. }
  9156. }
  9157. #endif
  9158. clif_reputation_list( *sd );
  9159. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9160. clif_guild_notice(sd); // Displays after VIP
  9161. guild_notice = false; // Do not display it twice
  9162. }
  9163. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9164. struct map_data *pmap = map_getmapdata(sd->state.pmap);
  9165. if ((pmap != nullptr && (mapdata_flag_gvg(pmap) || pmap->getMapFlag(MF_BATTLEGROUND))) || (mapdata != nullptr && (mapdata_flag_gvg(mapdata) || mapdata->getMapFlag(MF_BATTLEGROUND))))
  9166. status_calc_bl(&sd->bl, { SCB_FLEE }); //Refresh flee penalty
  9167. }
  9168. if( night_flag && mapdata->getMapFlag(MF_NIGHTENABLED) )
  9169. { //Display night.
  9170. if( !sd->state.night )
  9171. {
  9172. sd->state.night = 1;
  9173. clif_status_load(&sd->bl, EFST_SKE, 1);
  9174. }
  9175. }
  9176. else if( sd->state.night )
  9177. { //Clear night display.
  9178. sd->state.night = 0;
  9179. clif_status_load(&sd->bl, EFST_SKE, 0);
  9180. }
  9181. if( mapdata->getMapFlag(MF_BATTLEGROUND) )
  9182. {
  9183. clif_map_type( *sd, MAPTYPE_BATTLEFIELD ); // Battleground Mode
  9184. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9185. clif_bg_updatescore_single(sd);
  9186. }
  9187. if( mapdata->getMapFlag(MF_ALLOWKS) && !mapdata_flag_ks(mapdata) )
  9188. {
  9189. char output[128];
  9190. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9191. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9192. }
  9193. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9194. mapdata->hpmeter_visible++;
  9195. sd->state.hpmeter_visible = 1;
  9196. }
  9197. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9198. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9199. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9200. #ifdef VIP_ENABLE
  9201. if (!sd->state.connect_new &&
  9202. !sd->vip.disableshowrate &&
  9203. sd->state.pmap != sd->bl.m &&
  9204. map_getmapflag(sd->state.pmap, MF_BEXP) != mapdata->getMapFlag(MF_BEXP)
  9205. )
  9206. {
  9207. clif_display_pinfo( *sd );
  9208. }
  9209. #endif
  9210. // Instances do not need their own channels
  9211. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !mapdata->instance_id && !mapdata->getMapFlag(MF_NOMAPCHANNELAUTOJOIN) )
  9212. channel_mjoin(sd); //join new map
  9213. clif_pk_mode_message(sd);
  9214. }
  9215. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9216. clif_guild_notice(sd); // Displays at end
  9217. }
  9218. mail_clear(sd);
  9219. /* Guild Aura Init */
  9220. if( sd->guild && sd->state.gmaster_flag ) {
  9221. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild->guild,GD_LEADERSHIP));
  9222. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild->guild,GD_GLORYWOUNDS));
  9223. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild->guild,GD_SOULCOLD));
  9224. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild->guild,GD_HAWKEYES));
  9225. }
  9226. if( sd->state.vending ) { /* show we have a vending */
  9227. clif_openvending(sd,sd->bl.id,sd->vending);
  9228. clif_showvendingboard( *sd );
  9229. }
  9230. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9231. if(!sd->state.autotrade && mapdata->getMapFlag(MF_LOADEVENT)) // Lance
  9232. npc_script_event( *sd, NPCE_LOADMAP );
  9233. if (pc_checkskill(sd, SG_DEVIL) && ((sd->class_&MAPID_THIRDMASK) == MAPID_STAR_EMPEROR || pc_is_maxjoblv(sd)))
  9234. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9235. if (sd->sc.opt2) //Client loses these on warp.
  9236. clif_changeoption(&sd->bl);
  9237. 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)) {
  9238. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM);
  9239. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM);
  9240. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9241. }
  9242. clif_weather_check(sd);
  9243. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9244. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9245. npc_touch_area_allnpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9246. else
  9247. sd->areanpc.clear();
  9248. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9249. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9250. pc_setdead(sd);
  9251. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9252. if(pc_isdead(sd))
  9253. clif_clearunit_area( sd->bl, CLR_DEAD );
  9254. else {
  9255. skill_usave_trigger(sd);
  9256. if (battle_config.spawn_direction)
  9257. clif_changed_dir(&sd->bl, SELF);
  9258. }
  9259. // Trigger skill effects if you appear standing on them
  9260. if(!battle_config.pc_invincible_time)
  9261. skill_unit_move(&sd->bl,gettick(),1);
  9262. pc_show_questinfo_reinit(sd);
  9263. pc_show_questinfo(sd);
  9264. #if PACKETVER >= 20150513
  9265. if( sd->mail.inbox.unread ){
  9266. clif_Mail_new(sd, 0, nullptr, nullptr);
  9267. }
  9268. #endif
  9269. sd->state.connect_new = 0;
  9270. sd->state.changemap = false;
  9271. }
  9272. /// Server's tick (ZC_NOTIFY_TIME).
  9273. /// 007f <time>.L
  9274. void clif_notify_time(map_session_data* sd, t_tick time)
  9275. {
  9276. int fd = sd->fd;
  9277. WFIFOHEAD(fd,packet_len(0x7f));
  9278. WFIFOW(fd,0) = 0x7f;
  9279. WFIFOL(fd,2) = client_tick(time);
  9280. WFIFOSET(fd,packet_len(0x7f));
  9281. }
  9282. /// Request for server's tick.
  9283. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9284. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9285. /// There are various variants of this packet, some of them have padding between fields.
  9286. void clif_parse_TickSend(int fd, map_session_data *sd)
  9287. {
  9288. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9289. clif_notify_time(sd, gettick());
  9290. }
  9291. /// Sends hotkey bar.
  9292. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9293. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9294. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9295. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9296. void clif_hotkeys_send( map_session_data *sd, int tab ){
  9297. #if defined(HOTKEY_SAVING) && ( PACKETVER_MAIN_NUM >= 20070711 || PACKETVER_RE_NUM >= 20080827 || PACKETVER_AD_NUM >= 20070711 || PACKETVER_SAK_NUM >= 20070628 )
  9298. nullpo_retv( sd );
  9299. struct PACKET_ZC_SHORTCUT_KEY_LIST p;
  9300. p.packetType = HEADER_ZC_SHORTCUT_KEY_LIST;
  9301. #if PACKETVER_MAIN_NUM >= 20141022 || PACKETVER_RE_NUM >= 20141015 || defined(PACKETVER_ZERO)
  9302. if( tab == 0 ){
  9303. p.rotate = sd->status.hotkey_rowshift;
  9304. }else{
  9305. p.rotate = sd->status.hotkey_rowshift2;
  9306. }
  9307. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9308. p.tab = tab;
  9309. #endif
  9310. #endif
  9311. for( int i = 0, offset = tab * MAX_HOTKEYS; i < MAX_HOTKEYS_PACKET; i++ ){
  9312. p.hotkey[i].isSkill = sd->status.hotkeys[i + offset].type;
  9313. p.hotkey[i].id = sd->status.hotkeys[i + offset].id;
  9314. p.hotkey[i].count = sd->status.hotkeys[i + offset].lv;
  9315. }
  9316. clif_send( &p, sizeof(struct PACKET_ZC_SHORTCUT_KEY_LIST), &sd->bl, SELF );
  9317. #endif
  9318. }
  9319. /// Request to update a position on the hotkey row bar
  9320. void clif_parse_HotkeyRowShift( int fd, map_session_data *sd ){
  9321. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9322. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE2 *)RFIFOP( fd, 0 );
  9323. if( p->tab == 0 ){
  9324. sd->status.hotkey_rowshift = p->rowshift;
  9325. }else{
  9326. sd->status.hotkey_rowshift2 = p->rowshift;
  9327. }
  9328. #elif PACKETVER_MAIN_NUM >= 20140129 || PACKETVER_RE_NUM >= 20140129 || defined(PACKETVER_ZERO)
  9329. const struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *p = (struct PACKET_CZ_SHORTCUTKEYBAR_ROTATE1 *)RFIFOP( fd, 0 );
  9330. sd->status.hotkey_rowshift = p->rowshift;
  9331. #endif
  9332. }
  9333. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9334. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9335. void clif_parse_Hotkey(int fd, map_session_data *sd) {
  9336. #ifdef HOTKEY_SAVING
  9337. #if PACKETVER_MAIN_NUM >= 20190522 || PACKETVER_RE_NUM >= 20190508 || PACKETVER_ZERO_NUM >= 20190605
  9338. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE2* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE2*)RFIFOP( fd, 0 );
  9339. const unsigned short idx = p->index + p->tab * MAX_HOTKEYS;
  9340. if( idx >= MAX_HOTKEYS_DB ){
  9341. return;
  9342. }
  9343. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9344. sd->status.hotkeys[idx].id = p->hotkey.id;
  9345. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9346. #elif PACKETVER_MAIN_NUM >= 20070618 || defined(PACKETVER_RE) || defined(PACKETVER_ZERO) || PACKETVER_AD_NUM >= 20070618 || PACKETVER_SAK_NUM >= 20070618
  9347. const struct PACKET_CZ_SHORTCUT_KEY_CHANGE1* p = (struct PACKET_CZ_SHORTCUT_KEY_CHANGE1*)RFIFOP( fd, 0 );
  9348. const unsigned short idx = p->index;
  9349. if( idx >= MAX_HOTKEYS_DB ){
  9350. return;
  9351. }
  9352. sd->status.hotkeys[idx].type = p->hotkey.isSkill;
  9353. sd->status.hotkeys[idx].id = p->hotkey.id;
  9354. sd->status.hotkeys[idx].lv = p->hotkey.count;
  9355. #endif
  9356. #endif
  9357. }
  9358. /// Displays cast-like progress bar (ZC_PROGRESS).
  9359. /// 02f0 <color>.L <time>.L
  9360. void clif_progressbar(map_session_data * sd, unsigned long color, unsigned int second)
  9361. {
  9362. int fd = sd->fd;
  9363. WFIFOHEAD(fd,packet_len(0x2f0));
  9364. WFIFOW(fd,0) = 0x2f0;
  9365. WFIFOL(fd,2) = color;
  9366. WFIFOL(fd,6) = second;
  9367. WFIFOSET(fd,packet_len(0x2f0));
  9368. }
  9369. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9370. /// 02f2
  9371. void clif_progressbar_abort(map_session_data * sd)
  9372. {
  9373. int fd = sd->fd;
  9374. WFIFOHEAD(fd,packet_len(0x2f2));
  9375. WFIFOW(fd,0) = 0x2f2;
  9376. WFIFOSET(fd,packet_len(0x2f2));
  9377. }
  9378. /// Notification from the client, that the progress bar has reached 100%.
  9379. /// 02f1 (CZ_PROGRESS)
  9380. void clif_parse_progressbar(int fd, map_session_data * sd){
  9381. // No progressbar active, ignore it
  9382. if( !sd->progressbar.npc_id ){
  9383. return;
  9384. }
  9385. int npc_id = sd->progressbar.npc_id;
  9386. bool closing = false;
  9387. // Check if the progress was canceled
  9388. if( gettick() < sd->progressbar.timeout && sd->st ){
  9389. closing = true;
  9390. sd->st->state = CLOSE; // will result in END in npc_scriptcont
  9391. // If a message window was open, offer a close button to the user
  9392. if( sd->st->mes_active ){
  9393. clif_scriptclose( *sd, npc_id );
  9394. }
  9395. }
  9396. sd->progressbar.npc_id = 0;
  9397. sd->progressbar.timeout = 0;
  9398. sd->state.workinprogress = WIP_DISABLE_NONE;
  9399. if( battle_config.idletime_option&IDLE_NPC_PROGRESS ){
  9400. sd->idletime = last_tick;
  9401. }
  9402. npc_scriptcont(sd, npc_id, closing);
  9403. }
  9404. /// Displays cast-like progress bar on a NPC
  9405. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9406. void clif_progressbar_npc( struct npc_data *nd, map_session_data* sd ){
  9407. #if PACKETVER >= 20130821
  9408. unsigned char buf[14];
  9409. if( nd->progressbar.timeout > 0 ){
  9410. WBUFW(buf,0) = 0x9d1;
  9411. WBUFL(buf,2) = nd->bl.id;
  9412. WBUFL(buf,6) = nd->progressbar.color;
  9413. WBUFL(buf,10) = client_tick( ( nd->progressbar.timeout - gettick() ) / 1000 );
  9414. if( sd ){
  9415. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9416. }else{
  9417. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9418. }
  9419. }
  9420. #endif
  9421. }
  9422. /// Request to walk to a certain position on the current map.
  9423. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9424. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9425. /// There are various variants of this packet, some of them have padding between fields.
  9426. void clif_parse_WalkToXY(int fd, map_session_data *sd)
  9427. {
  9428. short x, y;
  9429. if (pc_isdead(sd)) {
  9430. clif_clearunit_area( sd->bl, CLR_DEAD );
  9431. return;
  9432. }
  9433. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9434. ; //You CAN walk on this OPT1 value.
  9435. else if (sd->progressbar.npc_id) {
  9436. clif_progressbar_abort(sd);
  9437. return; // First walk attempt cancels the progress bar
  9438. } else if (pc_cant_act(sd))
  9439. return;
  9440. if(sd->sc.getSCE(SC_RUN) || sd->sc.getSCE(SC_WUGDASH))
  9441. return;
  9442. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, nullptr);
  9443. //A move command one cell west is only valid if the target cell is free
  9444. if(battle_config.official_cell_stack_limit > 0
  9445. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9446. return;
  9447. // Cloaking wall check is actually updated when you click to process next movement
  9448. // not when you move each cell. This is official behaviour.
  9449. if (sd->sc.getSCE(SC_CLOAKING))
  9450. skill_check_cloaking(&sd->bl, sd->sc.getSCE(SC_CLOAKING));
  9451. status_change_end(&sd->bl, SC_ROLLINGCUTTER); // If you move, you lose your counters. [malufett]
  9452. status_change_end(&sd->bl, SC_CRESCIVEBOLT);
  9453. pc_delinvincibletimer(sd);
  9454. //Set last idle time... [Skotlex]
  9455. if (battle_config.idletime_option&IDLE_WALK)
  9456. sd->idletime = last_tick;
  9457. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_WALK)
  9458. sd->idletime_hom = last_tick;
  9459. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_WALK)
  9460. sd->idletime_mer = last_tick;
  9461. unit_walktoxy(&sd->bl, x, y, 4);
  9462. }
  9463. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9464. /// 018b <result>.W
  9465. /// result:
  9466. /// 0 = disconnect (quit)
  9467. /// 1 = cannot disconnect (wait 10 seconds)
  9468. /// ? = ignored
  9469. void clif_disconnect_ack(map_session_data* sd, short result)
  9470. {
  9471. int fd = sd->fd;
  9472. WFIFOHEAD(fd,packet_len(0x18b));
  9473. WFIFOW(fd,0) = 0x18b;
  9474. WFIFOW(fd,2) = result;
  9475. WFIFOSET(fd,packet_len(0x18b));
  9476. }
  9477. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9478. /// 018a <type>.W
  9479. /// type:
  9480. /// 0 = quit
  9481. void clif_parse_QuitGame(int fd, map_session_data *sd)
  9482. {
  9483. /* Rovert's prevent logout option fixed [Valaris] */
  9484. 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) &&
  9485. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9486. {
  9487. pc_damage_log_clear(sd,0);
  9488. clif_disconnect_ack(sd, 0);
  9489. flush_fifo( fd );
  9490. if( battle_config.drop_connection_on_quit ){
  9491. set_eof( fd );
  9492. }
  9493. } else {
  9494. clif_disconnect_ack(sd, 1);
  9495. }
  9496. }
  9497. /// Requesting unit's name.
  9498. /// 0094 <id>.L (CZ_REQNAME)
  9499. /// 0368 <id>.L (CZ_REQNAME2)
  9500. /// There are various variants of this packet, some of them have padding between fields.
  9501. void clif_parse_GetCharNameRequest(int fd, map_session_data *sd)
  9502. {
  9503. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9504. struct block_list* bl;
  9505. //status_change *sc;
  9506. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9507. id = sd->bl.id;
  9508. bl = map_id2bl(id);
  9509. if( bl == nullptr )
  9510. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9511. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9512. return; // Block namerequests past view range
  9513. // 'see people in GM hide' cheat detection
  9514. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9515. sc = status_get_sc(bl);
  9516. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9517. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9518. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9519. ) {
  9520. char gm_msg[256];
  9521. 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);
  9522. ShowWarning(gm_msg);
  9523. // information is sent to all online GMs
  9524. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9525. return;
  9526. }
  9527. */
  9528. clif_name(&sd->bl,bl,SELF);
  9529. }
  9530. /// Validates and processes global messages
  9531. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9532. /// There are various variants of this packet.
  9533. void clif_parse_GlobalMessage(int fd, map_session_data* sd)
  9534. {
  9535. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9536. size_t length;
  9537. // validate packet and retrieve name and message
  9538. if( !clif_process_message(sd, false, name, message, output ) )
  9539. return;
  9540. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9541. channel_send(sd->gcbind,sd,message);
  9542. return;
  9543. }
  9544. // send message to others (using the send buffer for temp. storage)
  9545. clif_GlobalMessage( sd->bl, output, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC );
  9546. length = strlen(output) + 1;
  9547. // send back message to the speaker
  9548. WFIFOHEAD(fd,4+length);
  9549. WFIFOW(fd,0) = 0x8e;
  9550. WFIFOW(fd,2) = (uint16)(4+length);
  9551. safestrncpy(WFIFOCP(fd,4), output, length );
  9552. WFIFOSET(fd, WFIFOW(fd,2));
  9553. #ifdef PCRE_SUPPORT
  9554. // trigger listening npcs
  9555. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9556. #endif
  9557. // Chat logging type 'O' / Global Chat
  9558. 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);
  9559. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9560. }
  9561. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9562. /// Request to warp to a map on given coordinates.
  9563. /// 0140 <map name>.16B <x>.W <y>.W
  9564. void clif_parse_MapMove(int fd, map_session_data *sd)
  9565. {
  9566. char command[MAP_NAME_LENGTH_EXT+25];
  9567. char* map_name;
  9568. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9569. map_name = RFIFOCP(fd,info->pos[0]);
  9570. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9571. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9572. RFIFOW(fd,info->pos[1]), //x
  9573. RFIFOW(fd,info->pos[2])); //y
  9574. is_atcommand(fd, sd, command, 1);
  9575. }
  9576. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9577. /// 009c <id>.L <head dir>.W <dir>.B
  9578. /// head dir:
  9579. /// 0 = straight
  9580. /// 1 = turned CW
  9581. /// 2 = turned CCW
  9582. /// dir:
  9583. /// 0 = north
  9584. /// 1 = northwest
  9585. /// 2 = west
  9586. /// 3 = southwest
  9587. /// 4 = south
  9588. /// 5 = southeast
  9589. /// 6 = east
  9590. /// 7 = northeast
  9591. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9592. {
  9593. unsigned char buf[64];
  9594. WBUFW(buf,0) = 0x9c;
  9595. WBUFL(buf,2) = bl->id;
  9596. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9597. WBUFB(buf,8) = unit_getdir(bl);
  9598. clif_send(buf, packet_len(0x9c), bl, target);
  9599. if (disguised(bl)) {
  9600. WBUFL(buf,2) = disguised_bl_id(bl->id);
  9601. WBUFW(buf,6) = 0;
  9602. clif_send(buf, packet_len(0x9c), bl, SELF);
  9603. }
  9604. }
  9605. /// Request to change own body and head direction.
  9606. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9607. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9608. /// There are various variants of this packet, some of them have padding between fields.
  9609. void clif_parse_ChangeDir(int fd, map_session_data *sd)
  9610. {
  9611. unsigned char headdir, dir;
  9612. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9613. headdir = RFIFOB(fd,info->pos[0]);
  9614. dir = RFIFOB(fd,info->pos[1]);
  9615. pc_setdir(sd, dir, headdir);
  9616. clif_changed_dir(&sd->bl, AREA_WOS);
  9617. }
  9618. /// Request to show an emotion (CZ_REQ_EMOTION).
  9619. /// 00bf <type>.B
  9620. /// type:
  9621. /// @see enum emotion_type
  9622. void clif_parse_Emotion(int fd, map_session_data *sd){
  9623. if( sd == nullptr ){
  9624. return;
  9625. }
  9626. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9627. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9628. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9629. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9630. return;
  9631. }
  9632. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9633. if (sd->emotionlasttime + 1 >= time(nullptr)) { // not more than 1 per second
  9634. sd->emotionlasttime = time(nullptr);
  9635. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9636. return;
  9637. }
  9638. sd->emotionlasttime = time(nullptr);
  9639. if (battle_config.idletime_option&IDLE_EMOTION)
  9640. sd->idletime = last_tick;
  9641. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_EMOTION)
  9642. sd->idletime_hom = last_tick;
  9643. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_EMOTION)
  9644. sd->idletime_mer = last_tick;
  9645. if (sd->state.block_action & PCBLOCK_EMOTION) {
  9646. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9647. return;
  9648. }
  9649. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9650. emoticon = rnd()%6+ET_DICE1;
  9651. }
  9652. clif_emotion(&sd->bl, emoticon);
  9653. } else
  9654. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 1 );
  9655. }
  9656. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9657. /// 00c2 <count>.L
  9658. void clif_user_count(map_session_data* sd, int count)
  9659. {
  9660. int fd = sd->fd;
  9661. WFIFOHEAD(fd,packet_len(0xc2));
  9662. WFIFOW(fd,0) = 0xc2;
  9663. WFIFOL(fd,2) = count;
  9664. WFIFOSET(fd,packet_len(0xc2));
  9665. }
  9666. /// /w /who (CZ_REQ_USER_COUNT).
  9667. /// Request to display amount of currently connected players.
  9668. /// 00c1
  9669. void clif_parse_HowManyConnections(int fd, map_session_data *sd)
  9670. {
  9671. clif_user_count(sd, map_getusers());
  9672. }
  9673. void clif_parse_ActionRequest_sub( map_session_data& sd, int action_type, int target_id, t_tick tick ){
  9674. if (pc_isdead(&sd)) {
  9675. clif_clearunit_area(sd.bl, CLR_DEAD);
  9676. return;
  9677. }
  9678. // Statuses that don't let the player sit / stand / talk with NPCs (targeted)
  9679. if (action_type != 0x00 && action_type != 0x07) {
  9680. if (sd.sc.cant.interact)
  9681. return;
  9682. pc_stop_walking(&sd, 1);
  9683. }
  9684. pc_stop_attack(&sd);
  9685. if(target_id<0 && -target_id == sd.bl.id) // for disguises [Valaris]
  9686. target_id = sd.bl.id;
  9687. switch(action_type)
  9688. {
  9689. case 0x00: // once attack
  9690. case 0x07: // continuous attack
  9691. if( pc_cant_act(&sd) )
  9692. return;
  9693. if (!battle_config.sdelay_attack_enable && pc_checkskill(&sd, SA_FREECAST) <= 0) {
  9694. if (DIFF_TICK(tick, sd.ud.canact_tick) < 0) {
  9695. clif_skill_fail( sd, 1, USESKILL_FAIL_SKILLINTERVAL );
  9696. return;
  9697. }
  9698. }
  9699. pc_delinvincibletimer(&sd);
  9700. if (battle_config.idletime_option&IDLE_ATTACK)
  9701. sd.idletime = last_tick;
  9702. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_ATTACK)
  9703. sd.idletime_hom = last_tick;
  9704. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_ATTACK)
  9705. sd.idletime_mer = last_tick;
  9706. unit_attack(&sd.bl, target_id, action_type != 0);
  9707. break;
  9708. case 0x02: // sitdown
  9709. if (battle_config.basic_skill_check && pc_checkskill(&sd, NV_BASIC) < 3 && pc_checkskill(&sd, SU_BASIC_SKILL) < 1) {
  9710. clif_skill_fail( sd, 1, USESKILL_FAIL_LEVEL, 2 );
  9711. break;
  9712. }
  9713. if(pc_issit(&sd)) {
  9714. //Bugged client? Just refresh them.
  9715. clif_sitting(&sd.bl);
  9716. return;
  9717. }
  9718. if (sd.ud.skilltimer != INVALID_TIMER || (sd.sc.opt1 && sd.sc.opt1 != OPT1_STONEWAIT && sd.sc.opt1 != OPT1_BURNING))
  9719. break;
  9720. if (sd.sc.count && (
  9721. sd.sc.getSCE(SC_DANCING) ||
  9722. (sd.sc.getSCE(SC_GRAVITATION) && sd.sc.getSCE(SC_GRAVITATION)->val3 == BCT_SELF)
  9723. )) //No sitting during these states either.
  9724. break;
  9725. if (sd.state.block_action & PCBLOCK_SITSTAND) {
  9726. clif_displaymessage(sd.fd, msg_txt(&sd,794)); // This action is currently blocked.
  9727. break;
  9728. }
  9729. if (battle_config.idletime_option&IDLE_SIT)
  9730. sd.idletime = last_tick;
  9731. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_SIT)
  9732. sd.idletime_hom = last_tick;
  9733. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_SIT)
  9734. sd.idletime_mer = last_tick;
  9735. pc_setsit(&sd);
  9736. skill_sit(&sd, true);
  9737. clif_sitting(&sd.bl);
  9738. break;
  9739. case 0x03: // standup
  9740. if (!pc_issit(&sd)) {
  9741. //Bugged client? Just refresh them.
  9742. clif_standing(&sd.bl);
  9743. return;
  9744. }
  9745. if (sd.sc.opt1 && sd.sc.opt1 != OPT1_STONEWAIT && sd.sc.opt1 != OPT1_BURNING)
  9746. break;
  9747. if (sd.state.block_action & PCBLOCK_SITSTAND) {
  9748. clif_displaymessage(sd.fd, msg_txt(&sd,794)); // This action is currently blocked.
  9749. break;
  9750. }
  9751. if (pc_setstand(&sd, false)) {
  9752. if (battle_config.idletime_option&IDLE_SIT)
  9753. sd.idletime = last_tick;
  9754. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_SIT)
  9755. sd.idletime_hom = last_tick;
  9756. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_SIT)
  9757. sd.idletime_mer = last_tick;
  9758. skill_sit(&sd, false);
  9759. clif_standing(&sd.bl);
  9760. }
  9761. break;
  9762. }
  9763. }
  9764. /// Request for an action.
  9765. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9766. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9767. /// action:
  9768. /// 0 = attack
  9769. /// 1 = pick up item
  9770. /// 2 = sit down
  9771. /// 3 = stand up
  9772. /// 7 = continous attack
  9773. /// 12 = (touch skill?)
  9774. /// There are various variants of this packet, some of them have padding between fields.
  9775. void clif_parse_ActionRequest(int fd, map_session_data *sd)
  9776. {
  9777. if( sd == nullptr ){
  9778. return;
  9779. }
  9780. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9781. clif_parse_ActionRequest_sub( *sd,
  9782. RFIFOB(fd,info->pos[1]),
  9783. RFIFOL(fd,info->pos[0]),
  9784. gettick()
  9785. );
  9786. }
  9787. /// Response to the death/system menu (CZ_RESTART).
  9788. /// 00b2 <type>.B
  9789. /// type:
  9790. /// 0 = restart (respawn)
  9791. /// 1 = char-select (disconnect)
  9792. void clif_parse_Restart(int fd, map_session_data *sd)
  9793. {
  9794. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9795. case 0x00:
  9796. pc_respawn(sd,CLR_OUTSIGHT);
  9797. break;
  9798. case 0x01:
  9799. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9800. 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) &&
  9801. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9802. { //Send to char-server for character selection.
  9803. pc_damage_log_clear(sd,0);
  9804. chrif_charselectreq(sd, session[fd]->client_addr);
  9805. } else {
  9806. clif_disconnect_ack(sd, 1);
  9807. }
  9808. break;
  9809. }
  9810. }
  9811. /// Validates and processes whispered messages (CZ_WHISPER).
  9812. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9813. void clif_parse_WisMessage(int fd, map_session_data* sd)
  9814. {
  9815. map_session_data* dstsd;
  9816. int i;
  9817. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9818. // validate packet and retrieve name and message
  9819. if( !clif_process_message( sd, true, target, message, output ) )
  9820. return;
  9821. // Chat logging type 'W' / Whisper
  9822. 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);
  9823. //-------------------------------------------------------//
  9824. // Lordalfa - Paperboy - To whisper NPC commands //
  9825. //-------------------------------------------------------//
  9826. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9827. {
  9828. char* str = target+4; //Skip the NPC: string part.
  9829. struct npc_data* npc;
  9830. if ((npc = npc_name2id(str))) {
  9831. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9832. char *split;
  9833. char event[EVENT_NAME_LENGTH];
  9834. str = message;
  9835. // skip codepage indicator, if detected
  9836. if( str[0] == '|' && strlen(str) >= 4 )
  9837. str += 3;
  9838. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9839. split = strchr(str,'#');
  9840. if( split == nullptr ) { // use the remaining string
  9841. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9842. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9843. split_data[i][0] = '\0';
  9844. break;
  9845. }
  9846. *split = '\0';
  9847. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9848. str = split+1;
  9849. }
  9850. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9851. char variablename[CHAT_SIZE_MAX];
  9852. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9853. set_var_str( sd, variablename, split_data[i] );
  9854. }
  9855. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9856. npc_event(sd,event,0); // Calls the NPC label
  9857. return;
  9858. }
  9859. } else if( target[0] == '#' ) {
  9860. struct Channel *channel = nullptr;
  9861. char* chname = target;
  9862. channel = channel_name2channel(chname,sd,3);
  9863. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9864. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9865. channel_send(channel,sd,message);
  9866. }
  9867. else if( channel->pass[0] == '\0') { //no pass needed
  9868. if (channel_join(channel,sd)==0)
  9869. channel_send(channel,sd,message); //join success
  9870. }
  9871. else {
  9872. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9873. }
  9874. return;
  9875. }
  9876. }
  9877. // searching destination character
  9878. dstsd = map_nick2sd(target,false);
  9879. if (dstsd == nullptr || strcmp(dstsd->status.name, target) != 0) {
  9880. // player is not on this map-server
  9881. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9882. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9883. // and if we ask for 'Test', we must not contact 'test' player
  9884. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9885. intif_wis_message(sd, target, message, strlen(message) + 1);
  9886. return;
  9887. }
  9888. // if player ignores everyone
  9889. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9890. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9891. clif_wis_end( *sd, ACKWHISPER_TARGET_OFFLINE );
  9892. else
  9893. clif_wis_end( *sd, ACKWHISPER_ALL_IGNORED );
  9894. return;
  9895. }
  9896. // if player is autotrading
  9897. if (dstsd->state.autotrade == 1){
  9898. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9899. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9900. return;
  9901. }
  9902. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9903. // if player ignores the source character
  9904. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9905. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9906. clif_wis_end( *sd, ACKWHISPER_IGNORED );
  9907. return;
  9908. }
  9909. }
  9910. // notify sender of success
  9911. clif_wis_end( *sd, ACKWHISPER_SUCCESS );
  9912. // Normal message
  9913. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9914. }
  9915. /// /b /nb (CZ_BROADCAST).
  9916. /// Request to broadcast a message on whole server.
  9917. /// 0099 <packet len>.W <text>.?B 00
  9918. void clif_parse_Broadcast(int fd, map_session_data* sd) {
  9919. char command[CHAT_SIZE_MAX+11];
  9920. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9921. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9922. char* msg = RFIFOCP(fd,info->pos[1]);
  9923. // as the length varies depending on the command used, just block unreasonably long strings
  9924. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9925. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9926. is_atcommand(fd, sd, command, 1);
  9927. }
  9928. /// Request to pick up an item.
  9929. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9930. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9931. /// There are various variants of this packet, some of them have padding between fields.
  9932. void clif_parse_TakeItem(int fd, map_session_data *sd)
  9933. {
  9934. struct flooritem_data *fitem;
  9935. int map_object_id;
  9936. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9937. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9938. do {
  9939. if (pc_isdead(sd)) {
  9940. clif_clearunit_area( sd->bl, CLR_DEAD );
  9941. break;
  9942. }
  9943. if (fitem == nullptr || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9944. break;
  9945. if (pc_cant_act(sd))
  9946. break;
  9947. if (!pc_takeitem(sd, fitem))
  9948. break;
  9949. return;
  9950. } while (0);
  9951. // Client REQUIRES a fail packet or you can no longer pick items.
  9952. clif_additem(sd,0,0,6);
  9953. }
  9954. /// Request to drop an item.
  9955. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9956. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9957. /// There are various variants of this packet, some of them have padding between fields.
  9958. void clif_parse_DropItem(int fd, map_session_data *sd){
  9959. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9960. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9961. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9962. for(;;) {
  9963. if (pc_isdead(sd))
  9964. break;
  9965. if (pc_cant_act2(sd) || sd->npc_id)
  9966. break;
  9967. if (sd->sc.cant.drop)
  9968. break;
  9969. if (!pc_dropitem(sd, item_index, item_amount))
  9970. break;
  9971. if (battle_config.idletime_option&IDLE_DROPITEM)
  9972. sd->idletime = last_tick;
  9973. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_DROPITEM)
  9974. sd->idletime_hom = last_tick;
  9975. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_DROPITEM)
  9976. sd->idletime_mer = last_tick;
  9977. return;
  9978. }
  9979. //Because the client does not like being ignored.
  9980. clif_dropitem( *sd, item_index, 0 );
  9981. }
  9982. /// Request to use an item.
  9983. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9984. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9985. /// There are various variants of this packet, some of them have padding between fields.
  9986. void clif_parse_UseItem(int fd, map_session_data *sd)
  9987. {
  9988. int n;
  9989. if (pc_isdead(sd)) {
  9990. clif_clearunit_area( sd->bl, CLR_DEAD );
  9991. return;
  9992. }
  9993. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID || (sd->state.block_action & PCBLOCK_USEITEM) ) {
  9994. clif_msg(sd, MSI_BUSY);
  9995. return;
  9996. }
  9997. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9998. if (battle_config.idletime_option&IDLE_USEITEM)
  9999. sd->idletime = last_tick;
  10000. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10001. sd->idletime_hom = last_tick;
  10002. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10003. sd->idletime_mer = last_tick;
  10004. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10005. if(n <0 || n >= MAX_INVENTORY)
  10006. return;
  10007. if (!pc_useitem(sd,n))
  10008. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  10009. }
  10010. /// Request to equip an item
  10011. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  10012. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  10013. void clif_parse_EquipItem(int fd,map_session_data *sd)
  10014. {
  10015. int index;
  10016. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10017. if(pc_isdead(sd)) {
  10018. clif_clearunit_area( sd->bl, CLR_DEAD );
  10019. return;
  10020. }
  10021. index = RFIFOW(fd,info->pos[0])-2;
  10022. if (index < 0 || index >= MAX_INVENTORY)
  10023. return; //Out of bounds check.
  10024. if((sd->npc_id && !sd->npc_item_flag) || (sd->state.block_action & PCBLOCK_EQUIP)) {
  10025. clif_msg_color( sd, MSI_CAN_NOT_EQUIP_ITEM, color_table[COLOR_RED] );
  10026. return;
  10027. } else if (sd->state.storage_flag || sd->sc.opt1)
  10028. ; //You can equip/unequip stuff while storage is open/under status changes
  10029. else if (pc_cant_act2(sd))
  10030. return;
  10031. if(!sd->inventory.u.items_inventory[index].identify) {
  10032. clif_equipitemack( *sd, ITEM_EQUIP_ACK_FAIL, index ); // fail
  10033. return;
  10034. }
  10035. if(!sd->inventory_data[index])
  10036. return;
  10037. if(sd->inventory_data[index]->type == IT_PETARMOR){
  10038. pet_equipitem(sd,index);
  10039. return;
  10040. }
  10041. if (battle_config.idletime_option&IDLE_USEITEM)
  10042. sd->idletime = last_tick;
  10043. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10044. sd->idletime_hom = last_tick;
  10045. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10046. sd->idletime_mer = last_tick;
  10047. //Client doesn't send the position for ammo.
  10048. if(sd->inventory_data[index]->type == IT_AMMO)
  10049. pc_equipitem(sd,index,EQP_AMMO);
  10050. else {
  10051. int req_pos;
  10052. #if PACKETVER >= 20120925
  10053. req_pos = RFIFOL(fd,info->pos[1]);
  10054. #else
  10055. req_pos = (int)RFIFOW(fd,info->pos[1]);
  10056. #endif
  10057. pc_equipitem(sd,index,req_pos);
  10058. }
  10059. }
  10060. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  10061. /// 00ab <index>.W
  10062. void clif_parse_UnequipItem(int fd,map_session_data *sd)
  10063. {
  10064. int index;
  10065. if(pc_isdead(sd)) {
  10066. clif_clearunit_area( sd->bl, CLR_DEAD );
  10067. return;
  10068. }
  10069. if((sd->npc_id && !sd->npc_item_flag) || (sd->state.block_action & PCBLOCK_EQUIP)) {
  10070. clif_msg_color( sd, MSI_CAN_NOT_EQUIP_ITEM, color_table[COLOR_RED] );
  10071. return;
  10072. } else if (sd->state.storage_flag || sd->sc.opt1)
  10073. ; //You can equip/unequip stuff while storage is open/under status changes
  10074. else if (pc_cant_act2(sd))
  10075. return;
  10076. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  10077. if (battle_config.idletime_option&IDLE_USEITEM)
  10078. sd->idletime = last_tick;
  10079. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USEITEM)
  10080. sd->idletime_hom = last_tick;
  10081. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USEITEM)
  10082. sd->idletime_mer = last_tick;
  10083. pc_unequipitem(sd,index,1);
  10084. }
  10085. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  10086. /// 0090 <id>.L <type>.B
  10087. /// type:
  10088. /// 1 = click
  10089. void clif_parse_NpcClicked(int fd,map_session_data *sd)
  10090. {
  10091. if( sd == nullptr ){
  10092. return;
  10093. }
  10094. struct block_list *bl;
  10095. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10096. if(pc_isdead(sd)) {
  10097. clif_clearunit_area( sd->bl, CLR_DEAD );
  10098. return;
  10099. }
  10100. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  10101. #ifdef RENEWAL
  10102. clif_msg( sd, MSI_BUSY);
  10103. #endif
  10104. return;
  10105. }
  10106. if( sd->state.mail_writing )
  10107. return;
  10108. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  10109. //type = RFIFOB(fd,info->pos[1]);
  10110. if (!bl) return;
  10111. switch (bl->type) {
  10112. case BL_MOB:
  10113. case BL_PC:
  10114. clif_parse_ActionRequest_sub( *sd, 0x07, bl->id, gettick() );
  10115. break;
  10116. case BL_NPC:
  10117. #ifdef RENEWAL
  10118. 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
  10119. clif_msg(sd, MSI_BUSY);
  10120. break;
  10121. }
  10122. #endif
  10123. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  10124. struct npc_data* nd = (struct npc_data*)bl;
  10125. // Progressbar is running
  10126. if( nd->progressbar.timeout > 0 ){
  10127. return;
  10128. }
  10129. npc_click(sd,nd);
  10130. }
  10131. break;
  10132. }
  10133. }
  10134. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  10135. /// 00c5 <id>.L <type>.B
  10136. /// type:
  10137. /// 0 = buy
  10138. /// 1 = sell
  10139. void clif_parse_NpcBuySellSelected(int fd,map_session_data *sd)
  10140. {
  10141. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10142. if (sd->state.trading)
  10143. return;
  10144. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  10145. }
  10146. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  10147. /// 00ca <result>.B
  10148. /// result:
  10149. /// 0 = "The deal has successfully completed."
  10150. /// 1 = "You do not have enough zeny."
  10151. /// 2 = "You are over your Weight Limit."
  10152. /// 3 = "Out of the maximum capacity, you have too many items."
  10153. /// 9 = "Amounts are exceeded the possession of the item is not available for purchase."
  10154. /// 10 = "Props open-air store sales will be traded in RODEX"
  10155. /// 11 = "The exchange failed."
  10156. /// 12 = "The exchange was well done."
  10157. /// 13 = "The item is already sold and out of stock."
  10158. /// 14 = "There is not enough goods to exchange."
  10159. void clif_npc_buy_result( map_session_data* sd, e_purchase_result result ){
  10160. struct PACKET_ZC_PC_PURCHASE_RESULT p = {};
  10161. p.packetType = HEADER_ZC_PC_PURCHASE_RESULT;
  10162. p.result = (uint8)result;
  10163. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  10164. }
  10165. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10166. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10167. void clif_parse_NpcBuyListSend( int fd, map_session_data* sd ){
  10168. const struct PACKET_CZ_PC_PURCHASE_ITEMLIST *p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST *)RFIFOP( fd, 0 );
  10169. uint16 n = ( p->packetLength - sizeof(struct PACKET_CZ_PC_PURCHASE_ITEMLIST) ) / sizeof( struct PACKET_CZ_PC_PURCHASE_ITEMLIST_sub );
  10170. e_purchase_result result;
  10171. if( sd->state.trading || !sd->npc_shopid )
  10172. result = e_purchase_result::PURCHASE_FAIL_MONEY;
  10173. else{
  10174. std::vector<s_npc_buy_list> items = {};
  10175. items.reserve( n );
  10176. for( uint16 i = 0; i < n; i++ ){
  10177. s_npc_buy_list item = {};
  10178. item.nameid = p->items[i].itemId;
  10179. item.qty = p->items[i].amount;
  10180. items.push_back( item );
  10181. }
  10182. result = npc_buylist( sd, items );
  10183. }
  10184. sd->npc_shopid = 0; //Clear shop data.
  10185. clif_npc_buy_result(sd, result);
  10186. }
  10187. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10188. /// 00cb <result>.B
  10189. /// result:
  10190. /// 0 = "The deal has successfully completed."
  10191. /// 1 = "The deal has failed."
  10192. void clif_npc_sell_result(map_session_data* sd, unsigned char result)
  10193. {
  10194. int fd = sd->fd;
  10195. WFIFOHEAD(fd,packet_len(0xcb));
  10196. WFIFOW(fd,0) = 0xcb;
  10197. WFIFOB(fd,2) = result;
  10198. WFIFOSET(fd,packet_len(0xcb));
  10199. }
  10200. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10201. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10202. void clif_parse_NpcSellListSend(int fd,map_session_data *sd)
  10203. {
  10204. int fail=0,n;
  10205. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10206. PACKET_CZ_PC_SELL_ITEMLIST* p = reinterpret_cast<PACKET_CZ_PC_SELL_ITEMLIST*>(RFIFOP(fd, 0));
  10207. n = (p->packetLength - 4) / sizeof(PACKET_CZ_PC_SELL_ITEMLIST_sub); // (pktlen-(cmd+len))/listsize
  10208. if (sd->state.trading || !sd->npc_shopid)
  10209. fail = 1;
  10210. else
  10211. fail = npc_selllist(sd, n, p->sellList);
  10212. sd->npc_shopid = 0; //Clear shop data.
  10213. clif_npc_sell_result(sd, fail);
  10214. }
  10215. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10216. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10217. /// type:
  10218. /// 0 = private
  10219. /// 1 = public
  10220. void clif_parse_CreateChatRoom(int fd, map_session_data* sd)
  10221. {
  10222. if( sd == nullptr ){
  10223. return;
  10224. }
  10225. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10226. int len = RFIFOW(fd,info->pos[0])-15;
  10227. int limit = RFIFOW(fd,info->pos[1]);
  10228. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10229. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10230. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10231. char s_password[CHATROOM_PASS_SIZE];
  10232. char s_title[CHATROOM_TITLE_SIZE];
  10233. if (sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM)
  10234. return;
  10235. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10236. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 3 );
  10237. return;
  10238. }
  10239. if( npc_isnear(&sd->bl) ) {
  10240. // uncomment to send msg_txt.
  10241. //char output[150];
  10242. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10243. //clif_displaymessage(sd->fd, output);
  10244. clif_skill_fail( *sd, 1, USESKILL_FAIL_THERE_ARE_NPC_AROUND );
  10245. return;
  10246. }
  10247. if( len <= 0 )
  10248. return; // invalid input
  10249. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10250. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10251. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10252. }
  10253. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10254. /// 00d9 <chat ID>.L <passwd>.8B
  10255. void clif_parse_ChatAddMember(int fd, map_session_data* sd){
  10256. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10257. int chatid = RFIFOL(fd,info->pos[0]);
  10258. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10259. chat_joinchat(sd,chatid,password);
  10260. }
  10261. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10262. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10263. /// type:
  10264. /// 0 = private
  10265. /// 1 = public
  10266. void clif_parse_ChatRoomStatusChange(int fd, map_session_data* sd){
  10267. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10268. int len = RFIFOW(fd,info->pos[0])-15;
  10269. int limit = RFIFOW(fd,info->pos[1]);
  10270. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10271. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10272. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10273. char s_password[CHATROOM_PASS_SIZE];
  10274. char s_title[CHATROOM_TITLE_SIZE];
  10275. if( len <= 0 )
  10276. return; // invalid input
  10277. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10278. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10279. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10280. }
  10281. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10282. /// 00e0 <role>.L <nick>.24B
  10283. /// role:
  10284. /// 0 = owner
  10285. /// 1 = normal
  10286. void clif_parse_ChangeChatOwner(int fd, map_session_data* sd)
  10287. {
  10288. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10289. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10290. }
  10291. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10292. /// 00e2 <name>.24B
  10293. void clif_parse_KickFromChat(int fd,map_session_data *sd)
  10294. {
  10295. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10296. }
  10297. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10298. /// 00e3
  10299. void clif_parse_ChatLeave(int fd, map_session_data* sd)
  10300. {
  10301. chat_leavechat(sd,0);
  10302. }
  10303. //Handles notifying asker and rejecter of what has just ocurred.
  10304. //Type is used to determine the correct msg_txt to use:
  10305. //0:
  10306. static void clif_noask_sub(map_session_data *sd, map_session_data *tsd, int type)
  10307. {
  10308. const char* msg;
  10309. char output[256];
  10310. // Your request has been rejected by autoreject option.
  10311. msg = msg_txt(sd,392);
  10312. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10313. //Notice that a request was rejected.
  10314. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10315. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10316. }
  10317. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10318. /// 00e4 <account id>.L
  10319. void clif_parse_TradeRequest(int fd,map_session_data *sd)
  10320. {
  10321. map_session_data *t_sd;
  10322. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10323. if(!sd->chatID && pc_cant_act(sd))
  10324. return; //You can trade while in a chatroom.
  10325. if(t_sd){
  10326. // @noask [LuzZza]
  10327. if(t_sd->state.noask) {
  10328. clif_noask_sub(sd, t_sd, 0);
  10329. return;
  10330. }
  10331. if (t_sd->state.mail_writing) {
  10332. int old = sd->trade_partner;
  10333. // Fake trading
  10334. sd->trade_partner = t_sd->status.account_id;
  10335. clif_tradestart(sd, 5);
  10336. // Restore old state
  10337. sd->trade_partner = old;
  10338. return;
  10339. }
  10340. }
  10341. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10342. clif_skill_fail( *sd, 1 );
  10343. return;
  10344. }
  10345. trade_traderequest(sd,t_sd);
  10346. }
  10347. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10348. /// 00e6 <result>.B
  10349. /// result:
  10350. /// 3 = accepted
  10351. /// 4 = rejected
  10352. void clif_parse_TradeAck(int fd,map_session_data *sd)
  10353. {
  10354. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10355. }
  10356. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10357. /// 00e8 <index>.W <amount>.L
  10358. void clif_parse_TradeAddItem(int fd,map_session_data *sd)
  10359. {
  10360. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10361. short index = RFIFOW(fd,info->pos[0]);
  10362. int amount = RFIFOL(fd,info->pos[1]);
  10363. if( index == 0 )
  10364. trade_tradeaddzeny(sd, amount);
  10365. else
  10366. trade_tradeadditem(sd, server_index(index), (short)amount);
  10367. }
  10368. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10369. /// 00eb
  10370. void clif_parse_TradeOk(int fd,map_session_data *sd)
  10371. {
  10372. trade_tradeok(sd);
  10373. }
  10374. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10375. /// 00ed
  10376. void clif_parse_TradeCancel(int fd,map_session_data *sd)
  10377. {
  10378. trade_tradecancel(sd);
  10379. }
  10380. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10381. /// 00ef
  10382. void clif_parse_TradeCommit(int fd,map_session_data *sd)
  10383. {
  10384. trade_tradecommit(sd);
  10385. }
  10386. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10387. /// 0118
  10388. void clif_parse_StopAttack(int fd,map_session_data *sd)
  10389. {
  10390. pc_stop_attack(sd);
  10391. if (sd) sd->ud.state.attack_continue = 0;
  10392. }
  10393. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10394. /// 0126 <index>.W <amount>.L
  10395. void clif_parse_PutItemToCart( int fd, map_session_data *sd ){
  10396. if (pc_istrading(sd) || !pc_iscarton(sd) || pc_cant_act2(sd))
  10397. return;
  10398. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10399. return;
  10400. struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART* p = (struct PACKET_CZ_MOVE_ITEM_FROM_BODY_TO_CART*)RFIFOP( fd, 0 );
  10401. pc_putitemtocart( sd, server_index( p->index ), p->count);
  10402. }
  10403. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10404. /// 0127 <index>.W <amount>.L
  10405. void clif_parse_GetItemFromCart(int fd,map_session_data *sd)
  10406. {
  10407. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10408. if (!pc_iscarton(sd) || pc_cant_act2(sd))
  10409. return;
  10410. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  10411. return;
  10412. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10413. }
  10414. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10415. /// 012a
  10416. void clif_parse_RemoveOption(int fd,map_session_data *sd)
  10417. {
  10418. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10419. #ifdef NEW_CARTS
  10420. && sd->sc.getSCE(SC_PUSH_CART) )
  10421. pc_setcart(sd,0);
  10422. #else
  10423. )
  10424. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10425. #endif
  10426. else // priority to remove this option before we can clear cart
  10427. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10428. }
  10429. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10430. /// 097f <Length>.W <identity>.L <type>.B
  10431. void clif_SelectCart(map_session_data *sd) {
  10432. #if PACKETVER >= 20150826
  10433. int i = 0, carts = 3;
  10434. int fd = sd->fd;
  10435. WFIFOHEAD(fd,8 + carts);
  10436. WFIFOW(fd,0) = 0x97f;
  10437. WFIFOW(fd,2) = 8 + carts;
  10438. WFIFOL(fd,4) = sd->status.account_id;
  10439. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10440. for( i = 0; i < carts; i++ ) {
  10441. WFIFOB(fd,8 + i) = 10 + i;
  10442. }
  10443. WFIFOSET(fd,8 + carts);
  10444. #endif
  10445. }
  10446. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10447. /// 0980 <identity>.L <type>.B
  10448. void clif_parse_SelectCart(int fd,map_session_data *sd) {
  10449. #if PACKETVER >= 20150826
  10450. int type;
  10451. // Check identity
  10452. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10453. return;
  10454. type = (int)RFIFOB(fd,6);
  10455. // Check type
  10456. if( type < 10 || type > 12 )
  10457. return;
  10458. pc_setcart(sd, type);
  10459. #endif
  10460. }
  10461. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10462. /// 01af <num>.W
  10463. void clif_parse_ChangeCart(int fd,map_session_data *sd)
  10464. {// TODO: State tracking?
  10465. int type;
  10466. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10467. return;
  10468. #ifdef RENEWAL
  10469. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10470. clif_msg(sd, MSI_BUSY);
  10471. return;
  10472. }
  10473. #endif
  10474. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10475. if(
  10476. #ifdef NEW_CARTS
  10477. #if PACKETVER >= 20191106
  10478. (type == 13 && sd->status.base_level > 100) ||
  10479. #endif
  10480. (type == 9 && sd->status.base_level > 130) ||
  10481. (type == 8 && sd->status.base_level > 120) ||
  10482. (type == 7 && sd->status.base_level > 110) ||
  10483. (type == 6 && sd->status.base_level > 100) ||
  10484. #endif
  10485. (type == 5 && sd->status.base_level > 90) ||
  10486. (type == 4 && sd->status.base_level > 80) ||
  10487. (type == 3 && sd->status.base_level > 65) ||
  10488. (type == 2 && sd->status.base_level > 40) ||
  10489. (type == 1))
  10490. pc_setcart(sd, type);
  10491. }
  10492. /// Request to increase status (CZ_STATUS_CHANGE).
  10493. /// 00bb <status id>.W <amount>.B
  10494. /// status id:
  10495. /// SP_STR ~ SP_LUK
  10496. /// amount:
  10497. /// Old clients always send 1 for this, even when using /str+ and the like.
  10498. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10499. void clif_parse_StatusUp(int fd,map_session_data *sd)
  10500. {
  10501. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10502. if( increase_amount < 0 ) {
  10503. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10504. fd, increase_amount);
  10505. }
  10506. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10507. }
  10508. /// Request to increase trait status.
  10509. /// 0b24 <status id>.W <amount>.W
  10510. /// status id:
  10511. /// SP_POW ~ SP_CON
  10512. /// amount:
  10513. /// The amount to increase the trait status
  10514. void clif_parse_traitstatus_up( int fd, map_session_data *sd ){
  10515. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10516. struct PACKET_CZ_ADVANCED_STATUS_CHANGE* p = (struct PACKET_CZ_ADVANCED_STATUS_CHANGE*)RFIFOP( fd, 0 );
  10517. if( p->amount < 0 ){
  10518. 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 );
  10519. return;
  10520. }
  10521. pc_traitstatusup( sd, p->type, p->amount );
  10522. #endif
  10523. }
  10524. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10525. /// 0112 <skill id>.W
  10526. void clif_parse_SkillUp(int fd,map_session_data *sd)
  10527. {
  10528. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10529. }
  10530. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10531. {
  10532. int lv;
  10533. if( !hd )
  10534. return;
  10535. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10536. clif_emotion(&hd->bl, ET_THINK);
  10537. return;
  10538. }
  10539. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10540. target_id = hd->bl.id;
  10541. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10542. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10543. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10544. clif_emotion(&hd->bl, ET_THINK);
  10545. if (hd->master)
  10546. clif_skill_fail( *hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10547. return;
  10548. }
  10549. lv = hom_checkskill(hd, skill_id);
  10550. if( skill_lv > lv )
  10551. skill_lv = lv;
  10552. if( skill_lv )
  10553. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10554. }
  10555. static void clif_parse_UseSkillToPos_homun(struct homun_data *hd, map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10556. {
  10557. int lv;
  10558. if( !hd )
  10559. return;
  10560. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10561. clif_emotion(&hd->bl, ET_THINK);
  10562. return;
  10563. }
  10564. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10565. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10566. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10567. clif_emotion(&hd->bl, ET_THINK);
  10568. if (hd->master)
  10569. clif_skill_fail( *hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10570. return;
  10571. }
  10572. #ifdef RENEWAL
  10573. if (hd->sc.getSCE(SC_BASILICA_CELL))
  10574. #else
  10575. if (hd->sc.getSCE(SC_BASILICA))
  10576. #endif
  10577. return;
  10578. lv = hom_checkskill(hd, skill_id);
  10579. if( skill_lv > lv )
  10580. skill_lv = lv;
  10581. if( skill_lv )
  10582. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10583. }
  10584. static void clif_parse_UseSkillToId_mercenary(s_mercenary_data *md, map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10585. {
  10586. int lv;
  10587. if( !md )
  10588. return;
  10589. if( skill_isNotOk_mercenary(skill_id, *md) )
  10590. return;
  10591. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10592. target_id = md->bl.id;
  10593. if( md->ud.skilltimer != INVALID_TIMER )
  10594. {
  10595. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10596. }
  10597. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10598. return;
  10599. lv = mercenary_checkskill(md, skill_id);
  10600. if( skill_lv > lv )
  10601. skill_lv = lv;
  10602. if( skill_lv )
  10603. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10604. }
  10605. static void clif_parse_UseSkillToPos_mercenary(s_mercenary_data *md, map_session_data *sd, t_tick tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10606. {
  10607. int lv;
  10608. if( !md )
  10609. return;
  10610. if( skill_isNotOk_mercenary(skill_id, *md) )
  10611. return;
  10612. if( md->ud.skilltimer != INVALID_TIMER )
  10613. return;
  10614. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10615. {
  10616. if (md->master)
  10617. clif_skill_fail( *md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10618. return;
  10619. }
  10620. #ifdef RENEWAL
  10621. if (md->sc.getSCE(SC_BASILICA_CELL))
  10622. #else
  10623. if (md->sc.getSCE(SC_BASILICA))
  10624. #endif
  10625. return;
  10626. lv = mercenary_checkskill(md, skill_id);
  10627. if( skill_lv > lv )
  10628. skill_lv = lv;
  10629. if( skill_lv )
  10630. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10631. }
  10632. void clif_parse_skill_toid( map_session_data* sd, uint16 skill_id, uint16 skill_lv, int target_id ){
  10633. if( sd == nullptr ){
  10634. return;
  10635. }
  10636. t_tick tick = gettick();
  10637. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10638. int inf = skill_get_inf(skill_id);
  10639. if (inf&INF_GROUND_SKILL || !inf)
  10640. return; //Using a ground/passive skill on a target? WRONG.
  10641. if (sd->state.block_action & PCBLOCK_SKILL) {
  10642. clif_msg(sd, MSI_BUSY);
  10643. return;
  10644. }
  10645. if( SKILL_CHK_HOMUN(skill_id) ) {
  10646. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10647. return;
  10648. }
  10649. if( SKILL_CHK_MERC(skill_id) ) {
  10650. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10651. return;
  10652. }
  10653. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10654. // This is done here, because homunculi and mercenaries can be triggered by AI and not by the player itself
  10655. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10656. sd->idletime = last_tick;
  10657. if (battle_config.hom_idle_no_share && sd->hd && battle_config.idletime_hom_option&IDLE_USESKILLTOID)
  10658. sd->idletime_hom = last_tick;
  10659. if (battle_config.mer_idle_no_share && sd->md && battle_config.idletime_mer_option&IDLE_USESKILLTOID)
  10660. sd->idletime_mer = last_tick;
  10661. if( sd->npc_id ){
  10662. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10663. #ifdef RENEWAL
  10664. clif_msg( sd, MSI_BUSY);
  10665. #endif
  10666. return;
  10667. }
  10668. }
  10669. if ((pc_cant_act2(sd) || sd->chatID) &&
  10670. skill_id != RK_REFRESH &&
  10671. !( ( skill_id == SR_GENTLETOUCH_CURE || skill_id == SU_GROOMING ) && (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10672. !(sd->state.storage_flag && (inf&INF_SELF_SKILL))) //SELF skills can be used with the storage open, issue: 8027
  10673. return;
  10674. if( pc_issit(sd) )
  10675. return;
  10676. if( skill_isNotOk(skill_id, *sd) )
  10677. return;
  10678. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10679. target_id = sd->bl.id; // never trust the client
  10680. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10681. target_id = sd->bl.id;
  10682. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10683. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10684. return;
  10685. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10686. if( sd->skillitem != skill_id ) {
  10687. clif_skill_fail( *sd, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10688. return;
  10689. }
  10690. }
  10691. if( sd->sc.option&OPTION_COSTUME )
  10692. return;
  10693. #ifndef RENEWAL
  10694. if( sd->sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd->sc.getSCE(SC_BASILICA)->val4 != sd->bl.id) )
  10695. return; // On basilica only caster can use Basilica again to stop it.
  10696. #endif
  10697. if( sd->menuskill_id ) {
  10698. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10699. clif_menuskill_clear(sd); //Cancel pet capture.
  10700. }else if( sd->menuskill_id == SG_FEEL ){
  10701. clif_menuskill_clear( sd ); // Cancel selection
  10702. }else if( sd->menuskill_id != SA_AUTOSPELL )
  10703. return; //Can't use skills while a menu is open.
  10704. }
  10705. if( sd->skillitem == skill_id ) {
  10706. if( skill_lv != sd->skillitemlv )
  10707. skill_lv = sd->skillitemlv;
  10708. if( !(inf&INF_SELF_SKILL) )
  10709. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10710. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10711. return;
  10712. }
  10713. sd->skillitem = sd->skillitemlv = 0;
  10714. if( SKILL_CHK_GUILD(skill_id) ) {
  10715. if (sd->guild && sd->state.gmaster_flag || skill_id == GD_CHARGESHOUT_BEATING)
  10716. skill_lv = guild_checkskill(sd->guild->guild, skill_id);
  10717. else
  10718. skill_lv = 0;
  10719. } else {
  10720. if( skill_id != ALL_EQSWITCH ){
  10721. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10722. }
  10723. }
  10724. pc_delinvincibletimer(sd);
  10725. if( skill_lv )
  10726. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10727. }
  10728. /// Request to use a targeted skill.
  10729. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10730. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10731. /// There are various variants of this packet, some of them have padding between fields.
  10732. void clif_parse_UseSkillToId( int fd, map_session_data *sd ){
  10733. struct s_packet_db* info = &packet_db[RFIFOW(fd, 0)];
  10734. clif_parse_skill_toid( sd, RFIFOW(fd, info->pos[1]), RFIFOW(fd, info->pos[0]), RFIFOL(fd, info->pos[2]) );
  10735. }
  10736. /*==========================================
  10737. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10738. *------------------------------------------*/
  10739. static void clif_parse_UseSkillToPosSub( int fd, map_session_data& sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo ){
  10740. t_tick tick = gettick();
  10741. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10742. return; //Using a target skill on the ground? WRONG.
  10743. if (sd.state.block_action & PCBLOCK_SKILL) {
  10744. clif_msg(&sd, MSI_BUSY);
  10745. return;
  10746. }
  10747. if( SKILL_CHK_HOMUN(skill_id) ) {
  10748. clif_parse_UseSkillToPos_homun(sd.hd, &sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10749. return;
  10750. }
  10751. if( SKILL_CHK_MERC(skill_id) ) {
  10752. clif_parse_UseSkillToPos_mercenary(sd.md, &sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10753. return;
  10754. }
  10755. if( pc_hasprogress( &sd, WIP_DISABLE_SKILLITEM ) ){
  10756. #ifdef RENEWAL
  10757. clif_msg( &sd, MSI_BUSY);
  10758. #endif
  10759. return;
  10760. }
  10761. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10762. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10763. sd.idletime = last_tick;
  10764. if (battle_config.hom_idle_no_share && sd.hd && battle_config.idletime_hom_option&IDLE_USESKILLTOPOS)
  10765. sd.idletime_hom = last_tick;
  10766. if (battle_config.mer_idle_no_share && sd.md && battle_config.idletime_mer_option&IDLE_USESKILLTOPOS)
  10767. sd.idletime_mer = last_tick;
  10768. if( skill_isNotOk(skill_id, sd) )
  10769. return;
  10770. if( skillmoreinfo != -1 ) {
  10771. if( pc_issit(&sd) ) {
  10772. clif_skill_fail( sd, skill_id );
  10773. return;
  10774. }
  10775. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10776. safestrncpy(sd.message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10777. }
  10778. if( sd.ud.skilltimer != INVALID_TIMER )
  10779. return;
  10780. if( DIFF_TICK(tick, sd.ud.canact_tick) < 0 ) {
  10781. if( sd.skillitem != skill_id ) {
  10782. clif_skill_fail( sd, skill_id, USESKILL_FAIL_SKILLINTERVAL );
  10783. return;
  10784. }
  10785. }
  10786. if( sd.sc.option&OPTION_COSTUME )
  10787. return;
  10788. #ifndef RENEWAL
  10789. if( sd.sc.getSCE(SC_BASILICA) && (skill_id != HP_BASILICA || sd.sc.getSCE(SC_BASILICA)->val4 != sd.bl.id) )
  10790. return; // On basilica only caster can use Basilica again to stop it.
  10791. #endif
  10792. if( sd.menuskill_id ) {
  10793. if( sd.menuskill_id == SA_TAMINGMONSTER ) {
  10794. clif_menuskill_clear(&sd); //Cancel pet capture.
  10795. }else if( sd.menuskill_id == SG_FEEL ){
  10796. clif_menuskill_clear( &sd ); // Cancel selection
  10797. } else if( sd.menuskill_id != SA_AUTOSPELL )
  10798. return; //Can't use skills while a menu is open.
  10799. }
  10800. pc_delinvincibletimer(&sd);
  10801. if( sd.skillitem == skill_id ) {
  10802. if( skill_lv != sd.skillitemlv )
  10803. skill_lv = sd.skillitemlv;
  10804. unit_skilluse_pos(&sd.bl, x, y, skill_id, skill_lv);
  10805. } else {
  10806. int lv;
  10807. sd.skillitem = sd.skillitemlv = 0;
  10808. if( (lv = pc_checkskill(&sd, skill_id)) > 0 ) {
  10809. if( skill_lv > lv )
  10810. skill_lv = lv;
  10811. unit_skilluse_pos(&sd.bl, x, y, skill_id,skill_lv);
  10812. }
  10813. }
  10814. }
  10815. /// Request to use a ground skill.
  10816. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10817. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10818. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10819. /// There are various variants of this packet, some of them have padding between fields.
  10820. void clif_parse_UseSkillToPos(int fd, map_session_data *sd)
  10821. {
  10822. if( sd == nullptr ){
  10823. return;
  10824. }
  10825. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10826. if (pc_cant_act(sd))
  10827. return;
  10828. if (pc_issit(sd))
  10829. return;
  10830. clif_parse_UseSkillToPosSub(fd, *sd,
  10831. RFIFOW(fd,info->pos[0]), //skill lv
  10832. RFIFOW(fd,info->pos[1]), //skill num
  10833. RFIFOW(fd,info->pos[2]), //pos x
  10834. RFIFOW(fd,info->pos[3]), //pos y
  10835. // TODO: find out what this is intended to do
  10836. //RFIFOB(fd, info->pos[4])
  10837. -1 //Skill more info.
  10838. );
  10839. }
  10840. /// Request to use a ground skill with text.
  10841. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10842. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10843. /// There are various variants of this packet, some of them have padding between fields.
  10844. void clif_parse_UseSkillToPosMoreInfo(int fd, map_session_data *sd)
  10845. {
  10846. if( sd == nullptr ){
  10847. return;
  10848. }
  10849. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10850. if (pc_cant_act(sd))
  10851. return;
  10852. if (pc_issit(sd))
  10853. return;
  10854. clif_parse_UseSkillToPosSub(fd, *sd,
  10855. RFIFOW(fd,info->pos[0]), //Skill lv
  10856. RFIFOW(fd,info->pos[1]), //Skill num
  10857. RFIFOW(fd,info->pos[2]), //pos x
  10858. RFIFOW(fd,info->pos[3]), //pos y
  10859. info->pos[4] //skill more info
  10860. );
  10861. }
  10862. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10863. /// 011b <skill id>.W <map name>.16B
  10864. void clif_parse_UseSkillMap(int fd, map_session_data* sd)
  10865. {
  10866. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10867. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10868. char map_name[MAP_NAME_LENGTH];
  10869. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10870. sd->state.workinprogress = WIP_DISABLE_NONE;
  10871. if(skill_id != sd->menuskill_id)
  10872. return;
  10873. //It is possible to use teleport with the storage window open bugreport:8027
  10874. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10875. clif_menuskill_clear(sd);
  10876. return;
  10877. }
  10878. pc_delinvincibletimer(sd);
  10879. skill_castend_map(sd,skill_id,map_name);
  10880. }
  10881. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10882. /// 011d
  10883. void clif_parse_RequestMemo(int fd,map_session_data *sd)
  10884. {
  10885. if (!pc_isdead(sd))
  10886. pc_memo(sd,-1);
  10887. }
  10888. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10889. /// 018e <name id>.W { <material id>.W }*3
  10890. void clif_parse_ProduceMix(int fd,map_session_data *sd){
  10891. if( sd == nullptr ){
  10892. return;
  10893. }
  10894. const struct PACKET_CZ_REQMAKINGITEM *p = (struct PACKET_CZ_REQMAKINGITEM*)RFIFOP( fd, 0 );
  10895. switch( sd->menuskill_id ) {
  10896. case -1:
  10897. case AM_PHARMACY:
  10898. case RK_RUNEMASTERY:
  10899. case GC_RESEARCHNEWPOISON:
  10900. break;
  10901. default:
  10902. return;
  10903. }
  10904. if (pc_istrading(sd)) {
  10905. //Make it fail to avoid shop exploits where you sell something different than you see.
  10906. clif_skill_fail( *sd, sd->ud.skill_id );
  10907. clif_menuskill_clear(sd);
  10908. return;
  10909. }
  10910. int produce_idx;
  10911. if( (produce_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, 1)) )
  10912. skill_produce_mix(sd,0,p->itemId,p->material[0],p->material[1],p->material[2],1,produce_idx-1);
  10913. clif_menuskill_clear(sd);
  10914. }
  10915. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10916. /// 025b <mk type>.W <name id>.W
  10917. /// mk type:
  10918. /// 1 = cooking
  10919. /// 2 = arrow
  10920. /// 3 = elemental
  10921. /// 4 = GN_MIX_COOKING
  10922. /// 5 = GN_MAKEBOMB
  10923. /// 6 = GN_S_PHARMACY
  10924. /// 7 = MT_M_MACHINE - Unconfirmed
  10925. /// 8 = BO_BIONIC_PHARMACY - Unconfirmed
  10926. void clif_parse_Cooking(int fd,map_session_data *sd) {
  10927. if( sd == nullptr ){
  10928. return;
  10929. }
  10930. const struct PACKET_CZ_REQ_MAKINGITEM *p = (struct PACKET_CZ_REQ_MAKINGITEM *)RFIFOP( fd, 0 );
  10931. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10932. short food_idx = -1;
  10933. if( p->type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  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. if( (food_idx = skill_can_produce_mix(sd,p->itemId,sd->menuskill_val, amount)) )
  10942. skill_produce_mix(sd,(p->type>1?sd->menuskill_id:0),p->itemId,0,0,0,amount,food_idx-1);
  10943. clif_menuskill_clear(sd);
  10944. }
  10945. /// Answer to repair weapon item selection dialog
  10946. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10947. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10948. void clif_parse_RepairItem( int fd, map_session_data *sd ){
  10949. if( sd == nullptr ){
  10950. return;
  10951. }
  10952. // Hercules has wrong date -> use correct one here
  10953. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  10954. const struct PACKET_CZ_REQ_ITEMREPAIR2 *p = (struct PACKET_CZ_REQ_ITEMREPAIR2 *)RFIFOP( fd, 0 );
  10955. #else
  10956. const struct PACKET_CZ_REQ_ITEMREPAIR1 *p = (struct PACKET_CZ_REQ_ITEMREPAIR1 *)RFIFOP( fd, 0 );
  10957. #endif
  10958. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10959. return;
  10960. if (pc_istrading(sd)) {
  10961. //Make it fail to avoid shop exploits where you sell something different than you see.
  10962. clif_skill_fail( *sd, sd->ud.skill_id );
  10963. clif_menuskill_clear(sd);
  10964. return;
  10965. }
  10966. skill_repairweapon( *sd, p->item.index );
  10967. clif_menuskill_clear(sd);
  10968. }
  10969. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10970. /// 0222 <index>.L
  10971. void clif_parse_WeaponRefine( int fd, map_session_data *sd ){
  10972. if( sd == nullptr ){
  10973. return;
  10974. }
  10975. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10976. return;
  10977. if (pc_istrading(sd)) {
  10978. //Make it fail to avoid shop exploits where you sell something different than you see.
  10979. clif_skill_fail( *sd, sd->ud.skill_id );
  10980. clif_menuskill_clear(sd);
  10981. return;
  10982. }
  10983. skill_weaponrefine( *sd, server_index( RFIFOL( fd, 2 ) ) );
  10984. clif_menuskill_clear(sd);
  10985. }
  10986. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10987. /// 00b8 <npc id>.L <choice>.B
  10988. /// choice:
  10989. /// 1~254 = menu item
  10990. /// 255 = cancel
  10991. /// NOTE: If there were more than 254 items in the list, choice
  10992. /// overflows to choice%256.
  10993. void clif_parse_NpcSelectMenu(int fd,map_session_data *sd){
  10994. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10995. int npc_id = RFIFOL(fd,info->pos[0]);
  10996. uint8 select = RFIFOB(fd,info->pos[1]);
  10997. #ifdef SECURE_NPCTIMEOUT
  10998. if( sd->npc_idle_timer == INVALID_TIMER && !sd->state.ignoretimeout )
  10999. return;
  11000. #endif
  11001. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  11002. TBL_NPC* nd = map_id2nd(npc_id);
  11003. 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);
  11004. clif_GM_kick(nullptr,sd);
  11005. return;
  11006. }
  11007. sd->npc_menu = select;
  11008. if( battle_config.idletime_option&IDLE_NPC_MENU ){
  11009. sd->idletime = last_tick;
  11010. }
  11011. npc_scriptcont(sd,npc_id, false);
  11012. }
  11013. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  11014. /// 00b9 <npc id>.L
  11015. void clif_parse_NpcNextClicked(int fd,map_session_data *sd)
  11016. {
  11017. if( battle_config.idletime_option&IDLE_NPC_NEXT ){
  11018. sd->idletime = last_tick;
  11019. }
  11020. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  11021. }
  11022. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  11023. /// 0143 <npc id>.L <value>.L
  11024. void clif_parse_NpcAmountInput(int fd,map_session_data *sd){
  11025. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11026. int npcid = RFIFOL(fd,info->pos[0]);
  11027. int amount = (int)RFIFOL(fd,info->pos[1]);
  11028. sd->npc_amount = amount;
  11029. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11030. sd->idletime = last_tick;
  11031. }
  11032. npc_scriptcont(sd, npcid, false);
  11033. }
  11034. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  11035. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  11036. void clif_parse_NpcStringInput(int fd, map_session_data* sd){
  11037. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11038. int message_len = RFIFOW(fd,info->pos[0])-8;
  11039. int npcid = RFIFOL(fd,info->pos[1]);
  11040. const char* message = RFIFOCP(fd,info->pos[2]);
  11041. if( message_len <= 0 )
  11042. return; // invalid input
  11043. #if PACKETVER >= 20151001
  11044. message_len++;
  11045. #endif
  11046. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  11047. if( battle_config.idletime_option&IDLE_NPC_INPUT ){
  11048. sd->idletime = last_tick;
  11049. }
  11050. npc_scriptcont(sd, npcid, false);
  11051. }
  11052. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  11053. /// 0146 <npc id>.L
  11054. void clif_parse_NpcCloseClicked(int fd,map_session_data *sd)
  11055. {
  11056. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  11057. return;
  11058. if( battle_config.idletime_option&IDLE_NPC_CLOSE ){
  11059. sd->idletime = last_tick;
  11060. }
  11061. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  11062. }
  11063. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  11064. /// 0178 <index>.W
  11065. /// index:
  11066. /// -1 = cancel
  11067. void clif_parse_ItemIdentify(int fd,map_session_data *sd) {
  11068. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  11069. if (sd->menuskill_id != MC_IDENTIFY)
  11070. return;
  11071. // Ignore the request
  11072. // - Invalid item index
  11073. // - Invalid item ID or item doesn't exist
  11074. // - Item is already identified
  11075. if (idx < 0 || idx >= MAX_INVENTORY ||
  11076. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == nullptr ||
  11077. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  11078. sd->state.workinprogress = WIP_DISABLE_NONE;
  11079. clif_menuskill_clear(sd);
  11080. return;
  11081. }
  11082. skill_identify(sd, idx);
  11083. clif_menuskill_clear(sd);
  11084. }
  11085. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  11086. /// 01ae <name id>.W
  11087. void clif_parse_SelectArrow(int fd,map_session_data *sd) {
  11088. if( sd == nullptr ){
  11089. return;
  11090. }
  11091. if (pc_istrading(sd)) {
  11092. //Make it fail to avoid shop exploits where you sell something different than you see.
  11093. clif_skill_fail( *sd, sd->ud.skill_id );
  11094. clif_menuskill_clear(sd);
  11095. return;
  11096. }
  11097. struct PACKET_CZ_REQ_MAKINGARROW* p = (struct PACKET_CZ_REQ_MAKINGARROW*)RFIFOP( fd, 0 );
  11098. switch (sd->menuskill_id) {
  11099. case AC_MAKINGARROW:
  11100. skill_arrow_create(sd,p->itemId);
  11101. break;
  11102. case SA_CREATECON:
  11103. skill_produce_mix(sd,SA_CREATECON,p->itemId,0,0,0,1,-1);
  11104. break;
  11105. case GC_POISONINGWEAPON:
  11106. skill_poisoningweapon(*sd,p->itemId);
  11107. break;
  11108. case NC_MAGICDECOY:
  11109. skill_magicdecoy(*sd,p->itemId);
  11110. break;
  11111. }
  11112. clif_menuskill_clear(sd);
  11113. }
  11114. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  11115. /// 01ce <skill id>.L
  11116. void clif_parse_AutoSpell(int fd,map_session_data *sd)
  11117. {
  11118. if (sd->menuskill_id != SA_AUTOSPELL)
  11119. return;
  11120. sd->state.workinprogress = WIP_DISABLE_NONE;
  11121. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11122. clif_menuskill_clear(sd);
  11123. }
  11124. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  11125. /// 017a <card index>.W
  11126. void clif_parse_UseCard(int fd,map_session_data *sd)
  11127. {
  11128. if (sd->state.trading != 0)
  11129. return;
  11130. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11131. }
  11132. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  11133. /// 017c <card index>.W <equip index>.W
  11134. void clif_parse_InsertCard(int fd,map_session_data *sd)
  11135. {
  11136. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11137. if (sd->state.trading != 0)
  11138. return;
  11139. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  11140. }
  11141. /// Request of character's name by char ID.
  11142. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  11143. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  11144. /// There are various variants of this packet, some of them have padding between fields.
  11145. void clif_parse_SolveCharName(int fd, map_session_data *sd)
  11146. {
  11147. int charid;
  11148. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11149. map_reqnickdb(sd, charid);
  11150. }
  11151. /// /resetskill /resetstate (CZ_RESET).
  11152. /// Request to reset stats or skills.
  11153. /// 0197 <type>.W
  11154. /// type:
  11155. /// 0 = state
  11156. /// 1 = skill
  11157. void clif_parse_ResetChar(int fd, map_session_data *sd) {
  11158. char cmd[15];
  11159. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  11160. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  11161. else
  11162. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  11163. is_atcommand(fd, sd, cmd, 1);
  11164. }
  11165. /// /lb /nlb (CZ_LOCALBROADCAST).
  11166. /// Request to broadcast a message on current map.
  11167. /// 019c <packet len>.W <text>.?B
  11168. void clif_parse_LocalBroadcast(int fd, map_session_data* sd)
  11169. {
  11170. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11171. char command[CHAT_SIZE_MAX+16];
  11172. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  11173. char* msg = RFIFOCP(fd,info->pos[1]);
  11174. // as the length varies depending on the command used, just block unreasonably long strings
  11175. mes_len_check(msg, len, CHAT_SIZE_MAX);
  11176. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  11177. is_atcommand(fd, sd, command, 1);
  11178. }
  11179. /// Request to move an item from inventory to storage.
  11180. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  11181. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  11182. /// There are various variants of this packet, some of them have padding between fields.
  11183. void clif_parse_MoveToKafra(int fd, map_session_data *sd)
  11184. {
  11185. int item_index, item_amount;
  11186. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11187. if (pc_istrading(sd))
  11188. return;
  11189. item_index = RFIFOW(fd,info->pos[0])-2;
  11190. item_amount = RFIFOL(fd,info->pos[1]);
  11191. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  11192. return;
  11193. if( sd->inventory.u.items_inventory[item_index].equipSwitch ){
  11194. clif_msg( sd, MSI_SWAP_EQUIPITEM_UNREGISTER_FIRST );
  11195. return;
  11196. }
  11197. if (sd->state.storage_flag == 1)
  11198. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  11199. else
  11200. if (sd->state.storage_flag == 2)
  11201. storage_guild_storageadd(sd, item_index, item_amount);
  11202. else if (sd->state.storage_flag == 3)
  11203. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  11204. }
  11205. /// Request to move an item from storage to inventory.
  11206. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  11207. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  11208. /// There are various variants of this packet, some of them have padding between fields.
  11209. void clif_parse_MoveFromKafra(int fd,map_session_data *sd)
  11210. {
  11211. int item_index, item_amount;
  11212. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11213. item_index = RFIFOW(fd,info->pos[0])-1;
  11214. item_amount = RFIFOL(fd,info->pos[1]);
  11215. if (sd->state.storage_flag == 1)
  11216. storage_storageget(sd, &sd->storage, item_index, item_amount);
  11217. else if(sd->state.storage_flag == 2)
  11218. storage_guild_storageget(sd, item_index, item_amount);
  11219. else if(sd->state.storage_flag == 3)
  11220. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  11221. }
  11222. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  11223. /// 0129 <index>.W <amount>.L
  11224. void clif_parse_MoveToKafraFromCart(int fd, map_session_data *sd){
  11225. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11226. int idx = RFIFOW(fd,info->pos[0]) - 2;
  11227. int amount = RFIFOL(fd,info->pos[1]);
  11228. if( sd->state.vending )
  11229. return;
  11230. if (!pc_iscarton(sd))
  11231. return;
  11232. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11233. return;
  11234. if (idx < 0 || idx >= MAX_INVENTORY || amount < 1)
  11235. return;
  11236. if( sd->inventory.u.items_inventory[idx].equipSwitch ){
  11237. clif_msg( sd, MSI_SWAP_EQUIPITEM_UNREGISTER_FIRST );
  11238. return;
  11239. }
  11240. if (sd->state.storage_flag == 1)
  11241. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  11242. else if (sd->state.storage_flag == 2)
  11243. storage_guild_storageaddfromcart(sd, idx, amount);
  11244. else if (sd->state.storage_flag == 3)
  11245. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  11246. }
  11247. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  11248. /// 0128 <index>.W <amount>.L
  11249. void clif_parse_MoveFromKafraToCart(int fd, map_session_data *sd){
  11250. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11251. int idx = RFIFOW(fd,info->pos[0]) - 1;
  11252. int amount = RFIFOL(fd,info->pos[1]);
  11253. if( sd->state.vending )
  11254. return;
  11255. if (!pc_iscarton(sd))
  11256. return;
  11257. if (map_getmapflag(sd->bl.m, MF_NOUSECART))
  11258. return;
  11259. if (sd->state.storage_flag == 1)
  11260. storage_storagegettocart(sd, &sd->storage, idx, amount);
  11261. else
  11262. if (sd->state.storage_flag == 2)
  11263. storage_guild_storagegettocart(sd, idx, amount);
  11264. else if (sd->state.storage_flag == 3)
  11265. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  11266. }
  11267. /// Request to close storage (CZ_CLOSE_STORE).
  11268. /// 00f7
  11269. void clif_parse_CloseKafra(int fd, map_session_data *sd)
  11270. {
  11271. if( sd->state.storage_flag == 1 )
  11272. storage_storageclose(sd);
  11273. else
  11274. if( sd->state.storage_flag == 2 )
  11275. storage_guild_storageclose(sd);
  11276. else if( sd->state.storage_flag == 3 )
  11277. storage_premiumStorage_close(sd);
  11278. }
  11279. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11280. /// 023a <info>.W
  11281. /// info:
  11282. /// 0 = password has not been set yet
  11283. /// 1 = storage is password-protected
  11284. /// 8 = too many wrong passwords
  11285. /// ? = ignored
  11286. /// NOTE: This packet is only available on certain non-kRO clients.
  11287. void clif_storagepassword(map_session_data* sd, short info)
  11288. {
  11289. int fd = sd->fd;
  11290. WFIFOHEAD(fd,packet_len(0x23a));
  11291. WFIFOW(fd,0) = 0x23a;
  11292. WFIFOW(fd,2) = info;
  11293. WFIFOSET(fd,packet_len(0x23a));
  11294. }
  11295. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11296. /// 023b <type>.W <password>.16B <new password>.16B
  11297. /// type:
  11298. /// 2 = change password
  11299. /// 3 = check password
  11300. /// NOTE: This packet is only available on certain non-kRO clients.
  11301. void clif_parse_StoragePassword(int fd, map_session_data *sd){ //@TODO
  11302. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11303. // int type = RFIFOW(fd,info->pos[0]);
  11304. // char* password = RFIFOP(fd,info->pos[1]);
  11305. // char* new_password = RFIFOP(fd,info->pos[2]);
  11306. // storage_changepass(sd,password,new_password);
  11307. }
  11308. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11309. /// 023c <result>.W <error count>.W
  11310. /// result:
  11311. /// 4 = password change success
  11312. /// 5 = password change failure
  11313. /// 6 = password check success
  11314. /// 7 = password check failure
  11315. /// 8 = too many wrong passwords
  11316. /// ? = ignored
  11317. /// NOTE: This packet is only available on certain non-kRO clients.
  11318. void clif_storagepassword_result(map_session_data* sd, short result, short error_count)
  11319. {
  11320. int fd = sd->fd;
  11321. WFIFOHEAD(fd,packet_len(0x23c));
  11322. WFIFOW(fd,0) = 0x23c;
  11323. WFIFOW(fd,2) = result;
  11324. WFIFOW(fd,4) = error_count;
  11325. WFIFOSET(fd,packet_len(0x23c));
  11326. }
  11327. /// Party creation request
  11328. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11329. void clif_parse_CreateParty(int fd, map_session_data *sd){
  11330. if( sd == nullptr ){
  11331. return;
  11332. }
  11333. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11334. name[NAME_LENGTH-1] = '\0';
  11335. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11336. clif_displaymessage(fd, msg_txt(sd,227));
  11337. return;
  11338. }
  11339. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11340. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 4 );
  11341. return;
  11342. }
  11343. party_create(sd,name,0,0);
  11344. }
  11345. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11346. void clif_parse_CreateParty2(int fd, map_session_data *sd){
  11347. if( sd == nullptr ){
  11348. return;
  11349. }
  11350. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11351. char* name = RFIFOCP(fd,info->pos[0]);
  11352. int item1 = RFIFOB(fd,info->pos[1]);
  11353. int item2 = RFIFOB(fd,info->pos[2]);
  11354. name[NAME_LENGTH-1] = '\0';
  11355. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11356. clif_displaymessage(fd, msg_txt(sd,227));
  11357. return;
  11358. }
  11359. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11360. clif_skill_fail( *sd, 1, USESKILL_FAIL_LEVEL, 4 );
  11361. return;
  11362. }
  11363. party_create(sd,name,item1,item2);
  11364. }
  11365. /// Party invitation request
  11366. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11367. void clif_parse_PartyInvite(int fd, map_session_data *sd)
  11368. {
  11369. map_session_data *t_sd;
  11370. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11371. clif_displaymessage(fd, msg_txt(sd,227));
  11372. return;
  11373. }
  11374. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11375. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11376. clif_noask_sub(sd, t_sd, 1);
  11377. return;
  11378. }
  11379. party_invite(sd, t_sd);
  11380. }
  11381. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11382. void clif_parse_PartyInvite2(int fd, map_session_data *sd){
  11383. map_session_data *t_sd;
  11384. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11385. name[NAME_LENGTH-1] = '\0';
  11386. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11387. clif_displaymessage(fd, msg_txt(sd,227));
  11388. return;
  11389. }
  11390. t_sd = map_nick2sd(name,false);
  11391. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11392. clif_noask_sub(sd, t_sd, 1);
  11393. return;
  11394. }
  11395. party_invite(sd, t_sd);
  11396. }
  11397. /// Party invitation reply
  11398. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11399. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11400. /// flag:
  11401. /// 0 = reject
  11402. /// 1 = accept
  11403. void clif_parse_ReplyPartyInvite(int fd,map_session_data *sd)
  11404. {
  11405. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11406. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11407. RFIFOL(fd,info->pos[1]));
  11408. }
  11409. //(CZ_PARTY_JOIN_REQ_ACK)
  11410. void clif_parse_ReplyPartyInvite2(int fd,map_session_data *sd)
  11411. {
  11412. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11413. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11414. RFIFOB(fd,info->pos[1]));
  11415. }
  11416. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11417. /// 0100
  11418. void clif_parse_LeaveParty(int fd, map_session_data *sd)
  11419. {
  11420. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11421. clif_displaymessage(fd, msg_txt(sd,227));
  11422. return;
  11423. }
  11424. party_leave(sd);
  11425. }
  11426. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11427. /// 0103 <account id>.L <char name>.24B
  11428. void clif_parse_RemovePartyMember(int fd, map_session_data *sd)
  11429. {
  11430. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11431. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11432. clif_displaymessage(fd, msg_txt(sd,227));
  11433. return;
  11434. }
  11435. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11436. RFIFOCP(fd,info->pos[1]));
  11437. }
  11438. /// Request to change party options.
  11439. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11440. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11441. void clif_parse_PartyChangeOption(int fd, map_session_data *sd)
  11442. {
  11443. struct party_data *p;
  11444. int i,expflag;
  11445. int cmd = RFIFOW(fd,0);
  11446. struct s_packet_db* info = &packet_db[cmd];
  11447. if( !sd->status.party_id )
  11448. return;
  11449. p = party_search(sd->status.party_id);
  11450. if( p == nullptr )
  11451. return;
  11452. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11453. if( i == MAX_PARTY )
  11454. return; //Shouldn't happen
  11455. if( !p->party.member[i].leader )
  11456. return;
  11457. expflag = RFIFOL(fd,info->pos[0]);
  11458. if(cmd == 0x0102){ //Client can't change the item-field
  11459. party_changeoption(sd, expflag, p->party.item);
  11460. }
  11461. else {
  11462. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11463. party_changeoption(sd, expflag, itemflag);
  11464. }
  11465. }
  11466. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11467. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11468. void clif_parse_PartyMessage(int fd, map_session_data* sd){
  11469. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11470. // validate packet and retrieve name and message
  11471. if( !clif_process_message( sd, false, name, message, output ) )
  11472. return;
  11473. party_send_message(sd, output, strlen(output) + 1 );
  11474. }
  11475. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11476. /// 07da <account id>.L
  11477. void clif_parse_PartyChangeLeader(int fd, map_session_data* sd){
  11478. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),nullptr);
  11479. }
  11480. /// Party Booking in KRO [Spiria]
  11481. ///
  11482. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11483. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11484. void clif_parse_PartyBookingRegisterReq(int fd, map_session_data* sd){
  11485. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11486. short level = RFIFOW(fd,info->pos[0]);
  11487. short mapid = RFIFOW(fd,info->pos[1]);
  11488. int idxpbj = info->pos[2];
  11489. short job[MAX_PARTY_BOOKING_JOBS];
  11490. int i;
  11491. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11492. job[i] = RFIFOB(fd,idxpbj+i*2);
  11493. party_booking_register(sd, level, mapid, job);
  11494. }
  11495. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11496. /// 0803 <result>.W
  11497. /// result:
  11498. /// 0 = success
  11499. /// 1 = failure
  11500. /// 2 = already registered
  11501. void clif_PartyBookingRegisterAck(map_session_data *sd, int flag)
  11502. {
  11503. int fd = sd->fd;
  11504. WFIFOHEAD(fd,packet_len(0x803));
  11505. WFIFOW(fd,0) = 0x803;
  11506. WFIFOW(fd,2) = flag;
  11507. WFIFOSET(fd,packet_len(0x803));
  11508. }
  11509. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11510. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11511. void clif_parse_PartyBookingSearchReq(int fd, map_session_data* sd){
  11512. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11513. short level = RFIFOW(fd,info->pos[0]);
  11514. short mapid = RFIFOW(fd,info->pos[1]);
  11515. short job = RFIFOW(fd,info->pos[2]);
  11516. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11517. short resultcount = RFIFOW(fd,info->pos[4]);
  11518. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11519. }
  11520. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11521. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11522. /// more results:
  11523. /// 0 = no
  11524. /// 1 = yes
  11525. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11526. {
  11527. int i, j;
  11528. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11529. struct party_booking_ad_info *pb_ad;
  11530. WFIFOHEAD(fd,size*count + 5);
  11531. WFIFOW(fd,0) = 0x805;
  11532. WFIFOW(fd,2) = size*count + 5;
  11533. WFIFOB(fd,4) = more_result;
  11534. for(i=0; i<count; i++)
  11535. {
  11536. pb_ad = results[i];
  11537. WFIFOL(fd,i*size+5) = pb_ad->index;
  11538. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11539. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11540. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11541. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11542. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11543. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11544. }
  11545. WFIFOSET(fd,WFIFOW(fd,2));
  11546. }
  11547. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11548. /// 0806
  11549. void clif_parse_PartyBookingDeleteReq(int fd, map_session_data* sd)
  11550. {
  11551. if(party_booking_delete(sd))
  11552. clif_PartyBookingDeleteAck(sd, 0);
  11553. }
  11554. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11555. /// 0807 <result>.W
  11556. /// result:
  11557. /// 0 = success
  11558. /// 1 = success (auto-removed expired ad)
  11559. /// 2 = failure
  11560. /// 3 = nothing registered
  11561. void clif_PartyBookingDeleteAck(map_session_data* sd, int flag)
  11562. {
  11563. int fd = sd->fd;
  11564. WFIFOHEAD(fd,packet_len(0x807));
  11565. WFIFOW(fd,0) = 0x807;
  11566. WFIFOW(fd,2) = flag;
  11567. WFIFOSET(fd,packet_len(0x807));
  11568. }
  11569. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11570. /// 0808 { <job>.W }*6
  11571. void clif_parse_PartyBookingUpdateReq(int fd, map_session_data* sd)
  11572. {
  11573. short job[MAX_PARTY_BOOKING_JOBS];
  11574. int i;
  11575. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11576. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11577. job[i] = RFIFOW(fd,idxpbu+i*2);
  11578. party_booking_update(sd, job);
  11579. }
  11580. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11581. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11582. void clif_PartyBookingInsertNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11583. {
  11584. int i;
  11585. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11586. if(pb_ad == nullptr) return;
  11587. WBUFW(buf,0) = 0x809;
  11588. WBUFL(buf,2) = pb_ad->index;
  11589. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11590. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11591. WBUFW(buf,34) = pb_ad->p_detail.level;
  11592. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11593. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11594. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11595. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11596. }
  11597. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11598. /// 080a <index>.L { <job>.W }*6
  11599. void clif_PartyBookingUpdateNotify(map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11600. {
  11601. int i;
  11602. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11603. if(pb_ad == nullptr) return;
  11604. WBUFW(buf,0) = 0x80a;
  11605. WBUFL(buf,2) = pb_ad->index;
  11606. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11607. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11608. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11609. }
  11610. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11611. /// 080b <index>.L
  11612. void clif_PartyBookingDeleteNotify(map_session_data* sd, int index)
  11613. {
  11614. uint8 buf[6];
  11615. WBUFW(buf,0) = 0x80b;
  11616. WBUFL(buf,2) = index;
  11617. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11618. }
  11619. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11620. /// 012e
  11621. void clif_parse_CloseVending(int fd, map_session_data* sd)
  11622. {
  11623. vending_closevending(sd);
  11624. }
  11625. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11626. /// 0130 <account id>.L
  11627. void clif_parse_VendingListReq(int fd, map_session_data* sd)
  11628. {
  11629. if( sd->npc_id ) {// using an NPC
  11630. return;
  11631. }
  11632. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11633. }
  11634. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11635. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11636. void clif_parse_PurchaseReq(int fd, map_session_data* sd){
  11637. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC*)RFIFOP( fd, 0 );
  11638. vending_purchasereq( sd, p->AID, sd->vended_id, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11639. // whether it fails or not, the buy window is closed
  11640. sd->vended_id = 0;
  11641. }
  11642. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11643. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11644. void clif_parse_PurchaseReq2(int fd, map_session_data* sd){
  11645. #if PACKETVER >= 20100105
  11646. struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2* p = (struct PACKET_CZ_PC_PURCHASE_ITEMLIST_FROMMC2*)RFIFOP( fd, 0 );
  11647. vending_purchasereq( sd, p->AID, p->UniqueID, (uint8*)p->list, ( p->packetLength - sizeof( *p ) ) / sizeof( struct CZ_PURCHASE_ITEM_FROMMC ) );
  11648. // whether it fails or not, the buy window is closed
  11649. sd->vended_id = 0;
  11650. #endif
  11651. }
  11652. /// Confirm or cancel the shop preparation window.
  11653. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11654. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11655. /// result:
  11656. /// 0 = canceled
  11657. /// 1 = open
  11658. void clif_parse_OpenVending(int fd, map_session_data* sd){
  11659. if( sd == nullptr ){
  11660. return;
  11661. }
  11662. int cmd = RFIFOW(fd,0);
  11663. struct s_packet_db* info = &packet_db[cmd];
  11664. short len = (short)RFIFOW(fd,info->pos[0]);
  11665. const char* message = RFIFOCP(fd,info->pos[1]);
  11666. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11667. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11668. len -= 84;
  11669. }
  11670. else { //(CZ_REQ_OPENSTORE2)
  11671. bool flag;
  11672. len -= 85;
  11673. flag = RFIFOB(fd,info->pos[2]) != 0;
  11674. if (!flag) {
  11675. sd->state.prevend = 0;
  11676. sd->state.workinprogress = WIP_DISABLE_NONE;
  11677. }
  11678. }
  11679. if( sd->sc.getSCE(SC_NOCHAT) && sd->sc.getSCE(SC_NOCHAT)->val1&MANNER_NOROOM )
  11680. return;
  11681. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11682. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11683. return;
  11684. }
  11685. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11686. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11687. return;
  11688. }
  11689. if( message[0] == '\0' ) // invalid input
  11690. return;
  11691. vending_openvending(*sd, message, data, len/8, nullptr);
  11692. }
  11693. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11694. /// 0165 <char id>.L <guild name>.24B
  11695. void clif_parse_CreateGuild(int fd,map_session_data *sd){
  11696. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11697. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11698. name[NAME_LENGTH-1] = '\0';
  11699. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11700. clif_displaymessage(fd, msg_txt(sd,228));
  11701. return;
  11702. }
  11703. if(sd->clan){
  11704. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11705. return;
  11706. }
  11707. guild_create(sd, name);
  11708. }
  11709. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11710. /// 014d
  11711. void clif_parse_GuildCheckMaster(int fd, map_session_data *sd)
  11712. {
  11713. clif_guild_masterormember(sd);
  11714. }
  11715. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11716. /// 014f <type>.L
  11717. /// type:
  11718. /// 0 = basic info
  11719. /// 1 = member manager
  11720. /// 2 = positions
  11721. /// 3 = skills
  11722. /// 4 = expulsion list
  11723. /// 5 = unknown (GM_ALLGUILDLIST)
  11724. /// 6 = notice
  11725. void clif_parse_GuildRequestInfo(int fd, map_session_data *sd)
  11726. {
  11727. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11728. if( !sd->status.guild_id && !sd->bg_id )
  11729. return;
  11730. switch( type )
  11731. {
  11732. case 0: // Basic Information Guild, hostile alliance information
  11733. clif_guild_basicinfo( *sd );
  11734. clif_guild_allianceinfo(sd);
  11735. clif_guild_castle_list(*sd);
  11736. break;
  11737. case 1: // Members list, list job title
  11738. clif_guild_positionnamelist(sd);
  11739. clif_guild_memberlist( *sd );
  11740. break;
  11741. case 2: // List job title, title information list
  11742. clif_guild_positionnamelist(sd);
  11743. clif_guild_positioninfolist(sd);
  11744. break;
  11745. case 3: // Skill list
  11746. clif_guild_skillinfo(sd);
  11747. break;
  11748. case 4: // Expulsion list
  11749. clif_guild_expulsionlist(sd);
  11750. break;
  11751. default:
  11752. ShowError("clif: guild request info: unknown type %d\n", type);
  11753. break;
  11754. }
  11755. }
  11756. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11757. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11758. void clif_parse_GuildChangePositionInfo(int fd, map_session_data *sd)
  11759. {
  11760. int i;
  11761. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11762. int len = RFIFOW(fd,info->pos[0]);
  11763. int idxgpos = info->pos[1];
  11764. if(!sd->state.gmaster_flag)
  11765. return;
  11766. for(i = idxgpos; i < len; i += 40 ){
  11767. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11768. }
  11769. }
  11770. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11771. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11772. void clif_parse_GuildChangeMemberPosition( int fd, map_session_data *sd ){
  11773. if(!sd->state.gmaster_flag)
  11774. return;
  11775. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS* p = (struct PACKET_CZ_REQ_CHANGE_MEMBERPOS*)RFIFOP( fd, 0 );
  11776. int16 entries = ( p->packetLength - sizeof( *p ) ) / sizeof( p->list[0] );
  11777. for( int16 i = 0; i < entries; i++ ){
  11778. struct PACKET_CZ_REQ_CHANGE_MEMBERPOS_sub& entry = p->list[i];
  11779. // Guild leadership change
  11780. if( entry.position == 0 ){
  11781. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11782. clif_msg( sd, MSI_IMPOSSIBLE_CHANGE_GUILD_MASTER_IN_SIEGE_TIME );
  11783. return;
  11784. }
  11785. if( battle_config.guild_leaderchange_delay && DIFF_TICK( time( nullptr ),sd->guild->guild.last_leader_change ) < battle_config.guild_leaderchange_delay ){
  11786. clif_msg( sd, MSI_IMPOSSIBLE_CHANGE_GUILD_MASTER_NOT_TIME );
  11787. return;
  11788. }
  11789. guild_gm_change( sd->status.guild_id, entry.CID );
  11790. // No further entries will be processed - the requesting player lost his guild master status
  11791. return;
  11792. }else if( entry.position > 0 ){
  11793. guild_change_memberposition( sd->status.guild_id, entry.AID, entry.CID, entry.position );
  11794. }
  11795. }
  11796. }
  11797. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11798. /// 0151 <guild id>.L
  11799. void clif_parse_GuildRequestEmblem(int fd,map_session_data *sd)
  11800. {
  11801. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11802. auto g = guild_search(guild_id);
  11803. if (g)
  11804. clif_guild_emblem(*sd, g->guild);
  11805. }
  11806. /// Validates data of a guild emblem (compressed bitmap)
  11807. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11808. EMBVALIDATE_SUCCESS = 0,
  11809. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11810. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of inter_config.emblem_transparency_limit
  11811. };
  11812. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11813. {
  11814. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11815. unsigned long buf_len = sizeof(buf);
  11816. int offset = 0;
  11817. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11818. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11819. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11820. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11821. ))
  11822. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11823. if(inter_config.emblem_transparency_limit != 100) {
  11824. int i, transcount = 1, tmp[3];
  11825. for(i = offset; i < buf_len-1; i++) {
  11826. int j = i%3;
  11827. tmp[j] = RBUFL(buf,i);
  11828. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11829. transcount++;
  11830. }
  11831. if(((transcount*300)/(buf_len-offset)) > inter_config.emblem_transparency_limit) //convert in % to chk
  11832. return EMBVALIDATE_ERR_TRANSPARENCY;
  11833. }
  11834. return EMBVALIDATE_SUCCESS;
  11835. }
  11836. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11837. /// 0153 <packet len>.W <emblem data>.?B
  11838. void clif_parse_GuildChangeEmblem(int fd,map_session_data *sd){
  11839. if( sd == nullptr ){
  11840. return;
  11841. }
  11842. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11843. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11844. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11845. int emb_val=0;
  11846. if( !emblem_len || !sd->state.gmaster_flag )
  11847. return;
  11848. if(!(inter_config.emblem_woe_change) && is_agit_start() ){
  11849. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11850. return;
  11851. }
  11852. emb_val = clif_validate_emblem(emblem, emblem_len);
  11853. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11854. 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);
  11855. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11856. return;
  11857. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11858. char output[128];
  11859. safesnprintf(output,sizeof(output),msg_txt(sd,387),inter_config.emblem_transparency_limit);
  11860. 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"
  11861. return;
  11862. }
  11863. guild_change_emblem( *sd, emblem_len, (const char*)emblem );
  11864. }
  11865. /// Request to update the guild emblem id
  11866. /// 0b46 <guild id>.L <version>.L
  11867. void clif_parse_GuildChangeEmblem2(int fd, map_session_data* sd) {
  11868. if( sd == nullptr ){
  11869. return;
  11870. }
  11871. #if PACKETVER >= 20190724
  11872. const PACKET_CZ_REQ_ADD_NEW_EMBLEM* p = (PACKET_CZ_REQ_ADD_NEW_EMBLEM*)RFIFOP(fd, 0);
  11873. auto &g = sd->guild;
  11874. if (!g || g->guild.guild_id != p->guild_id)
  11875. return;
  11876. if (!sd->state.gmaster_flag)
  11877. return;
  11878. if (!inter_config.emblem_woe_change && is_agit_start()) {
  11879. clif_messagecolor(&sd->bl, color_table[COLOR_RED], msg_txt(sd, 385), false, SELF); //"You not allowed to change emblem during woe"
  11880. return;
  11881. }
  11882. guild_change_emblem_version( *sd, p->version );
  11883. #endif
  11884. }
  11885. /// Guild notice update request (CZ_GUILD_NOTICE).
  11886. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11887. void clif_parse_GuildChangeNotice(int fd, map_session_data* sd){
  11888. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11889. int guild_id = RFIFOL(fd,info->pos[0]);
  11890. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11891. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11892. if(!sd->state.gmaster_flag)
  11893. return;
  11894. // compensate for some client defects when using multilanguage mode
  11895. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11896. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11897. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11898. guild_change_notice(sd, guild_id, msg1, msg2);
  11899. }
  11900. // Helper function for guild invite functions
  11901. int clif_sub_guild_invite(int fd, map_session_data *sd, map_session_data *t_sd)
  11902. {
  11903. if (t_sd == nullptr) // not online or does not exist
  11904. return 1;
  11905. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11906. clif_displaymessage(fd, msg_txt(sd,228));
  11907. return 1;
  11908. }
  11909. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11910. clif_noask_sub(sd, t_sd, 2);
  11911. return 1;
  11912. }
  11913. // Players in a clan can not join a guild
  11914. if(t_sd && t_sd->clan){
  11915. return 1;
  11916. }
  11917. guild_invite(sd, t_sd);
  11918. return 0;
  11919. }
  11920. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11921. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11922. void clif_parse_GuildInvite(int fd,map_session_data *sd){
  11923. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11924. map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11925. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11926. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11927. if (clif_sub_guild_invite(fd, sd, t_sd))
  11928. return;
  11929. }
  11930. /// Guild invite request (/guildinvite)
  11931. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11932. void
  11933. clif_parse_GuildInvite2(int fd, map_session_data *sd) {
  11934. map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11935. if (clif_sub_guild_invite(fd, sd, t_sd))
  11936. return;
  11937. }
  11938. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11939. /// 016b <guild id>.L <answer>.L
  11940. /// answer:
  11941. /// 0 = refuse
  11942. /// 1 = accept
  11943. void clif_parse_GuildReplyInvite(int fd,map_session_data *sd){
  11944. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11945. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11946. RFIFOL(fd,info->pos[1]));
  11947. }
  11948. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11949. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11950. void clif_parse_GuildLeave(int fd,map_session_data *sd){
  11951. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11952. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11953. clif_displaymessage(fd, msg_txt(sd,228));
  11954. return;
  11955. }
  11956. if( sd->bg_id ) {
  11957. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11958. return;
  11959. }
  11960. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11961. RFIFOL(fd,info->pos[1]),
  11962. RFIFOL(fd,info->pos[2]),
  11963. RFIFOCP(fd,info->pos[3]));
  11964. }
  11965. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11966. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11967. void clif_parse_GuildExpulsion(int fd,map_session_data *sd){
  11968. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11969. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  11970. { // Guild locked.
  11971. clif_displaymessage(fd, msg_txt(sd,228));
  11972. return;
  11973. }
  11974. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11975. RFIFOL(fd,info->pos[1]),
  11976. RFIFOL(fd,info->pos[2]),
  11977. RFIFOCP(fd,info->pos[3]));
  11978. }
  11979. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11980. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11981. void clif_parse_GuildMessage(int fd, map_session_data* sd){
  11982. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11983. // validate packet and retrieve name and message
  11984. if( !clif_process_message( sd, false, name, message, output ) )
  11985. return;
  11986. if( sd->bg_id )
  11987. bg_send_message(sd, output, strlen(output) );
  11988. else
  11989. guild_send_message(sd, output, strlen(output) );
  11990. }
  11991. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11992. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11993. void clif_parse_GuildRequestAlliance(int fd, map_session_data *sd)
  11994. {
  11995. map_session_data *t_sd;
  11996. if(!sd->state.gmaster_flag)
  11997. return;
  11998. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11999. clif_displaymessage(fd, msg_txt(sd,228));
  12000. return;
  12001. }
  12002. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12003. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12004. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  12005. // @noask [LuzZza]
  12006. if(t_sd && t_sd->state.noask) {
  12007. clif_noask_sub(sd, t_sd, 3);
  12008. return;
  12009. }
  12010. guild_reqalliance(sd,t_sd);
  12011. }
  12012. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  12013. /// 0172 <inviter account id>.L <answer>.L
  12014. /// answer:
  12015. /// 0 = refuse
  12016. /// 1 = accept
  12017. void clif_parse_GuildReplyAlliance(int fd, map_session_data *sd){
  12018. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12019. guild_reply_reqalliance(sd,
  12020. RFIFOL(fd,info->pos[0]),
  12021. RFIFOL(fd,info->pos[1]));
  12022. }
  12023. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  12024. /// 0183 <opponent guild id>.L <relation>.L
  12025. /// relation:
  12026. /// 0 = Ally
  12027. /// 1 = Enemy
  12028. void clif_parse_GuildDelAlliance(int fd, map_session_data *sd){
  12029. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12030. if(!sd->state.gmaster_flag)
  12031. return;
  12032. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12033. clif_displaymessage(fd, msg_txt(sd,228));
  12034. return;
  12035. }
  12036. guild_delalliance(sd,
  12037. RFIFOL(fd,info->pos[0]),
  12038. RFIFOL(fd,info->pos[1]));
  12039. }
  12040. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  12041. /// 0180 <account id>.L
  12042. void clif_parse_GuildOpposition(int fd, map_session_data *sd)
  12043. {
  12044. map_session_data *t_sd;
  12045. if(!sd->state.gmaster_flag)
  12046. return;
  12047. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  12048. clif_displaymessage(fd, msg_txt(sd,228));
  12049. return;
  12050. }
  12051. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12052. // @noask [LuzZza]
  12053. if(t_sd && t_sd->state.noask) {
  12054. clif_noask_sub(sd, t_sd, 4);
  12055. return;
  12056. }
  12057. guild_opposition(sd,t_sd);
  12058. }
  12059. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  12060. /// 015d <key>.40B
  12061. /// key:
  12062. /// now guild name; might have been (intended) email, since the
  12063. /// field name and size is same as the one in CH_DELETE_CHAR.
  12064. void clif_parse_GuildBreak(int fd, map_session_data *sd)
  12065. {
  12066. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  12067. clif_displaymessage(fd, msg_txt(sd,228));
  12068. return;
  12069. }
  12070. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12071. }
  12072. /// Pet
  12073. ///
  12074. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  12075. /// 01a1 <type>.B
  12076. /// type:
  12077. /// 0 = pet information
  12078. /// 1 = feed
  12079. /// 2 = performance
  12080. /// 3 = return to egg
  12081. /// 4 = unequip accessory
  12082. void clif_parse_PetMenu(int fd, map_session_data *sd){
  12083. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12084. }
  12085. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  12086. /// 019f <id>.L
  12087. void clif_parse_CatchPet(int fd, map_session_data *sd){
  12088. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12089. }
  12090. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  12091. /// 01a7 <index>.W
  12092. void clif_parse_SelectEgg(int fd, map_session_data *sd){
  12093. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  12094. return;
  12095. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  12096. clif_menuskill_clear(sd);
  12097. }
  12098. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  12099. /// 01a9 <data>.L
  12100. /// data:
  12101. /// is either emotion (@see enum emotion_type) or a compound value
  12102. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  12103. /// entry (given in parentheses) in data\pettalktable.xml
  12104. /// act id:
  12105. /// 0 = feeding
  12106. /// 1 = hunting
  12107. /// 2 = danger
  12108. /// 3 = dead
  12109. /// 4 = normal (stand)
  12110. /// 5 = special performance (perfor_s)
  12111. /// 6 = level up (levelup)
  12112. /// 7 = performance 1 (perfor_1)
  12113. /// 8 = performance 2 (perfor_2)
  12114. /// 9 = performance 3 (perfor_3)
  12115. /// 10 = log-in greeting (connect)
  12116. /// hungry value:
  12117. /// 0 = very hungry (hungry)
  12118. /// 1 = hungry (bit_hungry)
  12119. /// 2 = satisfied (noting)
  12120. /// 3 = stuffed (full)
  12121. /// 4 = full (so_full)
  12122. void clif_parse_SendEmotion(int fd, map_session_data *sd)
  12123. {
  12124. if(sd->pd)
  12125. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12126. }
  12127. /// Request to change pet's name (CZ_RENAME_PET).
  12128. /// 01a5 <name>.24B
  12129. void clif_parse_ChangePetName(int fd, map_session_data *sd)
  12130. {
  12131. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12132. }
  12133. /// /kill (CZ_DISCONNECT_CHARACTER).
  12134. /// Request to disconnect a character.
  12135. /// 00cc <account id>.L
  12136. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  12137. void clif_parse_GMKick(int fd, map_session_data *sd)
  12138. {
  12139. struct block_list *target;
  12140. int tid;
  12141. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12142. target = map_id2bl(tid);
  12143. if (!target) {
  12144. clif_GM_kickack(sd, 0);
  12145. return;
  12146. }
  12147. switch (target->type) {
  12148. case BL_PC:
  12149. {
  12150. char command[NAME_LENGTH+6];
  12151. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  12152. is_atcommand(fd, sd, command, 1);
  12153. }
  12154. break;
  12155. /**
  12156. * This one does not invoke any atcommand, so we need to check for permissions.
  12157. */
  12158. case BL_MOB:
  12159. {
  12160. char command[100];
  12161. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  12162. clif_GM_kickack(sd, 0);
  12163. return;
  12164. }
  12165. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  12166. log_atcommand(sd, command);
  12167. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  12168. }
  12169. break;
  12170. case BL_NPC:
  12171. {
  12172. struct npc_data* nd = (struct npc_data *)target;
  12173. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  12174. npc_unload_duplicates(nd);
  12175. npc_unload(nd,true);
  12176. npc_read_event_script();
  12177. }
  12178. }
  12179. break;
  12180. default:
  12181. clif_GM_kickack(sd, 0);
  12182. }
  12183. }
  12184. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  12185. /// Request to disconnect all characters.
  12186. /// 00ce
  12187. void clif_parse_GMKickAll(int fd, map_session_data* sd) {
  12188. char cmd[15];
  12189. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  12190. is_atcommand(fd, sd, cmd, 1);
  12191. }
  12192. /// /remove (CZ_REMOVE_AID).
  12193. /// Request to warp to a character with given login ID.
  12194. /// 01ba <account name>.24B
  12195. /// /shift (CZ_SHIFT).
  12196. /// Request to warp to a character with given name.
  12197. /// 01bb <char name>.24B
  12198. void clif_parse_GMShift(int fd, map_session_data *sd)
  12199. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  12200. char *player_name;
  12201. char command[NAME_LENGTH+8];
  12202. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12203. player_name[NAME_LENGTH-1] = '\0';
  12204. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  12205. is_atcommand(fd, sd, command, 1);
  12206. }
  12207. /// /remove (CZ_REMOVE_AID_SSO).
  12208. /// Request to warp to a character with given account ID.
  12209. /// 0843 <account id>.L
  12210. void clif_parse_GMRemove2(int fd, map_session_data* sd)
  12211. {
  12212. uint32 account_id;
  12213. map_session_data* pl_sd;
  12214. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12215. if( (pl_sd = map_id2sd(account_id)) != nullptr ) {
  12216. char command[NAME_LENGTH+8];
  12217. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  12218. is_atcommand(fd, sd, command, 1);
  12219. }
  12220. }
  12221. /// /recall (CZ_RECALL).
  12222. /// Request to summon a player with given login ID to own position.
  12223. /// 01bc <account name>.24B
  12224. /// /summon (CZ_RECALL_GID).
  12225. /// Request to summon a player with given name to own position.
  12226. /// 01bd <char name>.24B
  12227. void clif_parse_GMRecall(int fd, map_session_data *sd)
  12228. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  12229. char *player_name;
  12230. char command [NAME_LENGTH+8];
  12231. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12232. player_name[NAME_LENGTH-1] = '\0';
  12233. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  12234. is_atcommand(fd, sd, command, 1);
  12235. }
  12236. /// /recall (CZ_RECALL_SSO).
  12237. /// Request to summon a player with given account ID to own position.
  12238. /// 0842 <account id>.L
  12239. void clif_parse_GMRecall2(int fd, map_session_data* sd)
  12240. {
  12241. uint32 account_id;
  12242. map_session_data* pl_sd;
  12243. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12244. if( (pl_sd = map_id2sd(account_id)) != nullptr ) {
  12245. char command[NAME_LENGTH+8];
  12246. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  12247. is_atcommand(fd, sd, command, 1);
  12248. }
  12249. }
  12250. /// /item /monster (CZ_ITEM_CREATE).
  12251. /// Request to execute GM commands.
  12252. /// Usage:
  12253. /// /item n - summon n monster or acquire n item/s
  12254. /// /item money - grants 2147483647 zenies
  12255. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  12256. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  12257. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  12258. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  12259. /// /item cap_n - capture n monster as pet.(not yet implemented)
  12260. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  12261. /// 013f <item/mob name>.24B
  12262. /// 09ce <item/mob name>.100B [Ind/Yommy]
  12263. void clif_parse_GM_Item_Monster(int fd, map_session_data *sd)
  12264. {
  12265. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12266. int mob_id = 0;
  12267. StringBuf command;
  12268. char *str;
  12269. //#if PACKETVER >= 20131218
  12270. // char str[100];
  12271. //#else
  12272. // char str[24];
  12273. //#endif
  12274. str = RFIFOCP(fd,info->pos[0]);
  12275. if (!str || str[0] == '\0')
  12276. return;
  12277. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  12278. return;
  12279. trim(str);
  12280. // Zeny
  12281. if( strcmpi(str, "money") == 0 ) {
  12282. StringBuf_Init(&command);
  12283. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  12284. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12285. StringBuf_Destroy(&command);
  12286. return;
  12287. }
  12288. std::shared_ptr<item_data> id = item_db.searchname( str );
  12289. // Item
  12290. if( id ){
  12291. StringBuf_Init(&command);
  12292. if( !itemdb_isstackable2( id.get() ) ){ //Nonstackable
  12293. StringBuf_Printf(&command, "%citem2 %u 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12294. }else{
  12295. if (id->flag.guid)
  12296. StringBuf_Printf(&command, "%citem %u 1", atcommand_symbol, id->nameid);
  12297. else
  12298. StringBuf_Printf(&command, "%citem %u 20", atcommand_symbol, id->nameid);
  12299. }
  12300. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12301. StringBuf_Destroy(&command);
  12302. return;
  12303. }
  12304. // Monster
  12305. if ((mob_id = mobdb_searchname(str)) == 0)
  12306. mob_id = mobdb_checkid(atoi(str));
  12307. std::shared_ptr<s_mob_db> mob = mob_db.find(mob_id);
  12308. if( mob != nullptr ) {
  12309. StringBuf_Init(&command);
  12310. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite.c_str());
  12311. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12312. StringBuf_Destroy(&command);
  12313. return;
  12314. }
  12315. }
  12316. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12317. /// 019d <effect state>.L
  12318. /// effect state:
  12319. /// TODO: Any OPTION_* ?
  12320. void clif_parse_GMHide(int fd, map_session_data *sd) {
  12321. char cmd[6];
  12322. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12323. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12324. is_atcommand(fd, sd, cmd, 1);
  12325. }
  12326. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12327. /// 0149 <account id>.L <type>.B <value>.W
  12328. /// type:
  12329. /// 0 = positive points
  12330. /// 1 = negative points
  12331. /// 2 = self mute (+10 minutes)
  12332. void clif_parse_GMReqNoChat(int fd,map_session_data *sd)
  12333. {
  12334. int id, type, value;
  12335. map_session_data *dstsd;
  12336. char command[NAME_LENGTH+15];
  12337. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12338. id = RFIFOL(fd,info->pos[0]);
  12339. type = RFIFOB(fd,info->pos[1]);
  12340. value = RFIFOW(fd,info->pos[2]);
  12341. if( type == 0 )
  12342. value = -value;
  12343. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12344. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12345. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12346. return;
  12347. dstsd = map_id2sd(id);
  12348. if( dstsd == nullptr )
  12349. return;
  12350. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12351. is_atcommand(fd, sd, command, 1);
  12352. }
  12353. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12354. /// GM adjustment of a player's manner value by -60.
  12355. /// 0212 <char name>.24B
  12356. void clif_parse_GMRc(int fd, map_session_data* sd)
  12357. {
  12358. char command[NAME_LENGTH+15];
  12359. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12360. name[NAME_LENGTH-1] = '\0';
  12361. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12362. is_atcommand(fd, sd, command, 1);
  12363. }
  12364. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12365. /// 01e0 <account id>.L <account name>.24B
  12366. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12367. {
  12368. WFIFOHEAD(fd,packet_len(0x1e0));
  12369. WFIFOW(fd,0) = 0x1e0;
  12370. WFIFOL(fd,2) = account_id;
  12371. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12372. WFIFOSET(fd,packet_len(0x1e0));
  12373. }
  12374. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12375. /// 01df <account id>.L
  12376. //! TODO: Figure out how does this actually work
  12377. void clif_parse_GMReqAccountName(int fd, map_session_data *sd)
  12378. {
  12379. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12380. /*
  12381. char query[30];
  12382. safesnprintf(query,sizeof(query),"%d", account_id);
  12383. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12384. */
  12385. clif_account_name(fd, account_id, "");
  12386. }
  12387. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12388. /// GM single cell type change request.
  12389. /// 0198 <x>.W <y>.W <type>.W
  12390. /// type:
  12391. /// 0 = not walkable
  12392. /// 1 = walkable
  12393. void clif_parse_GMChangeMapType(int fd, map_session_data *sd)
  12394. {
  12395. int x,y,type;
  12396. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12397. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12398. return;
  12399. x = RFIFOW(fd,info->pos[0]);
  12400. y = RFIFOW(fd,info->pos[1]);
  12401. type = RFIFOW(fd,info->pos[2]);
  12402. map_setgatcell(sd->bl.m,x,y,type);
  12403. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12404. //FIXME: once players leave the map, the client 'forgets' this information.
  12405. }
  12406. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12407. /// Request to allow/deny whispers from a nick.
  12408. /// 00cf <nick>.24B <type>.B
  12409. /// type:
  12410. /// 0 = (/ex nick) deny speech from nick
  12411. /// 1 = (/in nick) allow speech from nick
  12412. void clif_parse_PMIgnore(int fd, map_session_data* sd)
  12413. {
  12414. char* nick;
  12415. uint8 type;
  12416. int i;
  12417. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12418. nick = RFIFOCP(fd,info->pos[0]);
  12419. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12420. type = RFIFOB(fd,info->pos[1]);
  12421. if( type == 0 ) { // Add name to ignore list (block)
  12422. if (strcmp(wisp_server_name, nick) == 0) {
  12423. clif_wisexin(sd, type, 1); // fail
  12424. return;
  12425. }
  12426. // try to find a free spot, while checking for duplicates at the same time
  12427. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12428. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12429. clif_wisexin(sd, type, 2); // too many blocks
  12430. return;
  12431. }
  12432. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12433. clif_wisexin(sd, type, 0); // Aegis reports success.
  12434. return;
  12435. }
  12436. //Insert in position i
  12437. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12438. } else { // Remove name from ignore list (unblock)
  12439. // find entry
  12440. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12441. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[0] == '\0' ) { //Not found
  12442. clif_wisexin(sd, type, 1); // fail
  12443. return;
  12444. }
  12445. // move everything one place down to overwrite removed entry
  12446. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12447. // wipe last entry
  12448. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12449. }
  12450. clif_wisexin(sd, type, 0); // success
  12451. }
  12452. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12453. /// Request to allow/deny all whispers.
  12454. /// 00d0 <type>.B
  12455. /// type:
  12456. /// 0 = (/exall) deny all speech
  12457. /// 1 = (/inall) allow all speech
  12458. void clif_parse_PMIgnoreAll(int fd, map_session_data *sd)
  12459. {
  12460. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12461. if( type == 0 ) {// Deny all
  12462. if( sd->state.ignoreAll ) {
  12463. flag = 1; // fail
  12464. } else {
  12465. sd->state.ignoreAll = 1;
  12466. flag = 0; // success
  12467. }
  12468. } else {//Unblock everyone
  12469. if( sd->state.ignoreAll ) {
  12470. sd->state.ignoreAll = 0;
  12471. flag = 0; // success
  12472. } else {
  12473. if (sd->ignore[0].name[0] != '\0')
  12474. { //Wipe the ignore list.
  12475. memset(sd->ignore, 0, sizeof(sd->ignore));
  12476. flag = 0; // success
  12477. } else {
  12478. flag = 1; // fail
  12479. }
  12480. }
  12481. }
  12482. clif_wisall(sd, type, flag);
  12483. }
  12484. /// Whisper ignore list (ZC_WHISPER_LIST).
  12485. /// 00d4 <packet len>.W { <char name>.24B }*
  12486. void clif_PMIgnoreList(map_session_data* sd)
  12487. {
  12488. int i, fd = sd->fd;
  12489. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12490. WFIFOW(fd,0) = 0xd4;
  12491. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12492. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12493. }
  12494. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12495. WFIFOSET(fd,WFIFOW(fd,2));
  12496. }
  12497. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12498. /// 00d3
  12499. void clif_parse_PMIgnoreList(int fd,map_session_data *sd)
  12500. {
  12501. clif_PMIgnoreList(sd);
  12502. }
  12503. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12504. /// 01e7
  12505. void clif_parse_NoviceDoriDori(int fd, map_session_data *sd)
  12506. {
  12507. if (sd->state.doridori) return;
  12508. switch (sd->class_&MAPID_UPPERMASK) {
  12509. case MAPID_SOUL_LINKER:
  12510. case MAPID_STAR_GLADIATOR:
  12511. case MAPID_TAEKWON:
  12512. if (!sd->state.rest)
  12513. break;
  12514. [[fallthrough]];
  12515. case MAPID_SUPER_NOVICE:
  12516. case MAPID_SUPER_BABY:
  12517. case MAPID_SUPER_NOVICE_E:
  12518. case MAPID_SUPER_BABY_E:
  12519. sd->state.doridori=1;
  12520. break;
  12521. }
  12522. }
  12523. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12524. /// 01ed
  12525. /// Note: This packet is caused by 7 lines of any text, followed by
  12526. /// the prayer and an another line of any text. The prayer is
  12527. /// defined by lines 790~793 in data\msgstringtable.txt
  12528. /// "Dear angel, can you hear my voice?"
  12529. /// "I am" (space separated player name) "Super Novice~"
  12530. /// "Help me out~ Please~ T_T"
  12531. void clif_parse_NoviceExplosionSpirits(int fd, map_session_data *sd)
  12532. {
  12533. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12534. t_exp next = pc_nextbaseexp(sd);
  12535. if( next ) {
  12536. int percent = (int)( ( (double)sd->status.base_exp/(double)next )*1000. );
  12537. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12538. sc_start(&sd->bl,&sd->bl, SC_EXPLOSIONSPIRITS, 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12539. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12540. }
  12541. }
  12542. }
  12543. }
  12544. /// Friends List
  12545. ///
  12546. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12547. /// 0206 <account id>.L <char id>.L <state>.B
  12548. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12549. /// state:
  12550. /// 0 = online
  12551. /// 1 = offline
  12552. void clif_friendslist_toggle(map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12553. {
  12554. int i, fd = sd->fd;
  12555. //Seek friend.
  12556. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12557. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12558. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12559. return; //Not found
  12560. WFIFOHEAD(fd,packet_len(0x206));
  12561. WFIFOW(fd, 0) = 0x206;
  12562. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12563. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12564. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12565. #if PACKETVER >= 20180221
  12566. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12567. #endif
  12568. WFIFOSET(fd, packet_len(0x206));
  12569. }
  12570. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12571. int clif_friendslist_toggle_sub(map_session_data *sd,va_list ap)
  12572. {
  12573. uint32 account_id, char_id, online;
  12574. account_id = va_arg(ap, int);
  12575. char_id = va_arg(ap, int);
  12576. online = va_arg(ap, int);
  12577. clif_friendslist_toggle(sd, account_id, char_id, online);
  12578. return 0;
  12579. }
  12580. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12581. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12582. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12583. void clif_friendslist_send( map_session_data& sd ){
  12584. PACKET_ZC_FRIENDS_LIST* p = reinterpret_cast<PACKET_ZC_FRIENDS_LIST*>( packet_buffer );
  12585. p->packetType = HEADER_ZC_FRIENDS_LIST;
  12586. p->PacketLength = sizeof( *p );
  12587. for( int i = 0, c = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12588. PACKET_ZC_FRIENDS_LIST_sub& f = p->friends[c];
  12589. f.AID = sd.status.friends[i].account_id;
  12590. f.CID = sd.status.friends[i].char_id;
  12591. #if !( PACKETVER_MAIN_NUM >= 20180307 || PACKETVER_RE_NUM >= 20180221 || PACKETVER_ZERO_NUM >= 20180328 ) || PACKETVER >= 20200902
  12592. safestrncpy( f.name, sd.status.friends[i].name, sizeof( f.name ) );
  12593. #endif
  12594. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( f ) );
  12595. c++;
  12596. }
  12597. clif_send( p, p->PacketLength, &sd.bl, SELF );
  12598. // Sending the online players
  12599. for( int i = 0; i < MAX_FRIENDS && sd.status.friends[i].char_id; i++ ){
  12600. if( map_charid2sd( sd.status.friends[i].char_id ) ){
  12601. clif_friendslist_toggle( &sd, sd.status.friends[i].account_id, sd.status.friends[i].char_id, 1 );
  12602. }
  12603. }
  12604. }
  12605. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12606. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12607. /// result:
  12608. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12609. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12610. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12611. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12612. void clif_friendslist_reqack(map_session_data *sd, map_session_data *f_sd, int type)
  12613. {
  12614. int fd;
  12615. nullpo_retv(sd);
  12616. fd = sd->fd;
  12617. WFIFOHEAD(fd,packet_len(0x209));
  12618. WFIFOW(fd,0) = 0x209;
  12619. WFIFOW(fd,2) = type;
  12620. if (f_sd) {
  12621. WFIFOL(fd,4) = f_sd->status.account_id;
  12622. WFIFOL(fd,8) = f_sd->status.char_id;
  12623. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12624. }
  12625. WFIFOSET(fd, packet_len(0x209));
  12626. }
  12627. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12628. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12629. void clif_friendlist_req(map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12630. {
  12631. int fd = sd->fd;
  12632. WFIFOHEAD(fd,packet_len(0x207));
  12633. WFIFOW(fd,0) = 0x207;
  12634. WFIFOL(fd,2) = account_id;
  12635. WFIFOL(fd,6) = char_id;
  12636. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12637. WFIFOSET(fd,packet_len(0x207));
  12638. }
  12639. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12640. /// 0202 <name>.24B
  12641. void clif_parse_FriendsListAdd(int fd, map_session_data *sd)
  12642. {
  12643. map_session_data *f_sd;
  12644. int i;
  12645. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12646. // Friend doesn't exist (no player with this name)
  12647. if (f_sd == nullptr) {
  12648. clif_displaymessage(fd, msg_txt(sd,3));
  12649. return;
  12650. }
  12651. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12652. return;
  12653. }
  12654. // ensure that the request player's friend list is not full
  12655. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12656. if( i == MAX_FRIENDS ){
  12657. clif_friendslist_reqack(sd, f_sd, 2);
  12658. return;
  12659. }
  12660. // @noask [LuzZza]
  12661. if(f_sd->state.noask) {
  12662. clif_noask_sub(sd, f_sd, 5);
  12663. return;
  12664. }
  12665. // Friend already exists
  12666. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12667. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12668. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12669. return;
  12670. }
  12671. }
  12672. f_sd->friend_req = sd->status.char_id;
  12673. sd->friend_req = f_sd->status.char_id;
  12674. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12675. }
  12676. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12677. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12678. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12679. /// reply:
  12680. /// 0 = rejected
  12681. /// 1 = accepted
  12682. void clif_parse_FriendsListReply(int fd, map_session_data *sd)
  12683. {
  12684. map_session_data *f_sd;
  12685. uint32 account_id;
  12686. char reply;
  12687. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12688. account_id = RFIFOL(fd,info->pos[0]);
  12689. //char_id = RFIFOL(fd,info->pos[1]);
  12690. #if PACKETVER < 6
  12691. reply = RFIFOB(fd,info->pos[2]);
  12692. #else
  12693. reply = RFIFOL(fd,info->pos[2]);
  12694. #endif
  12695. if( sd->bl.id == account_id ) {// adding oneself as friend
  12696. return;
  12697. }
  12698. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12699. if (f_sd == nullptr)
  12700. return;
  12701. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12702. clif_friendslist_reqack(f_sd, sd, 1);
  12703. else {
  12704. int i;
  12705. // Find an empty slot
  12706. for (i = 0; i < MAX_FRIENDS; i++)
  12707. if (f_sd->status.friends[i].char_id == 0)
  12708. break;
  12709. if (i == MAX_FRIENDS) {
  12710. clif_friendslist_reqack(f_sd, sd, 2);
  12711. return;
  12712. }
  12713. f_sd->status.friends[i].account_id = sd->status.account_id;
  12714. f_sd->status.friends[i].char_id = sd->status.char_id;
  12715. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12716. clif_friendslist_reqack(f_sd, sd, 0);
  12717. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12718. if (battle_config.friend_auto_add) {
  12719. // Also add f_sd to sd's friendlist.
  12720. for (i = 0; i < MAX_FRIENDS; i++) {
  12721. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12722. return; //No need to add anything.
  12723. if (sd->status.friends[i].char_id == 0)
  12724. break;
  12725. }
  12726. if (i == MAX_FRIENDS) {
  12727. clif_friendslist_reqack(sd, f_sd, 2);
  12728. return;
  12729. }
  12730. sd->status.friends[i].account_id = f_sd->status.account_id;
  12731. sd->status.friends[i].char_id = f_sd->status.char_id;
  12732. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12733. clif_friendslist_reqack(sd, f_sd, 0);
  12734. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12735. }
  12736. }
  12737. }
  12738. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12739. /// 0203 <account id>.L <char id>.L
  12740. void clif_parse_FriendsListRemove(int fd, map_session_data *sd)
  12741. {
  12742. map_session_data *f_sd = nullptr;
  12743. uint32 account_id, char_id;
  12744. int i, j;
  12745. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12746. account_id = RFIFOL(fd,info->pos[0]);
  12747. char_id = RFIFOL(fd,info->pos[1]);
  12748. // Search friend
  12749. for (i = 0; i < MAX_FRIENDS &&
  12750. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12751. if (i == MAX_FRIENDS) {
  12752. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12753. return;
  12754. }
  12755. //remove from friend's list first
  12756. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12757. for (i = 0; i < MAX_FRIENDS &&
  12758. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12759. if (i != MAX_FRIENDS) {
  12760. // move all chars up
  12761. for(j = i + 1; j < MAX_FRIENDS; j++)
  12762. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12763. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12764. //should the guy be notified of some message? we should add it here if so
  12765. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12766. WFIFOW(f_sd->fd,0) = 0x20a;
  12767. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12768. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12769. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12770. }
  12771. } else { //friend not online -- ask char server to delete from his friendlist
  12772. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12773. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12774. return;
  12775. }
  12776. }
  12777. // We can now delete from original requester
  12778. for (i = 0; i < MAX_FRIENDS &&
  12779. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12780. // move all chars up
  12781. for(j = i + 1; j < MAX_FRIENDS; j++)
  12782. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12783. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12784. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12785. WFIFOHEAD(fd,packet_len(0x20a));
  12786. WFIFOW(fd,0) = 0x20a;
  12787. WFIFOL(fd,2) = account_id;
  12788. WFIFOL(fd,6) = char_id;
  12789. WFIFOSET(fd, packet_len(0x20a));
  12790. }
  12791. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12792. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12793. void clif_PVPInfo(map_session_data* sd)
  12794. {
  12795. int fd = sd->fd;
  12796. WFIFOHEAD(fd,packet_len(0x210));
  12797. WFIFOW(fd,0) = 0x210;
  12798. WFIFOL(fd,2) = sd->status.char_id;
  12799. WFIFOL(fd,6) = sd->status.account_id;
  12800. WFIFOL(fd,10) = sd->pvp_won; // times won
  12801. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12802. WFIFOL(fd,18) = sd->pvp_point;
  12803. WFIFOSET(fd, packet_len(0x210));
  12804. }
  12805. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12806. /// 020f <char id>.L <account id>.L
  12807. void clif_parse_PVPInfo(int fd,map_session_data *sd)
  12808. {
  12809. // TODO: Is there a way to use this on an another player (char/acc id)?
  12810. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12811. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12812. clif_PVPInfo(sd);
  12813. }
  12814. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12815. /// 0254 <which>.B
  12816. /// which: (unused atm for security purpose)
  12817. /// 0 = sun
  12818. /// 1 = moon
  12819. /// 2 = star
  12820. void clif_parse_FeelSaveOk(int fd,map_session_data *sd)
  12821. {
  12822. int i;
  12823. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12824. if (sd->menuskill_id != SG_FEEL)
  12825. return;
  12826. i = sd->menuskill_val-1;
  12827. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12828. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12829. sd->feel_map[i].m = sd->bl.m;
  12830. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12831. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12832. // clif_misceffect2(&sd->bl, 0x1b0);
  12833. // clif_misceffect2(&sd->bl, 0x21f);
  12834. clif_feel_info(sd, i, 0);
  12835. clif_menuskill_clear(sd);
  12836. }
  12837. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12838. /// 0253 <which>.B
  12839. /// which:
  12840. /// 0 = sun
  12841. /// 1 = moon
  12842. /// 2 = star
  12843. void clif_feel_req(int fd, map_session_data *sd, uint16 skill_lv)
  12844. {
  12845. WFIFOHEAD(fd,packet_len(0x253));
  12846. WFIFOW(fd,0)=0x253;
  12847. WFIFOB(fd,2)=TOB(skill_lv-1);
  12848. WFIFOSET(fd, packet_len(0x253));
  12849. sd->menuskill_id = SG_FEEL;
  12850. sd->menuskill_val = skill_lv;
  12851. }
  12852. /// Request to change homunculus' name (CZ_RENAME_MER).
  12853. /// 0231 <name>.24B
  12854. void clif_parse_ChangeHomunculusName(int fd, map_session_data *sd){
  12855. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12856. }
  12857. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12858. /// 0234 <id>.L
  12859. void clif_parse_HomMoveToMaster(int fd, map_session_data *sd){
  12860. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12861. struct block_list *bl = nullptr;
  12862. struct unit_data *ud = nullptr;
  12863. if( sd->md && sd->md->bl.id == id )
  12864. bl = &sd->md->bl;
  12865. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12866. bl = &sd->hd->bl; // Moving Homunculus
  12867. else
  12868. return;
  12869. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12870. ud = unit_bl2ud(bl);
  12871. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12872. }
  12873. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12874. /// 0232 <id>.L <position data>.3B
  12875. void clif_parse_HomMoveTo(int fd, map_session_data *sd){
  12876. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12877. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12878. struct block_list *bl = nullptr;
  12879. short x, y;
  12880. RFIFOPOS(fd, info->pos[1], &x, &y, nullptr);
  12881. if( sd->md && sd->md->bl.id == id )
  12882. bl = &sd->md->bl; // Moving Mercenary
  12883. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12884. bl = &sd->hd->bl; // Moving Homunculus
  12885. else
  12886. return;
  12887. unit_walktoxy(bl, x, y, 4);
  12888. }
  12889. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12890. /// 0233 <id>.L <target id>.L <action>.B
  12891. /// action:
  12892. /// always 0
  12893. void clif_parse_HomAttack(int fd,map_session_data *sd)
  12894. {
  12895. struct block_list *bl = nullptr;
  12896. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12897. int id = RFIFOL(fd,info->pos[0]);
  12898. int target_id = RFIFOL(fd,info->pos[1]);
  12899. int action_type = RFIFOB(fd,info->pos[2]);
  12900. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12901. bl = &sd->hd->bl;
  12902. else if( sd->md && sd->md->bl.id == id )
  12903. bl = &sd->md->bl;
  12904. else return;
  12905. unit_stop_attack(bl);
  12906. unit_attack(bl, target_id, action_type != 0);
  12907. }
  12908. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12909. /// 022d <type>.W <command>.B
  12910. /// type:
  12911. /// always 0
  12912. /// command:
  12913. /// 0 = homunculus information
  12914. /// 1 = feed
  12915. /// 2 = delete
  12916. void clif_parse_HomMenu(int fd, map_session_data *sd)
  12917. { //[orn]
  12918. int cmd = RFIFOW(fd,0);
  12919. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12920. if(!hom_is_active(sd->hd))
  12921. return;
  12922. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12923. }
  12924. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12925. /// 0292
  12926. void clif_parse_AutoRevive(int fd, map_session_data *sd)
  12927. {
  12928. pc_revive_item(sd);
  12929. }
  12930. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12931. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12932. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12933. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12934. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12935. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12936. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12937. void clif_check(int fd, map_session_data* pl_sd)
  12938. {
  12939. WFIFOHEAD(fd,packet_len(0x214));
  12940. WFIFOW(fd, 0) = 0x214;
  12941. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12942. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12943. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12944. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12945. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12946. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12947. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12948. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12949. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12950. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12951. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12952. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12953. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12954. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12955. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12956. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12957. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12958. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12959. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12960. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12961. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12962. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12963. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12964. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12965. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12966. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12967. WFIFOSET(fd,packet_len(0x214));
  12968. }
  12969. /// /check (CZ_REQ_STATUS_GM).
  12970. /// Request character's status values.
  12971. /// 0213 <char name>.24B
  12972. void clif_parse_Check(int fd, map_session_data *sd)
  12973. {
  12974. char charname[NAME_LENGTH];
  12975. map_session_data* pl_sd;
  12976. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12977. return;
  12978. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12979. if( ( pl_sd = map_nick2sd(charname,false) ) == nullptr || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12980. {
  12981. return;
  12982. }
  12983. clif_check(fd, pl_sd);
  12984. }
  12985. /// MAIL SYSTEM
  12986. /// By Zephyrus
  12987. ///
  12988. /// Notification about the result of adding an item to mail
  12989. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12990. /// result:
  12991. /// 0 = success
  12992. /// 1 = failure
  12993. /// 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)
  12994. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12995. /// result:
  12996. /// 0 = success
  12997. /// 1 = over weight
  12998. /// 2 = fatal error
  12999. void clif_Mail_setattachment( map_session_data* sd, int index, int amount, uint8 flag ){
  13000. int fd = sd->fd;
  13001. #if PACKETVER < 20150513
  13002. WFIFOHEAD(fd,packet_len(0x255));
  13003. WFIFOW(fd,0) = 0x255;
  13004. WFIFOW(fd,2) = index;
  13005. WFIFOB(fd,4) = flag;
  13006. WFIFOSET(fd,packet_len(0x255));
  13007. #else
  13008. struct PACKET_ZC_ACK_ADD_ITEM_RODEX p;
  13009. if( flag ){
  13010. memset( &p, 0, sizeof( p ) );
  13011. }else{
  13012. struct item* item = &sd->inventory.u.items_inventory[server_index(index)];
  13013. p.index = index;
  13014. p.count = amount;
  13015. p.itemId = client_nameid( item->nameid );
  13016. p.type = itemtype( item->nameid );
  13017. p.IsIdentified = item->identify ? 1 : 0;
  13018. p.IsDamaged = item->attribute ? 1 : 0;
  13019. p.refiningLevel = item->refine;
  13020. clif_addcards( &p.slot, item );
  13021. clif_add_random_options( p.optionData, *item );
  13022. p.weight = 0;
  13023. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13024. if( sd->mail.item[i].nameid == 0 ){
  13025. continue;
  13026. }
  13027. p.weight += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13028. }
  13029. p.favorite = ( item->favorite != 0 ) ? 1 : 0;
  13030. p.location = pc_equippoint( sd, server_index( index ) );
  13031. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13032. p.grade = item->enchantgrade;
  13033. #endif
  13034. }
  13035. p.PacketType = HEADER_ZC_ACK_ADD_ITEM_RODEX;
  13036. p.result = flag;
  13037. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  13038. #endif
  13039. }
  13040. /// Notification about the result of retrieving a mail attachment
  13041. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  13042. /// result:
  13043. /// 0 = success
  13044. /// 1 = failure
  13045. /// 2 = too many items
  13046. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  13047. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  13048. void clif_mail_getattachment(map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  13049. #if PACKETVER < 20150513
  13050. int fd = sd->fd;
  13051. WFIFOHEAD(fd,packet_len(0x245));
  13052. WFIFOW(fd,0) = 0x245;
  13053. WFIFOB(fd,2) = result;
  13054. WFIFOSET(fd,packet_len(0x245));
  13055. #else
  13056. switch( type ){
  13057. case MAIL_ATT_ITEM:
  13058. case MAIL_ATT_ZENY:
  13059. break;
  13060. default:
  13061. return;
  13062. }
  13063. PACKET_ZC_ACK_ITEM_FROM_MAIL p = { 0 };
  13064. p.PacketType = type == MAIL_ATT_ZENY ? rodexgetzeny : rodexgetitem;
  13065. p.MailID = msg->id;
  13066. p.opentype = msg->type;
  13067. p.result = result;
  13068. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13069. clif_Mail_refreshinbox( sd, msg->type, 0 );
  13070. #endif
  13071. }
  13072. /// Notification about the result of sending a mail
  13073. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  13074. /// result:
  13075. /// 0 = success
  13076. /// 1 = recipinent does not exist
  13077. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  13078. void clif_Mail_send(map_session_data* sd, enum mail_send_result result){
  13079. #if PACKETVER < 20150513
  13080. int fd = sd->fd;
  13081. WFIFOHEAD(fd,packet_len(0x249));
  13082. WFIFOW(fd,0) = 0x249;
  13083. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  13084. WFIFOSET(fd,packet_len(0x249));
  13085. #else
  13086. PACKET_ZC_WRITE_MAIL_RESULT p = { 0 };
  13087. p.PacketType = rodexwriteresult;
  13088. p.result = result;
  13089. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13090. #endif
  13091. }
  13092. /// Notification about the result of deleting a mail.
  13093. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  13094. /// result:
  13095. /// 0 = success
  13096. /// 1 = failure
  13097. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  13098. void clif_mail_delete( map_session_data* sd, struct mail_message *msg, bool success ){
  13099. #if PACKETVER < 20150513
  13100. int fd = sd->fd;
  13101. WFIFOHEAD(fd, packet_len(0x257));
  13102. WFIFOW(fd,0) = 0x257;
  13103. WFIFOL(fd,2) = msg->id;
  13104. WFIFOW(fd,6) = !success;
  13105. WFIFOSET(fd, packet_len(0x257));
  13106. #else
  13107. // This is only a success notification
  13108. if( success ){
  13109. PACKET_ZC_ACK_DELETE_MAIL p = { 0 };
  13110. p.PacketType = rodexdelete;
  13111. p.opentype = msg->type;
  13112. p.MailID = msg->id;
  13113. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13114. }
  13115. #endif
  13116. }
  13117. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  13118. /// 0274 <mail id>.L <result>.W
  13119. /// result:
  13120. /// 0 = success
  13121. /// 1 = failure
  13122. void clif_Mail_return(int fd, int mail_id, short fail)
  13123. {
  13124. WFIFOHEAD(fd,packet_len(0x274));
  13125. WFIFOW(fd,0) = 0x274;
  13126. WFIFOL(fd,2) = mail_id;
  13127. WFIFOW(fd,6) = fail;
  13128. WFIFOSET(fd,packet_len(0x274));
  13129. }
  13130. /// Notification about new mail.
  13131. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  13132. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  13133. void clif_Mail_new(map_session_data* sd, int mail_id, const char *sender, const char *title){
  13134. #if PACKETVER < 20150513
  13135. int fd = sd->fd;
  13136. WFIFOHEAD(fd,packet_len(0x24a));
  13137. WFIFOW(fd,0) = 0x24a;
  13138. WFIFOL(fd,2) = mail_id;
  13139. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  13140. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  13141. WFIFOSET(fd,packet_len(0x24a));
  13142. #else
  13143. PACKET_ZC_NOTIFY_UNREADMAIL p = { 0 };
  13144. p.PacketType = rodexicon;
  13145. p.result = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  13146. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13147. #endif
  13148. }
  13149. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  13150. /// 0260 <type>.L
  13151. /// type:
  13152. /// 0 = open
  13153. /// 1 = close
  13154. void clif_Mail_window(int fd, int flag)
  13155. {
  13156. WFIFOHEAD(fd,packet_len(0x260));
  13157. WFIFOW(fd,0) = 0x260;
  13158. WFIFOL(fd,2) = flag;
  13159. WFIFOSET(fd,packet_len(0x260));
  13160. }
  13161. /// Lists mails stored in inbox.
  13162. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  13163. /// read:
  13164. /// 0 = unread
  13165. /// 1 = read
  13166. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  13167. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13168. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  13169. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  13170. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  13171. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  13172. void clif_Mail_refreshinbox(map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  13173. #if PACKETVER < 20150513
  13174. int fd = sd->fd;
  13175. struct mail_data *md = &sd->mail.inbox;
  13176. struct mail_message *msg;
  13177. int len, i, j;
  13178. len = 8 + (73 * md->amount);
  13179. WFIFOHEAD(fd,len);
  13180. WFIFOW(fd,0) = 0x240;
  13181. WFIFOW(fd,2) = len;
  13182. WFIFOL(fd,4) = md->amount;
  13183. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  13184. {
  13185. msg = &md->msg[i];
  13186. if (msg->id < 1)
  13187. continue;
  13188. WFIFOL(fd,8+73*j) = msg->id;
  13189. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  13190. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  13191. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  13192. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  13193. j++;
  13194. }
  13195. WFIFOSET(fd,len);
  13196. if( md->full ) {// TODO: is this official?
  13197. char output[100];
  13198. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  13199. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  13200. }
  13201. #else
  13202. int fd = sd->fd;
  13203. struct mail_data *md = &sd->mail.inbox;
  13204. struct mail_message *msg;
  13205. int i, j, k, offset, titleLength;
  13206. uint8 mailType, amount, remaining;
  13207. uint32 now = (uint32)time(nullptr);
  13208. #if PACKETVER >= 20170419
  13209. int cmd = 0xac2;
  13210. #elif PACKETVER >= 20160601
  13211. int cmd = 0xa7d;
  13212. #else
  13213. int cmd = 0x9f0;
  13214. #endif
  13215. if( battle_config.mail_daily_count ){
  13216. mail_refresh_remaining_amount(sd);
  13217. }
  13218. #if PACKETVER >= 20170419
  13219. // Always send all
  13220. i = md->amount;
  13221. #else
  13222. // If a starting mail id was sent
  13223. if( mailID != 0 ){
  13224. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  13225. // Unknown mail
  13226. if( i == md->amount ){
  13227. // Ignore the request for now
  13228. return; // TODO: Should we just show the first page instead?
  13229. }
  13230. // It was actually the oldest/first mail, there is no further page
  13231. if( i == 0 ){
  13232. return;
  13233. }
  13234. // We actually want the next/older mail
  13235. i -= 1;
  13236. }else{
  13237. i = md->amount;
  13238. }
  13239. #endif
  13240. // Count the remaining mails from the starting mail or the beginning
  13241. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  13242. for( j = i, remaining = 0; j >= 0; j-- ){
  13243. msg = &md->msg[j];
  13244. if (msg->id < 1)
  13245. continue;
  13246. #if PACKETVER < 20170419
  13247. if (msg->type != type)
  13248. continue;
  13249. #endif
  13250. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13251. continue;
  13252. remaining++;
  13253. }
  13254. #if PACKETVER >= 20170419
  13255. // Always send all
  13256. amount = remaining;
  13257. #else
  13258. if( remaining > MAIL_PAGE_SIZE ){
  13259. amount = MAIL_PAGE_SIZE;
  13260. }else{
  13261. amount = remaining;
  13262. }
  13263. #endif
  13264. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  13265. WFIFOW(fd, 0) = cmd;
  13266. #if PACKETVER >= 20170419
  13267. WFIFOB(fd, 4) = 1; // Unknown
  13268. offset = 5;
  13269. #else
  13270. WFIFOB(fd, 4) = type;
  13271. WFIFOB(fd, 5) = amount;
  13272. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  13273. offset = 7;
  13274. #endif
  13275. for( amount = 0; i >= 0; i-- ){
  13276. msg = &md->msg[i];
  13277. if (msg->id < 1)
  13278. continue;
  13279. #if PACKETVER < 20170419
  13280. if (msg->type != type)
  13281. continue;
  13282. #endif
  13283. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13284. continue;
  13285. #if PACKETVER >= 20170419
  13286. WFIFOB(fd, offset) = msg->type;
  13287. offset += 1;
  13288. #endif
  13289. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13290. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13291. mailType = MAIL_TYPE_TEXT; // Normal letter
  13292. if( msg->zeny > 0 ){
  13293. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13294. }
  13295. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13296. if( msg->item[k].nameid > 0 ){
  13297. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13298. break;
  13299. }
  13300. }
  13301. #if PACKETVER >= 20170419
  13302. // If it came from an npc?
  13303. if( !msg->send_id ){
  13304. mailType |= MAIL_TYPE_NPC;
  13305. }
  13306. #endif
  13307. WFIFOB(fd, offset + 9) = mailType;
  13308. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13309. #if PACKETVER < 20170419
  13310. // How much time has passed since you received the mail
  13311. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13312. offset += 4;
  13313. #endif
  13314. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13315. if( msg->scheduled_deletion > 0 ){
  13316. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13317. }else{
  13318. // Fake the scheduled deletion to one year in the future
  13319. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13320. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13321. }
  13322. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13323. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13324. offset += 40 + titleLength;
  13325. }
  13326. WFIFOW(fd, 2) = (int16)offset;
  13327. WFIFOSET(fd, offset);
  13328. #endif
  13329. }
  13330. /// Mail inbox list request.
  13331. /// 023f (CZ_MAIL_GET_LIST)
  13332. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13333. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13334. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13335. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13336. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13337. void clif_parse_Mail_refreshinbox(int fd, map_session_data *sd){
  13338. if( mail_invalid_operation( sd ) ){
  13339. return;
  13340. }
  13341. #if PACKETVER < 20150513
  13342. struct mail_data* md = &sd->mail.inbox;
  13343. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13344. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13345. else
  13346. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13347. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13348. mail_removezeny(sd, false);
  13349. #else
  13350. int cmd = RFIFOW(fd, 0);
  13351. #if PACKETVER < 20170419
  13352. uint8 openType = RFIFOB(fd, 2);
  13353. uint64 mailId = RFIFOQ(fd, 3);
  13354. #else
  13355. uint8 openType;
  13356. uint64 mailId = RFIFOQ(fd, 2);
  13357. int i;
  13358. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13359. if( i == MAIL_MAX_INBOX ){
  13360. openType = MAIL_INBOX_NORMAL;
  13361. mailId = 0;
  13362. }else{
  13363. openType = sd->mail.inbox.msg[i].type;
  13364. mailId = 0;
  13365. }
  13366. #endif
  13367. switch( openType ){
  13368. case MAIL_INBOX_NORMAL:
  13369. case MAIL_INBOX_ACCOUNT:
  13370. case MAIL_INBOX_RETURNED:
  13371. break;
  13372. default:
  13373. // Unknown type: ignore request
  13374. return;
  13375. }
  13376. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13377. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13378. return;
  13379. }
  13380. // If it is not a next page request
  13381. if( cmd != 0x9ee ){
  13382. mailId = 0;
  13383. }
  13384. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13385. #endif
  13386. }
  13387. /// Opens a mail
  13388. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13389. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13390. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13391. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13392. /// { }*n
  13393. // TODO: Packet description => for repeated block
  13394. void clif_Mail_read( map_session_data *sd, int mail_id ){
  13395. int i, fd = sd->fd;
  13396. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13397. if( i == MAIL_MAX_INBOX ) {
  13398. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13399. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13400. return;
  13401. } else {
  13402. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13403. struct item *item;
  13404. int16 msg_len;
  13405. msg_len = static_cast<decltype(msg_len)>( strlen(msg->body) );
  13406. if( msg_len == 0 ) {
  13407. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13408. msg_len = static_cast<decltype(msg_len)>( strlen(msg->body) );
  13409. }
  13410. #if PACKETVER < 20150513
  13411. item = &msg->item[0];
  13412. int16 len = 101 + msg_len;
  13413. WFIFOHEAD(fd,len);
  13414. WFIFOW(fd,0) = 0x242;
  13415. WFIFOW(fd,2) = len;
  13416. WFIFOL(fd,4) = msg->id;
  13417. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13418. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13419. WFIFOL(fd,72) = 0;
  13420. WFIFOL(fd,76) = msg->zeny;
  13421. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13422. if( item->nameid && data != nullptr ) {
  13423. WFIFOL(fd,80) = item->amount;
  13424. WFIFOW(fd,84) = client_nameid( item->nameid );
  13425. WFIFOW(fd,86) = itemtype( item->nameid );
  13426. WFIFOB(fd,88) = item->identify;
  13427. WFIFOB(fd,89) = item->attribute;
  13428. WFIFOB(fd,90) = item->refine;
  13429. WFIFOW(fd,91) = item->card[0];
  13430. WFIFOW(fd,93) = item->card[1];
  13431. WFIFOW(fd,95) = item->card[2];
  13432. WFIFOW(fd,97) = item->card[3];
  13433. } else // no item, set all to zero
  13434. memset(WFIFOP(fd,80), 0x00, 19);
  13435. WFIFOB(fd,99) = (unsigned char)msg_len;
  13436. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13437. WFIFOSET(fd,len);
  13438. #else
  13439. msg_len += 1; // Zero Termination
  13440. PACKET_ZC_ACK_READ_RODEX* p = reinterpret_cast<PACKET_ZC_ACK_READ_RODEX*>( packet_buffer );
  13441. p->PacketType = HEADER_ZC_ACK_READ_RODEX;
  13442. p->PacketLength = sizeof( *p );
  13443. p->opentype = msg->type;
  13444. p->MailID = msg->id;
  13445. p->TextcontentsLength = static_cast<decltype(p->TextcontentsLength)>( msg_len );
  13446. p->zeny = msg->zeny;
  13447. safestrncpy( WBUFCP( p, p->PacketLength ), msg->body, msg_len );
  13448. p->PacketLength += p->TextcontentsLength;
  13449. p->ItemCnt = 0;
  13450. for( int j = 0; j < MAIL_MAX_ITEM; j++ ){
  13451. item = &msg->item[j];
  13452. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13453. if( item->nameid > 0 && item->amount > 0 && data != nullptr ){
  13454. PACKET_ZC_ACK_READ_RODEX_SUB* mailitem = reinterpret_cast<PACKET_ZC_ACK_READ_RODEX_SUB*>( WBUFP( p, p->PacketLength ) );
  13455. mailitem->ITID = client_nameid( item->nameid );
  13456. mailitem->count = item->amount;
  13457. mailitem->type = itemtype( item->nameid );
  13458. mailitem->IsIdentified = item->identify ? 1 : 0;
  13459. mailitem->IsDamaged = item->attribute ? 1 : 0;
  13460. mailitem->refiningLevel = item->refine;
  13461. mailitem->location = pc_equippoint_sub( sd, data.get() );
  13462. mailitem->viewSprite = data->look;
  13463. mailitem->bindOnEquip = item->bound ? 2 : data->flag.bindOnEquip ? 1 : 0;
  13464. clif_addcards( &mailitem->slot, item );
  13465. clif_add_random_options( mailitem->option_data, *item );
  13466. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  13467. mailitem->grade = item->enchantgrade;
  13468. #endif
  13469. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( *mailitem ) );
  13470. p->ItemCnt++;
  13471. }
  13472. }
  13473. clif_send( p, p->PacketLength, &sd->bl, SELF );
  13474. #endif
  13475. if (msg->status == MAIL_UNREAD) {
  13476. msg->status = MAIL_READ;
  13477. intif_Mail_read(mail_id);
  13478. clif_parse_Mail_refreshinbox(fd, sd);
  13479. sd->mail.inbox.unread--;
  13480. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13481. }
  13482. }
  13483. }
  13484. /// Request to open a mail.
  13485. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13486. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13487. void clif_parse_Mail_read(int fd, map_session_data *sd){
  13488. #if PACKETVER < 20150513
  13489. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13490. #else
  13491. //uint8 openType = RFIFOB(fd, 2);
  13492. int mail_id = (int)RFIFOQ(fd, 3);
  13493. #endif
  13494. if( mail_id <= 0 )
  13495. return;
  13496. if( mail_invalid_operation(sd) )
  13497. return;
  13498. clif_Mail_read(sd, mail_id);
  13499. }
  13500. /// Allow a player to begin writing a mail
  13501. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13502. void clif_send_Mail_beginwrite_ack( map_session_data *sd, char* name, bool success ){
  13503. PACKET_ZC_ACK_OPEN_WRITE_MAIL p = { 0 };
  13504. p.PacketType = rodexopenwrite;
  13505. safestrncpy(p.receiveName, name, NAME_LENGTH);
  13506. p.result = success;
  13507. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13508. }
  13509. /// Request to start writing a mail
  13510. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13511. void clif_parse_Mail_beginwrite( int fd, map_session_data *sd ){
  13512. char name[NAME_LENGTH];
  13513. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13514. if( mail_invalid_operation( sd ) ){
  13515. return;
  13516. }
  13517. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13518. clif_send_Mail_beginwrite_ack(sd, name, false);
  13519. return;
  13520. }
  13521. mail_clear(sd);
  13522. sd->state.mail_writing = true;
  13523. clif_send_Mail_beginwrite_ack(sd, name,true);
  13524. }
  13525. /// Notification that the client cancelled writing a mail
  13526. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13527. void clif_parse_Mail_cancelwrite( int fd, map_session_data *sd ){
  13528. sd->state.mail_writing = false;
  13529. }
  13530. /// Give the client information about the recipient, if available
  13531. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13532. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13533. void clif_Mail_Receiver_Ack( map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13534. #if PACKETVER >= 20141119
  13535. PACKET_ZC_CHECKNAME p = { 0 };
  13536. p.PacketType = HEADER_ZC_CHECKNAME;
  13537. p.CharId = char_id;
  13538. p.Class = class_;
  13539. p.BaseLevel = level;
  13540. #if PACKETVER >= 20160302
  13541. strncpy(p.Name, name, NAME_LENGTH);
  13542. #endif
  13543. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13544. #endif
  13545. }
  13546. /// Request information about the recipient
  13547. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13548. void clif_parse_Mail_Receiver_Check(int fd, map_session_data *sd) {
  13549. #if PACKETVER >= 20140423
  13550. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13551. struct PACKET_CZ_CHECKNAME2* p = (struct PACKET_CZ_CHECKNAME2*)RFIFOP( fd, 0 );
  13552. #else
  13553. struct PACKET_CZ_CHECKNAME1* p = (struct PACKET_CZ_CHECKNAME1*)RFIFOP( fd, 0 );
  13554. #endif
  13555. static char name[NAME_LENGTH];
  13556. if( mail_invalid_operation( sd ) ){
  13557. return;
  13558. }
  13559. safestrncpy(name, p->Name, NAME_LENGTH);
  13560. intif_mail_checkreceiver(sd, name);
  13561. #endif
  13562. }
  13563. /// Request to receive mail's attachment.
  13564. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13565. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13566. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13567. void clif_parse_Mail_getattach( int fd, map_session_data *sd ){
  13568. int i;
  13569. struct mail_message* msg;
  13570. #if PACKETVER < 20150513
  13571. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13572. int attachment = MAIL_ATT_ALL;
  13573. #else
  13574. uint16 packet_id = RFIFOW(fd, 0);
  13575. int mail_id = (int)RFIFOQ(fd, 2);
  13576. //int openType = RFIFOB(fd, 10);
  13577. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13578. #endif
  13579. if( !chrif_isconnected() )
  13580. return;
  13581. if( mail_id <= 0 )
  13582. return;
  13583. if( mail_invalid_operation(sd) )
  13584. return;
  13585. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13586. if( i == MAIL_MAX_INBOX )
  13587. return;
  13588. msg = &sd->mail.inbox.msg[i];
  13589. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13590. attachment &= ~MAIL_ATT_ZENY;
  13591. }
  13592. if( attachment&MAIL_ATT_ITEM ){
  13593. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13594. // No items were found
  13595. if( i == MAIL_MAX_ITEM ){
  13596. attachment &= ~MAIL_ATT_ITEM;
  13597. }
  13598. }
  13599. // Either no attachment requested at all or there are no zeny or items in the mail
  13600. if( attachment == MAIL_ATT_NONE ){
  13601. return;
  13602. }
  13603. if( attachment&MAIL_ATT_ZENY ){
  13604. if( ( msg->zeny + sd->status.zeny + sd->mail.pending_zeny ) > MAX_ZENY ){
  13605. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13606. return;
  13607. }else{
  13608. // Store the pending zeny (required for the "retrieve all" feature)
  13609. sd->mail.pending_zeny += msg->zeny;
  13610. // To make sure another request fails
  13611. msg->zeny = 0;
  13612. }
  13613. }
  13614. if( attachment&MAIL_ATT_ITEM ){
  13615. int slots = 0, totalweight = 0;
  13616. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13617. struct item* item = &msg->item[i];
  13618. if( item->nameid > 0 && item->amount > 0 ){
  13619. std::shared_ptr<item_data> data = item_db.find(item->nameid);
  13620. if(data == nullptr)
  13621. continue;
  13622. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13623. case CHKADDITEM_NEW:
  13624. slots += data->inventorySlotNeeded( item->amount );
  13625. break;
  13626. case CHKADDITEM_OVERAMOUNT:
  13627. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13628. return;
  13629. }
  13630. totalweight += data->weight * item->amount;
  13631. }
  13632. }
  13633. if( ( totalweight + sd->weight + sd->mail.pending_weight ) > sd->max_weight ){
  13634. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13635. return;
  13636. }else if( pc_inventoryblank(sd) < ( slots + sd->mail.pending_slots ) ){
  13637. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13638. return;
  13639. }
  13640. // To make sure another request fails
  13641. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13642. // Store the pending weight (required for the "retrieve all" feature)
  13643. sd->mail.pending_weight += totalweight;
  13644. // Store the pending slots (required for the "retrieve all" feature)
  13645. sd->mail.pending_slots += slots;
  13646. }
  13647. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13648. }
  13649. /// Request to delete a mail.
  13650. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13651. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13652. void clif_parse_Mail_delete(int fd, map_session_data *sd){
  13653. #if PACKETVER < 20150513
  13654. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13655. #else
  13656. //int openType = RFIFOB(fd, 2);
  13657. int mail_id = (int)RFIFOQ(fd, 3);
  13658. #endif
  13659. int i, j;
  13660. if( !chrif_isconnected() )
  13661. return;
  13662. if( mail_id <= 0 )
  13663. return;
  13664. if( mail_invalid_operation(sd) )
  13665. return;
  13666. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13667. if (i < MAIL_MAX_INBOX) {
  13668. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13669. // can't delete mail without removing zeny first
  13670. if( msg->zeny > 0 ){
  13671. clif_mail_delete(sd, msg, false);
  13672. return;
  13673. }
  13674. // can't delete mail without removing attachment(s) first
  13675. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13676. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13677. clif_mail_delete(sd, msg, false);
  13678. return;
  13679. }
  13680. }
  13681. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13682. sd->mail.inbox.unread--;
  13683. clif_Mail_new(sd,0,nullptr,nullptr);
  13684. }
  13685. }
  13686. }
  13687. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13688. /// 0273 <mail id>.L <receive name>.24B
  13689. void clif_parse_Mail_return(int fd, map_session_data *sd){
  13690. #if PACKETVER_MAIN_NUM >= 20201104 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20201118
  13691. struct PACKET_CZ_RODEX_RETURN* p = (struct PACKET_CZ_RODEX_RETURN*)RFIFOP( fd, 0 );
  13692. //ShowDump( p, sizeof( p ) );
  13693. int mail_id = p->msgId;
  13694. // not supported for now
  13695. return;
  13696. #else
  13697. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13698. #endif
  13699. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13700. int i;
  13701. if( mail_id <= 0 )
  13702. return;
  13703. if( mail_invalid_operation(sd) )
  13704. return;
  13705. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13706. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13707. intif_Mail_return(sd->status.char_id, mail_id);
  13708. else
  13709. clif_Mail_return(sd->fd, mail_id, 1);
  13710. }
  13711. /// Request to add an item or Zeny to mail.
  13712. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13713. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13714. void clif_parse_Mail_setattach(int fd, map_session_data *sd){
  13715. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13716. uint16 idx = RFIFOW(fd,info->pos[0]);
  13717. #if PACKETVER < 20150513
  13718. int amount = RFIFOL(fd,info->pos[1]);
  13719. #else
  13720. int amount = RFIFOW(fd,info->pos[1]);
  13721. #endif
  13722. unsigned char flag;
  13723. if( !chrif_isconnected() )
  13724. return;
  13725. if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
  13726. return;
  13727. if (sd->inventory_data[server_index(idx)] == nullptr)
  13728. return;
  13729. if( mail_invalid_operation( sd ) ){
  13730. return;
  13731. }
  13732. flag = mail_setitem(sd, idx, amount);
  13733. if( flag == MAIL_ATTACH_EQUIPSWITCH ){
  13734. clif_msg( sd, MSI_SWAP_EQUIPITEM_UNREGISTER_FIRST );
  13735. }else{
  13736. clif_Mail_setattachment(sd,idx,amount,flag);
  13737. }
  13738. }
  13739. /// Remove an item from a mail
  13740. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13741. void clif_mail_removeitem( map_session_data* sd, bool success, int index, int amount ){
  13742. PACKET_ZC_ACK_REMOVE_ITEM_MAIL p = { 0 };
  13743. p.PacketType = rodexremoveitem;
  13744. p.result = success;
  13745. p.index = index;
  13746. p.cnt = amount;
  13747. int total = 0;
  13748. for( int i = 0; i < MAIL_MAX_ITEM; i++ ){
  13749. if( sd->mail.item[i].nameid == 0 ){
  13750. break;
  13751. }
  13752. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  13753. }
  13754. p.weight = total;
  13755. clif_send(&p, sizeof(p), &sd->bl, SELF);
  13756. }
  13757. /// Request to reset mail item and/or Zeny
  13758. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13759. /// type:
  13760. /// 0 = reset all
  13761. /// 1 = remove item
  13762. /// 2 = remove zeny
  13763. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13764. void clif_parse_Mail_winopen(int fd, map_session_data *sd)
  13765. {
  13766. #if PACKETVER < 20150513
  13767. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13768. if (type == 0 || type == 1)
  13769. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13770. if (type == 0 || type == 2)
  13771. mail_removezeny(sd, false);
  13772. #else
  13773. uint16 index = RFIFOW(fd, 2);
  13774. uint16 count = RFIFOW(fd, 4);
  13775. mail_removeitem(sd,0,index,count);
  13776. #endif
  13777. }
  13778. /// Request to send mail
  13779. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13780. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13781. /// 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)
  13782. void clif_parse_Mail_send(int fd, map_session_data *sd){
  13783. #if PACKETVER < 20150513
  13784. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13785. if( !chrif_isconnected() )
  13786. return;
  13787. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13788. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13789. return;
  13790. }
  13791. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13792. #else
  13793. uint16 length = RFIFOW(fd, 2);
  13794. if( length < 0x3e ){
  13795. ShowWarning("Too short...\n");
  13796. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13797. return;
  13798. }
  13799. if( mail_invalid_operation( sd ) ){
  13800. return;
  13801. }
  13802. // Forged request without a begin writing packet?
  13803. if( !sd->state.mail_writing ){
  13804. return; // Ignore it
  13805. }
  13806. char receiver[NAME_LENGTH];
  13807. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13808. // char sender[NAME_LENGTH];
  13809. // safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13810. uint64 zeny = RFIFOQ(fd, 52);
  13811. uint16 titleLength = RFIFOW(fd, 60);
  13812. uint16 textLength = RFIFOW(fd, 62);
  13813. uint16 realTitleLength = min(titleLength, MAIL_TITLE_LENGTH);
  13814. uint16 realTextLength = min(textLength, MAIL_BODY_LENGTH);
  13815. char title[MAIL_TITLE_LENGTH];
  13816. char text[MAIL_BODY_LENGTH];
  13817. #if PACKETVER <= 20160330
  13818. safestrncpy(title, RFIFOCP(fd, 64), realTitleLength);
  13819. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), realTextLength);
  13820. #else
  13821. // 64 = <char id>.L
  13822. safestrncpy(title, RFIFOCP(fd, 68), realTitleLength);
  13823. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), realTextLength);
  13824. #endif
  13825. if( zeny > 0 ){
  13826. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13827. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13828. return;
  13829. }
  13830. }
  13831. mail_send(sd, receiver, title, text, realTextLength);
  13832. #endif
  13833. }
  13834. /// AUCTION SYSTEM
  13835. /// By Zephyrus
  13836. ///
  13837. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13838. /// 025f <type>.L
  13839. /// type:
  13840. /// 0 = open
  13841. /// 1 = close
  13842. void clif_Auction_openwindow(map_session_data *sd)
  13843. {
  13844. int fd = sd->fd;
  13845. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13846. return;
  13847. if( !battle_config.feature_auction )
  13848. return;
  13849. WFIFOHEAD(fd,packet_len(0x25f));
  13850. WFIFOW(fd,0) = 0x25f;
  13851. WFIFOL(fd,2) = 0;
  13852. WFIFOSET(fd,packet_len(0x25f));
  13853. }
  13854. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13855. /// 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 }*
  13856. void clif_Auction_results(map_session_data *sd, short count, short pages, uint8 *buf)
  13857. {
  13858. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13859. struct auction_data auction;
  13860. WFIFOHEAD(fd,12 + (count * 83));
  13861. WFIFOW(fd,0) = 0x252;
  13862. WFIFOW(fd,2) = 12 + (count * 83);
  13863. WFIFOL(fd,4) = pages;
  13864. WFIFOL(fd,8) = count;
  13865. for( i = 0; i < count; i++ ) {
  13866. int k = 12 + (i * 83);
  13867. memcpy(&auction, RBUFP(buf,i * len), len);
  13868. WFIFOL(fd,k) = auction.auction_id;
  13869. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13870. WFIFOW(fd,28+k) = client_nameid( auction.item.nameid );
  13871. WFIFOL(fd,30+k) = auction.type;
  13872. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13873. WFIFOB(fd,36+k) = auction.item.identify;
  13874. WFIFOB(fd,37+k) = auction.item.attribute;
  13875. WFIFOB(fd,38+k) = auction.item.refine;
  13876. WFIFOW(fd,39+k) = auction.item.card[0];
  13877. WFIFOW(fd,41+k) = auction.item.card[1];
  13878. WFIFOW(fd,43+k) = auction.item.card[2];
  13879. WFIFOW(fd,45+k) = auction.item.card[3];
  13880. WFIFOL(fd,47+k) = auction.price;
  13881. WFIFOL(fd,51+k) = auction.buynow;
  13882. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13883. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13884. }
  13885. WFIFOSET(fd,WFIFOW(fd,2));
  13886. }
  13887. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13888. /// 0256 <index>.W <result>.B
  13889. /// result:
  13890. /// 0 = success
  13891. /// 1 = failure
  13892. static void clif_Auction_setitem(int fd, int index, bool fail)
  13893. {
  13894. WFIFOHEAD(fd,packet_len(0x256));
  13895. WFIFOW(fd,0) = 0x256;
  13896. WFIFOW(fd,2) = index;
  13897. WFIFOB(fd,4) = fail;
  13898. WFIFOSET(fd,packet_len(0x256));
  13899. }
  13900. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13901. /// 024b <type>.W
  13902. /// type:
  13903. /// 0 = create (any other action in auction window)
  13904. /// 1 = cancel (cancel pressed on register tab)
  13905. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13906. void clif_parse_Auction_cancelreg(int fd, map_session_data *sd){
  13907. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13908. if( sd->auction.amount > 0 )
  13909. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13910. sd->auction.amount = 0;
  13911. }
  13912. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13913. /// 024c <index>.W <count>.L
  13914. void clif_parse_Auction_setitem(int fd, map_session_data *sd){
  13915. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13916. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13917. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13918. if( !battle_config.feature_auction )
  13919. return;
  13920. if( sd->auction.amount > 0 )
  13921. sd->auction.amount = 0;
  13922. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13923. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13924. return;
  13925. }
  13926. 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.
  13927. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13928. return;
  13929. }
  13930. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[idx].nameid);
  13931. 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) )
  13932. { // Consumable or pets are not allowed
  13933. clif_Auction_setitem(sd->fd, idx, true);
  13934. return;
  13935. }
  13936. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13937. !sd->inventory.u.items_inventory[idx].identify ||
  13938. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13939. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13940. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13941. clif_Auction_setitem(sd->fd, idx, true);
  13942. return;
  13943. }
  13944. sd->auction.index = idx;
  13945. sd->auction.amount = amount;
  13946. clif_Auction_setitem(fd, idx + 2, false);
  13947. }
  13948. /// Result from an auction action (ZC_AUCTION_RESULT).
  13949. /// 0250 <result>.B
  13950. /// result:
  13951. /// 0 = You have failed to bid into the auction
  13952. /// 1 = You have successfully bid in the auction
  13953. /// 2 = The auction has been canceled
  13954. /// 3 = An auction with at least one bidder cannot be canceled
  13955. /// 4 = You cannot register more than 5 items in an auction at a time
  13956. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13957. /// 6 = You have won the auction
  13958. /// 7 = You have failed to win the auction
  13959. /// 8 = You do not have enough Zeny
  13960. /// 9 = You cannot place more than 5 bids at a time
  13961. void clif_Auction_message(int fd, unsigned char flag)
  13962. {
  13963. WFIFOHEAD(fd,packet_len(0x250));
  13964. WFIFOW(fd,0) = 0x250;
  13965. WFIFOB(fd,2) = flag;
  13966. WFIFOSET(fd,packet_len(0x250));
  13967. }
  13968. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13969. /// 025e <result>.W
  13970. /// result:
  13971. /// 0 = You have ended the auction
  13972. /// 1 = You cannot end the auction
  13973. /// 2 = Auction ID is incorrect
  13974. void clif_Auction_close(int fd, unsigned char flag)
  13975. {
  13976. WFIFOHEAD(fd,packet_len(0x25e));
  13977. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13978. WFIFOW(fd,2) = flag;
  13979. WFIFOSET(fd,packet_len(0x25e));
  13980. }
  13981. /// Request to add an auction (CZ_AUCTION_ADD).
  13982. /// 024d <now money>.L <max money>.L <delete hour>.W
  13983. void clif_parse_Auction_register(int fd, map_session_data *sd)
  13984. {
  13985. struct auction_data auction;
  13986. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13987. if( !battle_config.feature_auction )
  13988. return;
  13989. auction.price = RFIFOL(fd,info->pos[0]);
  13990. auction.buynow = RFIFOL(fd,info->pos[1]);
  13991. auction.hours = RFIFOW(fd,info->pos[2]);
  13992. // Invalid Situations...
  13993. if( sd->auction.amount < 1 ) {
  13994. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13995. return;
  13996. }
  13997. if( auction.price >= auction.buynow ) {
  13998. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13999. return;
  14000. }
  14001. if( auction.hours < 1 || auction.hours > 48 ) {
  14002. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  14003. return;
  14004. }
  14005. // Auction checks...
  14006. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  14007. clif_displaymessage(sd->fd, msg_txt(sd,293));
  14008. clif_Auction_message(fd, 2); // The auction has been canceled
  14009. return;
  14010. }
  14011. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  14012. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  14013. return;
  14014. }
  14015. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  14016. auction.buynow = battle_config.auction_maximumprice;
  14017. if( auction.price >= auction.buynow )
  14018. auction.price = auction.buynow - 1;
  14019. }
  14020. auction.auction_id = 0;
  14021. auction.seller_id = sd->status.char_id;
  14022. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  14023. auction.buyer_id = 0;
  14024. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  14025. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  14026. {
  14027. clif_Auction_message(fd, 2); // The auction has been canceled
  14028. return;
  14029. }
  14030. std::shared_ptr<item_data> id = item_db.find(sd->inventory.u.items_inventory[sd->auction.index].nameid);
  14031. if( id == nullptr )
  14032. { // Just in case
  14033. clif_Auction_message(fd, 2); // The auction has been canceled
  14034. return;
  14035. }
  14036. safestrncpy(auction.item_name, id->ename.c_str(), sizeof(auction.item_name));
  14037. auction.type = id->type;
  14038. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  14039. auction.item.amount = 1;
  14040. auction.timestamp = 0;
  14041. if( !intif_Auction_register(&auction) )
  14042. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  14043. else
  14044. {
  14045. int zeny = auction.hours*battle_config.auction_feeperhour;
  14046. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  14047. sd->auction.amount = 0;
  14048. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION);
  14049. }
  14050. }
  14051. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  14052. /// 024e <auction id>.L
  14053. void clif_parse_Auction_cancel(int fd, map_session_data *sd){
  14054. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14055. intif_Auction_cancel(sd->status.char_id, auction_id);
  14056. }
  14057. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  14058. /// 025d <auction id>.L
  14059. void clif_parse_Auction_close(int fd, map_session_data *sd){
  14060. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14061. intif_Auction_close(sd->status.char_id, auction_id);
  14062. }
  14063. /// Places a bid on an auction (CZ_AUCTION_BUY).
  14064. /// 024f <auction id>.L <money>.L
  14065. void clif_parse_Auction_bid(int fd, map_session_data *sd){
  14066. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14067. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  14068. int bid = RFIFOL(fd,info->pos[1]);
  14069. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  14070. clif_displaymessage(sd->fd, msg_txt(sd,246));
  14071. return;
  14072. }
  14073. if( bid <= 0 )
  14074. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14075. else if( bid > sd->status.zeny )
  14076. clif_Auction_message(fd, 8); // You do not have enough zeny
  14077. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  14078. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  14079. else {
  14080. pc_payzeny(sd, bid, LOG_TYPE_AUCTION);
  14081. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  14082. }
  14083. }
  14084. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  14085. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  14086. /// search type:
  14087. /// 0 = armor
  14088. /// 1 = weapon
  14089. /// 2 = card
  14090. /// 3 = misc
  14091. /// 4 = name search
  14092. /// 5 = auction id search
  14093. void clif_parse_Auction_search(int fd, map_session_data* sd){
  14094. char search_text[NAME_LENGTH];
  14095. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14096. short type = RFIFOW(fd,info->pos[0]);
  14097. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  14098. int page = RFIFOW(fd,info->pos[3]);
  14099. if( !battle_config.feature_auction )
  14100. return;
  14101. clif_parse_Auction_cancelreg(fd, sd);
  14102. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  14103. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  14104. }
  14105. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  14106. /// 025c <type>.W
  14107. /// type:
  14108. /// 0 = sell (own auctions)
  14109. /// 1 = buy (own bids)
  14110. void clif_parse_Auction_buysell(int fd, map_session_data* sd)
  14111. {
  14112. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  14113. if( !battle_config.feature_auction )
  14114. return;
  14115. clif_parse_Auction_cancelreg(fd, sd);
  14116. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  14117. }
  14118. /// CASH/POINT SHOP
  14119. ///
  14120. void clif_cashshop_open( map_session_data* sd, int tab ){
  14121. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14122. nullpo_retv( sd );
  14123. struct PACKET_ZC_SE_CASHSHOP_OPEN p;
  14124. p.packetType = HEADER_ZC_SE_CASHSHOP_OPEN;
  14125. p.cashPoints = sd->cashPoints;
  14126. p.kafraPoints = sd->kafraPoints;
  14127. #if PACKETVER_MAIN_NUM >= 20200129 || PACKETVER_RE_NUM >= 20200205 || PACKETVER_ZERO_NUM >= 20191224
  14128. p.tab = tab;
  14129. #endif
  14130. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  14131. #endif
  14132. }
  14133. void clif_parse_cashshop_open_request( int fd, map_session_data* sd ){
  14134. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14135. nullpo_retv( sd );
  14136. int tab = 0;
  14137. #if PACKETVER >= 20191224
  14138. struct PACKET_CZ_SE_CASHSHOP_OPEN2* p = (struct PACKET_CZ_SE_CASHSHOP_OPEN2*)RFIFOP( fd, 0 );
  14139. tab = p->tab;
  14140. #endif
  14141. if (map_getmapflag(sd->bl.m, MF_NOCASHSHOP)) {
  14142. clif_displaymessage(fd, msg_txt(sd, 451)); // Cash Shop is disabled on this map.
  14143. return;
  14144. }
  14145. sd->state.cashshop_open = true;
  14146. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14147. clif_cashshop_open( sd, tab );
  14148. #endif
  14149. }
  14150. void clif_parse_cashshop_close( int fd, map_session_data* sd ){
  14151. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined(PACKETVER_ZERO)
  14152. sd->state.cashshop_open = false;
  14153. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  14154. // No need to do anything here
  14155. #endif
  14156. }
  14157. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  14158. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  14159. void clif_parse_CashShopReqTab(int fd, map_session_data *sd) {
  14160. #if PACKETVER_MAIN_NUM >= 20100824 || PACKETVER_RE_NUM >= 20100824 || defined(PACKETVER_ZERO)
  14161. PACKET_CZ_REQ_SE_CASH_TAB_CODE* p_in = reinterpret_cast<PACKET_CZ_REQ_SE_CASH_TAB_CODE*>( RFIFOP( fd, 0 ) );
  14162. // TODO: most likely wrong answer packet. Most likely HEADER_ZC_ACK_SE_CASH_ITEM_LIST (0x847) would be correct [Lemongrass]
  14163. // [4144] packet exists only in 2011 and was dropped after
  14164. #if PACKETVER >= 20110222 && PACKETVER < 20120000
  14165. std::shared_ptr<s_cash_item_tab> tab = cash_shop_db.find( static_cast<e_cash_shop_tab>( p_in->tab ) );
  14166. if( tab == nullptr ){
  14167. return;
  14168. }
  14169. // Skip empty tabs, the client only expects filled ones
  14170. if( tab->items.empty() ){
  14171. return;
  14172. }
  14173. #if !(PACKETVER_SUPPORTS_SALES)
  14174. if( tab->tab == CASHSHOP_TAB_SALE ){
  14175. return;
  14176. }
  14177. #endif
  14178. PACKET_ZC_ACK_SE_CASH_ITEM_LIST2* p = reinterpret_cast<PACKET_ZC_ACK_SE_CASH_ITEM_LIST2*>( packet_buffer );
  14179. p->packetType = HEADER_ZC_ACK_SE_CASH_ITEM_LIST2;
  14180. p->packetLength = sizeof( *p );
  14181. p->tab = tab->tab;
  14182. p->count = 0;
  14183. for( std::shared_ptr<s_cash_item> item : tab->items ){
  14184. p->items[p->count].itemId = client_nameid( item->nameid );
  14185. p->items[p->count].price = item->price;
  14186. p->packetLength += static_cast<decltype>(p->packetLength)>( sizeof( p->items[0] ) );
  14187. p->count++;
  14188. }
  14189. clif_send( p, p->packetLength, &sd->bl, SELF );
  14190. #endif
  14191. #endif
  14192. }
  14193. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  14194. void clif_cashshop_list( map_session_data& sd ){
  14195. for( const auto& pair : cash_shop_db ){
  14196. std::shared_ptr<s_cash_item_tab> tab = pair.second;
  14197. // Skip empty tabs, the client only expects filled ones
  14198. if( tab->items.empty() ){
  14199. continue;
  14200. }
  14201. #if !(PACKETVER_SUPPORTS_SALES)
  14202. if( tab->tab == CASHSHOP_TAB_SALE ){
  14203. continue;
  14204. }
  14205. #endif
  14206. PACKET_ZC_ACK_SCHEDULER_CASHITEM* p = reinterpret_cast<PACKET_ZC_ACK_SCHEDULER_CASHITEM*>( packet_buffer );
  14207. p->packetType = HEADER_ZC_ACK_SCHEDULER_CASHITEM;
  14208. p->packetLength = sizeof( *p );
  14209. p->count = 0;
  14210. p->tabNum = tab->tab;
  14211. for( std::shared_ptr<s_cash_item> item : tab->items ){
  14212. p->items[p->count].itemId = client_nameid( item->nameid );
  14213. p->items[p->count].price = item->price;
  14214. #ifdef ENABLE_CASHSHOP_PREVIEW_PATCH
  14215. struct item_data* id = itemdb_search( item->nameid );
  14216. if( id == nullptr ){
  14217. p->items[p->count].location = 0;
  14218. p->items[p->count].viewSprite = 0;
  14219. }else{
  14220. p->items[p->count].location = pc_equippoint_sub( &sd, id );
  14221. p->items[p->count].viewSprite = id->look;
  14222. }
  14223. #endif
  14224. p->count++;
  14225. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  14226. if( ( static_cast<size_t>( p->packetLength ) + sizeof( p->items[0] ) ) >= INT16_MAX ){
  14227. // Send current data
  14228. clif_send( p, p->packetLength, &sd.bl, SELF );
  14229. // Start a new packet
  14230. p->count = 0;
  14231. p->packetLength = sizeof( *p );
  14232. }
  14233. }
  14234. clif_send( p, p->packetLength, &sd.bl, SELF );
  14235. }
  14236. }
  14237. void clif_parse_cashshop_list_request( int fd, map_session_data* sd ){
  14238. if( !sd->status.cashshop_sent ) {
  14239. clif_cashshop_list( *sd );
  14240. #if PACKETVER_SUPPORTS_SALES
  14241. sale_notify_login(sd);
  14242. #endif
  14243. sd->status.cashshop_sent = true;
  14244. }
  14245. }
  14246. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  14247. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  14248. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  14249. void clif_cashshop_show( map_session_data& sd, npc_data& nd ){
  14250. sd.npc_shopid = nd.bl.id;
  14251. int cost[2] = { 0, 0 };
  14252. npc_shop_currency_type( &sd, &nd, cost, true );
  14253. PACKET_ZC_PC_CASH_POINT_ITEMLIST* p = reinterpret_cast<PACKET_ZC_PC_CASH_POINT_ITEMLIST*>( packet_buffer );
  14254. p->packetType = HEADER_ZC_PC_CASH_POINT_ITEMLIST;
  14255. p->packetLength = sizeof( *p );
  14256. p->cashPoints = cost[0];
  14257. #if PACKETVER >= 20070711
  14258. p->kafraPoints = cost[1];
  14259. #endif
  14260. for( int i = 0; i < nd.u.shop.count; i++ ) {
  14261. struct item_data* id = itemdb_search( nd.u.shop.shop_item[i].nameid );
  14262. p->items[i].price = nd.u.shop.shop_item[i].value;
  14263. p->items[i].discountPrice = nd.u.shop.shop_item[i].value; // Discount Price
  14264. p->items[i].itemType = itemtype( id->nameid );
  14265. p->items[i].itemId = client_nameid( id->nameid );
  14266. #ifdef ENABLE_OLD_CASHSHOP_PREVIEW_PATCH
  14267. p->items[i].location = pc_equippoint_sub( &sd, id );
  14268. p->items[i].viewSprite = id->look;
  14269. memset( p->items[i].unused, 0, sizeof( p->items[i].unused ) );
  14270. #endif
  14271. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  14272. }
  14273. clif_send( p, p->packetLength, &sd.bl, SELF );
  14274. }
  14275. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  14276. /// 0289 <cash point>.L <error>.W
  14277. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  14278. /// error:
  14279. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  14280. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  14281. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  14282. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  14283. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  14284. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  14285. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  14286. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  14287. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  14288. void clif_cashshop_ack(map_session_data* sd, int error)
  14289. {
  14290. int fd, cost[2] = { 0, 0 };
  14291. struct npc_data *nd;
  14292. nullpo_retv(sd);
  14293. fd = sd->fd;
  14294. nd = map_id2nd(sd->npc_shopid);
  14295. npc_shop_currency_type(sd, nd, cost, false);
  14296. WFIFOHEAD(fd, packet_len(0x289));
  14297. WFIFOW(fd,0) = 0x289;
  14298. WFIFOL(fd,2) = cost[0];
  14299. #if PACKETVER < 20070711
  14300. WFIFOW(fd,6) = TOW(error);
  14301. #else
  14302. WFIFOL(fd,6) = cost[1];
  14303. WFIFOW(fd,10) = TOW(error);
  14304. #endif
  14305. WFIFOSET(fd, packet_len(0x289));
  14306. }
  14307. void clif_cashshop_result( map_session_data *sd, t_itemid item_id, uint16 result ){
  14308. #if PACKETVER_MAIN_NUM >= 20101123 || PACKETVER_RE_NUM >= 20120328 || defined( PACKETVER_ZERO )
  14309. nullpo_retv( sd );
  14310. struct PACKET_ZC_SE_PC_BUY_CASHITEM_RESULT packet = {};
  14311. packet.packetType = HEADER_ZC_SE_PC_BUY_CASHITEM_RESULT;
  14312. if( item_id != 0 ){
  14313. packet.itemId = client_nameid( item_id );
  14314. }else{
  14315. packet.itemId = 0;
  14316. }
  14317. packet.result = result;
  14318. packet.cashPoints = sd->cashPoints;
  14319. packet.kafraPoints = sd->kafraPoints;
  14320. clif_send( &packet, sizeof( packet ), &sd->bl, SELF );
  14321. #endif
  14322. }
  14323. /// Request to buy item(s) from cash shop.
  14324. /// 0288 <name id>.W <amount>.W (CZ_PC_BUY_CASH_POINT_ITEM)
  14325. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  14326. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  14327. void clif_parse_npccashshop_buy( int fd, map_session_data *sd ){
  14328. nullpo_retv( sd );
  14329. if( sd->state.trading || !sd->npc_shopid ){
  14330. clif_cashshop_ack( sd, 1 );
  14331. return;
  14332. }
  14333. struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM* p = (struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM *)RFIFOP( fd, 0 );
  14334. #if PACKETVER < 20070711
  14335. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, 0 ) );
  14336. #elif PACKETVER < 20101116
  14337. clif_cashshop_ack( sd, npc_cashshop_buy( sd, p->itemId, p->amount, p->kafraPoints ) );
  14338. #else
  14339. int s_itl = sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM_sub );
  14340. if( p->packetLength < sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM ) || p->packetLength != sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM ) + p->count * s_itl ){
  14341. ShowWarning( "Player %u sent incorrect cash shop buy packet (len %u:%" PRIdPTR ")!\n", sd->status.char_id, p->packetLength, sizeof( struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM ) + p->count * s_itl );
  14342. return;
  14343. }
  14344. std::vector<s_npc_buy_list> item_list = {};
  14345. item_list.reserve( p->count );
  14346. for( int i = 0; i < p->count; i++ ){
  14347. s_npc_buy_list item = {};
  14348. item.nameid = p->items[i].itemId;
  14349. item.qty = p->items[i].amount;
  14350. item_list.push_back( item );
  14351. }
  14352. clif_cashshop_ack( sd, npc_cashshop_buylist( sd, p->kafraPoints, item_list ) );
  14353. #endif
  14354. }
  14355. /// Request to buy item(s) from cash shop.
  14356. /// 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)
  14357. void clif_parse_cashshop_buy( int fd, map_session_data *sd ){
  14358. struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST* p = (struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST*)RFIFOP( fd, 0 );
  14359. int s_itl = sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST_sub );
  14360. if( p->packetLength < sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST ) || p->packetLength != sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST ) + p->count * s_itl ){
  14361. ShowWarning( "Player %u sent incorrect cash shop buy packet (len %u:%" PRIdPTR ")!\n", sd->status.char_id, p->packetLength, sizeof( struct PACKET_CZ_SE_PC_BUY_CASHITEM_LIST ) + p->count * s_itl );
  14362. return;
  14363. }
  14364. cashshop_buylist( sd, p->kafraPoints, p->count, p->items );
  14365. }
  14366. /// Adoption System
  14367. ///
  14368. /// Adoption message (ZC_BABYMSG).
  14369. /// 0216 <msg>.L
  14370. /// msg:
  14371. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  14372. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  14373. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  14374. void clif_Adopt_reply(map_session_data *sd, int type)
  14375. {
  14376. int fd = sd->fd;
  14377. WFIFOHEAD(fd,6);
  14378. WFIFOW(fd,0) = 0x216;
  14379. WFIFOL(fd,2) = type;
  14380. WFIFOSET(fd,6);
  14381. }
  14382. /// Adoption confirmation (ZC_REQ_BABY).
  14383. /// 01f6 <account id>.L <char id>.L <name>.B
  14384. void clif_Adopt_request(map_session_data *sd, map_session_data *src, int p_id)
  14385. {
  14386. int fd = sd->fd;
  14387. WFIFOHEAD(fd,34);
  14388. WFIFOW(fd,0) = 0x1f6;
  14389. WFIFOL(fd,2) = src->status.account_id;
  14390. WFIFOL(fd,6) = p_id;
  14391. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14392. WFIFOSET(fd,34);
  14393. }
  14394. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14395. /// 01f9 <account id>.L
  14396. void clif_parse_Adopt_request(int fd, map_session_data *sd)
  14397. {
  14398. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14399. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14400. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14401. {
  14402. tsd->adopt_invite = sd->status.account_id;
  14403. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14404. }
  14405. }
  14406. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14407. /// 01f7 <account id>.L <char id>.L <answer>.L
  14408. /// answer:
  14409. /// 0 = rejected
  14410. /// 1 = accepted
  14411. void clif_parse_Adopt_reply(int fd, map_session_data *sd){
  14412. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14413. int p1_id = RFIFOL(fd,info->pos[0]);
  14414. int p2_id = RFIFOL(fd,info->pos[1]);
  14415. int result = RFIFOL(fd,info->pos[2]);
  14416. map_session_data* p1_sd = map_id2sd(p1_id);
  14417. map_session_data* p2_sd = map_id2sd(p2_id);
  14418. int pid = sd->adopt_invite;
  14419. sd->adopt_invite = 0;
  14420. if( p1_sd == nullptr || p2_sd == nullptr )
  14421. return; // Both players need to be online
  14422. if( pid != p1_sd->status.account_id )
  14423. return; // Incorrect values
  14424. if( result == 0 )
  14425. return; // Rejected
  14426. pc_adoption(p1_sd, p2_sd, sd);
  14427. }
  14428. /// Convex Mirror
  14429. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B (ZC_BOSS_INFO)
  14430. /// infoType:
  14431. /// BOSS_INFO_NOT = No boss on this map.
  14432. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14433. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14434. /// BOSS_INFO_DEAD = Boss is dead.
  14435. void clif_bossmapinfo( map_session_data& sd, mob_data* md, e_bossmap_info flag ){
  14436. PACKET_ZC_BOSS_INFO p = {};
  14437. p.packetType = HEADER_ZC_BOSS_INFO;
  14438. p.type = flag;
  14439. switch (flag) {
  14440. case BOSS_INFO_NOT:
  14441. // No data required
  14442. break;
  14443. case BOSS_INFO_ALIVE_WITHMSG:
  14444. [[fallthrough]];
  14445. case BOSS_INFO_ALIVE:
  14446. p.x = md->bl.x;
  14447. p.y = md->bl.y;
  14448. break;
  14449. case BOSS_INFO_DEAD: {
  14450. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14451. unsigned int seconds;
  14452. int hours, minutes;
  14453. seconds = (unsigned int)(DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60);
  14454. hours = seconds / (60 * 60);
  14455. seconds = seconds - (60 * 60 * hours);
  14456. minutes = seconds / 60;
  14457. p.minHours = hours;
  14458. p.minMinutes = minutes;
  14459. break;
  14460. }
  14461. }
  14462. if( md != nullptr ){
  14463. safestrncpy( p.name, md->db->jname.c_str(), sizeof( p.name ) );
  14464. }
  14465. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  14466. }
  14467. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14468. /// 02d6 <account id>.L
  14469. void clif_parse_ViewPlayerEquip(int fd, map_session_data* sd)
  14470. {
  14471. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14472. map_session_data* tsd = map_id2sd(aid);
  14473. if (!tsd)
  14474. return;
  14475. if (sd->bl.m != tsd->bl.m)
  14476. return;
  14477. else if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14478. clif_viewequip_ack( *sd, *tsd );
  14479. else
  14480. clif_msg(sd, MSI_OPEN_EQUIPEDITEM_REFUSED);
  14481. }
  14482. /// Request to a configuration.
  14483. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14484. /// type: see enum e_config_type
  14485. /// flag:
  14486. /// false = disabled
  14487. /// true = enabled
  14488. void clif_parse_configuration( int fd, map_session_data* sd ){
  14489. int cmd = RFIFOW(fd,0);
  14490. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14491. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14492. switch( type ){
  14493. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14494. sd->status.show_equip = flag;
  14495. break;
  14496. case CONFIG_CALL:
  14497. sd->status.disable_call = flag;
  14498. break;
  14499. case CONFIG_PET_AUTOFEED:
  14500. // Player can not click this if he does not have a pet
  14501. if( sd->pd == nullptr || !battle_config.feature_pet_autofeed || !sd->pd->get_pet_db()->allow_autofeed ){
  14502. return;
  14503. }
  14504. sd->pd->pet.autofeed = flag;
  14505. break;
  14506. case CONFIG_HOMUNCULUS_AUTOFEED:
  14507. // Player can not click this if he does not have a homunculus or it is vaporized
  14508. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14509. return;
  14510. }
  14511. sd->hd->homunculus.autofeed = flag;
  14512. break;
  14513. default:
  14514. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14515. return;
  14516. }
  14517. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14518. }
  14519. /// Request to change party invitation tick.
  14520. /// value:
  14521. /// 0 = disabled (triggered by /accept)
  14522. /// 1 = enabled (triggered by /refuse)
  14523. void clif_parse_PartyTick( int fd, map_session_data* sd ){
  14524. PACKET_CZ_PARTY_CONFIG* p = (PACKET_CZ_PARTY_CONFIG*)RFIFOP( fd, 0 );
  14525. sd->status.disable_partyinvite = p->refuseInvite;
  14526. clif_partyinvitationstate( *sd );
  14527. }
  14528. /// Questlog System [Kevin] [Inkfish]
  14529. ///
  14530. /**
  14531. * Safe check to init packet len & quest num for player.
  14532. * @param def_len
  14533. * @param info_len Length of each quest info.
  14534. * @param avail_quests Avail quests that player has.
  14535. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14536. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14537. **/
  14538. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14539. (*limit_out) = (0xFFFF - def_len) / info_len;
  14540. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14541. (*len_out) = ((*limit_out) * info_len) + def_len;
  14542. }
  14543. std::string clif_quest_string( std::shared_ptr<s_quest_objective> objective ){
  14544. std::string race_name;
  14545. switch( objective->race ){
  14546. case RC_FORMLESS: race_name = "Formless"; break;
  14547. case RC_UNDEAD: race_name = "Undead"; break;
  14548. case RC_BRUTE: race_name = "Brute"; break;
  14549. case RC_PLANT: race_name = "Plant"; break;
  14550. case RC_INSECT: race_name = "Insect"; break;
  14551. case RC_FISH: race_name = "Fish"; break;
  14552. case RC_DEMON: race_name = "Demon"; break;
  14553. case RC_DEMIHUMAN: race_name = "Demihuman"; break;
  14554. case RC_ANGEL: race_name = "Angel"; break;
  14555. case RC_DRAGON: race_name = "Dragon"; break;
  14556. default:
  14557. ShowWarning( "clif_quest_string: Unsupported race %d - using empty string...\n", objective->race );
  14558. [[fallthrough]];
  14559. case RC_ALL: race_name = ""; break;
  14560. }
  14561. std::string size_name;
  14562. switch( objective->size ){
  14563. case SZ_SMALL: size_name = "Small"; break;
  14564. case SZ_MEDIUM: size_name = "Medium"; break;
  14565. case SZ_BIG: size_name = "Large"; break;
  14566. default:
  14567. ShowWarning( "clif_quest_string: Unsupported size %d - using empty string...\n", objective->size );
  14568. [[fallthrough]];
  14569. case SZ_ALL: size_name = ""; break;
  14570. }
  14571. std::string ele_name;
  14572. switch( objective->element ){
  14573. case ELE_NEUTRAL: ele_name = "Neutral Element"; break;
  14574. case ELE_WATER: ele_name = "Water Element"; break;
  14575. case ELE_EARTH: ele_name = "Earth Element"; break;
  14576. case ELE_FIRE: ele_name = "Fire Element"; break;
  14577. case ELE_WIND: ele_name = "Wind Element"; break;
  14578. case ELE_POISON: ele_name = "Poison Element"; break;
  14579. case ELE_HOLY: ele_name = "Holy Element"; break;
  14580. case ELE_DARK: ele_name = "Shadow Element"; break;
  14581. case ELE_GHOST: ele_name = "Ghost Element"; break;
  14582. case ELE_UNDEAD: ele_name = "Undead Element"; break;
  14583. default:
  14584. ShowWarning( "clif_quest_string: Unsupported element %d - using empty string...\n", objective->element );
  14585. [[fallthrough]];
  14586. case ELE_ALL: ele_name = ""; break;
  14587. }
  14588. std::string str;
  14589. if( !objective->map_name.empty() ){
  14590. str += objective->map_name;
  14591. }
  14592. if( !race_name.empty() ){
  14593. if( !str.empty() ){
  14594. str += ", ";
  14595. }
  14596. str += race_name;
  14597. }
  14598. if( !size_name.empty() ){
  14599. if( !str.empty() ){
  14600. str += ", ";
  14601. }
  14602. str += size_name;
  14603. }
  14604. if( !ele_name.empty() ){
  14605. if( !str.empty() ){
  14606. str += ", ";
  14607. }
  14608. str += ele_name;
  14609. }
  14610. return str;
  14611. }
  14612. /// Sends list of all quest states
  14613. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14614. /// 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)
  14615. /// 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)
  14616. void clif_quest_send_list(map_session_data *sd)
  14617. {
  14618. nullpo_retv(sd);
  14619. int fd = sd->fd;
  14620. int i;
  14621. int offset = 8;
  14622. int limit = 0;
  14623. #if PACKETVER >= 20141022
  14624. #if PACKETVER >= 20150513
  14625. int size = 22 + NAME_LENGTH;
  14626. #else
  14627. int size = 10 + NAME_LENGTH;
  14628. #endif
  14629. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14630. WFIFOHEAD(fd,i);
  14631. #if PACKETVER >= 20150513
  14632. WFIFOW(fd, 0) = 0x9f8;
  14633. #else
  14634. WFIFOW(fd, 0) = 0x97a;
  14635. #endif
  14636. WFIFOL(fd, 4) = limit;
  14637. for (i = 0; i < limit; i++) {
  14638. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14639. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14640. offset += 4;
  14641. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14642. offset++;
  14643. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14644. offset += 4;
  14645. WFIFOL(fd, offset) = static_cast<uint32>(sd->quest_log[i].time);
  14646. offset += 4;
  14647. WFIFOW(fd, offset) = static_cast<uint16>(qi->objectives.size());
  14648. offset += 2;
  14649. if (!qi->objectives.empty()) {
  14650. std::shared_ptr<s_mob_db> mob;
  14651. for (int j = 0; j < qi->objectives.size(); j++) {
  14652. mob = mob_db.find(qi->objectives[j]->mob_id);
  14653. e_race race = qi->objectives[j]->race;
  14654. e_size size = qi->objectives[j]->size;
  14655. e_element element = qi->objectives[j]->element;
  14656. #if PACKETVER >= 20150513
  14657. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14658. offset += 4;
  14659. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0)));
  14660. offset += 4;
  14661. #endif
  14662. WFIFOL(fd, offset) = ((mob && qi->objectives[j]->mob_id > 0) ? qi->objectives[j]->mob_id : MOBID_PORING);
  14663. offset += 4;
  14664. #if PACKETVER >= 20150513
  14665. WFIFOW(fd, offset) = qi->objectives[j]->min_level;
  14666. offset += 2;
  14667. WFIFOW(fd, offset) = qi->objectives[j]->max_level;
  14668. offset += 2;
  14669. #endif
  14670. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14671. offset += 2;
  14672. WFIFOW(fd, offset) = qi->objectives[j]->count;
  14673. offset += 2;
  14674. if (mob && qi->objectives[j]->mob_id > 0)
  14675. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14676. else
  14677. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14678. offset += NAME_LENGTH;
  14679. }
  14680. }
  14681. }
  14682. WFIFOW(fd, 2) = offset;
  14683. WFIFOSET(fd, offset);
  14684. #else
  14685. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14686. WFIFOHEAD(fd,i);
  14687. WFIFOW(fd, 0) = 0x2b1;
  14688. WFIFOL(fd, 4) = limit;
  14689. for (i = 0; i < limit; i++) {
  14690. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14691. offset += 4;
  14692. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14693. offset += 1;
  14694. }
  14695. WFIFOW(fd, 2) = offset;
  14696. WFIFOSET(fd, offset);
  14697. #endif
  14698. }
  14699. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14700. /// 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
  14701. void clif_quest_send_mission(map_session_data *sd)
  14702. {
  14703. nullpo_retv(sd);
  14704. int fd = sd->fd;
  14705. int limit = 0;
  14706. int len = sd->avail_quests*104+8;
  14707. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14708. WFIFOHEAD(fd, len);
  14709. WFIFOW(fd, 0) = 0x2b2;
  14710. WFIFOW(fd, 2) = len;
  14711. WFIFOL(fd, 4) = limit;
  14712. for (int i = 0; i < limit; i++) {
  14713. std::shared_ptr<s_quest_db> qi = quest_search(sd->quest_log[i].quest_id);
  14714. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14715. WFIFOL(fd, i*104+12) = static_cast<uint32>(sd->quest_log[i].time - qi->time);
  14716. WFIFOL(fd, i*104+16) = static_cast<uint32>(sd->quest_log[i].time);
  14717. WFIFOW(fd, i*104+20) = static_cast<uint16>(qi->objectives.size());
  14718. for (int j = 0 ; j < qi->objectives.size(); j++) {
  14719. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[j]->mob_id);
  14720. WFIFOL(fd, i*104+22+j*30) = (mob ? qi->objectives[j]->mob_id : MOBID_PORING);
  14721. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14722. if (mob && qi->objectives[j]->mob_id > 0)
  14723. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname.c_str(), NAME_LENGTH);
  14724. else
  14725. safestrncpy(WFIFOCP(fd, i*104+28+j*30), clif_quest_string(qi->objectives[j]).c_str(), NAME_LENGTH);
  14726. }
  14727. }
  14728. WFIFOSET(fd, len);
  14729. }
  14730. /// Notification about a new quest
  14731. /// 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)
  14732. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14733. /// 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)
  14734. void clif_quest_add(map_session_data *sd, struct quest *qd)
  14735. {
  14736. nullpo_retv(sd);
  14737. nullpo_retv(qd);
  14738. int fd = sd->fd;
  14739. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14740. if (!qi)
  14741. return;
  14742. #if PACKETVER >= 20150513
  14743. int cmd = 0x9f9;
  14744. #else
  14745. int cmd = 0x2b3;
  14746. #endif
  14747. WFIFOHEAD(fd, packet_len(cmd));
  14748. WFIFOW(fd, 0) = cmd;
  14749. WFIFOL(fd, 2) = qd->quest_id;
  14750. WFIFOB(fd, 6) = qd->state;
  14751. WFIFOB(fd, 7) = static_cast<uint8>(qd->time - qi->time);
  14752. WFIFOL(fd, 11) = static_cast<uint32>(qd->time);
  14753. WFIFOW(fd, 15) = static_cast<uint16>(qi->objectives.size());
  14754. for (int i = 0, offset = 17; i < qi->objectives.size(); i++) {
  14755. std::shared_ptr<s_mob_db> mob = mob_db.find(qi->objectives[i]->mob_id);
  14756. e_race race = qi->objectives[i]->race;
  14757. e_size size = qi->objectives[i]->size;
  14758. e_element element = qi->objectives[i]->element;
  14759. #if PACKETVER >= 20150513
  14760. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14761. offset += 4;
  14762. WFIFOL(fd, offset) = (race ? race : (size ? size : (element ? element : 0))); // effect ?
  14763. offset += 4;
  14764. #endif
  14765. 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
  14766. offset += 4;
  14767. #if PACKETVER >= 20150513
  14768. WFIFOW(fd, offset) = qi->objectives[i]->min_level;
  14769. offset += 2;
  14770. WFIFOW(fd, offset) = qi->objectives[i]->max_level;
  14771. offset += 2;
  14772. #endif
  14773. WFIFOW(fd, offset) = qd->count[i];
  14774. offset += 2;
  14775. if (mob && qi->objectives[i]->mob_id > 0)
  14776. safestrncpy(WFIFOCP(fd,offset), mob->jname.c_str(), NAME_LENGTH);
  14777. else
  14778. safestrncpy(WFIFOCP(fd,offset), clif_quest_string(qi->objectives[i]).c_str(), NAME_LENGTH);
  14779. offset += NAME_LENGTH;
  14780. }
  14781. WFIFOSET(fd, packet_len(cmd));
  14782. #if PACKETVER >= 20150513
  14783. int16 len;
  14784. len = static_cast<decltype(len)>( 4 + qi->objectives.size() * 12 );
  14785. WFIFOHEAD(fd, len);
  14786. WFIFOW(fd, 0) = 0x8fe;
  14787. WFIFOW(fd, 2) = len;
  14788. for (int i = 0, offset = 4; i < qi->objectives.size(); i++, offset += 12) {
  14789. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14790. WFIFOL(fd, offset + 4) = qi->objectives[i]->mob_id;
  14791. WFIFOW(fd, offset + 8) = qi->objectives[i]->count;
  14792. WFIFOW(fd, offset + 10) = qd->count[i];
  14793. }
  14794. WFIFOSET(fd, len);
  14795. #endif
  14796. }
  14797. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14798. /// 02b4 <quest id>.L
  14799. void clif_quest_delete(map_session_data *sd, int quest_id)
  14800. {
  14801. int fd = sd->fd;
  14802. WFIFOHEAD(fd, packet_len(0x2b4));
  14803. WFIFOW(fd, 0) = 0x2b4;
  14804. WFIFOL(fd, 2) = quest_id;
  14805. WFIFOSET(fd, packet_len(0x2b4));
  14806. }
  14807. /// Notification of an update to the hunting mission counter
  14808. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14809. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14810. void clif_quest_update_objective(map_session_data *sd, struct quest *qd)
  14811. {
  14812. int fd = sd->fd;
  14813. int offset = 6;
  14814. std::shared_ptr<s_quest_db> qi = quest_search(qd->quest_id);
  14815. int16 len;
  14816. len = static_cast<decltype(len)>( qi->objectives.size() * 12 + 6 );
  14817. #if PACKETVER >= 20150513
  14818. int cmd = 0x9fa;
  14819. #else
  14820. int cmd = 0x2b5;
  14821. #endif
  14822. WFIFOHEAD(fd, len);
  14823. WFIFOW(fd, 0) = cmd;
  14824. WFIFOW(fd, 4) = static_cast<uint16>(qi->objectives.size());
  14825. for (int i = 0; i < qi->objectives.size(); i++) {
  14826. WFIFOL(fd, offset) = qd->quest_id;
  14827. offset += 4;
  14828. #if PACKETVER >= 20150513
  14829. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14830. offset += 4;
  14831. #else
  14832. WFIFOL(fd, offset) = qi->objectives[i]->mob_id;
  14833. offset += 4;
  14834. #endif
  14835. WFIFOW(fd, offset) = qi->objectives[i]->count;
  14836. offset += 2;
  14837. WFIFOW(fd, offset) = qd->count[i];
  14838. offset += 2;
  14839. }
  14840. WFIFOW(fd, 2) = offset;
  14841. WFIFOSET(fd, offset);
  14842. }
  14843. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14844. /// 02b6 <quest id>.L <active>.B
  14845. void clif_parse_questStateAck(int fd, map_session_data *sd)
  14846. {
  14847. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14848. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14849. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14850. }
  14851. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14852. /// 02b7 <quest id>.L <active>.B
  14853. void clif_quest_update_status(map_session_data *sd, int quest_id, bool active)
  14854. {
  14855. int fd = sd->fd;
  14856. WFIFOHEAD(fd, packet_len(0x2b7));
  14857. WFIFOW(fd, 0) = 0x2b7;
  14858. WFIFOL(fd, 2) = quest_id;
  14859. WFIFOB(fd, 6) = active;
  14860. WFIFOSET(fd, packet_len(0x2b7));
  14861. }
  14862. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14863. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14864. /// effect:
  14865. /// 0 = none
  14866. /// 1 = exclamation mark icon
  14867. /// 2 = question mark icon
  14868. /// color:
  14869. /// 0 = yellow
  14870. /// 1 = orange
  14871. /// 2 = green
  14872. /// 3 = purple
  14873. void clif_quest_show_event(map_session_data *sd, struct block_list *bl, e_questinfo_types effect, e_questinfo_markcolor color)
  14874. {
  14875. #if PACKETVER >= 20090218
  14876. nullpo_retv(sd);
  14877. nullpo_retv(bl);
  14878. int fd = sd->fd;
  14879. WFIFOHEAD(fd, packet_len(0x446));
  14880. WFIFOW(fd, 0) = 0x446;
  14881. WFIFOL(fd, 2) = bl->id;
  14882. WFIFOW(fd, 6) = bl->x;
  14883. WFIFOW(fd, 8) = bl->y;
  14884. WFIFOW(fd, 10) = effect;
  14885. WFIFOW(fd, 12) = color;
  14886. WFIFOSET(fd, packet_len(0x446));
  14887. #endif
  14888. }
  14889. /// Mercenary System
  14890. ///
  14891. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14892. /// 02a2 <var id>.W <value>.L
  14893. void clif_mercenary_updatestatus(map_session_data *sd, int type)
  14894. {
  14895. s_mercenary_data *md;
  14896. struct status_data *status;
  14897. int fd;
  14898. if( !clif_session_isValid(sd) || (md = sd->md) == nullptr )
  14899. return;
  14900. fd = sd->fd;
  14901. status = &md->battle_status;
  14902. WFIFOHEAD(fd,packet_len(0x2a2));
  14903. WFIFOW(fd,0) = 0x2a2;
  14904. WFIFOW(fd,2) = type;
  14905. switch( type ) {
  14906. case SP_ATK1:
  14907. {
  14908. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14909. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14910. }
  14911. break;
  14912. case SP_MATK1:
  14913. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14914. break;
  14915. case SP_HIT:
  14916. WFIFOL(fd,4) = status->hit;
  14917. break;
  14918. case SP_CRITICAL:
  14919. WFIFOL(fd,4) = status->cri/10;
  14920. break;
  14921. case SP_DEF1:
  14922. WFIFOL(fd,4) = status->def;
  14923. break;
  14924. case SP_MDEF1:
  14925. WFIFOL(fd,4) = status->mdef;
  14926. break;
  14927. case SP_MERCFLEE:
  14928. WFIFOL(fd,4) = status->flee;
  14929. break;
  14930. case SP_ASPD:
  14931. WFIFOL(fd,4) = status->amotion;
  14932. break;
  14933. case SP_HP:
  14934. WFIFOL(fd,4) = status->hp;
  14935. break;
  14936. case SP_MAXHP:
  14937. WFIFOL(fd,4) = status->max_hp;
  14938. break;
  14939. case SP_SP:
  14940. WFIFOL(fd,4) = status->sp;
  14941. break;
  14942. case SP_MAXSP:
  14943. WFIFOL(fd,4) = status->max_sp;
  14944. break;
  14945. case SP_MERCKILLS:
  14946. WFIFOL(fd,4) = md->mercenary.kill_count;
  14947. break;
  14948. case SP_MERCFAITH:
  14949. WFIFOL(fd,4) = mercenary_get_faith(md);
  14950. break;
  14951. }
  14952. WFIFOSET(fd,packet_len(0x2a2));
  14953. }
  14954. /// Mercenary base status data (ZC_MER_INIT).
  14955. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14956. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14957. /// <calls>.L <kills>.L <atk range>.W
  14958. void clif_mercenary_info(map_session_data *sd)
  14959. {
  14960. int fd;
  14961. s_mercenary_data *md;
  14962. struct status_data *status;
  14963. int atk;
  14964. if( !clif_session_isValid(sd) || (md = sd->md) == nullptr )
  14965. return;
  14966. fd = sd->fd;
  14967. status = &md->battle_status;
  14968. WFIFOHEAD(fd,packet_len(0x29b));
  14969. WFIFOW(fd,0) = 0x29b;
  14970. WFIFOL(fd,2) = md->bl.id;
  14971. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14972. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->batk + status->rhw.atk;
  14973. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14974. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14975. WFIFOW(fd,10) = status->hit;
  14976. WFIFOW(fd,12) = status->cri/10;
  14977. WFIFOW(fd,14) = status->def;
  14978. WFIFOW(fd,16) = status->mdef;
  14979. WFIFOW(fd,18) = status->flee;
  14980. WFIFOW(fd,20) = status->amotion;
  14981. safestrncpy(WFIFOCP(fd,22), md->db->name.c_str(), NAME_LENGTH);
  14982. WFIFOW(fd,46) = md->db->lv;
  14983. WFIFOL(fd,48) = status->hp;
  14984. WFIFOL(fd,52) = status->max_hp;
  14985. WFIFOL(fd,56) = status->sp;
  14986. WFIFOL(fd,60) = status->max_sp;
  14987. WFIFOL(fd,64) = client_tick(time(nullptr) + (mercenary_get_lifetime(md) / 1000));
  14988. WFIFOW(fd,68) = mercenary_get_faith(md);
  14989. WFIFOL(fd,70) = mercenary_get_calls(md);
  14990. WFIFOL(fd,74) = md->mercenary.kill_count;
  14991. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14992. WFIFOSET(fd,packet_len(0x29b));
  14993. }
  14994. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14995. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14996. void clif_mercenary_skillblock(map_session_data *sd)
  14997. {
  14998. s_mercenary_data *md;
  14999. int fd, len = 4;
  15000. if( sd == nullptr || (md = sd->md) == nullptr )
  15001. return;
  15002. fd = sd->fd;
  15003. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  15004. WFIFOW(fd,0) = 0x29d;
  15005. for (const auto &it : md->db->skill) {
  15006. uint16 id = it.first;
  15007. if (!SKILL_CHK_MERC(id))
  15008. continue;
  15009. uint16 lv = it.second;
  15010. WFIFOW(fd,len) = id;
  15011. WFIFOL(fd,len+2) = skill_get_inf(id);
  15012. WFIFOW(fd,len+6) = lv;
  15013. WFIFOW(fd,len+8) = skill_get_sp(id, lv);
  15014. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, lv, false);
  15015. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  15016. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  15017. len += 37;
  15018. }
  15019. WFIFOW(fd,2) = len;
  15020. WFIFOSET(fd,len);
  15021. }
  15022. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  15023. /// 029f <command>.B
  15024. /// 1 = mercenary information
  15025. /// 2 = delete
  15026. void clif_parse_mercenary_action(int fd, map_session_data* sd)
  15027. {
  15028. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15029. if( sd->md == nullptr )
  15030. return;
  15031. if( option == 2 ) mercenary_delete(sd->md, 2);
  15032. }
  15033. /// Notification about the remaining time of a rental item.
  15034. /// 0298 <name id>.W <seconds>.L (ZC_CASH_TIME_COUNTER)
  15035. void clif_rental_time( map_session_data* sd, t_itemid nameid, int seconds ){
  15036. // '<ItemName>' item will disappear in <seconds/60> minutes.
  15037. struct PACKET_ZC_CASH_TIME_COUNTER p;
  15038. p.packetType = HEADER_ZC_CASH_TIME_COUNTER;
  15039. p.itemId = client_nameid( nameid );
  15040. p.seconds = seconds;
  15041. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15042. }
  15043. /// Deletes a rental item from client's inventory.
  15044. /// 0299 <index>.W <name id>.W (ZC_CASH_ITEM_DELETE)
  15045. void clif_rental_expired( map_session_data* sd, int index, t_itemid nameid ){
  15046. // '<ItemName>' item has been deleted from the Inventory
  15047. struct PACKET_ZC_CASH_ITEM_DELETE p;
  15048. p.packetType = HEADER_ZC_CASH_ITEM_DELETE;
  15049. p.index = client_index( index );
  15050. p.itemId = client_nameid( nameid );
  15051. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15052. }
  15053. /// Book Reading (ZC_READ_BOOK).
  15054. /// 0294 <book id>.L <page>.L
  15055. void clif_readbook(int fd, int book_id, int page)
  15056. {
  15057. WFIFOHEAD(fd,packet_len(0x294));
  15058. WFIFOW(fd,0) = 0x294;
  15059. WFIFOL(fd,2) = book_id;
  15060. WFIFOL(fd,6) = page;
  15061. WFIFOSET(fd,packet_len(0x294));
  15062. }
  15063. /// Battlegrounds
  15064. ///
  15065. /// Updates HP bar of a camp member.
  15066. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  15067. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  15068. void clif_bg_hp(map_session_data *sd) {
  15069. #if PACKETVER < 20140613
  15070. unsigned char buf[34];
  15071. const int cmd = 0x2e0;
  15072. #else
  15073. unsigned char buf[14];
  15074. const int cmd = 0xa0e;
  15075. #endif
  15076. nullpo_retv(sd);
  15077. WBUFW(buf,0) = cmd;
  15078. WBUFL(buf,2) = sd->status.account_id;
  15079. #if PACKETVER < 20140613
  15080. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15081. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  15082. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15083. WBUFW(buf,32) = 100;
  15084. } else {
  15085. WBUFW(buf,30) = sd->battle_status.hp;
  15086. WBUFW(buf,32) = sd->battle_status.max_hp;
  15087. }
  15088. #else
  15089. if( sd->battle_status.max_hp > INT32_MAX ) {
  15090. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  15091. WBUFL(buf,10) = 100;
  15092. } else {
  15093. WBUFL(buf,6) = sd->battle_status.hp;
  15094. WBUFL(buf,10) = sd->battle_status.max_hp;
  15095. }
  15096. #endif
  15097. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  15098. }
  15099. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  15100. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  15101. void clif_bg_xy(map_session_data *sd)
  15102. {
  15103. unsigned char buf[36];
  15104. nullpo_retv(sd);
  15105. WBUFW(buf,0)=0x2df;
  15106. WBUFL(buf,2)=sd->status.account_id;
  15107. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  15108. WBUFW(buf,30)=sd->status.class_;
  15109. WBUFW(buf,32)=sd->bl.x;
  15110. WBUFW(buf,34)=sd->bl.y;
  15111. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15112. }
  15113. void clif_bg_xy_remove(map_session_data *sd)
  15114. {
  15115. unsigned char buf[36];
  15116. nullpo_retv(sd);
  15117. WBUFW(buf,0)=0x2df;
  15118. WBUFL(buf,2)=sd->status.account_id;
  15119. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  15120. WBUFW(buf,30)=0;
  15121. WBUFW(buf,32)=-1;
  15122. WBUFW(buf,34)=-1;
  15123. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  15124. }
  15125. /// Notifies clients of a battleground message.
  15126. /// 02DC <packet len>.W <account id>.L <name>.24B <message>.?B (ZC_BATTLEFIELD_CHAT)
  15127. void clif_bg_message( struct s_battleground_data *bg, int src_id, const char *name, const char *mes, size_t len ){
  15128. map_session_data *sd = bg_getavailablesd( bg );
  15129. if( sd == nullptr ){
  15130. return;
  15131. }
  15132. // limit length
  15133. len = zmin( len + 1, CHAT_SIZE_MAX );
  15134. unsigned char buf[8 + NAME_LENGTH + CHAT_SIZE_MAX];
  15135. WBUFW(buf,0) = 0x2dc;
  15136. WBUFW(buf,2) = static_cast<int16>( len + NAME_LENGTH + 8 );
  15137. WBUFL(buf,4) = src_id;
  15138. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  15139. safestrncpy(WBUFCP(buf,8+NAME_LENGTH), mes, len );
  15140. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  15141. }
  15142. /// Validates and processes battlechat messages.
  15143. /// All messages that are sent after enabling battleground chat with /battlechat.
  15144. /// 02DB <packet len>.W <text>.?B (CZ_BATTLEFIELD_CHAT)
  15145. void clif_parse_BattleChat(int fd, map_session_data* sd){
  15146. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15147. if( !clif_process_message( sd, false, name, message, output ) )
  15148. return;
  15149. bg_send_message(sd, output, strlen(output) );
  15150. }
  15151. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  15152. /// 02de <camp A points>.W <camp B points>.W
  15153. void clif_bg_updatescore(int16 m)
  15154. {
  15155. struct block_list bl;
  15156. unsigned char buf[6];
  15157. struct map_data *mapdata = map_getmapdata(m);
  15158. bl.id = 0;
  15159. bl.type = BL_NUL;
  15160. bl.m = m;
  15161. WBUFW(buf,0) = 0x2de;
  15162. WBUFW(buf,2) = mapdata->bgscore_lion;
  15163. WBUFW(buf,4) = mapdata->bgscore_eagle;
  15164. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  15165. }
  15166. void clif_bg_updatescore_single(map_session_data *sd)
  15167. {
  15168. int fd;
  15169. nullpo_retv(sd);
  15170. fd = sd->fd;
  15171. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  15172. WFIFOHEAD(fd,packet_len(0x2de));
  15173. WFIFOW(fd,0) = 0x2de;
  15174. WFIFOW(fd,2) = mapdata->bgscore_lion;
  15175. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  15176. WFIFOSET(fd,packet_len(0x2de));
  15177. }
  15178. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  15179. /// 02dd <account id>.L <name>.24B <camp>.W
  15180. void clif_sendbgemblem_area(map_session_data *sd)
  15181. {
  15182. unsigned char buf[33];
  15183. nullpo_retv(sd);
  15184. WBUFW(buf, 0) = 0x2dd;
  15185. WBUFL(buf,2) = sd->bl.id;
  15186. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  15187. WBUFW(buf,30) = sd->bg_id;
  15188. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  15189. }
  15190. void clif_sendbgemblem_single(int fd, map_session_data *sd)
  15191. {
  15192. nullpo_retv(sd);
  15193. WFIFOHEAD(fd,32);
  15194. WFIFOW(fd,0) = 0x2dd;
  15195. WFIFOL(fd,2) = sd->bl.id;
  15196. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  15197. WFIFOW(fd,30) = sd->bg_id;
  15198. WFIFOSET(fd,packet_len(0x2dd));
  15199. }
  15200. /// Battlegrounds queue incoming apply request from client.
  15201. /// Queue types: 1 solo queue, 2 party queue, 4 guild queue.
  15202. /// 0x8d7 <queue type>.W <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_APPLY)
  15203. void clif_parse_bg_queue_apply_request(int fd, map_session_data *sd)
  15204. {
  15205. if (!battle_config.feature_bgqueue)
  15206. return;
  15207. nullpo_retv(sd);
  15208. short type = RFIFOW(fd,2);
  15209. char name[NAME_LENGTH];
  15210. safestrncpy(name, RFIFOCP(fd, 4), NAME_LENGTH);
  15211. if (sd->bg_queue_id > 0) {
  15212. //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);
  15213. clif_bg_queue_apply_result(BG_APPLY_DUPLICATE, name, sd); // Duplicate application warning
  15214. return;
  15215. } else if (type == 1) // Solo
  15216. bg_queue_join_solo(name, sd);
  15217. else if (type == 2) // Party
  15218. bg_queue_join_party(name, sd);
  15219. else if (type == 4) // Guild
  15220. bg_queue_join_guild(name, sd);
  15221. else {
  15222. 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);
  15223. clif_bg_queue_apply_result(BG_APPLY_INVALID_APP, name, sd); // Someone sent an invalid queue type packet
  15224. return;
  15225. }
  15226. }
  15227. /// Outgoing battlegrounds queue apply result.
  15228. /// Result types: @see e_bg_queue_apply_ack
  15229. /// 0x8d8 <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_APPLY)
  15230. void clif_bg_queue_apply_result(e_bg_queue_apply_ack result, const char *name, map_session_data *sd)
  15231. {
  15232. nullpo_retv(sd);
  15233. int fd = sd->fd;
  15234. WFIFOHEAD(fd, packet_len(0x8d8));
  15235. WFIFOW(fd,0) = 0x8d8;
  15236. WFIFOB(fd,2) = result;
  15237. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15238. WFIFOSET(fd, packet_len(0x8d8));
  15239. }
  15240. /// Outgoing battlegrounds queue apply notification.
  15241. /// Sends a notification at the start of the battlegrounds queue and is also used to update the queue number.
  15242. /// 0x8d9 <battleground name>.24B <queue number>.L (ZC_NOTIFY_ENTRY_QUEUE_APPLY)
  15243. void clif_bg_queue_apply_notify(const char *name, map_session_data *sd)
  15244. {
  15245. nullpo_retv(sd);
  15246. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15247. if (queue == nullptr) {
  15248. ShowError("clif_bg_queue_apply_notify: Player is not in a battleground queue.\n");
  15249. return;
  15250. }
  15251. int fd = sd->fd;
  15252. WFIFOHEAD(fd, packet_len(0x8d9));
  15253. WFIFOW(fd,0) = 0x8d9;
  15254. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15255. WFIFOL(fd,2+NAME_LENGTH) = static_cast<int32>( queue->teama_members.size() + queue->teamb_members.size() );
  15256. WFIFOSET(fd, packet_len(0x8d9));
  15257. }
  15258. /// Battlegrounds queue outgoing cancel result.
  15259. /// 0x8db <result>.B <battleground name>.24B (ZC_ACK_ENTRY_QUEUE_CANCEL)
  15260. void clif_bg_queue_cancel_result(bool success, const char *name, map_session_data *sd)
  15261. {
  15262. nullpo_retv(sd);
  15263. int fd = sd->fd;
  15264. WFIFOHEAD(fd, packet_len(0x8d8));
  15265. WFIFOW(fd,0) = 0x8db;
  15266. WFIFOB(fd,2) = success;
  15267. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15268. WFIFOSET(fd, packet_len(0x8d8));
  15269. }
  15270. /// Battlegrounds queue incoming cancel request from client.
  15271. /// 0x8da <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_CANCEL)
  15272. void clif_parse_bg_queue_cancel_request(int fd, map_session_data *sd)
  15273. {
  15274. if (!battle_config.feature_bgqueue)
  15275. return;
  15276. nullpo_retv(sd);
  15277. bool success;
  15278. if (sd->bg_queue_id > 0) {
  15279. std::shared_ptr<s_battleground_queue> queue = bg_search_queue(sd->bg_queue_id);
  15280. if (queue && queue->state == QUEUE_STATE_SETUP_DELAY)
  15281. 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.
  15282. else
  15283. success = bg_queue_leave(sd);
  15284. } else {
  15285. 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);
  15286. success = false;
  15287. }
  15288. char name[NAME_LENGTH];
  15289. safestrncpy( name, RFIFOCP( fd, 2 ), NAME_LENGTH );
  15290. clif_bg_queue_cancel_result(success, name, sd);
  15291. }
  15292. /// Battleground is ready to be joined, send a window asking for players to accept or decline.
  15293. /// 0x8df <battleground name>.24B <lobby name>.24B (ZC_NOTIFY_LOBBY_ADMISSION)
  15294. void clif_bg_queue_lobby_notify(const char *name, map_session_data *sd)
  15295. {
  15296. nullpo_retv(sd);
  15297. int fd = sd->fd;
  15298. WFIFOHEAD(fd, packet_len(0x8df));
  15299. WFIFOW(fd,0) = 0x8df;
  15300. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  15301. safestrncpy(WFIFOCP(fd,2+NAME_LENGTH), name, NAME_LENGTH);
  15302. WFIFOSET(fd, packet_len(0x8df));
  15303. }
  15304. /// Incoming packet from client telling server whether player wants to enter battleground or cancel.
  15305. /// Result types: 1(Accept), 2(Decline).
  15306. /// 0x8e0 <result>.B <battleground name>.24B <lobby name>.24B (CZ_REPLY_LOBBY_ADMISSION)
  15307. void clif_parse_bg_queue_lobby_reply(int fd, map_session_data *sd)
  15308. {
  15309. nullpo_retv(sd);
  15310. if(sd->bg_queue_id > 0) {
  15311. uint8 result = RFIFOB(fd, 2);
  15312. if(result == 1) { // Accept
  15313. bg_queue_on_accept_invite(sd);
  15314. } else if(result == 2) { // Decline
  15315. bg_queue_leave(sd);
  15316. clif_bg_queue_entry_init(sd);
  15317. }
  15318. }
  15319. }
  15320. /// Plays a gong sound, signaling that someone has accepted the invite to enter a battleground.
  15321. /// 0x8e1 <result>.B <battleground name>.24B <lobby name>.24B (ZC_REPLY_ACK_LOBBY_ADMISSION)
  15322. void clif_bg_queue_ack_lobby(bool result, const char *name, const char *lobbyname, map_session_data *sd)
  15323. {
  15324. nullpo_retv(sd);
  15325. int fd = sd->fd;
  15326. WFIFOHEAD(fd, packet_len(0x8e1));
  15327. WFIFOW(fd,0) = 0x8e1;
  15328. WFIFOB(fd,2) = result;
  15329. safestrncpy(WFIFOCP(fd,3), name, NAME_LENGTH);
  15330. safestrncpy(WFIFOCP(fd,3+NAME_LENGTH), lobbyname, NAME_LENGTH);
  15331. WFIFOSET(fd, packet_len(0x8e1));
  15332. }
  15333. /// Battlegrounds queue incoming queue number request from client.
  15334. /// 0x90a <battleground name>.24B (CZ_REQ_ENTRY_QUEUE_RANKING)
  15335. void clif_parse_bg_queue_request_queue_number(int fd, map_session_data *sd)
  15336. {
  15337. nullpo_retv(sd);
  15338. char name[NAME_LENGTH];
  15339. safestrncpy( name, RFIFOCP(fd, 2), NAME_LENGTH );
  15340. clif_bg_queue_apply_notify(name, sd);
  15341. }
  15342. /// Silently removes all the battlegrounds stuff client side so that you will open the first BG window when you press battle on the interface.
  15343. /// Send this when a player joins a battleground so that it will remove all the queue stuff upon warping in.
  15344. /// 0x90e (ZC_ENTRY_QUEUE_INIT)
  15345. void clif_bg_queue_entry_init(map_session_data *sd)
  15346. {
  15347. nullpo_retv(sd);
  15348. struct PACKET_ZC_ENTRY_QUEUE_INIT p = {};
  15349. p.packetType = HEADER_ZC_ENTRY_QUEUE_INIT;
  15350. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15351. }
  15352. /// Custom Fonts (ZC_NOTIFY_FONT).
  15353. /// 02ef <account_id>.L <font id>.W
  15354. void clif_font(map_session_data *sd)
  15355. {
  15356. #if PACKETVER >= 20080102
  15357. unsigned char buf[8];
  15358. nullpo_retv(sd);
  15359. WBUFW(buf,0) = 0x2ef;
  15360. WBUFL(buf,2) = sd->bl.id;
  15361. WBUFW(buf,6) = sd->status.font;
  15362. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  15363. #endif
  15364. }
  15365. /// Required to start the instancing information window on Client
  15366. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  15367. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  15368. void clif_instance_create( int instance_id, size_t num ){
  15369. #if PACKETVER >= 20071128
  15370. map_session_data *sd = nullptr;
  15371. enum send_target target = PARTY;
  15372. unsigned char buf[65];
  15373. instance_getsd(instance_id, sd, &target);
  15374. if (!sd)
  15375. return;
  15376. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15377. if (!db)
  15378. return;
  15379. WBUFW(buf,0) = 0x2cb;
  15380. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15381. WBUFW( buf, 63 ) = static_cast<int16>( num );
  15382. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  15383. #endif
  15384. }
  15385. /// To announce Instancing queue creation if no maps available
  15386. /// S 0x2cc <Standby Position>.W
  15387. void clif_instance_changewait(int instance_id, int num)
  15388. {
  15389. #if PACKETVER >= 20071128
  15390. map_session_data *sd = nullptr;
  15391. enum send_target target = PARTY;
  15392. unsigned char buf[4];
  15393. instance_getsd(instance_id, sd, &target);
  15394. if (!sd)
  15395. return;
  15396. WBUFW(buf,0) = 0x2cc;
  15397. WBUFW(buf,2) = num;
  15398. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  15399. #endif
  15400. return;
  15401. }
  15402. /// Notify the current status to members
  15403. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  15404. void clif_instance_status(int instance_id, unsigned int limit1, unsigned int limit2)
  15405. {
  15406. #if PACKETVER >= 20071128
  15407. map_session_data *sd = nullptr;
  15408. enum send_target target = PARTY;
  15409. unsigned char buf[71];
  15410. instance_getsd(instance_id, sd, &target);
  15411. if (!sd)
  15412. return;
  15413. std::shared_ptr<s_instance_db> db = instance_db.find(util::umap_find(instances, instance_id)->id);
  15414. if (!db)
  15415. return;
  15416. WBUFW(buf,0) = 0x2cd;
  15417. safestrncpy(WBUFCP(buf,2), db->name.c_str(), INSTANCE_NAME_LENGTH);
  15418. WBUFL(buf,63) = limit1;
  15419. WBUFL(buf,67) = limit2;
  15420. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  15421. #endif
  15422. return;
  15423. }
  15424. /// Notify a status change to members
  15425. /// S 0x2ce <Message ID>.L
  15426. /// 0 = Notification (EnterLimitDate update?)
  15427. /// 1 = The Memorial Dungeon expired; it has been destroyed
  15428. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  15429. /// 3 = The Memorial Dungeon has been removed.
  15430. /// 4 = Create failure (removes the instance window)
  15431. void clif_instance_changestatus(int instance_id, e_instance_notify type, unsigned int limit)
  15432. {
  15433. #if PACKETVER >= 20071128
  15434. map_session_data *sd = nullptr;
  15435. enum send_target target = PARTY;
  15436. unsigned char buf[10];
  15437. instance_getsd(instance_id, sd, &target);
  15438. if (!sd)
  15439. return;
  15440. WBUFW(buf,0) = 0x2ce;
  15441. WBUFL(buf,2) = type;
  15442. WBUFL(buf,6) = limit;
  15443. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  15444. #endif
  15445. return;
  15446. }
  15447. /// Destroy an instance from the status window
  15448. /// 02cf <command>.L (CZ_MEMORIALDUNGEON_COMMAND)
  15449. void clif_parse_MemorialDungeonCommand(int fd, map_session_data *sd)
  15450. {
  15451. if (pc_istrading(sd) || pc_isdead(sd) || map_getmapdata(sd->bl.m)->instance_id > 0)
  15452. return;
  15453. const PACKET_CZ_MEMORIALDUNGEON_COMMAND *p = (PACKET_CZ_MEMORIALDUNGEON_COMMAND *)RFIFOP(fd, 0);
  15454. switch (p->command) {
  15455. case COMMAND_MEMORIALDUNGEON_DESTROY_FORCE:
  15456. instance_destroy_command(sd);
  15457. break;
  15458. }
  15459. }
  15460. void clif_instance_info( map_session_data& sd ){
  15461. if( sd.instance_id > 0 ){
  15462. instance_reqinfo( &sd, sd.instance_id );
  15463. }
  15464. if( sd.status.party_id > 0 ){
  15465. struct party_data* p = party_search( sd.status.party_id );
  15466. if( p != nullptr && p->instance_id > 0 ){
  15467. instance_reqinfo( &sd, p->instance_id );
  15468. }
  15469. }
  15470. if( sd.guild != nullptr && sd.guild->instance_id > 0 ){
  15471. instance_reqinfo( &sd, sd.guild->instance_id );
  15472. }
  15473. if( sd.clan != nullptr && sd.clan->instance_id > 0 ){
  15474. instance_reqinfo( &sd, sd.clan->instance_id );
  15475. }
  15476. }
  15477. /// Notifies clients about item picked up by a party member.
  15478. /// 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)
  15479. void clif_party_show_picker( map_session_data* sd, struct item* item_data ){
  15480. #if PACKETVER >= 20071002
  15481. nullpo_retv( sd );
  15482. nullpo_retv( item_data );
  15483. struct item_data* id = itemdb_search( item_data->nameid );
  15484. struct PACKET_ZC_ITEM_PICKUP_PARTY p;
  15485. p.packetType = HEADER_ZC_ITEM_PICKUP_PARTY;
  15486. p.AID = sd->status.account_id;
  15487. p.itemId = client_nameid( item_data->nameid );
  15488. p.identified = item_data->identify;
  15489. p.damaged = item_data->attribute;
  15490. p.refine = item_data->refine;
  15491. clif_addcards( &p.slot, item_data );
  15492. p.location = id->equip; // equip location
  15493. p.itemType = itemtype( id->nameid ); // item type
  15494. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15495. p.grade = item_data->enchantgrade;
  15496. #endif
  15497. clif_send( &p, sizeof( p ), &sd->bl, PARTY_SAMEMAP_WOS );
  15498. #endif
  15499. }
  15500. /** Display gained exp.
  15501. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  15502. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  15503. * amount: INT32_MIN ~ INT32_MAX
  15504. * var id:
  15505. * SP_BASEEXP, SP_JOBEXP
  15506. * exp type:
  15507. * 0 = normal exp gained/lost
  15508. * 1 = quest exp gained/lost
  15509. * @param sd Player
  15510. * @param exp EXP value gained/loss
  15511. * @param type SP_BASEEXP, SP_JOBEXP
  15512. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  15513. * @param lost True:if losing EXP
  15514. */
  15515. void clif_displayexp(map_session_data *sd, t_exp exp, char type, bool quest, bool lost)
  15516. {
  15517. int fd;
  15518. int offset;
  15519. #if PACKETVER >= 20170830
  15520. int cmd = 0xacc;
  15521. #else
  15522. int cmd = 0x7f6;
  15523. #endif
  15524. nullpo_retv(sd);
  15525. fd = sd->fd;
  15526. WFIFOHEAD(fd, packet_len(cmd));
  15527. WFIFOW(fd,0) = cmd;
  15528. WFIFOL(fd,2) = sd->bl.id;
  15529. #if PACKETVER >= 20170830
  15530. WFIFOQ(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15531. offset = 4;
  15532. #else
  15533. WFIFOL(fd,6) = client_exp(exp) * (lost ? -1 : 1);
  15534. offset = 0;
  15535. #endif
  15536. WFIFOW(fd,10+offset) = type;
  15537. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  15538. WFIFOSET(fd,packet_len(cmd));
  15539. }
  15540. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  15541. /// type:
  15542. /// 0 = Displays 'value' for 5 seconds.
  15543. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  15544. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  15545. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  15546. /// value:
  15547. /// 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).
  15548. void clif_showdigit(map_session_data* sd, unsigned char type, int value)
  15549. {
  15550. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  15551. WFIFOW(sd->fd,0) = 0x1b1;
  15552. WFIFOB(sd->fd,2) = type;
  15553. WFIFOL(sd->fd,3) = value;
  15554. WFIFOSET(sd->fd, packet_len(0x1b1));
  15555. }
  15556. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  15557. /// 021d <state>.L
  15558. /// state:
  15559. /// 0 = Full effects
  15560. /// 1 = Reduced effects
  15561. ///
  15562. /// NOTE: The state is used on Aegis for sending skill unit packet
  15563. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  15564. /// whenever possible. Due to the way the decision check is
  15565. /// constructed, this state tracking was rendered useless,
  15566. /// as the only skill unit, that is sent with 0x1c9 is
  15567. /// Graffiti.
  15568. void clif_parse_LessEffect(int fd, map_session_data* sd){
  15569. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15570. sd->state.lesseffect = ( isLess != 0 );
  15571. }
  15572. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  15573. void clif_parse_ItemListWindowSelected(int fd, map_session_data* sd) {
  15574. if( sd == nullptr ){
  15575. return;
  15576. }
  15577. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15578. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  15579. int type = RFIFOL(fd,info->pos[1]);
  15580. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  15581. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  15582. if( sd->state.trading || sd->npc_shopid )
  15583. return;
  15584. if( flag == 0 || n == 0) {
  15585. clif_menuskill_clear(sd);
  15586. return; // Canceled by player.
  15587. }
  15588. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  15589. clif_menuskill_clear(sd);
  15590. return; // Prevent hacking.
  15591. }
  15592. switch( type ) {
  15593. case 0: // Change Material
  15594. skill_changematerial(sd,n,item_list);
  15595. break;
  15596. case 1: // Level 1: Pure to Rough
  15597. case 2: // Level 2: Rough to Pure
  15598. skill_elementalanalysis(*sd,n,type,item_list);
  15599. break;
  15600. }
  15601. clif_menuskill_clear(sd);
  15602. return;
  15603. }
  15604. /*==========================================
  15605. * Elemental System
  15606. *==========================================*/
  15607. void clif_elemental_updatestatus(map_session_data *sd, int type) {
  15608. s_elemental_data *ed;
  15609. struct status_data *status;
  15610. int fd;
  15611. if( !clif_session_isValid(sd) || (ed = sd->ed) == nullptr )
  15612. return;
  15613. fd = sd->fd;
  15614. status = &ed->battle_status;
  15615. WFIFOHEAD(fd,8);
  15616. WFIFOW(fd,0) = 0x81e;
  15617. WFIFOW(fd,2) = type;
  15618. switch( type ) {
  15619. case SP_HP:
  15620. WFIFOL(fd,4) = status->hp;
  15621. break;
  15622. case SP_MAXHP:
  15623. WFIFOL(fd,4) = status->max_hp;
  15624. break;
  15625. case SP_SP:
  15626. WFIFOL(fd,4) = status->sp;
  15627. break;
  15628. case SP_MAXSP:
  15629. WFIFOL(fd,4) = status->max_sp;
  15630. break;
  15631. }
  15632. WFIFOSET(fd,8);
  15633. }
  15634. void clif_elemental_info(map_session_data *sd) {
  15635. int fd;
  15636. s_elemental_data *ed;
  15637. struct status_data *status;
  15638. if( !clif_session_isValid(sd) || (ed = sd->ed) == nullptr )
  15639. return;
  15640. fd = sd->fd;
  15641. status = &ed->battle_status;
  15642. WFIFOHEAD(fd,22);
  15643. WFIFOW(fd, 0) = 0x81d;
  15644. WFIFOL(fd, 2) = ed->bl.id;
  15645. WFIFOL(fd, 6) = status->hp;
  15646. WFIFOL(fd,10) = status->max_hp;
  15647. WFIFOL(fd,14) = status->sp;
  15648. WFIFOL(fd,18) = status->max_sp;
  15649. WFIFOSET(fd,22);
  15650. }
  15651. /// Buying Store System
  15652. ///
  15653. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15654. /// 0810 <slots>.B
  15655. void clif_buyingstore_open(map_session_data* sd)
  15656. {
  15657. int fd = sd->fd;
  15658. WFIFOHEAD(fd,packet_len(0x810));
  15659. WFIFOW(fd,0) = 0x810;
  15660. WFIFOB(fd,2) = sd->buyingstore.slots;
  15661. WFIFOSET(fd,packet_len(0x810));
  15662. }
  15663. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15664. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15665. /// result:
  15666. /// 0 = cancel
  15667. /// 1 = open
  15668. static void clif_parse_ReqOpenBuyingStore( int fd, map_session_data* sd ){
  15669. const struct PACKET_CZ_REQ_OPEN_BUYING_STORE *p = (struct PACKET_CZ_REQ_OPEN_BUYING_STORE *)RFIFOP( fd, 0 );
  15670. // TODO: Make this check global for all variable length packets.
  15671. // minimum packet length
  15672. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ) ){
  15673. ShowError( "clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%" PRIdPTR ", length=%u, account_id=%d).\n", sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE ), p->packetLength, sd->bl.id );
  15674. return;
  15675. }
  15676. if (map_getmapflag(sd->bl.m, MF_NOBUYINGSTORE)) {
  15677. clif_displaymessage(sd->fd, msg_txt(sd, 276)); // "You can't open a shop on this map"
  15678. return;
  15679. }
  15680. if (map_getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOBUYINGSTORE)) {
  15681. clif_displaymessage(sd->fd, msg_txt(sd, 204)); // "You can't open a shop on this cell."
  15682. return;
  15683. }
  15684. char storename[MESSAGE_SIZE];
  15685. safestrncpy( storename, p->storeName, sizeof( storename ) );
  15686. // so that buyingstore_create knows, how many elements it has access to
  15687. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE );
  15688. if( packet_len % sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) ){
  15689. ShowError( "clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%" PRIdPTR ")\n", packet_len, sd->bl.id, sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ) );
  15690. return;
  15691. }
  15692. buyingstore_create( sd, p->zenyLimit, p->result, storename, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_OPEN_BUYING_STORE_sub ), nullptr );
  15693. }
  15694. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15695. /// 0812 <result>.W <total weight>.L
  15696. /// result:
  15697. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15698. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15699. /// 8 = "No sale (purchase) information available." (0x705)
  15700. /// ? = nothing
  15701. void clif_buyingstore_open_failed(map_session_data* sd, unsigned short result, unsigned int weight)
  15702. {
  15703. int fd = sd->fd;
  15704. WFIFOHEAD(fd,packet_len(0x812));
  15705. WFIFOW(fd,0) = 0x812;
  15706. WFIFOW(fd,2) = result;
  15707. WFIFOL(fd,4) = weight;
  15708. WFIFOSET(fd,packet_len(0x812));
  15709. }
  15710. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15711. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15712. void clif_buyingstore_myitemlist( map_session_data* sd ){
  15713. nullpo_retv( sd );
  15714. int fd = sd->fd;
  15715. if( !session_isActive( fd ) ){
  15716. return;
  15717. }
  15718. int length = sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE ) + sd->buyingstore.slots * sizeof( struct PACKET_ZC_MYITEMLIST_BUYING_STORE_sub );
  15719. WFIFOHEAD( fd, length );
  15720. struct PACKET_ZC_MYITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_MYITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15721. p->packetType = 0x813;
  15722. p->packetLength = length;
  15723. p->AID = sd->bl.id;
  15724. p->zenyLimit = sd->buyingstore.zenylimit;
  15725. for( int i = 0; i < sd->buyingstore.slots; i++ ){
  15726. p->items[i].price = sd->buyingstore.items[i].price;
  15727. p->items[i].amount = sd->buyingstore.items[i].amount;
  15728. p->items[i].itemType = itemtype( sd->buyingstore.items[i].nameid );
  15729. p->items[i].itemId = client_nameid( sd->buyingstore.items[i].nameid );
  15730. }
  15731. WFIFOSET( fd, p->packetLength );
  15732. }
  15733. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15734. /// 0814 <account id>.L <store name>.80B
  15735. void clif_buyingstore_entry( map_session_data& sd, struct block_list* tbl ){
  15736. #if PACKETVER >= 20100420
  15737. enum send_target target;
  15738. if( tbl == nullptr ){
  15739. tbl = &sd.bl;
  15740. target = AREA_WOS;
  15741. }else{
  15742. target = SELF;
  15743. }
  15744. struct PACKET_ZC_BUYING_STORE_ENTRY p = {};
  15745. p.packetType = HEADER_ZC_BUYING_STORE_ENTRY;
  15746. p.makerAID = sd.status.account_id;
  15747. safestrncpy( p.storeName, sd.message, sizeof( p.storeName ) );
  15748. clif_send( &p, sizeof( p ), tbl, target );
  15749. #endif
  15750. }
  15751. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15752. /// 0815
  15753. static void clif_parse_ReqCloseBuyingStore(int fd, map_session_data* sd)
  15754. {
  15755. buyingstore_close(sd);
  15756. }
  15757. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15758. /// 0816 <account id>.L
  15759. void clif_buyingstore_disappear_entry( map_session_data& sd, struct block_list* tbl ){
  15760. #if PACKETVER >= 20100309
  15761. enum send_target target;
  15762. if( tbl == nullptr ){
  15763. tbl = &sd.bl;
  15764. target = AREA_WOS;
  15765. }else{
  15766. target = SELF;
  15767. }
  15768. struct PACKET_ZC_DISAPPEAR_BUYING_STORE_ENTRY p = {};
  15769. p.packetType = HEADER_ZC_DISAPPEAR_BUYING_STORE_ENTRY;
  15770. p.makerAID = sd.status.account_id;
  15771. clif_send( &p, sizeof( p ), tbl, target );
  15772. #endif
  15773. }
  15774. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15775. /// 0817 <account id>.L
  15776. static void clif_parse_ReqClickBuyingStore(int fd, map_session_data* sd)
  15777. {
  15778. uint32 account_id;
  15779. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15780. buyingstore_open(sd, account_id);
  15781. }
  15782. /// Sends buying store item list.
  15783. /// 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)
  15784. void clif_buyingstore_itemlist( map_session_data* sd, map_session_data* pl_sd ){
  15785. nullpo_retv( sd );
  15786. nullpo_retv( pl_sd );
  15787. int fd = sd->fd;
  15788. if( !session_isActive( fd ) ){
  15789. return;
  15790. }
  15791. int length = sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE ) + pl_sd->buyingstore.slots * sizeof( struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE_sub );
  15792. WFIFOHEAD( fd, length );
  15793. struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *p = (struct PACKET_ZC_ACK_ITEMLIST_BUYING_STORE *)WFIFOP( fd, 0 );
  15794. p->packetType = 0x818;
  15795. p->packetLength = length;
  15796. p->AID = pl_sd->bl.id;
  15797. p->storeId = pl_sd->buyer_id;
  15798. p->zenyLimit = pl_sd->buyingstore.zenylimit;
  15799. for( int i = 0; i < pl_sd->buyingstore.slots; i++ ){
  15800. p->items[i].price = pl_sd->buyingstore.items[i].price;
  15801. p->items[i].amount = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  15802. p->items[i].itemType = itemtype(pl_sd->buyingstore.items[i].nameid);
  15803. p->items[i].itemId = client_nameid( pl_sd->buyingstore.items[i].nameid );
  15804. }
  15805. WFIFOSET( fd, p->packetLength );
  15806. }
  15807. /// Request to sell items to a buying store.
  15808. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }* (CZ_REQ_TRADE_BUYING_STORE)
  15809. static void clif_parse_ReqTradeBuyingStore( int fd, map_session_data* sd ){
  15810. const struct PACKET_CZ_REQ_TRADE_BUYING_STORE *p = (struct PACKET_CZ_REQ_TRADE_BUYING_STORE *)RFIFOP( fd, 0 );
  15811. // minimum packet length
  15812. if( p->packetLength < sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ) ){
  15813. ShowError( "clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%" PRIdPTR ", length=%u, account_id=%d).\n", sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE ), p->packetLength, sd->bl.id );
  15814. return;
  15815. }
  15816. // so that buyingstore_trade knows, how many elements it has access to
  15817. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE );
  15818. if( packet_len % sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) ){
  15819. ShowError( "clif_parse_ReqTradeBuyingStore: Unexpected item list size %u (account_id=%d, buyer_id=%d, block size=%" PRIdPTR ")\n", packet_len, sd->bl.id, p->AID, sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15820. return;
  15821. }
  15822. buyingstore_trade( sd, p->AID, p->storeId, p->items, packet_len / sizeof( struct PACKET_CZ_REQ_TRADE_BUYING_STORE_sub ) );
  15823. }
  15824. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15825. /// 081a <result>.W
  15826. /// result:
  15827. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15828. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15829. /// ? = nothing
  15830. void clif_buyingstore_trade_failed_buyer(map_session_data* sd, short result)
  15831. {
  15832. int fd = sd->fd;
  15833. WFIFOHEAD(fd,packet_len(0x81a));
  15834. WFIFOW(fd,0) = 0x81a;
  15835. WFIFOW(fd,2) = result;
  15836. WFIFOSET(fd,packet_len(0x81a));
  15837. }
  15838. /// Updates the zeny limit and an item in the buying store item list.
  15839. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15840. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15841. void clif_buyingstore_update_item( map_session_data* sd, t_itemid nameid, unsigned short amount, uint32 char_id, int zeny ){
  15842. struct PACKET_ZC_UPDATE_ITEM_FROM_BUYING_STORE p;
  15843. p.packetType = buyingStoreUpdateItemType;
  15844. p.itemId = client_nameid( nameid );
  15845. p.amount = amount;
  15846. p.zenyLimit = sd->buyingstore.zenylimit;
  15847. #if PACKETVER >= 20141016
  15848. p.zeny = zeny;
  15849. p.charId = char_id; // GID
  15850. p.updateTime = (int)time(nullptr);
  15851. #endif
  15852. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15853. }
  15854. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15855. /// 081c <index>.W <amount>.W <price>.L
  15856. /// message:
  15857. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15858. ///
  15859. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15860. void clif_buyingstore_delete_item(map_session_data* sd, short index, unsigned short amount, int price)
  15861. {
  15862. int fd = sd->fd;
  15863. WFIFOHEAD(fd,packet_len(0x81c));
  15864. WFIFOW(fd,0) = 0x81c;
  15865. WFIFOW(fd,2) = client_index( index );
  15866. WFIFOW(fd,4) = amount;
  15867. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15868. WFIFOSET(fd,packet_len(0x81c));
  15869. }
  15870. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15871. /// 0824 <result>.W <name id>.W
  15872. /// result:
  15873. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15874. /// 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)
  15875. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15876. /// ? = nothing
  15877. void clif_buyingstore_trade_failed_seller( map_session_data* sd, short result, t_itemid nameid ){
  15878. struct PACKET_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER p;
  15879. p.packetType = HEADER_ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER;
  15880. p.result = result;
  15881. p.itemId = client_nameid( nameid );
  15882. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  15883. }
  15884. /// Search Store Info System
  15885. ///
  15886. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15887. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15888. /// type:
  15889. /// 0 = Vending
  15890. /// 1 = Buying Store
  15891. ///
  15892. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15893. /// amount of card slots. If the client does not know about the item it
  15894. /// cannot be searched.
  15895. static void clif_parse_SearchStoreInfo( int fd, map_session_data *sd ){
  15896. const struct PACKET_CZ_SEARCH_STORE_INFO *p = (struct PACKET_CZ_SEARCH_STORE_INFO *)RFIFOP( fd, 0 );
  15897. // minimum packet length
  15898. if( p->packetLength < sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ) ){
  15899. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected length=%" PRIdPTR ", length=%u, account_id=%d).\n", sizeof( struct PACKET_CZ_SEARCH_STORE_INFO ), p->packetLength, sd->bl.id );
  15900. return;
  15901. }
  15902. // check, if there is enough data for the claimed count of items
  15903. int packet_len = p->packetLength - sizeof( struct PACKET_CZ_SEARCH_STORE_INFO );
  15904. if( packet_len % sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) ){
  15905. ShowError( "clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%" PRIdPTR ")\n", packet_len, sd->bl.id, sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item ) );
  15906. return;
  15907. }
  15908. int count = packet_len / sizeof( struct PACKET_CZ_SEARCH_STORE_INFO_item );
  15909. if( count < p->itemsCount + p->cardsCount ){
  15910. ShowError( "clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", p->itemsCount + p->cardsCount, count, sd->bl.id );
  15911. return;
  15912. }
  15913. searchstore_query( sd, p->searchType, p->minPrice, p->maxPrice, &p->items[0], p->itemsCount, &p->items[p->itemsCount], p->cardsCount );
  15914. }
  15915. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15916. /// 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 }*
  15917. /// is first page:
  15918. /// 0 = appends to existing results
  15919. /// 1 = clears previous results before displaying this result set
  15920. /// is next page:
  15921. /// 0 = no "next" label
  15922. /// 1 = "next" label to retrieve more results
  15923. void clif_search_store_info_ack( map_session_data* sd ){
  15924. #if PACKETVER_MAIN_NUM >= 20100817 || PACKETVER_RE_NUM >= 20100706 || defined(PACKETVER_ZERO)
  15925. nullpo_retv( sd );
  15926. int fd = sd->fd;
  15927. if( !session_isActive( fd ) ){
  15928. return;
  15929. }
  15930. uint32 start = sd->searchstore.pages * SEARCHSTORE_RESULTS_PER_PAGE ;
  15931. uint32 end = umin( static_cast<uint32>( sd->searchstore.items.size() ), start + SEARCHSTORE_RESULTS_PER_PAGE );
  15932. int len = sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK ) + ( end - start ) * sizeof( struct PACKET_ZC_SEARCH_STORE_INFO_ACK_sub );
  15933. WFIFOHEAD( fd, len );
  15934. struct PACKET_ZC_SEARCH_STORE_INFO_ACK *p = (struct PACKET_ZC_SEARCH_STORE_INFO_ACK *)WFIFOP( fd, 0 );
  15935. p->packetType = HEADER_ZC_SEARCH_STORE_INFO_ACK;
  15936. p->packetLength = len;
  15937. p->firstPage = !sd->searchstore.pages;
  15938. p->nextPage = searchstore_querynext( sd );
  15939. p->usesCount = (uint8)umin( sd->searchstore.uses, UINT8_MAX );
  15940. for( int i = 0; i < end - start; i++ ) {
  15941. std::shared_ptr<s_search_store_info_item> ssitem = sd->searchstore.items[start + i];
  15942. p->items[i].storeId = ssitem->store_id;
  15943. p->items[i].AID = ssitem->account_id;
  15944. safestrncpy( p->items[i].shopName, ssitem->store_name, MESSAGE_SIZE );
  15945. p->items[i].itemId = client_nameid( ssitem->nameid );
  15946. p->items[i].itemType = itemtype( ssitem->nameid );
  15947. p->items[i].price = ssitem->price;
  15948. p->items[i].amount = ssitem->amount;
  15949. p->items[i].refine = ssitem->refine;
  15950. // make-up an item for clif_addcards
  15951. struct item it = {};
  15952. for( int j = 0; j < MAX_SLOTS; j++ ){
  15953. it.card[j] = ssitem->card[j];
  15954. }
  15955. it.nameid = ssitem->nameid;
  15956. it.amount = ssitem->amount;
  15957. clif_addcards( &p->items[i].slot, &it );
  15958. #if PACKETVER >= 20150226
  15959. clif_add_random_options( p->items[i].option_data, it );
  15960. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  15961. p->items[i].grade = ssitem->enchantgrade;
  15962. #endif
  15963. #endif
  15964. }
  15965. WFIFOSET( fd, len );
  15966. #endif
  15967. }
  15968. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15969. /// 0837 <reason>.B
  15970. /// reason:
  15971. /// 0 = "No matching stores were found." (0x70b)
  15972. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15973. /// 2 = "You cannot search anymore." (0x706)
  15974. /// 3 = "You cannot search yet." (0x708)
  15975. /// 4 = "No sale (purchase) information available." (0x705)
  15976. void clif_search_store_info_failed(map_session_data* sd, unsigned char reason)
  15977. {
  15978. int fd = sd->fd;
  15979. WFIFOHEAD(fd,packet_len(0x837));
  15980. WFIFOW(fd,0) = 0x837;
  15981. WFIFOB(fd,2) = reason;
  15982. WFIFOSET(fd,packet_len(0x837));
  15983. }
  15984. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15985. /// 0838
  15986. static void clif_parse_SearchStoreInfoNextPage(int fd, map_session_data* sd)
  15987. {
  15988. searchstore_next(sd);
  15989. }
  15990. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15991. /// 083a <type>.W <remaining uses>.B
  15992. /// type:
  15993. /// 0 = Search Stores
  15994. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15995. void clif_open_search_store_info(map_session_data* sd)
  15996. {
  15997. int fd = sd->fd;
  15998. WFIFOHEAD(fd,packet_len(0x83a));
  15999. WFIFOW(fd,0) = 0x83a;
  16000. WFIFOW(fd,2) = sd->searchstore.effect;
  16001. #if PACKETVER > 20100701
  16002. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  16003. #endif
  16004. WFIFOSET(fd,packet_len(0x83a));
  16005. }
  16006. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  16007. /// 083b
  16008. static void clif_parse_CloseSearchStoreInfo(int fd, map_session_data* sd)
  16009. {
  16010. searchstore_close(sd);
  16011. }
  16012. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  16013. /// 083c <account id>.L <store id>.L <nameid>.W
  16014. static void clif_parse_SearchStoreInfoListItemClick( int fd, map_session_data* sd ){
  16015. const struct PACKET_CZ_SSILIST_ITEM_CLICK *p = (struct PACKET_CZ_SSILIST_ITEM_CLICK *)RFIFOP( fd, 0 );
  16016. searchstore_click( sd, p->AID, p->storeId, p->itemId );
  16017. }
  16018. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  16019. /// 083d <xPos>.W <yPos>.W
  16020. void clif_search_store_info_click_ack(map_session_data* sd, short x, short y)
  16021. {
  16022. int fd = sd->fd;
  16023. WFIFOHEAD(fd,packet_len(0x83d));
  16024. WFIFOW(fd,0) = 0x83d;
  16025. WFIFOW(fd,2) = x;
  16026. WFIFOW(fd,4) = y;
  16027. WFIFOSET(fd,packet_len(0x83d));
  16028. }
  16029. /// Parse function for packet debugging.
  16030. void clif_parse_debug(int fd,map_session_data *sd)
  16031. {
  16032. int16 packet_len;
  16033. // clif_parse ensures, that there is at least 2 bytes of data
  16034. uint16 cmd = RFIFOW(fd,0);
  16035. if( sd ) {
  16036. packet_len = packet_db[cmd].len;
  16037. if( packet_len == 0 )
  16038. {// unknown
  16039. packet_len = static_cast<decltype(packet_len)>( RFIFOREST(fd) );
  16040. }
  16041. else if( packet_len == -1 )
  16042. {// variable length
  16043. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  16044. }
  16045. 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);
  16046. }
  16047. else
  16048. {
  16049. packet_len = static_cast<decltype(packet_len)>( RFIFOREST(fd) );
  16050. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  16051. }
  16052. ShowDump(RFIFOP(fd,0), packet_len);
  16053. }
  16054. /*==========================================
  16055. * Server tells client to display a window similar to Magnifier (item) one
  16056. * Server populates the window with avilable elemental converter options according to player's inventory
  16057. *------------------------------------------*/
  16058. void clif_elementalconverter_list( map_session_data& sd ){
  16059. PACKET_ZC_MAKINGARROW_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGARROW_LIST*>( packet_buffer );
  16060. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16061. p->packetLength = sizeof( *p );
  16062. int count = 0;
  16063. for( int i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ){
  16064. if( skill_can_produce_mix( &sd, skill_produce_db[i].nameid, 23, 1 ) ){
  16065. p->items[count].itemId = client_nameid( skill_produce_db[i].nameid );
  16066. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  16067. count++;
  16068. }
  16069. }
  16070. clif_send( p, p->packetLength, &sd.bl, SELF );
  16071. if( count > 0 ){
  16072. sd.menuskill_id = SA_CREATECON;
  16073. sd.menuskill_val = count;
  16074. }
  16075. }
  16076. /**
  16077. * Rune Knight
  16078. **/
  16079. void clif_millenniumshield(struct block_list *bl, short shields) {
  16080. #if PACKETVER >= 20081217
  16081. unsigned char buf[10];
  16082. WBUFW(buf,0) = 0x440;
  16083. WBUFL(buf,2) = bl->id;
  16084. WBUFW(buf,6) = shields;
  16085. WBUFW(buf,8) = 0;
  16086. clif_send(buf,packet_len(0x440),bl,AREA);
  16087. #endif
  16088. }
  16089. /**
  16090. * Mechanic
  16091. **/
  16092. /*==========================================
  16093. * Magic Decoy Material List
  16094. *------------------------------------------*/
  16095. void clif_magicdecoy_list( map_session_data& sd, uint16 skill_lv, short x, short y ){
  16096. PACKET_ZC_MAKINGARROW_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGARROW_LIST*>( packet_buffer );
  16097. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16098. p->packetLength = sizeof( *p );
  16099. size_t count = 0;
  16100. for( size_t i = 0; i < MAX_INVENTORY; i++ ){
  16101. if( itemdb_group.item_exists( IG_ELEMENT, sd.inventory.u.items_inventory[i].nameid ) ){
  16102. p->items[count].itemId = client_nameid( sd.inventory.u.items_inventory[i].nameid );
  16103. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  16104. count++;
  16105. }
  16106. }
  16107. if( count > 0 ){
  16108. clif_send( p, p->packetLength, &sd.bl, SELF );
  16109. sd.menuskill_id = NC_MAGICDECOY;
  16110. sd.menuskill_val = skill_lv;
  16111. sd.sc.comet_x = x;
  16112. sd.sc.comet_y = y;
  16113. }else{
  16114. clif_skill_fail( sd, NC_MAGICDECOY );
  16115. }
  16116. }
  16117. /*==========================================
  16118. * Guillotine Cross Poisons List
  16119. *------------------------------------------*/
  16120. void clif_poison_list( map_session_data& sd, uint16 skill_lv ){
  16121. PACKET_ZC_MAKINGARROW_LIST* p = reinterpret_cast<PACKET_ZC_MAKINGARROW_LIST*>( packet_buffer );
  16122. p->packetType = HEADER_ZC_MAKINGARROW_LIST;
  16123. p->packetLength = sizeof( *p );
  16124. size_t count = 0;
  16125. for( size_t i = 0; i < MAX_INVENTORY; i++ ){
  16126. if( itemdb_group.item_exists( IG_POISON, sd.inventory.u.items_inventory[i].nameid ) ){
  16127. p->items[count].itemId = client_nameid( sd.inventory.u.items_inventory[i].nameid );
  16128. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->items[0] ) );
  16129. count++;
  16130. }
  16131. }
  16132. if( count > 0 ){
  16133. clif_send( p, p->packetLength, &sd.bl, SELF );
  16134. sd.menuskill_id = GC_POISONINGWEAPON;
  16135. sd.menuskill_val = skill_lv;
  16136. }else{
  16137. clif_skill_fail( sd, GC_POISONINGWEAPON, USESKILL_FAIL_GUILLONTINE_POISON );
  16138. }
  16139. }
  16140. /// 0442 <Length>.W <why>.L { <Skill_Id>.W }* (ZC_SKILL_SELECT_REQUEST).
  16141. void clif_autoshadowspell_list( map_session_data& sd ){
  16142. #if PACKETVER >= 20081210
  16143. if( sd.menuskill_id == SC_AUTOSHADOWSPELL )
  16144. return;
  16145. PACKET_ZC_SKILL_SELECT_REQUEST* p = reinterpret_cast<PACKET_ZC_SKILL_SELECT_REQUEST*>( packet_buffer );
  16146. p->packetType = HEADER_ZC_SKILL_SELECT_REQUEST;
  16147. p->packetLength = sizeof( *p );
  16148. p->flag = 1; // enum PACKET_ZC_SKILL_SELECT_REQUEST::enumWHY::WHY_SC_AUTOSHADOWSPELL = 0x1
  16149. size_t count = 0;
  16150. for( size_t i = 0; i < MAX_SKILL; i++ ){
  16151. if( sd.status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd.status.skill[i].id > 0 &&
  16152. skill_get_inf2(sd.status.skill[i].id, INF2_ISAUTOSHADOWSPELL))
  16153. {
  16154. p->skillIds[count] = sd.status.skill[i].id;
  16155. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->skillIds[0] ) );
  16156. count++;
  16157. }
  16158. }
  16159. if( count > 0 ) {
  16160. clif_send( p, p->packetLength, &sd.bl, SELF );
  16161. sd.menuskill_id = SC_AUTOSHADOWSPELL;
  16162. sd.menuskill_val = static_cast<decltype(sd.menuskill_val)>( count );
  16163. } else {
  16164. status_change_end( &sd.bl, SC_STOP );
  16165. clif_skill_fail( sd, SC_AUTOSHADOWSPELL, USESKILL_FAIL_IMITATION_SKILL_NONE );
  16166. }
  16167. #endif
  16168. }
  16169. /*===========================================
  16170. * Skill list for Four Elemental Analysis
  16171. * and Change Material skills.
  16172. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  16173. *------------------------------------------*/
  16174. int clif_skill_itemlistwindow( map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  16175. #if PACKETVER >= 20090922
  16176. int fd = sd->fd;
  16177. nullpo_ret(sd);
  16178. sd->menuskill_id = skill_id; // To prevent hacking.
  16179. sd->menuskill_val = skill_lv;
  16180. if( skill_id == GN_CHANGEMATERIAL )
  16181. skill_lv = 0; // Changematerial
  16182. WFIFOHEAD(fd, packet_len(0x7e3));
  16183. WFIFOW(fd,0) = 0x7e3;
  16184. WFIFOL(fd,2) = skill_lv;
  16185. WFIFOL(fd,4) = 0;
  16186. WFIFOSET(fd, packet_len(0x7e3));
  16187. #endif
  16188. return 1;
  16189. }
  16190. /*==========================================
  16191. * Select a skill into a given list (used by SA_AUTOSPELL/SC_AUTOSHADOWSPELL)
  16192. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  16193. *------------------------------------------*/
  16194. void clif_parse_SkillSelectMenu(int fd, map_session_data *sd) {
  16195. #if PACKETVER >= 20081210
  16196. if( sd == nullptr ){
  16197. return;
  16198. }
  16199. PACKET_CZ_SKILL_SELECT_RESPONSE* p = reinterpret_cast<PACKET_CZ_SKILL_SELECT_RESPONSE*>( RFIFOP( fd, 0 ) );
  16200. if (sd->menuskill_id == SA_AUTOSPELL) {
  16201. sd->state.workinprogress = WIP_DISABLE_NONE;
  16202. skill_autospell(sd, p->selectedSkillId);
  16203. } else if (sd->menuskill_id == SC_AUTOSHADOWSPELL) {
  16204. if (pc_istrading(sd)) {
  16205. clif_skill_fail( *sd, sd->ud.skill_id );
  16206. clif_menuskill_clear(sd);
  16207. return;
  16208. }
  16209. skill_select_menu(*sd, p->selectedSkillId);
  16210. } else
  16211. return;
  16212. clif_menuskill_clear(sd);
  16213. #endif
  16214. }
  16215. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  16216. /// 08cf <id>.L <type>.W <num>.W
  16217. void clif_spiritcharm(map_session_data *sd) {
  16218. unsigned char buf[10];
  16219. nullpo_retv(sd);
  16220. WBUFW(buf,0) = 0x08cf;
  16221. WBUFL(buf,2) = sd->bl.id;
  16222. WBUFW(buf,6) = sd->spiritcharm_type;
  16223. WBUFW(buf,8) = sd->spiritcharm;
  16224. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  16225. }
  16226. /// Move Item from or to Personal Tab
  16227. /// 0907 <index>.W <type>.B (CZ_INVENTORY_TAB)
  16228. /// type:
  16229. /// 0 = move item to personal tab
  16230. /// 1 = move item to normal tab
  16231. void clif_parse_MoveItem( int fd, map_session_data* sd ){
  16232. // TODO: Check for correct packet version
  16233. #if PACKETVER >= 20120410
  16234. /* can't move while dead. */
  16235. if(pc_isdead(sd)) {
  16236. return;
  16237. }
  16238. PACKET_CZ_INVENTORY_TAB* p = (PACKET_CZ_INVENTORY_TAB*)RFIFOP( fd, 0 );
  16239. uint16 index = server_index( p->index );
  16240. if( index >= MAX_INVENTORY ){
  16241. return;
  16242. }
  16243. if ( sd->inventory.u.items_inventory[index].favorite != 0 && p->favorite == true )
  16244. sd->inventory.u.items_inventory[index].favorite = 0;
  16245. else if( p->favorite == false )
  16246. sd->inventory.u.items_inventory[index].favorite = 1;
  16247. else
  16248. return;/* nothing to do. */
  16249. clif_favorite_item( *sd, index );
  16250. #endif
  16251. }
  16252. /// Items that are in favorite tab of inventory.
  16253. /// 0908 <index>.W <favorite>.B (ZC_INVENTORY_TAB)
  16254. static void clif_favorite_item( map_session_data& sd, uint16 index ){
  16255. // TODO: Check for correct packet version
  16256. #if PACKETVER >= 20111122
  16257. PACKET_ZC_INVENTORY_TAB p = {};
  16258. p.packetType = HEADER_ZC_INVENTORY_TAB;
  16259. p.index = client_index( index );
  16260. p.favorite = ( sd.inventory.u.items_inventory[index].favorite == 1 ) ? false : true;
  16261. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16262. #endif
  16263. }
  16264. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  16265. void clif_snap( struct block_list *bl, short x, short y ) {
  16266. unsigned char buf[10];
  16267. WBUFW(buf,0) = 0x8d2;
  16268. WBUFL(buf,2) = bl->id;
  16269. WBUFW(buf,6) = x;
  16270. WBUFW(buf,8) = y;
  16271. if( disguised(bl) )
  16272. {
  16273. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  16274. WBUFL(buf,2) = disguised_bl_id(bl->id);
  16275. clif_send(buf, packet_len(0x8d2), bl, SELF);
  16276. } else
  16277. clif_send(buf,packet_len(0x8d2),bl, AREA);
  16278. }
  16279. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  16280. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  16281. #if PACKETVER >= 20120404
  16282. WFIFOHEAD(fd,packet_len(0x977));
  16283. WFIFOW(fd,0) = 0x977;
  16284. WFIFOL(fd,2) = md->bl.id;
  16285. WFIFOL(fd,6) = md->status.hp;
  16286. WFIFOL(fd,10) = md->status.max_hp;
  16287. WFIFOSET(fd,packet_len(0x977));
  16288. #endif
  16289. }
  16290. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  16291. void __attribute__ ((unused)) clif_parse_dull(int fd, map_session_data *sd) {
  16292. return;
  16293. }
  16294. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  16295. /// 0979 <world name>.24B <char name>.24B
  16296. void clif_ackworldinfo(map_session_data* sd) {
  16297. int fd;
  16298. nullpo_retv(sd);
  16299. fd = sd->fd;
  16300. WFIFOHEAD(fd,packet_len(0x979));
  16301. WFIFOW(fd,0)=0x979;
  16302. //AID -> world name ?
  16303. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  16304. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  16305. WFIFOSET(fd,packet_len(0x979));
  16306. }
  16307. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  16308. /// 0978 <AID>.L
  16309. void clif_parse_reqworldinfo(int fd,map_session_data *sd) {
  16310. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  16311. if(sd)
  16312. clif_ackworldinfo(sd);
  16313. }
  16314. static void clif_loadConfirm( map_session_data *sd ){
  16315. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320 || PACKETVER_ZERO_NUM >= 20190410
  16316. nullpo_retv( sd );
  16317. struct PACKET_ZC_NOTIFY_ACTORINIT p = {};
  16318. p.packetType = HEADER_ZC_NOTIFY_ACTORINIT;
  16319. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16320. clif_instance_info( *sd );
  16321. #endif
  16322. }
  16323. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  16324. /// 0447
  16325. void clif_parse_blocking_playcancel( int fd, map_session_data *sd ){
  16326. clif_loadConfirm( sd );
  16327. }
  16328. /// req world info (CZ_CLIENT_VERSION)
  16329. /// 044A <version>.L
  16330. void clif_parse_client_version(int fd, map_session_data *sd) {
  16331. //if(sd)
  16332. ;
  16333. }
  16334. /// Ranking list
  16335. /// ranking pointlist { <name>.24B <point>.L }*10
  16336. void clif_sub_ranklist(unsigned char *buf,int idx,map_session_data* sd, enum e_rank rankingtype){
  16337. struct fame_list* list;
  16338. int i, size = MAX_FAME_LIST;
  16339. switch(rankingtype) {
  16340. case RANK_BLACKSMITH: list = smith_fame_list; break;
  16341. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  16342. case RANK_TAEKWON: list = taekwon_fame_list; break;
  16343. // PK currently unsupported
  16344. case RANK_KILLER: list = nullptr; size = 0; break;
  16345. default:
  16346. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16347. return;
  16348. }
  16349. //Packet size limits this list to 10 elements. [Skotlex]
  16350. for (i = 0; i < min(10,size); i++) {
  16351. if (list[i].id > 0) {
  16352. const char* name;
  16353. if (strcmp(list[i].name, "-") == 0 &&
  16354. (name = map_charid2nick(list[i].id)) != nullptr)
  16355. {
  16356. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  16357. } else {
  16358. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  16359. }
  16360. } else {
  16361. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  16362. }
  16363. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  16364. }
  16365. for(;i < 10; i++) { //In case the MAX is less than 10.
  16366. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  16367. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  16368. }
  16369. }
  16370. /// Request for the blacksmith ranklist.
  16371. /// /blacksmith command sends this packet to the server.
  16372. /// 0217 (CZ_BLACKSMITH_RANK)
  16373. void clif_parse_Blacksmith( int fd, map_session_data *sd ){
  16374. clif_ranklist(sd,RANK_BLACKSMITH);
  16375. }
  16376. /// Request for the alchemist ranklist.
  16377. /// /alchemist command sends this packet to the server.
  16378. /// 0218 (CZ_ALCHEMIST_RANK)
  16379. void clif_parse_Alchemist( int fd, map_session_data *sd ){
  16380. clif_ranklist(sd,RANK_ALCHEMIST);
  16381. }
  16382. /// Request for the taekwon ranklist.
  16383. /// /taekwon command sends this packet to the server.
  16384. /// 0225 (CZ_TAEKWON_RANK)
  16385. void clif_parse_Taekwon( int fd, map_session_data *sd ){
  16386. clif_ranklist(sd,RANK_TAEKWON);
  16387. }
  16388. /// Request for the killer ranklist.
  16389. /// /pk command sends this packet to the server.
  16390. /// 0237 (CZ_KILLER_RANK)
  16391. void clif_parse_RankingPk( int fd, map_session_data *sd ){
  16392. clif_ranklist(sd,RANK_KILLER);
  16393. }
  16394. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  16395. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  16396. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  16397. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  16398. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  16399. void clif_ranklist(map_session_data *sd, int16 rankingType) {
  16400. enum e_rank rank;
  16401. #if PACKETVER < 20130710
  16402. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  16403. short cmd;
  16404. switch( rankingType ){
  16405. case RANK_BLACKSMITH: cmd = 0x219; break;
  16406. case RANK_ALCHEMIST: cmd = 0x21a; break;
  16407. case RANK_TAEKWON: cmd = 0x226; break;
  16408. case RANK_KILLER: cmd = 0x238; break;
  16409. default:
  16410. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16411. return;
  16412. }
  16413. // Can be safely casted here, since we validated it before
  16414. rank = (enum e_rank)rankingType;
  16415. WBUFW(buf,0) = cmd;
  16416. clif_sub_ranklist(buf,2,sd,rank);
  16417. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  16418. #else
  16419. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  16420. int mypoint = 0;
  16421. switch( rankingType ){
  16422. case RANK_BLACKSMITH:
  16423. case RANK_ALCHEMIST:
  16424. case RANK_TAEKWON:
  16425. case RANK_KILLER:
  16426. break;
  16427. default:
  16428. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  16429. return;
  16430. }
  16431. // Can be safely casted here, since we validated it before
  16432. rank = (enum e_rank)rankingType;
  16433. WBUFW(buf,0) = 0x97d;
  16434. WBUFW(buf,2) = rank;
  16435. clif_sub_ranklist(buf,4,sd,rank);
  16436. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  16437. case MAPID_BLACKSMITH:
  16438. case MAPID_ALCHEMIST:
  16439. case MAPID_TAEKWON:
  16440. mypoint = sd->status.fame;
  16441. }
  16442. WBUFL(buf,284) = mypoint; //mypoint
  16443. clif_send(buf, 288, &sd->bl, SELF);
  16444. #endif
  16445. }
  16446. /*
  16447. * 097c <type> (CZ_REQ_RANKING)
  16448. * type
  16449. * 0: /blacksmith
  16450. * 1: /alchemist
  16451. * 2: /taekwon
  16452. * 3: /pk
  16453. * */
  16454. void clif_parse_ranklist(int fd,map_session_data *sd) {
  16455. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  16456. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  16457. clif_ranklist(sd,rankingtype);
  16458. }
  16459. /// Updates the fame rank points for the given ranking.
  16460. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  16461. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  16462. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  16463. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  16464. void clif_update_rankingpoint(map_session_data &sd, int rankingtype, int point) {
  16465. int fd = sd.fd;
  16466. #if PACKETVER < 20130710
  16467. short cmd;
  16468. switch(rankingtype){
  16469. case RANK_BLACKSMITH: cmd = 0x21b; break;
  16470. case RANK_ALCHEMIST: cmd = 0x21c; break;
  16471. case RANK_TAEKWON: cmd = 0x224; break;
  16472. default:
  16473. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  16474. return;
  16475. }
  16476. WFIFOHEAD(fd,packet_len(cmd));
  16477. WFIFOW(fd,0) = cmd;
  16478. WFIFOL(fd,2) = point;
  16479. WFIFOL(fd,6) = sd.status.fame;
  16480. WFIFOSET(fd, packet_len(cmd));
  16481. #else
  16482. WFIFOHEAD(fd,packet_len(0x97e));
  16483. WFIFOW(fd,0) = 0x97e;
  16484. WFIFOW(fd,2) = rankingtype;
  16485. WFIFOL(fd,4) = point;
  16486. WFIFOL(fd,8) = sd.status.fame;
  16487. WFIFOSET(fd,packet_len(0x97e));
  16488. #endif
  16489. }
  16490. /**
  16491. * Transmit personal information to player. (rates)
  16492. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  16493. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  16494. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  16495. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  16496. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  16497. * FIXME!
  16498. * - Find/decide for details of EXP, Drop, and Death penalty rates
  16499. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  16500. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  16501. */
  16502. #ifdef VIP_ENABLE
  16503. void clif_display_pinfo( map_session_data& sd ){
  16504. #if PACKETVER_MAIN_NUM >= 20110627 || PACKETVER_RE_NUM >= 20110628 || defined(PACKETVER_ZERO)
  16505. // 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]
  16506. int details_bexp[PINFO_MAX], details_drop[PINFO_MAX], details_penalty[PINFO_MAX];
  16507. /**
  16508. * EXP
  16509. */
  16510. //0:PCRoom
  16511. details_bexp[PINFO_BASIC] = map_getmapflag( sd.bl.m, MF_BEXP );
  16512. if (details_bexp[PINFO_BASIC] == 100 || !details_bexp[PINFO_BASIC])
  16513. details_bexp[PINFO_BASIC] = 0;
  16514. else {
  16515. if (details_bexp[PINFO_BASIC] < 100) {
  16516. details_bexp[PINFO_BASIC] = 100 - details_bexp[PINFO_BASIC];
  16517. details_bexp[PINFO_BASIC] = 0 - details_bexp[PINFO_BASIC];
  16518. } else
  16519. details_bexp[PINFO_BASIC] = details_bexp[PINFO_BASIC] - 100;
  16520. }
  16521. //1:Premium
  16522. if( pc_isvip( &sd ) ){
  16523. details_bexp[PINFO_PREMIUM] = battle_config.vip_base_exp_increase * battle_config.base_exp_rate / 100;
  16524. if (details_bexp[PINFO_PREMIUM] < 0)
  16525. details_bexp[PINFO_PREMIUM] = 0 - details_bexp[PINFO_PREMIUM];
  16526. } else
  16527. details_bexp[PINFO_PREMIUM] = 0;
  16528. //2:Server
  16529. details_bexp[PINFO_SERVER] = battle_config.base_exp_rate;
  16530. if (details_bexp[PINFO_SERVER] == 100)
  16531. details_bexp[PINFO_SERVER] = 0;
  16532. else {
  16533. if (details_bexp[PINFO_SERVER] < 100) {
  16534. details_bexp[PINFO_SERVER] = 100 - details_bexp[PINFO_SERVER];
  16535. details_bexp[PINFO_SERVER] = 0 - details_bexp[PINFO_SERVER];
  16536. } else
  16537. details_bexp[PINFO_SERVER] = details_bexp[PINFO_SERVER] - 100;
  16538. }
  16539. //3:TPLUS
  16540. details_bexp[PINFO_CAFE] = 0;
  16541. /**
  16542. * Drop rate
  16543. */
  16544. //0:PCRoom
  16545. details_drop[PINFO_BASIC] = 0;
  16546. //1:Premium
  16547. if( pc_isvip( &sd ) ){
  16548. details_drop[PINFO_PREMIUM] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16549. if (details_drop[PINFO_PREMIUM] < 0)
  16550. details_drop[PINFO_PREMIUM] = 0 - details_drop[PINFO_PREMIUM];
  16551. } else
  16552. details_drop[PINFO_PREMIUM] = 0;
  16553. //2:Server
  16554. details_drop[PINFO_SERVER] = battle_config.item_rate_common;
  16555. if (details_drop[PINFO_SERVER] == 100)
  16556. details_drop[PINFO_SERVER] = 0;
  16557. else {
  16558. if (details_drop[PINFO_SERVER] < 100) {
  16559. details_drop[PINFO_SERVER] = 100 - details_drop[PINFO_SERVER];
  16560. details_drop[PINFO_SERVER] = 0 - details_drop[PINFO_SERVER];
  16561. } else
  16562. details_drop[PINFO_SERVER] = details_drop[PINFO_SERVER] - 100;
  16563. }
  16564. //3:TPLUS
  16565. details_drop[PINFO_CAFE] = 0;
  16566. /**
  16567. * Penalty rate
  16568. */
  16569. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16570. //0:PCRoom
  16571. details_penalty[PINFO_BASIC] = 0;
  16572. //1:Premium
  16573. if( pc_isvip( &sd ) ){
  16574. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base;
  16575. if (details_penalty[PINFO_PREMIUM] == 100)
  16576. details_penalty[PINFO_PREMIUM] = 0;
  16577. else {
  16578. if (details_penalty[PINFO_PREMIUM] < 100) {
  16579. details_penalty[PINFO_PREMIUM] = 100 - details_penalty[PINFO_PREMIUM];
  16580. details_penalty[PINFO_PREMIUM] = 0 - details_penalty[PINFO_PREMIUM];
  16581. } else
  16582. details_penalty[PINFO_PREMIUM] = details_penalty[PINFO_PREMIUM] - 100;
  16583. }
  16584. if (battle_config.death_penalty_base > battle_config.vip_exp_penalty_base)
  16585. details_penalty[PINFO_PREMIUM] = battle_config.vip_exp_penalty_base - battle_config.death_penalty_base;
  16586. } else
  16587. details_penalty[PINFO_PREMIUM] = 0;
  16588. //2:Server
  16589. details_penalty[PINFO_SERVER] = battle_config.death_penalty_base;
  16590. if (details_penalty[PINFO_SERVER] == 100)
  16591. details_penalty[PINFO_SERVER] = 0;
  16592. else {
  16593. if (details_penalty[PINFO_SERVER] < 100) {
  16594. details_penalty[PINFO_SERVER] = 100 - details_penalty[PINFO_SERVER];
  16595. details_penalty[PINFO_SERVER] = 0 - details_penalty[PINFO_SERVER];
  16596. } else
  16597. details_penalty[PINFO_SERVER] = details_penalty[PINFO_SERVER] - 100;
  16598. }
  16599. //3:TPLUS
  16600. details_penalty[PINFO_CAFE] = 0;
  16601. PACKET_ZC_PERSONAL_INFOMATION* p = reinterpret_cast<PACKET_ZC_PERSONAL_INFOMATION*>( packet_buffer );
  16602. p->packetType = HEADER_ZC_PERSONAL_INFOMATION;
  16603. p->length = sizeof( *p );
  16604. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16605. p->total_exp = 100 * 1000;
  16606. p->total_death = 100 * 1000;
  16607. p->total_drop = 100 * 1000;
  16608. #else
  16609. p->total_exp = 100;
  16610. p->total_death = 100;
  16611. p->total_drop = 100;
  16612. #endif
  16613. for( int i = PINFO_BASIC; i < PINFO_MAX; i++ ){
  16614. p->details[i].type = i; // infotype 0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16615. #if PACKETVER_MAIN_NUM >= 20120503 || PACKETVER_RE_NUM >= 20120502 || defined(PACKETVER_ZERO)
  16616. p->details[i].exp = details_bexp[i] * 1000;
  16617. p->details[i].death = details_penalty[i] * 1000;
  16618. p->details[i].drop = details_drop[i] * 1000;
  16619. #else
  16620. p->details[i].exp = details_bexp[i];
  16621. p->details[i].death = details_penalty[i];
  16622. p->details[i].drop = details_drop[i];
  16623. #endif
  16624. p->total_exp += p->details[i].exp;
  16625. p->total_death += p->details[i].death;
  16626. p->total_drop += p->details[i].drop;
  16627. p->length += static_cast<decltype(p->length)>( sizeof( p->details[0] ) );
  16628. }
  16629. clif_send( p, p->length, &sd.bl, SELF );
  16630. #endif
  16631. }
  16632. #endif
  16633. void clif_parse_GMFullStrip(int fd, map_session_data *sd) {
  16634. char cmd[30];
  16635. int t_aid = RFIFOL(fd,2);
  16636. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16637. is_atcommand(fd, sd, cmd, 1);
  16638. }
  16639. /**
  16640. * Marks Crimson Marker target on mini-map to the caster
  16641. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16642. * @param fd
  16643. * @param bl Crimson Marker target
  16644. **/
  16645. void clif_crimson_marker( map_session_data& sd, struct block_list& bl, bool remove ){
  16646. #if PACKETVER_MAIN_NUM >= 20130731 || PACKETVER_RE_NUM >= 20130707 || defined(PACKETVER_ZERO)
  16647. struct PACKET_ZC_C_MARKERINFO p = {};
  16648. p.PacketType = HEADER_ZC_C_MARKERINFO;
  16649. p.AID = bl.id;
  16650. if( remove ){
  16651. p.xPos = -1;
  16652. p.yPos = -1;
  16653. }else{
  16654. p.xPos = bl.x;
  16655. p.yPos = bl.y;
  16656. }
  16657. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16658. #endif
  16659. }
  16660. /**
  16661. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16662. **/
  16663. void clif_notify_bindOnEquip( map_session_data& sd, int16 index ){
  16664. #if PACKETVER >= 20070227
  16665. struct PACKET_ZC_NOTIFY_BIND_ON_EQUIP p = {};
  16666. p.packetType = HEADER_ZC_NOTIFY_BIND_ON_EQUIP;
  16667. p.index = client_index( index );
  16668. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16669. #endif
  16670. }
  16671. /**
  16672. * [Ind/Hercules]
  16673. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16674. **/
  16675. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16676. char buf[256];
  16677. size_t len;
  16678. nullpo_retv(bl);
  16679. if(!message)
  16680. return;
  16681. len = strlen(message)+1;
  16682. if( len > sizeof(buf)-8 ) {
  16683. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%" PRIuPTR ").\n", message, len);
  16684. len = sizeof(buf)-8;
  16685. }
  16686. WBUFW(buf,0) = 0x8b3;
  16687. WBUFW(buf,2) = (uint16)(len+8);
  16688. WBUFL(buf,4) = bl->id;
  16689. safestrncpy(WBUFCP(buf,8), message, len);
  16690. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16691. }
  16692. /**
  16693. * [Ind/Hercules]
  16694. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16695. **/
  16696. void clif_party_leaderchanged(map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16697. unsigned char buf[10];
  16698. nullpo_retv(sd);
  16699. WBUFW(buf,0) = 0x7fc;
  16700. WBUFL(buf,2) = prev_leader_aid;
  16701. WBUFL(buf,6) = new_leader_aid;
  16702. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16703. }
  16704. /**
  16705. * Sends a clan message to a player
  16706. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16707. **/
  16708. void clif_clan_message( struct clan& clan, const char *mes, size_t len ){
  16709. #if PACKETVER >= 20131223
  16710. map_session_data* sd = clan_getavailablesd( clan );
  16711. if( len == 0 ){
  16712. return;
  16713. }
  16714. PACKET_ZC_NOTIFY_CLAN_CHAT* p = reinterpret_cast<PACKET_ZC_NOTIFY_CLAN_CHAT*>( packet_buffer );
  16715. // Maximum message length = size of our packet buffer minus fixed size of the packet and 1 byte zero termination
  16716. static size_t len_max = sizeof( packet_buffer ) - sizeof( *p ) - 1;
  16717. // Is the length bigger than the maximum message length
  16718. if( len > len_max ){
  16719. ShowWarning( "clif_clan_message: Truncated message '%s' (len=%" PRIuPTR ", max=%" PRIuPTR ", clan_id=%d).\n", mes, len, len_max, clan.id );
  16720. len = len_max;
  16721. }
  16722. p->PacketType = HEADER_ZC_NOTIFY_CLAN_CHAT;
  16723. p->PacketLength = sizeof( *p );
  16724. // 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
  16725. safestrncpy( p->MemberName, "", sizeof( p->MemberName ) );
  16726. safestrncpy( p->Message, mes, len + 1 );
  16727. p->PacketLength += static_cast<decltype(p->PacketLength)>( len + 1 );
  16728. clif_send( p, p->PacketLength, &sd->bl, CLAN );
  16729. #endif
  16730. }
  16731. /**
  16732. * Parses a clan message from a player.
  16733. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16734. **/
  16735. void clif_parse_clan_chat( int fd, map_session_data* sd ){
  16736. #if PACKETVER >= 20131223
  16737. if( sd == nullptr ){
  16738. return;
  16739. }
  16740. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16741. // validate packet and retrieve name and message
  16742. if( !clif_process_message(sd, false, name, message, output ) )
  16743. return;
  16744. clan_send_message( *sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16745. #endif
  16746. }
  16747. /**
  16748. * Sends the basic clan informations to the client.
  16749. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16750. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16751. **/
  16752. void clif_clan_basicinfo( map_session_data& sd ){
  16753. #if PACKETVER_MAIN_NUM >= 20130626 || PACKETVER_RE_NUM >= 20130605 || defined(PACKETVER_ZERO)
  16754. struct clan* clan = sd.clan;
  16755. if( clan == nullptr ){
  16756. return;
  16757. }
  16758. PACKET_ZC_CLANINFO* p = reinterpret_cast<PACKET_ZC_CLANINFO*>( packet_buffer );
  16759. p->PacketType = HEADER_ZC_CLANINFO;
  16760. p->PacketLength = sizeof( *p );
  16761. p->ClanID = clan->id;
  16762. safestrncpy( p->ClanName, clan->name, sizeof( p->ClanName ) );
  16763. safestrncpy( p->MasterName, clan->master, sizeof( p->MasterName ) );
  16764. mapindex_getmapname_ext( clan->map, p->Map );
  16765. p->AllyCount = clan_get_alliance_count( *clan, 0 );
  16766. p->AntagonistCount = clan_get_alliance_count( *clan, 1 );
  16767. for( int flag = 0; flag < 2; flag++ ){
  16768. for( int i = 0; i < MAX_CLANALLIANCE; i++ ){
  16769. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16770. char* name = reinterpret_cast<char*>( WBUFP( p, p->PacketLength ) );
  16771. safestrncpy( name, clan->alliance[i].name, NAME_LENGTH );
  16772. p->PacketLength += static_cast<decltype(p->PacketLength)>( NAME_LENGTH );
  16773. }
  16774. }
  16775. }
  16776. clif_send( p, p->PacketLength, &sd.bl, SELF );
  16777. #endif
  16778. }
  16779. /**
  16780. * Updates the online and maximum player count of a clan.
  16781. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16782. **/
  16783. void clif_clan_onlinecount( struct clan& clan ){
  16784. #if PACKETVER >= 20131223
  16785. map_session_data* sd = clan_getavailablesd( clan );
  16786. if( sd == nullptr){
  16787. return;
  16788. }
  16789. PACKET_ZC_NOTIFY_CLAN_CONNECTINFO p = {};
  16790. p.PacketType = HEADER_ZC_NOTIFY_CLAN_CONNECTINFO;
  16791. p.NumConnect = clan.connect_member;
  16792. p.NumTotal = clan.max_member;
  16793. clif_send( &p, sizeof( p ), &sd->bl, CLAN );
  16794. #endif
  16795. }
  16796. /**
  16797. * Notifies the client that the player has left his clan.
  16798. * 0989 (ZC_ACK_CLAN_LEAVE)
  16799. **/
  16800. void clif_clan_leave( map_session_data& sd ){
  16801. #if PACKETVER >= 20131223
  16802. PACKET_ZC_ACK_CLAN_LEAVE p = {};
  16803. p.PacketType = HEADER_ZC_ACK_CLAN_LEAVE;
  16804. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  16805. #endif
  16806. }
  16807. /**
  16808. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16809. * 0A2F <result>.B <title_id>.L
  16810. */
  16811. void clif_change_title_ack(map_session_data *sd, unsigned char result, unsigned long title_id)
  16812. {
  16813. #if PACKETVER >= 20150513
  16814. int fd;
  16815. nullpo_retv(sd);
  16816. if (!clif_session_isValid(sd))
  16817. return;
  16818. fd = sd->fd;
  16819. WFIFOHEAD(fd, packet_len(0xa2f));
  16820. WFIFOW(fd, 0) = 0xa2f;
  16821. WFIFOB(fd, 2) = result;
  16822. WFIFOL(fd, 3) = title_id;
  16823. WFIFOSET(fd, packet_len(0xa2f));
  16824. #endif
  16825. }
  16826. /**
  16827. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16828. * 0A2E <title_id>.L
  16829. */
  16830. void clif_parse_change_title(int fd, map_session_data *sd)
  16831. {
  16832. int title_id;
  16833. nullpo_retv(sd);
  16834. title_id = RFIFOL(fd, 2);
  16835. if( title_id == sd->status.title_id ){
  16836. // It is exactly the same as the old one
  16837. return;
  16838. }else if( title_id <= 0 ){
  16839. sd->status.title_id = 0;
  16840. }else{
  16841. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16842. clif_change_title_ack(sd, 1, title_id);
  16843. return;
  16844. }
  16845. sd->status.title_id = title_id;
  16846. }
  16847. clif_name_area(&sd->bl);
  16848. clif_change_title_ack(sd, 0, title_id);
  16849. }
  16850. #ifdef DUMP_UNKNOWN_PACKET
  16851. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16852. {
  16853. const char* packet_txt = "save/packet.txt";
  16854. FILE* fp;
  16855. time_t time_server;
  16856. struct tm *datetime;
  16857. char datestr[512];
  16858. time(&time_server); // get time in seconds since 1/1/1970
  16859. datetime = localtime(&time_server); // convert seconds in structure
  16860. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16861. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16862. if( ( fp = fopen( packet_txt , "a" ) ) != nullptr ) {
  16863. if( sd ) {
  16864. 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);
  16865. } else {
  16866. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16867. }
  16868. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16869. fprintf(fp, "\n");
  16870. fclose(fp);
  16871. } else {
  16872. ShowError("Failed to write '%s'.\n", packet_txt);
  16873. // Dump on console instead
  16874. if( sd ) {
  16875. 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);
  16876. } else {
  16877. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16878. }
  16879. ShowDump(RFIFOP(fd,0), packet_len);
  16880. }
  16881. }
  16882. #endif
  16883. /// Roulette System
  16884. /// Author: Yommy
  16885. void roulette_generate_bonus( map_session_data& sd ){
  16886. if( battle_config.feature_roulette_bonus_reward && sd.roulette.bonusItemID == 0 ){
  16887. int next_stage = 0;
  16888. if( sd.roulette_point.bronze > 0 ){
  16889. next_stage = 0;
  16890. }else if( sd.roulette_point.silver > 9 ){
  16891. next_stage = 2;
  16892. }else if( sd.roulette_point.gold > 9 ){
  16893. next_stage = 4;
  16894. }
  16895. // Get bonus item stage only from current stage or higher
  16896. int reward_stage = rnd_value( next_stage, MAX_ROULETTE_LEVEL - 1 );
  16897. sd.roulette.bonusItemID = rd.nameid[reward_stage][rnd()%rd.items[reward_stage]];
  16898. }else{
  16899. sd.roulette.bonusItemID = 0;
  16900. }
  16901. }
  16902. /// Opens the roulette window
  16903. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16904. void clif_roulette_open( map_session_data* sd ){
  16905. nullpo_retv( sd );
  16906. roulette_generate_bonus( *sd );
  16907. struct packet_roulette_open_ack p;
  16908. p.PacketType = 0xa1a;
  16909. p.Result = 0; // result
  16910. p.Serial = 0; // serial
  16911. p.Step = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16912. p.Idx = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16913. p.AdditionItemID = sd->roulette.bonusItemID;
  16914. p.GoldPoint = sd->roulette_point.gold;
  16915. p.SilverPoint = sd->roulette_point.silver;
  16916. p.BronzePoint = sd->roulette_point.bronze;
  16917. sd->state.roulette_open = true;
  16918. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16919. }
  16920. /// Request to open the roulette window
  16921. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16922. void clif_parse_roulette_open( int fd, map_session_data* sd ){
  16923. nullpo_retv(sd);
  16924. if (!battle_config.feature_roulette) {
  16925. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16926. return;
  16927. }
  16928. clif_roulette_open(sd);
  16929. }
  16930. /// Sends the info about the available roulette rewards to the client
  16931. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16932. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16933. void clif_roulette_info( map_session_data* sd ){
  16934. nullpo_retv(sd);
  16935. struct packet_roulette_info_ack p;
  16936. p.PacketType = rouletteinfoackType;
  16937. p.PacketLength = sizeof(p);
  16938. p.RouletteSerial = 1;
  16939. for( int i = 0, count = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16940. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++ ){
  16941. p.ItemInfo[count].Row = i;
  16942. p.ItemInfo[count].Position = j;
  16943. p.ItemInfo[count].ItemId = client_nameid( rd.nameid[i][j] );
  16944. p.ItemInfo[count].Count = rd.qty[i][j];
  16945. #if PACKETVER >= 20180511
  16946. p.ItemInfo[count].unused = 0;
  16947. #endif
  16948. count++;
  16949. }
  16950. }
  16951. clif_send( &p, sizeof(p), &sd->bl, SELF );
  16952. }
  16953. /// Request the roulette reward data
  16954. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  16955. void clif_parse_roulette_info( int fd, map_session_data* sd ){
  16956. nullpo_retv(sd);
  16957. if (!battle_config.feature_roulette) {
  16958. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16959. return;
  16960. }
  16961. clif_roulette_info(sd);
  16962. }
  16963. /// Notification of the client that the roulette window was closed
  16964. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  16965. void clif_parse_roulette_close( int fd, map_session_data* sd ){
  16966. nullpo_retv(sd);
  16967. if (!battle_config.feature_roulette) {
  16968. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16969. return;
  16970. }
  16971. sd->state.roulette_open = false;
  16972. }
  16973. /// Response to a item reward request
  16974. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  16975. static void clif_roulette_recvitem_ack(map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16976. #if PACKETVER >= 20141016
  16977. nullpo_retv(sd);
  16978. struct packet_roulette_itemrecv_ack p;
  16979. p.PacketType = roulettercvitemackType;
  16980. p.Result = type;
  16981. p.AdditionItemID = sd->roulette.bonusItemID;
  16982. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  16983. #endif
  16984. }
  16985. /**
  16986. * Claim roulette reward
  16987. * @param sd Player
  16988. * @return 0:Success
  16989. **/
  16990. static uint8 clif_roulette_getitem(map_session_data *sd) {
  16991. struct item it;
  16992. uint8 res = 1;
  16993. unsigned short factor = 1;
  16994. nullpo_retr(1, sd);
  16995. if (sd->roulette.prizeIdx < 0)
  16996. return RECV_ITEM_FAILED;
  16997. memset(&it, 0, sizeof(it));
  16998. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16999. it.identify = 1;
  17000. if( sd->roulette.bonusItemID != 0 ){
  17001. if( sd->roulette.bonusItemID == it.nameid && battle_config.feature_roulette_bonus_reward && !( rd.flag[sd->roulette.prizeStage][sd->roulette.prizeIdx]&1 ) ){
  17002. factor = 2;
  17003. // Reset the Bonus Item to trigger new calculation
  17004. sd->roulette.bonusItemID = 0;
  17005. }else{
  17006. for( int i = 0; i < MAX_ROULETTE_LEVEL && sd->roulette.bonusItemID != 0; i++ ){
  17007. for( int j = 0; j < MAX_ROULETTE_COLUMNS - i && sd->roulette.bonusItemID != 0; j++ ){
  17008. if( rd.nameid[i][j] == sd->roulette.bonusItemID ){
  17009. // 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
  17010. if( sd->roulette.prizeStage >= i ){
  17011. // Reset the Bonus Item to trigger new calculation and to cancel the loops
  17012. sd->roulette.bonusItemID = 0;
  17013. }
  17014. }
  17015. }
  17016. }
  17017. }
  17018. }
  17019. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx] * factor, LOG_TYPE_ROULETTE)) == 0) {
  17020. ; // onSuccess
  17021. }
  17022. if( sd->roulette.bonusItemID == 0 ){
  17023. roulette_generate_bonus( *sd );
  17024. }
  17025. sd->roulette.claimPrize = false;
  17026. sd->roulette.prizeStage = 0;
  17027. sd->roulette.prizeIdx = -1;
  17028. sd->roulette.stage = 0;
  17029. return res;
  17030. }
  17031. /// Update Roulette window with current stats
  17032. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  17033. void clif_roulette_generate( map_session_data *sd, unsigned char result, short stage, short prizeIdx, t_itemid bonusItemID ){
  17034. nullpo_retv( sd );
  17035. struct packet_roulette_generate_ack p;
  17036. p.PacketType = roulettgenerateackType;
  17037. p.Result = result;
  17038. p.Step = stage;
  17039. p.Idx = prizeIdx;
  17040. p.AdditionItemID = battle_config.feature_roulette_bonus_reward ? bonusItemID : 0;
  17041. p.RemainGold = sd->roulette_point.gold;
  17042. p.RemainSilver = sd->roulette_point.silver;
  17043. p.RemainBronze = sd->roulette_point.bronze;
  17044. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17045. }
  17046. /// Request to start the roulette
  17047. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  17048. void clif_parse_roulette_generate( int fd, map_session_data* sd ){
  17049. enum GENERATE_ROULETTE_ACK result;
  17050. nullpo_retv(sd);
  17051. if (!battle_config.feature_roulette) {
  17052. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17053. return;
  17054. }
  17055. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17056. return;
  17057. }
  17058. // Player has not claimed his prize yet
  17059. if( sd->roulette.claimPrize ){
  17060. clif_roulette_getitem( sd );
  17061. }
  17062. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  17063. // Make sure everything is reset
  17064. sd->roulette.stage = 0;
  17065. sd->roulette.claimPrize = false;
  17066. sd->roulette.prizeStage = 0;
  17067. sd->roulette.prizeIdx = -1;
  17068. }
  17069. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  17070. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  17071. }else{
  17072. if (!sd->roulette.stage) {
  17073. if (sd->roulette_point.bronze > 0) {
  17074. sd->roulette_point.bronze -= 1;
  17075. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  17076. } else if (sd->roulette_point.silver > 9) {
  17077. sd->roulette_point.silver -= 10;
  17078. sd->roulette.stage = 2;
  17079. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  17080. } else if (sd->roulette_point.gold > 9) {
  17081. sd->roulette_point.gold -= 10;
  17082. sd->roulette.stage = 4;
  17083. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  17084. }
  17085. }
  17086. sd->roulette.prizeStage = sd->roulette.stage;
  17087. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  17088. sd->roulette.claimPrize = true;
  17089. sd->roulette.tick = gettick() + i64max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  17090. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  17091. result = GENERATE_ROULETTE_LOSING;
  17092. sd->roulette.stage = 0;
  17093. }else{
  17094. result = GENERATE_ROULETTE_SUCCESS;
  17095. sd->roulette.stage++;
  17096. }
  17097. }
  17098. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx), sd->roulette.bonusItemID);
  17099. }
  17100. /// Request to claim a prize
  17101. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  17102. void clif_parse_roulette_item( int fd, map_session_data* sd ){
  17103. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  17104. nullpo_retv(sd);
  17105. if (!battle_config.feature_roulette) {
  17106. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  17107. return;
  17108. }
  17109. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  17110. return;
  17111. }
  17112. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  17113. switch (clif_roulette_getitem(sd)) {
  17114. case ADDITEM_SUCCESS:
  17115. type = RECV_ITEM_SUCCESS;
  17116. break;
  17117. case ADDITEM_INVALID:
  17118. case ADDITEM_OVERITEM:
  17119. case ADDITEM_OVERAMOUNT:
  17120. type = RECV_ITEM_OVERCOUNT;
  17121. break;
  17122. case ADDITEM_OVERWEIGHT:
  17123. type = RECV_ITEM_OVERWEIGHT;
  17124. break;
  17125. case ADDITEM_STACKLIMIT:
  17126. default:
  17127. type = RECV_ITEM_FAILED;
  17128. break;
  17129. }
  17130. }
  17131. clif_roulette_recvitem_ack(sd,type);
  17132. }
  17133. /// MERGE ITEM
  17134. /**
  17135. * Acknowledge the client about item merger result
  17136. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  17137. * @param fd
  17138. * @param sd
  17139. **/
  17140. void clif_merge_item_ack( map_session_data &sd, enum MERGE_ITEM_ACK type, uint16 index = 0, uint16 count = 0 ){
  17141. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17142. struct PACKET_ZC_ACK_MERGE_ITEM p = {};
  17143. p.packetType = HEADER_ZC_ACK_MERGE_ITEM;
  17144. if( type == MERGE_ITEM_SUCCESS ){
  17145. p.index = client_index( index );
  17146. }else{
  17147. p.index = index;
  17148. }
  17149. p.amount = count;
  17150. p.reason = type;
  17151. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17152. #endif
  17153. }
  17154. /**
  17155. * Check if item has the pair to be merged
  17156. * @param sd
  17157. * @param it Item
  17158. * @return True if has pair, False if not
  17159. **/
  17160. static bool clif_merge_item_has_pair(map_session_data *sd, struct item *it) {
  17161. struct item *it_;
  17162. unsigned short i;
  17163. nullpo_retr(false, sd);
  17164. 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);
  17165. if (i < MAX_INVENTORY)
  17166. return true;
  17167. return false;
  17168. }
  17169. /**
  17170. * Check if item can be merged
  17171. * @param id Item Data
  17172. * @param it Item
  17173. * @return True if can be merged, False if not
  17174. **/
  17175. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  17176. if (!id || !it)
  17177. return false;
  17178. if (id->type == IT_CASH)
  17179. return false;
  17180. if (!itemdb_isstackable2(id))
  17181. return false;
  17182. if (itemdb_isspecial(it->card[0]))
  17183. return false;
  17184. if (!it->unique_id)
  17185. return false;
  17186. return true;
  17187. }
  17188. /**
  17189. * Open available item to be merged.
  17190. * Only show 1 item in 1 process.
  17191. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  17192. * @param sd
  17193. **/
  17194. void clif_merge_item_open( map_session_data& sd ){
  17195. #if PACKETVER_MAIN_NUM >= 20120314 || PACKETVER_RE_NUM >= 20120221 || defined(PACKETVER_ZERO)
  17196. PACKET_ZC_MERGE_ITEM_OPEN* p = reinterpret_cast<PACKET_ZC_MERGE_ITEM_OPEN*>( packet_buffer );
  17197. p->packetType = HEADER_ZC_MERGE_ITEM_OPEN;
  17198. p->packetLen = sizeof( *p );
  17199. int n = 0;
  17200. // Get entries
  17201. for( int i = 0; i < MAX_INVENTORY; i++ ){
  17202. struct item* it = &sd.inventory.u.items_inventory[i];
  17203. if( !clif_merge_item_check( sd.inventory_data[i], it ) ){
  17204. continue;
  17205. }
  17206. if( clif_merge_item_has_pair( &sd, it ) ){
  17207. p->items[n++].index = client_index( i );
  17208. p->packetLen += static_cast<decltype(p->packetLen)>( sizeof( p->items[0] ) );
  17209. }
  17210. }
  17211. // No item need to be merged
  17212. if( n < 2 ){
  17213. clif_msg( &sd, MSI_NOT_EXIST_MERGE_ITEM );
  17214. return;
  17215. }
  17216. clif_send( p, p->packetLen, &sd.bl, SELF );
  17217. #endif
  17218. }
  17219. /**
  17220. * Process item merge request.
  17221. * 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  17222. * @param fd
  17223. * @param sd
  17224. **/
  17225. void clif_parse_merge_item_req( int fd, map_session_data* sd ){
  17226. struct PACKET_CZ_REQ_MERGE_ITEM* p = (struct PACKET_CZ_REQ_MERGE_ITEM*)RFIFOP( fd, 0 );
  17227. int count = ( p->packetLength - sizeof( *p ) ) / sizeof( p->indices[0] );
  17228. // No item need to be merged
  17229. if( count < 2 ){
  17230. clif_msg( sd, MSI_NOT_EXIST_MERGE_ITEM );
  17231. return;
  17232. }
  17233. uint16 idx_main = server_index( p->indices[0] );
  17234. if( idx_main >= MAX_INVENTORY ){
  17235. return;
  17236. }
  17237. if( !clif_merge_item_check( sd->inventory_data[idx_main], &sd->inventory.u.items_inventory[idx_main] ) ){
  17238. clif_msg( sd, MSI_NOT_EXIST_MERGE_ITEM );
  17239. return;
  17240. }
  17241. // Ensure each index only comes once
  17242. std::unordered_set<uint16> indices;
  17243. for( int i = 1; i < count; i++ ){
  17244. uint16 idx = server_index( p->indices[i] );
  17245. if( idx >= MAX_INVENTORY ){
  17246. return;
  17247. }
  17248. if( sd->inventory_data[idx] == nullptr ){
  17249. return;
  17250. }
  17251. // Check if it is the same item
  17252. if( sd->inventory_data[idx]->nameid != sd->inventory_data[idx_main]->nameid ){
  17253. return;
  17254. }
  17255. if( !clif_merge_item_check( sd->inventory_data[idx], &sd->inventory.u.items_inventory[idx] ) ){
  17256. clif_msg( sd, MSI_NOT_EXIST_MERGE_ITEM );
  17257. return;
  17258. }
  17259. indices.insert( idx );
  17260. }
  17261. if( indices.empty() ){
  17262. clif_msg( sd, MSI_NOT_EXIST_MERGE_ITEM );
  17263. return;
  17264. }
  17265. uint32 total_amount = sd->inventory.u.items_inventory[idx_main].amount;
  17266. for( uint16 idx : indices ){
  17267. total_amount += sd->inventory.u.items_inventory[idx].amount;
  17268. }
  17269. uint16 stack = sd->inventory_data[idx_main]->stack.amount;
  17270. if( stack == 0 ){
  17271. stack = MAX_AMOUNT;
  17272. }
  17273. if( total_amount >= stack ){
  17274. clif_merge_item_ack( *sd, MERGE_ITEM_FAILED_MAX_COUNT );
  17275. return;
  17276. }
  17277. // Merrrrge!!!!
  17278. for( uint16 idx : indices ){
  17279. uint16 amount = sd->inventory.u.items_inventory[idx].amount;
  17280. log_pick_pc( sd, LOG_TYPE_MERGE_ITEM, -amount, &sd->inventory.u.items_inventory[idx] );
  17281. memset( &sd->inventory.u.items_inventory[idx], 0, sizeof( sd->inventory.u.items_inventory[0] ) );
  17282. sd->inventory_data[idx] = nullptr;
  17283. clif_delitem( *sd, idx, amount, 0 );
  17284. }
  17285. sd->inventory.u.items_inventory[idx_main].amount = total_amount;
  17286. clif_merge_item_ack( *sd, MERGE_ITEM_SUCCESS, idx_main, total_amount );
  17287. }
  17288. /**
  17289. * Cancel item merge
  17290. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  17291. * @param fd
  17292. * @param sd
  17293. **/
  17294. void clif_parse_merge_item_cancel(int fd, map_session_data* sd) {
  17295. return; // Nothing todo yet
  17296. }
  17297. static std::string clif_hide_name(const char* original_name)
  17298. {
  17299. std::string censored(original_name);
  17300. size_t hide = zmin(battle_config.broadcast_hide_name, censored.length() - 1);
  17301. censored.replace(censored.length() - hide, hide, hide, '*');
  17302. return censored;
  17303. }
  17304. /**
  17305. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17306. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  17307. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  17308. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  17309. **/
  17310. void clif_broadcast_obtain_special_item( const char *char_name, t_itemid nameid, t_itemid container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type ){
  17311. char name[NAME_LENGTH];
  17312. if( battle_config.broadcast_hide_name ){
  17313. std::string dispname = clif_hide_name(char_name);
  17314. safestrncpy(name, dispname.c_str(), sizeof(name));
  17315. }else{
  17316. safestrncpy( name, char_name, sizeof( name ) );
  17317. }
  17318. switch( type ){
  17319. case ITEMOBTAIN_TYPE_BOXITEM:
  17320. #if PACKETVER >= 20091201
  17321. {
  17322. struct PACKET_ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN_item p = {};
  17323. p.PacketType = package_item_announceType;
  17324. p.PacketLength = sizeof( p );
  17325. p.type = type;
  17326. p.ItemID = client_nameid( nameid );
  17327. p.len = NAME_LENGTH;
  17328. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17329. p.boxItemID_len = (int8)sizeof( p.BoxItemID );
  17330. p.BoxItemID = client_nameid( container );
  17331. #if PACKETVER_MAIN_NUM >= 20220518 || PACKETVER_ZERO_NUM >= 20220518
  17332. p.refineLevel_len = (int8)sizeof( p.refineLevel );
  17333. p.refineLevel = 0; // TODO: implement
  17334. #endif
  17335. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17336. }
  17337. #endif
  17338. break;
  17339. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  17340. case ITEMOBTAIN_TYPE_NPC:
  17341. {
  17342. struct packet_item_drop_announce p;
  17343. p.PacketType = item_drop_announceType;
  17344. p.type = type;
  17345. p.ItemID = client_nameid( nameid );
  17346. p.len = NAME_LENGTH;
  17347. safestrncpy( p.Name, name, sizeof( p.Name ) );
  17348. if( type == ITEMOBTAIN_TYPE_MONSTER_ITEM ){
  17349. std::shared_ptr<s_mob_db> db = mob_db.find( container );
  17350. p.monsterNameLen = NAME_LENGTH;
  17351. safestrncpy( p.monsterName, db->name.c_str(), NAME_LENGTH );
  17352. }else{
  17353. p.monsterNameLen = 0;
  17354. p.monsterName[0] = '\0';
  17355. }
  17356. #if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
  17357. p.PacketLength = 12 + p.len + p.monsterNameLen;
  17358. #else
  17359. p.PacketLength = 8 + p.len + p.monsterNameLen;
  17360. #endif
  17361. clif_send( &p, p.PacketLength, nullptr, ALL_CLIENT );
  17362. }
  17363. break;
  17364. }
  17365. }
  17366. /// Show body view windows (ZC_DRESSROOM_OPEN).
  17367. /// 0A02 <view>.W
  17368. /// Value <flag> has the following effects:
  17369. /// 1: Open a Dress Room window.
  17370. void clif_dressing_room(map_session_data *sd, int flag) {
  17371. #if PACKETVER >= 20150513
  17372. int fd = sd->fd;
  17373. nullpo_retv(sd);
  17374. WFIFOHEAD(fd, packet_len(0xa02));
  17375. WFIFOW(fd,0) = 0xa02;
  17376. WFIFOW(fd,2) = flag;
  17377. WFIFOSET(fd, packet_len(0xa02));
  17378. #endif
  17379. }
  17380. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  17381. /// 0A35 <result>.W
  17382. void clif_parse_Oneclick_Itemidentify(int fd, map_session_data *sd) {
  17383. #if PACKETVER >= 20150513
  17384. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  17385. // Ignore the request
  17386. // - Invalid item index
  17387. // - Invalid item ID or item doesn't exist
  17388. // - Item is already identified
  17389. if (idx < 0 || idx >= MAX_INVENTORY ||
  17390. sd->inventory.u.items_inventory[idx].nameid == 0 || sd->inventory_data[idx] == nullptr ||
  17391. sd->inventory.u.items_inventory[idx].identify)
  17392. return;
  17393. // Ignore the request - No magnifiers in inventory
  17394. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  17395. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  17396. return;
  17397. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  17398. return;
  17399. skill_identify(sd, idx);
  17400. #endif
  17401. }
  17402. /// Starts navigation to the given target on client side
  17403. void clif_navigateTo(map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  17404. #if PACKETVER >= 20111010
  17405. int fd = sd->fd;
  17406. WFIFOHEAD(fd,27);
  17407. WFIFOW(fd,0) = 0x08e2;
  17408. // How detailed will our navigation be?
  17409. if( mob_id > 0 ){
  17410. x = 0;
  17411. y = 0;
  17412. WFIFOB(fd,2) = 3; // monster with destination field
  17413. }else if( x > 0 && y > 0 ){
  17414. WFIFOB(fd,2) = 0; // with coordinates
  17415. }else{
  17416. x = 0;
  17417. y = 0;
  17418. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  17419. }
  17420. // Which services can be used for transportation?
  17421. WFIFOB(fd,3) = flag;
  17422. // If this flag is set, the navigation window will not be opened up
  17423. WFIFOB(fd,4) = hideWindow;
  17424. // Target map
  17425. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  17426. // Target x
  17427. WFIFOW(fd,21) = x;
  17428. // Target y
  17429. WFIFOW(fd,23) = y;
  17430. // Target monster ID
  17431. WFIFOW(fd,25) = mob_id;
  17432. WFIFOSET(fd,27);
  17433. #endif
  17434. }
  17435. /// Send hat effects to the client.
  17436. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W } (ZC_EQUIPMENT_EFFECT)
  17437. void clif_hat_effects( map_session_data& sd, block_list& bl, enum send_target target ){
  17438. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17439. map_session_data *tsd;
  17440. block_list* tbl;
  17441. if( target == SELF ){
  17442. tsd = BL_CAST(BL_PC,&bl);
  17443. tbl = &sd.bl;
  17444. }else{
  17445. tsd = &sd;
  17446. tbl = &bl;
  17447. }
  17448. if( tsd == nullptr ){
  17449. return;
  17450. }
  17451. if( tsd->hatEffects.empty() || map_getmapdata(tbl->m)->getMapFlag(MF_NOCOSTUME) ){
  17452. return;
  17453. }
  17454. PACKET_ZC_EQUIPMENT_EFFECT* p = reinterpret_cast<PACKET_ZC_EQUIPMENT_EFFECT*>( packet_buffer );
  17455. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17456. p->packetLength = sizeof( *p );
  17457. p->aid = tsd->bl.id;
  17458. p->status = 1;
  17459. for( size_t i = 0; i < tsd->hatEffects.size(); i++ ){
  17460. p->effects[i] = tsd->hatEffects[i];
  17461. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->effects[0] ) );
  17462. }
  17463. clif_send( p, p->packetLength, tbl, target );
  17464. #endif
  17465. }
  17466. /// Send a single hat effect to the client.
  17467. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W } (ZC_EQUIPMENT_EFFECT)
  17468. void clif_hat_effect_single( map_session_data& sd, uint16 effectId, bool enable ){
  17469. #if PACKETVER_MAIN_NUM >= 20150507 || PACKETVER_RE_NUM >= 20150429 || defined(PACKETVER_ZERO)
  17470. PACKET_ZC_EQUIPMENT_EFFECT* p = reinterpret_cast<PACKET_ZC_EQUIPMENT_EFFECT*>( packet_buffer );
  17471. p->packetType = HEADER_ZC_EQUIPMENT_EFFECT;
  17472. p->packetLength = sizeof( *p );
  17473. p->aid = sd.bl.id;
  17474. p->status = enable;
  17475. p->effects[0] = effectId;
  17476. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( p->effects[0] ) );
  17477. clif_send( p, p->packetLength, &sd.bl, AREA );
  17478. #endif
  17479. }
  17480. /// Notify the client that a sale has started
  17481. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  17482. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17483. #if PACKETVER_SUPPORTS_SALES
  17484. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_SELLING p;
  17485. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_SELLING;
  17486. p.itemId = client_nameid( sale_item->nameid );
  17487. p.remainingTime = (uint32)(sale_item->end - time(nullptr)); // time in S
  17488. clif_send( &p, sizeof( p ), bl, target );
  17489. #endif
  17490. }
  17491. /// Notify the client that a sale has ended
  17492. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  17493. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17494. #if PACKETVER_SUPPORTS_SALES
  17495. struct PACKET_ZC_NOTIFY_BARGAIN_SALE_CLOSE p;
  17496. p.packetType = HEADER_ZC_NOTIFY_BARGAIN_SALE_CLOSE;
  17497. p.itemId = client_nameid( sale_item->nameid );
  17498. clif_send( &p, sizeof( p ), bl, target );
  17499. #endif
  17500. }
  17501. /// Update the remaining amount of a sale item.
  17502. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  17503. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  17504. #if PACKETVER_SUPPORTS_SALES
  17505. struct PACKET_ZC_ACK_COUNT_BARGAIN_SALE_ITEM p;
  17506. p.packetType = HEADER_ZC_ACK_COUNT_BARGAIN_SALE_ITEM;
  17507. p.itemId = client_nameid( sale_item->nameid );
  17508. p.amount = sale_item->amount;
  17509. clif_send( &p, sizeof( p ), bl, target );
  17510. #endif
  17511. }
  17512. /// The client requested a refresh of the current remaining count of a sale item
  17513. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17514. void clif_parse_sale_refresh( int fd, map_session_data* sd ){
  17515. #if PACKETVER_SUPPORTS_SALES
  17516. struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO* p = (struct PACKET_CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO*)RFIFOP( fd, 0 );
  17517. struct sale_item_data* sale;
  17518. if( p->AID != sd->status.account_id ){
  17519. return;
  17520. }
  17521. sale = sale_find_item( p->itemId, true );
  17522. if( sale == nullptr ){
  17523. return;
  17524. }
  17525. clif_sale_amount(sale, &sd->bl, SELF);
  17526. #endif
  17527. }
  17528. /// Opens the sale administration window on the client
  17529. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  17530. void clif_sale_open( map_session_data* sd ){
  17531. #if PACKETVER_SUPPORTS_SALES
  17532. nullpo_retv(sd);
  17533. if( sd->state.sale_open ){
  17534. return;
  17535. }
  17536. sd->state.sale_open = true;
  17537. int fd = sd->fd;
  17538. WFIFOHEAD(fd, 2);
  17539. WFIFOW(fd, 0) = 0x9b5;
  17540. WFIFOSET(fd, 2);
  17541. #endif
  17542. }
  17543. /// Client request to open the sale administration window.
  17544. /// This is sent by /limitedsale
  17545. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  17546. void clif_parse_sale_open( int fd, map_session_data* sd ){
  17547. #if PACKETVER_SUPPORTS_SALES
  17548. nullpo_retv(sd);
  17549. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17550. return;
  17551. }
  17552. char command[CHAT_SIZE_MAX];
  17553. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  17554. is_atcommand(fd, sd, command, 1);
  17555. #endif
  17556. }
  17557. /// Closes the sale administration window on the client.
  17558. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  17559. void clif_sale_close(map_session_data* sd) {
  17560. #if PACKETVER_SUPPORTS_SALES
  17561. nullpo_retv(sd);
  17562. if( !sd->state.sale_open ){
  17563. return;
  17564. }
  17565. sd->state.sale_open = false;
  17566. int fd = sd->fd;
  17567. WFIFOHEAD(fd, 2);
  17568. WFIFOW(fd, 0) = 0x9bd;
  17569. WFIFOSET(fd, 2);
  17570. #endif
  17571. }
  17572. /// Client request to close the sale administration window.
  17573. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  17574. void clif_parse_sale_close(int fd, map_session_data* sd) {
  17575. #if PACKETVER_SUPPORTS_SALES
  17576. nullpo_retv(sd);
  17577. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17578. return;
  17579. }
  17580. clif_sale_close(sd);
  17581. #endif
  17582. }
  17583. /// Reply to a item search request for item sale administration.
  17584. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17585. void clif_sale_search_reply( map_session_data* sd, std::shared_ptr<s_cash_item> item ){
  17586. #if PACKETVER_SUPPORTS_SALES
  17587. struct PACKET_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO p;
  17588. p.packetType = HEADER_ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO;
  17589. if( item != nullptr ){
  17590. p.result = 0;
  17591. p.itemId = client_nameid( item->nameid );
  17592. p.price = item->price;
  17593. }else{
  17594. p.result = 1;
  17595. p.itemId = 0;
  17596. p.price = 0;
  17597. }
  17598. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  17599. #endif
  17600. }
  17601. /// Search request for an item sale administration.
  17602. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17603. void clif_parse_sale_search( int fd, map_session_data* sd ){
  17604. #if PACKETVER_SUPPORTS_SALES
  17605. char item_name[ITEM_NAME_LENGTH];
  17606. nullpo_retv(sd);
  17607. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17608. return;
  17609. }
  17610. if( !sd->state.sale_open ){
  17611. return;
  17612. }
  17613. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17614. std::shared_ptr<item_data> id = item_db.searchname( item_name );
  17615. // not found
  17616. if( id == nullptr ){
  17617. clif_sale_search_reply( sd, nullptr );
  17618. return;
  17619. }
  17620. clif_sale_search_reply( sd, cash_shop_db.findItemInTab( CASHSHOP_TAB_SALE, id->nameid ) );
  17621. #endif
  17622. }
  17623. /// Reply if an item was successfully put on sale or not.
  17624. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17625. void clif_sale_add_reply( map_session_data* sd, enum e_sale_add_result result ){
  17626. #if PACKETVER_SUPPORTS_SALES
  17627. int fd = sd->fd;
  17628. WFIFOHEAD(fd, 4);
  17629. WFIFOW(fd, 0) = 0x9af;
  17630. WFIFOW(fd, 2) = (uint16)result;
  17631. WFIFOSET(fd, 4);
  17632. #endif
  17633. }
  17634. /// A client request to put an item on sale.
  17635. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17636. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W (CZ_REQ_APPLY_BARGAIN_SALE_ITEM2)
  17637. void clif_parse_sale_add( int fd, map_session_data* sd ){
  17638. #if PACKETVER_SUPPORTS_SALES
  17639. nullpo_retv( sd );
  17640. struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_APPLY_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17641. if( p->AID != sd->status.account_id ){
  17642. return;
  17643. }
  17644. if( !sd->state.sale_open ){
  17645. return;
  17646. }
  17647. time_t endTime = p->startTime + p->hours * 60 * 60;
  17648. clif_sale_add_reply( sd, sale_add_item( p->itemId, p->amount, p->startTime, endTime ) );
  17649. #endif
  17650. }
  17651. /// Reply to an item removal from sale.
  17652. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17653. void clif_sale_remove_reply( map_session_data* sd, bool failed ){
  17654. #if PACKETVER_SUPPORTS_SALES
  17655. int fd = sd->fd;
  17656. WFIFOHEAD(fd, 4);
  17657. WFIFOW(fd, 0) = 0x9b1;
  17658. WFIFOW(fd, 2) = failed;
  17659. WFIFOSET(fd, 4);
  17660. #endif
  17661. }
  17662. /// Request to remove an item from sale.
  17663. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17664. void clif_parse_sale_remove( int fd, map_session_data* sd ){
  17665. #if PACKETVER_SUPPORTS_SALES
  17666. nullpo_retv( sd );
  17667. struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM* p = (struct PACKET_CZ_REQ_REMOVE_BARGAIN_SALE_ITEM*)RFIFOP( fd, 0 );
  17668. if( p->AID != sd->status.account_id ){
  17669. return;
  17670. }
  17671. if( !sd->state.sale_open ){
  17672. return;
  17673. }
  17674. clif_sale_remove_reply( sd, !sale_remove_item( p->itemId ) );
  17675. #endif
  17676. }
  17677. /// Achievement System
  17678. /// Author: Luxuri, Aleos
  17679. /**
  17680. * Sends all achievement data to the client (ZC_ALL_ACH_LIST).
  17681. * 0a23 <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17682. */
  17683. void clif_achievement_list_all(map_session_data *sd)
  17684. {
  17685. nullpo_retv(sd);
  17686. if (!battle_config.feature_achievement) {
  17687. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17688. return;
  17689. }
  17690. int count = sd->achievement_data.count; // All achievements should be sent to the client
  17691. if (count == 0)
  17692. return;
  17693. int len = (50 * count) + 22;
  17694. int fd = sd->fd;
  17695. int *info = achievement_level(sd, true);
  17696. WFIFOHEAD(fd,len);
  17697. WFIFOW(fd, 0) = 0xa23;
  17698. WFIFOW(fd, 2) = len;
  17699. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17700. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17701. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17702. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17703. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17704. for (int i = 0; i < count; i++) {
  17705. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17706. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17707. for (int j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17708. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17709. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17710. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17711. }
  17712. WFIFOSET(fd, len);
  17713. }
  17714. /**
  17715. * Sends a single achievement's data to the client (ZC_ACH_UPDATE).
  17716. * 0a24 <ACHPoint>.L
  17717. */
  17718. void clif_achievement_update(map_session_data *sd, struct achievement *ach, int count)
  17719. {
  17720. nullpo_retv(sd);
  17721. if (!battle_config.feature_achievement) {
  17722. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17723. return;
  17724. }
  17725. int fd = sd->fd;
  17726. int *info = achievement_level(sd, true);
  17727. WFIFOHEAD(fd, packet_len(0xa24));
  17728. WFIFOW(fd, 0) = 0xa24;
  17729. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17730. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17731. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17732. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17733. if (ach) {
  17734. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17735. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17736. for (int i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17737. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17738. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17739. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17740. } else
  17741. memset(WFIFOP(fd, 16), 0, 40);
  17742. WFIFOSET(fd, packet_len(0xa24));
  17743. }
  17744. /**
  17745. * Checks if an achievement reward can be rewarded (CZ_REQ_ACH_REWARD).
  17746. * 0a25 <achievementID>.L
  17747. */
  17748. void clif_parse_AchievementCheckReward(int fd, map_session_data *sd)
  17749. {
  17750. nullpo_retv(sd);
  17751. if( sd->achievement_data.save )
  17752. intif_achievement_save(sd);
  17753. achievement_check_reward(sd, RFIFOL(fd,2));
  17754. }
  17755. /**
  17756. * Returns the result of achievement_check_reward (ZC_REQ_ACH_REWARD_ACK).
  17757. * 0a26 <result>.W <achievementID>.L
  17758. */
  17759. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17760. {
  17761. WFIFOHEAD(fd, packet_len(0xa26));
  17762. WFIFOW(fd, 0) = 0xa26;
  17763. WFIFOB(fd, 2) = result;
  17764. WFIFOL(fd, 3) = achievement_id;
  17765. WFIFOSET(fd, packet_len(0xa26));
  17766. }
  17767. /// Process the pet evolution request
  17768. /// 09fb <packetType>.W <packetLength>.W <evolutionPetEggITID>.W (CZ_PET_EVOLUTION)
  17769. void clif_parse_pet_evolution( int fd, map_session_data *sd ){
  17770. #if PACKETVER >= 20141008
  17771. const struct PACKET_CZ_PET_EVOLUTION *p = (struct PACKET_CZ_PET_EVOLUTION *)RFIFOP( fd, 0 );
  17772. auto pet = pet_db_search( p->EvolvedPetEggID, PET_EGG );
  17773. if (!pet) {
  17774. clif_pet_evolution_result(sd, e_pet_evolution_result::FAIL_NOT_PETEGG);
  17775. return;
  17776. }
  17777. pet_evolution(sd, pet->class_);
  17778. #endif
  17779. }
  17780. /// Sends the result of the evolution to the client.
  17781. /// 09fc <result>.L (ZC_PET_EVOLUTION_RESULT)
  17782. void clif_pet_evolution_result( map_session_data* sd, e_pet_evolution_result result ){
  17783. #if PACKETVER >= 20141008
  17784. int fd = sd->fd;
  17785. WFIFOHEAD(fd, packet_len(0x9fc));
  17786. WFIFOW(fd, 0) = 0x9fc;
  17787. WFIFOL(fd, 2) = static_cast<uint32>(result);
  17788. WFIFOSET(fd, packet_len(0x9fc));
  17789. #endif
  17790. }
  17791. /*
  17792. * This packet is sent by /changedress or /nocosplay
  17793. *
  17794. * 0ae8
  17795. */
  17796. void clif_parse_changedress( int fd, map_session_data* sd ){
  17797. #if PACKETVER >= 20180103
  17798. char command[CHAT_SIZE_MAX];
  17799. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17800. is_atcommand( fd, sd, command, 1 );
  17801. #endif
  17802. }
  17803. /// Opens an UI window of the given type and initializes it with the given data
  17804. /// 0AE2 <type>.B <data>.L
  17805. void clif_ui_open( map_session_data& sd, enum out_ui_type ui_type, int32 data ){
  17806. #if PACKETVER >= 20151202
  17807. // If the UI requires state tracking
  17808. switch( ui_type ){
  17809. case OUT_UI_STYLIST:
  17810. sd.state.stylist_open = true;
  17811. break;
  17812. case OUT_UI_ENCHANTGRADE:
  17813. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  17814. sd.state.enchantgrade_open = true;
  17815. break;
  17816. #else
  17817. return;
  17818. #endif
  17819. }
  17820. struct PACKET_ZC_UI_OPEN p = {};
  17821. p.PacketType = HEADER_ZC_UI_OPEN;
  17822. p.UIType = ui_type;
  17823. #if PACKETVER >= 20171122
  17824. p.data = data;
  17825. #endif
  17826. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  17827. #endif
  17828. }
  17829. /// Request to open an UI window of the given type
  17830. /// 0A68 <type>.B
  17831. void clif_parse_open_ui( int fd, map_session_data* sd ){
  17832. switch( RFIFOB(fd,2) ){
  17833. case IN_UI_ATTENDANCE:
  17834. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17835. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17836. }else if( pc_attendance_enabled() ){
  17837. clif_ui_open( *sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17838. }else{
  17839. clif_msg_color( sd, MSI_CHECK_ATTENDANCE_NOT_EVENT, color_table[COLOR_RED] );
  17840. }
  17841. break;
  17842. #if PACKETVER >= 20160316
  17843. case IN_UI_MACRO_REGISTER:
  17844. clif_ui_open(*sd, OUT_UI_CAPTCHA, 0);
  17845. break;
  17846. case IN_UI_MACRO_DETECTOR:
  17847. clif_ui_open(*sd, OUT_UI_MACRO, 0);
  17848. break;
  17849. #endif
  17850. }
  17851. }
  17852. /// Response for attedance request
  17853. /// 0AF0 <unknown>.L <data>.L
  17854. void clif_attendence_response( map_session_data *sd, int32 data ){
  17855. nullpo_retv(sd);
  17856. int fd = sd->fd;
  17857. WFIFOHEAD(fd,packet_len(0xAF0));
  17858. WFIFOW(fd,0) = 0xAF0;
  17859. WFIFOL(fd,2) = 0;
  17860. WFIFOL(fd,6) = data;
  17861. WFIFOSET(fd,packet_len(0xAF0));
  17862. }
  17863. /// Request from the client to retrieve today's attendance reward
  17864. /// 0AEF
  17865. void clif_parse_attendance_request( int fd, map_session_data* sd ){
  17866. pc_attendance_claim_reward(sd);
  17867. }
  17868. /// Send out the percentage of weight that causes it to be displayed in red.
  17869. /// 0ADE <percentage>.L
  17870. void clif_weight_limit( map_session_data* sd ){
  17871. #if PACKETVER >= 20171025
  17872. nullpo_retv(sd);
  17873. int fd = sd->fd;
  17874. WFIFOHEAD(fd, packet_len(0xADE));
  17875. WFIFOW(fd, 0) = 0xADE;
  17876. #ifdef RENEWAL
  17877. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17878. #else
  17879. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17880. #endif
  17881. WFIFOSET(fd, packet_len(0xADE));
  17882. #endif
  17883. }
  17884. enum e_private_airship_response : uint32{
  17885. PRIVATEAIRSHIP_OK,
  17886. PRIVATEAIRSHIP_RETRY,
  17887. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17888. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17889. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17890. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17891. };
  17892. /// Send out the response to a private airship request
  17893. /// 0A4A <response>.L
  17894. void clif_private_airship_response( map_session_data* sd, enum e_private_airship_response response ){
  17895. #if PACKETVER >= 20180321
  17896. nullpo_retv( sd );
  17897. int fd = sd->fd;
  17898. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17899. WFIFOW( fd, 0 ) = 0xA4A;
  17900. WFIFOL( fd, 2 ) = response;
  17901. WFIFOSET( fd, packet_len( 0xA4A ) );
  17902. #endif
  17903. }
  17904. /// Parses a request for a private airship
  17905. /// 0A49 <mapname>.16B <itemid>.W
  17906. void clif_parse_private_airship_request( int fd, map_session_data* sd ){
  17907. #if PACKETVER >= 20180321
  17908. // Check if the feature is enabled
  17909. if( !battle_config.feature_privateairship ){
  17910. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17911. return;
  17912. }
  17913. // Check if the player is allowed to warp from the source map
  17914. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17915. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17916. return;
  17917. }
  17918. const struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *p = (struct PACKET_CZ_PRIVATE_AIRSHIP_REQUEST *)RFIFOP( fd, 0 );
  17919. char mapname[MAP_NAME_LENGTH_EXT];
  17920. safestrncpy( mapname, p->mapName, MAP_NAME_LENGTH_EXT );
  17921. int16 mapindex = mapindex_name2id( mapname );
  17922. // Check if we know the mapname
  17923. if( mapindex < 0 ){
  17924. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17925. return;
  17926. }
  17927. int16 mapid = map_mapindex2mapid( mapindex );
  17928. // Check if the map is available on this server
  17929. if( mapid < 0 ){
  17930. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17931. return;
  17932. }
  17933. // Check if the player tried to warp to the map he is on
  17934. if( sd->bl.m == mapid ){
  17935. // This is blocked by the client, but just to be sure
  17936. return;
  17937. }
  17938. // This can only be a hack, so we prevent it
  17939. if( map_getmapdata( mapid )->instance_id ){
  17940. // Ignore requests to warp directly into a running instance
  17941. return;
  17942. }
  17943. // Check if the player is allowed to warp to the target map
  17944. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17945. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17946. return;
  17947. }
  17948. t_itemid item_id = p->ItemID;
  17949. // Check if the item sent by the client is known to us
  17950. if( !itemdb_group.item_exists(IG_PRIVATE_AIRSHIP, item_id) ){
  17951. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17952. return;
  17953. }
  17954. int idx = pc_search_inventory( sd, item_id );
  17955. // Check if the player has the item at all
  17956. if( idx < 0 ){
  17957. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17958. return;
  17959. }
  17960. // Delete the chosen item
  17961. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17962. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17963. return;
  17964. }
  17965. // Warp the player to a random spot on the destination map
  17966. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17967. #endif
  17968. }
  17969. /// Sends out the usage history of the guild storage
  17970. /// 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
  17971. /// { <card item id>.W }*4 <name>.24B <time>.24B <attribute>.B }*count (ZC_ACK_GUILDSTORAGE_LOG)
  17972. void clif_guild_storage_log( map_session_data* sd, std::vector<struct guild_log_entry>& log, enum e_guild_storage_log result ){
  17973. #if PACKETVER >= 20140205
  17974. nullpo_retv( sd );
  17975. int fd = sd->fd;
  17976. int16 size = sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG );
  17977. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17978. size += static_cast<int16>(log.size()) * sizeof( struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub );
  17979. }else{
  17980. log.clear();
  17981. }
  17982. WFIFOHEAD( fd, size );
  17983. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG *p = (struct PACKET_ZC_ACK_GUILDSTORAGE_LOG*)WFIFOP( fd, 0 );
  17984. p->packetType = HEADER_ZC_ACK_GUILDSTORAGE_LOG;
  17985. p->PacketLength = size;
  17986. p->result = result;
  17987. p->amount = (uint16)log.size();
  17988. if( result == GUILDSTORAGE_LOG_FINAL_SUCCESS ){
  17989. for( int i = 0; i < log.size(); i++ ){
  17990. struct PACKET_ZC_ACK_GUILDSTORAGE_LOG_sub* item = &p->items[i];
  17991. struct guild_log_entry& entry = log[i];
  17992. item->id = entry.id;
  17993. item->itemId = client_nameid( entry.item.nameid );
  17994. item->amount = (uint16)( entry.amount > 0 ? entry.amount : ( entry.amount * -1 ) );
  17995. item->action = entry.amount > 0; // action = true(put), false(get)
  17996. item->refine = entry.item.refine;
  17997. item->uniqueId = entry.item.unique_id;
  17998. item->IsIdentified = entry.item.identify;
  17999. item->itemType = itemtype( entry.item.nameid );
  18000. clif_addcards( &item->slot, &entry.item );
  18001. safestrncpy( item->name, entry.name, NAME_LENGTH );
  18002. safestrncpy( item->time, entry.time, NAME_LENGTH );
  18003. item->attribute = entry.item.attribute;
  18004. }
  18005. }
  18006. WFIFOSET( fd, p->PacketLength );
  18007. #endif
  18008. }
  18009. /// Activates the client camera info or updates the client camera with the given values.
  18010. /// 0A78 <type>.B <range>.F <rotation>.F <latitude>.F
  18011. void clif_camerainfo( map_session_data* sd, bool show, float range, float rotation, float latitude ){
  18012. #if PACKETVER >= 20160525
  18013. int fd = sd->fd;
  18014. WFIFOHEAD(fd, packet_len(0xa78));
  18015. WFIFOW(fd, 0) = 0xa78;
  18016. WFIFOB(fd, 2) = show;
  18017. WFIFOF(fd, 3) = range;
  18018. WFIFOF(fd, 7) = rotation;
  18019. WFIFOF(fd, 11) = latitude;
  18020. WFIFOSET(fd, packet_len(0xa78));
  18021. #endif
  18022. }
  18023. /// Activates or deactives the client camera info or updates the camera settings.
  18024. /// This packet is triggered by /viewpointvalue or /setcamera
  18025. /// 0A77 <type>.B <range>.F <rotation>.F <latitude>.F
  18026. void clif_parse_camerainfo( int fd, map_session_data* sd ){
  18027. char command[CHAT_SIZE_MAX];
  18028. // /viewpointvalue
  18029. if( RFIFOB( fd, 2 ) == 1 ){
  18030. safesnprintf( command, sizeof( command ), "%ccamerainfo", atcommand_symbol );
  18031. // /setcamera
  18032. }else{
  18033. safesnprintf( command, sizeof( command ), "%ccamerainfo %03.03f %03.03f %03.03f", atcommand_symbol, RFIFOF( fd, 3 ), RFIFOF( fd, 7 ), RFIFOF( fd, 11 ) );
  18034. }
  18035. is_atcommand( fd, sd, command, 1 );
  18036. }
  18037. /// Send the full list of items in the equip switch window
  18038. /// 0a9b <length>.W { <index>.W <position>.L }*
  18039. void clif_equipswitch_list( map_session_data* sd ){
  18040. #if PACKETVER >= 20170208
  18041. int fd = sd->fd;
  18042. int offset, i, position;
  18043. WFIFOW(fd, 0) = 0xa9b;
  18044. for( i = 0, offset = 4, position = 0; i < EQI_MAX; i++ ){
  18045. short index = sd->equip_switch_index[i];
  18046. if( index >= 0 && !( position & equip_bitmask[i] ) ){
  18047. WFIFOW(fd, offset) = index + 2;
  18048. WFIFOL(fd, offset + 2) = sd->inventory.u.items_inventory[index].equipSwitch;
  18049. position |= sd->inventory.u.items_inventory[index].equipSwitch;
  18050. offset += 6;
  18051. }
  18052. }
  18053. WFIFOW(fd, 2) = offset;
  18054. WFIFOSET(fd, offset);
  18055. #endif
  18056. }
  18057. /// Acknowledgement for removing an equip to the equip switch window
  18058. /// 0a9a <index>.W <position.>.L <failure>.W
  18059. void clif_equipswitch_remove( map_session_data* sd, uint16 index, uint32 pos, bool failed ){
  18060. #if PACKETVER >= 20170208
  18061. int fd = sd->fd;
  18062. WFIFOHEAD(fd, packet_len(0xa9a));
  18063. WFIFOW(fd, 0) = 0xa9a;
  18064. WFIFOW(fd, 2) = index + 2;
  18065. WFIFOL(fd, 4) = pos;
  18066. WFIFOW(fd, 8) = failed;
  18067. WFIFOSET(fd, packet_len(0xa9a));
  18068. #endif
  18069. }
  18070. /// Request to remove an equip from the equip switch window
  18071. /// 0a99 <index>.W <position>.L <= 20170502
  18072. /// 0a99 <index>.W
  18073. void clif_parse_equipswitch_remove( int fd, map_session_data* sd ){
  18074. #if PACKETVER >= 20170208
  18075. uint16 index = RFIFOW(fd, 2) - 2;
  18076. bool removed = false;
  18077. if( !battle_config.feature_equipswitch ){
  18078. return;
  18079. }
  18080. // Check if the index is valid
  18081. if( index >= MAX_INVENTORY ){
  18082. return;
  18083. }
  18084. pc_equipswitch_remove( sd, index );
  18085. #endif
  18086. }
  18087. /// Acknowledgement for adding an equip to the equip switch window
  18088. /// 0a98 <index>.W <position.>.L <flag>.L <= 20170502
  18089. /// 0a98 <index>.W <position.>.L <flag>.W
  18090. void clif_equipswitch_add( map_session_data* sd, uint16 index, uint32 pos, uint8 flag ){
  18091. #if PACKETVER >= 20170208
  18092. int fd = sd->fd;
  18093. WFIFOHEAD(fd, packet_len(0xa98));
  18094. WFIFOW(fd, 0) = 0xa98;
  18095. WFIFOW(fd, 2) = index + 2;
  18096. WFIFOL(fd, 4) = pos;
  18097. #if PACKETVER <= 20170502
  18098. WFIFOL(fd, 8) = flag;
  18099. #else
  18100. WFIFOW(fd, 8) = flag;
  18101. #endif
  18102. WFIFOSET(fd,packet_len(0xa98));
  18103. #endif
  18104. }
  18105. /// Request to add an equip to the equip switch window
  18106. /// 0a97 <index>.W <position>.L
  18107. void clif_parse_equipswitch_add( int fd, map_session_data* sd ){
  18108. #if PACKETVER >= 20170208
  18109. uint16 index = RFIFOW(fd, 2) - 2;
  18110. uint32 position = RFIFOL(fd, 4);
  18111. if( !battle_config.feature_equipswitch ){
  18112. return;
  18113. }
  18114. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  18115. return;
  18116. }
  18117. if( sd->state.trading || sd->npc_shopid ){
  18118. clif_equipswitch_add( sd, index, position, ITEM_EQUIP_ACK_OK );
  18119. return;
  18120. }
  18121. if( sd->inventory_data[index]->type == IT_AMMO ){
  18122. position = EQP_AMMO;
  18123. }
  18124. pc_equipitem( sd, index, position, true );
  18125. #endif
  18126. }
  18127. /// Acknowledgement packet for the full equip switch
  18128. /// 0a9d <failed>.W
  18129. void clif_equipswitch_reply( map_session_data* sd, bool failed ){
  18130. #if PACKETVER >= 20170208
  18131. int fd = sd->fd;
  18132. WFIFOHEAD(fd, packet_len(0xa9d));
  18133. WFIFOW(fd, 0) = 0xa9d;
  18134. WFIFOW(fd, 2) = failed;
  18135. WFIFOSET(fd, packet_len(0xa9d));
  18136. #endif
  18137. }
  18138. /// Request to do a full equip switch
  18139. /// 0a9c
  18140. void clif_parse_equipswitch_request( int fd, map_session_data* sd ){
  18141. #if PACKETVER >= 20170208
  18142. int i;
  18143. t_tick tick = gettick();
  18144. uint16 skill_id = ALL_EQSWITCH, skill_lv = 1;
  18145. if( DIFF_TICK(tick, sd->equipswitch_tick) < 0 ) {
  18146. // Client will not let you send a request
  18147. return;
  18148. }
  18149. sd->equipswitch_tick = tick + skill_get_cooldown( skill_id, skill_lv );
  18150. if( !battle_config.feature_equipswitch ){
  18151. return;
  18152. }
  18153. ARR_FIND( 0, EQI_MAX, i, sd->equip_switch_index[i] >= 0 );
  18154. if( i == EQI_MAX ){
  18155. // client will show: "There is no item to replace." and should not even come here
  18156. clif_equipswitch_reply( sd, false );
  18157. return;
  18158. }
  18159. if( pc_issit(sd) && !pc_setstand( sd, false ) ){
  18160. return;
  18161. }
  18162. clif_parse_skill_toid( sd, skill_id, skill_lv, sd->bl.id );
  18163. #endif
  18164. }
  18165. /// Request to do a single equip switch
  18166. /// 0ace <index>.W
  18167. void clif_parse_equipswitch_request_single( int fd, map_session_data* sd ){
  18168. #if PACKETVER >= 20170502
  18169. uint16 index = RFIFOW(fd, 2) - 2;
  18170. if( !battle_config.feature_equipswitch ){
  18171. return;
  18172. }
  18173. // Check if the index is valid
  18174. if( index >= MAX_INVENTORY ){
  18175. return;
  18176. }
  18177. // Check if the item exists
  18178. if (sd->inventory_data[index] == nullptr)
  18179. return;
  18180. // Check if the item was already added to equip switch
  18181. if( sd->inventory.u.items_inventory[index].equipSwitch ){
  18182. if( sd->npc_id ){
  18183. #ifdef RENEWAL
  18184. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  18185. clif_msg( sd, MSI_BUSY);
  18186. return;
  18187. }
  18188. #endif
  18189. if( !sd->npc_item_flag ){
  18190. return;
  18191. }
  18192. }
  18193. pc_equipswitch( sd, index );
  18194. return;
  18195. }
  18196. pc_equipitem( sd, index, pc_equippoint(sd, index), true );
  18197. #endif
  18198. }
  18199. void clif_parse_StartUseSkillToId( int fd, map_session_data* sd ){
  18200. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18201. const struct PACKET_CZ_USE_SKILL_START* p = (struct PACKET_CZ_USE_SKILL_START*)RFIFOP( fd, 0 );
  18202. // Only rolling cutter is supported for now
  18203. if( p->skillId != GC_ROLLINGCUTTER ){
  18204. return;
  18205. }
  18206. // Already running - cant happen on officials, since only one skill is supported
  18207. if( sd->skill_keep_using.skill_id != 0 ){
  18208. return;
  18209. }
  18210. sd->skill_keep_using.tid = INVALID_TIMER;
  18211. sd->skill_keep_using.skill_id = p->skillId;
  18212. sd->skill_keep_using.level = p->skillLv;
  18213. sd->skill_keep_using.target = p->targetId;
  18214. clif_parse_skill_toid( sd, sd->skill_keep_using.skill_id, sd->skill_keep_using.level, sd->skill_keep_using.target );
  18215. #endif
  18216. }
  18217. void clif_parse_StopUseSkillToId( int fd, map_session_data* sd ){
  18218. #if PACKETVER_MAIN_NUM >= 20181002 || PACKETVER_RE_NUM >= 20181002 || PACKETVER_ZERO_NUM >= 20181010
  18219. const struct PACKET_CZ_USE_SKILL_END* p = (struct PACKET_CZ_USE_SKILL_END*)RFIFOP( fd, 0 );
  18220. // Not running
  18221. if( sd->skill_keep_using.skill_id == 0 ){
  18222. return;
  18223. }
  18224. #if 0
  18225. // Hack
  18226. if( p->skillId != sd->skill_keep_using.skill_id ){
  18227. return;
  18228. }
  18229. #endif
  18230. if( sd->skill_keep_using.tid != INVALID_TIMER ){
  18231. delete_timer( sd->skill_keep_using.tid, skill_keep_using );
  18232. sd->skill_keep_using.tid = INVALID_TIMER;
  18233. }
  18234. sd->skill_keep_using.skill_id = 0;
  18235. sd->skill_keep_using.level = 0;
  18236. sd->skill_keep_using.target = 0;
  18237. #endif
  18238. }
  18239. void clif_ping( map_session_data* sd ){
  18240. #if PACKETVER_MAIN_NUM >= 20190213 || PACKETVER_RE_NUM >= 20190213 || PACKETVER_ZERO_NUM >= 20190130
  18241. nullpo_retv( sd );
  18242. int fd = sd->fd;
  18243. if( !session_isActive( fd ) ){
  18244. return;
  18245. }
  18246. struct PACKET_ZC_PING_LIVE p = {};
  18247. p.packetType = HEADER_ZC_PING_LIVE;
  18248. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18249. #endif
  18250. }
  18251. int clif_ping_timer_sub( map_session_data *sd, va_list ap ){
  18252. nullpo_ret( sd );
  18253. int fd = sd->fd;
  18254. if( !session_isActive( fd ) ){
  18255. return 0;
  18256. }
  18257. t_tick tick = va_arg( ap, t_tick );
  18258. if( session[fd]->wdata_tick + battle_config.ping_time < tick ){
  18259. clif_ping( sd );
  18260. }
  18261. return 0;
  18262. }
  18263. TIMER_FUNC( clif_ping_timer ){
  18264. map_foreachpc( clif_ping_timer_sub, gettick() );
  18265. return 0;
  18266. }
  18267. /**
  18268. * Opens the refine UI on the designated client.
  18269. * 0aa0
  18270. */
  18271. void clif_refineui_open( map_session_data* sd ){
  18272. #if PACKETVER >= 20161012
  18273. nullpo_retv( sd );
  18274. struct PACKET_ZC_OPEN_REFINING_UI p = {};
  18275. p.packetType = HEADER_ZC_OPEN_REFINING_UI;
  18276. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18277. sd->state.refineui_open = true;
  18278. #endif
  18279. }
  18280. /**
  18281. * Parses cancel/close of the refine UI on client side.
  18282. * 0aa4
  18283. */
  18284. void clif_parse_refineui_close( int fd, map_session_data* sd ){
  18285. #if PACKETVER >= 20161012
  18286. sd->state.refineui_open = false;
  18287. #endif
  18288. }
  18289. /**
  18290. * Adds the selected item into the refine UI and sends the possible materials
  18291. * to the client.
  18292. * 0aa2 <length>.W <index>.W <catalyst count>.B { <material>.W <chance>.B <price>.L }*
  18293. */
  18294. void clif_refineui_info( map_session_data* sd, uint16 index ){
  18295. #if PACKETVER >= 20161012
  18296. int fd = sd->fd;
  18297. // Get the item db reference
  18298. struct item_data* id = sd->inventory_data[index];
  18299. // No item data was found
  18300. if( id == nullptr ){
  18301. return;
  18302. }
  18303. // Check the inventory
  18304. struct item* item = &sd->inventory.u.items_inventory[index];
  18305. // No item was found at the given index
  18306. if( item == nullptr ){
  18307. return;
  18308. }
  18309. // Check if the item is identified
  18310. if( !item->identify ){
  18311. return;
  18312. }
  18313. // Check if the item is broken
  18314. if( item->attribute ){
  18315. return;
  18316. }
  18317. PACKET_ZC_REFINING_MATERIAL_LIST* p = reinterpret_cast<PACKET_ZC_REFINING_MATERIAL_LIST*>( packet_buffer );
  18318. p->packetType = HEADER_ZC_REFINING_MATERIAL_LIST;
  18319. p->packetLength = sizeof( *p );
  18320. p->itemIndex = client_index( index );
  18321. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18322. // No possibilities were found
  18323. if( info == nullptr ){
  18324. p->blacksmithBlessing = 0;
  18325. }else{
  18326. p->blacksmithBlessing = static_cast<decltype(p->blacksmithBlessing)>( info->blessing_amount );
  18327. for( uint16 i = REFINE_COST_NORMAL, count = 0; i < REFINE_COST_MAX; i++ ){
  18328. std::shared_ptr<s_refine_cost> cost = util::umap_find( info->costs, i );
  18329. if( cost == nullptr ){
  18330. continue;
  18331. }
  18332. PACKET_ZC_REFINING_MATERIAL_LIST_SUB& entry = p->req[count];
  18333. entry.itemId = client_nameid( cost->nameid );
  18334. entry.chance = static_cast<decltype(entry.chance)>( cost->chance / 100 );
  18335. entry.zeny = cost->zeny;
  18336. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  18337. count++;
  18338. }
  18339. }
  18340. clif_send( p, p->packetLength, &sd->bl, SELF );
  18341. #endif
  18342. }
  18343. /**
  18344. * Client request to add an item to the refine UI.
  18345. * 0aa1 <index>.W
  18346. */
  18347. void clif_parse_refineui_add( int fd, map_session_data* sd ){
  18348. #if PACKETVER >= 20161012
  18349. struct PACKET_CZ_REFINING_SELECT_ITEM* p = (struct PACKET_CZ_REFINING_SELECT_ITEM*)RFIFOP( fd, 0 );
  18350. uint16 index = server_index( p->index );
  18351. // Check if the refine UI is open
  18352. if( !sd->state.refineui_open ){
  18353. return;
  18354. }
  18355. // Check if the index is valid
  18356. if( index >= MAX_INVENTORY ){
  18357. return;
  18358. }
  18359. // Send out the requirements for the refine process
  18360. clif_refineui_info( sd, index );
  18361. #endif
  18362. }
  18363. /**
  18364. * Client requests to try to refine an item.
  18365. * 0aa3 <index>.W <material>.W <catalyst>.B
  18366. */
  18367. void clif_parse_refineui_refine( int fd, map_session_data* sd ){
  18368. #if PACKETVER >= 20161012
  18369. struct PACKET_CZ_REQ_REFINING* p = (struct PACKET_CZ_REQ_REFINING*)RFIFOP( fd, 0 );
  18370. uint16 index = server_index( p->index );
  18371. t_itemid material = p->itemId;
  18372. int16 j;
  18373. // Check if the refine UI is open
  18374. if( !sd->state.refineui_open ){
  18375. return;
  18376. }
  18377. // Check if the index is valid
  18378. if( index >= MAX_INVENTORY ){
  18379. return;
  18380. }
  18381. // Get the item db reference
  18382. struct item_data* id = sd->inventory_data[index];
  18383. // No item data was found
  18384. if( id == nullptr ){
  18385. return;
  18386. }
  18387. // Check the inventory
  18388. struct item* item = &sd->inventory.u.items_inventory[index];
  18389. // No item was found at the given index
  18390. if( item == nullptr ){
  18391. return;
  18392. }
  18393. // Check if the item is identified
  18394. if( !item->identify ){
  18395. return;
  18396. }
  18397. // Check if the item is broken
  18398. if( item->attribute ){
  18399. return;
  18400. }
  18401. std::shared_ptr<s_refine_level_info> info = refine_db.findLevelInfo( *id, *item );
  18402. // No refine possible
  18403. if( info == nullptr ){
  18404. return;
  18405. }
  18406. // No possibilities were found
  18407. if( info->costs.empty() ){
  18408. return;
  18409. }
  18410. // Check if the player has the selected material
  18411. if( ( j = pc_search_inventory( sd, material ) ) < 0 ){
  18412. return;
  18413. }
  18414. int16 blacksmith_index = -1;
  18415. uint16 blacksmith_amount = 0;
  18416. // Check if the player has enough blacksmith blessings
  18417. if( p->blacksmithBlessing != 0 ){
  18418. blacksmith_amount = info->blessing_amount;
  18419. // Player tried to use blacksmith blessing on a refine level, where it is not available
  18420. if( blacksmith_amount == 0 ){
  18421. return;
  18422. }
  18423. // Check if the player has blacksmith blessings
  18424. if( ( blacksmith_index = pc_search_inventory( sd, ITEMID_BLACKSMITH_BLESSING ) ) < 0 ){
  18425. return;
  18426. }
  18427. // Check if the player has enough blacksmith blessings
  18428. if( sd->inventory.u.items_inventory[blacksmith_index].amount < blacksmith_amount ){
  18429. return;
  18430. }
  18431. }
  18432. std::shared_ptr<s_refine_cost> cost = nullptr;
  18433. for( const auto& pair : info->costs ){
  18434. if( pair.second->nameid == material ){
  18435. cost = pair.second;
  18436. break;
  18437. }
  18438. }
  18439. // The material was not in the list of possible materials
  18440. if( cost == nullptr ){
  18441. return;
  18442. }
  18443. // Try to pay for the refine
  18444. if( pc_payzeny( sd, cost->zeny, LOG_TYPE_CONSUME ) ){
  18445. clif_npc_buy_result( sd, e_purchase_result::PURCHASE_FAIL_MONEY ); // "You do not have enough zeny."
  18446. return;
  18447. }
  18448. // Delete the required material
  18449. if( pc_delitem( sd, j, 1, 0, 0, LOG_TYPE_CONSUME ) ){
  18450. return;
  18451. }
  18452. // Delete the required blacksmith blessings
  18453. if( blacksmith_amount > 0 && pc_delitem( sd, blacksmith_index, blacksmith_amount, 0, 0, LOG_TYPE_CONSUME ) ){
  18454. return;
  18455. }
  18456. // Try to refine the item
  18457. if( cost->chance >= ( rnd() % 10000 ) ){
  18458. log_pick_pc( sd, LOG_TYPE_OTHER, -1, item );
  18459. // Success
  18460. item->refine = cap_value( item->refine + 1, 0, MAX_REFINE );
  18461. log_pick_pc( sd, LOG_TYPE_OTHER, 1, item );
  18462. clif_misceffect( sd->bl, NOTIFYEFFECT_REFINE_SUCCESS );
  18463. clif_refine( *sd, index, ITEMREFINING_SUCCESS );
  18464. if (info->broadcast_success) {
  18465. clif_broadcast_refine_result(*sd, item->nameid, item->refine, true);
  18466. }
  18467. if( id->type == IT_WEAPON ){
  18468. achievement_update_objective( sd, AG_ENCHANT_SUCCESS, 2, id->weapon_level, item->refine );
  18469. }
  18470. clif_refineui_info( sd, index );
  18471. }else{
  18472. // Failure
  18473. if (info->broadcast_failure) {
  18474. clif_broadcast_refine_result(*sd, item->nameid, item->refine, false);
  18475. }
  18476. // Blacksmith blessings were used to prevent breaking and downgrading
  18477. if( blacksmith_amount > 0 ){
  18478. clif_refine( *sd, index, ITEMREFINING_FAILURE2 );
  18479. clif_refineui_info( sd, index );
  18480. // Delete the item if it is breakable
  18481. }else if( cost->breaking_rate > 0 && ( rnd() % 10000 ) < cost->breaking_rate ){
  18482. clif_refine( *sd, index, ITEMREFINING_FAILURE );
  18483. pc_delitem( sd, index, 1, 0, 2, LOG_TYPE_CONSUME );
  18484. // Downgrade the item if necessary
  18485. }else if( cost->downgrade_amount > 0 ){
  18486. item->refine = cap_value( item->refine - cost->downgrade_amount, 0, MAX_REFINE );
  18487. clif_refine( *sd, index, ITEMREFINING_DOWNGRADE );
  18488. clif_refineui_info(sd, index);
  18489. // Only show failure, but dont do anything
  18490. }else{
  18491. clif_refine( *sd, index, ITEMREFINING_FAILURE2 );
  18492. clif_refineui_info( sd, index );
  18493. }
  18494. clif_misceffect( sd->bl, NOTIFYEFFECT_REFINE_FAILURE );
  18495. achievement_update_objective( sd, AG_ENCHANT_FAIL, 1, 1 );
  18496. }
  18497. #endif
  18498. }
  18499. void clif_unequipall_reply( map_session_data* sd, bool failed ){
  18500. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18501. struct PACKET_ZC_ACK_TAKEOFF_EQUIP_ALL p = {};
  18502. p.PacketType = HEADER_ZC_ACK_TAKEOFF_EQUIP_ALL;
  18503. p.result = failed;
  18504. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18505. #endif // PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103
  18506. }
  18507. void clif_parse_unequipall( int fd, map_session_data* sd ){
  18508. #if PACKETVER_MAIN_NUM >= 20210818 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210818
  18509. if( pc_cant_act( sd ) ){
  18510. clif_unequipall_reply( sd, true );
  18511. return;
  18512. }
  18513. struct PACKET_CZ_REQ_TAKEOFF_EQUIP_ALL* p = (struct PACKET_CZ_REQ_TAKEOFF_EQUIP_ALL*)RFIFOP( fd, 0 );
  18514. #if PACKETVER_MAIN_NUM >= 20230906
  18515. uint32 location = p->location;
  18516. int max = EQI_MAX;
  18517. #else
  18518. uint32 location = 0xFFFFFFFF;
  18519. int max = EQI_COSTUME_HEAD_TOP;
  18520. #endif
  18521. for( int i = 0; i < max; i++ ){
  18522. if( sd->equip_index[i] >= 0 && ( location & equip_bitmask[i] ) != 0 ){
  18523. pc_unequipitem( sd, sd->equip_index[i], 1 );
  18524. }
  18525. }
  18526. clif_unequipall_reply( sd, false );
  18527. #endif
  18528. }
  18529. void clif_stylist_response( map_session_data* sd, bool failed ){
  18530. #if PACKETVER >= 20151104
  18531. struct PACKET_ZC_STYLE_CHANGE_RES p = {};
  18532. p.PacketType = HEADER_ZC_STYLE_CHANGE_RES;
  18533. p.flag = failed;
  18534. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18535. if( !failed ){
  18536. sd->state.stylist_open = false;
  18537. }
  18538. #endif
  18539. }
  18540. bool clif_parse_stylist_buy_sub( map_session_data* sd, _look look, int16 index ){
  18541. std::shared_ptr<s_stylist_list> list = stylist_db.find( look );
  18542. if( list == nullptr ){
  18543. return false;
  18544. }
  18545. std::shared_ptr<s_stylist_entry> entry = util::umap_find( list->entries, index );
  18546. if( entry == nullptr ){
  18547. return false;
  18548. }
  18549. std::shared_ptr<s_stylist_costs> costs;
  18550. if( ( sd->class_ & MAPID_BASEMASK ) == MAPID_SUMMONER ){
  18551. costs = entry->doram;
  18552. }else{
  18553. costs = entry->human;
  18554. }
  18555. if( costs == nullptr ){
  18556. return false;
  18557. }
  18558. if( sd->status.zeny < costs->price ){
  18559. return false;
  18560. }
  18561. int16 inventoryIndex = -1;
  18562. if( costs->requiredItem != 0 ){
  18563. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18564. if( inventoryIndex < 0 ){
  18565. // No other option
  18566. if( costs->requiredItemBox == 0 ){
  18567. return false;
  18568. }
  18569. // Check if the box that contains the item is in the inventory
  18570. inventoryIndex = pc_search_inventory( sd, costs->requiredItemBox );
  18571. // The box containing the item also does not exist
  18572. if( inventoryIndex < 0 ){
  18573. return false;
  18574. }
  18575. }
  18576. }else if( costs->requiredItemBox != 0 ){
  18577. inventoryIndex = pc_search_inventory( sd, costs->requiredItem );
  18578. if( inventoryIndex < 0 ){
  18579. return false;
  18580. }
  18581. }
  18582. if( inventoryIndex >= 0 && pc_delitem( sd, inventoryIndex, 1, 0, 0, LOG_TYPE_OTHER ) != 0 ){
  18583. return false;
  18584. }
  18585. if( costs->price > 0 && pc_payzeny( sd, costs->price, LOG_TYPE_OTHER ) != 0 ){
  18586. return false;
  18587. }
  18588. switch( look ){
  18589. case LOOK_HAIR:
  18590. case LOOK_HAIR_COLOR:
  18591. case LOOK_CLOTHES_COLOR:
  18592. case LOOK_BODY2:
  18593. pc_changelook( sd, look, entry->value );
  18594. break;
  18595. case LOOK_HEAD_BOTTOM:
  18596. case LOOK_HEAD_MID:
  18597. case LOOK_HEAD_TOP: {
  18598. struct mail_message msg = {};
  18599. msg.dest_id = sd->status.char_id;
  18600. safestrncpy( msg.send_name, "Styling Shop", NAME_LENGTH );
  18601. safestrncpy( msg.title, "<MSG>2949</MSG>", MAIL_TITLE_LENGTH );
  18602. safestrncpy( msg.body, "<MSG>2950</MSG>", MAIL_BODY_LENGTH );
  18603. msg.item[0].nameid = entry->value;
  18604. msg.item[0].identify = 1;
  18605. msg.item[0].amount = 1;
  18606. msg.status = MAIL_NEW;
  18607. msg.type = MAIL_INBOX_NORMAL;
  18608. msg.timestamp = time( nullptr );
  18609. intif_Mail_send( 0, &msg );
  18610. } break;
  18611. }
  18612. return true;
  18613. }
  18614. void clif_parse_stylist_buy( int fd, map_session_data* sd ){
  18615. #if PACKETVER >= 20151104
  18616. #if PACKETVER >= 20180516
  18617. struct PACKET_CZ_REQ_STYLE_CHANGE2* p = (struct PACKET_CZ_REQ_STYLE_CHANGE2*)RFIFOP( fd, 0 );
  18618. #else
  18619. struct PACKET_CZ_REQ_STYLE_CHANGE* p = (struct PACKET_CZ_REQ_STYLE_CHANGE*)RFIFOP( fd, 0 );
  18620. #endif
  18621. if( p->HeadPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR_COLOR, p->HeadPalette ) ){
  18622. clif_stylist_response( sd, true );
  18623. return;
  18624. }
  18625. if( p->HeadStyle != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HAIR, p->HeadStyle ) ){
  18626. clif_stylist_response( sd, true );
  18627. return;
  18628. }
  18629. if( p->BodyPalette != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_CLOTHES_COLOR, p->BodyPalette ) ){
  18630. clif_stylist_response( sd, true );
  18631. return;
  18632. }
  18633. if( p->TopAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_TOP, p->TopAccessory ) ){
  18634. clif_stylist_response( sd, true );
  18635. return;
  18636. }
  18637. if( p->MidAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_MID, p->MidAccessory ) ){
  18638. clif_stylist_response( sd, true );
  18639. return;
  18640. }
  18641. if( p->BottomAccessory != 0 && !clif_parse_stylist_buy_sub( sd, LOOK_HEAD_BOTTOM, p->BottomAccessory ) ){
  18642. clif_stylist_response( sd, true );
  18643. return;
  18644. }
  18645. #if PACKETVER >= 20180516
  18646. if( p->BodyStyle != 0 && ( sd->class_ & JOBL_THIRD ) != 0 && ( sd->class_ & JOBL_FOURTH ) == 0 && !clif_parse_stylist_buy_sub( sd, LOOK_BODY2, p->BodyStyle ) ){
  18647. clif_stylist_response( sd, true );
  18648. return;
  18649. }
  18650. #endif
  18651. clif_stylist_response( sd, false );
  18652. #endif
  18653. }
  18654. void clif_parse_stylist_close( int fd, map_session_data* sd ){
  18655. #if PACKETVER >= 20151104
  18656. sd->state.stylist_open = false;
  18657. #endif
  18658. }
  18659. void clif_inventory_expansion_info( map_session_data* sd ){
  18660. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18661. nullpo_retv( sd );
  18662. struct PACKET_ZC_EXTEND_BODYITEM_SIZE p = {};
  18663. p.packetType = HEADER_ZC_EXTEND_BODYITEM_SIZE;
  18664. p.expansionSize = sd->status.inventory_slots - INVENTORY_BASE_SIZE;
  18665. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18666. #endif
  18667. }
  18668. enum class e_inventory_expansion_response : uint8{
  18669. ASK_CONFIRMATION = 0,
  18670. FAILED,
  18671. BUSY,
  18672. MISSING_ITEM,
  18673. MAXIMUM_REACHED
  18674. };
  18675. void clif_inventory_expansion_response( map_session_data* sd, e_inventory_expansion_response response ){
  18676. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18677. nullpo_retv( sd );
  18678. struct PACKET_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE p = {};
  18679. p.packetType = HEADER_ZC_ACK_OPEN_MSGBOX_EXTEND_BODYITEM_SIZE;
  18680. p.result = (uint8)response;
  18681. p.itemId = sd->state.inventory_expansion_confirmation;
  18682. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18683. #endif
  18684. }
  18685. void clif_parse_inventory_expansion_request( int fd, map_session_data* sd ){
  18686. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18687. // Check if player is dead or busy with other stuff
  18688. if( pc_isdead( sd ) || pc_cant_act( sd ) ){
  18689. clif_inventory_expansion_response( sd, e_inventory_expansion_response::BUSY );
  18690. return;
  18691. }
  18692. // Check if the player already reached the maximum
  18693. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18694. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18695. return;
  18696. }
  18697. static std::map<t_itemid, uint16> items = {
  18698. // The order of entries in this list defines which will be used first
  18699. // This order and the usable items are hardcoded into the client
  18700. // The number of increased slots is "hardcoded" in the message of the client and cannot be sent per item
  18701. { ITEMID_INVENTORY_EX_EVT, 10 },
  18702. { ITEMID_INVENTORY_EX_DIS, 10 },
  18703. { ITEMID_INVENTORY_EX, 10 },
  18704. };
  18705. int16 index = -1;
  18706. bool found_over_limit = false;
  18707. for( const auto& entry : items ){
  18708. // Check if the player has the required item
  18709. index = pc_search_inventory( sd, entry.first );
  18710. // Found an item
  18711. if( index >= 0 ){
  18712. // Check if the player would exceed the maximum
  18713. if( sd->status.inventory_slots + entry.second > MAX_INVENTORY ){
  18714. found_over_limit = true;
  18715. }else{
  18716. found_over_limit = false;
  18717. sd->state.inventory_expansion_confirmation = entry.first;
  18718. sd->state.inventory_expansion_amount = entry.second;
  18719. break;
  18720. }
  18721. }
  18722. }
  18723. // Check if an item was found
  18724. if( sd->state.inventory_expansion_confirmation == 0 ){
  18725. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MISSING_ITEM );
  18726. return;
  18727. }
  18728. // Check if an item would have been found, but the player would exceed the maximum
  18729. if( found_over_limit ){
  18730. clif_inventory_expansion_response( sd, e_inventory_expansion_response::MAXIMUM_REACHED );
  18731. return;
  18732. }
  18733. // The player met all requirements => ask him for confirmation
  18734. clif_inventory_expansion_response( sd, e_inventory_expansion_response::ASK_CONFIRMATION );
  18735. #endif
  18736. }
  18737. enum class e_inventory_expansion_result : uint8{
  18738. SUCCESS = 0,
  18739. FAILED,
  18740. BUSY,
  18741. MISSING_ITEM,
  18742. MAXIMUM_REACHED
  18743. };
  18744. void clif_inventory_expansion_result( map_session_data* sd, e_inventory_expansion_result result ){
  18745. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18746. nullpo_retv( sd );
  18747. struct PACKET_ZC_ACK_EXTEND_BODYITEM_SIZE p = {};
  18748. p.packetType = HEADER_ZC_ACK_EXTEND_BODYITEM_SIZE;
  18749. p.result = (uint8)result;
  18750. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  18751. // Reset the state tracking
  18752. sd->state.inventory_expansion_confirmation = 0;
  18753. sd->state.inventory_expansion_amount = 0;
  18754. #endif
  18755. }
  18756. void clif_parse_inventory_expansion_confirm( int fd, map_session_data* sd ){
  18757. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18758. if( sd->state.inventory_expansion_confirmation == 0 ){
  18759. return;
  18760. }
  18761. // Check if player is dead
  18762. if( pc_isdead( sd ) ){
  18763. clif_inventory_expansion_result( sd, e_inventory_expansion_result::BUSY );
  18764. return;
  18765. }
  18766. // Check if the player already reached the maximum
  18767. if( sd->status.inventory_slots >= MAX_INVENTORY ){
  18768. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18769. return;
  18770. }
  18771. // Check if the player has the required item
  18772. int index = pc_search_inventory( sd, sd->state.inventory_expansion_confirmation );
  18773. // The player did not have the item anymore
  18774. if( index < 0 ){
  18775. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MISSING_ITEM );
  18776. return;
  18777. }
  18778. // Check if the player would exceed the maximum
  18779. if( sd->status.inventory_slots + sd->state.inventory_expansion_amount > MAX_INVENTORY ){
  18780. clif_inventory_expansion_result( sd, e_inventory_expansion_result::MAXIMUM_REACHED );
  18781. return;
  18782. }
  18783. // Delete the required item
  18784. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_OTHER ) ){
  18785. clif_inventory_expansion_result( sd, e_inventory_expansion_result::FAILED );
  18786. return;
  18787. }
  18788. // Increase the slots
  18789. sd->status.inventory_slots += sd->state.inventory_expansion_amount;
  18790. // Save player data (slots) and inventory data (removed item)
  18791. chrif_save( sd, CSAVE_NORMAL | CSAVE_INVENTORY );
  18792. // Inform the player of success
  18793. clif_inventory_expansion_result( sd, e_inventory_expansion_result::SUCCESS );
  18794. clif_inventory_expansion_info( sd );
  18795. #endif
  18796. }
  18797. void clif_parse_inventory_expansion_reject( int fd, map_session_data* sd ){
  18798. #if PACKETVER_MAIN_NUM >= 20181219 || PACKETVER_RE_NUM >= 20181219 || PACKETVER_ZERO_NUM >= 20181212
  18799. sd->state.inventory_expansion_confirmation = 0;
  18800. sd->state.inventory_expansion_amount = 0;
  18801. #endif
  18802. }
  18803. void clif_barter_open( map_session_data& sd, struct npc_data& nd ){
  18804. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18805. if( nd.subtype != NPCTYPE_BARTER || nd.u.barter.extended || sd.state.barter_open ){
  18806. return;
  18807. }
  18808. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18809. if( barter == nullptr ){
  18810. return;
  18811. }
  18812. sd.state.barter_open = true;
  18813. PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO* p = reinterpret_cast<PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO*>( packet_buffer );
  18814. p->packetType = HEADER_ZC_NPC_BARTER_MARKET_ITEMINFO;
  18815. p->packetLength = sizeof( *p );
  18816. int16 count = 0;
  18817. for( const auto& itemPair : barter->items ){
  18818. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18819. if( id == nullptr ){
  18820. continue;
  18821. }
  18822. PACKET_ZC_NPC_BARTER_MARKET_ITEMINFO_sub& item = p->list[count];
  18823. item.nameid = client_nameid( id->nameid );
  18824. item.type = itemtype( id->nameid );
  18825. if( itemPair.second->stockLimited ){
  18826. item.amount = itemPair.second->stock;
  18827. }else{
  18828. item.amount = -1;
  18829. }
  18830. item.weight = id->weight;
  18831. item.index = itemPair.second->index;
  18832. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18833. item.viewSprite = id->look;
  18834. item.location = pc_equippoint_sub( &sd, id.get() );
  18835. #endif
  18836. // Use a loop if someone did not start with index 0
  18837. for( const auto& requirementPair : itemPair.second->requirements ){
  18838. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  18839. item.currencyNameid = client_nameid( requirement->nameid );
  18840. item.currencyAmount = requirement->amount;
  18841. // It is a normal barter, cancel after first entry
  18842. break;
  18843. }
  18844. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( item ) );
  18845. count++;
  18846. }
  18847. clif_send( p, p->packetLength, &sd.bl, SELF );
  18848. #endif
  18849. }
  18850. void clif_parse_barter_close( int fd, map_session_data* sd ){
  18851. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18852. if( sd->state.barter_open ){
  18853. sd->npc_shopid = 0;
  18854. sd->state.barter_open = false;
  18855. }
  18856. #endif
  18857. }
  18858. void clif_parse_barter_buy( int fd, map_session_data* sd ){
  18859. #if PACKETVER_MAIN_NUM >= 20190116 || PACKETVER_RE_NUM >= 20190116 || PACKETVER_ZERO_NUM >= 20181226
  18860. // No shop open
  18861. if( sd->npc_shopid == 0 || !sd->state.barter_open ){
  18862. return;
  18863. }
  18864. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  18865. // Unknown shop
  18866. if( nd == nullptr ){
  18867. return;
  18868. }
  18869. // Not a barter
  18870. if( nd->subtype != NPCTYPE_BARTER ){
  18871. return;
  18872. }
  18873. // It is an extended barter
  18874. if( nd->u.barter.extended ){
  18875. return;
  18876. }
  18877. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  18878. if( barter == nullptr ){
  18879. return;
  18880. }
  18881. struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  18882. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_BARTER_MARKET_PURCHASE_sub );
  18883. // Empty purchase list
  18884. if( entries == 0 ){
  18885. return;
  18886. }
  18887. std::vector<s_barter_purchase> purchases;
  18888. purchases.reserve( entries );
  18889. // Make sure each shop index and target item id is only used once
  18890. for( int i = 0; i < entries; i++ ){
  18891. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  18892. // Invalid shop index
  18893. if( item == nullptr ){
  18894. return;
  18895. }
  18896. for( int j = i + 1; j < entries; j++ ){
  18897. // Same shop index
  18898. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  18899. return;
  18900. }
  18901. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  18902. // Invalid shop index
  18903. if( item2 == nullptr ){
  18904. return;
  18905. }
  18906. // Same target item id
  18907. if( item->nameid == item2->nameid ){
  18908. return;
  18909. }
  18910. }
  18911. s_barter_purchase purchase = {};
  18912. purchase.item = item;
  18913. purchase.amount = p->list[i].amount;
  18914. purchases.push_back( purchase );
  18915. }
  18916. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  18917. #endif
  18918. }
  18919. void clif_barter_extended_open( map_session_data& sd, struct npc_data& nd ){
  18920. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  18921. if( nd.subtype != NPCTYPE_BARTER || !nd.u.barter.extended || sd.state.barter_extended_open ){
  18922. return;
  18923. }
  18924. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd.exname );
  18925. if( barter == nullptr ){
  18926. return;
  18927. }
  18928. sd.state.barter_extended_open = true;
  18929. PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO* p = reinterpret_cast<PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO*>( packet_buffer );
  18930. p->packetType = HEADER_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO;
  18931. p->packetLength = sizeof( *p );
  18932. p->items_count = 0;
  18933. for( const auto& itemPair : barter->items ){
  18934. std::shared_ptr<item_data> id = item_db.find(itemPair.second->nameid);
  18935. if( id == nullptr ){
  18936. continue;
  18937. }
  18938. // Needs dynamic calculation, because of variable currencies
  18939. PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub* item = reinterpret_cast<PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub*>( WBUFP( p, p->packetLength ) );
  18940. item->nameid = client_nameid( id->nameid );
  18941. item->type = itemtype( id->nameid );
  18942. if( itemPair.second->stockLimited ){
  18943. item->amount = itemPair.second->stock;
  18944. }else{
  18945. item->amount = -1;
  18946. }
  18947. item->weight = id->weight;
  18948. item->index = itemPair.second->index;
  18949. item->zeny = itemPair.second->price;
  18950. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103
  18951. item->viewSprite = id->look;
  18952. item->location = pc_equippoint_sub( &sd, id.get() );
  18953. #endif
  18954. // Because of a MSVS bug, the currencies have been defined with a fixed array entry, which has to be substracted
  18955. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( *item ) - sizeof( item->currencies ) );
  18956. p->items_count++;
  18957. item->currency_count = 0;
  18958. for( const auto& requirementPair : itemPair.second->requirements ){
  18959. // Needs dynamic calculation, because of variable currencies
  18960. PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2* req = reinterpret_cast<PACKET_ZC_NPC_EXPANDED_BARTER_MARKET_ITEMINFO_sub2*>( WBUFP( p, p->packetLength ) );
  18961. std::shared_ptr<s_npc_barter_requirement> requirement = requirementPair.second;
  18962. req->nameid = requirement->nameid;
  18963. if( requirement->refine >= 0 ){
  18964. req->refine_level = requirement->refine;
  18965. }else{
  18966. req->refine_level = 0;
  18967. }
  18968. req->amount = requirement->amount;
  18969. req->type = itemtype( requirement->nameid );
  18970. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( *req ) );
  18971. item->currency_count++;
  18972. }
  18973. }
  18974. clif_send( p, p->packetLength, &sd.bl, SELF );
  18975. #endif
  18976. }
  18977. void clif_parse_barter_extended_close( int fd, map_session_data* sd ){
  18978. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  18979. if( sd->state.barter_extended_open ){
  18980. sd->npc_shopid = 0;
  18981. sd->state.barter_extended_open = false;
  18982. }
  18983. #endif
  18984. }
  18985. void clif_parse_barter_extended_buy( int fd, map_session_data* sd ){
  18986. #if PACKETVER_MAIN_NUM >= 20191120 || PACKETVER_RE_NUM >= 20191106 || PACKETVER_ZERO_NUM >= 20191127
  18987. // No shop open
  18988. if( sd->npc_shopid == 0 || !sd->state.barter_extended_open ){
  18989. return;
  18990. }
  18991. struct npc_data* nd = map_id2nd( sd->npc_shopid );
  18992. // Unknown shop
  18993. if( nd == nullptr ){
  18994. return;
  18995. }
  18996. // Not a barter
  18997. if( nd->subtype != NPCTYPE_BARTER ){
  18998. return;
  18999. }
  19000. // Not an extended barter
  19001. if( !nd->u.barter.extended ){
  19002. return;
  19003. }
  19004. std::shared_ptr<s_npc_barter> barter = barter_db.find( nd->exname );
  19005. if( barter == nullptr ){
  19006. return;
  19007. }
  19008. struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE* p = (struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE*)RFIFOP( fd, 0 );
  19009. uint16 entries = ( p->packetLength - sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE ) ) / sizeof( struct PACKET_CZ_NPC_EXPANDED_BARTER_MARKET_PURCHASE_sub );
  19010. // Empty purchase list
  19011. if( entries == 0 ){
  19012. return;
  19013. }
  19014. std::vector<s_barter_purchase> purchases;
  19015. purchases.reserve( entries );
  19016. // Make sure each shop index and target item id is only used once
  19017. for( int i = 0; i < entries; i++ ){
  19018. std::shared_ptr<s_npc_barter_item> item = util::map_find( barter->items, (uint16)p->list[i].shopIndex );
  19019. // Invalid shop index
  19020. if( item == nullptr ){
  19021. return;
  19022. }
  19023. for( int j = i + 1; j < entries; j++ ){
  19024. // Same shop index
  19025. if( p->list[i].shopIndex == p->list[j].shopIndex ){
  19026. return;
  19027. }
  19028. std::shared_ptr<s_npc_barter_item> item2 = util::map_find( barter->items, (uint16)p->list[j].shopIndex );
  19029. // Invalid shop index
  19030. if( item2 == nullptr ){
  19031. return;
  19032. }
  19033. // Same target item id
  19034. if( item->nameid == item2->nameid ){
  19035. return;
  19036. }
  19037. }
  19038. s_barter_purchase purchase = {};
  19039. purchase.item = item;
  19040. purchase.amount = p->list[i].amount;
  19041. purchases.push_back( purchase );
  19042. }
  19043. clif_npc_buy_result( sd, npc_barter_purchase( *sd, barter, purchases ) );
  19044. #endif
  19045. }
  19046. void clif_summon_init(struct mob_data& md) {
  19047. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19048. struct block_list* master_bl = battle_get_master(&md.bl);
  19049. if( master_bl == nullptr ){
  19050. return;
  19051. }
  19052. struct PACKET_ZC_SUMMON_HP_INIT p = {};
  19053. p.PacketType = HEADER_ZC_SUMMON_HP_INIT;
  19054. p.summonAID = md.bl.id;
  19055. p.CurrentHP = md.status.hp;
  19056. p.MaxHP = md.status.max_hp;
  19057. clif_send( &p, sizeof( p ), master_bl, SELF );
  19058. #endif
  19059. }
  19060. void clif_summon_hp_bar(struct mob_data& md) {
  19061. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19062. struct block_list* master_bl = battle_get_master(&md.bl);
  19063. if( master_bl == nullptr ){
  19064. return;
  19065. }
  19066. struct PACKET_ZC_SUMMON_HP_UPDATE p = {};
  19067. p.PacketType = HEADER_ZC_SUMMON_HP_UPDATE;
  19068. p.summonAID = md.bl.id;
  19069. p.VarId = SP_HP; // HP parameter
  19070. p.Value = md.status.hp;
  19071. clif_send( &p, sizeof( p ), master_bl, SELF );
  19072. #endif
  19073. }
  19074. void clif_laphine_synthesis_open( map_session_data *sd, std::shared_ptr<s_laphine_synthesis> synthesis ){
  19075. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19076. nullpo_retv( sd );
  19077. sd->state.laphine_synthesis = synthesis->item_id;
  19078. struct PACKET_ZC_RANDOM_COMBINE_ITEM_UI_OPEN p = {};
  19079. p.packetType = HEADER_ZC_RANDOM_COMBINE_ITEM_UI_OPEN;
  19080. p.itemId = client_nameid( synthesis->item_id );
  19081. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19082. #endif
  19083. }
  19084. void clif_parse_laphine_synthesis_close( int fd, map_session_data* sd ){
  19085. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19086. sd->state.laphine_synthesis = 0;
  19087. #endif
  19088. }
  19089. enum e_laphine_synthesis_result : int16{
  19090. LAPHINE_SYNTHESIS_SUCCESS = 0,
  19091. LAPHINE_SYNTHESIS_AMOUNT = 5,
  19092. LAPHINE_SYNTHESIS_ITEM = 7
  19093. };
  19094. void clif_laphine_synthesis_result( map_session_data* sd, enum e_laphine_synthesis_result result ){
  19095. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19096. nullpo_retv( sd );
  19097. struct PACKET_ZC_ACK_RANDOM_COMBINE_ITEM p = {};
  19098. p.packetType = HEADER_ZC_ACK_RANDOM_COMBINE_ITEM;
  19099. p.result = result;
  19100. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19101. #endif
  19102. }
  19103. void clif_parse_laphine_synthesis( int fd, map_session_data* sd ){
  19104. #if PACKETVER_MAIN_NUM >= 20160601 || PACKETVER_RE_NUM >= 20160525 || defined(PACKETVER_ZERO)
  19105. if( sd->state.laphine_synthesis == 0 ){
  19106. return;
  19107. }
  19108. struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM*)RFIFOP( fd, 0 );
  19109. if( sd->state.laphine_synthesis != p->itemId ){
  19110. return;
  19111. }
  19112. std::shared_ptr<s_laphine_synthesis> synthesis = laphine_synthesis_db.find( sd->state.laphine_synthesis );
  19113. if( synthesis == nullptr ){
  19114. return;
  19115. }
  19116. size_t count = ( p->packetLength - sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM ) ) / sizeof( struct PACKET_CZ_REQ_RANDOM_COMBINE_ITEM_sub );
  19117. // Player sent more or less than actually required
  19118. if( count != synthesis->requiredRequirements ){
  19119. return;
  19120. }
  19121. // Check for duplicates
  19122. for( size_t i = 0; i < count; i++ ){
  19123. for( size_t j = i + 1; j < count; j++ ){
  19124. if( p->items[i].index == p->items[j].index ){
  19125. return;
  19126. }
  19127. }
  19128. }
  19129. for( size_t i = 0; i < count; i++ ){
  19130. int16 index = server_index( p->items[i].index );
  19131. if( index >= MAX_INVENTORY ){
  19132. return;
  19133. }
  19134. if( sd->inventory_data[index] == nullptr ){
  19135. return;
  19136. }
  19137. struct item* item = &sd->inventory.u.items_inventory[index];
  19138. std::shared_ptr<s_laphine_synthesis_requirement> requirement = util::umap_find( synthesis->requirements, item->nameid );
  19139. if( requirement == nullptr ){
  19140. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19141. return;
  19142. }
  19143. if( p->items[i].count != requirement->amount ){
  19144. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19145. return;
  19146. }
  19147. if( item->amount < requirement->amount ){
  19148. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_AMOUNT );
  19149. return;
  19150. }
  19151. if( item->refine < synthesis->minimumRefine ){
  19152. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19153. return;
  19154. }
  19155. if( item->refine > synthesis->maximumRefine ){
  19156. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19157. return;
  19158. }
  19159. if( item->equip != 0 ){
  19160. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19161. return;
  19162. }
  19163. if( item->equipSwitch != 0 ){
  19164. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19165. return;
  19166. }
  19167. }
  19168. // If triggered from item
  19169. if( sd->itemid == sd->state.laphine_synthesis ){
  19170. int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis );
  19171. if( index < 0 ){
  19172. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM );
  19173. return;
  19174. }
  19175. if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19176. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19177. return;
  19178. }
  19179. }
  19180. }
  19181. for( size_t i = 0; i < count; i++ ){
  19182. int16 index = server_index( p->items[i].index );
  19183. if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19184. return;
  19185. }
  19186. }
  19187. itemdb_group.pc_get_itemgroup( synthesis->rewardGroupId, true, *sd );
  19188. clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_SUCCESS );
  19189. #endif
  19190. }
  19191. void clif_laphine_upgrade_open( map_session_data* sd, std::shared_ptr<s_laphine_upgrade> upgrade ){
  19192. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19193. nullpo_retv( sd );
  19194. sd->state.laphine_upgrade = upgrade->item_id;
  19195. struct PACKET_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN p = {};
  19196. p.packetType = HEADER_ZC_RANDOM_UPGRADE_ITEM_UI_OPEN;
  19197. p.itemId = client_nameid( upgrade->item_id );
  19198. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19199. #endif
  19200. }
  19201. void clif_parse_laphine_upgrade_close( int fd, map_session_data* sd ){
  19202. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19203. sd->state.laphine_upgrade = 0;
  19204. #endif
  19205. }
  19206. void clif_laphine_upgrade_result( map_session_data *sd, bool failed ){
  19207. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19208. struct PACKET_ZC_ACK_RANDOM_UPGRADE_ITEM p = {};
  19209. p.packetType = HEADER_ZC_ACK_RANDOM_UPGRADE_ITEM;
  19210. p.result = failed;
  19211. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19212. #endif
  19213. }
  19214. static void clif_item_preview( map_session_data *sd, int16 index ){
  19215. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19216. nullpo_retv( sd );
  19217. struct item* item = &sd->inventory.u.items_inventory[index];
  19218. struct PACKET_ZC_CHANGE_ITEM_OPTION p = {};
  19219. p.packetType = HEADER_ZC_CHANGE_ITEM_OPTION;
  19220. p.index = client_index( index );
  19221. #if PACKETVER_MAIN_NUM >= 20181017 || PACKETVER_RE_NUM >= 20181017 || PACKETVER_ZERO_NUM >= 20181024
  19222. p.isDamaged = item->attribute != 0;
  19223. #endif
  19224. p.refiningLevel = item->refine;
  19225. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200723
  19226. p.grade = item->enchantgrade;
  19227. #endif
  19228. clif_addcards( &p.slot, item );
  19229. clif_add_random_options( p.option_data, *item );
  19230. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  19231. #endif
  19232. }
  19233. void clif_parse_laphine_upgrade( int fd, map_session_data* sd ){
  19234. #if PACKETVER_MAIN_NUM >= 20170726 || PACKETVER_RE_NUM >= 20170621 || defined(PACKETVER_ZERO)
  19235. if( sd->state.laphine_upgrade == 0 ){
  19236. return;
  19237. }
  19238. struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM* p = (struct PACKET_CZ_REQ_RANDOM_UPGRADE_ITEM*)RFIFOP( fd, 0 );
  19239. if( sd->state.laphine_upgrade != p->itemId ){
  19240. return;
  19241. }
  19242. std::shared_ptr<s_laphine_upgrade> upgrade = laphine_upgrade_db.find( sd->state.laphine_upgrade );
  19243. if( upgrade == nullptr ){
  19244. return;
  19245. }
  19246. uint16 index = server_index( p->index );
  19247. if( index >= MAX_INVENTORY ){
  19248. return;
  19249. }
  19250. if( sd->inventory_data[index] == nullptr ){
  19251. return;
  19252. }
  19253. struct item* item = &sd->inventory.u.items_inventory[index];
  19254. // Not a valid target item
  19255. if( !util::vector_exists( upgrade->target_item_ids, item->nameid ) ){
  19256. clif_laphine_upgrade_result( sd, true );
  19257. return;
  19258. }
  19259. // If target item is not identified
  19260. if( item->identify == 0 ){
  19261. clif_laphine_upgrade_result( sd, true );
  19262. return;
  19263. }
  19264. // If target item is equipped
  19265. if( item->equip != 0 ){
  19266. clif_laphine_upgrade_result( sd, true );
  19267. return;
  19268. }
  19269. // If target item is in equipswitch
  19270. if( item->equipSwitch != 0 ){
  19271. clif_laphine_upgrade_result( sd, true );
  19272. return;
  19273. }
  19274. // Check minimum refine requirement
  19275. if( item->refine < upgrade->minimumRefine ){
  19276. clif_laphine_upgrade_result( sd, true );
  19277. return;
  19278. }
  19279. // Check maximum refine requirement
  19280. if( item->refine > upgrade->maximumRefine ){
  19281. clif_laphine_upgrade_result( sd, true );
  19282. return;
  19283. }
  19284. // If no cards are allowed
  19285. if( !upgrade->cardsAllowed ){
  19286. for( int i = 0; i < MAX_SLOTS; i++ ){
  19287. if( item->card[i] != 0 ){
  19288. clif_laphine_upgrade_result( sd, true );
  19289. return;
  19290. }
  19291. }
  19292. }
  19293. // If random options are required
  19294. if( upgrade->requiredRandomOptions > 0 ){
  19295. int i;
  19296. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19297. if( item->option[i].id != 0 ){
  19298. break;
  19299. }
  19300. }
  19301. if( ( i + 1 ) < upgrade->requiredRandomOptions ){
  19302. clif_laphine_upgrade_result( sd, true );
  19303. return;
  19304. }
  19305. }
  19306. int16 index2 = pc_search_inventory( sd, sd->state.laphine_upgrade );
  19307. if( index2 < 0 ){
  19308. clif_laphine_upgrade_result( sd, true );
  19309. return;
  19310. }
  19311. if( ( sd->inventory_data[index2]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){
  19312. if( pc_delitem( sd, index2, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){
  19313. return;
  19314. }
  19315. }
  19316. // Log removal of item
  19317. log_pick_pc( sd, LOG_TYPE_LAPHINE, -1, item );
  19318. // Visually remove it from the client
  19319. clif_delitem( *sd, index, 1, 0 );
  19320. // Apply the random options
  19321. if( upgrade->randomOptionGroup != nullptr ){
  19322. upgrade->randomOptionGroup->apply( *item );
  19323. }
  19324. // Change the refine rate if needed
  19325. if( upgrade->resultRefine > 0 ){
  19326. // Absolute refine level change
  19327. item->refine = max( item->refine, upgrade->resultRefine );
  19328. }else if( upgrade->resultRefineMaximum > 0 ){
  19329. // If a minimum is specified it can also downgrade
  19330. if( upgrade->resultRefineMinimum ){
  19331. item->refine = static_cast<uint8>( rnd_value<uint16>( upgrade->resultRefineMinimum, upgrade->resultRefineMaximum ) );
  19332. }else{
  19333. // Otherwise it can only be upgraded until the maximum, but not downgraded
  19334. item->refine = static_cast<uint8>( rnd_value<uint16>( item->refine, upgrade->resultRefineMaximum ) );
  19335. }
  19336. }else if( upgrade->resultRefineMinimum > 0 ){
  19337. // No maximum has been specified, so it can be anything between minimum and MAX_REFINE
  19338. item->refine = static_cast<uint8>( rnd_value<uint16>( upgrade->resultRefineMinimum, MAX_REFINE ) );
  19339. }
  19340. // Log retrieving the item again -> with the new options
  19341. log_pick_pc( sd, LOG_TYPE_LAPHINE, 1, item );
  19342. // Make it visible for the client again
  19343. clif_additem( sd, index, 1, 0 );
  19344. // Open a preview of the item
  19345. clif_item_preview( sd, index );
  19346. // Tell the client we are done
  19347. clif_laphine_upgrade_result( sd, false );
  19348. #endif
  19349. }
  19350. void clif_enchantgrade_add( map_session_data& sd, uint16 index = UINT16_MAX, std::shared_ptr<s_enchantgradelevel> gradeLevel = nullptr ){
  19351. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19352. PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST* p = reinterpret_cast<PACKET_ZC_GRADE_ENCHANT_MATERIAL_LIST*>( packet_buffer );
  19353. p->PacketType = HEADER_ZC_GRADE_ENCHANT_MATERIAL_LIST;
  19354. p->PacketLength = sizeof( *p );
  19355. if( index < UINT16_MAX ){
  19356. p->index = client_index( index );
  19357. p->success_chance = gradeLevel->chances[sd.inventory.u.items_inventory[index].refine] / 100;
  19358. p->blessing_info.id = client_nameid( gradeLevel->catalyst.item );
  19359. p->blessing_info.amount = gradeLevel->catalyst.amountPerStep;
  19360. p->blessing_info.max_blessing = gradeLevel->catalyst.maximumSteps;
  19361. p->blessing_info.bonus = gradeLevel->catalyst.chanceIncrease / 100;
  19362. // Not displayed by client
  19363. p->protect_itemid = 0;
  19364. p->protect_amount = 0;
  19365. int i = 0;
  19366. for( const auto& pair : gradeLevel->options ){
  19367. GRADE_ENCHANT_MATERIAL& mat = p->material_info[i];
  19368. std::shared_ptr<s_enchantgradeoption> option = pair.second;
  19369. mat.nameid = client_nameid( option->item );
  19370. mat.amount = option->amount;
  19371. mat.price = option->zeny;
  19372. mat.downgrade = option->downgrade_amount > 0;
  19373. mat.breakable = option->breaking_rate > 0;
  19374. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( mat ) );
  19375. i++;
  19376. }
  19377. }else{
  19378. p->index = -1;
  19379. p->success_chance = 0;
  19380. p->blessing_info.id = 0;
  19381. p->blessing_info.amount = 0;
  19382. p->blessing_info.max_blessing = 0;
  19383. p->blessing_info.bonus = 0;
  19384. p->protect_itemid = 0;
  19385. p->protect_amount = 0;
  19386. }
  19387. clif_send( p, p->PacketLength, &sd.bl, SELF );
  19388. #endif
  19389. }
  19390. void clif_parse_enchantgrade_add( int fd, map_session_data* sd ){
  19391. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19392. nullpo_retv( sd );
  19393. if( !sd->state.enchantgrade_open ){
  19394. return;
  19395. }
  19396. struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT* p = (struct PACKET_CZ_GRADE_ENCHANT_SELECT_EQUIPMENT*)RFIFOP( fd, 0 );
  19397. uint16 index = server_index( p->index );
  19398. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19399. return;
  19400. }
  19401. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19402. // Unsupported item type - no answer, because client should have actually prevented this request
  19403. if( enchantgrade == nullptr ){
  19404. return;
  19405. }
  19406. // Item can't be enhanced
  19407. if( !sd->inventory_data[index]->flag.gradable ){
  19408. return;
  19409. }
  19410. uint16 level = 0;
  19411. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19412. level = sd->inventory_data[index]->weapon_level;
  19413. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19414. level = sd->inventory_data[index]->armor_level;
  19415. }
  19416. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19417. // Cannot upgrade this weapon or armor level
  19418. if( enchantgradelevels == enchantgrade->levels.end() ){
  19419. clif_enchantgrade_add( *sd );
  19420. return;
  19421. }
  19422. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19423. // Cannot increase enchantgrade any further - no answer, because client should have actually prevented this request
  19424. if( enchantgradelevel == nullptr ){
  19425. return;
  19426. }
  19427. clif_enchantgrade_add( *sd, index, enchantgradelevel );
  19428. #endif
  19429. }
  19430. /// <summary>
  19431. /// Sends the result for trying to enchant an item
  19432. /// </summary>
  19433. /// <param name="sd">The player session</param>
  19434. /// <param name="index">The target item</param>
  19435. /// <param name="result">
  19436. /// 0= The grade has been successfully upgraded.
  19437. /// 1= Refinement failed.
  19438. /// 2= The refine level has decreased.
  19439. /// 3= Equipment destroyed.
  19440. /// 4= The equipment is protected.
  19441. /// </param>
  19442. void clif_enchantgrade_result( map_session_data& sd, uint16 index, e_enchantgrade_result result ){
  19443. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19444. struct PACKET_ZC_GRADE_ENCHANT_ACK p = {};
  19445. p.PacketType = HEADER_ZC_GRADE_ENCHANT_ACK;
  19446. p.index = client_index( index );
  19447. p.grade = sd.inventory.u.items_inventory[index].enchantgrade;
  19448. p.result = result;
  19449. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19450. #endif
  19451. }
  19452. void clif_enchantgrade_announce( map_session_data& sd, struct item& item, bool success ){
  19453. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19454. struct PACKET_ZC_GRADE_ENCHANT_BROADCAST_RESULT p = {};
  19455. p.packetType = HEADER_ZC_GRADE_ENCHANT_BROADCAST_RESULT;
  19456. safestrncpy( p.name, sd.status.name, sizeof( p.name ) );
  19457. p.itemId = client_nameid( item.nameid );
  19458. p.grade = item.enchantgrade;
  19459. p.status = success;
  19460. clif_send( &p, sizeof( p ), nullptr, ALL_CLIENT );
  19461. #endif
  19462. }
  19463. void clif_parse_enchantgrade_start( int fd, map_session_data* sd ){
  19464. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19465. nullpo_retv( sd );
  19466. if( !sd->state.enchantgrade_open ){
  19467. return;
  19468. }
  19469. struct PACKET_CZ_GRADE_ENCHANT_REQUEST* p = (struct PACKET_CZ_GRADE_ENCHANT_REQUEST*)RFIFOP( fd, 0 );
  19470. uint16 index = server_index( p->index );
  19471. if( index >= MAX_INVENTORY || sd->inventory_data[index] == nullptr ){
  19472. return;
  19473. }
  19474. std::shared_ptr<s_enchantgrade> enchantgrade = enchantgrade_db.find( sd->inventory_data[index]->type );
  19475. // Unsupported item type - no answer
  19476. if( enchantgrade == nullptr ){
  19477. return;
  19478. }
  19479. uint16 level = 0;
  19480. if( sd->inventory_data[index]->type == IT_WEAPON ){
  19481. level = sd->inventory_data[index]->weapon_level;
  19482. }else if( sd->inventory_data[index]->type == IT_ARMOR ){
  19483. level = sd->inventory_data[index]->armor_level;
  19484. }
  19485. const auto& enchantgradelevels = enchantgrade->levels.find( level );
  19486. // Cannot upgrade this weapon or armor level - no answer
  19487. if( enchantgradelevels == enchantgrade->levels.end() ){
  19488. return;
  19489. }
  19490. std::shared_ptr<s_enchantgradelevel> enchantgradelevel = util::map_find( enchantgradelevels->second, (e_enchantgrade)sd->inventory.u.items_inventory[index].enchantgrade );
  19491. // Cannot increase enchantgrade any further - no answer
  19492. if( enchantgradelevel == nullptr ){
  19493. return;
  19494. }
  19495. uint16 totalChance = enchantgradelevel->chances[sd->inventory.u.items_inventory[index].refine];
  19496. // No chance to increase the enchantgrade
  19497. if( totalChance == 0 ){
  19498. return;
  19499. }
  19500. std::shared_ptr<s_enchantgradeoption> option = util::map_find( enchantgradelevel->options, (uint16)p->material_index );
  19501. // Unknown option id - no answer
  19502. if( option == nullptr ){
  19503. return;
  19504. }
  19505. // Not enough zeny
  19506. if( sd->status.zeny < option->zeny ){
  19507. return;
  19508. }
  19509. uint16 steps = min( p->blessing_amount, enchantgradelevel->catalyst.maximumSteps );
  19510. std::unordered_map<uint16, uint16> requiredItems;
  19511. if( p->blessing_flag ){
  19512. // If the catalysator item is the same as the option item build the sum of amounts
  19513. if( enchantgradelevel->catalyst.item == option->item ){
  19514. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps + option->amount;
  19515. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19516. if( index < 0 ){
  19517. return;
  19518. }
  19519. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19520. return;
  19521. }
  19522. requiredItems[index] = amount;
  19523. }else{
  19524. uint16 amount = enchantgradelevel->catalyst.amountPerStep * steps;
  19525. // Check catalysator item
  19526. int16 index = pc_search_inventory( sd, enchantgradelevel->catalyst.item );
  19527. if( index < 0 ){
  19528. return;
  19529. }
  19530. if( sd->inventory.u.items_inventory[index].amount < amount ){
  19531. return;
  19532. }
  19533. requiredItems[index] = amount;
  19534. // Check option item
  19535. index = pc_search_inventory( sd, option->item );
  19536. if( index < 0 ){
  19537. return;
  19538. }
  19539. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19540. return;
  19541. }
  19542. requiredItems[index] = option->amount;
  19543. }
  19544. totalChance += steps * enchantgradelevel->catalyst.chanceIncrease;
  19545. }else{
  19546. // Check option item
  19547. int16 index = pc_search_inventory( sd, option->item );
  19548. if( index < 0 ){
  19549. return;
  19550. }
  19551. if( sd->inventory.u.items_inventory[index].amount < option->amount ){
  19552. return;
  19553. }
  19554. requiredItems[index] = option->amount;
  19555. }
  19556. // All items should be there, start deleting
  19557. for( const auto& pair : requiredItems ){
  19558. if( pc_delitem( sd, pair.first, pair.second, 0, 0, LOG_TYPE_ENCHANTGRADE ) != 0 ){
  19559. return;
  19560. }
  19561. }
  19562. if( pc_payzeny( sd, option->zeny, LOG_TYPE_ENCHANTGRADE ) > 0 ){
  19563. return;
  19564. }
  19565. if( rnd()%10000 < totalChance ){
  19566. // Log removal of item
  19567. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19568. // Increase enchantgrade
  19569. sd->inventory.u.items_inventory[index].enchantgrade = min( sd->inventory.u.items_inventory[index].enchantgrade + 1, MAX_ENCHANTGRADE );
  19570. // On successful enchantgrade increase the refine is reset
  19571. sd->inventory.u.items_inventory[index].refine = 0;
  19572. // Log retrieving the item again -> with the new refine and enchantgrade
  19573. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19574. // Show success
  19575. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_SUCCESS );
  19576. // Check if it has to be announced
  19577. if( enchantgradelevel->announceSuccess ){
  19578. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], true );
  19579. }
  19580. }else{
  19581. // Check if it has to be announced (has to be done before deleting the item from inventory)
  19582. if( enchantgradelevel->announceFail ){
  19583. clif_enchantgrade_announce( *sd, sd->inventory.u.items_inventory[index], false );
  19584. }
  19585. // Delete the item if it is breakable
  19586. if( option->breaking_rate > 0 && ( rnd() % 10000 ) < option->breaking_rate ){
  19587. // Delete the item
  19588. pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_ENCHANTGRADE );
  19589. // Show failure
  19590. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_BREAK );
  19591. // Downgrade the item if necessary
  19592. }else if( option->downgrade_amount > 0 ){
  19593. // Log removal of item
  19594. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, -1, &sd->inventory.u.items_inventory[index] );
  19595. // Decrease refine level
  19596. sd->inventory.u.items_inventory[index].refine = cap_value( sd->inventory.u.items_inventory[index].refine - option->downgrade_amount, 0, MAX_REFINE );
  19597. // Log retrieving the item again -> with the new refine
  19598. log_pick_pc( sd, LOG_TYPE_ENCHANTGRADE, 1, &sd->inventory.u.items_inventory[index] );
  19599. // Show downgrade
  19600. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_DOWNGRADE );
  19601. // Only show failure, but dont do anything
  19602. }else{
  19603. clif_enchantgrade_result( *sd, index, ENCHANTGRADE_UPGRADE_FAILED );
  19604. }
  19605. }
  19606. #endif
  19607. }
  19608. void clif_parse_enchantgrade_close( int fd, map_session_data* sd ){
  19609. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20200724
  19610. nullpo_retv( sd );
  19611. sd->state.enchantgrade_open = false;
  19612. #endif
  19613. }
  19614. void clif_reputation_type( map_session_data& sd, int64 type, int64 points ){
  19615. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19616. PACKET_ZC_REPUTE_INFO* p = reinterpret_cast<PACKET_ZC_REPUTE_INFO*>( packet_buffer );
  19617. p->packetType = HEADER_ZC_REPUTE_INFO;
  19618. p->packetLength = sizeof( *p );
  19619. p->success = true;
  19620. PACKET_ZC_REPUTE_INFO_sub& entry = p->list[0];
  19621. entry.type = type;
  19622. entry.points = points;
  19623. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( entry ) );
  19624. clif_send( p, p->packetLength, &sd.bl, SELF );
  19625. #endif
  19626. }
  19627. void clif_reputation_list( map_session_data& sd ){
  19628. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19629. PACKET_ZC_REPUTE_INFO* p = reinterpret_cast<PACKET_ZC_REPUTE_INFO*>( packet_buffer );
  19630. p->packetType = HEADER_ZC_REPUTE_INFO;
  19631. p->packetLength = sizeof( *p );
  19632. p->success = true;
  19633. size_t index = 0;
  19634. for( const auto& entry : reputation_db ){
  19635. std::shared_ptr<s_reputation> reputation = entry.second;
  19636. PACKET_ZC_REPUTE_INFO_sub& list_entry = p->list[index];
  19637. list_entry.type = reputation->id;
  19638. list_entry.points = pc_readreg2( &sd, reputation->variable.c_str() );
  19639. p->packetLength += static_cast<decltype(p->packetLength)>( sizeof( list_entry ) );
  19640. index++;
  19641. }
  19642. clif_send( p, p->packetLength, &sd.bl, SELF );
  19643. #endif
  19644. }
  19645. void clif_item_reform_open( map_session_data& sd, t_itemid item ){
  19646. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19647. struct PACKET_ZC_OPEN_REFORM_UI p = {};
  19648. p.PacketType = HEADER_ZC_OPEN_REFORM_UI;
  19649. p.ITID = item;
  19650. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19651. sd.state.item_reform = item;
  19652. #endif
  19653. }
  19654. void clif_parse_item_reform_close( int fd, map_session_data* sd ){
  19655. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19656. sd->state.item_reform = 0;
  19657. #endif
  19658. }
  19659. void clif_item_reform_result( map_session_data& sd, uint16 index, uint8 result ){
  19660. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19661. struct PACKET_ZC_ITEM_REFORM_ACK p = {};
  19662. p.PacketType = HEADER_ZC_ITEM_REFORM_ACK;
  19663. p.index = client_index( index );
  19664. p.result = result;
  19665. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19666. if( result == 0 ){
  19667. // Client closes the window on success
  19668. sd.state.item_reform = 0;
  19669. }
  19670. #endif
  19671. }
  19672. void clif_parse_item_reform_start( int fd, map_session_data* sd ){
  19673. #if PACKETVER_MAIN_NUM >= 20200916 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19674. // Not opened
  19675. if( sd->state.item_reform == 0 ){
  19676. return;
  19677. }
  19678. struct PACKET_CZ_ITEM_REFORM *p = (struct PACKET_CZ_ITEM_REFORM*)RFIFOP( fd, 0 );
  19679. // Item mismatch
  19680. if( p->ITID != sd->state.item_reform ){
  19681. return;
  19682. }
  19683. uint16 index = server_index( p->index );
  19684. if( index >= MAX_INVENTORY ){
  19685. return;
  19686. }
  19687. if( sd->inventory_data[index] == nullptr ){
  19688. return;
  19689. }
  19690. std::shared_ptr<s_item_reform> reform = item_reform_db.find( sd->state.item_reform );
  19691. if( reform == nullptr ){
  19692. return;
  19693. }
  19694. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19695. std::shared_ptr<s_item_reform_base> base = util::umap_find( reform->base_items, selected_item.nameid );
  19696. if( base == nullptr ){
  19697. return;
  19698. }
  19699. // If target item is not identified
  19700. if( selected_item.identify == 0 ){
  19701. return;
  19702. }
  19703. // If target item is equipped
  19704. if( selected_item.equip != 0 ){
  19705. return;
  19706. }
  19707. // Check minimum refine requirement
  19708. if( selected_item.refine < base->minimumRefine ){
  19709. return;
  19710. }
  19711. // Check maximum refine requirement
  19712. if( selected_item.refine > base->maximumRefine ){
  19713. return;
  19714. }
  19715. // If no cards are allowed
  19716. if( !base->cardsAllowed ){
  19717. for( int i = 0; i < MAX_SLOTS; i++ ){
  19718. if( selected_item.card[i] != 0 ){
  19719. return;
  19720. }
  19721. }
  19722. }
  19723. // If random options are required
  19724. if( base->requiredRandomOptions > 0 ){
  19725. int i;
  19726. for( i = MAX_ITEM_RDM_OPT - 1; i >= 0; i-- ){
  19727. if( selected_item.option[i].id != 0 ){
  19728. break;
  19729. }
  19730. }
  19731. if( ( i + 1 ) < base->requiredRandomOptions ){
  19732. return;
  19733. }
  19734. }
  19735. std::unordered_map<uint16, uint16> materials;
  19736. // Check if all materials exist
  19737. for( const auto& material : base->materials ){
  19738. int16 material_index = pc_search_inventory( sd, material.first );
  19739. if( material_index < 0 ){
  19740. return;
  19741. }
  19742. if( sd->inventory.u.items_inventory[material_index].amount < material.second ){
  19743. return;
  19744. }
  19745. materials[material_index] = material.second;
  19746. }
  19747. // Remove the material
  19748. for( const auto& material : materials ){
  19749. if( pc_delitem( sd, material.first, material.second, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19750. return;
  19751. }
  19752. }
  19753. // If triggered from item
  19754. if( sd->itemid == sd->state.item_reform && pc_delitem( sd, sd->itemindex, 1, 0, 0, LOG_TYPE_REFORM ) != 0 ){
  19755. return;
  19756. }
  19757. // Log removal of item
  19758. log_pick_pc( sd, LOG_TYPE_REFORM, -1, &selected_item );
  19759. // Visually remove it from the client
  19760. clif_delitem( *sd, index, 1, 0 );
  19761. // Apply the random options
  19762. if( base->randomOptionGroup != nullptr ){
  19763. base->randomOptionGroup->apply( selected_item );
  19764. }
  19765. // Change the refine rate if needed
  19766. if( base->refineChange != 0 ){
  19767. selected_item.refine = cap_value( selected_item.refine + base->refineChange, 0, MAX_REFINE );
  19768. }
  19769. // Remove all cards and socket enchants
  19770. if( base->clearSlots ){
  19771. for( int i = 0; i < MAX_SLOTS; i++ ){
  19772. selected_item.card[i] = 0;
  19773. }
  19774. }
  19775. // Remove the current enchantgrade
  19776. if( base->removeEnchantgrade ){
  19777. selected_item.enchantgrade = 0;
  19778. }
  19779. // Finally change the item id
  19780. selected_item.nameid = base->resultItemId;
  19781. // Link inventory data cache to the new item
  19782. sd->inventory_data[index] = itemdb_search( base->resultItemId );
  19783. // Log retrieving the item again -> with the new options
  19784. log_pick_pc( sd, LOG_TYPE_REFORM, 1, &selected_item );
  19785. // Make it visible for the client again
  19786. clif_additem( sd, index, 1, 0 );
  19787. clif_item_reform_result( *sd, index, 0 );
  19788. #endif
  19789. }
  19790. void clif_enchantwindow_open( map_session_data& sd, uint64 clientLuaIndex ){
  19791. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19792. // Hardcoded clientside check
  19793. if( sd.weight > ( ( sd.max_weight * 70 ) / 100 ) ){
  19794. clif_msg_color( &sd, MSI_ENCHANT_FAILED_OVER_WEIGHT, color_table[COLOR_RED] );
  19795. sd.state.item_enchant_index = 0;
  19796. return;
  19797. }
  19798. struct PACKET_ZC_UI_OPEN_V3 p = {};
  19799. p.packetType = HEADER_ZC_UI_OPEN_V3;
  19800. p.type = OUT_UI_ENCHANT;
  19801. p.data = clientLuaIndex;
  19802. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19803. sd.state.item_enchant_index = clientLuaIndex;
  19804. #endif
  19805. }
  19806. void clif_enchantwindow_result( map_session_data& sd, bool success, t_itemid enchant = 0 ){
  19807. #if PACKETVER_RE_NUM >= 20211103 || PACKETVER_MAIN_NUM >= 20220330
  19808. struct PACKET_ZC_RESPONSE_ENCHANT p = {};
  19809. p.PacketType = HEADER_ZC_RESPONSE_ENCHANT;
  19810. if( success ){
  19811. p.msgId = MSI_ENCHANT_SUCCESS;
  19812. }else{
  19813. p.msgId = MSI_ENCHANT_FAILED;
  19814. }
  19815. p.ITID = enchant;
  19816. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  19817. sd.state.item_enchant_index = 0;
  19818. #endif
  19819. }
  19820. bool clif_parse_enchant_basecheck( struct item& selected_item, std::shared_ptr<s_item_enchant> enchant ){
  19821. if( selected_item.equip != 0 ){
  19822. return false;
  19823. }
  19824. if( selected_item.equipSwitch != 0 ){
  19825. return false;
  19826. }
  19827. if( selected_item.attribute != 0 ){
  19828. return false;
  19829. }
  19830. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  19831. return false;
  19832. }
  19833. if( selected_item.refine < enchant->minimumRefine ){
  19834. return false;
  19835. }
  19836. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  19837. return false;
  19838. }
  19839. if( !enchant->allowRandomOptions ){
  19840. for( const s_item_randomoption& option : selected_item.option ){
  19841. if( option.id != 0 ){
  19842. return false;
  19843. }
  19844. }
  19845. }
  19846. return true;
  19847. }
  19848. void clif_parse_enchantwindow_general( int fd, map_session_data* sd ){
  19849. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19850. struct PACKET_CZ_REQUEST_RANDOM_ENCHANT *p = (struct PACKET_CZ_REQUEST_RANDOM_ENCHANT*)RFIFOP( fd, 0 );
  19851. if( sd->state.item_enchant_index != p->enchant_group ){
  19852. return;
  19853. }
  19854. uint16 index = server_index( p->index );
  19855. if( index >= MAX_INVENTORY ){
  19856. return;
  19857. }
  19858. if( sd->inventory_data[index] == nullptr ){
  19859. return;
  19860. }
  19861. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19862. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  19863. if( enchant == nullptr ){
  19864. return;
  19865. }
  19866. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  19867. return;
  19868. }
  19869. uint16 slot = MAX_SLOTS;
  19870. for( uint16 nextSlot : enchant->order ){
  19871. if( selected_item.card[nextSlot] == 0 ){
  19872. slot = nextSlot;
  19873. break;
  19874. }
  19875. }
  19876. if( slot == MAX_SLOTS ){
  19877. return;
  19878. }
  19879. if( slot < sd->inventory_data[index]->slots ){
  19880. return;
  19881. }
  19882. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  19883. if( enchant_slot == nullptr ){
  19884. return;
  19885. }
  19886. std::shared_ptr<s_item_enchant_normal> enchants_for_enchantgrade = util::umap_find( enchant_slot->normal.enchants, (uint16)selected_item.enchantgrade );
  19887. if( enchants_for_enchantgrade == nullptr ){
  19888. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 829 ), false, SELF); // Enchanting is not possible for your item's enchant grade.
  19889. clif_enchantwindow_result( *sd, false );
  19890. return;
  19891. }
  19892. if( sd->status.zeny < enchant_slot->normal.zeny ){
  19893. return;
  19894. }
  19895. std::unordered_map<uint16, uint16> materials;
  19896. for( const auto& entry : enchant_slot->normal.materials ){
  19897. int16 idx = pc_search_inventory( sd, entry.first );
  19898. if( idx < 0 ){
  19899. return;
  19900. }
  19901. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  19902. return;
  19903. }
  19904. materials[idx] = entry.second;
  19905. }
  19906. if( pc_payzeny( sd, enchant_slot->normal.zeny, LOG_TYPE_ENCHANT ) != 0 ){
  19907. return;
  19908. }
  19909. for( const auto& entry : materials ){
  19910. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  19911. return;
  19912. }
  19913. }
  19914. uint32 chance = enchant_slot->normal.chance;
  19915. for( int i = 0; i <= MAX_ENCHANTGRADE; i++ ){
  19916. chance += enchant_slot->normal.enchantgradeChanceIncrease[i];
  19917. }
  19918. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  19919. clif_enchantwindow_result( *sd, false );
  19920. return;
  19921. }
  19922. // Log removal of item
  19923. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  19924. size_t maximum = 3 * enchant_slot->normal.enchants.size();
  19925. bool enchanted = false;
  19926. for( int i = 0; i < maximum; i++ ){
  19927. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  19928. if( rnd_value( 0, 10000 ) < normal_enchant->chance ){
  19929. selected_item.card[slot] = normal_enchant->item_id;
  19930. enchanted = true;
  19931. break;
  19932. }
  19933. }
  19934. if( !enchanted ){
  19935. std::shared_ptr<s_item_enchant_normal_sub> normal_enchant = util::umap_random( enchants_for_enchantgrade->enchants );
  19936. selected_item.card[slot] = normal_enchant->item_id;
  19937. }
  19938. // Log retrieving the item again -> with the new enchant
  19939. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  19940. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  19941. #endif
  19942. }
  19943. void clif_parse_enchantwindow_perfect( int fd, map_session_data* sd ){
  19944. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  19945. struct PACKET_CZ_REQUEST_PERFECT_ENCHANT *p = (struct PACKET_CZ_REQUEST_PERFECT_ENCHANT*)RFIFOP( fd, 0 );
  19946. if( sd->state.item_enchant_index != p->enchant_group ){
  19947. return;
  19948. }
  19949. uint16 index = server_index( p->index );
  19950. if( index >= MAX_INVENTORY ){
  19951. return;
  19952. }
  19953. if( sd->inventory_data[index] == nullptr ){
  19954. return;
  19955. }
  19956. struct item& selected_item = sd->inventory.u.items_inventory[index];
  19957. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  19958. if( enchant == nullptr ){
  19959. return;
  19960. }
  19961. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  19962. return;
  19963. }
  19964. uint16 slot = MAX_SLOTS;
  19965. for( uint16 nextSlot : enchant->order ){
  19966. if( selected_item.card[nextSlot] == 0 ){
  19967. slot = nextSlot;
  19968. break;
  19969. }
  19970. }
  19971. if( slot == MAX_SLOTS ){
  19972. return;
  19973. }
  19974. if( slot < sd->inventory_data[index]->slots ){
  19975. return;
  19976. }
  19977. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  19978. if( enchant_slot == nullptr ){
  19979. return;
  19980. }
  19981. std::shared_ptr<s_item_enchant_perfect> perfect_enchant = util::umap_find( enchant_slot->perfect.enchants, p->ITID );
  19982. if( perfect_enchant == nullptr ){
  19983. return;
  19984. }
  19985. if( sd->status.zeny < perfect_enchant->zeny ){
  19986. return;
  19987. }
  19988. std::unordered_map<uint16, uint16> materials;
  19989. for( const auto& entry : perfect_enchant->materials ){
  19990. int16 idx = pc_search_inventory( sd, entry.first );
  19991. if( idx < 0 ){
  19992. return;
  19993. }
  19994. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  19995. return;
  19996. }
  19997. materials[idx] = entry.second;
  19998. }
  19999. if( pc_payzeny( sd, perfect_enchant->zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20000. return;
  20001. }
  20002. for( const auto& entry : materials ){
  20003. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20004. return;
  20005. }
  20006. }
  20007. // Log removal of item
  20008. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20009. selected_item.card[slot] = perfect_enchant->item_id;
  20010. // Log retrieving the item again -> with the new enchant
  20011. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20012. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20013. #endif
  20014. }
  20015. void clif_parse_enchantwindow_upgrade( int fd, map_session_data* sd ){
  20016. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20017. struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT *p = (struct PACKET_CZ_REQUEST_UPGRADE_ENCHANT*)RFIFOP( fd, 0 );
  20018. if( sd->state.item_enchant_index != p->enchant_group ){
  20019. return;
  20020. }
  20021. uint16 index = server_index( p->index );
  20022. if( index >= MAX_INVENTORY ){
  20023. return;
  20024. }
  20025. if( sd->inventory_data[index] == nullptr ){
  20026. return;
  20027. }
  20028. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20029. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20030. if( enchant == nullptr ){
  20031. return;
  20032. }
  20033. if( !clif_parse_enchant_basecheck( selected_item, enchant ) ){
  20034. return;
  20035. }
  20036. uint16 slot = p->slot;
  20037. if( slot >= MAX_SLOTS ){
  20038. return;
  20039. }
  20040. if( slot < sd->inventory_data[index]->slots ){
  20041. return;
  20042. }
  20043. if( selected_item.card[slot] == 0 ){
  20044. return;
  20045. }
  20046. std::shared_ptr<s_item_enchant_slot> enchant_slot = util::umap_find( enchant->slots, slot );
  20047. if( enchant_slot == nullptr ){
  20048. return;
  20049. }
  20050. std::shared_ptr<s_item_enchant_upgrade> upgrade = util::umap_find( enchant_slot->upgrade.enchants, selected_item.card[slot] );
  20051. if( upgrade == nullptr ){
  20052. return;
  20053. }
  20054. if( sd->status.zeny < upgrade->zeny ){
  20055. return;
  20056. }
  20057. std::unordered_map<uint16, uint16> materials;
  20058. for( const auto& entry : upgrade->materials ){
  20059. int16 idx = pc_search_inventory( sd, entry.first );
  20060. if( idx < 0 ){
  20061. return;
  20062. }
  20063. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20064. return;
  20065. }
  20066. materials[idx] = entry.second;
  20067. }
  20068. if( pc_payzeny( sd, upgrade->zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20069. return;
  20070. }
  20071. for( const auto& entry : materials ){
  20072. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20073. return;
  20074. }
  20075. }
  20076. // Log removal of item
  20077. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20078. selected_item.card[slot] = upgrade->upgrade_item_id;
  20079. // Log retrieving the item again -> with the new enchant
  20080. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20081. clif_enchantwindow_result( *sd, true, selected_item.card[slot] );
  20082. #endif
  20083. }
  20084. void clif_parse_enchantwindow_reset( int fd, map_session_data* sd ){
  20085. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20086. struct PACKET_CZ_REQUEST_RESET_ENCHANT *p = (struct PACKET_CZ_REQUEST_RESET_ENCHANT*)RFIFOP( fd, 0 );
  20087. if( sd->state.item_enchant_index != p->enchant_group ){
  20088. return;
  20089. }
  20090. uint16 index = server_index( p->index );
  20091. if( index >= MAX_INVENTORY ){
  20092. return;
  20093. }
  20094. if( sd->inventory_data[index] == nullptr ){
  20095. return;
  20096. }
  20097. struct item& selected_item = sd->inventory.u.items_inventory[index];
  20098. if( selected_item.equip != 0 ){
  20099. return;
  20100. }
  20101. if( selected_item.equipSwitch != 0 ){
  20102. return;
  20103. }
  20104. if( selected_item.attribute != 0 ){
  20105. return;
  20106. }
  20107. std::shared_ptr<s_item_enchant> enchant = item_enchant_db.find( p->enchant_group );
  20108. if( enchant == nullptr ){
  20109. return;
  20110. }
  20111. if( !util::vector_exists( enchant->target_item_ids, selected_item.nameid ) ){
  20112. return;
  20113. }
  20114. if( selected_item.refine < enchant->minimumRefine ){
  20115. return;
  20116. }
  20117. if( selected_item.enchantgrade < enchant->minimumEnchantgrade ){
  20118. return;
  20119. }
  20120. bool is_enchanted = false;
  20121. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20122. if( selected_item.card[i] != 0 ){
  20123. is_enchanted = true;
  20124. break;
  20125. }
  20126. }
  20127. if( !is_enchanted ){
  20128. return;
  20129. }
  20130. if( sd->status.zeny < enchant->reset.zeny ){
  20131. return;
  20132. }
  20133. std::unordered_map<uint16, uint16> materials;
  20134. for( const auto& entry : enchant->reset.materials ){
  20135. int16 idx = pc_search_inventory( sd, entry.first );
  20136. if( idx < 0 ){
  20137. return;
  20138. }
  20139. if( sd->inventory.u.items_inventory[idx].amount < entry.second ){
  20140. return;
  20141. }
  20142. materials[idx] = entry.second;
  20143. }
  20144. if( pc_payzeny( sd, enchant->reset.zeny, LOG_TYPE_ENCHANT ) != 0 ){
  20145. return;
  20146. }
  20147. for( const auto& entry : materials ){
  20148. if( pc_delitem( sd, entry.first, entry.second, 0, 0, LOG_TYPE_ENCHANT ) != 0 ){
  20149. return;
  20150. }
  20151. }
  20152. uint32 chance = enchant->reset.chance;
  20153. if( chance == 0 ){
  20154. return;
  20155. }
  20156. if( chance < 100000 && rnd_value( 0, 100000 ) > chance ){
  20157. clif_enchantwindow_result( *sd, false );
  20158. return;
  20159. }
  20160. // Log removal of item
  20161. log_pick_pc( sd, LOG_TYPE_ENCHANT, -1, &selected_item );
  20162. for( int i = sd->inventory_data[index]->slots; i < MAX_SLOTS; i++ ){
  20163. selected_item.card[i] = 0;
  20164. }
  20165. // Log retrieving the item again -> with the new enchant
  20166. log_pick_pc( sd, LOG_TYPE_ENCHANT, 1, &selected_item );
  20167. clif_enchantwindow_result( *sd, true );
  20168. #endif
  20169. }
  20170. void clif_parse_enchantwindow_close( int fd, map_session_data* sd ){
  20171. #if PACKETVER_MAIN_NUM >= 20201118 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20172. sd->state.item_enchant_index = 0;
  20173. #endif
  20174. }
  20175. void clif_parse_itempackage_select( int fd, map_session_data* sd ){
  20176. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220316
  20177. struct PACKET_CZ_USE_PACKAGEITEM* p = (struct PACKET_CZ_USE_PACKAGEITEM*)RFIFOP( fd, 0 );
  20178. if( p->AID != sd->status.account_id ){
  20179. return;
  20180. }
  20181. uint16 index = server_index( p->index );
  20182. if( index >= MAX_INVENTORY ){
  20183. return;
  20184. }
  20185. if( sd->inventory_data[index] == nullptr ){
  20186. return;
  20187. }
  20188. if( sd->inventory_data[index]->nameid != p->itemID ){
  20189. return;
  20190. }
  20191. if( sd->inventory_data[index]->elv > sd->status.base_level ){
  20192. return;
  20193. }
  20194. std::shared_ptr<s_item_package> package = item_package_db.find( p->itemID );
  20195. if( package == nullptr ){
  20196. return;
  20197. }
  20198. std::shared_ptr<s_item_package_group> group = util::umap_find( package->groups, p->BoxIndex );
  20199. if( group == nullptr ){
  20200. return;
  20201. }
  20202. if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_PACKAGE ) != 0 ){
  20203. return;
  20204. }
  20205. for( const auto& entry : group->items ){
  20206. struct item item = {};
  20207. item.nameid = entry.second->item_id;
  20208. item.identify = 1;
  20209. item.refine = (char)entry.second->refine;
  20210. if( entry.second->rentalhours ){
  20211. item.expire_time = (uint32)( time( nullptr ) + entry.second->rentalhours * 3600 );
  20212. }
  20213. // Check if it is a pet egg
  20214. std::shared_ptr<s_pet_db> pet = pet_db_search( item.nameid, PET_EGG );
  20215. if( pet != nullptr ){
  20216. for( int i = 0; i < entry.second->amount; i++ ){
  20217. pet_create_egg( sd, item.nameid );
  20218. }
  20219. }else if( entry.second->amount > 1 && ( !itemdb_isstackable( item.nameid ) || item.expire_time > 0 ) ){
  20220. for( int i = 0; i < entry.second->amount; i++ ){
  20221. // New random options on each iteration
  20222. if( entry.second->randomOptionGroup != nullptr ){
  20223. entry.second->randomOptionGroup->apply( item );
  20224. }
  20225. pc_additem( sd, &item, 1, LOG_TYPE_PACKAGE );
  20226. }
  20227. }else{
  20228. if( entry.second->randomOptionGroup != nullptr ){
  20229. entry.second->randomOptionGroup->apply( item );
  20230. }
  20231. pc_additem( sd, &item, entry.second->amount, LOG_TYPE_PACKAGE );
  20232. }
  20233. }
  20234. #endif
  20235. }
  20236. void clif_broadcast_refine_result(map_session_data& sd, t_itemid itemId, int8 level, bool success)
  20237. {
  20238. #if PACKETVER_MAIN_NUM >= 20170906 || PACKETVER_RE_NUM >= 20170830 || defined(PACKETVER_ZERO)
  20239. PACKET_ZC_BROADCAST_ITEMREFINING_RESULT p{};
  20240. p.packetType = HEADER_ZC_BROADCAST_ITEMREFINING_RESULT;
  20241. p.itemId = itemId;
  20242. p.refine_level = level;
  20243. p.status = (int8)success;
  20244. if (battle_config.broadcast_hide_name) {
  20245. std::string dispname = clif_hide_name(sd.status.name);
  20246. safestrncpy(p.name, dispname.c_str(), sizeof(p.name));
  20247. }
  20248. else {
  20249. safestrncpy(p.name, sd.status.name, sizeof(p.name));
  20250. }
  20251. clif_send(&p, sizeof(p), &sd.bl, ALL_CLIENT);
  20252. #endif
  20253. }
  20254. void clif_parse_captcha_register(int fd, map_session_data *sd) {
  20255. #if PACKETVER >= 20160316
  20256. nullpo_retv(sd);
  20257. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20258. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20259. return;
  20260. }
  20261. PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *p = (PACKET_CZ_REQ_UPLOAD_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20262. pc_macro_captcha_register(*sd, p->imageSize, p->answer);
  20263. #endif
  20264. }
  20265. void clif_captcha_upload_request(map_session_data &sd) {
  20266. #if PACKETVER >= 20160330
  20267. PACKET_ZC_ACK_UPLOAD_MACRO_DETECTOR p = {};
  20268. p.PacketType = HEADER_ZC_ACK_UPLOAD_MACRO_DETECTOR;
  20269. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20270. if (sd.captcha_upload.cd != nullptr) {
  20271. p.captchaFlag = 0;
  20272. } else {
  20273. p.captchaFlag = 1;
  20274. }
  20275. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20276. #endif
  20277. }
  20278. void clif_parse_captcha_upload(int fd, map_session_data *sd) {
  20279. #if PACKETVER >= 20160316
  20280. nullpo_retv(sd);
  20281. if (!pc_has_permission(sd, PC_PERM_MACRO_REGISTER)) {
  20282. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20283. return;
  20284. }
  20285. PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20286. int16 upload_size = p->PacketLength - sizeof(PACKET_CZ_UPLOAD_MACRO_DETECTOR_CAPTCHA);
  20287. if (upload_size < 1 || upload_size > MAX_CAPTCHA_CHUNK_SIZE)
  20288. return;
  20289. if (sd->captcha_upload.upload_size + upload_size > sd->captcha_upload.cd->image_size)
  20290. return;
  20291. pc_macro_captcha_register_upload(*sd, upload_size, p->imageData);
  20292. #endif
  20293. }
  20294. void clif_captcha_upload_end(map_session_data &sd) {
  20295. #if PACKETVER >= 20160330
  20296. PACKET_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA p = {};
  20297. p.PacketType = HEADER_ZC_COMPLETE_UPLOAD_MACRO_DETECTOR_CAPTCHA;
  20298. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20299. #endif
  20300. }
  20301. void clif_parse_captcha_preview_request(int fd, map_session_data *sd) {
  20302. #if PACKETVER >= 20160323
  20303. nullpo_retv(sd);
  20304. if (!(pc_has_permission(sd, PC_PERM_MACRO_REGISTER) && pc_has_permission(sd, PC_PERM_MACRO_DETECT))) {
  20305. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20306. return;
  20307. }
  20308. PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *p = (PACKET_CZ_REQ_PREVIEW_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20309. clif_captcha_preview_response(*sd, captcha_db.find(p->captchaID));
  20310. #endif
  20311. }
  20312. void clif_captcha_preview_response(map_session_data &sd, std::shared_ptr<s_captcha_data> cd) {
  20313. #if PACKETVER >= 20160330
  20314. PACKET_ZC_ACK_PREVIEW_MACRO_DETECTOR p = {};
  20315. p.PacketType = HEADER_ZC_ACK_PREVIEW_MACRO_DETECTOR;
  20316. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20317. if (cd == nullptr) {
  20318. p.captchaFlag = 1;
  20319. p.imageSize = 0;
  20320. } else {
  20321. p.captchaFlag = 0;
  20322. p.imageSize = cd->image_size;
  20323. }
  20324. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20325. if (cd != nullptr) {
  20326. for (uint16 offset = 0; offset < cd->image_size;) {
  20327. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20328. PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA* p2 = reinterpret_cast<PACKET_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA*>( packet_buffer );
  20329. p2->PacketType = HEADER_ZC_PREVIEW_MACRO_DETECTOR_CAPTCHA;
  20330. p2->PacketLength = sizeof( *p2 );
  20331. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20332. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20333. p2->PacketLength += static_cast<decltype(p2->PacketLength)>( chunk_size );
  20334. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20335. offset += chunk_size;
  20336. }
  20337. }
  20338. #endif
  20339. }
  20340. void clif_macro_detector_request(map_session_data &sd) {
  20341. #if PACKETVER >= 20160330
  20342. std::shared_ptr<s_captcha_data> cd = sd.macro_detect.cd;
  20343. if (cd == nullptr) {
  20344. return;
  20345. }
  20346. // Send preview initialization request to the client.
  20347. PACKET_ZC_APPLY_MACRO_DETECTOR p = {};
  20348. p.PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR;
  20349. p.imageSize = cd->image_size;
  20350. safestrncpy(p.captchaKey, "", sizeof(p.captchaKey));
  20351. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20352. for (uint16 offset = 0; offset < cd->image_size;) {
  20353. uint16 chunk_size = min(cd->image_size - offset, MAX_CAPTCHA_CHUNK_SIZE);
  20354. PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA* p2 = reinterpret_cast<PACKET_ZC_APPLY_MACRO_DETECTOR_CAPTCHA*>( packet_buffer );
  20355. p2->PacketType = HEADER_ZC_APPLY_MACRO_DETECTOR_CAPTCHA;
  20356. p2->PacketLength = sizeof( *p2 );
  20357. safestrncpy(p2->captchaKey, p.captchaKey, sizeof(p2->captchaKey));
  20358. memcpy(p2->imageData, &cd->image_data[offset], chunk_size);
  20359. p2->PacketLength += static_cast<decltype(p2->PacketLength)>( chunk_size );
  20360. clif_send(p2, p2->PacketLength, &sd.bl, SELF);
  20361. offset += chunk_size;
  20362. }
  20363. #endif
  20364. }
  20365. void clif_macro_detector_request_show(map_session_data &sd) {
  20366. #if PACKETVER >= 20160330
  20367. PACKET_ZC_REQ_ANSWER_MACRO_DETECTOR p = {};
  20368. p.PacketType = HEADER_ZC_REQ_ANSWER_MACRO_DETECTOR;
  20369. p.retryCount = sd.macro_detect.retry;
  20370. p.timeout = battle_config.macro_detection_timeout;
  20371. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20372. #endif
  20373. }
  20374. void clif_parse_macro_detector_download_ack(int fd, map_session_data *sd) {
  20375. #if PACKETVER >= 20160316
  20376. nullpo_retv(sd);
  20377. if (sd->macro_detect.retry != 0) {
  20378. //PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *p = (PACKET_CZ_COMPLETE_APPLY_MACRO_DETECTOR_CAPTCHA *)RFIFOP(fd, 0);
  20379. clif_macro_detector_request_show(*sd);
  20380. }
  20381. #endif
  20382. }
  20383. void clif_parse_macro_detector_answer(int fd, map_session_data *sd) {
  20384. #if PACKETVER >= 20160316
  20385. nullpo_retv(sd);
  20386. PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *p = (PACKET_CZ_ACK_ANSWER_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20387. pc_macro_detector_process_answer(*sd, p->answer);
  20388. #endif
  20389. }
  20390. void clif_macro_detector_status(map_session_data &sd, e_macro_detect_status stype) {
  20391. #if PACKETVER >= 20160330
  20392. PACKET_ZC_CLOSE_MACRO_DETECTOR p = {};
  20393. p.PacketType = HEADER_ZC_CLOSE_MACRO_DETECTOR;
  20394. p.status = stype;
  20395. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20396. #endif
  20397. }
  20398. void clif_parse_macro_reporter_select(int fd, map_session_data *sd) {
  20399. #if PACKETVER >= 20160330
  20400. nullpo_retv(sd);
  20401. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20402. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20403. return;
  20404. }
  20405. PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *p = (PACKET_CZ_REQ_PLAYER_AID_IN_RANGE *)RFIFOP(fd, 0);
  20406. pc_macro_reporter_area_select(*sd, p->xPos, p->yPos, p->RadiusRange);
  20407. #endif
  20408. }
  20409. void clif_macro_reporter_select(map_session_data &sd, const std::vector<uint32> &aid_list) {
  20410. #if PACKETVER >= 20160330
  20411. PACKET_ZC_ACK_PLAYER_AID_IN_RANGE* p = reinterpret_cast<PACKET_ZC_ACK_PLAYER_AID_IN_RANGE*>( packet_buffer );
  20412. p->PacketType = HEADER_ZC_ACK_PLAYER_AID_IN_RANGE;
  20413. p->PacketLength = sizeof( *p );
  20414. for (size_t i = 0; i < aid_list.size(); i++){
  20415. p->AID[i] = aid_list[static_cast<int32>(i)];
  20416. p->PacketLength += static_cast<decltype(p->PacketLength)>( sizeof( p->AID[0] ) );
  20417. }
  20418. clif_send(p, p->PacketLength, &sd.bl, SELF);
  20419. #endif
  20420. }
  20421. void clif_parse_macro_reporter_ack(int fd, map_session_data *sd) {
  20422. #if PACKETVER >= 20160316
  20423. nullpo_retv(sd);
  20424. if (!pc_has_permission(sd, PC_PERM_MACRO_DETECT)) {
  20425. clif_displaymessage(sd->fd, msg_txt(sd, 246)); // Your GM level doesn't authorize you to perform this action.
  20426. return;
  20427. }
  20428. PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *p = (PACKET_CZ_REQ_APPLY_MACRO_DETECTOR *)RFIFOP(fd, 0);
  20429. map_session_data *tsd = map_id2sd(p->AID);
  20430. if (tsd == nullptr) {
  20431. clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
  20432. return;
  20433. }
  20434. if (tsd->macro_detect.retry != 0) {
  20435. clif_macro_reporter_status(*sd, MCR_INPROGRESS);
  20436. return;
  20437. }
  20438. if (captcha_db.empty()) {
  20439. clif_macro_reporter_status(*sd, MCR_NO_DATA);
  20440. return;
  20441. }
  20442. pc_macro_reporter_process(*tsd, sd->status.account_id);
  20443. clif_macro_reporter_status(*sd, MCR_MONITORING);
  20444. #endif
  20445. }
  20446. void clif_macro_reporter_status(map_session_data &sd, e_macro_report_status stype) {
  20447. #if PACKETVER >= 20160330
  20448. PACKET_ZC_ACK_APPLY_MACRO_DETECTOR p = {};
  20449. p.PacketType = HEADER_ZC_ACK_APPLY_MACRO_DETECTOR;
  20450. p.status = stype;
  20451. clif_send(&p, sizeof(p), &sd.bl, SELF);
  20452. #endif
  20453. }
  20454. void clif_dynamicnpc_result( map_session_data& sd, e_dynamicnpc_result result ){
  20455. #if PACKETVER_MAIN_NUM >= 20140430 || PACKETVER_RE_NUM >= 20140430 || defined(PACKETVER_ZERO)
  20456. struct PACKET_ZC_DYNAMICNPC_CREATE_RESULT p = {};
  20457. p.PacketType = HEADER_ZC_DYNAMICNPC_CREATE_RESULT;
  20458. p.result = result;
  20459. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20460. #endif
  20461. }
  20462. void clif_partybooking_ask( map_session_data* sd, map_session_data* joining_sd ){
  20463. #if PACKETVER >= 20191204
  20464. struct PACKET_ZC_PARTY_REQ_MASTER_TO_JOIN p = { 0 };
  20465. p.packetType = HEADER_ZC_PARTY_REQ_MASTER_TO_JOIN;
  20466. p.CID = joining_sd->status.char_id;
  20467. p.AID = joining_sd->status.account_id;
  20468. safestrncpy( p.name, joining_sd->status.name, NAME_LENGTH );
  20469. p.x = joining_sd->status.base_level;
  20470. p.y = joining_sd->status.class_;
  20471. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20472. #endif
  20473. }
  20474. void clif_parse_partybooking_join( int fd, map_session_data* sd ){
  20475. #if PACKETVER >= 20191204
  20476. struct PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN* p = (struct PACKET_CZ_PARTY_REQ_MASTER_TO_JOIN*)RFIFOP( fd, 0 );
  20477. // Character is already in a party
  20478. if( sd->status.party_id != 0 ){
  20479. return;
  20480. }
  20481. map_session_data* tsd = map_charid2sd( p->CID );
  20482. // Target player is offline
  20483. if( tsd == nullptr ){
  20484. return;
  20485. }
  20486. if( tsd->status.account_id != p->AID ){
  20487. return;
  20488. }
  20489. struct s_party_booking_requirement requirement;
  20490. if( !party_booking_load( tsd->status.account_id, tsd->status.char_id, &requirement ) ){
  20491. return;
  20492. }
  20493. if( sd->status.base_level < requirement.minimum_level ){
  20494. return;
  20495. }
  20496. if( sd->status.base_level > requirement.maximum_level ){
  20497. return;
  20498. }
  20499. // Already requested to join this party
  20500. if( util::vector_exists( tsd->party_booking_requests, sd->status.char_id ) ){
  20501. return;
  20502. }
  20503. // Store information that the player tried to join the party
  20504. tsd->party_booking_requests.push_back( sd->status.char_id );
  20505. clif_partybooking_ask( tsd, sd );
  20506. #endif
  20507. }
  20508. void clif_partybooking_reply( map_session_data* sd, map_session_data* party_leader_sd, bool accepted ){
  20509. #if PACKETVER >= 20191204
  20510. struct PACKET_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER p = { 0 };
  20511. if( party_leader_sd->status.party_id == 0 ){
  20512. return;
  20513. }
  20514. struct party_data* party = party_search( party_leader_sd->status.party_id );
  20515. if( party == nullptr ){
  20516. return;
  20517. }
  20518. p.packetType = HEADER_ZC_PARTY_JOIN_REQ_ACK_FROM_MASTER;
  20519. safestrncpy( p.player_name, party_leader_sd->status.name, NAME_LENGTH );
  20520. safestrncpy( p.party_name, party->party.name, NAME_LENGTH );
  20521. p.AID = party_leader_sd->status.account_id;
  20522. p.refused = !accepted;
  20523. clif_send( &p, sizeof( p ), &sd->bl, SELF );
  20524. #endif
  20525. }
  20526. void clif_parse_partybooking_reply( int fd, map_session_data* sd ){
  20527. #if PACKETVER >= 20191204
  20528. struct PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN* p = (struct PACKET_CZ_PARTY_REQ_ACK_MASTER_TO_JOIN*)RFIFOP( fd, 0 );
  20529. map_session_data* tsd = map_charid2sd( p->CID );
  20530. // Target player is offline
  20531. if( tsd == nullptr ){
  20532. return;
  20533. }
  20534. if( tsd->status.account_id != p->AID ){
  20535. return;
  20536. }
  20537. // Check if the player even requested to join the party
  20538. if( !util::vector_exists( sd->party_booking_requests, p->CID ) ){
  20539. return;
  20540. }
  20541. util::vector_erase_if_exists( sd->party_booking_requests, p->CID );
  20542. // Only party leaders can reply
  20543. if( !party_isleader( sd ) ){
  20544. return;
  20545. }
  20546. if( p->accept ){
  20547. party_join( tsd, sd->status.party_id );
  20548. }
  20549. clif_partybooking_reply( tsd, sd, p->accept );
  20550. #endif
  20551. }
  20552. void clif_parse_reset_skill( int fd, map_session_data* sd ){
  20553. #if PACKETVER_MAIN_NUM >= 20220216 || PACKETVER_ZERO_NUM >= 20220203
  20554. PACKET_CZ_RESET_SKILL* p = (PACKET_CZ_RESET_SKILL*)RFIFOP( fd, 0 );
  20555. #endif
  20556. }
  20557. void clif_set_dialog_align(map_session_data& sd, int npcid, e_say_dialog_align align)
  20558. {
  20559. #if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20560. PACKET_ZC_DIALOG_TEXT_ALIGN p = {};
  20561. p.PacketType = HEADER_ZC_DIALOG_TEXT_ALIGN;
  20562. p.align = align;
  20563. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20564. #endif // PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024
  20565. }
  20566. void clif_set_npc_window_size(map_session_data& sd, int width, int height)
  20567. {
  20568. #if PACKETVER_MAIN_NUM >= 20220504
  20569. PACKET_ZC_DIALOG_WINDOW_SIZE p = {};
  20570. p.PacketType = HEADER_ZC_DIALOG_WINDOW_SIZE;
  20571. p.width = width;
  20572. p.height = height;
  20573. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20574. #endif // PACKETVER_MAIN_NUM >= 20220504
  20575. }
  20576. void clif_set_npc_window_pos(map_session_data& sd, int x, int y)
  20577. {
  20578. #if PACKETVER_MAIN_NUM >= 20220504
  20579. PACKET_ZC_DIALOG_WINDOW_POS p = {};
  20580. p.PacketType = HEADER_ZC_DIALOG_WINDOW_POS;
  20581. p.x = x;
  20582. p.y = y;
  20583. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20584. #endif // PACKETVER_MAIN_NUM >= 20220504
  20585. }
  20586. void clif_set_npc_window_pos_percent(map_session_data& sd, int x, int y)
  20587. {
  20588. #if PACKETVER_MAIN_NUM >= 20220504
  20589. PACKET_ZC_DIALOG_WINDOW_POS2 p = {};
  20590. p.PacketType = HEADER_ZC_DIALOG_WINDOW_POS2;
  20591. p.x = x;
  20592. p.y = y;
  20593. clif_send( &p, sizeof( p ), &sd.bl, SELF );
  20594. #endif // PACKETVER_MAIN_NUM >= 20220504
  20595. }
  20596. /*==========================================
  20597. * Main client packet processing function
  20598. *------------------------------------------*/
  20599. static int clif_parse(int fd)
  20600. {
  20601. int cmd, packet_len;
  20602. TBL_PC* sd;
  20603. int pnum;
  20604. #ifdef PACKET_OBFUSCATION
  20605. int cmd2;
  20606. #endif
  20607. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  20608. // Note: "click masters" can do 80+ clicks in 10 seconds
  20609. 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]
  20610. { // begin main client packet processing loop
  20611. sd = (TBL_PC *)session[fd]->session_data;
  20612. if (session[fd]->flag.eof) {
  20613. if (sd) {
  20614. if (sd->state.autotrade) {
  20615. //Disassociate character from the socket connection.
  20616. session[fd]->session_data = nullptr;
  20617. sd->fd = 0;
  20618. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  20619. } else
  20620. if (sd->state.active) {
  20621. // Player logout display [Valaris]
  20622. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  20623. clif_quitsave(fd, sd);
  20624. } else {
  20625. //Unusual logout (during log on/off/map-changer procedure)
  20626. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  20627. map_quit(sd);
  20628. }
  20629. } else {
  20630. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, nullptr));
  20631. }
  20632. do_close(fd);
  20633. return 0;
  20634. }
  20635. if (RFIFOREST(fd) < 2)
  20636. return 0;
  20637. cmd = RFIFOW(fd, 0);
  20638. #ifdef PACKET_OBFUSCATION
  20639. // Check if it is a player that tries to connect to the map server.
  20640. if( sd ){
  20641. // Decrypt the current packet ID with the last key stored in the session.
  20642. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  20643. }else{
  20644. // Store the original value for checking
  20645. cmd2 = cmd;
  20646. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  20647. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20648. }
  20649. #endif
  20650. // filter out invalid / unsupported packets
  20651. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  20652. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  20653. #ifdef DUMP_INVALID_PACKET
  20654. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20655. #endif
  20656. #ifdef PACKET_OBFUSCATION_WARN
  20657. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  20658. if( !sd ){
  20659. #ifdef PACKET_OBFUSCATION
  20660. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  20661. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  20662. }
  20663. #else
  20664. // Try to use the initial keys for the decryption of the packet ID.
  20665. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  20666. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  20667. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  20668. }
  20669. #endif
  20670. }
  20671. #endif
  20672. set_eof(fd);
  20673. return 0;
  20674. }
  20675. // determine real packet length
  20676. packet_len = packet_db[cmd].len;
  20677. if (packet_len == -1) { // variable-length packet
  20678. if (RFIFOREST(fd) < 4)
  20679. return 0;
  20680. packet_len = RFIFOW(fd,2);
  20681. if (packet_len < 4 || packet_len > 32768) {
  20682. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  20683. #ifdef DUMP_INVALID_PACKET
  20684. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  20685. #endif
  20686. set_eof(fd);
  20687. return 0;
  20688. }
  20689. }
  20690. if ((int)RFIFOREST(fd) < packet_len){
  20691. 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 );
  20692. #ifdef DUMP_INVALID_PACKET
  20693. ShowDump( RFIFOP( fd, 0 ), RFIFOREST( fd ) );
  20694. #endif
  20695. set_eof( fd );
  20696. return 0; // not enough data received to form the packet
  20697. }
  20698. #ifdef PACKET_OBFUSCATION
  20699. RFIFOW(fd, 0) = cmd;
  20700. if (sd)
  20701. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  20702. #endif
  20703. if( packet_db[cmd].func == clif_parse_debug )
  20704. packet_db[cmd].func(fd, sd);
  20705. else if( packet_db[cmd].func != nullptr ) {
  20706. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  20707. ; //Only valid packet when there is no session
  20708. else
  20709. if( sd && sd->bl.prev == nullptr && packet_db[cmd].func != clif_parse_LoadEndAck )
  20710. ; //Only valid packet when player is not on a map
  20711. else
  20712. packet_db[cmd].func(fd, sd);
  20713. }
  20714. #ifdef DUMP_UNKNOWN_PACKET
  20715. else DumpUnknown(fd,sd,cmd,packet_len);
  20716. #endif
  20717. RFIFOSKIP(fd, packet_len);
  20718. }; // main loop end
  20719. return 0;
  20720. }
  20721. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, map_session_data *), ... ){
  20722. va_list argp;
  20723. int i;
  20724. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  20725. return;
  20726. packet_db[cmd].len = length;
  20727. packet_db[cmd].func = func;
  20728. va_start(argp, func);
  20729. for( i = 0; i < MAX_PACKET_POS; i++ ){
  20730. int offset = va_arg(argp, int);
  20731. if( offset == 0 ){
  20732. break;
  20733. }
  20734. packet_db[cmd].pos[i] = offset;
  20735. }
  20736. if( i == MAX_PACKET_POS ){
  20737. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  20738. }
  20739. va_end(argp);
  20740. }
  20741. /*==========================================
  20742. * Reads packets and setups its array reference
  20743. *------------------------------------------*/
  20744. void packetdb_readdb(){
  20745. memset(packet_db,0,sizeof(packet_db));
  20746. #include "clif_packetdb.hpp"
  20747. #include "clif_shuffle.hpp"
  20748. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  20749. #ifdef PACKET_OBFUSCATION
  20750. 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]);
  20751. #else
  20752. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  20753. #endif
  20754. }
  20755. /*==========================================
  20756. *
  20757. *------------------------------------------*/
  20758. void do_init_clif(void) {
  20759. const int colors[COLOR_MAX] = {
  20760. 0x00FF00, // COLOR_DEFAULT
  20761. 0xFF0000, // COLOR_RED
  20762. 0xFFFFFF, // COLOR_WHITE
  20763. 0xFFFF00, // COLOR_YELLOW
  20764. 0x00FFFF, // COLOR_CYAN
  20765. 0xB5FFB5, // COLOR_LIGHT_GREEN
  20766. 0xFFFF63, // COLOR_LIGHT_YELLOW
  20767. };
  20768. /**
  20769. * Setup Color Table (saves unnecessary load of strtoul on every call)
  20770. **/
  20771. for( int i = 0; i < COLOR_MAX; i++ ){
  20772. color_table[i] = ( colors[i] & 0x0000FF ) << 16 | ( colors[i] & 0x00FF00 ) | ( colors[i] & 0xFF0000 ) >> 16; //RGB to BGR
  20773. }
  20774. packetdb_readdb();
  20775. set_defaultparse(clif_parse);
  20776. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  20777. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  20778. exit(EXIT_FAILURE);
  20779. }
  20780. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  20781. add_timer_func_list(clif_delayquit, "clif_delayquit");
  20782. #if PACKETVER_MAIN_NUM >= 20190403 || PACKETVER_RE_NUM >= 20190320
  20783. add_timer_func_list( clif_ping_timer, "clif_ping_timer" );
  20784. if( battle_config.ping_timer_interval > 0 ){
  20785. add_timer_interval( gettick() + battle_config.ping_timer_interval * 1000, clif_ping_timer, 0, 0, battle_config.ping_timer_interval * 1000 );
  20786. }
  20787. #endif
  20788. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  20789. }
  20790. void do_final_clif(void) {
  20791. ers_destroy(delay_clearunit_ers);
  20792. }